I want to disable this just for one Post Type, as it doesn’t really matters if there’s another user editing it (the main content editing area is Ajaxified and non-admins can only see that).
I looked at the core functions but couldn’t find an entry point. From the function wp_set_post_lock
I’m guessing that I’d have to intercept the get_post_meta
, but is there an official way to do it?
And there’s a second lock that doesn’t seem to be affected by the filter wp_check_post_lock_window
(as shown by birgire, here in an ). I’ve tried remove_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 );
at various points but it keeps beating without respecting remove_filter
.
As an addition to @birgire answer…
Findings
register_post_type()
allows to register a post type support, which can as well be done later on using add_post_type_support()
. And that can get checked against even later using the all mighty post_type_supports( $cpt, $feat )
.
A general mini plugin that adds a new feature
Now the following (mu-)plugin checks for a new kind of post type support that disables the post lock feature. It’s named disabled_post_lock
.
<?php
defined( 'ABSPATH' );
/** Plugin Name: (#120179) Maybe Disable Post Type Support */
add_action( 'load-edit.php', 'wpse120179MaybeDisablePostLock' );
function wpse120179MaybeDisablePostLock()
{
if ( post_type_supports( get_current_screen()->post_type, 'disabled_post_lock' ) )
add_filter( 'wp_check_post_lock_window', '__return_false' );
}
One plugin per CPT
Then we can easily add mini plugins to disable post type support for our own or third party plugins (saving us some bandwidth and DB size in the user meta table):
<?php
defined( 'ABSPATH' );
/** Plugin Name: (#120179) Disable Post Type Support for "Beer" Posts */
add_action( 'init', function()
{
add_post_type_support( 'beer', 'disabled_post_lock' );
} );
As soon as the second plugin is activated our beer post type has no more post lock. This should work nice and is easily revertable through the plugins admin screen.
Disabling the heartbeat API
Extending the plugin to disable the hearbeat API as well:
<?php
defined( 'ABSPATH' );
/** Plugin Name: (#120179) Maybe Disable Post Type Support */
add_action( 'load-edit.php', 'wpse120179MaybeDisablePostLock' );
function wpse120179MaybeDisablePostLock()
{
if ( post_type_supports( get_current_screen()->post_type, 'disabled_post_lock' ) )
{
add_filter( 'wp_check_post_lock_window', '__return_false' );
add_filter( 'heartbeat_settings', function( $settings )
{
return wp_parse_args( [ 'autostart' => false ], $settings );
} );
}
}