wp_set_post_lock

函式
wp_set_post_lock ( $post )
引數
  • (int|WP_Post) $post ID or object of the post being edited.
    Required:
返回值
  • (array|false) { Array of the lock time and user ID. False if the post does not exist, or there is no current user. @type int $0 The current time as a Unix timestamp. @type int $1 The ID of the current user. }
定義位置
相關方法
wp_check_post_lockwp_set_post_catswp_refresh_post_lockwp_set_post_tagswp_get_post_cats
引入
2.5.0
棄用
-

wp_set_post_lock: 這個函式鎖住一個文章,防止其他使用者編輯它。它接受文章的ID和鎖定該文章的使用者的ID。

將該文章標記為當前使用者正在編輯。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_set_post_lock( $post ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$user_id = get_current_user_id();
if ( 0 == $user_id ) {
return false;
}
$now = time();
$lock = "$now:$user_id";
update_post_meta( $post->ID, '_edit_lock', $lock );
return array( $now, $user_id );
}
function wp_set_post_lock( $post ) { $post = get_post( $post ); if ( ! $post ) { return false; } $user_id = get_current_user_id(); if ( 0 == $user_id ) { return false; } $now = time(); $lock = "$now:$user_id"; update_post_meta( $post->ID, '_edit_lock', $lock ); return array( $now, $user_id ); }
function wp_set_post_lock( $post ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$user_id = get_current_user_id();

	if ( 0 == $user_id ) {
		return false;
	}

	$now  = time();
	$lock = "$now:$user_id";

	update_post_meta( $post->ID, '_edit_lock', $lock );

	return array( $now, $user_id );
}

常見問題

FAQs
檢視更多 >