wp_refresh_post_lock

函数
wp_refresh_post_lock ( $response, $data, $screen_id )
参数
  • (array) $response The Heartbeat response.
    Required:
  • (array) $data The $_POST data sent.
    Required:
  • (string) $screen_id The screen ID.
    Required:
返回值
  • (array) The Heartbeat response.
定义位置
相关方法
wp_refresh_post_nonceswp_set_post_lockwp_check_post_lockwp_ajax_wp_remove_post_lockwp_trash_post
引入
3.6.0
弃用
-

wp_refresh_post_lock: 这个函数用来刷新一个文章的锁,以防止其他用户在当前用户进行修改时对其进行编辑。

在”新建/编辑文章” 屏幕上检查锁定状态,并刷新锁定。

function wp_refresh_post_lock( $response, $data, $screen_id ) {
	if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) {
		$received = $data['wp-refresh-post-lock'];
		$send     = array();

		$post_id = absint( $received['post_id'] );

		if ( ! $post_id ) {
			return $response;
		}

		if ( ! current_user_can( 'edit_post', $post_id ) ) {
			return $response;
		}

		$user_id = wp_check_post_lock( $post_id );
		$user    = get_userdata( $user_id );

		if ( $user ) {
			$error = array(
				'name' => $user->display_name,
				/* translators: %s: User's display name. */
				'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ),
			);

			if ( get_option( 'show_avatars' ) ) {
				$error['avatar_src']    = get_avatar_url( $user->ID, array( 'size' => 64 ) );
				$error['avatar_src_2x'] = get_avatar_url( $user->ID, array( 'size' => 128 ) );
			}

			$send['lock_error'] = $error;
		} else {
			$new_lock = wp_set_post_lock( $post_id );

			if ( $new_lock ) {
				$send['new_lock'] = implode( ':', $new_lock );
			}
		}

		$response['wp-refresh-post-lock'] = $send;
	}

	return $response;
}

常见问题

FAQs
查看更多 >