You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @deprecated This function is not used when 'amp' theme support is added.
334
346
*/
335
347
functionamp_render() {
336
348
// Note that queried object is used instead of the ID so that the_preview for the queried post can apply.
@@ -345,6 +357,8 @@ function amp_render() {
345
357
* Render AMP post template.
346
358
*
347
359
* @since 0.5
360
+
* @deprecated This function is not used when 'amp' theme support is added.
361
+
*
348
362
* @param WP_Post|int $post Post.
349
363
* @global WP_Query $wp_query
350
364
*/
@@ -377,6 +391,8 @@ function amp_render_post( $post ) {
377
391
/**
378
392
* Fires before rendering a post in AMP.
379
393
*
394
+
* This action is not triggered when 'amp' theme support is present. Instead, you should use 'template_redirect' action and check if `is_amp_endpoint()`.
395
+
*
380
396
* @since 0.2
381
397
*
382
398
* @param int $post_id Post ID.
@@ -412,9 +428,11 @@ function _amp_bootstrap_customizer() {
412
428
* Redirects the old AMP URL to the new AMP URL.
413
429
* If post slug is updated the amp page with old post slug will be redirected to the updated url.
414
430
*
415
-
* @param string $link New URL of the post.
431
+
* @since 0.5
432
+
* @deprecated This function is irrelevant when 'amp' theme support is added.
Copy file name to clipboardExpand all lines: includes/amp-helper-functions.php
+56-12Lines changed: 56 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -8,14 +8,26 @@
8
8
/**
9
9
* Get the slug used in AMP for the query var, endpoint, and post type support.
10
10
*
11
-
* The return value can be overridden by previously defining a AMP_QUERY_VAR
11
+
* This function always returns 'amp' when 'amp' theme support is present. Otherwise,
12
+
* the return value can be overridden by previously defining a AMP_QUERY_VAR
12
13
* constant or by adding a 'amp_query_var' filter, but *warning* this ability
13
14
* may be deprecated in the future. Normally the slug should be just 'amp'.
14
15
*
15
16
* @since 0.7
17
+
* @since 1.0 The return value is always 'amp' when 'amp' theme support is present, and the 'amp_query_var' filter no longer applies.
18
+
*
16
19
* @return string Slug used for query var, endpoint, and post type support.
17
20
*/
18
21
functionamp_get_slug() {
22
+
if ( current_theme_supports( 'amp' ) ) {
23
+
if ( ! defined( 'AMP_QUERY_VAR' ) ) {
24
+
define( 'AMP_QUERY_VAR', 'amp' );
25
+
} elseif ( 'amp' !== AMP_QUERY_VAR ) {
26
+
_doing_it_wrong( __FUNCTION__, esc_html__( 'The AMP_QUERY_VAR constant should only be defined as "amp" when "amp" theme support is present.', 'amp' ), '1.0' );
27
+
}
28
+
return'amp';
29
+
}
30
+
19
31
if ( defined( 'AMP_QUERY_VAR' ) ) {
20
32
returnAMP_QUERY_VAR;
21
33
}
@@ -26,6 +38,8 @@ function amp_get_slug() {
26
38
* Warning: This filter may become deprecated.
27
39
*
28
40
* @since 0.3.2
41
+
* @since 1.0 This filter does not apply when 'amp' theme support is present.
42
+
*
29
43
* @param string $query_var The AMP query variable.
* Retrieves the full AMP-specific permalink for the given post ID.
40
54
*
41
55
* @since 0.1
56
+
* @since 1.0 The query var 'amp' is always used exclusively when 'amp' theme support is present; the 'amp_pre_get_permalink' and 'amp_get_permalink' filters do not apply.
42
57
*
43
58
* @param int $post_id Post ID.
44
59
*
45
60
* @return string AMP permalink.
46
61
*/
47
62
functionamp_get_permalink( $post_id ) {
48
63
64
+
// When theme support is present, the plain query var should always be used.
* @since 1.0 This filter does not apply when 'amp' theme support is present.
81
123
*
82
124
* @param false $amp_url AMP URL.
83
125
* @param int $post_id Post ID.
@@ -166,7 +208,7 @@ function post_supports_amp( $post ) {
166
208
/**
167
209
* Are we currently on an AMP URL?
168
210
*
169
-
* Note: will always return `false` if called before the `parse_query` hook.
211
+
* @since 1.0 This function can be called before the `parse_query` action because the 'amp' query var is specifically and exclusively used when 'amp' theme support is added.
170
212
*
171
213
* @return bool Whether it is the AMP endpoint.
172
214
*/
@@ -175,15 +217,17 @@ function is_amp_endpoint() {
175
217
returnfalse;
176
218
}
177
219
178
-
if ( amp_is_canonical() ) {
220
+
// When 'amp' theme support is (or will be added) then these are the conditions that are key to be checked.
221
+
if ( amp_is_canonical() || isset( $_GET[ amp_get_slug() ] ) ) { // WPCS: CSRF OK.
179
222
returntrue;
180
223
}
181
224
182
-
if ( 0 === did_action( 'parse_query' ) ) {
183
-
_doing_it_wrong( __FUNCTION__, sprintf( esc_html__( "is_amp_endpoint() was called before the 'parse_query' hook was called. This function will always return 'false' before the 'parse_query' hook is called.", 'amp' ) ), '0.4.2' );
225
+
// Condition for non-theme support when /amp/ endpoint is used.
226
+
if ( false !== get_query_var( amp_get_slug(), false ) ) {
0 commit comments