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
|
<?php /** * Plugin Name: Penci PenNews AMP - WordPress Complete AMP * Description: Add AMP support to your WordPress site. * Plugin URI: http://pencidesign.com/ * Author: PenciDesign * Author URI: http://themeforest.net/user/pencidesign?ref=pencidesign * Version: 2.6.5 * Text Domain: penci-amp * Domain Path: /languages/ */
if ( ! defined( 'ABSPATH' ) ) { exit; }
if( defined( 'PENCI_AMP_VERSION' ) ) { return; }
define( 'PENCI_AMP_FILE', __FILE__ ); define( 'PENCI_AMP_URL', plugin_dir_url( __FILE__ ) ); define( 'PENCI_AMP_DIR', dirname( __FILE__ ) ); define( 'PENCI_AMP_VERSION', '2.6.5' ); define( 'PENCI_STARTPOINT', 'amp' );
require_once( PENCI_AMP_DIR . '/back-compat/back-compat.php' ); require_once( PENCI_AMP_DIR . '/includes/amp-helper-functions.php' ); require_once( PENCI_AMP_DIR . '/includes/admin/functions.php' ); require_once( PENCI_AMP_DIR . '/includes/class-amp-product.php' ); require_once( PENCI_AMP_DIR . '/includes/class-amp-menu-walker.php' ); require_once( PENCI_AMP_DIR . '/includes/class-amp-custom-rewrite-rules.php' ); require_once( PENCI_AMP_DIR . '/includes/class-amp-social-share.php' ); require_once( PENCI_AMP_DIR . '/includes/class-amp-compatibility.php' ); require_once( PENCI_AMP_DIR . '/includes/amp-metabox.php' );
require_once( PENCI_AMP_DIR . '/includes/sanitizers/class-amp-link-sanitizer.php' ); require_once( PENCI_AMP_DIR . '/includes/settings/default-setting.php' ); require_once( PENCI_AMP_DIR . '/includes/settings/class-amp-customizer-settings.php' ); require_once( PENCI_AMP_DIR . '/includes/settings/class-amp-customizer-design-settings.php' );
register_activation_hook( __FILE__, 'penci_amp_activate' ); if ( ! function_exists( 'penci_amp_activate' ) ) { function penci_amp_activate() { if ( ! did_action( 'penci_amp_init' ) ) { penci_amp_init(); } flush_rewrite_rules(); } }
register_deactivation_hook( __FILE__, 'penci_amp_deactivate' );
if ( ! function_exists( 'penci_amp_deactivate' ) ) { function penci_amp_deactivate() { global $wp_rewrite; foreach ( $wp_rewrite->endpoints as $index => $endpoint ) { if ( PENCI_AMP_QUERY_VAR === $endpoint[1] ) { unset( $wp_rewrite->endpoints[ $index ] ); break; } }
flush_rewrite_rules(); } }
add_action( 'init', 'penci_amp_init' );
if ( ! function_exists( 'penci_amp_init' ) ) { function penci_amp_init() { if ( false === apply_filters( 'penci_amp_is_enabled', true ) ) { return; }
define( 'PENCI_AMP_QUERY_VAR', apply_filters( 'penci_amp_query_var', PENCI_STARTPOINT ) );
do_action( 'penci_amp_init' );
load_plugin_textdomain( 'penci-amp', false, plugin_basename( PENCI_AMP_DIR ) . '/languages' ); register_nav_menu( 'penci-amp-sidebar-nav', esc_html__( 'AMP Navigation', 'penci-amp' ) );
// Home page add_rewrite_rule( PENCI_AMP_QUERY_VAR . '/?$', "index.php?amp=index", 'top' );
$GLOBALS['Penci_AMP_Custom_Rewrite_Rules'] = new Penci_AMP_Custom_Rewrite_Rules(); global $Penci_AMP_Custom_Rewrite_Rules; $Penci_AMP_Custom_Rewrite_Rules->add_startpoint( PENCI_STARTPOINT, EP_ALL, $query_var = true ); $Penci_AMP_Custom_Rewrite_Rules->add_endpoint( PENCI_STARTPOINT, EP_ALL, $query_var = true );
add_rewrite_endpoint( PENCI_AMP_QUERY_VAR, EP_PERMALINK ); add_post_type_support( 'post', PENCI_AMP_QUERY_VAR ); add_post_type_support( 'page', PENCI_AMP_QUERY_VAR ); add_post_type_support( 'product', PENCI_AMP_QUERY_VAR ); add_post_type_support( 'attachment', PENCI_AMP_QUERY_VAR );
add_rewrite_rule( PENCI_AMP_QUERY_VAR . '/?$', "index.php?amp=index", 'top' );
add_filter( 'request', 'penci_amp_force_query_var_value' ); add_action( 'wp', 'penci_amp_maybe_add_actions' );
add_filter( 'old_slug_redirect_url', 'penci_amp_redirect_old_slug_to_new_url' );
if ( class_exists( 'Jetpack' ) && ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) { require_once( PENCI_AMP_DIR . '/jetpack-helper.php' ); }
add_action( 'template_redirect', 'penci_amp_auto_redirect_to_amp', 1 ); } }
function penci_amp_auto_redirect_to_amp() { $is_penci_amp = is_penci_amp();
if ( $is_penci_amp ) { return; }
$auto_redirect = get_theme_mod( 'penci_amp_mobile_version' ); if( ! $auto_redirect ) { return; }
if ( ! empty( $_GET['penciamp-skip-redirect'] ) || ! empty( $_COOKIE['penciamp-skip-redirect'] ) ) { if ( ! isset( $_COOKIE['penciamp-skip-redirect'] ) ) { setcookie( 'penciamp-skip-redirect', true, time() + DAY_IN_SECONDS, '/' ); }
return; } else { if ( isset( $_COOKIE['penciamp-skip-redirect'] ) ) { unset( $_COOKIE['penciamp-skip-redirect'] ); } } if ( wp_is_mobile() ) { $requested_url = ''; if ( isset( $_SERVER['HTTP_HOST'] ) ) { $requested_url = is_ssl() ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; } $amp_permalink = Penci_AMP_Link_Sanitizer::__pre_url( $requested_url ); if ( $requested_url && $amp_permalink && $amp_permalink !== $requested_url ) { wp_redirect( $amp_permalink ); exit; } } }
add_action( 'request', 'penci_fix_search' );
if ( ! function_exists( 'penci_fix_search' ) ) { function penci_fix_search( $query ) { if ( ! empty( $query['s'] ) && ! empty( $query['amp'] ) ) { $query['post_type'] = array( 'post' ); }
return $query; } }
if ( ! function_exists( 'penci_amp_force_query_var_value' ) ) { function penci_amp_force_query_var_value( $query_vars ) { if ( isset( $query_vars[ PENCI_AMP_QUERY_VAR ] ) && '' === $query_vars[ PENCI_AMP_QUERY_VAR ] ) { $query_vars[ PENCI_AMP_QUERY_VAR ] = 1; }
return $query_vars; } }
if ( ! function_exists( 'penci_amp_maybe_add_actions' ) ) { function penci_amp_maybe_add_actions() {
$is_penci_amp_endpoint = is_penci_amp_endpoint();
if ( is_singular() && is_page() && ! is_feed() ) {
global $wp_query; $post = $wp_query->post;
$supports = penci_post_supports_amp( $post );
if ( ! $supports ) { if ( $is_penci_amp_endpoint ) { wp_safe_redirect( get_permalink( $post->ID ) ); exit; }
return; } }
if ( $is_penci_amp_endpoint ) { penci_amp_prepare_render(); } else { penci_amp_add_frontend_actions(); } } }
if ( ! function_exists( 'penci_amp_load_classes' ) ) { function penci_amp_load_classes() { require_once( PENCI_AMP_DIR . '/includes/class-amp-post-template.php' ); } }
if ( ! function_exists( 'penci_amp_add_frontend_actions' ) ) { function penci_amp_add_frontend_actions() { require_once( PENCI_AMP_DIR . '/includes/amp-frontend-actions.php' ); } }
if ( ! function_exists( 'penci_amp_add_post_template_actions' ) ) { function penci_amp_add_post_template_actions() { require_once( PENCI_AMP_DIR . '/includes/amp-post-template-actions.php' ); require_once( PENCI_AMP_DIR . '/includes/amp-post-template-functions.php' ); penci_amp_post_template_init_hooks(); } }
if ( ! function_exists( 'penci_amp_prepare_render' ) ) { function penci_amp_prepare_render() { add_action( 'template_redirect', 'penci_amp_render' ); } }
if ( ! function_exists( 'penci_amp_render' ) ) { function penci_amp_render() {
$post_id = get_queried_object_id();
$dis_amp_onpost = get_post_meta( $post_id, 'penci_dis_amp_onpost', true );
if ( $dis_amp_onpost ) { return; }
if ( function_exists( 'is_bbpress' ) && is_bbpress() ) { return; }
penci_amp_render_post( $post_id ); exit; } }
if ( ! function_exists( 'penci_amp_render_post' ) ) { function penci_amp_render_post( $post_id ) {
$post = get_post( $post_id ); if ( ! $post && is_singular() ) { return; }
penci_amp_load_classes();
do_action( 'pre_penci_amp_render_post', $post_id );
penci_amp_add_post_template_actions(); $template = new Penci_AMP_Post_Template( $post_id ); $include = penci_amp_template_loader();
$template->load( $include ); } }
if ( ! function_exists( 'penci_amp_template_loader' ) ) { function penci_amp_template_loader() { if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) : if ( function_exists( 'is_shop' ) && ( is_shop() || is_product_category() || is_product_tag() ) ): $template = 'woocommerce'; elseif ( is_singular( 'product' ) ): $template = 'single-product'; endif; elseif ( is_404() ) : $template = 'page404'; elseif ( is_search() ) : $template = 'search'; elseif ( is_front_page() || is_home() ) : $template = 'index'; elseif ( is_post_type_archive() || is_tax() || is_category() || is_tag() || is_author() || is_date() || is_archive() || is_paged() ) : $template = 'archive'; elseif ( is_attachment() || is_singular() || is_single() ) : $template = 'single'; elseif ( is_page() ) : $template = 'page'; else : $template = 'index'; endif;
return $template; } }
if ( ! function_exists( '_penci_amp_bootstrap_customizer' ) ) { function _penci_amp_bootstrap_customizer() { $penci_amp_customizer_enabled = apply_filters( 'penci_amp_customizer_is_enabled', true );
if ( true === $penci_amp_customizer_enabled ) { penci_amp_init_customizer(); } } }
add_action( 'plugins_loaded', '_penci_amp_bootstrap_customizer', 9 );
if ( ! function_exists( 'penci_amp_redirect_old_slug_to_new_url' ) ) { function penci_amp_redirect_old_slug_to_new_url( $link ) {
if ( is_penci_amp_endpoint() ) { $link = trailingslashit( trailingslashit( $link ) . PENCI_AMP_QUERY_VAR ); }
return $link; } }
|