-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathdeprecated.php
385 lines (350 loc) · 10.4 KB
/
deprecated.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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<?php
/**
* Deprecated functions.
*
* @package AMP
*/
use AmpProject\AmpWP\Services;
/**
* Load classes.
*
* @since 0.2
* @codeCoverageIgnore
* @deprecated As of 0.6 since autoloading is now employed.
* @internal
*/
function amp_load_classes() {
_deprecated_function( __FUNCTION__, '0.6' );
}
/**
* Conditionally add AMP actions or render the transitional mode template(s).
*
* If the request is for an AMP page and this is in 'canonical mode,' redirect to the non-AMP page.
* It won't need this plugin's template system, nor the frontend actions like the 'rel' link.
*
* @codeCoverageIgnore
* @deprecated This function is not used when 'amp' theme support is added.
* @global WP_Query $wp_query
* @since 0.2
* @return void
*/
function amp_maybe_add_actions() {
_deprecated_function( __FUNCTION__, '1.5' );
// Short-circuit when theme supports AMP, as everything is handled by AMP_Theme_Support.
if ( current_theme_supports( AMP_Theme_Support::SLUG ) ) {
return;
}
// The remaining logic here is for transitional mode running in themes that don't support AMP, the template system in AMP<=0.6.
global $wp_query;
if ( ! ( is_singular() || $wp_query->is_posts_page ) || is_feed() ) {
return;
}
$is_amp_request = amp_is_request();
/**
* Queried post object.
*
* @var WP_Post $post
*/
$post = get_queried_object();
if ( ! amp_is_post_supported( $post ) ) {
if ( $is_amp_request ) {
/*
* Temporary redirect is used for admin users because reader mode and AMP support can be enabled by user at any time,
* so they will be able to make AMP available for this URL and see the change without wrestling with the redirect cache.
*/
wp_safe_redirect( get_permalink( $post->ID ), current_user_can( 'manage_options' ) ? 302 : 301 );
exit;
}
return;
}
if ( $is_amp_request ) {
// Prevent infinite URL space under /amp/ endpoint.
global $wp;
$path_args = [];
wp_parse_str( $wp->matched_query, $path_args );
if ( isset( $path_args[ amp_get_slug() ] ) && '' !== $path_args[ amp_get_slug() ] ) {
wp_safe_redirect( amp_get_permalink( $post->ID ), 301 );
exit;
}
amp_prepare_render();
} else {
amp_add_frontend_actions();
}
}
/**
* Add post template actions.
*
* @since 0.2
* @codeCoverageIgnore
* @deprecated This function is not used when 'amp' theme support is added.
*/
function amp_add_post_template_actions() {
_deprecated_function( __FUNCTION__, '1.5' );
require_once AMP__DIR__ . '/includes/amp-post-template-functions.php';
amp_post_template_init_hooks();
}
/**
* Add action to do post template rendering at template_redirect action.
*
* @since 0.2
* @since 1.0 The amp_render() function is called at template_redirect action priority 11 instead of priority 10.
* @codeCoverageIgnore
* @deprecated This function is not used when 'amp' theme support is added.
*/
function amp_prepare_render() {
_deprecated_function( __FUNCTION__, '1.5' );
add_action( 'template_redirect', 'amp_render', 11 );
}
/**
* Render AMP for queried post.
*
* @since 0.1
* @codeCoverageIgnore
* @deprecated This function is not used when 'amp' theme support is added.
*/
function amp_render() {
_deprecated_function( __FUNCTION__, '1.5' );
// Note that queried object is used instead of the ID so that the_preview for the queried post can apply.
$post = get_queried_object();
if ( $post instanceof WP_Post ) {
amp_render_post( $post );
exit;
}
}
/**
* Render AMP post template.
*
* @since 0.5
* @codeCoverageIgnore
* @deprecated Rendering a post is now handled by AMP_Theme_Support.
*
* @param WP_Post|int $post Post.
* @global WP_Query $wp_query
*/
function amp_render_post( $post ) {
_deprecated_function( __FUNCTION__, '1.5' );
global $wp_query;
if ( ! ( $post instanceof WP_Post ) ) {
$post = get_post( $post );
if ( ! $post ) {
return;
}
}
$post_id = $post->ID;
/*
* If amp_render_post is called directly outside of the standard endpoint, amp_is_request() will return false,
* which is not ideal for any code that expects to run in an AMP context.
* Let's force the value to be true while we render AMP.
*/
$was_set = isset( $wp_query->query_vars[ amp_get_slug() ] );
if ( ! $was_set ) {
$wp_query->query_vars[ amp_get_slug() ] = true;
}
// Prevent New Relic from causing invalid AMP responses due the NREUM script it injects after the meta charset.
if ( extension_loaded( 'newrelic' ) ) {
newrelic_disable_autorum();
}
/**
* Fires before rendering a post in AMP.
*
* This action is not triggered when 'amp' theme support is present. Instead, you should use 'template_redirect' action and check if `amp_is_request()`.
*
* @since 0.2
* @deprecated Check amp_is_request() on the template_redirect action instead.
*
* @param int $post_id Post ID.
*/
do_action( 'pre_amp_render_post', $post_id );
amp_add_post_template_actions();
$template = new AMP_Post_Template( $post );
$template->load();
if ( ! $was_set ) {
unset( $wp_query->query_vars[ amp_get_slug() ] );
}
}
/**
* Print scripts.
*
* @codeCoverageIgnore
* @deprecated Scripts are now automatically added.
* @internal
* @see amp_register_default_scripts()
* @see amp_filter_script_loader_tag()
* @param AMP_Post_Template $amp_template Template.
*/
function amp_post_template_add_scripts( $amp_template ) {
_deprecated_function( __FUNCTION__, '1.5' );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo amp_render_scripts(
array_merge(
[
// Just in case the runtime has been overridden by amp_post_template_data filter.
'amp-runtime' => $amp_template->get( 'amp_runtime_script' ),
],
$amp_template->get( 'amp_component_scripts', [] )
)
);
}
/**
* Print boilerplate CSS.
*
* @codeCoverageIgnore
* @deprecated Boilerplate is now automatically added via the ampproject/amp-toolbox library.
* @internal
* @since 0.3
* @see amp_get_boilerplate_code()
*/
function amp_post_template_add_boilerplate_css() {
_deprecated_function( __FUNCTION__, '1.5' );
echo amp_get_boilerplate_code(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Print Schema.org metadata.
*
* @codeCoverageIgnore
* @deprecated Since 0.7
* @internal
*/
function amp_post_template_add_schemaorg_metadata() {
_deprecated_function( __FUNCTION__, '0.7', 'amp_print_schemaorg_metadata' );
amp_print_schemaorg_metadata();
}
/**
* Bootstrap AMP post meta box.
*
* This function must be invoked only once through the 'wp_loaded' action.
*
* @since 0.6
* @codeCoverageIgnore
* @deprecated Since 1.5.0, as admin class bootstrapping is moved to amp_bootstrap_admin().
* @internal
*/
function amp_post_meta_box() {
_deprecated_function( __FUNCTION__, '1.5.0' );
}
/**
* Bootstrap the AMP admin pointer class.
*
* @since 1.0
* @codeCoverageIgnore
* @deprecated Since 1.5.0, as admin class bootstrapping is moved to amp_bootstrap_admin().
* @internal
*/
function amp_admin_pointer() {
_deprecated_function( __FUNCTION__, '1.5.0' );
}
/**
* Print admin notice if the Xdebug extension is loaded.
*
* @since 1.3
* @deprecated 1.5.0 Warning moved to Site Health.
* @codeCoverageIgnore
* @internal
* @see AmpProject\AmpWP\Admin\SiteHealth::xdebug_extension()
*/
function _amp_xdebug_admin_notice() {
_deprecated_function( __FUNCTION__, '1.5.0' );
?>
<div class="notice notice-warning">
<p>
<?php
esc_html_e(
'Your server currently has the Xdebug PHP extension loaded. This can cause some of the AMP plugin\'s processes to timeout depending on your system resources and configuration. Please deactivate Xdebug for the best experience.',
'amp'
);
?>
</p>
</div>
<?php
}
/**
* Redirects the old AMP URL to the new AMP URL.
*
* If post slug is updated the amp page with old post slug will be redirected to the updated url.
*
* @since 0.5
* @internal
* @deprecated
*
* @param string $link New URL of the post.
* @return string URL to be redirected.
*/
function amp_redirect_old_slug_to_new_url( $link ) {
_deprecated_function( __FUNCTION__, '2.1' );
return Services::get( 'paired_routing' )->maybe_add_paired_endpoint( $link );
}
/**
* Fix up WP_Query for front page when amp query var is present.
*
* Normally the front page would not get served if a query var is present other than preview, page, paged, and cpage.
*
* @since 0.6
* @internal
* @see WP_Query::parse_query()
* @link https://github.com/WordPress/wordpress-develop/blob/0baa8ae85c670d338e78e408f8d6e301c6410c86/src/wp-includes/class-wp-query.php#L951-L971
* @deprecated
*
* @param WP_Query $query Query.
*/
function amp_correct_query_when_is_front_page( WP_Query $query ) {
_deprecated_function( __FUNCTION__, '2.1' );
Services::get( 'paired_routing' )->correct_query_when_is_front_page( $query );
}
/**
* Add frontend actions.
*
* @since 0.2
* @deprecated Since 2.1, moved to PairedRouting.
* @internal
*/
function amp_add_frontend_actions() {
_deprecated_function( __FUNCTION__, '2.1' );
add_action( 'wp_head', 'amp_add_amphtml_link' );
}
/**
* Add analytics scripts.
*
* @internal
* @deprecated 2.1 This is no longer necessary since amp-analytics is added automatically to the page during post-processing.
* @codeCoverageIgnore
*
* @param array $data Data.
* @return array Data.
*/
function amp_post_template_add_analytics_script( $data ) {
_deprecated_function( __FUNCTION__, '2.1' );
if ( ! empty( $data['amp_analytics'] ) ) {
$data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
}
return $data;
}
/**
* Determine whether the use of Bento components is enabled.
*
* When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation
* of the component framework.
*
* @since 2.2
* @link https://blog.amp.dev/2021/01/28/bento/
*
* @deprecated 2.5.0 Bento support has been removed.
* @codeCoverageIgnore
* @return bool Whether Bento components are enabled.
*/
function amp_is_bento_enabled() {
_deprecated_function( __FUNCTION__, 'AMP 2.5.0' );
/**
* Filters whether the use of Bento components is enabled.
*
* When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation
* of the component framework.
*
* @since 2.2
* @link https://blog.amp.dev/2021/01/28/bento/
*
* @deprecated 2.5.0 Bento support has been removed.
*
* @param bool $enabled Enabled.
*/
return apply_filters_deprecated( 'amp_bento_enabled', [ false ], 'AMP 2.5.0', 'Remove bento support', 'Bento support has been removed.' );
}