-
Notifications
You must be signed in to change notification settings - Fork 0
/
cherry-socialize.php
executable file
·390 lines (326 loc) · 8.92 KB
/
cherry-socialize.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
<?php
/**
* Plugin Name: Cherry Socialize
* Plugin URI: https://wordpress.org/plugins/cherry-socialize/
* Description: A social plugin for WordPress.
* Version: 1.1.4
* Author: Jetimpex
* Author URI: https://jetimpex.com/wordpress/
* Text Domain: cherry-socialize
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Domain Path: /languages
*
* @link http://www.cherryframework.com/plugins/
* @since 1.1.3
* @package Cherry_Socialize
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die();
}
// If class `Cherry_Socialize` doesn't exists yet.
if ( ! class_exists( 'Cherry_Socialize' ) ) {
/**
* Sets up and initializes the Cherry Socialize plugin.
*/
class Cherry_Socialize {
/**
* 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_Core class.
*
* @since 1.0.0
* @access private
* @var object
*/
private $core = null;
/**
* Plugin folder URL.
*
* @since 1.0.0
* @access public
* @var string
*/
public $plugin_url = '';
/**
* Plugin folder path.
*
* @since 1.0.0
* @access public
* @var string
*/
public $plugin_dir = '';
/**
* Plugin version.
*
* @since 1.0.0
* @access public
* @var string
*/
public $version = '1.1.4';
/**
* Sets up needed actions/filters for the plugin to initialize.
*
* @since 1.0.0
*/
public function __construct() {
// Loads plugin dependencies.
add_action( 'plugins_loaded', array( $this, 'load_deps' ), 1 );
// Internationalize the text strings used.
add_action( 'plugins_loaded', array( $this, 'lang' ), 2 );
// 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 );
// Initialization of modules.
add_action( 'current_screen', array( $this, 'init_modules' ) );
// Load the include files.
add_action( 'after_setup_theme', array( $this, 'includes' ), 10 );
// Register a public javascripts and stylesheets.
add_action( 'wp_enqueue_scripts', array( $this, 'register_public_assets' ), 1 );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_public_assets' ), 9 );
// Register activation, deactivation and uninstall hooks.
register_activation_hook( __FILE__, array( $this, 'activation' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
register_uninstall_hook( __FILE__, array( 'Cherry_Socialize', 'uninstall' ) );
}
/**
* Loads plugin dependencies.
*
* @since 1.0.0
*/
public function load_deps() {
if ( ! class_exists( 'TLC_Transient_Update_Server' ) ) {
require_once $this->plugin_dir( 'includes/wp-tlc-transients/class-tlc-transient-update-server.php' );
}
new TLC_Transient_Update_Server;
if ( ! class_exists( 'TLC_Transient' ) ) {
require_once $this->plugin_dir( 'includes/wp-tlc-transients/class-tlc-transient.php' );
}
require_once $this->plugin_dir( 'includes/wp-tlc-transients/functions.php' );
}
/**
* Loads the translation files.
*
* @since 1.0.0
*/
public function lang() {
load_plugin_textdomain( 'cherry-socialize', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* 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
*/
public function get_core() {
/**
* Fires before loads the plugin's core.
*
* @since 1.0.0
*/
do_action( 'cherry_socialize_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_dir( 'cherry-framework' ),
'base_url' => $this->plugin_url( 'cherry-framework' ),
'modules' => array(
'cherry-js-core' => array(
'autoload' => false,
),
'cherry-ui-elements' => array(
'autoload' => false,
),
'cherry-widget-factory' => array(
'autoload' => true,
),
'cherry-interface-builder' => array(
'autoload' => false,
),
),
) );
return $this->core;
}
/**
* Initalize UI elements in admin area widgets page.
*
* @since 1.0.0
*/
public function init_modules() {
if ( ! is_admin() ) {
return;
}
$current_screen = get_current_screen();
if ( ( $current_screen && 'widgets' == $current_screen->id ) || is_customize_preview() ) {
$this->get_core()->init_module( 'cherry-js-core' );
$this->get_core()->init_module( 'cherry-interface-builder' );
}
}
/**
* Loads public files.
*
* @since 1.0.0
*/
public function includes() {
require_once $this->plugin_dir( 'public/includes/class-cherry-instagram-widget.php' );
require_once $this->plugin_dir( 'public/includes/class-cherry-sharing.php' );
require_once $this->plugin_dir( 'public/includes/class-cherry-user-social-links.php' );
}
/**
* Get plugin URL (or some plugin dir/file URL)
*
* @since 1.0.0
* @param string $path dir or file inside plugin dir.
* @return string
*/
public function plugin_url( $path = null ) {
if ( ! $this->plugin_url ) {
$this->plugin_url = plugin_dir_url( __FILE__ );
}
if ( null !== $path ) {
$path = wp_normalize_path( $path );
return $this->plugin_url . ltrim( $path, '/' );
}
return $this->plugin_url;
}
/**
* Get plugin dir path (or some plugin dir/file path)
*
* @since 1.0.0
* @param string $path dir or file inside plugin dir.
* @return string
*/
public function plugin_dir( $path = null ) {
if ( ! $this->plugin_dir ) {
$this->plugin_dir = plugin_dir_path( __FILE__ );
}
if ( null !== $path ) {
$path = wp_normalize_path( $path );
return $this->plugin_dir . $path;
}
return $this->plugin_dir;
}
/**
* Register public assets.
*
* @since 1.0.0
*/
public function register_public_assets() {
wp_register_style( 'font-awesome', $this->plugin_url( 'assets/css/font-awesome.min.css' ), array(), '4.7.0' );
wp_register_style( 'cherry-socialize-public', $this->plugin_url( 'assets/css/public.css' ), array( 'font-awesome' ), $this->version );
}
/**
* Enqueue public assets.
*
* @since 1.1.0
*/
public function enqueue_public_assets() {
$is_conditional_check = apply_filters( 'cherry_socialize_dequeue_style', false );
if ( false === $is_conditional_check ) {
wp_enqueue_style( 'cherry-socialize-public' );
}
}
/**
* Retrieve the name of the highest priority template file that exists, optionally loading that file.
*
* @since 1.0.0
* @param string $name Template name
* @return string
*/
public function locate_template( $name ) {
$template = locate_template( "cherry-socialize/{$name}", false, false );
if ( empty( $template ) ) {
$template = $this->plugin_dir( "public/views/$name" );
}
return $template;
}
/**
* On plugin activation.
*
* @since 1.0.0
*/
public function activation() {
/**
* Fire when plugin are activate.
*
* @since 1.0.0
*/
do_action( 'cherry_socialize_activate' );
}
/**
* On plugin deactivation.
*
* @since 1.0.0
*/
public function deactivation() {
/**
* Fire when plugin are deactivate.
*
* @since 1.0.0
*/
do_action( 'cherry_socialize_deactivate' );
}
/**
* On plugin uninstall.
*
* @since 1.0.0
*/
public static function uninstall() {
$cache_keys = get_option( 'cherry_instagram_widget_cache_keys', array() );
if ( ! empty( $cache_keys ) ) {
foreach ( $cache_keys as $widget_id => $key ) {
delete_transient( $key );
}
}
delete_option( 'cherry_instagram_widget_cache_keys' );
/**
* Fire when plugin are uninstall.
*
* @since 1.0.0
*/
do_action( 'cherry_socialize_uninstall' );
}
/**
* Returns the instance.
*
* @since 1.0.0
*/
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_socialize' ) ) {
/**
* Returns instanse of the plugin class.
*
* @since 1.0.0
* @return object
*/
function cherry_socialize() {
return Cherry_Socialize::get_instance();
}
}
cherry_socialize();