-
Notifications
You must be signed in to change notification settings - Fork 1
/
testimonials.php
331 lines (283 loc) · 8.44 KB
/
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
<?php
/**
* Plugin Name: Cherry Testimonials
* Plugin URI:
* Description: A testimonials management plugin for WordPress.
* Version: 1.1.3
* Author: Zemez
* Author URI: https://zemez.io/wordpress/
* Text Domain: cherry-testi
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Domain Path: /languages
*
* @package Cherry_Testi
* @author Zemez
* @license GPL-3.0+
* @copyright 2002-2016, Zemez
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// If class `TM_Testimonials_Plugin` not exists.
if ( ! class_exists( 'TM_Testimonials_Plugin' ) ) {
/**
* Sets up and initializes the plugin.
*
* @since 1.0.0
*/
class TM_Testimonials_Plugin {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* A reference to an instance of cherry framework core class.
*
* @since 1.0.0
* @var object
*/
private $core = null;
/**
* The post type name.
*
* @since 1.0.0
* @var string
*/
private $post_type_name = 'tm-testimonials';
/**
* Sets up needed actions/filters for the plugin to initialize.
*
* @since 1.0.0
*/
public function __construct() {
// Internationalize the text strings used.
add_action( 'plugins_loaded', array( $this, 'constants' ), 1 );
add_action( 'plugins_loaded', array( $this, 'lang' ), 2 );
// Set up a Cherry core.
add_action( 'after_setup_theme', require( trailingslashit( dirname( __FILE__ ) ) . 'cherry-framework/setup.php' ), 0 );
add_action( 'after_setup_theme', array( $this, 'get_core' ), 1 );
add_action( 'after_setup_theme', array( 'Cherry_Core', 'load_all_modules' ), 2 );
add_action( 'after_setup_theme', array( $this, 'includes' ), 4 );
// Registers theme support for a `post-thumbnails` feature.
add_action( 'after_setup_theme', array( $this, 'add_theme_support' ) );
// Load public-facing stylesheet and javascript.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ), 9 );
// Register activation and deactivation hook.
add_action( 'tm_testimonials_plugin_pre_activation', array( $this, 'cpt_registration' ) );
register_activation_hook( __FILE__, array( $this, 'activation' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
}
/**
* Defines constants for the plugin.
*
* @since 1.0.0
*/
public function constants() {
/**
* Set constant name for the post type name.
*
* @since 1.0.0
*/
define( 'TM_TESTI_NAME', 'tm_testimonials' );
/**
* Set the version number of the plugin.
*
* @since 1.0.0
*/
define( 'TM_TESTI_VERSION', '1.1.3' );
/**
* Set the name for the `meta_key` value in the `wp_postmeta` table.
*
* @since 1.0.0
*/
define( 'TM_TESTI_POSTMETA', '_tm_testimonial_' );
/**
* Set constant path to the plugin directory.
*
* @since 1.0.0
*/
define( 'TM_TESTI_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
/**
* Set constant path to the plugin URI.
*
* @since 1.0.0
*/
define( 'TM_TESTI_URI', trailingslashit( plugin_dir_url( __FILE__ ) ) );
if ( ! defined( 'TM_TESTI_TMPL_SUBDIR' ) ) {
define( 'TM_TESTI_TMPL_SUBDIR', 'templates/shortcodes/testimonials/' );
}
}
/**
* Loads the translation files.
*
* @since 1.0.0
*/
public function lang() {
load_plugin_textdomain( 'cherry-testi', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Loads the core functions. These files are needed before loading anything else in the
* themes or plugins because they have required functions for use.
*
* @since 1.0.0
*/
public function get_core() {
/**
* Fires before loads the core.
*
* @since 1.0.0
*/
do_action( 'tm_testimonials_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' => TM_TESTI_DIR . 'cherry-framework',
'base_url' => TM_TESTI_URI . 'cherry-framework',
'modules' => array(
'cherry-js-core' => array(
'autoload' => true,
),
'cherry-ui-elements' => array(
'autoload' => false,
),
'cherry-utility' => array(
'autoload' => false,
),
'cherry-interface-builder' => array(
'autoload' => false,
),
'cherry-handler' => array(
'autoload' => false,
),
'cherry-post-meta' => array(
'autoload' => false,
),
'cherry5-insert-shortcode' => array(
'autoload' => false,
),
),
) );
return $this->core;
}
/**
* Loads files from the 'public/includes' folder.
*
* @since 1.0.0
*/
public function includes() {
require_once( TM_TESTI_DIR . 'public/includes/class-tm-testimonials-options.php' );
require_once( TM_TESTI_DIR . 'public/includes/class-tm-testimonials-hook.php' );
require_once( TM_TESTI_DIR . 'public/includes/class-tm-testimonials-registration.php' );
require_once( TM_TESTI_DIR . 'public/includes/class-tm-testimonials-page-template.php' );
require_once( TM_TESTI_DIR . 'public/includes/class-tm-testimonials-data.php' );
require_once( TM_TESTI_DIR . 'public/includes/class-tm-testimonials-shortcode.php' );
// Loads admin files.
if ( is_admin() ) {
require_once( TM_TESTI_DIR . 'admin/includes/class-tm-testimonials-admin.php' );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
require_once( TM_TESTI_DIR . 'admin/includes/class-tm-testimonials-ajax.php' );
}
}
}
/**
* Register and enqueue public-facing stylesheet.
*
* @since 1.0.0
*/
public function enqueue_assets() {
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_style( 'cherry-testi-swiper', plugins_url( 'includes/swiper/css/swiper.min.css', __FILE__ ), array(), '4.3.5' );
wp_enqueue_style( 'cherry-testi', plugins_url( 'public/assets/css/style.css', __FILE__ ), array( 'cherry-testi-swiper' ), TM_TESTI_VERSION );
wp_register_script( 'cherry-testi-swiper', plugins_url( "includes/swiper/js/swiper{$min}.js", __FILE__ ), array( 'jquery' ), '4.3.5', true );
wp_register_script( 'cherry-testi-public', plugins_url( "public/assets/js/public{$min}.js", __FILE__ ), array( 'cherry-testi-swiper' ), apply_filters( 'tm_testimonials_public_scripts_ver', TM_TESTI_VERSION ), true );
}
/**
* Fired when the plugin is activated.
*
* @since 1.0.0
*/
public function activation() {
do_action( 'tm_testimonials_plugin_pre_activation' );
flush_rewrite_rules();
do_action( 'tm_testimonials_plugin_activation' );
}
/**
* Fired when the plugin is deactivated.
*
* @since 1.0.0
*/
public function deactivation() {
flush_rewrite_rules();
}
/**
* Loads the CPT registration.
*
* @since 1.0.0
*/
public function cpt_registration() {
require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'public/includes/class-tm-testimonials-registration.php' );
/**
* Call CPT registration function.
*
* @link https://codex.wordpress.org/Function_Reference/flush_rewrite_rules#Examples
*/
TM_Testimonials_Registration::register_post_type();
TM_Testimonials_Registration::register_taxonomy();
}
/**
* Ensure that "post-thumbnails" support is available for those themes that don't register it.
*
* @since 1.0.0
*/
public function add_theme_support() {
if ( ! current_theme_supports( 'post-thumbnails' ) ) {
add_theme_support( 'post-thumbnails' );
}
}
/**
* Retrieve a post type name.
*
* @since 1.0.0
* @return string
*/
public function get_post_type_name() {
return apply_filters( 'tm_testimonials_get_post_type_name', $this->post_type_name );
}
/**
* Returns the instance.
*
* @since 1.0.0
* @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;
}
}
}
/**
* Gets the instance of the `TM_Testimonials_Plugin` class.
*
* @since 1.0.0
* @return object
*/
function tm_testimonials_plugin() {
return TM_Testimonials_Plugin::get_instance();
}
tm_testimonials_plugin();