Using WordPress ‘override_post_lock’ PHP filter

The override_post_lock WordPress PHP filter allows you to control whether the post lock can be overridden or not.

Usage

add_filter('override_post_lock', 'your_custom_function', 10, 3);

function your_custom_function($override, $post, $user) {
  // Your custom code here

  return $override;
}

Parameters

  • $override (bool) – Whether to allow the post lock to be overridden. Default is true.
  • $post (WP_Post) – The post object being locked.
  • $user (WP_User) – The user who currently holds the lock for the post.

More information

See WordPress Developer Resources: override_post_lock

Examples

Prevent post lock override for specific user role

Prevent users with the ‘contributor’ role from overriding the post lock.

add_filter('override_post_lock', 'prevent_contributor_override', 10, 3);

function prevent_contributor_override($override, $post, $user) {
  if (in_array('contributor', $user->roles)) {
    return false;
  }

  return $override;
}

Prevent post lock override for specific post type

Disable post lock override for the ‘event’ post type.

add_filter('override_post_lock', 'prevent_event_override', 10, 3);

function prevent_event_override($override, $post, $user) {
  if ($post->post_type == 'event') {
    return false;
  }

  return $override;
}

Allow post lock override for specific user

Allow only user with ID 5 to override post lock.

add_filter('override_post_lock', 'allow_user_override', 10, 3);

function allow_user_override($override, $post, $user) {
  if ($user->ID == 5) {
    return true;
  }

  return $override;
}

Prevent post lock override for specific post ID

Disable post lock override for a specific post with ID 10.

add_filter('override_post_lock', 'prevent_specific_post_override', 10, 3);

function prevent_specific_post_override($override, $post, $user) {
  if ($post->ID == 10) {
    return false;
  }

  return $override;
}