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 / posts / post-editability-resolver.php

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

58 lines 1.9 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\Posts;
5
6 use Yoast\WP\SEO\Bulk_Editor\Application\Updates\Post_Access_Checker_Interface;
7
8 /**
9 * Resolves, for a page of posts, whether the current user may edit each one.
10 *
11 * The database query narrows the candidates by post type, status and author (a sound approximation that
12 * keeps pagination cheap). This resolver then applies the exact per-post check, current_user_can(
13 * 'edit_post', $id ), so the collector can lock and blank the posts the update endpoint would refuse (for
14 * example a post that a plugin blocks for the current user through map_meta_cap). It runs on the page only,
15 * never the whole result set, so the cost stays bound to the page size.
16 */
17 class Post_Editability_Resolver {
18
19 /**
20 * The post access checker.
21 *
22 * @var Post_Access_Checker_Interface
23 */
24 private $post_access_checker;
25
26 /**
27 * The constructor.
28 *
29 * @param Post_Access_Checker_Interface $post_access_checker The post access checker.
30 */
31 public function __construct( Post_Access_Checker_Interface $post_access_checker ) {
32 $this->post_access_checker = $post_access_checker;
33 }
34
35 /**
36 * Returns, for each given post ID, whether the current user may edit it.
37 *
38 * @param array<int> $post_ids The post IDs on the current page.
39 *
40 * @return array<int, bool> A map of post ID to whether the current user may edit it.
41 */
42 public function resolve( array $post_ids ): array {
43 if ( $post_ids === [] ) {
44 return [];
45 }
46
47 // Prime the post cache once so the per-post edit check does not run a query per post.
48 \_prime_post_caches( $post_ids, false, false );
49
50 $editability = [];
51 foreach ( $post_ids as $post_id ) {
52 $editability[ $post_id ] = $this->post_access_checker->can_edit( $post_id );
53 }
54
55 return $editability;
56 }
57 }
58