-
Notifications
You must be signed in to change notification settings - Fork 3
/
cherry-team.php
389 lines (328 loc) · 9.99 KB
/
cherry-team.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
<?php
/**
* Plugin Name: Cherry Team
* Plugin URI: http://www.cherryframework.com/
* Description: A team management plugin for WordPress.
* Version: 1.0.8
* Author: Cherry Team
* Author URI: http://www.cherryframework.com/
* Text Domain: cherry-team
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Domain Path: /languages
*
* @package Cherry Team
* @category Core
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// If class 'Cherry_Team' not exists.
if ( ! class_exists( 'Cherry_Team' ) ) {
/**
* Sets up and initializes the Cherry Team plugin.
*
* @since 1.0.0
*/
class Cherry_Team {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Sets up needed actions/filters for the plugin to initialize.
*
* @since 1.0.0
*/
public function __construct() {
$this->constants();
$this->includes();
// Internationalize the text strings used.
add_action( 'plugins_loaded', array( $this, 'lang' ), 2 );
// Load the admin files.
add_action( 'plugins_loaded', array( $this, 'admin' ), 4 );
// Load public-facing style sheet and JavaScript.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ), 20 );
add_filter( 'cherry_compiler_static_css', array( $this, 'add_style_to_compiler' ) );
add_action( 'wp_head', array( $this, 'add_icons_font' ), 99 );
// Adds options.
add_filter( 'cherry_layouts_options_list', array( $this, 'add_cherry_options' ), 11 );
add_filter( 'cherry_get_single_post_layout', array( $this, 'get_single_option' ), 11, 2 );
// Register activation and deactivation hook.
register_activation_hook( __FILE__, array( __CLASS__, 'activation' ) );
register_deactivation_hook( __FILE__, array( __CLASS__, 'deactivation' ) );
}
/**
* Defines constants for the plugin.
*
* @since 1.0.0
*/
function constants() {
/**
* Set constant name for the post type name.
*
* @since 1.0.0
*/
define( 'CHERRY_TEAM_NAME', 'team' );
/**
* Set the version number of the plugin.
*
* @since 1.0.0
*/
define( 'CHERRY_TEAM_VERSION', '1.0.8' );
/**
* Set the slug of the plugin.
*
* @since 1.0.0
*/
define( 'CHERRY_TEAM_SLUG', basename( dirname( __FILE__ ) ) );
/**
* Set the name for the 'meta_key' value in the 'wp_postmeta' table.
*
* @since 1.0.0
*/
define( 'CHERRY_TEAM_POSTMETA', '_cherry_team' );
/**
* Set constant path to the plugin directory.
*
* @since 1.0.0
*/
define( 'CHERRY_TEAM_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
/**
* Set constant path to the plugin URI.
*
* @since 1.0.0
*/
define( 'CHERRY_TEAM_URI', trailingslashit( plugin_dir_url( __FILE__ ) ) );
}
/**
* Loads files from the '/inc' folder.
*
* @since 1.0.0
*/
function includes() {
require_once( trailingslashit( CHERRY_TEAM_DIR ) . 'public/includes/class-cherry-team-registration.php' );
require_once( trailingslashit( CHERRY_TEAM_DIR ) . 'public/includes/class-cherry-team-templates.php' );
require_once( trailingslashit( CHERRY_TEAM_DIR ) . 'public/includes/class-cherry-team-data.php' );
require_once( trailingslashit( CHERRY_TEAM_DIR ) . 'public/includes/class-cherry-team-shortcode.php' );
require_once( trailingslashit( CHERRY_TEAM_DIR ) . 'public/includes/class-cherry-team-widget.php' );
}
/**
* Loads the translation files.
*
* @since 1.0.0
*/
function lang() {
load_plugin_textdomain( 'cherry-team', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Loads admin files.
*
* @since 1.0.0
*/
function admin() {
if ( is_admin() ) {
require_once( CHERRY_TEAM_DIR . 'admin/includes/class-cherry-team-admin.php' );
require_once( CHERRY_TEAM_DIR . 'admin/includes/class-cherry-update/class-cherry-plugin-update.php' );
$Cherry_Plugin_Update = new Cherry_Plugin_Update();
$Cherry_Plugin_Update -> init( array(
'version' => CHERRY_TEAM_VERSION,
'slug' => CHERRY_TEAM_SLUG,
'repository_name' => CHERRY_TEAM_SLUG,
));
}
}
/**
* Register and enqueue public-facing style sheet.
*
* @since 1.0.0
*/
public function enqueue_styles() {
wp_enqueue_style( 'cherry-team', CHERRY_TEAM_URI.'public/assets/css/style.css', '', CHERRY_TEAM_VERSION );
}
/**
* Pass style handle to CSS compiler.
*
* @since 1.0.0
*
* @param array $handles CSS handles to compile.
*/
function add_style_to_compiler( $handles ) {
$handles = array_merge(
array( 'cherry-team' => plugins_url( 'public/assets/css/style.css', __FILE__ ) ),
$handles
);
return $handles;
}
/**
* Register Icon font for social nets icons
*
* @since 1.0.0
*/
public function add_icons_font() {
$user_font = apply_filters( 'cherry_team_icon_font', false );
if ( false !== $user_font ) {
wp_cache_set( 'team_icon_font', $user_font, 'cherry' );
return;
}
global $wp_styles;
if ( ! is_array( $wp_styles->registered ) ) {
return;
}
if ( isset( $wp_styles->registered['font-awesome'] ) ) {
wp_cache_set( 'team_icon_font', 'font-awesome', 'cherry' );
return;
}
wp_register_style(
'font-awesome',
'//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css',
false,
'4.4.0',
'all'
);
wp_cache_set( 'team_icon_font', 'font-awesome', 'cherry' );
return;
}
/**
* Static method to call icon font handle when needed
*
* @since 1.0.0
*/
public static function enqueue_icon_font() {
$handle = wp_cache_get( 'team_icon_font', 'cherry' );
if ( ! $handle ) {
return;
}
wp_enqueue_style( $handle );
}
/**
* On plugin activation.
*
* @since 1.0.0
*/
public static function activation() {
Cherry_Team_Registration::register_post();
Cherry_Team_Registration::register_tax();
flush_rewrite_rules();
}
/**
* On plugin deactivation.
*
* @since 1.0.0
*/
public static function deactivation() {
flush_rewrite_rules();
}
/**
* Staic function to get plugin metadta on frontend and in admin
*
* @since 1.0.0
*
* @param int $post_id post ID to get meta for.
* @param string $name meta name to get.
* @param mixed $default default meta value.
* @return mixed
*/
public static function get_meta( $post_id = null, $name, $default = false ) {
$post_id = ( null == $post_id ) ? get_the_id() : $post_id;
$meta = get_post_meta( $post_id, CHERRY_TEAM_POSTMETA, true );
if ( ! $meta || ! is_array( $meta ) || ! isset( $meta[ $name ] ) ) {
return $default;
}
return $meta[ $name ];
}
/**
* Adds a option in `Grid -> Layouts` subsection.
*
* @since 1.0.0
* @param array $layouts_options current options array.
* @return array
*/
public function add_cherry_options( $layouts_options ) {
$layouts_options['single-team-layout'] = array(
'type' => 'radio',
'title' => __( 'Team posts', 'cherry-team' ),
'hint' => array(
'type' => 'text',
'content' => __( 'You can choose if you want to display sidebars and how you want to display them.', 'cherry-team' ),
),
'value' => 'content-sidebar',
'display_input' => false,
'options' => array(
'sidebar-content' => array(
'label' => __( 'Left sidebar', 'cherry-team' ),
'img_src' => get_template_directory_uri() . '/lib/admin/assets/images/svg/page-layout-left-sidebar.svg',
),
'content-sidebar' => array(
'label' => __( 'Right sidebar', 'cherry-team' ),
'img_src' => get_template_directory_uri() . '/lib/admin/assets/images/svg/page-layout-right-sidebar.svg',
),
'sidebar-content-sidebar' => array(
'label' => __( 'Left and right sidebar', 'cherry-team' ),
'img_src' => get_template_directory_uri() . '/lib/admin/assets/images/svg/page-layout-both-sidebar.svg',
),
'sidebar-sidebar-content' => array(
'label' => __( 'Two sidebars on the left', 'cherry-team' ),
'img_src' => get_template_directory_uri() . '/lib/admin/assets/images/svg/page-layout-sameside-left-sidebar.svg',
),
'content-sidebar-sidebar' => array(
'label' => __( 'Two sidebars on the right', 'cherry-team' ),
'img_src' => get_template_directory_uri() . '/lib/admin/assets/images/svg/page-layout-sameside-right-sidebar.svg',
),
'no-sidebar' => array(
'label' => __( 'No sidebar', 'cherry-team' ),
'img_src' => get_template_directory_uri() . '/lib/admin/assets/images/svg/page-layout-fullwidth.svg',
),
),
);
return $layouts_options;
}
/**
* Rewrite a single option.
*
* @since 1.0.0
*/
public function get_single_option( $value, $object_id ) {
if ( CHERRY_TEAM_NAME != get_post_type( $object_id ) ) {
return $value;
}
return $this->get_option( 'single-team-layout', 'content-sidebar' );
}
/**
* Return a values for a named option from the options database table.
*
* @since 1.0.0
* @param string $option Name of the option to retrieve.
* @param mixed $default The default value to return if no value is returned.
* @return mixed Current value for the specified option. If the option does not exist, returns
* parameter $default if specified or boolean FALSE by default.
*/
public function get_option( $option, $default = false ) {
if ( function_exists( 'cherry_get_option' ) ) {
$result = cherry_get_option( $option, $default );
return $result;
}
return $default;
}
/**
* 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;
}
}
Cherry_Team::get_instance();
}