-
Notifications
You must be signed in to change notification settings - Fork 96
/
accelerated-moblie-pages.php
1664 lines (1531 loc) · 65.9 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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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: 1.1.2
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','1.1.2');
define('AMPFORWP_EXTENSION_DIR',plugin_dir_path(__FILE__).'includes/options/extensions');
define('AMPFORWP_ANALYTICS_URL',plugin_dir_url(__FILE__).'includes/features/analytics');
if(!defined('AMPFROWP_HOST_NAME')){
$urlinfo = get_bloginfo('url');
$url = parse_url($urlinfo);
$host = $url['host'];
define('AMPFROWP_HOST_NAME', esc_attr($host));
}
// 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() {
// Adding rewrite rules only when we are in standard mode
if (is_amp_plugin_active()) {
return;
}
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() );
if( $page )
$output = $page->ID;
}
return $output;
}
/**
* All in One SEO Plugin Conflict
* for stopping redirecting
* on amp query string
* @since 1.0.82
*/
if( in_array( 'all-in-one-seo-pack/all_in_one_seo_pack.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_filter( 'aioseo_unrecognized_allowed_query_args', 'AMP_for_WP_QueryStringAllowed_for_AIOSEO_Plugin', -1 );
function AMP_for_WP_QueryStringAllowed_for_AIOSEO_Plugin($allowedQueryArgs) {
return array_merge($allowedQueryArgs, array(
'nonamp',
'namp',
'nonamphead',
));
}
}
// Add Custom Rewrite Rule to make sure pagination & redirection is working correctly
function ampforwp_add_custom_rewrite_rules() {
// Adding rewrite rules only when we are in standard mode
if (is_amp_plugin_active()) {
return;
}
global $redux_builder_amp, $wp_rewrite;
// For Homepage
add_rewrite_rule(
'amp/?$',
'index.php?amp',
'top'
);
do_action('ampforwp_rewrite_rules_hook');
// For Homepage with Pagination
add_rewrite_rule(
'amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&paged=$matches[1]',
'top'
);
// For Pagination with index.php
add_rewrite_rule(
'index.php/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 = '';
$rewrite_category = get_transient('ampforwp_category_base');
if ( false == $rewrite_category ) {
$rewrite_category = get_option('category_base');
if ( empty($rewrite_category) ) {
$rewrite_category = 'category';
}
set_transient('ampforwp_category_base', $rewrite_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 = '';
$permalink_structure = get_transient('ampforwp_permalink_structure');
if ( false == $permalink_structure ) {
$permalink_structure = get_option('permalink_structure');
set_transient('ampforwp_permalink_structure', $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 = '';
$rewrite_tag = get_transient('ampforwp_tag_base');
if ( false == $rewrite_tag ) {
$rewrite_tag = get_option('tag_base');
if ( empty($rewrite_tag) ) {
$rewrite_tag = 'tag';
}
set_transient('ampforwp_tag_base',$rewrite_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
add_rewrite_rule(
'([0-9]{4})/([0-9]{1,2})\/amp\/?$',
'index.php?year=$matches[1]&monthnum=$matches[2]&=1',
'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
$taxonomies = array();
if( function_exists('ampforwp_generate_taxonomies_transient')){
//Rewrite rule for custom Taxonomies
$taxonomies = ampforwp_generate_taxonomies_transient();
}
if(!function_exists('amp_woocommerce_pro_add_woocommerce_support') ) {
if( class_exists( 'WooCommerce' ) ) {
$wc_permalinks = '';
$wc_permalinks = get_transient('ampforwp_woocommerce_permalinks');
if( false == $wc_permalinks ) {
$wc_permalinks = get_option( 'woocommerce_permalinks' );
set_transient('ampforwp_woocommerce_permalinks', $wc_permalinks);
}
if ( $wc_permalinks && !empty( $taxonomies) ) {
$taxonomies = array_merge($taxonomies, $wc_permalinks);
}
}
}
$post_types = ampforwp_get_all_post_types();
if ( $post_types ) {
foreach ($post_types as $post_type ) {
if ( 'post' != $post_type && 'page' != $post_type ){
add_rewrite_rule(
$post_type.'\/amp/?$',
'index.php?amp&post_type='.$post_type,
'top'
);
if ( class_exists( 'Lsvr_Permalink_Settings_Knowledge_Base' ) ) {
$lsvr_value = get_post_type_archive_link( 'lsvr_kba' );
$lsvr_value = explode("/",$lsvr_value);
$lsvr_value = array_filter($lsvr_value);
$lsvr_value = end($lsvr_value);
add_rewrite_rule(
$lsvr_value.'\/amp/?$',
'index.php?amp&post_type='.$post_type,
'top'
);
}
add_rewrite_rule(
$post_type.'\/(.+?)\/amp\/?$',
'index.php?amp&'.$post_type.'=$matches[1]',
'top'
);
add_rewrite_rule(
$post_type.'\/(.+?)\/amp\/?$',
'index.php?amp&'.$post_type.'=$matches[1]',
'top'
);
add_rewrite_rule(
$post_type.'\/amp/'.$wp_rewrite->pagination_base.'/([0-9]{1,})/?$',
'index.php?amp=1&post_type='.$post_type.'&paged=$matches[1]',
'top'
);
}
}
}
$taxonomies = apply_filters( 'ampforwp_modify_rewrite_tax', $taxonomies );
if ( $taxonomies ) {
$taxonomySlug = '';
foreach ( $taxonomies as $taxonomyName => $taxonomyLabel ) {
$taxonomies = get_taxonomy( $taxonomyName );
if(isset($taxonomies->rewrite['slug']) && !empty($taxonomies->rewrite['slug']) ){
$taxonomySlug = $taxonomies->rewrite['slug'];
}else{
$taxonomySlug = $taxonomyName;
}
if ( ! empty( $taxonomySlug ) ) {
add_rewrite_rule(
$taxonomySlug.'\/([^/]+)\/amp/?$',
'index.php?amp&'.$taxonomyName.'=$matches[1]',
'top'
);
// For Custom Taxonomies with pages
add_rewrite_rule(
$taxonomySlug.'\/([^/]+)\/amp\/'.$wp_rewrite->pagination_base.'\/?([0-9]{1,})\/?$',
'index.php?amp&'.$taxonomyName.'=$matches[1]&paged=$matches[2]',
'top'
);
}
}
}
if (ampforwp_get_setting('ampforwp-pagination-link-type')) {
add_rewrite_rule(
'(.+?)-[0-9]+\/([0-9]{1,})\/amp$',
'index.php?amp=1&name=$matches[1]&paged=$matches[2]',
'top'
);
add_rewrite_rule(
'(.+?)\/([0-9]{1,})\/amp$',
'index.php?amp=1&name=$matches[1]&paged=$matches[2]',
'top'
);
}
}
add_action( 'init', 'ampforwp_add_custom_rewrite_rules', 25 );
// Delete category_base transient when it is updated #2924
add_action('update_option_category_base', 'ampforwp_update_option_category_base');
function ampforwp_update_option_category_base(){
delete_transient('ampforwp_category_base');
}
// Delete category_base transient when it is updated #2924
add_action('update_option_tag_base', 'ampforwp_update_option_tag_base');
function ampforwp_update_option_tag_base(){
delete_transient('ampforwp_tag_base');
}
// Delete permalink_structure transient when it is updated #2924
add_action('update_option_permalink_structure', 'ampforwp_update_option_permalink_structure');
function ampforwp_update_option_permalink_structure(){
delete_transient('ampforwp_permalink_structure');
// Delete ampforwp_woocommerce_permalinks transient when it is updated #2924
if( class_exists( 'WooCommerce' ) ) {
delete_transient('ampforwp_woocommerce_permalinks');
}
}
// 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(){
// Adding rewrite rules only when we are in standard mode
if (is_amp_plugin_active()) {
return;
}
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['category_rewrite_slug'].'\/(.+?)\/([^\/]+)\/amp\/?$',
'index.php?amp&product_cat=$matches[2]',
'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() {
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', false);
}
}
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');
// Remove admin notice after dismissing it
delete_transient( 'ampforwp_automattic_activation_notice');
}
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/',
),
);
}
}
require_once dirname( __FILE__ ).'/includes/options/redux-core/framework.php';
require_once dirname( __FILE__ ).'/includes/options/extensions/loader.php';
add_action('after_setup_theme', 'ampforwp_include_options_file' );
function ampforwp_include_options_file(){
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';
// Global UX Fields
$amp_ux_fields = array();
require_once AMPFORWP_PLUGIN_DIR."includes/ampforwp-fields-array.php";
}
}
// Modules
add_action('after_setup_theme','ampforwp_add_module_files');
function ampforwp_add_module_files() {
global $redux_builder_amp;
if ( function_exists('ampforwp_custom_theme_files_register') ) {
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() ) {
add_action( 'plugins_loaded', 'amp_update_db_check' );
// 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 ) {
$amp_activate = '';
if ( function_exists('amp_activate') ) {
$amp_activate = ' | <span style="color:black;">' . esc_html__('Status: Addon Mode', 'accelerated-mobile-pages') . '</span>';
}
$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>'. $amp_activate );
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$actions = array_merge( $actions, $settings );
}
return $actions;
}
}
} // is_admin() closing
// Fallback for file exists #3156
if( ! function_exists('ampforwp_require_file') ){
function ampforwp_require_file($path){
if(file_exists($path)){
return require_once $path;
}
else{
return false;
}
}
}
// AMP endpoint Verifier
function ampforwp_is_amp_endpoint() {
if ( (function_exists('ampforwp_is_non_amp') && ampforwp_is_non_amp()) && ! is_admin()) {
return apply_filters('ampforwp_is_amp_endpoint_takeover', ampforwp_is_non_amp() );
}
else {
return apply_filters('ampforwp_is_amp_endpoint', false !== ampforwp_get_query_var( 'amp', false ) );
}
}
/*
* Customizing get_query_var to fix fatal error logs get() on null
* when ampforwp_is_amp_endpoint() function is used by third party plugin
* [Fatal error with Nitropack #5427]
*/
function ampforwp_get_query_var( $var, $default = '' ) {
global $wp_query;
if( ! isset( $wp_query ) || ! method_exists( $wp_query, 'get' ) ) return $default;
return $wp_query->get( $var, $default );
}
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( ! class_exists( 'Ampforwp_Init', false ) ) {
class Ampforwp_Init {
public function __construct(){
require AMPFORWP_PLUGIN_DIR .'/includes/features/functions.php';
// Load Files required for the plugin to run
if( function_exists('amp_activate') ){
require_once AMPFORWP_PLUGIN_DIR."includes/features/amp_bridge.php";
}
else{
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();
}
//Other Features
require_once AMPFORWP_PLUGIN_DIR."includes/features/advertisement/ads-functions.php";
require_once AMPFORWP_PLUGIN_DIR."includes/features/advertisement/mgid-ads-functions.php";
require_once AMPFORWP_PLUGIN_DIR."includes/features/performance/performance-functions.php";
require_once AMPFORWP_PLUGIN_DIR."includes/features/analytics/analytics-functions.php";
require_once AMPFORWP_PLUGIN_DIR."includes/features/structure-data/structured-data-functions.php";
require_once AMPFORWP_PLUGIN_DIR."includes/features/notice-bar/notice-bar-functions.php";
require_once AMPFORWP_PLUGIN_DIR."includes/features/push-notification/push-notification-functions.php";
require_once AMPFORWP_PLUGIN_DIR."includes/mb-helper-function.php";
}
}
}
/*
* Start the plugin.
* Gentlemen start your engines
*/
function ampforwp_plugin_init() {
if ( defined( 'AMPFORWP__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
*/
ampforwp_require_file( AMPFORWP_PLUGIN_DIR.'/templates/woo-widget.php' );
ampforwp_require_file( AMPFORWP_PLUGIN_DIR.'/templates/amp-code-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';
ampforwp_require_file( AMPFORWP_PLUGIN_DIR .'/templates/template-mode/template-mode.php' );
define( 'AMPFORWP__FILE__', __FILE__ );
if ( ! defined('AMP__VENDOR__DIR__') ) {
define( 'AMP__VENDOR__DIR__', plugin_dir_path(__FILE__) . 'includes/vendor/amp/' );
}
if ( ! defined('AMP_QUERY_VAR') ){
define('AMP_QUERY_VAR', 'amp');
}
define( 'AMP__VENDOR__VERSION', '0.4.2' );
require_once( AMP__VENDOR__DIR__ . '/back-compat/back-compat.php' );
require_once( AMP__VENDOR__DIR__ . '/includes/amp-helper-functions.php' );
require_once( AMP__VENDOR__DIR__ . '/includes/admin/functions.php' );
require_once( AMP__VENDOR__DIR__ . '/includes/settings/class-amp-customizer-settings.php' );
require_once( AMP__VENDOR__DIR__ . '/includes/settings/class-amp-customizer-design-settings.php' );
// Widgets
require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-categories.php' );
require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-archives.php' );
require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-media-video.php' );
require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-recent-comments.php' );
require_once ( AMP__VENDOR__DIR__ . '/includes/widgets/class-amp-widget-text.php' );
//Removed JNews AMP Extender #3526
if ( function_exists( 'jnews_get_option' ) ){
remove_action( 'plugins_loaded', 'jnews_amp' );
remove_filter( 'amp_content_sanitizers', 'jnews_amp_content_sanitize');
}
if (function_exists('wpda_hb_pro__plugins_loaded')) {
$url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH),'/' );
if( function_exists('ampforwp_is_amp_inURL') && ampforwp_is_amp_inURL($url_path)) {
remove_action('plugins_loaded', 'wpda_hb_pro__plugins_loaded');
}
}
}
add_action('plugins_loaded','ampforwp_bundle_core_amp_files', 8);
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__VENDOR__DIR__') ) {
define( 'AMP__VENDOR__DIR__', plugin_dir_path(__FILE__) . 'includes/vendor/amp/' );
}
do_action( 'amp_init' );
load_plugin_textdomain( 'accelerated-mobile-pages', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
// Adding rewrite rules only when we are in standard mode
if (!is_amp_plugin_active()) {
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
}
add_post_type_support( 'post', AMP_QUERY_VAR );
add_filter( 'request', 'AMPforWP\\AMPVendor\\amp_force_query_var_value' );
add_action( 'wp', 'AMPforWP\\AMPVendor\\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__VENDOR__DIR__ . '/jetpack-helper.php' );
}
// AMP by Automattic Compatibility #2287
// Remove the FrontPage query added by AMP to make our FrontPage/Homepage works
if ( function_exists('amp_activate') ) {
remove_action( 'parse_query', 'amp_correct_query_when_is_front_page' );
remove_action( 'wp', 'amp_maybe_add_actions' );
}
}
}
function amp_update_db_check() {
global $redux_builder_amp;
$ampforwp_current_version = AMPFORWP_VERSION;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['ampforwp-dismiss-theme'] ) &&
trim( sanitize_text_field( wp_unslash( $_GET['ampforwp-dismiss-theme'] ) ) ) === "ampforwp_dismiss_admin_notices" &&
isset( $_GET['ampforwp_notice'] ) &&
wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['ampforwp_notice'] ) ), 'ampforwp_notice' ) ) {
update_option( 'ampforwp_theme_notice', true, false );
wp_redirect("admin.php?page=amp_options");
exit; // Always exit after wp_redirect
}
if ( get_option( 'AMPforwp_db_version' ) !== $ampforwp_current_version ) {
if ( isset( $_GET['ampforwp-dismiss'] ) &&
trim( sanitize_text_field( wp_unslash( $_GET['ampforwp-dismiss'] ) ) ) === "ampforwp_dismiss_admin_notices" &&
isset( $_GET['ampforwp_notice'] ) &&
wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['ampforwp_notice'] ) ), 'ampforwp_notice' ) ) {
update_option( 'AMPforwp_db_version', $ampforwp_current_version );
wp_redirect(remove_query_arg('ampforwp-dismiss'), 301);
exit; // Always exit after wp_redirect
}
}
}
// Admin notice for AMP WordPress Theme
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 }
}
}
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 ( AMPFORWP_PLUGIN_DIR.'/install/index.php' );
if ( !function_exists('amp_activate') ) {
require_once( AMPFORWP_PLUGIN_DIR. 'base_remover/base_remover.php' );
require_once( AMPFORWP_PLUGIN_DIR. 'includes/thirdparty-compatibility.php' );
$enablePb = false;
if(is_admin()){
global $pagenow;
if( is_multisite() ){
/* phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash */
$current_url = ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( esc_url_raw( $_SERVER['REQUEST_URI'] ) ) : "";
$post_old = preg_match('/post\.php/', $current_url);
$post_new = preg_match('/post-new\.php/', $current_url);
if($post_old || $post_new){
$enablePb = true;
}
}elseif( ('post.php' || 'post-new.php') == $pagenow ) {
$enablePb = true;
}
if (defined('DOING_AJAX') && DOING_AJAX) {
$enablePb = true;
}
}else{
$enablePb = true;
}
if ($enablePb && ampforwp_get_setting('ampforwp-pagebuilder')== true ){
require_once( AMPFORWP_PLUGIN_DIR. 'pagebuilder/amp-page-builder.php');
}
}
if(is_admin()){
require_once( AMPFORWP_PLUGIN_DIR. 'includes/modules-upgrade.php' );
add_action( "redux/options/redux_builder_amp/saved", 'ampforwp_update_data_when_saved', 10, 2 );
add_action( "redux/options/redux_builder_amp/reset", 'ampforwp_update_data_when_reset' );
add_action( "redux/options/redux_builder_amp/section/reset", 'ampforwp_update_data_when_reset' );
add_action( "redux/options/redux_builder_amp/saved", 'ampforwp_save_local_font', 10, 2 );
}
/**
* 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 == ampforwp_get_setting('amp-design-selector') && ! function_exists('amp_activate') ) {
$value = false;
}
return $value;
}
}
// Get Settings from Redux #2177 & #2911
function ampforwp_get_setting( $opt_name='', $child_option='', $sanitize_method='' ){
global $redux_builder_amp;
if (is_plugin_active('amp/amp.php')) {
unset($redux_builder_amp['ampforwp-seo-selection']);
}
if(empty($redux_builder_amp)){
$redux_builder_amp = (array) get_option('redux_builder_amp');
}
$opt_value = '';
if ( isset($redux_builder_amp[$opt_name]) ) {
$opt_value = $redux_builder_amp[$opt_name];
if ( '' !== $child_option && isset($redux_builder_amp[$opt_name][$child_option]) ){
$opt_value = $redux_builder_amp[$opt_name][$child_option];
}
}
if ( '' !== $sanitize_method && function_exists($sanitize_method) ){
return $sanitize_method($opt_value);
}
return $opt_value;
}
// Setup funtion
if(!function_exists('ampforwp_get_setup_info')){
function ampforwp_get_setup_info($ux_option=''){
$ux_content = "";
if($ux_option=="ampforwp-ux-website-type-section"){
$ux_content = ampforwp_get_setting('ampforwp-setup-ux-website-type');
if(ampforwp_get_setting('ampforwp-sd-type-posts') && preg_match("/Other/", $ux_content)==0 && $ux_content!=="Local Business"){
$ux_content = ampforwp_get_setting('ampforwp-sd-type-posts');
}else{
$ux_content = ampforwp_get_setting('ampforwp-setup-ux-website-type');
}
if($ux_content=="NewsArticle" || $ux_content=="News"){
$ux_content="News";
}else if($ux_content=="BlogPosting" || $ux_content=="Blog" || $ux_content==""){
$ux_content="Blog";
}else if($ux_content=="Product"){
$ux_content="Ecommerce";
}
if(preg_match("/Other/", $ux_content)!=0){
$other = explode("-", $ux_content);
if(isset($other[1])){
$ux_content=$other[1];
}else{
$ux_content="WebPage";
}
}
}else if($ux_option=="ampforwp-ux-need-type-section"){
$home = ampforwp_get_setting('ampforwp-homepage-on-off-support');
$posts = ampforwp_get_setting('amp-on-off-for-all-posts');
$pages = ampforwp_get_setting('amp-on-off-for-all-pages');
$archive = ampforwp_get_setting('ampforwp-archive-support');
$ntype_arr = array();
if($home==1){$ntype_arr[] = "Home";}
if($posts==1){$ntype_arr[] = "Posts";}
if($pages==1){$ntype_arr[] = "Pages";}
if($archive==1){$ntype_arr[] = "Archive";}