-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordquest.php
3790 lines (3338 loc) · 153 KB
/
wordquest.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
// ===============================
// === WORDQUEST PLUGIN HELPER ===
// ===============================
$wordquestversion = '1.8.2';
// === Notes ===
// - Changelog at end of this file
// - Requires PHP 5.3 (for anonymous functions)
// -- (helper library load bypassed if not met)
// WordQuest Admin Menu Position
// -----------------------------
// Note: wordquest_menu_position filter is called in wordquest plugins - not in helper
// Example override (use in Child Theme functions.php or /wp-content/mu-plugins/):
//
// if (!has_filter('wordquest_menu_position', 'custom_wordquest_menu_position')) {
// add_filter('wordquest_menu_position', 'custom_wordquest_menu_position');
// }
// if (!function_exists('custom_wordquest_menu_position')) {
// function custom_wordquest_menu_position() {
// return '10'; // numeric menu priority (defaults to 3)
// }
// }
// Development TODOs
// -----------------
// TODO: handle Freemius plugin add-ons ?
// ? add collapse/expand buttons to righthand sidebar
// -------------------------------------------------
// Require PHP 5.3 Minimum (for Anonymous Functions)
// -------------------------------------------------
if ( version_compare( PHP_VERSION, '5.3.0' ) < 0 ) {
return;
}
// ---------------------------------
// Set this Wordquest Helper version
// ---------------------------------
// 1.6.0: wqv to wqhv for new variable functions
// 1.6.6: move wordquestversion to top for easy changing
$wqhv = str_replace( '.', '', $wordquestversion );
// --------------------
// Set Global Site URLs
// --------------------
// 1.6.5: added for clearer/cleaner usage
// 1.7.7: added https protocol to links
global $wqurls;
$wqurls = array(
'wp' => 'https://wordpress.org',
'wq' => 'https://wordquest.org',
'wpm' => 'https://wpmedic.tech',
'prn' => 'https://pluginreview.net',
'bio' => 'https://bioship.space',
);
// ------------------------
// Set Debug Switch Default
// ------------------------
// 1.6.6: set debug switch to off to recheck later
global $wqdebug;
$wqdebug = false;
// -----------------------------------------
// === Version Handling Loader Functions ===
// -----------------------------------------
// ...future proof helper update library...
// ----------------------------------
// Add Helper version to global array
// ----------------------------------
// 1.6.0: change globals to use new variable functions (as not backcompatible!)
global $wordquesthelpers, $wqfunctions;
if ( !is_array( $wordquesthelpers ) ) {
$wordquesthelpers = array( $wqhv );
} elseif ( !in_array( $wqhv, $wordquesthelpers ) ) {
$wordquesthelpers[] = $wqhv;
}
// ------------------------------------------
// Set Latest Wordquest Version on Admin Load
// ------------------------------------------
// 1.5.0: use admin_init not plugins_loaded so as to be usable by themes
// 1.8.0: remove unnecessary third parameter
if ( !has_action( 'admin_init', 'wqhelper_admin_loader' ) ) {
add_action( 'admin_init', 'wqhelper_admin_loader', 1 );
}
if ( !function_exists( 'wqhelper_admin_loader' ) ) {
function wqhelper_admin_loader() {
global $wqdebug;
// --- maybe set debug mode ---
// 1.6.6: check debug switch here so we can check permissions
if ( current_user_can( 'manage_options' ) ) {
// 1.8.1: use sanitize_text_field on request variable
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_REQUEST['wqdebug'] ) && in_array( sanitize_title( $_REQUEST['wqdebug'] ), array( '1', 'yes' ) ) ) {
$wqdebug = true;
}
}
// --- maybe remove old action ---
// 1.6.0: maybe remove the pre 1.6.0 loader action
if ( has_action( 'admin_init', 'wordquest_admin_load' ) ) {
remove_action( 'admin_init', 'wordquest_admin_load' );
}
// --- set helper version to use ---
// 1.6.0: new globals used for new method
global $wordquesthelper, $wordquesthelpers;
$wordquesthelper = max( $wordquesthelpers );
if ( $wqdebug ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions
echo "<!-- WQ Helper Versions: " . esc_html( print_r( $wordquesthelpers, true ) ) . " -->";
echo "<!-- Latest Version: " . esc_html( $wordquesthelper ) . " -->";
}
// --- load callable functions ---
// 1.6.0: set the function caller helper
global $wqcaller, $wqfunctions;
$functionname = 'wqhelper_caller_';
$func = $functionname . $wordquesthelper;
if ( $wqdebug ) {
echo "<!-- Caller Name: " . esc_html( $func ) . " -->";
}
// --- set callable functions ---
if ( is_callable( $wqfunctions[$func] ) ) {
$wqfunctions[$func]( $functionname );
} elseif ( function_exists( $func ) ) {
call_user_func( $func, $functionname );
}
if ( $wqdebug ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions
echo "<!-- Caller Object: " . esc_html( print_r( $wqcaller, true ) ) . " -->";
}
// --- load admin notices ---
// 1.5.0: set up any admin notices via helper version
// 1.6.0: ...use caller function directly for this
$adminnotices = 'wqhelper_admin_notices';
if ( is_callable( $wqcaller ) ) {
$wqcaller( $adminnotices );
} elseif ( function_exists( $adminnotices ) ) {
call_user_func( $adminnotices );
}
}
}
// ----------------------------------
// Function to Define Function Caller
// ----------------------------------
// 1.6.0: some lovely double abstraction here!
$funcname = 'wqhelper_caller_' . $wqhv;
if ( !isset( $wqfunctions[$funcname] ) || !is_callable( $wqfunctions[$funcname] ) ) {
$wqfunctions[$funcname] = function( $func ) {
global $wqfunctions, $wqcaller;
if ( !is_callable( $wqcaller ) ) {
$wqcaller = function( $function, $args = null ) {
global $wordquesthelper, $wqfunctions;
$func = $function . '_' . $wordquesthelper;
// echo "<!-- Called Function: ".$func." -->";
if ( is_callable( $wqfunctions[$func] ) ) {
return $wqfunctions[$func]( $args );
} elseif ( function_exists( $func ) ) {
return call_user_func( $func, $args );
}
// 1.8.0: added missing return null statement
return null;
};
}
};
}
// -------------------------------------
// Versioned Admin Page Caller Functions
// -------------------------------------
// 1.7.2: use direct superglobal to shorten functions
// wqhelper_admin_page
// wqhelper_admin_notice_boxer
// wqhelper_get_plugin_info
// wqhelper_admin_plugins_column
// wqhelper_admin_feeds_column
// wqhelper_install_plugin
// wqhelper_reminder_notice
// wqhelper_translate
// --- admin page ---
if ( !function_exists( 'wqhelper_admin_page' ) ) {
function wqhelper_admin_page( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- admin notice boxer ---
if ( !function_exists( 'wqhelper_admin_notice_boxer' ) ) {
function wqhelper_admin_notice_boxer( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- get plugins info ---
if ( !function_exists( 'wqhelper_get_plugin_info' ) ) {
function wqhelper_get_plugin_info( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- admin page plugins column ---
if ( !function_exists( 'wqhelper_admin_plugins_column' ) ) {
function wqhelper_admin_plugins_column( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- admin page feeds column ---
if ( !function_exists( 'wqhelper_admin_feeds_column' ) ) {
function wqhelper_admin_feeds_column( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// 1.6.5: install WordQuest plugin
if ( !function_exists( 'wqhelper_install_plugin' ) ) {
function wqhelper_install_plugin( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// 1.6.5: reminder notice message
if ( !function_exists( 'wqhelper_reminder_notice' ) ) {
function wqhelper_reminder_notice( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// 1.6.9: translation wrapper
if ( !function_exists( 'wqhelper_translate' ) ) {
function wqhelper_translate( $string ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $string );
}
}
// ---------------------------------
// Sidebar Floatbox Caller Functions
// ---------------------------------
// 1.7.2: use direct superglobal to shorten functions
// 1.7.4: added patreon wrapper function
// - wqhelper_sidebar_floatbox
// - wqhelper_sidebar_patreon_button
// - wqhelper_sidebar_paypal_donations
// - wqhelper_sidebar_testimonial_box
// - wqhelper_sidebar_floatmenuscript
// - wqhelper_sidebar_stickykitscript
// --- sidebar floatbox ---
if ( !function_exists( 'wqhelper_sidebar_floatbox' ) ) {
function wqhelper_sidebar_floatbox( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- patreon supporters button ---
if ( !function_exists( 'wqhelper_sidebar_patreon_button' ) ) {
function wqhelper_sidebar_patreon_button( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- paypal donations button ---
if ( !function_exists( 'wqhelper_sidebar_paypal_donations' ) ) {
function wqhelper_sidebar_paypal_donations( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- testimonials box ---
if ( !function_exists( 'wqhelper_sidebar_testimonial_box' ) ) {
function wqhelper_sidebar_testimonial_box( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- floating menu script ---
if ( !function_exists( 'wqhelper_sidebar_floatmenuscript' ) ) {
function wqhelper_sidebar_floatmenuscript( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- sticky kit script ---
if ( !function_exists( 'wqhelper_sidebar_stickykitscript' ) ) {
function wqhelper_sidebar_stickykitscript( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// Dashboard Feed Caller Functions
// -------------------------------
// 1.7.2: use direct superglobal to shorten functions
// - wqhelper_add_dashboard_feed_widget
// - wqhelper_dashboard_feed_javascript
// - wqhelper_dashboard_feed_widget
// - wqhelper_pluginreview_feed_widget
// - wqhelper_process_rss_feed
// - wqhelper_load_category_feed
// - wqhelper_get_feed_ad
// --- add dashboard feed widget ---
if ( !function_exists( 'wqhelper_add_dashboard_feed_widget' ) ) {
function wqhelper_add_dashboard_feed_widget( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- dashboard feed javascript ---
if ( !function_exists( 'wqhelper_dashboard_feed_javascript' ) ) {
function wqhelper_dashboard_feed_javascript( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- dashboard feed widget ---
if ( !function_exists( 'wqhelper_dashboard_feed_widget' ) ) {
function wqhelper_dashboard_feed_widget( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- plugin review feed widget ---
if ( !function_exists( 'wqhelper_pluginreview_feed_widget' ) ) {
function wqhelper_pluginreview_feed_widget( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- process RSS feed ---
if ( !function_exists( 'wqhelper_process_rss_feed' ) ) {
function wqhelper_process_rss_feed( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --- load category feed ---
if ( !function_exists( 'wqhelper_load_category_feed' ) ) {
function wqhelper_load_category_feed( $args = null ) {
// 1.7.7: simplified admin condition logic
if ( is_admin() ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
// 1.8.0: added missing empty return
return '';
}
}
// --- get feed ad ---
// 1.8.0: added feed ad wrapper function
if ( !function_exists( 'wqhelper_get_feed_ad' ) ) {
function wqhelper_get_feed_ad( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// --------------------------
// === Styles and Scripts ===
// --------------------------
// ---------------------------------
// Add Helper Styles to Admin Footer
// ---------------------------------
if ( !has_action( 'admin_footer', 'wqhelper_admin_styles' ) ) {
add_action( 'admin_footer', 'wqhelper_admin_styles' );
}
if ( !function_exists( 'wqhelper_admin_styles' ) ) {
function wqhelper_admin_styles( $args = null ) {
remove_action( 'admin_footer', 'wordquest_admin_styles' );
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// ----------------------------------
// Add Helper Scripts to Admin Footer
// ----------------------------------
if ( !has_action( 'admin_footer', 'wqhelper_admin_scripts' ) ) {
add_action( 'admin_footer', 'wqhelper_admin_scripts' );
}
if ( !function_exists( 'wqhelper_admin_scripts' ) ) {
function wqhelper_admin_scripts( $args = null ) {
remove_action( 'admin_footer', 'wordquest_admin_scripts' );
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// ----------------------
// === AJAX Functions ===
// ----------------------
// AJAX for reminder dismissal
// ---------------------------
// 1.6.5: added this AJAX function
if ( !has_action( 'wp_ajax_wqhelper_reminder_dismiss', 'wqhelper_reminder_dismiss' ) ) {
add_action( 'wp_ajax_wqhelper_reminder_dismiss', 'wqhelper_reminder_dismiss' );
}
if ( !function_exists( 'wqhelper_reminder_dismiss' ) ) {
function wqhelper_reminder_dismiss( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// -----------------------
// AJAX Load Category Feed
// -----------------------
if ( !has_action( 'wp_ajax_wqhelper_load_feed_cat', 'wqhelper_load_feed_category' ) ) {
add_action( 'wp_ajax_wqhelper_load_feed_cat', 'wqhelper_load_feed_category' );
}
if ( !function_exists( 'wqhelper_load_feed_category' ) ) {
function wqhelper_load_feed_category( $args = null ) {
return $GLOBALS['wqcaller']( __FUNCTION__, $args );
}
}
// ----------------------
// Update Sidebar Options
// ----------------------
// 1.6.0: ! NOTE ! caller exception ! use matching form version function here just in case...
if ( !has_action( 'wp_ajax_wqhelper_update_sidebar_boxes', 'wqhelper_update_sidebar_boxes' ) ) {
add_action( 'wp_ajax_wqhelper_update_sidebar_boxes', 'wqhelper_update_sidebar_boxes' );
}
if ( !function_exists( 'wqhelper_update_sidebar_boxes' ) ) {
function wqhelper_update_sidebar_boxes() {
// --- get helper version ---
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( !isset( $_POST['wqhv'] ) ) {
return;
} else {
// 1.8.1: sanitize to integer and cast to string
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$wqhv = (string) absint( $_POST['wqhv'] );
}
// 1.6.6: added sanitization of version value
// 1.8.1: simplified to check for 3 digits only
if ( strlen( $wqhv ) !== 3 ) {
return;
}
// --- set matching function version ---
$func = 'wqhelper_update_sidebar_options_' . $wqhv;
// --- call function ---
// 1.6.5: fix to function call method
global $wqfunctions;
if ( is_callable( $wqfunctions[$func] ) ) {
$wqfunctions[$func]();
} elseif ( function_exists( $func ) ) {
call_user_func( $func );
}
}
}
// ----------------------------------
// === Version Specific Functions ===
// ----------------------------------
// (functions below this point must be suffixed with _{VERSION} to work
// and update with each plugin helper version regardless of change state)
// -------------------
// Translation Wrapper
// -------------------
// 1.6.9: check translated labels global
$funcname = 'wqhelper_translate_' . $wqhv;
if ( !isset( $wqfunctions[$funcname] ) || !is_callable( $wqfunctions[$funcname] ) ) {
$wqfunctions[$funcname] = function( $string ) {
global $wqlabels;
if ( isset( $wqlabels[$string] ) ) {
return $wqlabels[$string];
}
// 1.6.9: added fallback translation for bioship theme
if ( function_exists( 'bioship_translate' ) ) {
return bioship_translate( $string );
}
if ( function_exists( 'translate' ) ) {
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
return translate( (string) $string, 'default' );
}
return $string;
};
}
// ------------------
// Admin Notice Boxer
// ------------------
// (for settings pages)
$funcname = 'wqhelper_admin_notice_boxer_' . $wqhv;
if ( !isset( $wqfunctions[$funcname] ) || !is_callable( $wqfunctions[$funcname] ) ) {
$wqfunctions[$funcname] = function() {
// 1.7.7: bug out if already using AdminSanity Notices box
// 1.7.8: replace with better check for AdminSanity Notices box
global $adminsanity;
if ( isset( $adminsanity ) && isset( $adminsanity['load'] ) && $adminsanity['load']['notices'] ) {
return;
}
// --- count admin notices ---
// global $wp_filter; $notices = 0; // print_r($wp_filter);
// if (isset($wp_filter['admin_notices'])) {$adminnotices = $notices = count($wp_filter['admin_notices']);}
// if (is_network_admin()) {if (isset($wp_filter['network_admin_notices'])) {$networknotices = count($wp_filter['network_admin_notices']); $notices = $notices + $networknotices;} }
// if (is_user_admin()) {if (isset($wp_filter['user_admin_notices'])) {$usernotices = count($wp_filter['user_admin_notices']); $notices = $notices + $usernotices;} }
// if (isset($wp_filter['all_admin_notices'])) {$alladminnotices = count($wp_filter['all_admin_notices']); $notices = $notices + $alladminnotices;}
// if ($notices == 0) {return;}
// print_r($wp_filter['admin_notices']); print_r($wp_filter['all_admin_notices']);
// echo "<!-- Notices: ".$adminnotices." - ".$networknotices." - ".$useradminnotices." - ".$alladminnotices." -->";
// --- toggle notice box script ---
echo "<script>function wq_togglenoticebox() {divid = 'adminnoticewrap';
if (document.getElementById(divid).style.display == '') {
document.getElementById(divid).style.display = 'none'; document.getElementById('adminnoticearrow').innerHTML = '▾';}
else {document.getElementById(divid).style.display = ''; document.getElementById('adminnoticearrow').innerHTML= '▸';} } ";
// this is from /wp-admin/js/common.js... to move the notices if common.js is not loaded...
echo "jQuery(document).ready(function() {jQuery( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( jQuery( '.wrap h1, .wrap h2' ).first() ); });";
echo "</script>";
// --- output notice box ---
echo '<div style="width:680px" id="adminnoticebox" class="postbox">';
echo '<h3 class="hndle" style="margin:7px 14px;font-size:12pt;" onclick="wq_togglenoticebox();">';
echo '<span id="adminnoticearrow">▾</span> ';
echo esc_html( wqhelper_translate( 'Admin Notices' ) );
echo '</span></h3><div id="adminnoticewrap" style="display:none;"><h2></h2></div></div>';
};
}
// ---------------------------
// Usage Reminder Notice Check
// ---------------------------
// 1.5.0: added reminder prototype that does nothing yet
// 1.6.5: completed usage reminder notices
$funcname = 'wqhelper_admin_notices_' . $wqhv;
if ( !isset( $wqfunctions[$funcname] ) || !is_callable( $wqfunctions[$funcname] ) ) {
$wqfunctions[$funcname] = function() {
global $wordquestplugins;
foreach ( $wordquestplugins as $pluginslug => $wqplugin ) {
// --- check current user capabilities ---
// 1.7.3: only show reminder notice to users with capabilities
$shownotice = false;
if ( current_user_can( 'manage_options' )
|| ( ( 'bioship' == $pluginslug ) && current_user_can( 'install_themes' ) )
|| ( ( 'bioship' != $pluginslug ) && current_user_can( 'install_plugins' ) ) ) {
$shownotice = true;
}
if ( $shownotice ) {
// 1.6.8: move here to fix undefined index warning
$prefix = $wqplugin['settings'];
// 1.7.0: moved up here to fix install version check
$sidebaroptions = get_option( $prefix . '_sidebar_options' );
// 1.6.7: maybe set first install version for plugin
if ( !isset( $sidebaroptions['installversion'] ) ) {
$sidebaroptions['installversion'] = $wqplugin['version'];
update_option( $prefix . '_sidebar_options', $sidebaroptions );
}
// 1.6.5: no reminders needed if pro version
// 1.7.7: added check if plan key is set for back-compat
if ( isset( $wqplugin['plan'] ) && ( 'premium' == $wqplugin['plan'] ) ) {
return;
}
// 1.6.5: no reminders if donation box has been turned off
// 1.6.7: revert that as so many other ways to still contribute
// if ( (isset($sidebaroptions['donationboxoff']))
// && ($sidebaroptions['donationboxoff'] == 'checked') ) {return;}
if ( isset( $sidebaroptions['installdate'] ) ) {
// --- check usage length ---
$reminder = false;
$installtime = strtotime( $sidebaroptions['installdate'] );
$timesince = time() - $installtime;
$dayssince = floor( $timesince / ( 24 * 60 * 60 ) );
// --- 30 days, 90 days and 1 year notices ---
if ( $dayssince > 365 ) {
// --- 365 day notice ---
if ( !isset( $sidebaroptions['365days'] ) ) {
$reminder = '365';
}
} elseif ( $dayssince > 90 ) {
// --- 90 day notice ---
if ( !isset( $sidebaroptions['90days'] ) ) {
$reminder = '90';
}
} elseif ( $dayssince > 30 ) {
// --- 30 day notice ---
if ( !isset( $sidebaroptions['30days'] ) ) {
$reminder = '30';
}
}
if ( $reminder ) {
// --- add an admin reminder notice ---
global $wqreminder;
$wqreminder[$pluginslug] = $wqplugin;
$wqreminder[$pluginslug]['days'] = $dayssince;
$wqreminder[$pluginslug]['notice'] = $reminder;
add_action( 'admin_notices', 'wqhelper_reminder_notice' );
}
} else {
$sidebaroptions['installdate'] = date( 'Y-m-d' );
update_option( $prefix . '_sidebar_options', $sidebaroptions );
}
}
}
};
}
// ---------------------
// Usage Reminder Notice
// ---------------------
// 1.6.5: added reminder notice text
$funcname = 'wqhelper_reminder_notice_' . $wqhv;
if ( !isset( $wqfunctions[$funcname] ) || !is_callable( $wqfunctions[$funcname] ) ) {
$wqfunctions[$funcname] = function() {
global $wqreminder, $wqurls, $wordquestplugins;
// --- loop reminders ---
foreach ( $wqreminder as $pluginslug => $reminder ) {
// --- reminder wrapper ---
echo '<div class="updated notice is-dismissable" id="' . esc_attr( $pluginslug ) . '-reminder-notice" style="font-size:16px; line-height:24px; margin:0;">';
echo esc_html( wqhelper_translate( "You've been enjoying" ) ) . ' ';
echo esc_html( $wqreminder[$pluginslug]['title'] ) . ' ' . esc_html( wqhelper_translate( 'for' ) ) . ' ';
echo esc_html( $wqreminder[$pluginslug]['days'] ) . ' ' . esc_html( wqhelper_translate( 'days' ) ) . '. ';
echo esc_html( wqhelper_translate( "If you like it, here's some ways you can help make it better" ) ) . ':<br>';
// Action Links Table
// ------------------
// 1.6.7: extended link anchor text for clarity
echo '<table id="wq-reminders" cellpadding="0" cellspacing="0" style="width:100%;"><tr><td>';
echo '<ul>';
// --- Supporter Link ---
// 1.7.4: add supporter link heart icon
// 1.7.6: fix to check if donate link defined
if ( isset( $wordquestplugins[$pluginslug]['donate'] ) ) {
$donatelink = $wordquestplugins[$pluginslug]['donate'];
echo '<li style="margin-left:0px;">';
echo '<span style="color:#E00;" class="dashicons dashicons-heart"></span> ';
if ( strstr( $donatelink, 'patreon' ) ) {
// --- Patreon supporter Link ---
echo '<a class="notice-link" href="' . esc_url( $donatelink ) . '" target="_blank">→ ' . esc_html( wqhelper_translate( 'Become a Supporter' ) ) . '</a>';
} else {
// --- WordQuest subscription link ---
echo '<a class="notice-link" href="' . esc_url( $wqurls['wq'] ) . '/contribute/?tab=supporterlevels" target="_blank">→ ' . esc_html( wqhelper_translate( 'Become a Supporter' ) ) . '</a>';
}
echo '</li>';
}
// --- Donate Link ---
// 1.7.4: removed one-off donation link (just too many links)
// echo '<li style="display:inline-block;margin-left:15px;">';
// echo '<a href="' . esc_url( $wqurls['wq'] ) . '/contribute/?plugin=' . $pluginslug . '" target="_blank">→ ' . esc_html( wqhelper_translate( 'Make a Donation' ) ) . '</a>';
// echo '</li>';
// --- Rating Link (for WordPress.org) ---
// 1.7.2: removed ?rate=5 from rating URLs (no longer used)
// 1.7.4: added rating link star icon
if ( isset( $wqreminder['wporgslug'] ) ) {
echo '<li>';
echo '<span style="color:#FC5;" class="dashicons dashicons-star-filled"></span> ';
// 1.6.7: added different rating action for theme
if ( 'bioship' == $pluginslug ) {
// theme rate link --
$rateurl = $wqurls['wp'] . '/support/theme/' . $pluginslug . '/reviews/#new-post';
echo '<a class="notice-link" href="' . esc_url( $rateurl ) . '" target="_blank">→ ' . esc_html( wqhelper_translate( 'Rate this Theme' ) ) . '</a>';
} else {
// --- plugin rate link ---
$rateurl = $wqurls['wp'] . '/support/plugin/' . $pluginslug . '/reviews/#new-post';
echo '<a class="notice-link" href="' . esc_url( $rateurl ) . '" target="_blank">→ ' . esc_html( wqhelper_translate( 'Rate this Plugin' ) ) . '</a>';
}
echo '</li>';
}
// 1.7.2: removed unused testimonial link
// echo "<li><a href='".$wqurls['wq']."/contribute/?tab=testimonial' target=_blank>→ ".wqhelper_translate('Send a Testimonial')."</a></li>";
// --- Share Link ---
// 1.7.2: add share theme / plugin link
// 1.7.4: added share link icon
echo '<li>';
echo '<span style="color:#E0E;" class="dashicons dashicons-share"></span> ';
if ( 'bioship' == $pluginslug ) {
echo '<a class="notice-link" href="' . esc_url( $wqurls['bio'] ) . '#share" target="_blank">→ ' . esc_html( wqhelper_translate( 'Share this Theme' ) ) . '</a>';
} else {
$shareurl = $wqurls['wq'] . '/plugins/' . $pluginslug . '/#share';
echo '<a class="notice-link" href="' . esc_url( $shareurl ) . '" target="_blank">→ ' . esc_html( wqhelper_translate( 'Share this Plugin' ) ) . '</a>';
}
echo '</li>';
// --- Feedback Link ---
// 1.7.4: renamed anchor to simply feedback in this context
// 1.7.4: added feedback link (slanted envelope) icon
echo '<li>';
echo '<span style="color:#00E;" class="dashicons dashicons-email-alt"></span> ';
$supporturl = $wqurls['wq'] . '/support/' . $pluginslug;
echo '<a class="notice-link" href="' . esc_url( $supporturl ) . '" target="_blank">→ ' . esc_html( wqhelper_translate( 'Provide Feedback' ) ) . '</a>';
echo "</li>";
// --- Contribute Link ---
// 1.7.4: removed contribute link (just too many links)
// echo "<li style='display:inline-block;margin-left:15px;'><a href='".$wqurls['wq']."/contribute/?tab=development' target=_blank>→ ".wqhelper_translate('Contribute to Development')."</a></li>";
// --- Pro Version plan link (Freemius) ---
// TODO: handle Freemius plugin add-ons ?
if ( isset( $wqreminder['hasplans'] ) && ( $wqreminder['hasplans'] ) ) {
$upgradeurl = admin_url( 'admin.php' ) . '?page=' . $wqreminder['slug'] . '-pricing';
echo '<li><a href="' . esc_url( $upgradeurl ) . '">';
echo '<b>→ ' . esc_html( wqhelper_translate( 'Go PRO' ) ) . '</b>';
echo '</a></li>';
}
echo '</ul>';
echo '</td><td style="text-align:right;">';
// --- dismiss notice X link ---
$dismisslink = admin_url( 'admin-ajax.php' ) . '?action=wqhelper_reminder_dismiss&slug=' . $pluginslug . '¬ice=' . $wqreminder[$pluginslug]['notice'];
echo '<a href="' . esc_url( $dismisslink ) . '" target="wqdismissframe" style="text-decoration:none;" title="' . esc_attr( wqhelper_translate( 'Dismiss this Notice' ) ) . '">';
echo '<div class="dashicons dashicons-dismiss" style="font-size:16px;"></div></a>';
echo '</td></tr></table></div>';
}
// --- notice styles ---
// 1.7.5: added notice styling
echo "<style>#wq-reminders ul {list-style:none; padding:0; margin:0;}
#wq-reminders ul li {display:inline-block; margin-left:15px;}
#wq-reminders span.dashicons {display:inline; font-size:16px; color:#00E; vertical-align:middle;}
.notice-link {text-decoration:none;} .notice-link:hover {text-decoration:underline;}</style>";
// --- notice dismissal iframe ---
echo '<iframe style="display:none;" src="javascript:void(0);" name="wqdismissframe" id="wqdimissframe"></iframe>';
};
}
// -----------------------
// AJAX Reminder Dismisser
// -----------------------
$funcname = 'wqhelper_reminder_dismiss_' . $wqhv;
if ( !isset( $wqfunctions[$funcname] ) || !is_callable( $wqfunctions[$funcname] ) ) {
$wqfunctions[$funcname] = function() {
// --- check conditions ---
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$pluginslug = sanitize_title( $_REQUEST['slug'] );
// 1.8.1: sanitize to integer and validate against array
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$notice = absint( $_REQUEST['notice'] );
if ( !in_array( $notice, array( 30, 90, 365 ) ) ) {
return;
}
// --- check capabilities ---
$dismiss = false;
if ( current_user_can( 'manage_options' )
|| ( ( 'bioship' == $pluginslug ) && current_user_can( 'install_themes' ) )
|| ( ( 'bioship' != $pluginslug ) && current_user_can( 'install_plugins' ) ) ) {
$dismiss = true;
}
if ( $dismiss ) {
// --- dismiss the reminder notice ---
global $wordquestplugins;
$prefix = $wordquestplugins[$pluginslug]['settings'];
$sidebaroptions = get_option( $prefix . '_sidebar_options' );
if ( isset( $sidebaroptions[$notice . 'days'] ) && ( 'dismissed' == $sidebaroptions[$notice . 'days'] ) ) {
$sidebaroptions[$notice . 'days'] = '';
} else {
$sidebaroptions[$notice . 'days'] = 'dismissed';
}
update_option( $prefix . '_sidebar_options', $sidebaroptions );
// --- hide the notice in the parent window ---
echo "<script>parent.document.getElementById('" . esc_js( $pluginslug ) . "-reminder-notice').style.display = 'none';</script>";
}
exit;
};
}
// --------------------------
// Get WordQuest Plugins Info
// --------------------------
$funcname = 'wqhelper_get_plugin_info_' . $wqhv;
if ( !isset( $wqfunctions[$funcname] ) || !is_callable( $wqfunctions[$funcname] ) ) {
$wqfunctions[$funcname] = function() {
global $wqurls, $wqdebug;
// --- maybe get cached plugin info ---
// 1.5.0: get plugin info (maximum twice daily)
$plugininfo = get_transient( 'wordquest_plugin_info' );
// clear transient when debugging
if ( $wqdebug ) {
$plugininfo = '';
}
// --- maybe get plugin info now ---
if ( !$plugininfo || ( '' == $plugininfo ) || !is_array( $plugininfo ) ) {
$pluginsurl = $wqurls['wq'] . '/?get_plugins_info=yes';
$args = array( 'timeout' => 15 );
$plugininfo = wp_remote_get( $pluginsurl, $args );
if ( !is_wp_error( $plugininfo ) ) {
$plugininfo = $plugininfo['body'];
$dataend = "*****END DATA*****";
if ( strstr( $plugininfo, $dataend ) ) {
$pos = strpos( $plugininfo, $dataend );
$plugininfo = substr( $plugininfo, 0, $pos );
$plugininfo = json_decode( $plugininfo, true );
set_transient( 'wordquest_plugin_info', $plugininfo, ( 12 * 60 * 60 ) );
} else {
$plugininfo = '';
}
} else {
$plugininfo = '';
}
}
if ( $wqdebug ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions
echo "<!-- Plugin Info: " . esc_html( print_r( $plugininfo ) ) . " -->";
}
return $plugininfo;
};
}
// ---------------------------
// Version Specific Admin Page
// ---------------------------
$funcname = 'wqhelper_admin_page_' . $wqhv;
if ( !isset( $wqfunctions[$funcname] ) || !is_callable( $wqfunctions[$funcname] ) ) {
$wqfunctions[$funcname] = function() {
global $wordquesthelper, $wordquestplugins, $wqurls;
echo '<div id="pagewrap" class="wrap">';
// --- admin notice boxer ---
wqhelper_admin_notice_boxer();
// --- toggle metabox script ---
echo "<script>function wq_togglemetabox(divid) {
divid += '-inside';
if (document.getElementById(divid).style.display == '') {
document.getElementById(divid).style.display = 'none';
} else {document.getElementById(divid).style.display = '';}
}</script>";
// --- admin page styles ---
echo '<style>#plugincolumn, #feedcolumn {display: inline-block; float:left; margin: 0 5px;}
#plugincolumn .postbox {max-width:300px;} #feedcolumn .postbox {max-width:300px;}
#plugincolumn .postbox h2, #feedcolumn .postbox h2 {font-size: 16px; margin-top: 0; background-color: #E0E0EE; padding: 5px;}
#page-title a {text-decoration:none;} #page-title h2 {color: #3568A9;}
</style>';
// --- Floating Sidebar ---
// set dummy "plugin" values for admin page sidebar
global $wordquestplugins, $wordquesthelper;
$wordquestplugins['wordquest'] = array(
'version' => $wordquesthelper,
'title' => 'WordQuest Alliance',
'namespace' => 'wordquest',
'settings' => 'wq',
'plan' => 'free',
'wporg' => false,
'wporgslug' => false,
);
$args = array( 'wordquest', 'special' );
wqhelper_sidebar_floatbox( $args );
// --- load sticky kit on sidebar ---
// 1.6.5: replace floatmenu with stickykit
// 1.8.1: use new echo argument on stickykit function
wqhelper_sidebar_stickykitscript( true );
echo "<style>#floatdiv {float:right;} #wpcontent, #wpfooter {margin-left:150px !important;}</style>";
echo "<script>jQuery('#floatdiv').stick_in_parent();</script>";
unset( $wordquestplugins['wordquest'] );
// echo wqhelper_sidebar_floatmenuscript();
// echo '<script language="javascript" type="text/javascript">
// floatingMenu.add("floatdiv", {targetRight: 10, targetTop: 20, centerX: false, centerY: false});
// function move_upper_right() {
// floatingArray[0].targetTop=20;
// floatingArray[0].targetBottom=undefined;
// floatingArray[0].targetLeft=undefined;
// floatingArray[0].targetRight=10;
// floatingArray[0].centerX=undefined;
// floatingArray[0].centerY=undefined;
// }
// move_upper_right();
// </script>
// --- Admin Page Title ---
$wordquesticon = plugins_url( 'images/wordquest.png', __FILE__ );
echo '<style>.wqlink {text-decoration:none;} .wqlink:hover {text-decoration:underline;}</style>';
echo '<table><tr>';
echo '<td width="20"></td>';
echo '<td><img src="' . esc_url( $wordquesticon ) . '" alt="' . esc_attr( wqhelper_translate( 'WordQuest icon' ) ) . '"></td>';
echo '<td width="20"></td>';
echo '<td><div id="page-title"><a href="' . esc_url( $wqurls['wq'] ) . '" target="_blank"><h2>WordQuest Alliance</h2></a></div></td>';
echo '<td width="30"></td>';
echo '<td><h4>→ <a href="' . esc_url( $wqurls['wq'] ) . '/register/" class="wqlink" target="_blank">' . esc_html( wqhelper_translate( 'Join' ) ) . '</a></h4></td>';
echo '<td> / </td>';
echo '<td><h4><a href="' . esc_url( $wqurls['wq'] ) . '/login/" class="wqlink" target="_blank">' . esc_html( wqhelper_translate( 'Login' ) ) . '</a></h4></td>';
echo '<td width="20"></td>';
echo '<td><h4>→ <a href="' . esc_url( $wqurls['wq'] ) . '/solutions/" class="wqlink" target="_blank">' . esc_html( wqhelper_translate( 'Solutions' ) ) . '</a></h4></td>';
echo '<td width="20"></td>';
echo '<td><h4>→ <a href="' . esc_url( $wqurls['wq'] ) . '/contribute/" class="wqlink" target="_blank">' . esc_html( wqhelper_translate( 'Contribute' ) ) . '</a></h4></td>';
echo '</tr></table>';
// --- Output Plugins Column ---
wqhelper_admin_plugins_column( null );
// --- Output Feeds Column ---
wqhelper_admin_feeds_column( null );
// --- Wordquest Sidebar 'plugin' box ---
if ( !function_exists( 'wq_sidebar_plugin_footer' ) ) {
function wq_sidebar_plugin_footer() {
global $wqurls;
$iconurl = plugins_url( 'images/wordquest.png', __FILE__ );
echo '<div id="pluginfooter"><div class="stuffbox" style="width:250px;background-color:#ffffff;"><h3>' . esc_html( wqhelper_translate( 'Source Info' ) ) . '</h3><div class="inside">';
echo '<center><table><tr>';
echo '<td><a href="' . esc_url( $wqurls['wq'] ) . '" target="_blank"><img src="' . esc_url( $iconurl ) . '" alt="' . esc_attr( wqhelper_translate( 'WordQuest Icon' ) ) . ' "border="0"></a></td>';
echo '<td width="14"></td>';
echo '<td><a href="' . esc_url( $wqurls['wq'] ) . '" target="_blank">WordQuest Alliance</a><br>';
echo '<a href="' . esc_url( $wqurls['wq'] ) . '/plugins/" target="_blank"><b>→ WordQuest Plugins</b></a><br>';
echo '<a href="' . esc_url( $wqurls['prn'] ) . '/directory/" target="_blank">→ Plugin Directory</a></td>';
echo '</tr></table></center>';
echo '</div></div></div>';
}
}
echo '</div>';
// --- hidden iframe for plugin actions ---
echo '<iframe id="pluginactionframe" src="javascript:void(0);" style="display:none;"></iframe>';
echo '</div>';
};
}
// -------------------------------
// Version Specific Plugins Column
// -------------------------------
$funcname = 'wqhelper_admin_plugins_column_' . $wqhv;
if ( !isset( $wqfunctions[$funcname] ) || !is_callable( $wqfunctions[$funcname] ) ) {
$wqfunctions[$funcname] = function( $args ) {
global $wordquesthelper, $wordquestplugins, $wqurls, $wqdebug;
// --- check if WordPress.Org plugins only ---
// 1.6.6: check if current WQ plugins are all installed via WordPress.Org
// (if so, only provide option to install other WQ plugins in repository)
global $wq_wordpress_org;
$wq_wordpress_org = true;
foreach ( $wordquestplugins as $pluginslug => $plugin ) {
// - if this is false, it was from WordQuest not WordPress -
if ( !$plugin['wporg'] ) {
$wq_wordpress_org = false;
}
}
// --- Plugin Action Select Javascript ---
// 1.7.2: updated star rating link
// TODO: test all options here more thoroughly..?
echo "<script>
function wq_plugin_action(pluginslug) {
selectelement = document.getElementById(pluginslug+'-action');
actionvalue = selectelement.options[selectelement.selectedIndex].value;
linkel = document.getElementById(pluginslug+'-link');
adminpageurl = '" . esc_url( admin_url( 'admin.php' ) ) . "';
wqurl = '" . esc_url( $wqurls['wq'] ) . "';
if (actionvalue == 'settings') {linkel.target = '_self'; linkel.href = adminpageurl+'?page='+pluginslug;}
if (actionvalue == 'update') {linkel.target = '_self'; linkel.href = document.getElementById(pluginslug+'-update-link').value;}
if (actionvalue == 'activate') {linkel.target = '_self'; linkel.href = document.getElementById(pluginslug+'-activate-link').value;}
if (actionvalue == 'install') {linkel.target = '_self'; linkel.href = document.getElementById(pluginslug+'-install-link').value;}
if (actionvalue == 'support') {linkel.target = '_blank'; linkel.href = adminpageurl+'?page='+pluginslug+'-wp-support-forum';}
if (actionvalue == 'donate') {linkel.target = '_blank'; linkel.href = wqurl+'/contribute/?plugin='+pluginslug;}
if (actionvalue == 'testimonial') {linkel.target = '_blank'; linkel.href = wqurl+'/contribute/?tab=testimonial';}
if (actionvalue == 'rate') {linkel.target = '_blank'; linkel.href = '" . esc_url( $wqurls['wp'] ) . "/plugins/'+pluginslug+'/reviews/#new-post';}
if (actionvalue == 'development') {linkel.target = '_blank'; linkel.href= wqurl+'/contribute/?tab=development';}
if (actionvalue == 'contact') {linkel.target = '_self'; linkel.href = adminpageurl+'?page='+pluginslug+'-contact';}
if (actionvalue == 'home') {linkel.target = '_blank'; linkel.href = wqurl+'/plugins/'+pluginslug+'/';}
if (actionvalue == 'upgrade') {linkel.target = '_self'; linkel.href = adminpageurl+'?page='+pluginslug+'-pricing';}
if (actionvalue == 'account') {linkel.target = '_self'; linkel.href = adminpageurl+'?page='+pluginslug+'-account';}
}</script>";
// --- link styles ---