/
accelerated-moblie-pages.php
795 lines (691 loc) · 31.5 KB
/
accelerated-moblie-pages.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
<?php
/*
Plugin Name: Accelerated Mobile Pages
Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
Description: AMP for WP - Accelerated Mobile Pages for WordPress
Version: 0.9.97.22
Author: Ahmed Kaludi, Mohammed Kaludi
Author URI: https://ampforwp.com/
Donate link: https://www.paypal.me/Kaludi/25
License: GPL2+
Text Domain: accelerated-mobile-pages
Domain Path: /languages/
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
define('AMPFORWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ));
define('AMPFORWP_PLUGIN_DIR_URI', plugin_dir_url(__FILE__));
define('AMPFORWP_DISQUS_URL',plugin_dir_url(__FILE__).'includes/disqus.html');
define('AMPFORWP_IMAGE_DIR',plugin_dir_url(__FILE__).'images');
define('AMPFORWP_MAIN_PLUGIN_DIR', plugin_dir_path( __DIR__ ) );
define('AMPFORWP_VERSION','0.9.97.22');
// any changes to AMP_QUERY_VAR should be refelected here
function ampforwp_generate_endpoint(){
$ampforwp_slug = '';
$get_permalink_structure = '';
$ampforwp_slug = "amp";
return $ampforwp_slug;
}
define('AMPFORWP_AMP_QUERY_VAR', apply_filters( 'amp_query_var', ampforwp_generate_endpoint() ) );
// Rewrite the Endpoints after the plugin is activate, as priority is set to 11
function ampforwp_add_custom_post_support() {
global $redux_builder_amp;
add_rewrite_endpoint( AMPFORWP_AMP_QUERY_VAR, EP_PAGES | EP_PERMALINK | EP_AUTHORS | EP_ALL_ARCHIVES | EP_ROOT );
// Pages
if ( isset($redux_builder_amp['amp-on-off-for-all-pages']) && $redux_builder_amp['amp-on-off-for-all-pages'] ) {
add_post_type_support( 'page', AMPFORWP_AMP_QUERY_VAR );
}
// Custom Post Types
if ( isset($redux_builder_amp['ampforwp-custom-type'] ) && $redux_builder_amp['ampforwp-custom-type'] ) {
foreach ( $redux_builder_amp['ampforwp-custom-type'] as $custom_post ) {
add_post_type_support( $custom_post, AMP_QUERY_VAR );
}
}
}
add_action( 'init', 'ampforwp_add_custom_post_support',11);
// Frontpage and Blog page check from reading settings.
function ampforwp_name_blog_page() {
if ( ! $page_for_posts = get_option('page_for_posts')) return;
$page_for_posts = get_option( 'page_for_posts' );
$post = get_post($page_for_posts);
if ( $post ) {
$slug = $post->post_name;
return $slug;
}
}
function ampforwp_custom_post_page() {
$front_page_type = get_option( 'show_on_front' );
if ( $front_page_type ) {
return $front_page_type;
}
}
function ampforwp_get_the_page_id_blog_page(){
$page = "";
$output = "";
if ( ampforwp_name_blog_page() ) {
$page = get_page_by_path( ampforwp_name_blog_page() );
$output = $page->ID;
}
return $output;
}
// Add Custom Rewrite Rule to make sure pagination & redirection is working correctly
function ampforwp_add_custom_rewrite_rules() {
global $redux_builder_amp, $wp_rewrite;
// For Homepage
add_rewrite_rule(
'amp/?$',
'index.php?amp',
'top'
);
// For Homepage with Pagination
add_rewrite_rule(
'amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&paged=$matches[1]',
'top'
);
// For /Blog page with Pagination
if( ampforwp_name_blog_page() ) {
add_rewrite_rule(
ampforwp_name_blog_page(). '/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&paged=$matches[1]&page_id=' .ampforwp_get_the_page_id_blog_page(),
'top'
);
// Pagination to work with Extensions like.hml
add_rewrite_rule(
ampforwp_name_blog_page(). '(.+?)/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&paged=$matches[2]&page_id=' .ampforwp_get_the_page_id_blog_page(),
'top'
);
}
// For Author pages
add_rewrite_rule(
'author\/([^/]+)\/amp\/?$',
'index.php?amp=1&author_name=$matches[1]',
'top'
);
add_rewrite_rule(
'author\/([^/]+)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&author_name=$matches[1]&paged=$matches[2]',
'top'
);
// For category pages
$rewrite_category = get_option('category_base');
if ( ! empty($rewrite_category) ) {
$rewrite_category = get_option('category_base');
} else {
$rewrite_category = 'category';
}
add_rewrite_rule(
$rewrite_category.'\/(.+?)\/amp/?$',
'index.php?amp=1&category_name=$matches[1]',
'top'
);
// For category pages with Pagination
add_rewrite_rule(
$rewrite_category.'/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&category_name=$matches[1]&paged=$matches[2]',
'top'
);
// For category pages with Pagination (Custom Permalink Structure)
$permalink_structure = get_option('permalink_structure');
$permalink_structure = preg_replace('/(%.*%)/', '', $permalink_structure);
$permalink_structure = preg_replace('/\//', '', $permalink_structure);
if ( $permalink_structure ) {
add_rewrite_rule(
$permalink_structure.'\/'.$rewrite_category.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&category_name=$matches[1]&paged=$matches[2]',
'top'
);
}
// For tag pages
$rewrite_tag = get_option('tag_base');
if ( ! empty($rewrite_tag) ) {
$rewrite_tag = get_option('tag_base');
} else {
$rewrite_tag = 'tag';
}
add_rewrite_rule(
$rewrite_tag.'\/(.+?)\/amp/?$',
'index.php?amp=1&tag=$matches[1]',
'top'
);
// For tag pages with Pagination
add_rewrite_rule(
$rewrite_tag.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&tag=$matches[1]&paged=$matches[2]',
'top'
);
// For tag pages with Pagination (Custom Permalink Structure)
if ( $permalink_structure ) {
add_rewrite_rule(
$permalink_structure.'\/'.$rewrite_tag.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp=1&tag=$matches[1]&paged=$matches[2]',
'top'
);
}
// Rewrite rule for date archive with pagination #2289
add_rewrite_rule(
'([0-9]{4})/([0-9]{1,2})/amp/'.$wp_rewrite->pagination_base.'/?([0-9]{1,})/?$',
'index.php?year=$matches[1]&monthnum=$matches[2]&=1&paged=$matches[3]',
'top'
);
//Rewrite rule for custom Taxonomies
$args = array(
'public' => true,
'_builtin' => false,
);
$output = 'names'; // or objects
$operator = 'and'; // 'and' or 'or'
$taxonomies = get_taxonomies( $args, $output, $operator );
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if(!is_plugin_active('amp-woocommerce-pro/amp-woocommerce.php' )) {
if( class_exists( 'WooCommerce' ) ) {
$wc_permalinks = get_option( 'woocommerce_permalinks' );
if ( $wc_permalinks ) {
$taxonomies = array_merge($taxonomies, $wc_permalinks);
}
}
}
$taxonomies = apply_filters( 'ampforwp_modify_rewrite_tax', $taxonomies );
if ( $taxonomies ) {
foreach ( $taxonomies as $key => $taxonomy ) {
if ( ! empty( $taxonomy ) ) {
add_rewrite_rule(
$taxonomy.'\/(.+?)\/amp/?$',
'index.php?amp&'.$key.'=$matches[1]',
'top'
);
// For Custom Taxonomies with pages
add_rewrite_rule(
$taxonomy.'\/(.+?)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp&'.$taxonomy.'=$matches[1]&paged=$matches[2]',
'top'
);
}
}
}
}
add_action( 'init', 'ampforwp_add_custom_rewrite_rules', 25 );
// add re-write rule for Products
add_action( 'init', 'ampforwp_custom_rewrite_rules_for_product_category' );
if ( ! function_exists('ampforwp_custom_rewrite_rules_for_product_category') ) {
function ampforwp_custom_rewrite_rules_for_product_category(){
if ( class_exists('WooCommerce') ) {
$permalinks = wp_parse_args( (array) get_option( 'woocommerce_permalinks', array() ), array(
'product_base' => '',
'category_base' => '',
'tag_base' => '',
'attribute_base' => '',
'use_verbose_page_rules' => false,
) );
// Ensure rewrite slugs are set.
$permalinks['product_rewrite_slug'] = untrailingslashit( empty( $permalinks['product_base'] ) ? _x( 'product', 'slug', 'accelerated-mobile-pages' ) : $permalinks['product_base'] );
$permalinks['category_rewrite_slug'] = untrailingslashit( empty( $permalinks['category_base'] ) ? _x( 'product-category', 'slug', 'accelerated-mobile-pages' ) : $permalinks['category_base'] );
$permalinks['tag_rewrite_slug'] = untrailingslashit( empty( $permalinks['tag_base'] ) ? _x( 'product-tag', 'slug', 'accelerated-mobile-pages' ) : $permalinks['tag_base'] );
$permalinks['attribute_rewrite_slug'] = untrailingslashit( empty( $permalinks['attribute_base'] ) ? '' : $permalinks['attribute_base'] );
add_rewrite_rule(
$permalinks['product_rewrite_slug']."\/amp\/page\/([0-9]{1,})/?$",
'index.php?post_type=product&paged=$matches[1]&=1',
'top'
);
add_rewrite_rule(
$permalinks['category_rewrite_slug'].'\/(.+?)\/amp\/page\/?([0-9]{1,})/?$',
'index.php?product_cat=$matches[1]&paged=$matches[2]&=1',
'top'
);
add_rewrite_rule(
$permalinks['category_rewrite_slug'].'\/(.+?)\/amp\/?$',
'index.php?amp&product_cat=$matches[1]',
'top'
);
add_rewrite_rule(
$permalinks['tag_rewrite_slug'].'\/(.+?)\/amp\/page\/?([0-9]{1,})/?$',
'index.php?product_tag=$matches[1]&paged=$matches[2]&=1',
'top'
);
add_rewrite_rule(
$permalinks['tag_rewrite_slug'].'\/(.+?)\/amp\/?$',
'index.php?amp&product_tag=$matches[1]',
'top'
);
}
}
}
function ampforwp_plugin_info(){
$data = array();
$date = new DateTime();
$data = array('activation_data' => $date->getTimestamp() );
add_option( 'ampforwp_plugin_info', $data );
}
add_action('upgrader_process_complete','ampforwp_plugin_info' );
register_activation_hook( __FILE__, 'ampforwp_rewrite_activation', 20 );
function ampforwp_rewrite_activation() {
// Run AMP deactivation code while activation
ampforwp_deactivate_amp_plugin();
if ( ! did_action( 'ampforwp_init' ) ) {
ampforwp_init();
}
flush_rewrite_rules();
ampforwp_add_custom_post_support();
ampforwp_add_custom_rewrite_rules();
ampforwp_plugin_info();
// Flushing rewrite urls ONLY on activation
global $wp_rewrite;
$wp_rewrite->flush_rules();
delete_option('ampforwp_rewrite_flush_option');
// Set transient for Welcome page
set_transient( 'ampforwp_welcome_screen_activation_redirect', true, 30 );
}
add_action( 'admin_init', 'ampforwp_flush_after_update');
function ampforwp_flush_after_update() {
// Flushing rewrite urls ONLY on after Update is installed
$older_version = "";
$older_version = get_transient('ampforwp_current_version_check');
if ( empty($older_version) || ( $older_version < AMPFORWP_VERSION ) ) {
flush_rewrite_rules();
global $wp_rewrite;
$wp_rewrite->flush_rules();
set_transient('ampforwp_current_version_check', AMPFORWP_VERSION);
}
}
add_action('init', 'ampforwp_flush_rewrite_by_option', 20);
function ampforwp_flush_rewrite_by_option(){
global $wp_rewrite;
$get_current_permalink_settings = "";
$get_current_permalink_settings = get_option('ampforwp_rewrite_flush_option');
if ( $get_current_permalink_settings ) {
return;
}
// Adding double check to make sure, we are not updating and calling database unnecessarily
if ( empty( $get_current_permalink_settings ) ) {
$wp_rewrite->flush_rules();
update_option('ampforwp_rewrite_flush_option', 'true');
}
}
register_deactivation_hook( __FILE__, 'ampforwp_rewrite_deactivate', 20 );
function ampforwp_rewrite_deactivate() {
// Flushing rewrite urls ONLY on deactivation
global $wp_rewrite;
foreach ( $wp_rewrite->endpoints as $index => $endpoint ) {
if ( AMP_QUERY_VAR === $endpoint[1] ) {
unset( $wp_rewrite->endpoints[ $index ] );
break;
}
}
flush_rewrite_rules();
$wp_rewrite->flush_rules();
// Remove transient for Welcome page
delete_transient( 'ampforwp_welcome_screen_activation_redirect');
}
add_action( 'admin_init','ampforwp_parent_plugin_check');
function ampforwp_parent_plugin_check() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$amp_plugin_activation_check = is_plugin_active( 'amp/amp.php' );
if ( $amp_plugin_activation_check ) {
// set_transient( 'ampforwp_parent_plugin_check', true, 30 );
} else {
delete_option( 'ampforwp_parent_plugin_check');
}
}
if( !function_exists('ampforwp_upcomming_layouts_demo') ){
function ampforwp_upcomming_layouts_demo(){
return array(
array(
"name"=>'Creative Services',
"image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-9.png',
"link"=>'https://ampforwp.com/layouts-9/',
),
array(
"name"=>'App',
"image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-8.png',
"link"=>'https://ampforwp.com/layouts-8/',
),
array(
"name"=>'Business Blog',
"image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-7.png',
"link"=>'https://ampforwp.com/layouts-7/',
),
array(
"name"=>'Journal',
"image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-6.png',
"link"=>'https://ampforwp.com/layouts-6/',
),
array(
"name"=>'Studio',
"image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-5.png',
"link"=>'https://ampforwp.com/layouts-5/',
),
array(
"name"=>'Agency',
"image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-4.png',
"link"=>'https://ampforwp.com/layouts-4/',
),
array(
"name"=>'Elegance',
"image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-3.png',
"link"=>'https://ampforwp.com/layouts-3/',
),
array(
"name"=>'Weekly Magazine',
"image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-2.png',
"link"=>'https://ampforwp.com/layouts-2/',
),
array(
"name"=>'News',
"image"=>''.AMPFORWP_IMAGE_DIR . '/layouts-1.png',
"link"=>'https://ampforwp.com/layouts-1/',
),
);
}
}
// Redux panel inclusion code
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$amp_plugin_manager_version = array();
$plugin_manager_active = is_plugin_active('amp-plugin-manager/ampforwp-3rd-party-plugin-creator.php');
$amp_plugin_manager_active = is_plugin_active('plugin-manager/ampforwp-3rd-party-plugin-creator.php');
if ( $plugin_manager_active) {
$amp_plugin_manager = get_plugin_data(AMPFORWP_MAIN_PLUGIN_DIR.'/amp-plugin-manager/ampforwp-3rd-party-plugin-creator.php');
$amp_plugin_manager_version = $amp_plugin_manager['Version'];
}
if ( $amp_plugin_manager_active) {
$plugin_manager = get_plugin_data(AMPFORWP_MAIN_PLUGIN_DIR.'/plugin-manager/ampforwp-3rd-party-plugin-creator.php');
$amp_plugin_manager_version = $plugin_manager['Version'];
}
if ( $plugin_manager_active || $amp_plugin_manager_active ) {
if ( (! class_exists( 'ReduxFramework' ) && $GLOBALS['pagenow']=='admin.php' && $_GET['page']=='amp_options') || is_plugin_active('redux-framework/redux-framework.php') || '1.0' == $amp_plugin_manager_version ) {
require_once dirname( __FILE__ ).'/includes/options/extensions/loader.php';
require_once dirname( __FILE__ ).'/includes/options/redux-core/framework.php';
}
}
add_action('after_setup_theme', 'ampforwp_load_amp_options');
function ampforwp_load_amp_options(){
if ( ! class_exists( 'ReduxFramework' ) ) {
require_once dirname( __FILE__ ).'/includes/options/extensions/loader.php';
require_once dirname( __FILE__ ).'/includes/options/redux-core/framework.php';
}
if ( is_admin() ) {
// Register all the main options
require_once dirname( __FILE__ ).'/includes/options/admin-config.php';
require_once dirname( __FILE__ ).'/templates/report-bugs.php';
}
}
// Modules
add_action('after_setup_theme','ampforwp_add_module_files');
function ampforwp_add_module_files() {
global $redux_builder_amp;
if ( isset($redux_builder_amp['ampforwp-content-builder']) && $redux_builder_amp['ampforwp-content-builder'] ) {
if ( ! function_exists( 'bstw' ) ) {
require_once AMPFORWP_PLUGIN_DIR .'/includes/vendor/tinymce-widget/tinymce-widget.php';
}
require_once AMPFORWP_PLUGIN_DIR .'/includes/modules/ampforwp-blurb.php';
require_once AMPFORWP_PLUGIN_DIR .'/includes/modules/ampforwp-button.php';
}
}
/*
* Load Files only in the backend
* As we don't need plugin activation code to run everytime the site loads
*/
if ( is_admin() ) {
// Include Welcome page only on Admin pages
require AMPFORWP_PLUGIN_DIR .'/includes/welcome.php';
// Add Settings Button in Plugin backend
if ( ! function_exists( 'ampforwp_plugin_settings_link' ) ) {
// Deactivate Parent Plugin notice
add_filter( 'plugin_action_links', 'ampforwp_plugin_settings_link', 10, 5 );
function ampforwp_plugin_settings_link( $actions, $plugin_file ) {
static $plugin;
if ( ! isset($plugin))
$plugin = plugin_basename(__FILE__);
if ( $plugin === $plugin_file ) {
$settings = array( 'settings' => '<a href="admin.php?page=amp_options&tab=8">' . esc_html__('Settings', 'accelerated-mobile-pages') . '</a> | <a href="https://ampforwp.com/extensions/#utm_source=plugin-panel&utm_medium=plugin-extension&utm_campaign=features">' . esc_html__('Premium Features', 'accelerated-mobile-pages') . '</a> | <a href="https://ampforwp.com/membership/#utm_source=plugin-panel&utm_medium=plugin-extension&utm_campaign=pro">' . esc_html__('Pro', 'accelerated-mobile-pages') . '</a>' );
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$actions = array_merge( $actions, $settings );
}
return $actions;
}
}
} // is_admin() closing
// AMP endpoint Verifier
function ampforwp_is_amp_endpoint() {
if ( ampforwp_is_non_amp() && ! is_admin()) {
return ampforwp_is_non_amp();
}
else {
return false !== get_query_var( 'amp', false );
}
}
if ( ! class_exists( 'Ampforwp_Init', false ) ) {
class Ampforwp_Init {
public function __construct(){
// Load Files required for the plugin to run
require AMPFORWP_PLUGIN_DIR .'/includes/includes.php';
// Redirection Code added
require AMPFORWP_PLUGIN_DIR.'/includes/redirect.php';
require AMPFORWP_PLUGIN_DIR .'/classes/class-init.php';
new Ampforwp_Loader();
}
}
}
/*
* Start the plugin.
* Gentlemen start your engines
*/
function ampforwp_plugin_init() {
if ( defined( 'AMP__FILE__' ) && defined('AMPFORWP_PLUGIN_DIR') ) {
new Ampforwp_Init();
}
}
add_action('init','ampforwp_plugin_init',9);
/*
* customized output widget
* to be used be used in before or after Loop
*/
require AMPFORWP_PLUGIN_DIR.'/templates/category-widget.php';
require AMPFORWP_PLUGIN_DIR.'/templates/woo-widget.php';
/*
* Including core AMP plugin files and removing any other things if necessary
*/
function ampforwp_bundle_core_amp_files(){
// Bundling Default plugin
require_once AMPFORWP_PLUGIN_DIR .'/includes/vendor/amp/amp.php';
define( 'AMP__FILE__', __FILE__ );
if ( ! defined('AMP__DIR__') ) {
define( 'AMP__DIR__', AMPFORWP_PLUGIN_DIR . 'includes/vendor/amp/' );
}
if ( ! defined('AMP_QUERY_VAR') ){
define('AMP_QUERY_VAR', 'amp');
}
define( 'AMP__VERSION', '0.4.2' );
require_once( AMP__DIR__ . '/back-compat/back-compat.php' );
require_once( AMP__DIR__ . '/includes/amp-helper-functions.php' );
require_once( AMP__DIR__ . '/includes/admin/functions.php' );
require_once( AMP__DIR__ . '/includes/settings/class-amp-customizer-settings.php' );
require_once( AMP__DIR__ . '/includes/settings/class-amp-customizer-design-settings.php' );
}
add_action('plugins_loaded','ampforwp_bundle_core_amp_files', 8);
function ampforwp_deactivate_amp_plugin() {
if ( version_compare( floatval( get_bloginfo( 'version' ) ), '3.5', '>=' ) ) {
if ( current_user_can( 'activate_plugins' ) ) {
add_action( 'admin_init', 'ampforwp_deactivate_amp' );
function ampforwp_deactivate_amp() {
deactivate_plugins( AMPFORWP_MAIN_PLUGIN_DIR . 'amp/amp.php' );
}
}
}
}
add_action( 'plugins_loaded', 'ampforwp_deactivate_amp_plugin' );
function ampforwp_modify_amp_activatation_link( $actions, $plugin_file ) {
$plugin = '';
$plugin = 'amp/amp.php';
if ( $plugin == $plugin_file ) {
add_thickbox();
unset($actions['activate']);
$amp_activate = '<span style="cursor:pointer;color:#0089c8" class="warning_activate_amp" onclick="alert(\''.esc_html__('AMP is already bundled with AMPforWP. Please do not install this plugin with AMPforWP to avoid conflicts', 'accelerated-mobile-pages'). '\')">Activate</span>';
array_unshift ($actions,$amp_activate);
}
return $actions;
}
add_filter( 'plugin_action_links', 'ampforwp_modify_amp_activatation_link', 10, 2 );
if ( ! function_exists('ampforwp_init') ) {
add_action( 'init', 'ampforwp_init' );
function ampforwp_init() {
if ( false === apply_filters( 'amp_is_enabled', true ) ) {
return;
}
if( ! defined('AMP_QUERY_VAR')){
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
}
if ( ! defined('AMP__DIR__') ) {
define( 'AMP__DIR__', AMPFORWP_PLUGIN_DIR . 'includes/vendor/amp/' );
}
do_action( 'amp_init' );
load_plugin_textdomain( 'accelerated-mobile-pages', false, trailingslashit(AMPFORWP_PLUGIN_DIR) . 'languages' );
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
add_post_type_support( 'post', AMP_QUERY_VAR );
add_filter( 'request', 'amp_force_query_var_value' );
add_action( 'wp', 'amp_maybe_add_actions' );
// Redirect the old url of amp page to the updated url. #1033 (Vendor Update)
add_filter( 'old_slug_redirect_url', 'ampforwp_redirect_old_slug_to_new_url' );
if ( class_exists( 'Jetpack' ) && ! (defined( 'IS_WPCOM' ) && IS_WPCOM) ) {
require_once( AMP__DIR__ . '/jetpack-helper.php' );
}
}
}
function amp_update_db_check() {
global $redux_builder_amp;
$ampforwp_current_version = AMPFORWP_VERSION;
if ( isset( $_GET['ampforwp-dismiss-theme'] ) && trim( $_GET['ampforwp-dismiss-theme']) === "ampforwp_dismiss_admin_notices" && wp_verify_nonce($_GET['ampforwp_notice'], 'ampforwp_notice') ) {
update_option( 'ampforwp_theme_notice', true );
wp_redirect("admin.php?page=amp_options");
}
if ( get_option( 'AMPforwp_db_version' ) !== $ampforwp_current_version ) {
if ( isset( $_GET['ampforwp-dismiss'] ) && trim( $_GET['ampforwp-dismiss']) === "ampforwp_dismiss_admin_notices" && wp_verify_nonce($_GET['ampforwp_notice'], 'ampforwp_notice') ) {
update_option( 'AMPforwp_db_version', $ampforwp_current_version );
wp_redirect(remove_query_arg('ampforwp-dismiss'), 301);
}
if ( isset($redux_builder_amp['ampforwp-update-notification-bar'] ) && $redux_builder_amp['ampforwp-update-notification-bar'] && current_user_can( 'manage_options' ) ) {
add_action('admin_notices', 'ampforwp_update_notice');
}
}
}
add_action( 'plugins_loaded', 'amp_update_db_check' );
// Admin notice for AMP WordPress Theme
add_action('admin_notices', 'ampforwp_ampwptheme_notice');
function ampforwp_ampwptheme_notice() {
$theme = '';
$theme = wp_get_theme(); // gets the current theme
if ( ('AMP WordPress Theme' == $theme->name || 'AMP WordPress Theme' == $theme->parent_theme) && true != get_option('ampforwp_theme_notice') ) {
add_thickbox(); ?>
<div id="some" class="notice-warning settings-error notice is-dismissible">
<span style="margin: 0.5em 0.5em 0 0"><?php echo esc_html__('AMP WordPress Theme is installed', 'accelerated-mobile-pages'); ?></span><br>
<span style="margin: 0.5em 0.5em 0 0"><?php echo esc_html__('One Last Step Required:', 'accelerated-mobile-pages'); ?> <a href="#TB_inline?width=600&height=550&inlineId=my-content-id" class="thickbox"><?php echo esc_html__('Finish Setup', 'accelerated-mobile-pages') ?></a></span><br>
</div>
<div id="my-content-id" style="display:none;">
<p>
<iframe width="100%" height="480" src="https://www.youtube.com/embed/" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'ampforwp-dismiss-theme', 'ampforwp_dismiss_admin_notices' ), 'ampforwp_notice', 'ampforwp_notice' ) ) ?>"><?php echo esc_html__('Take me to the Options Panel', 'accelerated-mobile-pages'); ?></a>
</p>
</div>
<?php }
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$amp_plugin_manager_version = array();
$plugin_manager_active = is_plugin_active('amp-plugin-manager/ampforwp-3rd-party-plugin-creator.php');
$amp_plugin_manager_active = is_plugin_active('plugin-manager/ampforwp-3rd-party-plugin-creator.php');
if ( $plugin_manager_active) {
$amp_plugin_manager = get_plugin_data(AMPFORWP_MAIN_PLUGIN_DIR.'/amp-plugin-manager/ampforwp-3rd-party-plugin-creator.php');
$amp_plugin_manager_version = $amp_plugin_manager['Version'];
}
if ( $amp_plugin_manager_active) {
$plugin_manager = get_plugin_data(AMPFORWP_MAIN_PLUGIN_DIR.'/plugin-manager/ampforwp-3rd-party-plugin-creator.php');
$amp_plugin_manager_version = $plugin_manager['Version'];
}
if ( $plugin_manager_active || $amp_plugin_manager_active ) {
$screen = get_current_screen();
if ( '1.0' == $amp_plugin_manager_version && 'plugins' === $screen->base) { ?>
<div id="ampforwp_pluginmanager" class="notice-warning settings-error notice is-dismissible"><p><b><?php echo esc_html__(' Attention','accelerated-mobile-pages'); ?>:</b> <?php echo esc_html__(' AMPforWP Plugin Manager requires an upgrade. Please','accelerated-mobile-pages'); ?> <b><a href="https://ampforwp.com/plugins-manager/?update=plugins-manager#utm_source=plugin-page&utm_medium=plugin-manager-update&utm_campaign=update-notice" target="_blank"><?php echo esc_html__('Download & install the latest version', 'accelerated-mobile-pages'); ?></a></b> <?php echo esc_html__('for free','accelerated-mobile-pages'); ?>.
</p>
</div>
<?php }
}
}
function ampforwp_update_notice() {
$screen = '';
$screen = get_current_screen();
$ampforwp_current_version = AMPFORWP_VERSION;
if ( 'toplevel_page_amp_options' == $screen->base ) { ?>
<div class="notice-success notice is-dismissible amp-update-notice">
<div class="amp-update-notice-text-box">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAn1BMVEUAAADuHCXwHiTuHSTtHST/IjjuHSXuHCTvHSXvHCXwHi3/JyfuHSTuHCTvHSTvHCTxHSb/NDTyHyj0IyruHSTvHSXvHSbuHST1ICftHCXuHCXuHSXwHiXvHy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Q7QVqYzKGziGpWPhw5VEnCGCrcRWSs2Yj/gWM2CDs/WA9VexneR9XY+9XTn1VJrPlvAUGzdejbXHcf/KkZ/sdmeHozisc6RuR9Wges/L1PPsPZR8jb+YV8jsHagsnvOyX5LOXX0/zmb4uUfAPTTmKy8wY/SMNzEdxW9ulzRL6bXegpfuAY+/diAb51PGn/3AqDrpcf58V4Oxlk5H/lJxdt5e+wtfWRAAAAAElFTkSuQmCC" width="128" height="128" />
<div class="amp-update-notice-text"> <?php echo esc_html__('AMP has been updated to '.$ampforwp_current_version, 'accelerated-mobile-pages' ); ?></div>
<a href="https://ampforwp.com/new/" target="_blank" href="admin.php?page=acmforwp_update"><?php echo esc_html__('What\'s New ?', 'accelerated-mobile-pages');?></a>
</div>
<div class="amp-update-notice-dismiss">
<a title="Close this Notification" href="<?php echo esc_url( wp_nonce_url(add_query_arg( 'ampforwp-dismiss', 'ampforwp_dismiss_admin_notices' ), 'ampforwp_notice', 'ampforwp_notice') ) ?>">X</a>
</div>
<div class="amp-update-notice-review-box">
<a class="star_icon" href="https://wordpress.org/support/view/plugin-reviews/accelerated-mobile-pages?rate=5#new-post" target="_blank"> <?php echo esc_html__('Appreciate it?','accelerated-mobile-pages')?> <br> <span title="Give Us 5 Star"><?php echo esc_html__('Leave a Review', 'accelerated-mobile-pages') ?> →</span></a>
</div>
</div>
<?php }
}
if ( ! defined('AMP_FRAMEWORK_COMOPNENT_DIR_PATH') ) {
define('AMP_FRAMEWORK_COMOPNENT_DIR_PATH', AMPFORWP_PLUGIN_DIR ."/components");
}
require_once( AMP_FRAMEWORK_COMOPNENT_DIR_PATH . '/components-core.php' );
require_once( AMPFORWP_PLUGIN_DIR. 'pagebuilder/amp-page-builder.php' );
require_once( AMPFORWP_PLUGIN_DIR. 'base_remover/base_remover.php' );
require_once( AMPFORWP_PLUGIN_DIR. 'includes/thirdparty-compatibility.php' );
if(is_admin()){
require_once( AMPFORWP_PLUGIN_DIR. '/includes/modules-upgrade.php');
}
require ( AMPFORWP_PLUGIN_DIR.'/install/index.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.
*
* @param string $link New URL of the post.
*
* @return string $link URL to be redirected.
*/
if ( ! function_exists( 'ampforwp_redirect_old_slug_to_new_url' ) ) {
function ampforwp_redirect_old_slug_to_new_url( $link ) {
if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) {
$link = trailingslashit( trailingslashit( $link ) . AMPFORWP_AMP_QUERY_VAR );
}
return $link;
}
}
// Hide Post Builder if Swift is enabled
add_filter('amp_customizer_is_enabled', 'ampforwp_customizer_is_enabled');
if ( ! function_exists('ampforwp_customizer_is_enabled') ) {
function ampforwp_customizer_is_enabled($value){
global $redux_builder_amp;
if ( 4 == $redux_builder_amp['amp-design-selector'] ) {
$value = false;
}
return $value;
}
}
// Get Settings from Redux #2177
function ampforwp_get_setting( $opt_name='' ){
global $redux_builder_amp;
$opt_value = '';
if ( isset($redux_builder_amp[$opt_name]) ) {
$opt_value = $redux_builder_amp[$opt_name];
}
return $opt_value;
}
// color sanitizer
function ampforwp_sanitize_color( $color ) {
if ( empty( $color ) || is_array( $color ) )
return 'rgba(0,0,0,0)';
// If string does not start with 'rgba', then treat as hex
// sanitize the hex color and finally convert hex to rgba
if ( false === strpos( $color, 'rgba' ) ) {
return sanitize_hex_color( $color );
}
// By now we know the string is formatted as an rgba color so we need to further sanitize it.
$color = str_replace( ' ', '', $color );
sscanf( $color, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha );
return 'rgba('.$red.','.$green.','.$blue.','.$alpha.')';
}