Yoast\WP\SEO\Bulk_Editor\Infrastructure\Updates

Post_Access_Checker{} │ Yoast 1.0└─ Post_Access_Checker_Interface

Checks post access through the WordPress APIs.

Хуков нет.

Использование

$Post_Access_Checker = new Post_Access_Checker();
// use class methods

Методы

  1. public __construct( Post_Type_Helper $post_type_helper )
  2. public can_edit( int $post_id )
  3. public exists( int $post_id )
  4. public is_supported_type( int $post_id )
  5. ERROR: no method name found on line ``
  6. ERROR: no method name found on line `/**`

Код Post_Access_Checker{} Yoast 28.8

class Post_Access_Checker implements Post_Access_Checker_Interface {

	/**
	 * The post type helper.
	 *
	 * @var Post_Type_Helper
	 */
	private $post_type_helper;

	/**
	 * The constructor.
	 *
	 * @param Post_Type_Helper $post_type_helper The post type helper.
	 */
	public function __construct( Post_Type_Helper $post_type_helper ) {
		$this->post_type_helper = $post_type_helper;
	}

	/**
	 * Whether the post exists.
	 *
	 * @param int $post_id The ID of the post.
	 *
	 * @return bool Whether the post exists.
	 */
	public function exists( int $post_id ): bool {
		return \get_post( $post_id ) !== null;
	}

	/**
	 * Whether the post is of an indexable post type.
	 *
	 * @param int $post_id The ID of the post.
	 *
	 * @return bool Whether the post is of an indexable post type.
	 */
	public function is_supported_type( int $post_id ): bool {
		$post = \get_post( $post_id );
		if ( $post === null ) {
			return false;
		}

		return $this->post_type_helper->is_of_indexable_post_type( $post->post_type );
	}

	/**
	 * Whether the current user is allowed to edit the post.
	 *
	 * @param int $post_id The ID of the post.
	 *
	 * @return bool Whether the current user is allowed to edit the post.
	 */
	public function can_edit( int $post_id ): bool {
		return \current_user_can( 'edit_post', $post_id );
	}
}