frontend.php
7.49 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
/**
* Backwards compatibility class for WPSEO_Frontend.
*
* @package Yoast\YoastSEO\Backwards_Compatibility
*/
use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
use Yoast\WP\SEO\Presenters\Canonical_Presenter;
use Yoast\WP\SEO\Presenters\Meta_Description_Presenter;
use Yoast\WP\SEO\Presenters\Rel_Next_Presenter;
use Yoast\WP\SEO\Presenters\Rel_Prev_Presenter;
use Yoast\WP\SEO\Presenters\Robots_Presenter;
use Yoast\WP\SEO\Surfaces\Helpers_Surface;
/**
* Class WPSEO_Frontend
*
* @codeCoverageIgnore Because of deprecation.
*/
class WPSEO_Frontend {
/**
* Instance of this class.
*
* @var WPSEO_Frontend
*/
public static $instance;
/**
* The memoizer for the meta tags context.
*
* @var Meta_Tags_Context_Memoizer
*/
private $context_memoizer;
/**
* The WPSEO Replace Vars object.
*
* @var WPSEO_Replace_Vars
*/
private $replace_vars;
/**
* The helpers surface.
*
* @var Helpers_Surface
*/
private $helpers;
/**
* WPSEO_Frontend constructor.
*/
public function __construct() {
$this->context_memoizer = YoastSEO()->classes->get( Meta_Tags_Context_Memoizer::class );
$this->replace_vars = YoastSEO()->classes->get( WPSEO_Replace_Vars::class );
$this->helpers = YoastSEO()->classes->get( Helpers_Surface::class );
}
/**
* Catches call to methods that don't exist and might deprecated.
*
* @param string $method The called method.
* @param array $arguments The given arguments.
*
* @return mixed
*/
public function __call( $method, $arguments ) {
_deprecated_function( $method, 'Yoast SEO 14.0' );
$title_methods = [
'title',
'fix_woo_title',
'get_content_title',
'get_seo_title',
'get_taxonomy_title',
'get_author_title',
'get_title_from_options',
'get_default_title',
'force_wp_title',
];
if ( in_array( $method, $title_methods, true ) ) {
return $this->get_title();
}
return null;
}
/**
* Retrieves an instance of the class.
*
* @return static The instance.
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Outputs the canonical value.
*
* @param bool $echo Whether or not to output the canonical element.
* @param bool $un_paged Whether or not to return the canonical with or without pagination added to the URL.
* @param bool $no_override Whether or not to return a manually overridden canonical.
*
* @return string|void
*/
public function canonical( $echo = true, $un_paged = false, $no_override = false ) {
_deprecated_function( __METHOD__, 'Yoast SEO 14.0' );
$presentation = $this->get_current_page_presentation();
$presenter = new Canonical_Presenter();
/** This filter is documented in src/integrations/front-end-integration.php */
$presenter->presentation = $presentation;
$presenter->helpers = $this->helpers;
$presenter->replace_vars = $this->replace_vars;
if ( ! $echo ) {
return $presenter->get();
}
echo $presenter->present();
}
/**
* Retrieves the meta robots value.
*
* @return string
*/
public function get_robots() {
_deprecated_function( __METHOD__, 'Yoast SEO 14.0' );
$presentation = $this->get_current_page_presentation();
return $presentation->robots;
}
/**
* Outputs the meta robots value.
*/
public function robots() {
_deprecated_function( __METHOD__, 'Yoast SEO 14.0' );
$presentation = $this->get_current_page_presentation();
$presenter = new Robots_Presenter();
$presenter->presentation = $presentation;
$presenter->helpers = $this->helpers;
$presenter->replace_vars = $this->replace_vars;
echo $presenter->present();
}
/**
* Determine $robots values for a single post.
*
* @param array $robots Robots data array.
* @param int $post_id The post ID for which to determine the $robots values, defaults to current post.
*
* @return array
*/
public function robots_for_single_post( $robots, $post_id = 0 ) {
_deprecated_function( __METHOD__, 'Yoast SEO 14.0' );
$presentation = $this->get_current_page_presentation();
return $presentation->robots;
}
/**
* Used for static home and posts pages as well as singular titles.
*
* @param object|null $object If filled, object to get the title for.
*
* @return string The content title.
*/
private function get_title( $object = null ) {
_deprecated_function( __METHOD__, 'Yoast SEO 14.0' );
$presentation = $this->get_current_page_presentation();
$title = $presentation->title;
return $this->replace_vars->replace( $title, $presentation->source );
}
/**
* This function adds paging details to the title.
*
* @param string $sep Separator used in the title.
* @param string $seplocation Whether the separator should be left or right.
* @param string $title The title to append the paging info to.
*
* @return string
*/
public function add_paging_to_title( $sep, $seplocation, $title ) {
_deprecated_function( __METHOD__, 'Yoast SEO 14.0' );
return $title;
}
/**
* Add part to title, while ensuring that the $seplocation variable is respected.
*
* @param string $sep Separator used in the title.
* @param string $seplocation Whether the separator should be left or right.
* @param string $title The title to append the title_part to.
* @param string $title_part The part to append to the title.
*
* @return string
*/
public function add_to_title( $sep, $seplocation, $title, $title_part ) {
_deprecated_function( __METHOD__, 'Yoast SEO 14.0' );
if ( $seplocation === 'right' ) {
return $title . $sep . $title_part;
}
return $title_part . $sep . $title;
}
/**
* Adds 'prev' and 'next' links to archives.
*
* @link http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
*/
public function adjacent_rel_links() {
_deprecated_function( __METHOD__, 'Yoast SEO 14.0' );
$presentation = $this->get_current_page_presentation();
$rel_prev_presenter = new Rel_Prev_Presenter();
$rel_prev_presenter->presentation = $presentation;
$rel_prev_presenter->helpers = $this->helpers;
$rel_prev_presenter->replace_vars = $this->replace_vars;
echo $rel_prev_presenter->present();
$rel_next_presenter = new Rel_Next_Presenter();
$rel_next_presenter->presentation = $presentation;
$rel_next_presenter->helpers = $this->helpers;
$rel_next_presenter->replace_vars = $this->replace_vars;
echo $rel_next_presenter->present();
}
/**
* Outputs the meta description element or returns the description text.
*
* @param bool $echo Echo or return output flag.
*
* @return string
*/
public function metadesc( $echo = true ) {
_deprecated_function( __METHOD__, 'Yoast SEO 14.0' );
$presentation = $this->get_current_page_presentation();
$presenter = new Meta_Description_Presenter();
$presenter->presentation = $presentation;
$presenter->helpers = $this->helpers;
$presenter->replace_vars = $this->replace_vars;
if ( ! $echo ) {
return $presenter->get();
}
$presenter->present();
}
/**
* Returns the current page presentation.
*
* @return Indexable_Presentation The current page presentation.
*/
private function get_current_page_presentation() {
$context = $this->context_memoizer->for_current_page();
/** This filter is documented in src/integrations/front-end-integration.php */
return apply_filters( 'wpseo_frontend_presentation', $context->presentation, $context );
}
}