PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / bulk-editor / infrastructure / updates / post-access-checker.php

post-access-checker.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/bulk-editor/infrastructure/updates/post-access-checker.php

68 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Bulk_Editor\Infrastructure\Updates;
5
6 use Yoast\WP\SEO\Bulk_Editor\Application\Updates\Post_Access_Checker_Interface;
7 use Yoast\WP\SEO\Helpers\Post_Type_Helper;
8
9 /**
10 * Checks post access through the WordPress APIs.
11 */
12 class Post_Access_Checker implements Post_Access_Checker_Interface {
13
14 /**
15 * The post type helper.
16 *
17 * @var Post_Type_Helper
18 */
19 private $post_type_helper;
20
21 /**
22 * The constructor.
23 *
24 * @param Post_Type_Helper $post_type_helper The post type helper.
25 */
26 public function __construct( Post_Type_Helper $post_type_helper ) {
27 $this->post_type_helper = $post_type_helper;
28 }
29
30 /**
31 * Whether the post exists.
32 *
33 * @param int $post_id The ID of the post.
34 *
35 * @return bool Whether the post exists.
36 */
37 public function exists( int $post_id ): bool {
38 return \get_post( $post_id ) !== null;
39 }
40
41 /**
42 * Whether the post is of an indexable post type.
43 *
44 * @param int $post_id The ID of the post.
45 *
46 * @return bool Whether the post is of an indexable post type.
47 */
48 public function is_supported_type( int $post_id ): bool {
49 $post = \get_post( $post_id );
50 if ( $post === null ) {
51 return false;
52 }
53
54 return $this->post_type_helper->is_of_indexable_post_type( $post->post_type );
55 }
56
57 /**
58 * Whether the current user is allowed to edit the post.
59 *
60 * @param int $post_id The ID of the post.
61 *
62 * @return bool Whether the current user is allowed to edit the post.
63 */
64 public function can_edit( int $post_id ): bool {
65 return \current_user_can( 'edit_post', $post_id );
66 }
67 }
68