-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectPages.php
1679 lines (1200 loc) · 57.3 KB
/
ProjectPages.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: Project Pages
Plugin URI: https://projectpages.io
Description: Project Pages is the simplest way to share your projects beautifully.
Version: 2.1
Author: <a href="https://projectpages.io">Project Pages.io</a>
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
// PHP Version check
if (version_compare(phpversion(), '5.4', '<')) {
// php version isn't high enough
echo '<div style="font-family: \'Open Sans\',sans-serif;">Project Pages Requires PHP Version 5.4 or above, please ask web hosting provider to update your PHP!</div>';
exit();
}
// Hooks
// Install/uninstall
register_activation_hook(__FILE__,'projectPages_install');
register_deactivation_hook(__FILE__,'projectPages_uninstall');
// general
add_action('init', 'projectPages_init');
add_action('admin_menu', 'projectPages_admin_menu');
// init vars
global $projectPages_db_version,$projectPages_version;
$projectPages_db_version = "1.0";
$projectPages_version = "2.0";
// Urls
global $projectPages_urls;
$projectPages_urls['home'] = 'http://projectpages.io';
$projectPages_urls['feedback'] = 'https://forms.gle/sAhUjTcNABN6ZgGLA'; // note this is also hardcoded in all blocks. change there if changed here.
$projectPages_urls['subscribe'] = 'https://projectpages.io/join/';
$projectPages_urls['get-pro'] = 'https://projectpages.io/pro/';
$projectPages_urls['x'] = 'https://twitter.com/projectpagesio';
$projectPages_urls['xwh'] = 'https://twitter.com/woodyhayday';
$projectPages_urls['wh'] = 'https://woodyhayday.com';
$projectPages_urls['join'] = 'https://projectpages.io/services/wp-join/wp-join.php';
$projectPages_urls['review'] = 'https://wordpress.org/support/view/plugin-reviews/project-pages?filter=5#new-post';
$projectPages_urls['kb-getting-started'] = 'https://projectpages.io/docs/getting-started-with-project-pages/';
$projectPages_urls['kb-templates'] = 'https://projectpages.io/docs/templates/';
$projectPages_urls['kb-permalink-root'] = 'https://projectpages.io/docs/urls-permalink-root/';
$projectPages_urls['kb-og-meta-generate'] = 'https://projectpages.io/docs/generating-custom-sharing-images-og-meta-with-project-pages-pro/';
$projectPages_urls['kb-imagemagick-req'] = 'https://projectpages.io/docs/project-pages-pro-requires-imagemagick/';
$projectPages_urls['kb-prompts'] = 'https://projectpages.io/docs/using-prompts-for-better-project-updates-in-project-pages-pro/';
$projectPages_urls['kb-not-block-based'] = 'https://projectpages.io/docs/block-enabled-themes/';
$projectPages_urls['publish-on-pp-io'] = 'https://projectpages.io/publish-to-projectpages/';
// Page slugs
global $projectPages_slugs;
$projectPages_slugs['home'] = "projectpages";
$projectPages_slugs['settings'] = "projectpages-plugin-settings";
// defined
define( 'PROJECTPAGES_ROOTFILE', __FILE__ );
define( 'PROJECTPAGES_PATH', plugin_dir_path(__FILE__) );
define( 'PROJECTPAGES_ROOTDIR', basename(dirname(__FILE__)) ); // zero-bs-crm
define( 'PROJECTPAGES_URL', plugin_dir_url(__FILE__) );
define( 'PROJECTPAGES_ROOTPLUGIN', PROJECTPAGES_ROOTDIR.'/'.basename( PROJECTPAGES_ROOTFILE ) );
define( 'PROJECTPAGES_PLUGIN_TEMPLATE_PATH', PROJECTPAGES_PATH . 'templates');
define( 'PROJECTPAGES_THEME_TEMPLATE_PATH', get_stylesheet_directory().'/project-pages');
// Includes
// Pre-init
require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.Pre.Init.php' );
// PRO VER
//require_once( PROJECTPAGES_PATH . 'pro/ProjectPages.PRO.php' );
// Init
require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.Config.Init.php' );
require_once( PROJECTPAGES_PATH . 'includes/wh.config.lib.php' );
require_once( PROJECTPAGES_PATH . 'includes/wh.helpers.lib.php' );
require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.DAL.php' );
require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.MetaBoxes.php' );
require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.AJAX.php' );
require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.Blocks.php' );
// **EXPERIMENTAL** require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.BlockEditor.php' );
require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.Templating.php' );
require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.OGMeta.php' );
# require_once( PROJECTPAGES_PATH . 'includes/ProjectPages.Announcements.php' );
// Init settings model (after init hook)
do_action( 'project_pages_pre_settings_hook' );
global $projectPages_Settings, $projectPages_Conf_Setup;
//echo '<pre>'.json_encode($projectPages_Conf_Setup).'</pre>'; exit();
if (!isset($projectPages_Settings)) $projectPages_Settings = new WH_WP_ConfigLib($projectPages_Conf_Setup);
// post settings hook
do_action( 'project_pages_post_settings_hook' );
#================== Init/Admin Enqueuing etc.
// Install function
function projectPages_install(){
global $projectPages_version, $projectPages_db_version, $projectPages_Settings;
// Initialising settings no happens via Settings Class
// As of V1.0
if (!is_array($projectPages_Settings->getAll())){
add_action('admin_notices','projectPages__settingsfail');function projectPages__settingsfail(){echo '<div class="error"><p>Project Pages Plugin Could not create its options object!</p></div>';}
} else {
// check if theme is block-based
projectPages_theme_check();
}
}
// uninstall
function projectPages_uninstall(){
// Skip deactivation feedback if it's a JSON/AJAX request or via WP-CLI
if ( wp_is_json_request() || wp_doing_ajax() || ( defined( 'WP_CLI' ) && WP_CLI ) || wp_is_xml_request() ) {
return;
}
// got feedback? - currently not using this mark as fed-back feat.
$has_given_feedback = get_option( 'has_given_projectpages_feedback' );
// if php notice, (e.g. php ver to low, skip this)
if ( $has_given_feedback == false && !defined('PROJECTPAGES_FEEDBACK_INPROG')){
// Show feedback dialog + Deactivate
// Define is to stop an infinite loop :)
// (Won't get here the second time)
define( 'PROJECTPAGES_FEEDBACK_INPROG', true );
// ask for feedback
try {
// manually deactivate before exit
deactivate_plugins( plugin_basename( PROJECTPAGES_ROOTFILE ) );
// include feedback file
require_once( PROJECTPAGES_PATH . 'pages/deactivation-feedback.php' ); exit();
} catch (Exception $e){
// Nada
}
}
}
// Install template(s)
// Switched this to an "optional override" like woocommerce :)
function projectPages_installProjectPageTemplates($quiet=false) {
// Add dir if needed (copy perms as per wp theme protocol.)
if (!file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH)) mkdir(PROJECTPAGES_THEME_TEMPLATE_PATH,0707);
// copy single template
if (!file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/single-projectpage.php')){
copy(PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/single-projectpage_DEFAULT.php', PROJECTPAGES_THEME_TEMPLATE_PATH . '/single-projectpage.php' );
// Check
if (!file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/single-projectpage.php')){
if (!$quiet) projectPages_html_msg(1,'Failed to install template into your theme directory! (single-projectpage.php)');
} else {
if (!$quiet) projectPages_html_msg(0,'Template successfully installed into your theme directory! (single-projectpage.php)');
}
} else {
if (!$quiet) projectPages_html_msg(1,'Template already exists in your theme directory! (single-projectpage.php)');
}
// copy archive template
if (!file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/archive-projectpage.php')){
copy(PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/archive-projectpage_DEFAULT.php', PROJECTPAGES_THEME_TEMPLATE_PATH . '/archive-projectpage.php' );
// Check
if (!file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/archive-projectpage.php')){
if (!$quiet) projectPages_html_msg(1,'Failed to install template into your theme directory! (archive-projectpage.php)');
} else {
if (!$quiet) projectPages_html_msg(0,'Template successfully installed into your theme directory! (archive-projectpage.php)');
}
} else {
if (!$quiet) projectPages_html_msg(1,'Template already exists in your theme directory! (archive-projectpage.php)');
}
// copy taxonomy template
if (!file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/taxonomy-projectpagetag.php')){
copy(PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/taxonomy-projectpage_DEFAULT.php', PROJECTPAGES_THEME_TEMPLATE_PATH . '/taxonomy-projectpagetag.php' );
// Check
if (!file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/taxonomy-projectpagetag.php')){
if (!$quiet) projectPages_html_msg(1,'Failed to install template into your theme directory! (taxonomy-projectpagetag.php)');
} else {
if (!$quiet) projectPages_html_msg(0,'Template successfully installed into your theme directory! (taxonomy-projectpagetag.php)');
}
} else {
if (!$quiet) projectPages_html_msg(1,'Template already exists in your theme directory! (taxonomy-projectpagetag.php)');
}
// copy taxonomy template
if (!file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/projectpages-footer.php')){
copy(PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/projectpages-footer.php', PROJECTPAGES_THEME_TEMPLATE_PATH . '/projectpages-footer.php' );
// Check
if (!file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/projectpages-footer.php')){
if (!$quiet) projectPages_html_msg(1,'Failed to install template into your theme directory! (projectpages-footer.php)');
} else {
if (!$quiet) projectPages_html_msg(0,'Template successfully installed into your theme directory! (projectpages-footer.php)');
}
} else {
if (!$quiet) projectPages_html_msg(1,'Template already exists in your theme directory! (projectpages-footer.php)');
}
}
function projectPages_renameProjectPageTemplates(){
// Brutal.
// rename single template
if (file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/single-projectpage.php')){
rename(PROJECTPAGES_THEME_TEMPLATE_PATH . '/single-projectpage.php',PROJECTPAGES_THEME_TEMPLATE_PATH . '/single-projectpage_replaced-'.time().'.php' );
}
// rename archive template
if (file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/archive-projectpage.php')){
rename(PROJECTPAGES_THEME_TEMPLATE_PATH . '/archive-projectpage.php',PROJECTPAGES_THEME_TEMPLATE_PATH . '/archive-projectpage_replaced-'.time().'.php' );
}
// copy taxonomy template
if (file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/taxonomy-projectpagetag.php')){
rename(PROJECTPAGES_THEME_TEMPLATE_PATH . '/taxonomy-projectpagetag.php',PROJECTPAGES_THEME_TEMPLATE_PATH . '/taxonomy-projectpagetag_replaced-'.time().'.php' );
}
// copy taxonomy template
if (file_exists(PROJECTPAGES_THEME_TEMPLATE_PATH . '/projectpages-footer.php')){
rename(PROJECTPAGES_THEME_TEMPLATE_PATH . '/projectpages-footer.php',PROJECTPAGES_THEME_TEMPLATE_PATH . '/projectpages-footer_replaced-'.time().'.php' );
}
}
// Props 2 http://wordpress.stackexchange.com/questions/2553/how-to-register-sidebar-without-messing-up-the-order
function projectPages_self_deprecating_sidebar_registration(){
if ( function_exists('register_sidebar') ){
register_sidebar(array(
'id' => 'whpp-mid',
'name' => 'Project Pages Footer Mid',
'before_widget' => '<div class="three wide column"><div class="ppFooterWidgetWrap">',
'after_widget' => '</div></div>',
'before_title' => '<h4 class="ui inverted header">',
'after_title' => '</h4>',
)
);
register_sidebar(array(
'id' => 'whpp-right',
'name' => 'Project Pages Footer Right',
'before_widget' => '<div class="ppFooterWidgetWrap">',
'after_widget' => '</div>',
'before_title' => '<h4 class="ui inverted header">',
'after_title' => '</h4>',
)
);
}
}
add_action( 'wp_loaded', 'projectPages_self_deprecating_sidebar_registration' );
// Initialisation - enqueueing scripts/styles
function projectPages_init(){
global $projectPages_slugs, $projectPages_Settings; #req
// Retrieve settings
$settings = $projectPages_Settings->getAll();
// setup post types
projectPages_setupPostTypes();
// Load Lang
load_plugin_textdomain( 'projectpages', false, dirname( plugin_basename( __FILE__ ) ) . '/translations' );
// Admin & Public
wp_enqueue_script("jquery");
// Admin only
if (is_admin()){
global $pagenow;
// Hmmm not that efficient.
$postTypeStr = ''; if (isset($_GET['post'])) $postTypeStr = get_post_type((int)$_GET['post']);
if (
(isset($_GET['post_type']) && $_GET['post_type'] == 'projectpage' && $pagenow !== 'edit.php' && $pagenow !== 'edit-tags.php') ||
(!empty($postTypeStr) && $postTypeStr == 'projectpage')
) {
projectPages_enqueue_editor_page();
}
// gutenberg stuff
if ( $pagenow == 'site-editor.php' ){
projectPages_gutenberg_init();
}
// theme issue outstanding
if ( get_user_meta(get_current_user_id(), 'pp_theme_issue', true)) {
add_action('admin_notices','project_pages_theme_fail');
}
// theme opportunity outstanding
if ( get_user_meta(get_current_user_id(), 'pp_theme_opportunity', true)) {
add_action('admin_notices','project_pages_theme_opportunity');
}
}
// blocks
projectPages_init_blocks();
// **EXPERIMENTAL**
// Gutenberg editing (WIP)
// setup block editor template (wp 6.1+)
// projectPages_register_block_template();
}
// check rewrite rules
function projectPages_rewrite_rules_check()
{
$rules = get_option( 'rewrite_rules' );
if ( ! isset( $rules['projects/?$'] ) ) {
projectPages_rewrite_rules_flush();
}
}
add_action( 'wp_loaded','projectPages_rewrite_rules_check' );
// flush rewrite rules
function projectPages_rewrite_rules_flush()
{
global $wp_rewrite; $wp_rewrite->flush_rules();
}
// redirect to homepage on activation
function projectPages_activated_plugin( $filename ) {
// Skip the re-direction if it's a JSON/AJAX request or via WP-CLI
if ( wp_is_json_request() || wp_doing_ajax() || ( defined( 'WP_CLI' ) && WP_CLI ) || wp_is_xml_request() ) {
return;
}
if ( $filename == PROJECTPAGES_ROOTPLUGIN ) {
// send user to our home page
if ( wp_redirect( admin_url( 'options.php?page=projectpages' ) ) ) {
exit;
}
}
}
add_action( 'activated_plugin', 'projectPages_activated_plugin' );
// Add le admin menu
function projectPages_admin_menu() {
global $projectPages_slugs;
// Welcome
// as sub-item as hidden page, we then use projectPages_admin_header + ProjectPages.global.wp-admin.js to rewrite the url href on top level menu item to this
$project_pages_hidden_menu_item = add_submenu_page( 'options.php', 'Project Pages', 'Welcome', 'edit_published_pages', $projectPages_slugs['home'], 'projectPages_pages_home', 1 );
add_action( "admin_print_styles-{$project_pages_hidden_menu_item}", 'projectPages_enqueue_home_page' );
// settings
$project_pages_settings_menu_item = add_submenu_page( 'edit.php?post_type=projectpage', 'Project Pages', 'Settings', 'manage_options', $projectPages_slugs['settings'], 'projectPages_pages_settings' );
add_action( "admin_print_styles-{$project_pages_settings_menu_item}", 'projectPages_enqueue_settings_page' );
do_action('project_pages_admin_menu');
}
// put out any logic we need to admin header (menu rewrite url for js)
function projectPages_admin_header() {
// edit.php?post_type=projectpage&page=projectpages
?><script>
// Tweak menu :/
var projectPages_home_url = '<?php echo admin_url( 'options.php?page=projectpages' ); ?>';
jQuery(function(){
jQuery('li.menu-top .menu-icon-projectpage').attr( 'href', window.projectPages_home_url );
});
</script>
<?php // gutenberg additions
projectPages_gutenberg_scripts( false );
// PRO hook
do_action( 'project_pages_admin_header' );
}
add_action( 'admin_head', 'projectPages_admin_header' );
// home page css/js
function projectPages_enqueue_home_page() {
wp_enqueue_style('pp_bootstrap', PROJECTPAGES_URL . 'css/bootstrap/bootstrap.min.css' );
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_script( 'bootstrap-js', PROJECTPAGES_URL . 'js/libs/bootstrap/bootstrap.bundle.min.js', array('jquery'), '3.3.4', true );
wp_enqueue_style('pp_home', PROJECTPAGES_URL . 'css/ProjectPages.Home.min.css' );
wp_enqueue_script( 'pp_home_js', PROJECTPAGES_URL . 'js/ProjectPages.Home.min.js' );
}
// settings page css/js
function projectPages_enqueue_settings_page() {
wp_enqueue_style('pp_bootstrap', PROJECTPAGES_URL . 'css/bootstrap/bootstrap.min.css' );
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_script( 'bootstrap-js', PROJECTPAGES_URL . 'js/libs/bootstrap/bootstrap.bundle.min.js', array('jquery'), '3.3.4', true );
// vue app (settings page)
wp_enqueue_style('pp_settings_app', PROJECTPAGES_URL . 'css/ProjectPages.Settings.min.css' );
wp_enqueue_script( 'pp_settings_app_js', PROJECTPAGES_URL . 'js/ProjectPages.Settings.min.js' );
wp_enqueue_script( 'pp_settings_app_add_js', PROJECTPAGES_URL . 'js/ProjectPages.Settings.Additions.min.js' );
}
// editor page css/js
function projectPages_enqueue_editor_page() {
wp_enqueue_style( 'pp_bootstrap', PROJECTPAGES_URL . 'css/bootstrap/bootstrap.min.css' );
wp_enqueue_script( 'bootstrap-js', PROJECTPAGES_URL . 'js/libs/bootstrap/bootstrap.bundle.min.js', array('jquery'), '3.3.4', true );
wp_enqueue_script( 'bootstrap-datepicker-js', PROJECTPAGES_URL . 'js/libs/bootstrap-datepicker.min.js', array('jquery') );
wp_enqueue_style( 'projectpagesadmcss', plugins_url('/css/ProjectPages.Admin.min.css',__FILE__) );
wp_enqueue_script( 'pp_editor_js', PROJECTPAGES_URL . 'js/ProjectPages.admin.editor.min.js' );
//wp_enqueue_script( 'pp_editor_bs_select_js', PROJECTPAGES_URL . 'js/libs/bootstrap-select.js', array('jquery','bootstrap-js') );
//wp_enqueue_style( 'pp_editor_bs_select_css', plugins_url('/css/bootstrap-select.min.css',__FILE__) );
wp_enqueue_style( 'projectpagesspectrumcss', plugins_url('/css/libs/spectrum.css',__FILE__) );
wp_enqueue_script( 'projectpagesspectrumjs', plugins_url('/js/libs/spectrum.js',__FILE__) );
// dashicons picker
wp_enqueue_style( 'dashicons-picker', plugin_dir_url( __FILE__ ) . 'css/libs/dashicons-picker.css', array( 'dashicons' ), '1.0' );
wp_enqueue_script( 'dashicons-picker', plugin_dir_url( __FILE__ ) . 'js/libs/dashicons-picker.mod.js', array( 'jquery' ), '1.0' ); // modified version, added change monitoring
}
// front-end enqueuement
function projectPages_enqueue_project_pages_frontend(){
if ( is_singular( 'projectpage' ) || is_post_type_archive( 'projectpage' ) || is_tax( 'projectpagetag' ) ) {
// shared with some blocks
projectPages_enqueue_frontend();
// PRO hook
do_action( 'project_pages_frontend_enqueuement' );
}
} add_action( 'wp_enqueue_scripts', 'projectPages_enqueue_project_pages_frontend' );
// frontend styles
function projectPages_enqueue_frontend(){
// wrecks stuff wp_enqueue_style( 'pp_bootstrap', PROJECTPAGES_URL . 'css/bootstrap/bootstrap.min.css' );
wp_enqueue_style( 'pp_bootstrap', PROJECTPAGES_URL . 'css/bootstrap/bootstrap-grid.min.css' );
wp_enqueue_style( 'project-pages-frontend', plugin_dir_url( __FILE__ ) . 'css/ProjectPages.Frontend.min.css' );
}
// the vue settings app code needs type=module.
add_filter('script_loader_tag', function($tag, $handle, $src) {
if ( 'pp_settings_app_js' !== $handle ) {
return $tag;
}
// change the script tag by adding type="module" and return it.
$tag = '<script type="module" src="' . esc_url( $src ) . '"></script>';
return $tag;
} , 10, 3);
#================== / Init/Admin Enqueuing etc.
#================== Custom Post Types
function projectPages_setupPostTypes() {
global $projectPagesTagsPermaRoot;
$labels = array(
'name' => _x( 'Project Tags', 'Project Tags', 'projectpages' ),
'singular_name' => _x( 'Project Tag', 'Project Tag', 'projectpages' ),
'menu_name' => __( 'Project Tags', 'projectpages' ),
'all_items' => __( 'All Tags', 'projectpages' ),
'parent_item' => __( 'Parent Tag', 'projectpages' ),
'parent_item_colon' => __( 'Parent Tag:', 'projectpages' ),
'new_item_name' => __( 'New Tag Name', 'projectpages' ),
'add_new_item' => __( 'Add Tag Item', 'projectpages' ),
'edit_item' => __( 'Edit Tag', 'projectpages' ),
'update_item' => __( 'Tag Item', 'projectpages' ),
'view_item' => __( 'View Tag', 'projectpages' ),
'separate_items_with_commas' => __( 'Separate Tags with commas', 'projectpages' ),
'add_or_remove_items' => __( 'Add or remove Tags', 'projectpages' ),
'choose_from_most_used' => __( 'Choose from the most used', 'projectpages' ),
'popular_items' => __( 'Popular Tags', 'projectpages' ),
'search_items' => __( 'Search Tags', 'projectpages' ),
'not_found' => __( 'Not Found', 'projectpages' ),
'no_terms' => __( 'No Tags', 'projectpages' ),
'items_list' => __( 'Tags list', 'projectpages' ),
'items_list_navigation' => __( 'Tags list navigation', 'projectpages' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'capabilities' => array(
'manage_terms'=> 'manage_categories',
'edit_terms'=> 'manage_categories',
'delete_terms'=> 'manage_categories',
'assign_terms' => 'read'
),
'rewrite' => array(
'slug' => projectPages_permalink_root() . '/' . $projectPagesTagsPermaRoot,
'with_front' => false
)
);
register_taxonomy( 'projectpagetag', null, $args ); # set as null here, assigned below: array( 'projectpage' )
$labels = array(
'name' => _x( 'Project Pages', 'Project Pages', 'projectpages' ),
'singular_name' => _x( 'Project Page', 'Project Page', 'projectpages' ),
'menu_name' => __( 'Project Pages', 'projectpages' ),
'name_admin_bar' => __( 'Project Pages', 'projectpages' ),
'parent_item_colon' => __( 'Parent Project Page:', 'projectpages' ),
'all_items' => __( 'All Project Pages', 'projectpages' ),
'add_new_item' => __( 'Add New Project Page', 'projectpages' ),
'add_new' => __( 'Add New', 'projectpages' ),
'new_item' => __( 'New Project Page', 'projectpages' ),
'edit_item' => __( 'Edit Project Page', 'projectpages' ),
'update_item' => __( 'Update Project Page', 'projectpages' ),
'view_item' => __( 'View Project Page', 'projectpages' ),
'search_items' => __( 'Search Project Pages', 'projectpages' ),
'not_found' => __( 'No Project Pages Found', 'projectpages' ),
'not_found_in_trash' => __( 'Project Page Not found in Trash', 'projectpages' ),
);
$args = array(
'label' => __( 'Project Page', 'projectpages' ),
'description' => __( 'Project Page', 'projectpages' ),
'labels' => $labels,
'supports' => array(
'title',
'thumbnail',
'taxonomies',
'custom-fields'
),
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-schedule',#plugins_url('/i/icon.png', __FILE__),//'dashicons-tickets',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => false,
'has_archive' => projectPages_permalink_root(),
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'taxonomies' => array('projectpagetag'),
'rewrite' => array(
'slug' => projectPages_permalink_root(),
'with_front' => false
)
);
// **EXPERIMENTAL**
// Gutenberg editing (WIP)
//$args['supports'][] = 'editor';
//$args['show_in_rest'] = true;
register_post_type( 'projectpage', $args );
$labels = array(
'name' => _x( 'Project Logs', 'Project Logs', 'zerobscrm' ),
'singular_name' => _x( 'Project Log', 'Project Log', 'zerobscrm' ),
'menu_name' => __( 'Project Logs', 'zerobscrm' ),
'name_admin_bar' => __( 'Project Log', 'zerobscrm' ),
'archives' => __( 'Project Log Archives', 'zerobscrm' ),
'parent_item_colon' => __( 'Project Log:', 'zerobscrm' ),
'parent' => __( 'Project Log', 'zerobscrm' ),
'all_items' => __( 'All Project Logs', 'zerobscrm' ),
'add_new_item' => __( 'Add New Project Log', 'zerobscrm' ),
'add_new' => __( 'Add New', 'zerobscrm' ),
'new_item' => __( 'New Project Log', 'zerobscrm' ),
'edit_item' => __( 'Edit Project Log', 'zerobscrm' ),
'update_item' => __( 'Update Project Log', 'zerobscrm' ),
'view_item' => __( 'View Project Log', 'zerobscrm' ),
'search_items' => __( 'Search Project Log', 'zerobscrm' ),
'not_found' => __( 'Not found', 'zerobscrm' ),
'not_found_in_trash' => __( 'Not found in Trash', 'zerobscrm' ),
'featured_image' => __( 'Project Log Image', 'zerobscrm' ),
'set_featured_image' => __( 'Set Project Log image', 'zerobscrm' ),
'remove_featured_image' => __( 'Remove Project Log image', 'zerobscrm' ),
'use_featured_image' => __( 'Use as Project Log image', 'zerobscrm' ),
'insert_into_item' => __( 'Insert into Project Log', 'zerobscrm' ),
'uploaded_to_this_item' => __( 'Uploaded to this Project Log', 'zerobscrm' ),
'items_list' => __( 'Project Logs list', 'zerobscrm' ),
'items_list_navigation' => __( 'Project Logs list navigation', 'zerobscrm' ),
'filter_items_list' => __( 'Filter Project Logs list', 'zerobscrm' ),
);
$args = array(
'label' => __( 'Project Log', 'zerobscrm' ),
'description' => __( 'Project Page Log', 'zerobscrm' ),
'labels' => $labels,
'supports' => array( 'thumbnail', 'taxonomies'), #, 'page-attributes'
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false, #zeroBSCRM_getSetting('companylevelcustomers'), // Will be true if b2b on
'public' => true,
'show_ui' => false,
'show_in_menu' => false,
'menu_position' => "5.1",
'menu_icon' => 'dashicons-admin-users',
'show_in_admin_bar' => false,
'show_in_nav_menus' => false,
'can_export' => false,
'has_archive' => false,
'exclude_from_search' => true, #false, # Exclude from front end
'publicly_queryable' => false, #true, , # Exclude from front end
'capability_type' => 'post',
'taxonomies' => array()
);
register_post_type( 'projectpagelog', $args );
}
#================== / Custom Post Types
#================== Templating
/* this is another way around it....
https://stackoverflow.com/questions/72171038/use-gutenberg-block-in-template-with-template-include
function pp_manage_block_templates( $query_result, $query, $template_type ) {
// if template exists, mute this
if ( !file_exists(get_stylesheet_directory().'/templates/single-projectpage.html') ){
// if overriding, don't bother
$use_override_php = projectPages_getSetting('enable_overwrite_templates');
if ( $use_override_php !== "1" ){
$theme = wp_get_theme();
$template_contents = file_get_contents( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/single-projectpage_DEFAULT.html' );
//$template_contents = str_replace( '~theme~', $theme->stylesheet, $template_contents );
$new_block = new WP_Block_Template();
$new_block->type = 'wp_template';
$new_block->theme = $theme->stylesheet;
$new_block->slug = 'single-projectpage';
$new_block->id = $theme->stylesheet . '//single-projectpage';
$new_block->title = 'single-projectpage';
$new_block->description = '';
$new_block->source = 'custom';
$new_block->status = 'publish';
$new_block->has_theme_file = true;
$new_block->is_custom = true;
$new_block->content = $template_contents;
$query_result[] = $new_block;
}
}
return $query_result;
}
//add_filter( 'get_block_templates', 'pP_manage_block_templates', 10, 3 );
*/
# Thank you: http://wordpress.stackexchange.com/questions/17385/custom-post-type-templates-from-plugin-folder
// Note: Changes here need to be reflected in settings function `projectPages_settings_explainers_extend()`
function projectPages_singleProjectTemplate( $single ) {
global $post;
// First check for a post_type match:
if ( $post->post_type == "projectpage" ){
// #legacy template mode - use php variants
if ( projectPages_getSetting('template_mode') == "legacy" ){
$legacy_template = projectPages_discern_single_template_legacy();
if ( $legacy_template ) return $legacy_template;
}
// .... else, default: html gutenberg templates
// If user already has a templated file, use that
if ( file_exists( get_stylesheet_directory() . '/templates/single-projectpage.html' ) ) return $single;
// ... if no override, fallback to our file :)
if ( file_exists( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/single-projectpage_DEFAULT.html' ) ){
// ... as at 2/5/24 there is no legit way to hook in templates into gutenberg via plugin,
// ... so this is a workaround, and it's ugly.
global $_wp_current_template_content;
$_wp_current_template_content = file_get_contents( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/single-projectpage_DEFAULT.html' );
}
}
// else return to single
return $single;
}
add_filter('single_template', 'projectPages_singleProjectTemplate', 99);
// discerns which single #legacy template to use
function projectPages_discern_single_template_legacy(){
// If match, then first check users theme/project-pages/* to see if they've made an override
if ( file_exists( PROJECTPAGES_THEME_TEMPLATE_PATH . '/single-projectpage.php' ) ) return PROJECTPAGES_THEME_TEMPLATE_PATH . '/single-projectpage.php';
// ... if no override, fallback to our file :)
if ( file_exists( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/single-projectpage_DEFAULT.php' ) ) return PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/single-projectpage_DEFAULT.php';
return false;
}
// Note: Changes here need to be reflected in settings function `projectPages_settings_explainers_extend()`
function projectPages_archiveProjectTemplate( $archive_template ) {
global $post;
// First check for a post_type match:
if (
// if posts
( $post && $post->post_type == "projectpage" )
||
// if empty
( wh_get_queried_post_type() == 'projectpage' )
){
// #legacy template mode - use php variants
if ( projectPages_getSetting('template_mode') == "legacy" ){
$legacy_template = projectPages_discern_archive_template_legacy();
if ( $legacy_template ) return $legacy_template;
}
// .... else, default: html gutenberg templates
// If match, then first check users theme/project-pages/* to see if they've made an override
if ( file_exists( get_stylesheet_directory() . '/templates/archive-projectpage.html' ) ) return $archive_template;
// ... if no override, fallback to our file :)
if ( file_exists( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/archive-projectpage_DEFAULT.html' ) ){
// ... as at 2/5/24 there is no legit way to hook in templates into gutenberg via plugin,
// ... so this is a workaround, and it's ugly.
global $_wp_current_template_content;
$_wp_current_template_content = file_get_contents( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/archive-projectpage_DEFAULT.html' );
}
}
// else return passed var
return $archive_template;
}
add_filter('archive_template', 'projectPages_archiveProjectTemplate', 99);
// discerns which archive #legacy template to use
function projectPages_discern_archive_template_legacy(){
// If match, then first check users theme/project-pages/* to see if they've made an override
if ( file_exists( PROJECTPAGES_THEME_TEMPLATE_PATH . '/archive-projectpage.php' ) ) return PROJECTPAGES_THEME_TEMPLATE_PATH . '/archive-projectpage.php';
// ... if no override, fallback to our file :)
if ( file_exists( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/archive-projectpage_DEFAULT.php' ) ) return PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/archive-projectpage_DEFAULT.php';
return false;
}
// THIS NEEDS a higher priority than archive_template :) else that kicks in
// Note: Changes here need to be reflected in settings function `projectPages_settings_explainers_extend()`
function projectPages_taxonomyProjectTemplate( $taxonomy_template ) {
global $post;
// Get the current term object. We will use get_queried_object
$current_term = get_queried_object();
// If the current term does not belong to advert post type, bail
// could also use if ( get_query_var('taxonomy') == "projectpagetag" )
if ( $current_term->taxonomy !== 'projectpagetag' ) return $taxonomy_template;
// #legacy template mode - use php variants
if ( projectPages_getSetting('template_mode') == "legacy" ){
$legacy_template = projectPages_discern_taxonomy_template_legacy();
if ( $legacy_template ) return $legacy_template;
}
// .... else, default: html gutenberg templates
// If match, then first check users theme/project-pages/* to see if they've made an override
if ( file_exists( get_stylesheet_directory() . '/templates/taxonomy-projectpagetag.html' ) ) return $taxonomy_template;
// ... if no override, fallback to our file :)
if ( file_exists( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/taxonomy-projectpagetag_DEFAULT.html' ) ){
// ... as at 2/5/24 there is no legit way to hook in templates into gutenberg via plugin,
// ... so this is a workaround, and it's ugly.
global $_wp_current_template_content;
$_wp_current_template_content = file_get_contents( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/taxonomy-projectpagetag_DEFAULT.html' );
}
// else return passed var
return $taxonomy_template;
}
add_filter('taxonomy_template', 'projectPages_taxonomyProjectTemplate', 99);
// discerns which taxonomy #legacy template to use
function projectPages_discern_taxonomy_template_legacy(){
// If match, then first check users theme/project-pages/* to see if they've made an override
if ( file_exists( PROJECTPAGES_THEME_TEMPLATE_PATH . '/taxonomy-projectpagetag.php' ) ) return PROJECTPAGES_THEME_TEMPLATE_PATH . '/taxonomy-projectpagetag.php';
// ... if no override, fallback to our file :)
if ( file_exists( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/taxonomy-projectpage_DEFAULT.php' ) ) return PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/taxonomy-projectpage_DEFAULT.php';
return false;
}
// Had to write this to do teh above for get_template_part
// ... as no filter to achieve this http://wordpress.stackexchange.com/questions/153004/is-it-possible-to-override-the-result-of-get-template-part
// #legay templating uses this.
function projectPages_get_template_part( $templateName='' ){
// Check for template in our stores:
// First check users theme/project-pages/* to see if they've made an override
if ( file_exists( PROJECTPAGES_THEME_TEMPLATE_PATH . '/'.$templateName.'.php')) { require(PROJECTPAGES_THEME_TEMPLATE_PATH . '/'.$templateName.'.php' ); return; }
// ... if no override, fallback to our file :)
if ( file_exists( PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/'.$templateName.'.php')) { require(PROJECTPAGES_PLUGIN_TEMPLATE_PATH . '/'.$templateName.'.php' ); return; }
// No luck? then fallback to template part:
get_template_part($templateName);
return;
}
#================== / Templating
#================== Admin Pages
// Admin Page header
function projectPages_pages_header($subpage=''){
global $wpdb, $projectPages_urls, $projectPages_version,$projectPages_Settings;
if (!current_user_can('edit_published_pages')) { wp_die( __('You do not have sufficient permissions to access this page.','projectpages') ); }
?>
<div id="sgpBody">
<div class="wrap">
<div id="icon-sb" class="icon32"><br /></div><h2>Project Pages<?php if (!empty($subpage)) echo ': '.$subpage; ?></h2>
</div>
<div id="sgpHeader">
<a href="<?php echo $projectPages_urls['home']; ?>" title="Project Pages" target="_blank">Project Pages</a> |
Version <?php echo $projectPages_version; ?>
</div>
<div id="ProjectPagesAdminPage">
<?php
// Check for required upgrade
#projectPages_checkForUpgrade();
}
// Admin Page footer
function projectPages_pages_footer(){
?></div><?php
}
// welcome page
function projectPages_pages_home() {
if ( !current_user_can( 'edit_published_pages' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.', 'projectpages' ) ); }
if ( !function_exists( 'projectPages_page_welcome' ) ) require_once( PROJECTPAGES_PATH . 'pages/welcome.php' );
// welcome
projectPages_page_welcome();
}
// settings page
function projectPages_pages_settings() {
if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.','projectpages') ); }
if(!function_exists('projectPages_page_settings' ) ) require_once( PROJECTPAGES_PATH . 'pages/settings.php' );
// check if theme is block-based
projectPages_theme_check();
// Settings
projectPages_page_settings();
}
// Main Config page
function projectPages_pages_settings_old() {
global $wpdb, $projectPages_urls, $projectPages_version;
if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.','projectpages') ); }