-
Notifications
You must be signed in to change notification settings - Fork 11
/
class-strong-testimonials.php
644 lines (546 loc) · 18.7 KB
/
class-strong-testimonials.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
<?php
/**
* Class Strong_Testimonials - Main plugin class
*
* @since 3.1.16
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Strong_Testimonials' ) ) :
/**
* Main plugin class.
*
* @property Strong_Testimonials_View_Shortcode shortcode
* @property Strong_Testimonials_Render render
* @property Strong_Mail mail
* @property Strong_Templates templates
* @property Strong_Testimonials_Form form
* @since 1.15.0
*/
final class Strong_Testimonials {
private static $instance;
private $db_version = '1.0';
public $plugin_data;
/**
* @var Strong_Testimonials_View_Shortcode
*/
public $shortcode;
/**
* @var Strong_Testimonials_Render
*/
public $render;
/**
* @var Strong_Mail
*/
public $mail;
/**
* @var Strong_Templates
*/
public $templates;
/**
* @var Strong_Testimonials_Form
*/
public $form;
/**
* A singleton instance.
*
* Used for preprocessing shortcodes and widgets to properly enqueue styles and scripts
* (1) to improve overall plugin flexibility,
* (2) to improve compatibility with page builder plugins, and
* (3) to maintain conditional loading best practices.
*
* Also used to store testimonial form data during Post-Redirect-Get.
*
* @return Strong_Testimonials Strong_Testimonials object
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Strong_Testimonials ) ) {
self::$instance = new Strong_Testimonials();
self::$instance->setup_constants();
self::$instance->includes();
add_action( 'init', array( self::$instance, 'init' ) );
self::$instance->add_actions();
}
return self::$instance;
}
/**
* Throw error on object clone
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @return void
* @since 1.21.0
* @access protected
*/
public function __clone() {
// Cloning instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'strong-testimonials' ), '1.21' );
}
/**
* Disable unserializing of the class
*
* @return void
* @since 1.21.0
* @access protected
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'strong-testimonials' ), '1.21' );
}
/**
* Plugin activation
*/
public static function plugin_activation( $network_wide = false ) {
$first_install = ! get_option( 'wpmtst_db_version' ) ? true : false;
// check if
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
// check if it's multisite.
if ( is_multisite() && true === $network_wide ) {
// get websites
$sites = get_sites();
// loop
if ( count( $sites ) > 0 ) {
foreach ( $sites as $site ) {
// switch to blog
switch_to_blog( $site->blog_id );
// run installer on blog
wpmtst_update_tables();
// restore current blog
restore_current_blog();
}
}
} else {
// no multisite so do normal install
wpmtst_update_tables();
}
wpmtst_register_cpt();
flush_rewrite_rules();
do_action( 'wpmtst_after_update_setup', $first_install );
}
/**
* Run installer for new blogs on multisite when plugin is network activated
*
* @param array $site Blog - WP_Site object.
*
* @since 3.1.8
*/
public static function mu_new_blog( $site ) {
// check if plugin is network activated.
if ( is_plugin_active_for_network( 'strong-testimonials/strong-testimonials.php' ) ) {
// switch to new blog
switch_to_blog( $site->blog_id );
// run installer on blog
wpmtst_update_tables();
// restore current blog
restore_current_blog();
}
}
/**
* Plugin deactivation
*/
public static function plugin_deactivation() {
flush_rewrite_rules();
}
/**
* Setup plugin constants
*
* @access private
* @return void
*/
private function setup_constants() {
defined( 'WPMTST_DIR' ) || define( 'WPMTST_DIR', plugin_dir_path( __FILE__ ) );
defined( 'WPMTST_URL' ) || define( 'WPMTST_URL', plugin_dir_url( __FILE__ ) );
defined( 'WPMTST_INC' ) || define( 'WPMTST_INC', WPMTST_DIR . 'includes/' );
defined( 'WPMTST_ADMIN' ) || define( 'WPMTST_ADMIN', WPMTST_DIR . 'admin/' );
defined( 'WPMTST_ADMIN_URL' ) || define( 'WPMTST_ADMIN_URL', WPMTST_URL . 'admin/' );
defined( 'WPMTST_PUBLIC' ) || define( 'WPMTST_PUBLIC', WPMTST_DIR . 'assets/public/' );
defined( 'WPMTST_PUBLIC_URL' ) || define( 'WPMTST_PUBLIC_URL', WPMTST_URL . 'assets/public/' );
defined( 'WPMTST_DEF_TPL' ) || define( 'WPMTST_DEF_TPL', WPMTST_DIR . 'templates/default/' );
defined( 'WPMTST_DEF_TPL_URI' ) || define( 'WPMTST_DEF_TPL_URI', WPMTST_URL . 'templates/default/' );
defined( 'WPMTST_TPL' ) || define( 'WPMTST_TPL', WPMTST_DIR . 'templates' );
defined( 'WPMTST_TPL_URI' ) || define( 'WPMTST_TPL_URI', WPMTST_URL . 'templates' );
defined( 'WPMTST_ASSETS_CSS' ) || define( 'WPMTST_ASSETS_CSS', WPMTST_URL . 'assets/css/' );
defined( 'WPMTST_ASSETS_JS' ) || define( 'WPMTST_ASSETS_JS', WPMTST_URL . 'assets/dist/' );
defined( 'WPMTST_ASSETS_SRC' ) || define( 'WPMTST_ASSETS_SRC', WPMTST_URL . 'assets/src/' );
defined( 'WPMTST_ASSETS_IMG' ) || define( 'WPMTST_ASSETS_IMG', WPMTST_URL . 'assets/img/' );
}
/**
* Instantiate our classes.
*/
public function init() {
$this->shortcode = new Strong_Testimonials_View_Shortcode();
$this->render = new Strong_Testimonials_Render();
$this->mail = new Strong_Mail();
$this->templates = new Strong_Templates();
$this->form = new Strong_Testimonials_Form();
new Strong_Testimonials_Count_Shortcode();
new Strong_Testimonials_Average_Shortcode();
new Strong_Testimonials_Privacy();
}
/**
* Include required files
*
* @access private
* @return void
* @since 1.21.0
*/
private function includes() {
require_once WPMTST_INC . 'logs/class-strong-testimonials-logger.php';
require_once WPMTST_INC . 'class-strong-log.php';
require_once WPMTST_INC . 'class-strong-testimonials-privacy.php';
require_once WPMTST_INC . 'class-strong-testimonials-view-shortcode.php';
require_once WPMTST_INC . 'class-strong-gutemberg.php';
require_once WPMTST_INC . 'elementor/class-strong-testimonials-elementor-check.php';
require_once WPMTST_INC . 'strong-testimonials-beaver-block/class-strong-testimonials-beaver.php';
require_once WPMTST_INC . 'class-strong-testimonials-count-shortcode.php';
require_once WPMTST_INC . 'class-strong-testimonials-average-shortcode.php';
require_once WPMTST_INC . 'class-strong-testimonials-render.php';
require_once WPMTST_INC . 'class-strong-view.php';
require_once WPMTST_INC . 'class-strong-view-display.php';
require_once WPMTST_INC . 'class-strong-view-slideshow.php';
require_once WPMTST_INC . 'class-strong-view-form.php';
require_once WPMTST_INC . 'class-strong-testimonials-templates.php';
require_once WPMTST_INC . 'class-strong-mail.php';
require_once WPMTST_INC . 'class-strong-testimonials-form.php';
require_once WPMTST_INC . 'class-walker-strong-category-checklist-front.php';
require_once WPMTST_INC . 'deprecated.php';
require_once WPMTST_INC . 'filters.php';
require_once WPMTST_INC . 'functions.php';
require_once WPMTST_INC . 'functions-activation.php';
require_once WPMTST_INC . 'functions-content.php';
require_once WPMTST_INC . 'functions-rating.php';
require_once WPMTST_INC . 'functions-image.php';
require_once WPMTST_INC . 'functions-template.php';
require_once WPMTST_INC . 'functions-template-form.php';
require_once WPMTST_INC . 'functions-views.php';
require_once WPMTST_INC . 'post-types.php';
require_once WPMTST_INC . 'retro.php';
require_once WPMTST_INC . 'scripts.php';
require_once WPMTST_INC . 'class-strong-testimonials-view-widget.php';
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
require_once WPMTST_ADMIN . 'menu/class-strong-testimonials-menu.php';
require_once WPMTST_ADMIN . 'menu/class-strong-testimonials-menu-fields.php';
require_once WPMTST_ADMIN . 'menu/class-strong-testimonials-menu-settings.php';
require_once WPMTST_ADMIN . 'menu/class-strong-testimonials-menu-views.php';
require_once WPMTST_ADMIN . 'menu/class-strong-testimonials-menu-shortcodes.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-page-shortcodes.php';
require_once WPMTST_ADMIN . 'settings/class-strong-testimonials-settings.php';
require_once WPMTST_ADMIN . 'settings/class-strong-testimonials-settings-general.php';
require_once WPMTST_ADMIN . 'settings/class-strong-testimonials-settings-form.php';
require_once WPMTST_ADMIN . 'settings/class-strong-testimonials-settings-compat.php';
require_once WPMTST_ADMIN . 'settings/class-strong-testimonials-advanced-settings.php';
require_once WPMTST_ADMIN . 'settings/class-strong-testimonials-forms.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-addons.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-defaults.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-list-table.php';
require_once WPMTST_ADMIN . 'class-strong-views-list-table.php';
require_once WPMTST_ADMIN . 'class-walker-strong-category-checklist.php';
require_once WPMTST_ADMIN . 'class-walker-strong-form-category-checklist.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-help.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-admin-scripts.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-admin-list.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-admin-category-list.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-post-editor.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-exporter.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-wpchill-upsells.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-upsell.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-updater.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-review.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-helper.php';
require_once WPMTST_ADMIN . 'class-strong-testimonials-lite-vs-pro-page.php';
require_once WPMTST_ADMIN . 'admin.php';
require_once WPMTST_ADMIN . 'admin-notices.php';
require_once WPMTST_ADMIN . 'compat.php';
require_once WPMTST_ADMIN . 'custom-fields.php';
require_once WPMTST_ADMIN . 'custom-fields-ajax.php';
require_once WPMTST_ADMIN . 'form-preview.php';
require_once WPMTST_ADMIN . 'views.php';
require_once WPMTST_ADMIN . 'views-ajax.php';
require_once WPMTST_ADMIN . 'view-list-order.php';
require_once WPMTST_ADMIN . 'views-validate.php';
require_once WPMTST_INC . 'class-strong-testimonials-order.php';
// Uninstall form
require_once WPMTST_ADMIN . 'uninstall/class-strong-testimonials-uninstall.php';
// WPMTST Challenge Modal
//require_once WPMTST_ADMIN . 'challenge/class-wpmtst-challenge-modal.php';
// Admin Helpers
require_once WPMTST_ADMIN . 'class-wpmtst-admin-helpers.php';
// WPMTST Onboarding
require_once WPMTST_ADMIN . 'class-wpmtst-onboarding.php';
// WPMTST Debuging
require_once WPMTST_ADMIN . 'class-strong-testimonials-debug.php';
}
}
/**
* Text domain
*/
public function load_textdomain() {
load_plugin_textdomain( 'strong-testimonials', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Action and filters.
*/
private function add_actions() {
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
add_action( 'plugins_loaded', array( $this, 'remove_license_tab' ) );
/**
* Plugin setup.
*/
add_action( 'init', array( $this, 'l10n_check' ) );
//add_action( 'init', array( $this, 'reorder_check' ) );
/**
* Theme support for thumbnails.
*/
add_action( 'after_setup_theme', array( $this, 'add_theme_support' ) );
/**
* Add image size for widget.
*/
add_action( 'after_setup_theme', array( $this, 'add_image_size' ) );
add_filter( 'views_edit-wpm-testimonial', array( $this, 'add_onboarding_view' ), 10, 1 );
if ( is_admin() ) {
// Check if we need to add lite vs pro page
$license = get_option( 'strong_testimonials_license_key' );
$status = get_option( 'strong_testimonials_license_status', false );
if ( '' === $license || false === $status || ! isset( $status->license ) || 'valid' !== $status->license ) {
if ( class_exists( 'Strong_Testimonials_Lite_Vs_PRO_Page' ) ) {
new Strong_Testimonials_Lite_Vs_PRO_Page();
}
}
}
}
/**
* Remove license tab added by premium extensions.
*/
public function remove_license_tab() {
if ( class_exists( 'Strong_Testimonials_Settings_License' ) ) {
remove_action(
'wpmtst_settings_tabs',
array( 'Strong_Testimonials_Settings_License', 'register_tab' ),
90
);
}
}
/**
* Add theme support for this custom post type only.
*
* @since 1.4.0
* @since 1.19.1 Appends our testimonial post type to the existing array.
* @since 2.26.5 Simply using add_theme_support(). Let the chips fall where they may.
*/
public function add_theme_support() {
/**
* This will fail if the theme uses add_theme_support incorrectly;
* e.g. add_theme_support( 'post-thumbnails', 'post' );
* which WordPress does not catch.
*
* The plugin attempted to handle this in versions 1.19.1 - 2.26.4
* but now it lets the condition occur so the underlying problem
* will surface and can be fixed.
*/
add_theme_support( 'post-thumbnails', array( 'wpm-testimonial' ) );
}
/**
* Add widget thumbnail size.
*
* @since 1.21.0
*/
public function add_image_size() {
// name, width, height, crop = false
add_image_size( 'widget-thumbnail', 75, 75, true );
}
/**
* Load specific files for translation plugins.
*/
public function l10n_check() {
// WPML
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
require_once WPMTST_INC . 'l10n-wpml.php';
}
// Polylang
if ( defined( 'POLYLANG_VERSION' ) ) {
require_once WPMTST_INC . 'l10n-polylang.php';
}
// WP Globus
if ( defined( 'WPGLOBUS_VERSION' ) ) {
// Translate
remove_filter( 'wpmtst_l10n', 'wpmtst_l10n_default' );
add_filter( 'wpmtst_the_content', array( 'WPGlobus_Filters', 'filter__text' ), 0 );
add_filter( 'wpmtst_get_the_excerpt', array( 'WPGlobus_Filters', 'filter__text' ), 0 );
}
}
/**
* Load reorder class if enabled.
*/
// public function reorder_check() {
// $options = get_option( 'wpmtst_options' );
// if ( isset( $options['reorder'] ) && $options['reorder'] ) {
// require_once WPMTST_INC . 'class-strong-testimonials-order.php';
// }
// }
/**
* Get att(s).
*
* @param null $keys
*
* @return array|bool
*/
public function atts( $keys = null ) {
// return all
if ( ! $keys ) {
return $this->render->view_atts;
}
// return some
if ( is_array( $keys ) ) {
$found = array();
foreach ( $keys as $key ) {
if ( isset( $this->render->view_atts[ $key ] ) ) {
$found[ $key ] = $this->render->view_atts[ $key ];
}
}
return $found;
}
// return one
if ( isset( $this->render->view_atts[ $keys ] ) ) {
return $this->render->view_atts[ $keys ];
}
// return none
return false;
}
/**
* Set atts.
*
* @param $atts
*/
public function set_atts( $atts ) {
$this->render->set_atts( $atts );
}
/**
* Store current query.
*
* @param $query
*/
public function set_query( $query ) {
$this->render->query = $query;
}
/**
* Return current query.
*
* @return mixed
*/
public function get_query() {
return $this->render->query;
}
/**
* Get database tables version.
*
* @return string
*/
public function get_db_version() {
return $this->db_version;
}
/**
* Set plugin data.
*
* @since 2.12.0
*/
public function set_plugin_data() {
$this->plugin_data = array(
'Version' => WPMTST_VERSION,
);
}
/**
* Get plugin data.
*
* @return array
* @since 2.12.0
*
*/
public function get_plugin_data() {
return $this->plugin_data;
}
/**
* Return plugin info.
*
* @return array
* @deprecated
*
*/
public function get_plugin_info() {
if ( ! function_exists( 'get_plugin_data' ) ) {
if ( file_exists( ABSPATH . 'wp-admin/includes/plugin.php' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( file_exists( ABSPATH . 'wp-admin/includes/admin.php' ) ) {
require_once ABSPATH . 'wp-admin/includes/admin.php';
}
}
return get_file_data(
__FILE__,
array(
'name' => 'Plugin Name',
'version' => 'Version',
)
);
}
public function add_onboarding_view( $views ) {
$query = new WP_Query(
array(
'post_type' => 'wpm-testimonial',
'post_status' => array(
'publish',
'future',
'trash',
'draft',
'inherit',
'pending',
),
)
);
$this->display_extension_tab();
if ( ! $query->have_posts() ) {
global $wp_list_table;
$wp_list_table = new WPMTST_Onboarding();
return array();
}
return $views;
}
public function display_extension_tab() {
?>
<h2 class="nav-tab-wrapper">
<?php
$tabs = array(
'testimonials' => array(
'name' => esc_html_x( 'Testimonials', 'post type general name', 'strong-testimonials' ),
'url' => admin_url( 'edit.php?post_type=wpm-testimonial' ),
'priority' => '1',
),
'suggest_feature' => array(
'name' => esc_html__( 'Suggest a feature', 'strong-testimonials' ),
'icon' => 'dashicons-external',
'url' => 'https://docs.google.com/forms/d/e/1FAIpQLScch0AchtnzxJsSrjUcW9ypcr1fZ9r-vyk3emEp8Sv47brb2g/viewform',
'target' => '_blank',
'priority' => '10',
),
);
if ( current_user_can( 'install_plugins' ) ) {
$tabs['extensions'] = array(
'name' => esc_html__( 'Extensions', 'strong-testimonials' ),
'url' => admin_url( 'edit.php?post_type=wpm-testimonial&page=strong-testimonials-addons' ),
'priority' => '5',
);
}
$tabs = apply_filters( 'wpmtst_add_edit_tabs', $tabs );
uasort( $tabs, array( 'Strong_Testimonials_Helper', 'sort_data_by_priority' ) );
WPMTST_Admin_Helpers::wpmtst_tab_navigation( $tabs, 'testimonials' );
?>
</h2>
<br/>
<?php
}
}
endif; // class_exists check.