PluginProbe
AWSM Team – Team Showcase Plugin / trunk
AWSM Team – Team Showcase Plugin vtrunk
trunk 1.0 1.1 1.1.2 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4
awsm-team / awsm-team.php

awsm-team.php in AWSM Team – Team Showcase Plugin trunk, at awsm-team.php

850 lines 26.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: AWSM Team
4 * Plugin URI: https://docs.awsm.in/team-pro-documentation
5 * Description: The most versatile plugin to create and manage your Team page. Packed with 8 unique presets and number of styles to choose from.
6 * Version: 1.3.5
7 * Requires at least: 4.0
8 * Requires PHP: 5.6
9 * Author: AWSM Innovations
10 * Author URI: http://awsm.in/
11 * License: GPL v2 or later
12 * Copyright: AWSM Innovations
13 * Text domain: awsm-team
14 * Domain Path: /language
15 *
16 * @package awsm-team
17 */
18
19 /**
20 * Exit if direct access
21 */
22 if ( ! defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 if ( ! class_exists( 'Awsm_Team_Lite' ) ) :
27 /**
28 * Team main class
29 *
30 * @author: AWSM Innovations
31 */
32 class Awsm_Team_Lite {
33
34 /**
35 * The single instance of the class.
36 *
37 * @var Awsm_Team_Lite
38 */
39 private static $instance = null;
40
41 /**
42 * Plugin settings.
43 *
44 * @var array
45 */
46 private $settings;
47
48 /**
49 * Creates or returns an instance of this class.
50 *
51 * @since 1.0.0
52 */
53 public static function get_instance() {
54 // If an instance hasn't been created and set to $instance create an instance and set it to $instance.
55 if ( null == self::$instance ) {
56 self::$instance = new self();
57 }
58 return self::$instance;
59 }
60
61 /**
62 * Awsm Team Constructor.
63 */
64 public function __construct() {
65 $this->settings = array(
66 'plugin_path' => plugin_dir_path( __FILE__ ),
67 'plugin_url' => plugin_dir_url( __FILE__ ),
68 'plugin_base' => dirname( plugin_basename( __FILE__ ) ),
69 'plugin_file' => __FILE__,
70 'plugin_version' => '1.3.5',
71 );
72 $this->load_plugin_textdomain();
73 $this->run_plugin();
74 $this->adminfunctions();
75 }
76
77 /**
78 * Localisation
79 *
80 * @since: 1.0
81 */
82 public function load_plugin_textdomain() {
83 load_plugin_textdomain( 'awsm-team', false, $this->settings['plugin_base'] . '/language/' );
84 }
85
86 /**
87 * Main plugin function
88 *
89 * @since: 1.0
90 */
91 public function run_plugin() {
92 add_action( 'init', array( $this, 'create_member_support' ) );
93 add_action( 'init', array( $this, 'custom_image_size' ) );
94 add_shortcode( 'awsmteam', array( $this, 'awsmteam_shortcode' ) );
95 add_action( 'wp_enqueue_scripts', array( $this, 'embed_front_script_styles' ) );
96 add_action( 'wp_head', array( $this, 'custom_css' ) );
97 }
98
99 /**
100 * Team custom css on theme head
101 *
102 * @since: 1.0
103 */
104 public function custom_css() {
105 global $wp_query;
106 $posts = $wp_query->posts;
107 $pattern = '(awsmteam)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
108 $snippet = '';
109 $shortcodes = array();
110 if ( $posts ) {
111 foreach ( $posts as $post ) {
112 $pattern = get_shortcode_regex();
113 preg_match( '/\[awsmteam (.+?)\]/', $post->post_content, $matches );
114 if ( is_array( $matches ) && isset( $matches[1] ) ) {
115 if ( is_array( shortcode_parse_atts( $matches[1] ) ) ) {
116 $shortcodes[] = shortcode_parse_atts( $matches[1] );
117 }
118 }
119
120 if ( ! empty( $shortcodes ) ) {
121 foreach ( $shortcodes as $shortcode ) {
122 if ( isset( $shortcode['id'] ) ) {
123 $custom_css = get_post_meta( $shortcode['id'], 'custom_css', true );
124 if ( $custom_css ) {
125 $snippet .= $custom_css;
126 }
127 }
128 }
129 }
130 }
131 if ( $snippet ) {
132 printf( '<style type="text/css">%s</style>', wp_strip_all_tags( $snippet ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
133 }
134 }
135 }
136
137 /**
138 * Custom image size for team memebers
139 *
140 * @since 1.0
141 */
142 public function custom_image_size() {
143 if ( function_exists( 'add_image_size' ) ) {
144 add_image_size( 'awsm_team', 500, 500, true );
145 }
146 }
147
148 /**
149 * AWSM team shortocde
150 *
151 * @since 1.0
152 *
153 * @param array $atts Shortcode attributes.
154 */
155 public function awsmteam_shortcode( $atts ) {
156 $shortcode_atts = shortcode_atts(
157 array(
158 'id' => false,
159 ),
160 $atts,
161 'awsmteam'
162 );
163 $id = $shortcode_atts['id'];
164 $options = $this->get_options( 'awsm_team', $id );
165 if ( ! $options ) {
166 return '<div class="awsm-team-error">' . esc_html__( 'Team not found', 'awsm-team' ) . '</div>';
167 }
168 if ( empty( $options['memberlist'] ) ) {
169 return '<div class="awsm-team-error">' . esc_html__( 'No members found', 'awsm-team' ) . '</div>';
170 }
171
172 // Define a whitelist of allowed template styles.
173 $allowed_styles = array( 'cards', 'list', 'table' );
174
175 // Sanitize and validate the team-style option.
176 $team_style = preg_replace( '/[^a-zA-Z0-9_-]/', '', $options['team-style'] );
177
178 if ( ! in_array( $team_style, $allowed_styles ) ) {
179 return '<div class="awsm-team-error">' . esc_html__( 'Invalid team style', 'awsm-team' ) . '</div>';
180 }
181
182 $template = $this->settings['plugin_path'] . 'templates/' . $team_style . '.php';
183 if ( file_exists( $template ) ) {
184 ob_start();
185 $teamargs = array(
186 'orderby' => 'post__in',
187 'post_type' => 'awsm_team_member',
188 'post__in' => $options['memberlist'],
189 'posts_per_page' => -1,
190 );
191 $team = new WP_Query( $teamargs );
192 include $template;
193 wp_reset_postdata();
194 return ob_get_clean();
195 } else {
196 return '<div class="awsm-team-error">' . esc_html__( 'Template not found', 'awsm-team' ) . '</div>';
197 }
198 }
199
200 /**
201 * Register front scripts
202 *
203 * @since 1.0.0
204 */
205 public function embed_front_script_styles() {
206 wp_enqueue_script(
207 'awsm-team',
208 plugins_url( 'js/team.min.js', $this->settings['plugin_file'] ),
209 array(
210 'jquery',
211 ),
212 $this->settings['plugin_version'],
213 true
214 );
215 wp_enqueue_style( 'awsm-team', plugins_url( 'css/team.min.css', $this->settings['plugin_file'] ), false, $this->settings['plugin_version'], 'all' );
216 }
217
218 /**
219 * Create custom post type
220 *
221 * @since 1.0.0
222 */
223 public function create_member_support() {
224 // Create awsm_team_member post type.
225 if ( post_type_exists( 'awsm_team_member' ) ) {
226 return;
227 }
228 $singular = __( 'Team Member', 'awsm-team' );
229 $plural = __( 'Team Members', 'awsm-team' );
230 $labels = array(
231 'name' => $plural,
232 'singular_name' => $singular,
233 'menu_name' => __( 'AWSM Team', 'awsm-team' ),
234 'add_new' => __( 'Add New Member', 'awsm-team' ),
235 /* translators: %s: singular term */
236 'add_new_item' => sprintf( __( 'Add %s', 'awsm-team' ), $singular ),
237 /* translators: %s: singular term */
238 'new_item' => sprintf( __( 'New %s', 'awsm-team' ), $singular ),
239 /* translators: %s: singular term */
240 'edit_item' => sprintf( __( 'Edit %s', 'awsm-team' ), $singular ),
241 /* translators: %s: singular term */
242 'view_item' => sprintf( __( 'View %s', 'awsm-team' ), $singular ),
243 'all_items' => sprintf( __( 'Members', 'awsm-team' ) ),
244 /* translators: %s: plural term */
245 'search_items' => sprintf( __( 'Search %s', 'awsm-team' ), $plural ),
246 /* translators: %s: plural term */
247 'not_found' => sprintf( __( 'No %s found', 'awsm-team' ), $plural ),
248 /* translators: %s: plural term */
249 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'awsm-team' ), $plural ),
250 );
251 $cp_args = array(
252 'labels' => $labels,
253 /* translators: %s: plural term */
254 'description' => sprintf( __( 'This is where you can create and manage %s.', 'awsm-team' ), $plural ),
255 'publicly_queryable' => false,
256 'show_ui' => true,
257 'show_in_menu' => true,
258 'capability_type' => 'post',
259 'supports' => array(
260 'title',
261 'editor',
262 'thumbnail',
263 'custom-fields',
264 ),
265 'menu_icon' => 'dashicons-admin-users',
266 'show_in_rest' => true,
267 );
268 register_post_type( 'awsm_team_member', $cp_args );
269 if ( post_type_exists( 'awsm_team' ) ) {
270 return;
271 }
272 $singular = __( 'Team', 'awsm-team' );
273 $plural = __( 'Teams', 'awsm-team' );
274 $labels = array(
275 'name' => $plural,
276 'singular_name' => $singular,
277 'menu_name' => __( 'Awsm Team', 'awsm-team' ),
278 'add_new' => __( 'Add Team', 'awsm-team' ),
279 /* translators: %s: singular term */
280 'add_new_item' => sprintf( __( 'Add %s', 'awsm-team' ), $singular ),
281 /* translators: %s: singular term */
282 'new_item' => sprintf( __( 'New %s', 'awsm-team' ), $singular ),
283 /* translators: %s: singular term */
284 'edit_item' => sprintf( __( 'Edit %s', 'awsm-team' ), $singular ),
285 /* translators: %s: singular term */
286 'view_item' => sprintf( __( 'View %s', 'awsm-team' ), $singular ),
287 'all_items' => sprintf( __( 'Teams', 'awsm-team' ) ),
288 /* translators: %s: plural term */
289 'search_items' => sprintf( __( 'Search %s', 'awsm-team' ), $plural ),
290 /* translators: %s: plural term */
291 'not_found' => sprintf( __( 'No %s found', 'awsm-team' ), $plural ),
292 /* translators: %s: plural term */
293 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'awsm-team' ), $plural ),
294 );
295 $cp_args = array(
296 'labels' => $labels,
297 /* translators: %s: plural term */
298 'description' => sprintf( __( 'This is where you can create and manage %s.', 'awsm-team' ), $plural ),
299 'show_ui' => true,
300 'show_in_menu' => 'edit.php?post_type=awsm_team_member',
301 'capability_type' => 'post',
302 'supports' => array(
303 'title',
304 ),
305 );
306 register_post_type( 'awsm_team', $cp_args );
307 }
308
309 /**
310 * Initiate admin functions.
311 *
312 * @since 1.0
313 */
314 public function adminfunctions() {
315 if ( is_admin() ) {
316 add_action( 'add_meta_boxes', array( $this, 'register_metaboxes' ) );
317 add_action( 'save_post', array( $this, 'save_metabox_data' ), 10, 3 );
318 add_action( 'admin_enqueue_scripts', array( $this, 'meta_box_scripts' ), 10, 1 );
319 add_action( 'admin_menu', array( $this, 'add_submenu_items' ), 12 );
320 add_action( 'edit_form_after_title', array( $this, 'shortcode_preview' ) );
321 add_filter( 'manage_awsm_team_member_posts_columns', array( $this, 'custom_columns_member' ) );
322 add_action( 'manage_awsm_team_member_posts_custom_column', array( $this, 'custom_columns_member_data' ), 10, 2 );
323 add_filter( 'manage_awsm_team_posts_columns', array( $this, 'custom_columns_team' ) );
324 add_action( 'manage_awsm_team_posts_custom_column', array( $this, 'custom_columns_team_data' ), 10, 2 );
325 add_filter( 'admin_post_thumbnail_html', array( $this, 'image_help' ) );
326 add_filter( 'admin_post_thumbnail_size', array( $this, 'custom_admin_thumb_size' ) );
327 }
328 }
329
330 /**
331 * Custom thumbnail size for awsm_team_member
332 *
333 * @since 1.0
334 *
335 * @param string|array $thumb_size Post thumbnail image size to display in the meta box.
336 * @return string|array
337 */
338 public function custom_admin_thumb_size( $thumb_size ) {
339 global $post_type,$post;
340 if ( $post_type == 'awsm_team_member' ) {
341 $thumb_size = 'awsm_team';
342 }
343 return $thumb_size;
344 }
345
346 /**
347 * Image size help text.
348 *
349 * @since 1.0.0
350 *
351 * @param string $content Admin post thumbnail HTML markup.
352 * @return string
353 */
354 public function image_help( $content ) {
355 global $post_type,$post;
356 if ( $post_type == 'awsm_team_member' ) {
357 if ( ! has_post_thumbnail( $post->ID ) ) {
358 $content .= '<p>' . __( 'Please upload square-cropped photos with a minimum dimension of 500px', 'awsm-team' ) . '</p>';
359 }
360 }
361 return $content;
362 }
363
364 /**
365 * Custom column on member table.
366 *
367 * @since 1.0.0
368 *
369 * @param array $columns An associative array of column headings.
370 * @return array
371 */
372 public function custom_columns_member( $columns ) {
373 $columns = array(
374 'cb' => '<input type="checkbox" />',
375 'title' => __( 'Name', 'awsm-team' ),
376 'member_image' => __( 'Photo', 'awsm-team' ),
377 'designation' => __( 'Designation', 'awsm-team' ),
378 'date' => 'Date',
379 );
380 return $columns;
381 }
382
383 /**
384 * Custom member table data.
385 *
386 * @since 1.0.0
387 * @param string $column The name of the column to display.
388 * @param int $post_ID The current post ID.
389 */
390 public function custom_columns_member_data( $column, $post_ID ) {
391 $options = $this->get_options( 'awsm_team_member', $post_ID );
392 switch ( $column ) {
393 case 'member_image':
394 the_post_thumbnail( 'thumbnail' );
395 break;
396 case 'designation':
397 echo wp_kses( $options['awsm-team-designation'], 'post' );
398 break;
399 }
400 }
401
402 /**
403 * Custom member column for team.
404 *
405 * @since 1.0.0
406 *
407 * @param array $columns An associative array of column headings.
408 * @return array
409 */
410 public function custom_columns_team( $columns ) {
411 $columns = array(
412 'cb' => '<input type="checkbox" />',
413 'title' => __( 'Name', 'awsm-team' ),
414 'members' => __( 'Members', 'awsm-team' ),
415 'preset' => __( 'Preset', 'awsm-team' ),
416 'style' => __( 'Style', 'awsm-team' ),
417 'shortcode' => __( 'Shortcode', 'awsm-team' ),
418 );
419 return $columns;
420 }
421
422 /**
423 * Custom member column data for team.
424 *
425 * @since 1.0.0
426 *
427 * @param string $column The name of the column to display.
428 * @param int $post_ID The current post ID.
429 */
430 public function custom_columns_team_data( $column, $post_ID ) {
431 $options = $this->get_options( 'awsm_team', $post_ID );
432 $post = get_post( $post_ID );
433 switch ( $column ) {
434 case 'members':
435 echo count( $options['memberlist'] );
436 break;
437 case 'preset':
438 echo esc_html( $options['team-style'] );
439 break;
440 case 'style':
441 echo esc_html( $options['preset'] );
442 break;
443 case 'shortcode':
444 printf( '<code>[awsmteam id="%s"]</code>', esc_attr( $post_ID ) );
445 break;
446 }
447 }
448
449 /**
450 * Shortcode preview on team edit page.
451 *
452 * @since 1.0.0
453 * @param WP_Post $post Post object.
454 */
455 public function shortcode_preview( $post ) {
456 if ( 'awsm_team' == $post->post_type && 'publish' == $post->post_status ) {
457 printf( '<p>%1$s: <code>[awsmteam id="%2$s"]</code><button id="copy-awsm" type="button" data-clipboard-text="[awsmteam id=&quot;%2$s&quot;]" class="button">%3$s</button></p>', esc_html__( 'Shortcode', 'awsm-team' ), esc_attr( $post->ID ), esc_html__( 'Copy', 'awsm-team' ) );
458 }
459 return;
460 }
461
462 /**
463 * Loads meta box helper scripts.
464 *
465 * @since 1.0.0
466 * @param string $hook The current admin page.
467 */
468 public function meta_box_scripts( $hook ) {
469 global $post;
470 if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
471 if ( 'awsm_team_member' == $post->post_type || 'awsm_team' == $post->post_type ) {
472 wp_enqueue_style( 'awsm-team-admin', plugins_url( 'css/admin.css', $this->settings['plugin_file'] ), false, $this->settings['plugin_version'], 'all' );
473 wp_enqueue_script( 'team-meta-box', plugins_url( 'js/team-admin.js', $this->settings['plugin_file'] ), array( 'jquery', 'jquery-ui-sortable', 'wp-util' ), $this->settings['plugin_version'] );
474 wp_enqueue_script( 'select2', plugins_url( 'js/select2.min.js', $this->settings['plugin_file'] ), array( 'jquery' ), $this->settings['plugin_version'] );
475 wp_enqueue_style( 'select2', plugins_url( 'css/select2.min.css', $this->settings['plugin_file'] ), false, $this->settings['plugin_version'], 'all' );
476 wp_enqueue_style( 'awsm-team-icomoon-css', plugins_url( 'css/icomoon.css', $this->settings['plugin_file'] ), false, $this->settings['plugin_version'], 'all' );
477 }
478 }
479 }
480
481 /**
482 * Adding submenu items
483 *
484 * @since 1.0.0
485 */
486 public function add_submenu_items() {
487 add_submenu_page( 'edit.php?post_type=awsm_team_member', __( 'Add Team', 'awsm-team' ), __( 'Add Team', 'awsm-team' ), 'manage_options', 'post-new.php?post_type=awsm_team' );
488 }
489
490 /**
491 * Register meta box
492 *
493 * @since 1.0.0
494 */
495 public function register_metaboxes() {
496 add_meta_box( 'member_details', __( 'Member Details', 'awsm-team' ), array( $this, 'member_details_meta' ), 'awsm_team_member' );
497 add_meta_box( 'team_details', __( 'Team Details', 'awsm-team' ), array( $this, 'team_details_meta' ), 'awsm_team', 'normal', 'high' );
498 add_meta_box( 'awsm_team_pro', __( 'Upgrade to Pro', 'awsm-team' ), array( $this, 'pro_metabox' ), 'awsm_team', 'side', 'default' );
499 }
500
501 /**
502 * Upgrade to PRO meta box handler.
503 */
504 public function pro_metabox() {
505 include $this->settings['plugin_path'] . 'includes/pro-features.php';
506 }
507
508 /**
509 * Meta box display callback - Member details.
510 *
511 * @since 1.0.0
512 * @param WP_Post $post Current post object.
513 */
514 public function member_details_meta( $post ) {
515 wp_nonce_field( basename( __FILE__ ), 'awsm_meta_details' );
516 $awsm_social = get_post_meta( $post->ID, 'awsm_social', true );
517 $socialicons = array( 'mail', 'link', 'phone', 'google-plus', 'google-plus2', 'hangouts', 'google-drive', 'facebook', 'facebook2', 'instagram', 'whatsapp', 'twitter', 'youtube', 'vimeo', 'vimeo2', 'flickr', 'flickr2', 'dribbble', 'behance', 'behance2', 'dropbox', 'wordpress', 'blogger', 'tumblr', 'tumblr2', 'skype', 'linkedin2', 'linkedin', 'stackoverflow', 'pinterest2', 'pinterest', 'foursquare', 'github', 'flattr', 'xing', 'xing2', 'stumbleupon', 'stumbleupon2', 'delicious', 'lastfm', 'lastfm2', 'hackernews', 'reddit', 'soundcloud', 'soundcloud2', 'yahoo', 'blogger2', 'ello', 'wordpress2', 'steam', 'steam2', '500px', 'deviantart', 'twitch', 'feed', 'feed2', 'sina-weibo', 'renren', 'vk', 'vine', 'telegram', 'spotify', 'mail2', 'mail3', 'imdb', 'discord', 'slack', 'viber', 'yelp', 'quora', 'meetup', 'mixer', 'snapchat-ghost', 'wechat' );
518 include $this->settings['plugin_path'] . 'includes/member-details.php';
519 }
520
521 /**
522 * Meta box display callback - Team details.
523 *
524 * @since 1.0.0
525 * @param WP_Post $post Current post object.
526 */
527 public function team_details_meta( $post ) {
528 wp_nonce_field( basename( __FILE__ ), 'awsm_meta_details' );
529 $args = array(
530 'post_type' => 'awsm_team_member',
531 'posts_per_page' => -1,
532 'post_status' => 'publish',
533 );
534 $members = new WP_Query( $args );
535 $options = $this->get_options( 'awsm_team', $post->ID );
536 $defaultimage = $this->settings['plugin_url'] . 'images/default-user.png';
537 include $this->settings['plugin_path'] . 'includes/team-details.php';
538 }
539
540 /**
541 * Save metabox
542 *
543 * @param Int $post_id id of the post.
544 * @param Object $post Post Object.
545 * @since 1.0
546 */
547 public function save_metabox_data( $post_id, $post ) {
548 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
549 return;
550 }
551 if ( ! isset( $_POST['awsm_meta_details'] ) || ! wp_verify_nonce( sanitize_key( $_POST['awsm_meta_details'] ), basename( __FILE__ ) ) ) {
552 return $post_id;
553 }
554 $post_type = get_post_type_object( $post->post_type );
555 if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
556 return $post_id;
557 }
558 if ( $post->post_type == 'awsm_team_member' ) {
559 $team_repeater = array(
560 'awsm_social' => array(
561 'icon' => 'awsm-team-icon',
562 'link' => 'awsm-team-link',
563 ),
564 );
565 $team_meta = array(
566 'awsm-team-designation',
567 'awsm-team-short-desc',
568 );
569 foreach ( $team_repeater as $key => $value ) {
570 $olddata = get_post_meta( $post_id, $key, true );
571 $newdata = $item = array(); // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
572 foreach ( $value as $sub_key => $sub_value ) {
573 $item[ $sub_key ] = isset( $_POST[ $sub_value ] ) ? wp_unslash( $_POST[ $sub_value ] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
574 }
575 $count = count( reset( $item ) );
576 for ( $i = 0; $i < $count; $i++ ) {
577 foreach ( $value as $k => $v ) {
578 if ( $item[ $k ][ $i ] != '' ) {
579 $newdata[ $i ][ $k ] = stripslashes( strip_tags( $item[ $k ][ $i ] ) );
580 }
581 }
582 }
583 if ( ! empty( $newdata ) && $newdata != $olddata ) {
584 update_post_meta( $post_id, $key, $newdata );
585 } elseif ( empty( $newdata ) && $olddata ) {
586 delete_post_meta( $post_id, $key, $olddata );
587 }
588 }
589 } elseif ( $post->post_type == 'awsm_team' ) {
590 $team_meta = array( 'memberlist', 'team-style', 'preset', 'columns', 'custom_css' );
591 }
592 foreach ( $team_meta as $meta_key ) {
593 $olddata = get_post_meta( $post_id, $meta_key, true );
594 $newdata = array();
595 if ( isset( $_POST[ $meta_key ] ) ) {
596 if ( is_array( $_POST[ $meta_key ] ) ) {
597 $newdata = array_map( 'wp_strip_all_tags', wp_unslash( $_POST[ $meta_key ] ) );
598 } else {
599 if ( $meta_key === 'awsm-team-designation' || $meta_key === 'awsm-team-short-desc' ) {
600 $newdata = wp_kses( wp_unslash( $_POST[ $meta_key ] ), 'post' );
601 } else {
602 $newdata = wp_strip_all_tags( wp_unslash( $_POST[ $meta_key ] ) );
603 }
604 }
605 if ( ! empty( $newdata ) && $newdata != $olddata ) {
606 update_post_meta( $post_id, $meta_key, $newdata );
607 } elseif ( empty( $newdata ) && $olddata ) {
608 delete_post_meta( $post_id, $meta_key, $olddata );
609 }
610 } else {
611 delete_post_meta( $post_id, $meta_key, $olddata );
612 }
613 }
614 }
615
616 /**
617 * Dropdown Builder.
618 *
619 * @since 1.0.0
620 *
621 * @param string $name Field name.
622 * @param array $options Dropdown Options.
623 * @param string $selected Selected Value.
624 * @param string $selecttext Dropdown field text.
625 * @param string $class HTML class for the field.
626 * @param string $optionvalue Value to be selected for options.
627 */
628 public function selectbuilder( $name, $options, $selected = '', $selecttext = '', $class = '', $optionvalue = 'value' ) {
629 if ( is_array( $options ) ) :
630 $select_html = "<select name=\"$name\" id=\"$name\" class=\"$class\">";
631 if ( $selecttext ) {
632 $select_html .= '<option value="">' . $selecttext . '</option>';
633 }
634 foreach ( $options as $key => $option ) {
635 if ( $optionvalue == 'value' ) {
636 $value = $option;
637 } else {
638 $value = $key;
639 }
640 $select_html .= "<option value=\"$value\"";
641 if ( $value == $selected ) {
642 $select_html .= ' selected="selected"';
643 }
644 $select_html .= ">$option</option>\n";
645 }
646 $select_html .= '</select>';
647 echo wp_kses(
648 $select_html,
649 array(
650 'select' => array(
651 'name' => array(),
652 'id' => array(),
653 'class' => array(),
654 ),
655 'option' => array(
656 'value' => array(),
657 'selected' => array(),
658 ),
659 )
660 );
661 endif;
662 }
663
664 /**
665 * Get options
666 *
667 * @param String $postype Post type slug.
668 * @param Int $post_id ID of post.
669 * @since 1.0
670 */
671 public function get_options( $postype, $post_id ) {
672 $post = get_post( $post_id );
673
674 if ( ! $post ) {
675 return false;
676 }
677
678 $metakeys['awsm_team_member'] = array(
679 'awsm_social',
680 'awsm-team-designation',
681 'awsm-team-short-desc',
682 );
683 $metakeys['awsm_team'] = array(
684 'memberlist',
685 'team-style',
686 'preset',
687 'columns',
688 'custom_css',
689 );
690 $options['awsm_team_member'] = array(
691 'awsm_social' => array(),
692 'awsm-team-designation' => '',
693 'awsm-team-short-desc' => '',
694 );
695 $options['awsm_team'] = array(
696 'memberlist' => array(),
697 'team-style' => 'cards',
698 'preset' => '',
699 'columns' => '',
700 'custom_css' => '',
701 );
702 foreach ( $metakeys[ $postype ] as $key => $value ) {
703 $metavalue = get_post_meta( $post_id, $value, true );
704 if ( $metavalue ) {
705 $options[ $postype ][ $value ] = $metavalue;
706 }
707 }
708 return $options[ $postype ];
709 }
710
711 /**
712 * Get team thumbnail
713 *
714 * @param Int $team_id Post id of team.
715 * @param string $thumbnail thumbnail size.
716 * @since 1.0
717 */
718 public function team_thumbnail( $team_id, $thumbnail = 'awsm_team' ) {
719 $defaultimage = $this->settings['plugin_url'] . 'images/default-user.png';
720 $member_image = get_post_thumbnail_id( $team_id );
721 if ( $member_image ) {
722 $member_image_url = wp_get_attachment_image_src( $member_image, $thumbnail, true );
723 $member_image_url = $member_image_url[0];
724 } else {
725 $member_image_url = $defaultimage;
726 }
727 return $member_image_url;
728 }
729
730 /**
731 * Get team thumbnail.
732 *
733 * @since 1.0.0
734 * @param int $team_id Post id of team.
735 * @param string $thumbnail thumbnail size.
736 */
737 public function get_team_thumbnail( $team_id, $thumbnail = 'awsm_team' ) {
738 $defaultimage = '<img src="' . $this->settings['plugin_url'] . 'images/default-user.png" alt="' . esc_attr( get_the_title( $team_id ) ) . '">';
739 $member_image = ( has_post_thumbnail( $team_id ) ) ? get_the_post_thumbnail( $team_id, $thumbnail ) : $defaultimage;
740 return $member_image;
741 }
742
743 /**
744 * Item styling class name generator.
745 *
746 * @since 1.0.0
747 *
748 * @param array $options Class names collection.
749 * @param string $custom Custom class name.
750 * @return string
751 */
752 public function item_style( $options, $custom = '' ) {
753 $style = array(
754 $options['team-style'] . '-style',
755 $options['preset'],
756 'grid-' . $options['columns'] . '-col',
757 $custom,
758 );
759 return implode( ' ', $style );
760 }
761
762 /**
763 * Class generator
764 *
765 * @since 1.0.0
766 *
767 * @param array $class classnames.
768 */
769 public function addclass( $class ) {
770 return implode( ' ', $class );
771 }
772
773 /**
774 * ID generator
775 *
776 * @since 1.0.0
777 *
778 * @param array $id Unique HTML ID Collection.
779 */
780 public function add_id( $id ) {
781 return implode( '-', $id );
782 }
783
784 /**
785 * Print the meta data after checking it's existence.
786 *
787 * @since 1.0.0
788 *
789 * @param string $template The format string.
790 * @param boolean|string $value Value for output.
791 * @param boolean $return Whether to return the value or not.
792 */
793 public function checkprint( $template, $value, $return = false ) {
794 if ( $value ) {
795 if ( $return ) {
796 return sprintf( $template, $value );
797 } else {
798 echo sprintf( $template, $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
799 }
800 }
801 }
802
803 /**
804 * Phone number validation.
805 *
806 * @param string $phone The phone number.
807 * @return boolean
808 */
809 public function validate_phone_number( $phone ) {
810 if ( preg_match( '/^(?=.*[0-9])[- +()0-9]{4,15}+$/', $phone ) ) {
811 return true;
812 } else {
813 return false;
814 }
815 }
816 }
817
818 /**
819 * Initialize the main class.
820 */
821 function awms_team_activation() {
822 if ( ! class_exists( 'Awsm_Team' ) ) {
823 Awsm_Team_Lite::get_instance();
824 }
825 }
826
827 /**
828 * Disable the free plugin if PRO exists.
829 */
830 function awms_team__disable_self() {
831 if ( class_exists( 'Awsm_Team' ) ) {
832 deactivate_plugins( plugin_basename( __FILE__ ) );
833 add_action( 'admin_notices', 'awms_team_disable_notice' );
834 }
835 }
836
837 /**
838 * Admin notice to show when PRO exists.
839 */
840 function awms_team_disable_notice() {
841 $class = 'notice is-dismissible notice-warning';
842 $message = __( 'Thanks for upgrading AWSM Team Pro! The free version ‘AWSM Team’ has now been deactivated.', 'awsm-team' );
843 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
844 }
845
846 // Plugin activation hook.
847 add_action( 'plugins_loaded', 'awms_team_activation' );
848 add_action( 'admin_init', 'awms_team__disable_self' );
849 endif;
850