How to disable the “Post Lock/Edit Lock”?

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 );
        } );
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)