C:\xampp\htdocs\landing\wp-content\plugins\wordpress-seo\src\routes\yoast-head-rest-field.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php

namespace Yoast\WP\SEO\Routes;

use 
Yoast\WP\SEO\Actions\Indexables\Indexable_Head_Action;
use 
Yoast\WP\SEO\Conditionals\Headless_Rest_Endpoints_Enabled_Conditional;
use 
Yoast\WP\SEO\Helpers\Post_Helper;
use 
Yoast\WP\SEO\Helpers\Post_Type_Helper;
use 
Yoast\WP\SEO\Helpers\Taxonomy_Helper;

/**
 * Yoast_Head_REST_Field class.
 *
 * Registers the yoast head REST field.
 * Not technically a route but behaves the same so is included here.
 */
class Yoast_Head_REST_Field implements Route_Interface {

    
/**
     * The name of the yoast head field.
     *
     * @var string
     */
    
const YOAST_HEAD_FIELD_NAME 'yoast_head';

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

    
/**
     * The taxonomy helper.
     *
     * @var Taxonomy_Helper
     */
    
protected $taxonomy_helper;

    
/**
     * The post helper.
     *
     * @var Post_Helper
     */
    
protected $post_helper;

    
/**
     * The head action.
     *
     * @var Indexable_Head_Action
     */
    
protected $head_action;

    
/**
     * Returns the conditionals based in which this loadable should be active.
     *
     * @return array
     */
    
public static function get_conditionals() {
        return [ 
Headless_Rest_Endpoints_Enabled_Conditional::class ];
    }

    
/**
     * Yoast_Head_REST_Field constructor.
     *
     * @param Post_Type_Helper      $post_type_helper The post type helper.
     * @param Taxonomy_Helper       $taxonomy_helper  The taxonomy helper.
     * @param Post_Helper           $post_helper      The post helper.
     * @param Indexable_Head_Action $head_action      The head action.
     */
    
public function __construct(
        
Post_Type_Helper $post_type_helper,
        
Taxonomy_Helper $taxonomy_helper,
        
Post_Helper $post_helper,
        
Indexable_Head_Action $head_action
    
) {
        
$this->post_type_helper $post_type_helper;
        
$this->taxonomy_helper  $taxonomy_helper;
        
$this->post_helper      $post_helper;
        
$this->head_action      $head_action;
    }

    
/**
     * Registers routes with WordPress.
     *
     * @return void
     */
    
public function register_routes() {
        
$public_post_types $this->post_type_helper->get_public_post_types();

        foreach ( 
$public_post_types as $post_type ) {
            \
register_rest_field$post_typeself::YOAST_HEAD_FIELD_NAME, [ 'get_callback' => [ $this'for_post' ] ] );
        }

        
$public_taxonomies $this->taxonomy_helper->get_public_taxonomies();

        foreach ( 
$public_taxonomies as $taxonomy ) {
            if ( 
$taxonomy === 'post_tag' ) {
                
$taxonomy 'tag';
            }
            \
register_rest_field$taxonomyself::YOAST_HEAD_FIELD_NAME, [ 'get_callback' => [ $this'for_term' ] ] );
        }

        \
register_rest_field'user'self::YOAST_HEAD_FIELD_NAME, [ 'get_callback' => [ $this'for_author' ] ] );

        \
register_rest_field'type'self::YOAST_HEAD_FIELD_NAME, [ 'get_callback' => [ $this'for_post_type_archive' ] ] );
    }

    
/**
     * Returns the head for a post.
     *
     * @param array $params The rest request params.
     *
     * @return string The head.
     */
    
public function for_post$params ) {
        if ( ! isset( 
$params['id'] ) ) {
            return 
null;
        }

        if ( ! 
$this->post_helper->is_post_indexable$params['id'] ) ) {
            return 
null;
        }
        
$obj $this->head_action->for_post$params['id'] );

        if ( 
$obj->status === 404 ) {
            return 
null;
        }

        return 
$obj->head;
    }

    
/**
     * Returns the head for a term.
     *
     * @param array $params The rest request params.
     *
     * @return string The head.
     */
    
public function for_term$params ) {
        
$obj $this->head_action->for_term$params['id'] );

        if ( 
$obj->status === 404 ) {
            return 
null;
        }

        return 
$obj->head;
    }

    
/**
     * Returns the head for an author.
     *
     * @param array $params The rest request params.
     *
     * @return string The head.
     */
    
public function for_author$params ) {
        
$obj $this->head_action->for_author$params['id'] );

        if ( 
$obj->status === 404 ) {
            return 
null;
        }

        return 
$obj->head;
    }

    
/**
     * Returns the head for a post type archive.
     *
     * @param array $params The rest request params.
     *
     * @return string The head.
     */
    
public function for_post_type_archive$params ) {
        if ( 
$params['slug'] === 'post' ) {
            
$obj $this->head_action->for_posts_page();
        }
        elseif ( ! 
$this->post_type_helper->has_archive$params['slug'] ) ) {
            return 
null;
        }
        else {
            
$obj $this->head_action->for_post_type_archive$params['slug'] );
        }

        if ( 
$obj->status === 404 ) {
            return 
null;
        }

        return 
$obj->head;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586