-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbmlt-workflow.php
More file actions
2025 lines (1752 loc) · 95.6 KB
/
bmlt-workflow.php
File metadata and controls
2025 lines (1752 loc) · 95.6 KB
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
// Copyright (C) 2022 nigel.bmlt@gmail.com
//
// This file is part of bmlt-workflow.
//
// bmlt-workflow is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// bmlt-workflow is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with bmlt-workflow. If not, see <http://www.gnu.org/licenses/>.
/**
* Plugin Name: BMLT Workflow
* Plugin URI: https://github.com/bmlt-enabled/bmlt-workflow
* Description: Workflows for BMLT meeting management!
* Version: 1.1.41
* Requires at least: 5.2
* Tested up to: 6.8.2
* Author: @nigel-bmlt
* Author URI: https://github.com/nigel-bmlt
**/
define('BMLTWF_PLUGIN_VERSION', '1.1.41');
if ((!defined('ABSPATH') && (!defined('BMLTWF_RUNNING_UNDER_PHPUNIT')))) exit; // die if being called directly
require 'config.php';
if (file_exists('vendor/autoload.php')) {
// use composer autoload if we're running under phpunit
include 'vendor/autoload.php';
} else {
// custom autoloader if not. only autoloads out of src directory
spl_autoload_register(function (string $class) {
if (strpos($class, 'bmltwf\\') === 0) {
$class = str_replace('bmltwf\\', '', $class);
require __DIR__ . '/src/' . str_replace('\\', '/', $class) . '.php';
}
});
}
use bmltwf\BMLT\Integration;
use bmltwf\REST\Controller;
use bmltwf\BMLTWF_Database;
use bmltwf\BMLTWF_Rest;
// database configuration
global $wpdb;
if (!class_exists('bmltwf_plugin')) {
class bmltwf_plugin
{
use \bmltwf\BMLTWF_Debug;
use \bmltwf\BMLTWF_Constants;
private Integration $bmlt_integration;
private Controller $BMLTWF_Rest_Controller;
private BMLTWF_Database $BMLTWF_Database;
public function __construct()
{
// Set global debug flag to avoid repeated database calls
global $bmltwf_debug_enabled;
$bmltwf_debug_enabled = (get_option('bmltwf_enable_debug', 'false') === 'true');
// Initialize debug file if debug is enabled
if ($bmltwf_debug_enabled) {
$this->debug_log("BMLT Workflow plugin initialized");
}
// $this->debug_log("bmlt-workflow: Creating new Integration");
$this->bmlt_integration = new Integration();
// $this->debug_log("bmlt-workflow: Creating new Controller");
$this->BMLTWF_Rest_Controller = new Controller();
// $this->debug_log("bmlt-workflow: Creating new BMLTWF_Database");
$this->BMLTWF_Database = new BMLTWF_Database();
// Check database version and upgrade if needed
$this->check_database_version();
// ensure our default options are always available
$this->bmltwf_add_default_options();
// actions, shortcodes, menus and filters
add_action('wp_enqueue_scripts', array(&$this, 'bmltwf_enqueue_form_deps'));
add_action('admin_menu', array(&$this, 'bmltwf_menu_pages'));
add_action('admin_enqueue_scripts', array(&$this, 'bmltwf_admin_scripts'));
add_action('admin_init', array(&$this, 'bmltwf_register_setting'));
add_action('rest_api_init', array(&$this, 'bmltwf_rest_controller'));
add_shortcode('bmltwf-meeting-update-form', array(&$this, 'bmltwf_meeting_update_form'));
add_shortcode('bmltwf-correspondence-form', array(&$this, 'bmltwf_correspondence_form'));
add_filter('plugin_action_links', array(&$this, 'bmltwf_add_plugin_link'), 10, 2);
add_action('user_register', array(&$this, 'bmltwf_add_capability'), 10, 1);
register_activation_hook(__FILE__, array(&$this, 'bmltwf_install'));
}
/**
* Check database version and upgrade if needed
*/
private function check_database_version()
{
$installed_version = get_option('bmltwf_db_version');
$current_version = $this->BMLTWF_Database->bmltwf_db_version;
if ($installed_version === false || version_compare($installed_version, $current_version, '<')) {
$this->debug_log("Database upgrade needed from {$installed_version} to {$current_version}");
$result = $this->BMLTWF_Database->bmltwf_db_upgrade($current_version, false);
if ($result === 2) {
$this->debug_log("Database upgraded successfully");
} elseif ($result === 1) {
$this->debug_log("Database fresh install completed");
} else {
$this->debug_log("No database changes needed");
}
}
}
public function bmltwf_load_textdomain()
{
$domain = 'bmlt-workflow';
$locale = get_locale();
$mofile = dirname(plugin_basename(__FILE__)) . '/lang/' . $domain . '-' . $locale . '.mo';
$path = plugin_dir_path(__FILE__) . 'lang/' . $domain . '-' . $locale . '.mo';
// Debug output
error_log("BMLTWF Debug - Locale: " . $locale);
error_log("BMLTWF Debug - MO file path: " . $path);
error_log("BMLTWF Debug - MO file exists: " . (file_exists($path) ? 'YES' : 'NO'));
$result = load_plugin_textdomain($domain, false, dirname(plugin_basename(__FILE__)) . '/lang');
error_log("BMLTWF Debug - load_plugin_textdomain result: " . ($result ? 'SUCCESS' : 'FAILED'));
// Test translation
$test = __('New Meeting', $domain);
error_log("BMLTWF Debug - Translation test: " . $test);
}
public function bmltwf_correspondence_form($atts = [], $content = null, $tag = '')
{
// Enqueue required scripts
wp_enqueue_script('wp-i18n');
$this->prevent_cache_enqueue_script('bmltwf-correspondence-form-js', array('jquery', 'wp-i18n'), 'js/correspondence_form.js');
$this->prevent_cache_enqueue_style('bmltwf-correspondence-form-css', false, 'css/correspondence_form.css');
// Set up translations
wp_set_script_translations('bmltwf-correspondence-form-js', 'bmlt-workflow', plugin_dir_path(__FILE__) . 'lang/');
// Get thread ID from URL parameter
$thread_id = isset($_GET['thread']) ? sanitize_text_field($_GET['thread']) : '';
// Localize script with REST API URL and thread ID
wp_localize_script('bmltwf-correspondence-form-js', 'bmltwf_correspondence_data', array(
'rest_url' => esc_url_raw(rest_url($this->bmltwf_rest_namespace . '/correspondence/thread/' . $thread_id)),
'thread_id' => $thread_id,
'nonce' => wp_create_nonce('wp_rest'),
'submission_rest_url' => esc_url_raw(rest_url($this->bmltwf_rest_namespace . '/submissions/')),
'i18n' => array(
'loading' => __('Loading correspondence...', 'bmlt-workflow'),
'error' => __('Error loading correspondence. Please check the URL and try again.', 'bmlt-workflow'),
'reply' => __('Reply', 'bmlt-workflow'),
'send' => __('Send', 'bmlt-workflow'),
'cancel' => __('Cancel', 'bmlt-workflow'),
'your_reply' => __('Your reply...', 'bmlt-workflow'),
'reply_sent' => __('Your reply has been sent.', 'bmlt-workflow'),
'reply_error' => __('Error sending reply. Please try again.', 'bmlt-workflow'),
)
));
include_once('public/correspondence_form.php');
return bmltwf_correspondence_form_shortcode($atts);
}
public function bmltwf_meeting_update_form($atts = [], $content = null, $tag = '')
{
$bmltwf_bmlt_test_status = get_option('bmltwf_bmlt_test_status', "failure");
if ($bmltwf_bmlt_test_status != "success") {
wp_die("<h4>BMLTWF Plugin Error: BMLT Root Server not configured and tested.</h4>");
}
// $this->debug_log(("inside shortcode setup"));
// base css and js for this page
$this->prevent_cache_enqueue_script('bmltwf-meeting-update-form-js', array('jquery', 'wp-i18n'), 'js/meeting_update_form.js');
$this->prevent_cache_enqueue_style('bmltwf-meeting-update-form-css', false, 'css/meeting_update_form.css');
$this->prevent_cache_enqueue_script('bmltwf-general-js', array('jquery', 'wp-i18n'), 'js/script_includes.js');
wp_enqueue_style('dashicons');
// jquery validation
wp_enqueue_script('jqueryvalidate');
wp_enqueue_script('jqueryvalidateadditional');
// select2
$this->enqueue_select2();
// inline scripts
$script = 'var bmltwf_form_submit_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/submissions') . '; ';
$script .= 'var bmltwf_bmltserver_meetings_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/bmltserver/meetings') . '; ';
// optional fields
$script .= 'var bmltwf_optional_location_nation = "' . get_option('bmltwf_optional_location_nation') . '";';
$script .= 'var bmltwf_optional_location_sub_province = "' . get_option('bmltwf_optional_location_sub_province') . '";';
$script .= 'var bmltwf_optional_location_province = "' . get_option('bmltwf_optional_location_province') . '";';
$script .= 'var bmltwf_optional_postcode = "' . get_option('bmltwf_optional_postcode') . '";';
$script .= 'var bmltwf_fso_feature = "' . get_option('bmltwf_fso_feature') . '";';
$script .= 'var bmltwf_meeting_sort_order = "' . get_option('bmltwf_meeting_sort_order') . '";';
// add counties/states/provinces if they are populated
$meeting_counties_and_sub_provinces = $this->bmlt_integration->getMeetingCounties();
if (is_wp_error($meeting_counties_and_sub_provinces)) {
wp_die("<h4>" . __('BMLTWF Plugin Error: Unable to retrieve meeting counties from BMLT server.', 'bmlt-workflow') . "</h4>");
}
$script .= "var bmltwf_counties_and_sub_provinces = " . json_encode($meeting_counties_and_sub_provinces) . ";";
if ($meeting_counties_and_sub_provinces) {
$script .= json_encode($meeting_counties_and_sub_provinces) . ";";
} else {
$script .= "false;";
}
$meeting_states_and_provinces = $this->bmlt_integration->getMeetingStates();
if (is_wp_error($meeting_states_and_provinces)) {
wp_die("<h4>" . __('BMLTWF Plugin Error: Unable to retrieve meeting states/provinces from BMLT server.', 'bmlt-workflow') . "</h4>");
}
$script .= "var bmltwf_do_states_and_provinces = " . json_encode($meeting_states_and_provinces) . ";";
if ($meeting_states_and_provinces) {
$script .= json_encode($meeting_states_and_provinces) . ";";
} else {
$script .= "false;";
}
$formatarr = $this->bmlt_integration->getMeetingFormats();
if (is_wp_error($formatarr)) {
wp_die("<h4>" . __('BMLTWF Plugin Error: Unable to retrieve meeting formats from BMLT server.', 'bmlt-workflow') . "</h4>");
}
// $this->debug_log("FORMATS");
// $this->debug_log($formatarr);
// $this->debug_log(json_encode($formatarr));
$script .= 'var bmltwf_bmlt_formats = ' . json_encode($formatarr) . '; ';
// do a one off lookup for our servicebodies
$url = '/' . $this->bmltwf_rest_namespace . '/servicebodies';
// $this->debug_log("rest url = " . $url);
$request = new WP_REST_Request('GET', $url);
$response = rest_do_request($request);
$result = rest_get_server()->response_to_data($response, true);
if (count($result) == 0) {
wp_die("<h4>BMLT Workflow Plugin Error: Service bodies not configured.</h4>");
}
$script .= 'var bmltwf_service_bodies = ' . json_encode($result) . '; ';
$status = wp_add_inline_script('bmltwf-meeting-update-form-js', $script, 'before');
$a = wp_set_script_translations('bmltwf-meeting-update-form-js', 'bmlt-workflow', plugin_dir_path(__FILE__) . 'lang/');
if ($a === true) {
$this->debug_log("script translation succeeded");
} else {
$this->debug_log("script translation failed");
}
ob_start();
include('public/meeting_update_form.php');
$content .= ob_get_clean();
return $content;
}
private function prevent_cache_register_script($handle, $deps, $name)
{
wp_register_script($handle, plugin_dir_url(__FILE__) . $name, $deps, filemtime(plugin_dir_path(__FILE__) . $name), true);
}
private function prevent_cache_register_style($handle, $deps, $name)
{
$ret = wp_register_style($handle, plugin_dir_url(__FILE__) . $name, $deps, filemtime(plugin_dir_path(__FILE__) . $name), 'all');
}
private function prevent_cache_enqueue_script($handle, $deps, $name)
{
$ret = wp_enqueue_script($handle, plugin_dir_url(__FILE__) . $name, $deps, filemtime(plugin_dir_path(__FILE__) . $name), true);
}
private function prevent_cache_enqueue_style($handle, $deps, $name)
{
$ret = wp_enqueue_style($handle, plugin_dir_url(__FILE__) . $name, $deps, filemtime(plugin_dir_path(__FILE__) . $name), 'all');
}
private function register_select2()
{
wp_register_style('select2css', plugin_dir_url(__FILE__) . '/thirdparty/css/select2@4.1.0-rc.0/dist/css/select2.min.css', false, '1.0', 'all');
wp_register_script('select2', plugin_dir_url(__FILE__) . '/thirdparty/js/select2@4.1.0-rc.0/dist/js/select2.min.js', array('jquery'), '1.0', true);
}
private function enqueue_select2()
{
wp_enqueue_style('select2css');
wp_enqueue_script('select2');
}
private function enqueue_jquery_dialog()
{
// jquery dialogs
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_style('wp-jquery-ui-dialog');
}
public function bmltwf_enqueue_form_deps()
{
$this->register_select2();
wp_register_script('jqueryvalidate', plugin_dir_url(__FILE__) . '/thirdparty/js/jquery-validation@1.19.3/dist/jquery.validate.min.js', array('jquery'), '1.0', true);
wp_register_script('jqueryvalidateadditional', plugin_dir_url(__FILE__) . '/thirdparty/js/jquery-validation@1.19.3/dist/additional-methods.min.js', array('jquery', 'jqueryvalidate'), '1.0', true);
$this->prevent_cache_register_script('bmltwf-general-js', array('jquery', 'wp-i18n'), 'js/script_includes.js');
$this->prevent_cache_register_script('bmltwf-meeting-update-form-js', array('jquery', 'jqueryvalidate', 'jqueryvalidateadditional', 'wp-i18n'), 'js/meeting_update_form.js');
$this->prevent_cache_register_style('bmltwf-meeting-update-form-css', false, 'css/meeting_update_form.css');
$this->debug_log("scripts and styles registered");
}
public function bmltwf_admin_scripts($hook)
{
$this->debug_log("admin scripts");
$this->debug_log($hook);
if (($hook != 'toplevel_page_bmltwf-settings') && ($hook != 'bmlt-workflow_page_bmltwf-options') && ($hook != 'toplevel_page_bmltwf-submissions') && ($hook != 'bmlt-workflow_page_bmltwf-submissions') && ($hook != 'bmlt-workflow_page_bmltwf-service-bodies')) {
return;
}
$this->prevent_cache_enqueue_script('bmltwfjs', array('jquery', 'wp-i18n'), 'js/script_includes.js');
switch ($hook) {
case ('toplevel_page_bmltwf-settings'):
case ('bmlt-workflow_page_bmltwf-options'):
// base css and scripts for this page
$this->prevent_cache_enqueue_style('bmltwf-admin-css', false, 'css/admin_options.css');
$this->prevent_cache_enqueue_script('bmltwf-admin-options-js', array('jquery', 'wp-i18n'), 'js/admin_options.js');
// clipboard
wp_enqueue_script('clipboard');
// jquery dialog
$this->enqueue_jquery_dialog();
// inline scripts
$script = 'var bmltwf_admin_bmltserver_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/bmltserver') . '; ';
$script .= 'var bmltwf_admin_backup_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/options/backup') . '; ';
$script .= 'var bmltwf_admin_restore_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/options/restore') . '; ';
$script .= 'var bmltwf_admin_debuglog_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/options/debug') . '; ';
$script .= 'var bmltwf_admin_correspondence_page_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/options/correspondence-page') . '; ';
$script .= 'var bmltwf_admin_bmltwf_service_bodies_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/servicebodies') . '; ';
$script .= 'var bmltwf_fso_feature = "' . get_option('bmltwf_fso_feature') . '";';
$script .= 'var bmltwf_google_maps_key_select = ';
$google_maps_key = get_option('bmltwf_google_maps_key', '');
if ($google_maps_key === '') {
$script .= '"bmlt_key";';
} else {
$script .= '"your_own_key";';
}
wp_add_inline_script('bmltwf-admin-options-js', $script, 'before');
wp_set_script_translations('bmltwf-admin-options-js', 'bmlt-workflow', plugin_dir_path(__FILE__) . 'lang/');
break;
case ('bmlt-workflow_page_bmltwf-submissions'):
case ('toplevel_page_bmltwf-submissions'):
// base css and scripts for this page
$this->prevent_cache_enqueue_script('bmltwf-admin-submissions-js', array('jquery', 'wp-i18n'), 'js/admin_submissions.js');
$this->prevent_cache_enqueue_style('bmltwf-admin-submissions-css', false, 'css/admin_submissions.css');
// jquery dialog
$this->enqueue_jquery_dialog();
// datatables
wp_register_style('dtcss', plugin_dir_url(__FILE__) . 'thirdparty/DataTables/datatables.min.css', false, '1.0', 'all');
wp_register_script('dt', plugin_dir_url(__FILE__) . 'thirdparty/DataTables/datatables.min.js', array('jquery'), '1.0', true);
wp_enqueue_style('dtcss');
wp_enqueue_script('dt');
// select2 for quick editor
$this->register_select2();
$this->enqueue_select2();
// make sure our rest urls are populated
$script = 'var bmltwf_admin_submissions_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/submissions/') . '; ';
$script .= 'var bmltwf_bmltserver_geolocate_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/bmltserver/geolocate') . '; ';
// add our bmlt server for the submission lookups
$script .= 'var bmltwf_bmlt_server_address = "' . get_option('bmltwf_bmlt_server_address') . '";';
$script .= 'var bmltwf_remove_virtual_meeting_details_on_venue_change = "' . get_option('bmltwf_remove_virtual_meeting_details_on_venue_change') . '";';
$script .= 'var bmltwf_optional_location_sub_province_displayname = "' . sanitize_text_field(get_option('bmltwf_optional_location_sub_province_displayname')) . '";';
$script .= 'var bmltwf_optional_location_province_displayname = "' . sanitize_text_field(get_option('bmltwf_optional_location_province_displayname')) . '";';
$script .= 'var bmltwf_optional_location_postal_code_1_displayname = "' . sanitize_text_field(get_option('bmltwf_optional_postcode_displayname')) . '";';
$script .= 'var bmltwf_optional_location_nation_displayname = "' . sanitize_text_field(get_option('bmltwf_optional_location_nation_displayname')) . '";';
// add counties/states/provinces if they are populated
$meeting_counties_and_sub_provinces = $this->bmlt_integration->getMeetingCounties();
$script .= "var bmltwf_counties_and_sub_provinces = " . json_encode($meeting_counties_and_sub_provinces) . ";";
$meeting_states_and_provinces = $this->bmlt_integration->getMeetingStates();
$script .= "var bmltwf_do_states_and_provinces = " . json_encode($meeting_states_and_provinces) . ";";
// handling for zip and county auto geocoding
$script .= "var bmltwf_zip_auto_geocoding = " . json_encode($this->bmlt_integration->isAutoGeocodingEnabled('zip')) . ";";
$script .= "var bmltwf_county_auto_geocoding = " . json_encode($this->bmlt_integration->isAutoGeocodingEnabled('county')) . ";";
// add meeting formats
$formatarr = $this->bmlt_integration->getMeetingFormats();
$script .= 'var bmltwf_bmlt_formats = ' . json_encode($formatarr) . '; ';
// do a one off lookup for our servicebodies
$url = '/' . $this->bmltwf_rest_namespace . '/servicebodies';
$request = new WP_REST_Request('GET', $url);
$response = rest_do_request($request);
$result = rest_get_server()->response_to_data($response, true);
$script .= 'var bmltwf_admin_bmltwf_service_bodies = ' . json_encode($result) . '; ';
// defaults for approve close form
$bmltwf_default_closed_meetings = get_option('bmltwf_delete_closed_meetings');
$script .= 'var bmltwf_default_closed_meetings = "' . $bmltwf_default_closed_meetings . '"; ';
// optional fields in quickedit
$script .= 'var bmltwf_optional_location_nation = "' . get_option('bmltwf_optional_location_nation') . '";';
$script .= 'var bmltwf_optional_location_sub_province = "' . get_option('bmltwf_optional_location_sub_province') . '";';
$script .= 'var bmltwf_optional_location_province = "' . get_option('bmltwf_optional_location_province') . '";';
$script .= 'var bmltwf_optional_postcode = "' . get_option('bmltwf_optional_postcode') . '";';
$key = $this->bmlt_integration->getGmapsKey();
if (\is_wp_error($key)) {
$key = "";
} else {
$script .= 'var bmltwf_gmaps_key = "' . $key . '";';
}
$script .= 'var bmltwf_auto_geocoding_enabled = ' . json_encode($this->bmlt_integration->isAutoGeocodingEnabled('auto')) . ';';
// can current user use the delete button?
$show_delete = "false";
if (get_option('bmltwf_trusted_servants_can_delete_submissions') == 'true') {
$show_delete = "true";
} else if (current_user_can('manage_options')) {
$show_delete = "true";
}
$script .= 'var bmltwf_datatables_delete_enabled = ' . $show_delete . ';';
// correspondence page configuration
$correspondence_page_id = get_option('bmltwf_correspondence_page');
$correspondence_enabled = 'false';
if (!empty($correspondence_page_id)) {
$page = get_post($correspondence_page_id);
if ($page && $page->post_status === 'publish' && has_shortcode($page->post_content, 'bmltwf-correspondence-form')) {
$correspondence_enabled = 'true';
}
}
$script .= 'var bmltwf_correspondence_enabled = ' . $correspondence_enabled . ';';
wp_add_inline_script('bmltwf-admin-submissions-js', $script, 'before');
wp_set_script_translations('bmltwf-admin-submissions', 'bmlt-workflow', plugin_dir_path(__FILE__) . 'lang/');
break;
case ('bmlt-workflow_page_bmltwf-service-bodies'):
// base css and scripts for this page
$this->prevent_cache_enqueue_script('bmltwf-admin-service-bodies-js', array('jquery', 'wp-i18n'), 'js/admin_service_bodies.js');
$this->prevent_cache_enqueue_style('bmltwf-admin-submissions-css', false, 'css/admin_service_bodies.css');
// select2
$this->register_select2();
$this->enqueue_select2();
// make sure our rest url is populated
$script = 'var bmltwf_admin_bmltwf_service_bodies_rest_url = ' . json_encode(get_rest_url() . $this->bmltwf_rest_namespace . '/servicebodies') . '; ';
$script .= 'var wp_users_url = ' . json_encode(get_rest_url() . 'wp/v2/users') . '; ';
wp_add_inline_script('bmltwf-admin-service-bodies-js', $script, 'before');
wp_set_script_translations('bmltwf-admin-service-bodies-js', 'bmlt-workflow', plugin_dir_path(__FILE__) . 'lang/');
break;
}
}
public function bmltwf_menu_pages()
{
$toplevelslug = 'bmltwf-settings';
// if we're just a submission editor, make our submissions page the landing page
if (!current_user_can('manage_options') && (current_user_can($this->bmltwf_capability_manage_submissions))) {
$toplevelslug = 'bmltwf-submissions';
}
// give our admins the view capability on the fly
if (current_user_can('manage_options') && (!current_user_can($this->bmltwf_capability_manage_submissions))) {
global $current_user;
$current_user->add_cap($this->bmltwf_capability_manage_submissions);
}
// $this->debug_log("slug = ".$toplevelslug);
add_menu_page(
'BMLT Workflow',
'BMLT Workflow',
$this->bmltwf_capability_manage_submissions,
$toplevelslug,
'',
'dashicons-analytics',
null
);
add_submenu_page(
'bmltwf-settings',
__('Configuration', 'bmlt-workflow'),
__('Configuration', 'bmlt-workflow'),
'manage_options',
'bmltwf-options',
array(&$this, 'display_bmltwf_admin_options_page'),
2
);
add_submenu_page(
'bmltwf-settings',
__('Workflow Submissions', 'bmlt-workflow'),
__('Workflow Submissions', 'bmlt-workflow'),
$this->bmltwf_capability_manage_submissions,
'bmltwf-submissions',
array(&$this, 'display_bmltwf_admin_submissions_page'),
2
);
add_submenu_page(
'bmltwf-settings',
__('Service Bodies', 'bmlt-workflow'),
__('Service Bodies', 'bmlt-workflow'),
'manage_options',
'bmltwf-service-bodies',
array(&$this, 'display_bmltwf_admin_service_bodies_page'),
2
);
if (!current_user_can('manage_options') && (current_user_can($this->bmltwf_capability_manage_submissions))) {
remove_menu_page('bmltwf-settings');
}
// Remove the duplicate submenu item that WordPress automatically creates
remove_submenu_page('bmltwf-settings', 'bmltwf-settings');
}
public function bmltwf_add_plugin_link($plugin_actions, $plugin_file)
{
$new_actions = array();
if (basename(plugin_dir_path(__FILE__)) . '/bmlt-workflow.php' === $plugin_file) {
$new_actions['cl_settings'] = sprintf('<a href="%s">Settings</a>', esc_url(admin_url('admin.php?page=bmltwf-options')));
}
return array_merge($new_actions, $plugin_actions);
}
public function bmltwf_rest_controller()
{
$this->BMLTWF_Rest_Controller->register_routes();
}
public function bmltwf_register_setting()
{
if (!current_user_can('activate_plugins')) {
return;
}
$this->debug_log("registering settings");
register_setting(
'bmltwf-settings-group',
'bmltwf_email_from_address',
array(
'type' => 'string',
'description' => __('Email from address', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_email_from_address_sanitize_callback'),
'show_in_rest' => false,
'default' => 'example@example.com'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_google_maps_key',
array(
'type' => 'string',
'description' => __('Google maps key', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_google_maps_key_sanitize_callback'),
'show_in_rest' => false,
'default' => ''
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_delete_closed_meetings',
array(
'type' => 'string',
'description' => __('Default behaviour when closing meetings', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_delete_closed_meetings_sanitize_callback'),
'show_in_rest' => false,
'default' => 'unpublish'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_trusted_servants_can_delete_submissions',
array(
'type' => 'string',
'description' => __('Trusted servants can delete submissions', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_trusted_servants_can_delete_submissions_sanitize_callback'),
'show_in_rest' => false,
'default' => 'false'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_remove_virtual_meeting_details_on_venue_change',
array(
'type' => 'string',
'description' => __('Remove virtual meeting details on venue change', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_remove_virtual_meeting_details_on_venue_change_sanitize_callback'),
'show_in_rest' => false,
'default' => 'false'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_enable_debug',
array(
'type' => 'string',
'description' => __('Enable debug logging', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_enable_debug_sanitize_callback'),
'show_in_rest' => false,
'default' => 'false'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_correspondence_page',
array(
'type' => 'string',
'description' => __('Correspondence page for email links', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_correspondence_page_sanitize_callback'),
'show_in_rest' => false,
'default' => ''
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_optional_location_nation',
array(
'type' => 'string',
'description' => __('Option to enable displaying nation field to end users', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_optional_location_nation_sanitize_callback'),
'show_in_rest' => false,
'default' => 'hidden'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_optional_location_nation_displayname',
array(
'type' => 'string',
'description' => __('Display name for nation field', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_textstring_sanitize_callback'),
'show_in_rest' => false,
'default' => 'Nation'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_optional_location_sub_province',
array(
'type' => 'string',
'description' => __('Option to enable displaying subprovince field to end users', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_optional_location_sub_province_sanitize_callback'),
'show_in_rest' => false,
'default' => 'hidden'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_optional_location_sub_province_displayname',
array(
'type' => 'string',
'description' => __('Display name for subprovince field', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_textstring_sanitize_callback'),
'show_in_rest' => false,
'default' => 'Sub Province'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_optional_location_province',
array(
'type' => 'string',
'description' => __('optional field for location_province', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_optional_location_province_sanitize_callback'),
'show_in_rest' => false,
'default' => 'display'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_optional_location_province_displayname',
array(
'type' => 'string',
'description' => __('optional field for location_province', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_textstring_sanitize_callback'),
'show_in_rest' => false,
'default' => 'Province'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_optional_postcode',
array(
'type' => 'string',
'description' => __('optional field for postcode', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_optional_postcode_sanitize_callback'),
'show_in_rest' => false,
'default' => 'display'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_optional_postcode_displayname',
array(
'type' => 'string',
'description' => __('optional field for postcode', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_textstring_sanitize_callback'),
'show_in_rest' => false,
'default' => 'Postcode'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_required_meeting_formats',
array(
'type' => 'string',
'description' => __('required field for meeting format', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_required_meeting_formats_sanitize_callback'),
'show_in_rest' => false,
'default' => 'true'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_submitter_email_template',
array(
'type' => 'string',
'description' => __('Email template for submitter', 'bmlt-workflow'),
'sanitize_callback' => null,
'show_in_rest' => false,
'default' => file_get_contents(BMLTWF_PLUGIN_DIR . 'templates/default_submitter_email_template.html')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_submitter_email_subject',
array(
'type' => 'string',
'description' => __('Email subject for submitter notifications', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_textstring_sanitize_callback'),
'show_in_rest' => false,
'default' => __('NA Meeting Change Request Acknowledgement - Submission ID {field:change_id}', 'bmlt-workflow')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_fso_feature',
array(
'type' => 'string',
'description' => __('Toggle for FSO feature', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_fso_feature_sanitize_callback'),
'show_in_rest' => false,
'default' => 'display'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_fso_email_template',
array(
'type' => 'string',
'description' => __('Email template for FSO', 'bmlt-workflow'),
'sanitize_callback' => null,
'show_in_rest' => false,
'default' => file_get_contents(BMLTWF_PLUGIN_DIR . 'templates/default_fso_email_template.html')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_fso_email_subject',
array(
'type' => 'string',
'description' => __('Email subject for FSO notifications', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_textstring_sanitize_callback'),
'show_in_rest' => false,
'default' => __('Starter Kit Request', 'bmlt-workflow')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_fso_email_address',
array(
'type' => 'string',
'description' => __('FSO email address', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_fso_email_address_sanitize_callback'),
'show_in_rest' => false,
'default' => 'example@example.com'
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_correspondence_submitter_email_template',
array(
'type' => 'string',
'description' => __('Email template for correspondence notifications to submitters', 'bmlt-workflow'),
'sanitize_callback' => null,
'show_in_rest' => false,
'default' => file_get_contents(BMLTWF_PLUGIN_DIR . 'templates/default_correspondence_submitter_email_template.html')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_correspondence_submitter_email_subject',
array(
'type' => 'string',
'description' => __('Email subject for correspondence notifications to submitters', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_textstring_sanitize_callback'),
'show_in_rest' => false,
'default' => __('New correspondence about your meeting submission', 'bmlt-workflow')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_correspondence_admin_email_template',
array(
'type' => 'string',
'description' => __('Email template for correspondence notifications to admins', 'bmlt-workflow'),
'sanitize_callback' => null,
'show_in_rest' => false,
'default' => file_get_contents(BMLTWF_PLUGIN_DIR . 'templates/default_correspondence_admin_email_template.html')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_correspondence_admin_email_subject',
array(
'type' => 'string',
'description' => __('Email subject for correspondence notifications to admins', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_textstring_sanitize_callback'),
'show_in_rest' => false,
'default' => __('New correspondence received - Submission ID {field:change_id}', 'bmlt-workflow')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_admin_notification_email_template',
array(
'type' => 'string',
'description' => __('Email template for admin notifications of new submissions', 'bmlt-workflow'),
'sanitize_callback' => null,
'show_in_rest' => false,
'default' => file_get_contents(BMLTWF_PLUGIN_DIR . 'templates/default_admin_notification_email_template.html')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_admin_notification_email_subject',
array(
'type' => 'string',
'description' => __('Email subject for admin notifications of new submissions', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_textstring_sanitize_callback'),
'show_in_rest' => false,
'default' => __('[bmlt-workflow] {field:submission_type} request received - {field:service_body_name} - Change ID #{field:change_id}', 'bmlt-workflow')
)
);
register_setting(
'bmltwf-settings-group',
'bmltwf_meeting_sort_order',
array(
'type' => 'string',
'description' => __('Meeting sort order in meeting update form', 'bmlt-workflow'),
'sanitize_callback' => array(&$this, 'bmltwf_meeting_sort_order_sanitize_callback'),
'show_in_rest' => false,
'default' => 'alphabetical'
)
);
// Create separate sections for each tab
add_settings_section(
'bmltwf-bmlt-config-section',
'',
'',
'bmltwf-bmlt-config'
);
add_settings_section(
'bmltwf-form-settings-section',
'',
'',
'bmltwf-form-settings'
);
add_settings_section(
'bmltwf-email-templates-section',
'',
'',
'bmltwf-email-templates'
);
add_settings_section(
'bmltwf-advanced-section',
'',
'',
'bmltwf-advanced'
);
// BMLT Configuration Tab
add_settings_field(
'bmltwf_bmlt_server_address',
__('BMLT Root Server Configuration', 'bmlt-workflow'),
array(&$this, 'bmltwf_bmlt_server_address_html'),
'bmltwf-bmlt-config',
'bmltwf-bmlt-config-section'
);
add_settings_field(
'bmltwf_geocoding',
__('Auto Geocoding Root Server Settings', 'bmlt-workflow'),
array(&$this, 'bmltwf_auto_geocoding_enabled_html'),
'bmltwf-bmlt-config',
'bmltwf-bmlt-config-section'
);
add_settings_field(
'bmltwf_google_maps_key',
__('Google Maps Key', 'bmlt-workflow'),
array(&$this, 'bmltwf_google_maps_key_html'),
'bmltwf-bmlt-config',
'bmltwf-bmlt-config-section'
);
// Form Settings Tab
add_settings_field(
'bmltwf_shortcode',
__('Meeting Update Form Shortcode', 'bmlt-workflow'),
array(&$this, 'bmltwf_shortcode_html'),
'bmltwf-form-settings',
'bmltwf-form-settings-section'
);
add_settings_field(
'bmltwf_optional_form_fields',
__('Optional form fields', 'bmlt-workflow'),
array(&$this, 'bmltwf_optional_form_fields_html'),
'bmltwf-form-settings',
'bmltwf-form-settings-section'
);