PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.6
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 / deprecated / frontend / frontend.php

frontend.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.6, at src/deprecated/frontend/frontend.php

277 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Backwards compatibility class for WPSEO_Frontend.
4 *
5 * @package Yoast\YoastSEO\Backwards_Compatibility
6 */
7
8 use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
9 use Yoast\WP\SEO\Presenters\Canonical_Presenter;
10 use Yoast\WP\SEO\Presenters\Meta_Description_Presenter;
11 use Yoast\WP\SEO\Presenters\Rel_Next_Presenter;
12 use Yoast\WP\SEO\Presenters\Rel_Prev_Presenter;
13 use Yoast\WP\SEO\Presenters\Robots_Presenter;
14 use Yoast\WP\SEO\Surfaces\Helpers_Surface;
15
16 /**
17 * Class WPSEO_Frontend
18 *
19 * @codeCoverageIgnore Because of deprecation.
20 */
21 class WPSEO_Frontend {
22
23 /**
24 * Instance of this class.
25 *
26 * @var WPSEO_Frontend
27 */
28 public static $instance;
29
30 /**
31 * The memoizer for the meta tags context.
32 *
33 * @var Meta_Tags_Context_Memoizer
34 */
35 private $context_memoizer;
36
37 /**
38 * The WPSEO Replace Vars object.
39 *
40 * @var WPSEO_Replace_Vars
41 */
42 private $replace_vars;
43
44 /**
45 * The helpers surface.
46 *
47 * @var Helpers_Surface
48 */
49 private $helpers;
50
51 /**
52 * WPSEO_Frontend constructor.
53 */
54 public function __construct() {
55 $this->context_memoizer = YoastSEO()->classes->get( Meta_Tags_Context_Memoizer::class );
56 $this->replace_vars = YoastSEO()->classes->get( WPSEO_Replace_Vars::class );
57 $this->helpers = YoastSEO()->classes->get( Helpers_Surface::class );
58 }
59
60 /**
61 * Catches call to methods that don't exist and might deprecated.
62 *
63 * @param string $method The called method.
64 * @param array $arguments The given arguments.
65 *
66 * @return mixed
67 */
68 public function __call( $method, $arguments ) {
69 _deprecated_function( $method, 'WPSEO 14.0' );
70
71 $title_methods = [
72 'title',
73 'fix_woo_title',
74 'get_content_title',
75 'get_seo_title',
76 'get_taxonomy_title',
77 'get_author_title',
78 'get_title_from_options',
79 'get_default_title',
80 'force_wp_title',
81 ];
82 if ( in_array( $method, $title_methods, true ) ) {
83 return $this->get_title();
84 }
85
86 return null;
87 }
88
89 /**
90 * Retrieves an instance of the class.
91 *
92 * @return static The instance.
93 */
94 public static function get_instance() {
95 if ( is_null( self::$instance ) ) {
96 self::$instance = new self();
97 }
98
99 return self::$instance;
100 }
101
102 /**
103 * Outputs the canonical value.
104 *
105 * @param bool $echo Whether or not to output the canonical element.
106 * @param bool $un_paged Whether or not to return the canonical with or without pagination added to the URL.
107 * @param bool $no_override Whether or not to return a manually overridden canonical.
108 *
109 * @return string|void
110 */
111 public function canonical( $echo = true, $un_paged = false, $no_override = false ) {
112 _deprecated_function( __METHOD__, 'WPSEO 14.0' );
113
114 $presentation = $this->get_current_page_presentation();
115 $presenter = new Canonical_Presenter();
116 /** This filter is documented in src/integrations/front-end-integration.php */
117 $presenter->presentation = $presentation;
118 $presenter->helpers = $this->helpers;
119 $presenter->replace_vars = $this->replace_vars;
120
121 if ( ! $echo ) {
122 return $presenter->get();
123 }
124
125 echo $presenter->present();
126 }
127
128 /**
129 * Retrieves the meta robots value.
130 *
131 * @return string
132 */
133 public function get_robots() {
134 _deprecated_function( __METHOD__, 'WPSEO 14.0' );
135
136 $presentation = $this->get_current_page_presentation();
137 return $presentation->robots;
138 }
139
140 /**
141 * Outputs the meta robots value.
142 */
143 public function robots() {
144 _deprecated_function( __METHOD__, 'WPSEO 14.0' );
145
146 $presentation = $this->get_current_page_presentation();
147 $presenter = new Robots_Presenter();
148 $presenter->presentation = $presentation;
149 $presenter->helpers = $this->helpers;
150 $presenter->replace_vars = $this->replace_vars;
151 echo $presenter->present();
152 }
153
154 /**
155 * Determine $robots values for a single post.
156 *
157 * @param array $robots Robots data array.
158 * @param int $post_id The post ID for which to determine the $robots values, defaults to current post.
159 *
160 * @return array
161 */
162 public function robots_for_single_post( $robots, $post_id = 0 ) {
163 _deprecated_function( __METHOD__, 'WPSEO 14.0' );
164
165 $presentation = $this->get_current_page_presentation();
166
167 return $presentation->robots;
168 }
169
170 /**
171 * Used for static home and posts pages as well as singular titles.
172 *
173 * @param object|null $object If filled, object to get the title for.
174 *
175 * @return string The content title.
176 */
177 private function get_title( $object = null ) {
178 _deprecated_function( __METHOD__, 'WPSEO 14.0' );
179
180 $presentation = $this->get_current_page_presentation();
181 $title = $presentation->title;
182
183 return $this->replace_vars->replace( $title, $presentation->source );
184 }
185
186 /**
187 * This function adds paging details to the title.
188 *
189 * @param string $sep Separator used in the title.
190 * @param string $seplocation Whether the separator should be left or right.
191 * @param string $title The title to append the paging info to.
192 *
193 * @return string
194 */
195 public function add_paging_to_title( $sep, $seplocation, $title ) {
196 _deprecated_function( __METHOD__, 'WPSEO 14.0' );
197
198 return $title;
199 }
200
201 /**
202 * Add part to title, while ensuring that the $seplocation variable is respected.
203 *
204 * @param string $sep Separator used in the title.
205 * @param string $seplocation Whether the separator should be left or right.
206 * @param string $title The title to append the title_part to.
207 * @param string $title_part The part to append to the title.
208 *
209 * @return string
210 */
211 public function add_to_title( $sep, $seplocation, $title, $title_part ) {
212 _deprecated_function( __METHOD__, 'WPSEO 14.0' );
213
214 if ( $seplocation === 'right' ) {
215 return $title . $sep . $title_part;
216 }
217
218 return $title_part . $sep . $title;
219 }
220
221 /**
222 * Adds 'prev' and 'next' links to archives.
223 *
224 * @link http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
225 */
226 public function adjacent_rel_links() {
227 _deprecated_function( __METHOD__, 'WPSEO 14.0' );
228
229 $presentation = $this->get_current_page_presentation();
230
231 $rel_prev_presenter = new Rel_Prev_Presenter();
232 $rel_prev_presenter->presentation = $presentation;
233 $rel_prev_presenter->helpers = $this->helpers;
234 $rel_prev_presenter->replace_vars = $this->replace_vars;
235 echo $rel_prev_presenter->present();
236
237 $rel_next_presenter = new Rel_Next_Presenter();
238 $rel_next_presenter->presentation = $presentation;
239 $rel_next_presenter->helpers = $this->helpers;
240 $rel_next_presenter->replace_vars = $this->replace_vars;
241 echo $rel_next_presenter->present();
242 }
243
244 /**
245 * Outputs the meta description element or returns the description text.
246 *
247 * @param bool $echo Echo or return output flag.
248 *
249 * @return string
250 */
251 public function metadesc( $echo = true ) {
252 _deprecated_function( __METHOD__, 'WPSEO 14.0' );
253
254 $presentation = $this->get_current_page_presentation();
255 $presenter = new Meta_Description_Presenter();
256 $presenter->presentation = $presentation;
257 $presenter->helpers = $this->helpers;
258 $presenter->replace_vars = $this->replace_vars;
259
260 if ( ! $echo ) {
261 return $presenter->get();
262 }
263 $presenter->present();
264 }
265
266 /**
267 * Returns the current page presentation.
268 *
269 * @return Indexable_Presentation The current page presentation.
270 */
271 private function get_current_page_presentation() {
272 $context = $this->context_memoizer->for_current_page();
273 /** This filter is documented in src/integrations/front-end-integration.php */
274 return apply_filters( 'wpseo_frontend_presentation', $context->presentation, $context );
275 }
276 }
277