• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 3953764123d71d76729b2ec7e7f5816cbab76e29

05 Dec 2025 02:42PM UTC coverage: 53.045% (-3.5%) from 56.559%
3953764123d71d76729b2ec7e7f5816cbab76e29

push

github

enricobattocchi
Merge branch 'release/26.6' into trunk

8706 of 16073 branches covered (54.17%)

Branch coverage included in aggregate %.

0 of 9 new or added lines in 4 files covered. (0.0%)

1 existing line in 1 file now uncovered.

32426 of 61468 relevant lines covered (52.75%)

46909.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/routes/meta-search-route.php
1
<?php
2

3
namespace Yoast\WP\SEO\Routes;
4

5
use WP_REST_Request;
6
use WP_REST_Response;
7
use Yoast\WP\SEO\Conditionals\No_Conditionals;
8
use Yoast\WP\SEO\Main;
9

10
/**
11
 * Meta_Search_Route class
12
 */
13
class Meta_Search_Route implements Route_Interface {
14

15
        use No_Conditionals;
16

17
        /**
18
         * Represents meta search route.
19
         *
20
         * @var string
21
         */
22
        public const META_SEARCH_ROUTE = '/meta/search';
23

24
        /**
25
         * Registers routes with WordPress.
26
         *
27
         * @return void
28
         */
29
        public function register_routes() {
×
30
                $route = [
×
31
                        [
×
32
                                'methods'             => 'GET',
×
33
                                'callback'            => [ $this, 'search_meta' ],
×
34
                                'permission_callback' => [ $this, 'permission_check' ],
×
35
                        ],
×
36
                ];
×
37

38
                \register_rest_route( Main::API_V1_NAMESPACE, self::META_SEARCH_ROUTE, $route );
×
39
        }
40

41
        /**
42
         * Performs the permission check.
43
         *
44
         * @param WP_REST_Request $request The request.
45
         *
46
         * @return bool
47
         */
48
        public function permission_check( $request ) {
×
49
                if ( ! isset( $request['post_id'] ) ) {
×
50
                        return false;
×
51
                }
52

53
                $post_type        = \get_post_type( $request['post_id'] );
×
54
                $post_type_object = \get_post_type_object( $post_type );
×
55

NEW
56
                return \current_user_can( $post_type_object->cap->edit_post, $request['post_id'] );
×
57
        }
58

59
        /**
60
         * Searches meta fields of a given post.
61
         *
62
         * @param WP_REST_Request $request The REST request.
63
         *
64
         * @return WP_REST_Response
65
         */
66
        public function search_meta( $request ) {
×
67
                $post_id = $request['post_id'];
×
68
                $query   = $request['query'];
×
69
                $meta    = \get_post_custom( $post_id );
×
70
                $matches = [];
×
71

72
                foreach ( $meta as $key => $values ) {
×
73
                        if ( \substr( $key, 0, \strlen( $query ) ) !== $query ) {
×
74
                                continue;
×
75
                        }
76

77
                        if ( empty( $query ) && \substr( $key, 0, 1 ) === '_' ) {
×
78
                                continue;
×
79
                        }
80

81
                        // Skip custom field values that are serialized.
82
                        if ( \is_serialized( $values[0] ) ) {
×
83
                                continue;
×
84
                        }
85

86
                        $matches[] = [
×
87
                                'key'   => $key,
×
88
                                'value' => $values[0],
×
89
                        ];
×
90

91
                        if ( \count( $matches ) >= 25 ) {
×
92
                                break;
×
93
                        }
94
                }
95

96
                return \rest_ensure_response( [ 'meta' => $matches ] );
×
97
        }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc