-
Notifications
You must be signed in to change notification settings - Fork 2
/
cherry-services-list.php
642 lines (557 loc) · 14.2 KB
/
cherry-services-list.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
<?php
/**
* Plugin Name: Cherry Services List
* Plugin URI:
* Description: Cherry Services is a flexible WordPress plugin that lets you display your company’s services in a variety of ways.
* Version: 1.4.7
* Author: Zemez
* Author URI: https://zemez.io/wordpress/
* Text Domain: cherry-services
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Domain Path: /languages
*
* @package Cherry_Services_List
* @author Cherry Team
* @version 1.0.0
* @license GPL-3.0+
* @copyright 2002-2017, Cherry Team
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die();
}
// If class `Cherry_Services_List` doesn't exists yet.
if ( ! class_exists( 'Cherry_Services_List' ) ) {
/**
* Sets up and initializes the plugin.
*/
class Cherry_Services_List {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @access private
* @var object
*/
private static $instance = null;
/**
* A reference to an instance of cherry framework core class.
*
* @since 1.0.0
* @access private
* @var object
*/
private $core = null;
/**
* Holder for dynamic CSS instance
*
* @since 1.0.0
* @access public
* @var object
*/
public $dynamic_css = null;
/**
* Holder for Cherry Utilities instance
*
* @since 1.1.0
* @access public
* @var object
*/
public $utilities = null;
/**
* Holder for base plugin URL
*
* @since 1.0.0
* @access private
* @var string
*/
private $plugin_url = null;
/**
* Holder for base plugin path
*
* @since 1.0.0
* @access private
* @var string
*/
private $plugin_path = null;
/**
* Plugin version
*
* @since 1.0.0
* @access private
* @var string
*/
private $version = '1.4.7';
/**
* Plugin CPT name
*
* @since 1.0.0
* @access private
* @var string
*/
private $post_type = 'cherry-services';
/**
* Option to store all services data in
*
* @since 1.0.0
* @access private
* @var string
*/
private $option_key = 'cherry-services';
/**
* Theme supports array
*
* @since 1.0.0
* @access public
* @var array
*/
public $theme_supports = null;
/**
* Default options list
*
* @var array
*/
public $default_options = array(
'archive-page' => '',
'archive-page-shows' => 'posts',
'posts-per-page' => 9,
'archive-columns' => 3,
'single-template' => 'single',
'single-image-size' => 'thumbnail',
'listing-template' => 'default',
'listing-image-size' => 'thumbnail',
);
/**
* Options storage
*
* @var array
*/
private $options_val = null;
/**
* Elemntor compat instance
*
* @var object
*/
public $elementor_compat = null;
/**
* Sets up needed actions/filters for the plugin to initialize.
*
* @since 1.0.0
* @access public
* @return void
*/
public function __construct() {
// Load the installer core.
add_action( 'after_setup_theme', require( trailingslashit( dirname( __FILE__ ) ) . 'cherry-framework/setup.php' ), 0 );
// Load the core functions/classes required by the rest of the plugin.
add_action( 'after_setup_theme', array( $this, 'get_core' ), 1 );
// Load the modules.
add_action( 'after_setup_theme', array( 'Cherry_Core', 'load_all_modules' ), 2 );
// Load files
add_action( 'after_setup_theme', array( $this, 'load_files' ), 3 );
// Internationalize the text strings used.
add_action( 'after_setup_theme', array( $this, 'lang' ), 11 );
// Load the admin files.
add_action( 'after_setup_theme', array( $this, 'admin' ), 12 );
// Load the admin files.
add_action( 'after_setup_theme', array( $this, 'init_modules' ), 13 );
// Load public-facing stylesheets.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
// Load public-facing JavaScripts.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
// Register activation and deactivation hook.
register_activation_hook( __FILE__, array( $this, 'activation' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
}
/**
* Loads the core functions. These files are needed before loading anything else in the
* plugin because they have required functions for use.
*
* @since 1.0.0
* @access public
* @return object
*/
public function get_core() {
/**
* Fires before loads the plugin's core.
*
* @since 1.0.0
*/
do_action( 'cherry_services_list_core_before' );
global $chery_core_version;
if ( null !== $this->core ) {
return $this->core;
}
if ( 0 < sizeof( $chery_core_version ) ) {
$core_paths = array_values( $chery_core_version );
require_once( $core_paths[0] );
} else {
die( 'Class Cherry_Core not found' );
}
$this->core = new Cherry_Core( array(
'base_dir' => $this->plugin_path( 'cherry-framework' ),
'base_url' => $this->plugin_url( 'cherry-framework' ),
'modules' => array(
'cherry-interface-builder' => array(
'autoload' => false,
),
'cherry-toolkit' => array(
'autoload' => false,
),
'cherry-js-core' => array(
'autoload' => true,
),
'cherry-ui-elements' => array(
'autoload' => false,
),
'cherry-utility' => array(
'autoload' => false,
),
'cherry-handler' => array(
'autoload' => false,
),
'cherry-post-meta' => array(
'autoload' => false,
),
'cherry-dynamic-css' => array(
'autoload' => false,
),
'cherry5-insert-shortcode' => array(
'autoload' => false,
),
),
) );
return $this->core;
}
/**
* Check if passed capability disabled in theme.
*
* @since 1.0.0
* @param string $cap Capability name.
* @return boolean
*/
public function check_theme_supports( $cap ) {
if ( null === $this->theme_supports ) {
$this->theme_supports = apply_filters(
'cherry_services_theme_supports',
array(
'blank_theme' => true,
'customizer_options' => true,
)
);
}
if ( ! isset( $this->theme_supports[ $cap ] ) ) {
return false;
}
return $this->theme_supports[ $cap ];
}
/**
* Returns plugin version
*
* @return string
*/
public function get_version() {
return $this->version;
}
/**
* Load all globally available files.
*
* @return void
*/
public function load_files() {
$this->setup();
require $this->plugin_path( 'public/includes/class-cherry-services-list-templater.php' );
require $this->plugin_path( 'public/includes/class-cherry-services-list-tools.php' );
require $this->plugin_path( 'public/includes/class-cherry-services-list-data.php' );
require $this->plugin_path( 'public/includes/class-cherry-services-list-shortcode.php' );
require $this->plugin_path( 'public/includes/class-cherry-services-list-form.php' );
}
/**
* Manually init required modules.
*
* @return void
*/
public function init_modules() {
$this->utilities = $this->get_core()->init_module( 'cherry-utility', array(
'meta_key' => array(
'term_thumb' => 'cherry_terms_thumbnails',
),
) );
$this->dynamic_css = $this->get_core()->init_module(
'cherry_dynamic_css',
array()
);
}
/**
* Load base files.
*
* @return void
*/
public function setup() {
require $this->plugin_path( 'public/includes/class-cherry-services-list-init.php' );
}
/**
* Returns path to file or dir inside plugin folder
*
* @param string $path Path inside plugin dir.
* @return string
*/
public function plugin_path( $path = null ) {
if ( ! $this->plugin_path ) {
$this->plugin_path = trailingslashit( plugin_dir_path( __FILE__ ) );
}
return $this->plugin_path . $path;
}
/**
* Returns url to file or dir inside plugin folder
*
* @param string $path Path inside plugin dir.
* @return string
*/
public function plugin_url( $path = null ) {
if ( ! $this->plugin_url ) {
$this->plugin_url = trailingslashit( plugin_dir_url( __FILE__ ) );
}
return $this->plugin_url . $path;
}
/**
* Loads admin files.
*
* @since 1.0.0
* @access public
* @return void
*/
public function admin() {
add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_assets' ), 0 );
require $this->plugin_path( 'admin/includes/class-cherry-services-meta.php' );
require $this->plugin_path( 'admin/includes/class-cherry-services-options-page.php' );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
require $this->plugin_path( 'admin/includes/class-cherry-services-ajax.php' );
}
}
/**
* Loads the translation files.
*
* @since 1.0.0
* @access public
* @return void
*/
public function lang() {
load_plugin_textdomain( 'blank-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Returns services post type name
*
* @since 1.0.0
* @return string
*/
public function post_type() {
return apply_filters( 'cherry_services_post_type', $this->post_type );
}
/**
* Returns services taxonomy name
*
* @since 1.0.0
* @param string $type Tax type.
* @return string
*/
public function tax( $type = 'category' ) {
return $this->post_type() . '_' . esc_attr( $type );
}
/**
* Get the template path.
*
* @return string
*/
public function template_path() {
return apply_filters( 'cherry_services_template_path', 'cherry-services/' );
}
/**
* Returns key to store options in
*
* @since 1.0.0
* @return string
*/
public function option_key() {
return $this->option_key;
}
/**
* Get option value
*
* @param string $option Option name
* @param boolean $default Default value
* @return mixed
*/
public function get_option( $option, $default = false ) {
if ( null === $this->options_val ) {
$this->options_val = get_option( $this->option_key() );
}
if ( isset( $this->options_val[ $option ] ) ) {
return $this->options_val[ $option ];
} else {
return $default;
}
}
/**
* Register admin-related scripts and style.
*
* @return void
*/
public function register_admin_assets() {
wp_register_style(
'cherry-services-admin',
$this->plugin_url( 'admin/assets/css/cherry-services.css' ),
false,
$this->get_version()
);
wp_register_script(
'serialize-object',
$this->plugin_url( 'admin/assets/js/serialize-object.js' ),
array(),
$this->get_version(),
true
);
wp_register_script(
'cherry-services-admin',
$this->plugin_url( 'admin/assets/js/cherry-services-admin.js' ),
array( 'serialize-object' ),
$this->get_version(),
true
);
}
/**
* Enqueue public-facing stylesheets.
*
* @since 1.0.0
* @access public
* @return void
*/
public function enqueue_styles() {
$styles = apply_filters(
'cherry_services_styles',
array(
'cherry-services' => array(
'src' => $this->plugin_url( 'public/assets/css/cherry-services.css' ),
'deps' => array(),
'ver' => $this->get_version(),
'media' => 'all',
),
'cherry-services-theme' => array(
'src' => $this->plugin_url( 'public/assets/css/cherry-services-theme.css' ),
'deps' => array(),
'ver' => $this->get_version(),
'media' => 'all',
),
'cherry-services-grid' => array(
'src' => $this->plugin_url( 'public/assets/css/cherry-services-grid.css' ),
'deps' => array(),
'ver' => $this->get_version(),
'media' => 'all',
),
'font-awesome' => array(
'src' => $this->plugin_url( 'public/assets/css/font-awesome.min.css' ),
'deps' => array(),
'ver' => '4.6.3',
'media' => 'all',
),
)
);
if ( ! $this->check_theme_supports( 'blank_theme' ) && isset( $styles['cherry-services-theme'] ) ) {
unset( $styles['cherry-services-theme'] );
}
foreach ( $styles as $handle => $style ) {
wp_enqueue_style( $handle, $style['src'], $style['deps'], $style['ver'], $style['media'] );
}
}
/**
* Enqueue public-facing JavaScripts.
*
* @since 1.0.0
* @access public
* @return void
*/
public function enqueue_scripts() {
wp_register_script(
'cherry-services',
$this->plugin_url( 'public/assets/js/cherry-services.js' ),
array( 'jquery' ),
'1.0.0',
true
);
wp_localize_script(
'cherry-services',
'cherryServices',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'loader' => apply_filters(
'cherry_services_loader_html',
'<div class="cherry-spinner cherry-spinner-double-bounce"><div class="cherry-double-bounce1"></div><div class="cherry-double-bounce2"></div></div>'
)
)
);
}
/**
* Do some stuff on plugin activation
*
* @since 1.0.0
* @return void
*/
public function activation() {
$this->setup();
$init = Cherry_Services_List_Init::get_instance();
/**
* Call CPT registration function.
*
* @link https://codex.wordpress.org/Function_Reference/flush_rewrite_rules#Examples
*/
$init->register_post();
$init->register_tax();
flush_rewrite_rules();
$options = array(
$this->option_key() => get_option( $this->option_key() ),
$this->option_key() . '_default' => get_option( $this->option_key() . '_default' ),
);
foreach ( $options as $key => $value ) {
if ( empty( $value ) ) {
add_option( $key, $this->default_options, '', false );
}
}
}
/**
* Do some stuff on plugin activation
*
* @since 1.0.0
* @return void
*/
public function deactivation() {
flush_rewrite_rules();
}
/**
* Returns the instance.
*
* @since 1.0.0
* @access public
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
if ( ! function_exists( 'cherry_services_list' ) ) {
/**
* Returns instanse of the plugin class.
*
* @since 1.0.0
* @return object
*/
function cherry_services_list() {
return Cherry_Services_List::get_instance();
}
}
cherry_services_list();