PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / 22.7.0
WPSSO Core – Complete Schema Markup and Meta Tags v22.7.0
22.7.0 22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
wpsso / lib / integ / seo / seoframework.php

seoframework.php in WPSSO Core – Complete Schema Markup and Meta Tags 22.7.0, at lib/integ/seo/seoframework.php

344 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * License: GPLv3
4 * License URI: https://www.gnu.org/licenses/gpl.txt
5 * Copyright 2012-2026 Jean-Sebastien Morisset (https://wpsso.com/)
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9
10 die( 'These aren\'t the droids you\'re looking for.' );
11 }
12
13 /*
14 * Integration module for the The SEO Framework plugin.
15 *
16 * See https://wordpress.org/plugins/autodescription/.
17 */
18 if ( ! class_exists( 'WpssoIntegSeoSeoframework' ) ) {
19
20 class WpssoIntegSeoSeoframework {
21
22 private $p; // Wpsso class object.
23
24 private $is_admin = false;
25
26 public function __construct( &$plugin ) {
27
28 $this->p =& $plugin;
29
30 if ( $this->p->debug->enabled ) {
31
32 $this->p->debug->mark();
33 }
34
35 $this->is_admin = is_admin();
36
37 $this->p->util->add_plugin_filters( $this, array(
38 'redirect_disabled' => '__return_true',
39 'primary_term_id' => 4,
40 'title_seed' => 5,
41 'description_seed' => 4,
42 'post_url' => 2,
43 'redirect_url' => 3,
44 ), 100 );
45
46 add_filter( 'the_seo_framework_current_object_id', array( $this, 'current_object_id' ), 10, 1 );
47 add_filter( 'the_seo_framework_json_search_output', '__return_false', PHP_INT_MAX );
48 add_filter( 'the_seo_framework_ldjson_plugin_detected', '__return_false', PHP_INT_MAX );
49 add_filter( 'the_seo_framework_ldjson_scripts', '__return_empty_string', PHP_INT_MAX );
50
51 if ( $this->is_admin ) {
52
53 add_action( 'current_screen', array( $this, 'cleanup_seoframework_edit_view' ), PHP_INT_MIN, 1 );
54
55 add_filter( 'the_seo_framework_inpost_settings_tabs', array( $this, 'cleanup_seoframework_tabs' ), 1000, 1 );
56 }
57 }
58
59 public function filter_primary_term_id( $primary_term_id, $mod, $tax_slug, $is_custom ) {
60
61 if ( $this->p->debug->enabled ) {
62
63 $this->p->debug->mark();
64 }
65
66 if ( $is_custom ) {
67
68 if ( $this->p->debug->enabled ) {
69
70 $this->p->debug->log( 'exiting early: $is_custom is true' );
71 }
72
73 return $primary_term_id;
74
75 } elseif ( empty( $mod[ 'is_post' ] ) || empty( $mod[ 'id' ] ) ) {
76
77 if ( $this->p->debug->enabled ) {
78
79 $this->p->debug->log( 'exiting early: not post object or no post ID' );
80 }
81
82 return $primary_term_id;
83
84 } elseif ( empty( $tax_slug ) ) {
85
86 if ( $this->p->debug->enabled ) {
87
88 $this->p->debug->log( 'exiting early: $tax_slug is empty' );
89 }
90
91 return $primary_term_id;
92
93 } else {
94
95 if ( $this->is_admin ) {
96
97 SucomUtilWP::maybe_load_post( $mod[ 'id' ] ); // Maybe re-define the $post global.
98 }
99
100 $tsf = the_seo_framework();
101
102 if ( version_compare( THE_SEO_FRAMEWORK_VERSION, '5.0.0', '>=' ) ) {
103
104 $ret = $tsf->data()->plugin()->post()->get_primary_term_id( $mod[ 'id' ], $tax_slug );
105
106 } else $tsf->get_primary_term_id( $mod[ 'id' ], $tax_slug );
107
108 if ( $ret ) return $ret;
109 }
110
111 return $primary_term_id;
112 }
113
114 public function filter_title_seed( $title_text, $mod, $num_hashtags, $md_key, $title_sep ) {
115
116 if ( $this->p->debug->enabled ) {
117
118 $this->p->debug->mark();
119 }
120
121 if ( $mod[ 'is_post' ] && $mod[ 'id' ] && $this->is_admin ) {
122
123 SucomUtilWP::maybe_load_post( $mod[ 'id' ] ); // Maybe re-define the $post global.
124 }
125
126 /*
127 * The SEO Framework can only provide titles and descriptions by ID for posts and terms.
128 *
129 * Important note:
130 *
131 * $tsf->get_title() uses '$social = true' as a third argument.
132 *
133 * $tsf->get_description() uses 'social => true' in the $args array.
134 */
135 $args = false;
136
137 switch ( $mod[ 'name' ] ) {
138
139 case 'post':
140
141 $args = array(
142 'id' => $mod[ 'id' ],
143 'pta' => $mod[ 'is_post_type_archive' ] ? $mod[ 'post_type' ] : '',
144 );
145
146 break;
147
148 case 'term':
149
150 $args = array(
151 'id' => $mod[ 'id' ],
152 'taxonomy' => $mod[ 'tax_slug' ],
153 );
154
155 break;
156 }
157
158 if ( ! empty( $args ) ) {
159
160 $tsf = the_seo_framework();
161
162 $title_text = $tsf->get_title( $args, $escape = false, $social = true );
163
164 if ( $this->p->debug->enabled ) {
165
166 $this->p->debug->log( 'seo framework title: ' . $title_text );
167 }
168 }
169
170 return $title_text;
171 }
172
173 public function filter_description_seed( $desc_text, $mod, $num_hashtags, $md_key ) {
174
175 if ( $this->p->debug->enabled ) {
176
177 $this->p->debug->mark();
178 }
179
180 if ( $mod[ 'is_post' ] && $this->is_admin ) {
181
182 SucomUtilWP::maybe_load_post( $mod[ 'id' ] ); // Maybe re-define the $post global.
183 }
184
185 /*
186 * The SEO Framework can only provide titles and descriptions by ID for posts and terms.
187 *
188 * Important note:
189 *
190 * $tsf->get_title() uses '$social = true' as a third argument.
191 *
192 * $tsf->get_description() uses 'social => true' in the $args array.
193 */
194 $args = false;
195
196 switch ( $mod[ 'name' ] ) {
197
198 case 'post':
199
200 $args = array(
201 'id' => $mod[ 'id' ],
202 'pta' => $mod[ 'is_post_type_archive' ] ? $mod[ 'post_type' ] : '',
203 'social' => true,
204 );
205
206 break;
207
208 case 'term':
209
210 $args = array(
211 'id' => $mod[ 'id' ],
212 'taxonomy' => $mod[ 'tax_slug' ],
213 'social' => true,
214 );
215
216 break;
217 }
218
219 if ( ! empty( $args ) ) {
220
221 $tsf = the_seo_framework();
222
223 $desc_text = $tsf->get_description( $args, $escape = false );
224
225 if ( $this->p->debug->enabled ) {
226
227 $this->p->debug->log( 'seo framework description: ' . $desc_text );
228 }
229 }
230
231 return $desc_text;
232 }
233
234 public function filter_post_url( $url, $mod ) {
235
236 if ( $this->p->debug->enabled ) {
237
238 $this->p->debug->mark();
239 }
240
241 if ( $mod[ 'is_post' ] && $this->is_admin ) {
242
243 SucomUtilWP::maybe_load_post( $mod[ 'id' ] ); // Maybe re-define the $post global.
244 }
245
246 $tsf = the_seo_framework();
247
248 $args = array(
249 'id' => $mod[ 'id' ],
250 'taxonomy' => $mod[ 'is_term' ] ? $mod[ 'tax_slug' ] : '',
251 'pta' => $mod[ 'is_post_type_archive' ] ? $mod[ 'post_type' ] : '',
252 );
253
254 $url = version_compare( THE_SEO_FRAMEWORK_VERSION, '5.0.0', '>=' ) ?
255 $tsf->uri()->get_canonical_url( $args ) :
256 $tsf->get_canonical_url( $args );
257
258 if ( $this->p->debug->enabled ) {
259
260 $this->p->debug->log( 'seo framework post_url: ' . $url );
261 }
262
263 return $url;
264 }
265
266 public function filter_redirect_url( $url, $mod, $is_custom ) {
267
268 if ( $this->p->debug->enabled ) {
269
270 $this->p->debug->mark();
271 }
272
273 if ( $mod[ 'is_post' ] && $this->is_admin ) {
274
275 SucomUtilWP::maybe_load_post( $mod[ 'id' ] ); // Maybe re-define the $post global.
276 }
277
278 $tsf = the_seo_framework();
279
280 $args = array(
281 'id' => $mod[ 'id' ],
282 'taxonomy' => $mod[ 'is_term' ] ? $mod[ 'tax_slug' ] : '',
283 'pta' => $mod[ 'is_post_type_archive' ] ? $mod[ 'post_type' ] : '',
284 );
285
286 $url = version_compare( THE_SEO_FRAMEWORK_VERSION, '5.0.0', '>=' ) ?
287 $tsf->uri()->get_redirect_url( $args ) :
288 $tsf->get_redirect_url( $args );
289
290 if ( $this->p->debug->enabled ) {
291
292 $this->p->debug->log( 'seo framework post_url: ' . $url );
293 }
294
295 return $url;
296 }
297
298 public function current_object_id( $obj_id ) {
299
300 if ( $this->p->debug->enabled ) {
301
302 $this->p->debug->mark();
303 }
304
305 if ( empty( $obj_id ) ) {
306
307 if ( $this->p->debug->enabled ) {
308
309 $this->p->debug->log( 'required call to WpssoPage->get_mod()' );
310 }
311
312 /*
313 * Note that in_the_loop() can be true in both archive and singular pages.
314 */
315 $use_post = apply_filters( 'wpsso_use_post', in_the_loop() ? true : false );
316
317 $mod = $this->p->page->get_mod( $use_post );
318
319 $obj_id = $mod[ 'id' ];
320 }
321
322 return $obj_id;
323 }
324
325 /*
326 * Remove the "Authorial Info" section from the user editing page.
327 */
328 public function cleanup_seoframework_edit_view( $screen ) {
329
330 if ( in_array( $screen->base, array( 'profile', 'user-edit' ) ) ) {
331
332 SucomUtilWP::remove_filter_hook_name( 'current_screen', 'The_SEO_Framework\Load::_init_user_edit_view' );
333 }
334 }
335
336 public function cleanup_seoframework_tabs( $tabs ) {
337
338 unset( $tabs[ 'social' ] );
339
340 return $tabs;
341 }
342 }
343 }
344