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: 這是一個檢查一個文章是否被其他使用者鎖定的函式。它可以用來防止兩個使用者同時編輯同一個文章。

確定該文章目前是否被其他使用者編輯。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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
檢視更多 >