wp_check_post_lock

函数
wp_check_post_lock ( $post )
参数
  • (int|WP_Post) $post ID or object of the post to check for editing.
    Required:
返回值
  • (int|false) ID of the user with lock. False if the post does not exist, post is not locked, the user with lock does not exist, or the post is locked by current user.
定义位置
相关方法
wp_set_post_lockwp_refresh_post_lockwp_check_comment_floodwp_check_passwordwp_check_locked_posts
引入
2.5.0
弃用
-

wp_check_post_lock: 这是一个检查一个文章是否被其他用户锁定的函数。它可以用来防止两个用户同时编辑同一个文章。

确定该文章目前是否被其他用户编辑。

function wp_check_post_lock( $post ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$lock = get_post_meta( $post->ID, '_edit_lock', true );

	if ( ! $lock ) {
		return false;
	}

	$lock = explode( ':', $lock );
	$time = $lock[0];
	$user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );

	if ( ! get_userdata( $user ) ) {
		return false;
	}

	/** This filter is documented in wp-admin/includes/ajax-actions.php */
	$time_window = apply_filters( 'wp_check_post_lock_window', 150 );

	if ( $time && $time > time() - $time_window && get_current_user_id() != $user ) {
		return $user;
	}

	return false;
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-14 09:36:28

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: