| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: AWSM Team |
| 4 |
Plugin URI: http://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.1 |
| 7 |
Author: AWSM Innovations |
| 8 |
Author URI: http://awsm.in/ |
| 9 |
License: GPL |
| 10 |
Copyright: AWSM Innovations |
| 11 |
*/ |
| 12 |
|
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
// if direct access |
| 17 |
|
| 18 |
if (!class_exists('Awsm_team_lite')): |
| 19 |
/** |
| 20 |
* Team main class |
| 21 |
* author : AWSM |
| 22 |
*/ |
| 23 |
class Awsm_team_lite |
| 24 |
{ |
| 25 |
private static $instance = null; |
| 26 |
private $settings; |
| 27 |
|
| 28 |
/** |
| 29 |
* Creates or returns an instance of this class. |
| 30 |
* @since 1.0.0 |
| 31 |
*/ |
| 32 |
public static function get_instance() |
| 33 |
{ |
| 34 |
// If an instance hasn't been created and set to $instance create an instance and set it to $instance. |
| 35 |
if (null == self::$instance) { |
| 36 |
self::$instance = new self; |
| 37 |
} |
| 38 |
return self::$instance; |
| 39 |
} |
| 40 |
|
| 41 |
public function __construct() |
| 42 |
{ |
| 43 |
$this->settings = array( |
| 44 |
'plugin_path' => plugin_dir_path(__FILE__), |
| 45 |
'plugin_url' => plugin_dir_url(__FILE__), |
| 46 |
'plugin_base' => dirname(plugin_basename(__FILE__)), |
| 47 |
'plugin_file' => __FILE__, |
| 48 |
'plugin_version' => '1.1', |
| 49 |
); |
| 50 |
$this->load_plugin_textdomain(); |
| 51 |
$this->run_plugin(); |
| 52 |
$this->adminfunctions(); |
| 53 |
} |
| 54 |
/** |
| 55 |
* Localisation |
| 56 |
* @since: 1.0 |
| 57 |
*/ |
| 58 |
public function load_plugin_textdomain() |
| 59 |
{ |
| 60 |
load_plugin_textdomain( 'awsm-team',FALSE, $this->settings['plugin_base'] . '/language/' ); |
| 61 |
} |
| 62 |
/** |
| 63 |
* Main plugin function |
| 64 |
* @since: 1.0 |
| 65 |
*/ |
| 66 |
public function run_plugin() |
| 67 |
{ |
| 68 |
add_action('init', array( $this, 'create_member_support' )); |
| 69 |
add_action('init', array( $this, 'custom_image_size' )); |
| 70 |
add_shortcode('awsmteam', array( $this, 'awsmteam_shortcode' )); |
| 71 |
add_action('wp_enqueue_scripts', array( $this, 'embed_front_script_styles' )); |
| 72 |
add_action('wp_head', array( $this, 'custom_css' )); |
| 73 |
} |
| 74 |
/** |
| 75 |
* Team custom css on theme head |
| 76 |
* @since: 1.0 |
| 77 |
*/ |
| 78 |
function custom_css(){ |
| 79 |
global $wp_query; |
| 80 |
$posts = $wp_query->posts; |
| 81 |
$pattern = '(awsmteam)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)'; |
| 82 |
$snippet = ''; |
| 83 |
$shortcodes = array(); |
| 84 |
if ($posts) { |
| 85 |
foreach ($posts as $post){ |
| 86 |
$pattern = get_shortcode_regex(); |
| 87 |
preg_match('/\[awsmteam (.+?)\]/', $post->post_content, $matches); |
| 88 |
if (is_array($matches) && isset($matches[1])) { |
| 89 |
if(is_array(shortcode_parse_atts($matches[1]))){ |
| 90 |
$shortcodes[] = shortcode_parse_atts($matches[1]); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
if(!empty($shortcodes)){ |
| 95 |
foreach ($shortcodes as $shortcode) { |
| 96 |
if(isset($shortcode['id'])){ |
| 97 |
$custom_css = get_post_meta( $shortcode['id'], 'custom_css', true ); |
| 98 |
if($custom_css){ |
| 99 |
$snippet.= $custom_css; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
if($snippet){ |
| 107 |
printf('<style type="text/css">%s</style>',$snippet) ; |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
/** |
| 112 |
* Custom image size for team memebers |
| 113 |
* @since 1.0 |
| 114 |
*/ |
| 115 |
public function custom_image_size() |
| 116 |
{ |
| 117 |
if ( function_exists( 'add_image_size' ) ) { |
| 118 |
add_image_size('awsm_team', 500, 500, true); |
| 119 |
} |
| 120 |
} |
| 121 |
/** |
| 122 |
* AWSM team shortocde |
| 123 |
* @since 1.0 |
| 124 |
*/ |
| 125 |
public function awsmteam_shortcode($atts) |
| 126 |
{ |
| 127 |
extract(shortcode_atts(array( |
| 128 |
'id' => false |
| 129 |
), $atts)); |
| 130 |
$options = $this->get_options('awsm_team', $id); |
| 131 |
if (!$options) { |
| 132 |
return '<div class="awsm-team-error">' . __('Team not found', 'awsm-team') . '</div>'; |
| 133 |
} |
| 134 |
if (empty($options['memberlist'])) { |
| 135 |
return '<div class="awsm-team-error">' . __('No members found', 'awsm-team') . '</div>'; |
| 136 |
} |
| 137 |
$template = $this->settings['plugin_path'] . 'templates/' . $options['team-style'] . '.php'; |
| 138 |
if (file_exists($template)) { |
| 139 |
ob_start(); |
| 140 |
$teamargs = array( |
| 141 |
'orderby' => 'post__in', |
| 142 |
'post_type' => 'awsm_team_member', |
| 143 |
'post__in' => $options['memberlist'], |
| 144 |
'posts_per_page' => -1 , |
| 145 |
); |
| 146 |
$team = new WP_Query($teamargs); |
| 147 |
include $template; |
| 148 |
wp_reset_postdata(); |
| 149 |
return ob_get_clean(); |
| 150 |
} |
| 151 |
} |
| 152 |
/** |
| 153 |
* Register front scripts |
| 154 |
* @since 1.0.0 |
| 155 |
*/ |
| 156 |
public function embed_front_script_styles() |
| 157 |
{ |
| 158 |
wp_enqueue_script('awsm-team', plugins_url('js/team.min.js', $this->settings['plugin_file']), array( |
| 159 |
'jquery' |
| 160 |
), $this->settings['plugin_version'], true); |
| 161 |
wp_enqueue_style('awsm-team', plugins_url('css/team.min.css', $this->settings['plugin_file']), false, $this->settings['plugin_version'], 'all'); |
| 162 |
} |
| 163 |
/** |
| 164 |
* Create custom post type |
| 165 |
* @since 1.0.0 |
| 166 |
*/ |
| 167 |
public function create_member_support() |
| 168 |
{ |
| 169 |
// Create awsm_team_member post type |
| 170 |
if (post_type_exists("awsm_team_member")) { |
| 171 |
return; |
| 172 |
} |
| 173 |
$singular = __('Team Member', 'awsm-team'); |
| 174 |
$plural = __('Team Members', 'awsm-team'); |
| 175 |
$labels = array( |
| 176 |
'name' => $plural, |
| 177 |
'singular_name' => $singular, |
| 178 |
'menu_name' => __('AWSM Team', 'awsm-team'), |
| 179 |
'add_new' => __('Add New Member', 'awsm-team'), |
| 180 |
'add_new_item' => sprintf(__('Add %s', 'awsm-team'), $singular), |
| 181 |
'new_item' => sprintf(__('New %s', 'awsm-team'), $singular), |
| 182 |
'edit_item' => sprintf(__('Edit %s', 'awsm-team'), $singular), |
| 183 |
'view_item' => sprintf(__('View %s', 'awsm-team'), $singular), |
| 184 |
'all_items' => sprintf(__('Members', 'awsm-team')), |
| 185 |
'search_items' => sprintf(__('Search %s', 'awsm-team'), $plural), |
| 186 |
'not_found' => sprintf(__('No %s found', 'awsm-team'), $plural), |
| 187 |
'not_found_in_trash' => sprintf(__('No %s found in trash', 'awsm-team'), $plural) |
| 188 |
); |
| 189 |
$cp_args = array( |
| 190 |
'labels' => $labels, |
| 191 |
'description' => sprintf(__('This is where you can create and manage %s.', 'awsm-team'), $plural), |
| 192 |
'publicly_queryable' => false, |
| 193 |
'show_ui' => true, |
| 194 |
'show_in_menu' => true, |
| 195 |
'capability_type' => 'post', |
| 196 |
'supports' => array( |
| 197 |
'title', |
| 198 |
'editor', |
| 199 |
'thumbnail' |
| 200 |
), |
| 201 |
'menu_icon' => 'dashicons-admin-users' |
| 202 |
); |
| 203 |
register_post_type('awsm_team_member', $cp_args); |
| 204 |
if (post_type_exists("awsm_team")) { |
| 205 |
return; |
| 206 |
} |
| 207 |
$singular = __('Team', 'awsm-team'); |
| 208 |
$plural = __('Teams', 'awsm-team'); |
| 209 |
$labels = array( |
| 210 |
'name' => $plural, |
| 211 |
'singular_name' => $singular, |
| 212 |
'menu_name' => __('Awsm Team', 'awsm-team'), |
| 213 |
'add_new' => __('Add Team', 'awsm-team'), |
| 214 |
'add_new_item' => sprintf(__('Add %s', 'awsm-team'), $singular), |
| 215 |
'new_item' => sprintf(__('New %s', 'awsm-team'), $singular), |
| 216 |
'edit_item' => sprintf(__('Edit %s', 'awsm-team'), $singular), |
| 217 |
'view_item' => sprintf(__('View %s', 'awsm-team'), $singular), |
| 218 |
'all_items' => sprintf(__('Teams', 'awsm-team')), |
| 219 |
'search_items' => sprintf(__('Search %s', 'awsm-team'), $plural), |
| 220 |
'not_found' => sprintf(__('No %s found', 'awsm-team'), $plural), |
| 221 |
'not_found_in_trash' => sprintf(__('No %s found in trash', 'awsm-team'), $plural) |
| 222 |
); |
| 223 |
$cp_args = array( |
| 224 |
'labels' => $labels, |
| 225 |
'description' => sprintf(__('This is where you can create and manage %s.', 'awsm-team'), $plural), |
| 226 |
'show_ui' => true, |
| 227 |
"show_in_menu" => 'edit.php?post_type=awsm_team_member', |
| 228 |
'capability_type' => 'post', |
| 229 |
'supports' => array( |
| 230 |
'title' |
| 231 |
) |
| 232 |
); |
| 233 |
register_post_type('awsm_team', $cp_args); |
| 234 |
} |
| 235 |
/** |
| 236 |
* Initiate admin functions. |
| 237 |
* @since 1.0 |
| 238 |
*/ |
| 239 |
public function adminfunctions() |
| 240 |
{ |
| 241 |
if (is_admin()) { |
| 242 |
add_action('add_meta_boxes', array( $this, 'register_metaboxes' )); |
| 243 |
add_action('save_post', array( $this, 'save_metabox_data' ), 10, 3); |
| 244 |
add_action('admin_init', array( $this, 'meta_box_scripts' )); |
| 245 |
add_action('admin_menu', array( $this, 'add_submenu_items' ), 12); |
| 246 |
add_action('edit_form_after_title', array( $this, 'shortcode_preview' )); |
| 247 |
add_filter('manage_awsm_team_member_posts_columns' , array( $this, 'custom_columns_member' )); |
| 248 |
add_action('manage_awsm_team_member_posts_custom_column' , array( $this, 'custom_columns_member_data' ) , 10, 2 ); |
| 249 |
add_filter('manage_awsm_team_posts_columns' , array( $this, 'custom_columns_team' )); |
| 250 |
add_action('manage_awsm_team_posts_custom_column' , array( $this, 'custom_columns_team_data' ) , 10, 2 ); |
| 251 |
add_filter('admin_post_thumbnail_html', array($this,'image_help')); |
| 252 |
add_filter('admin_post_thumbnail_size', array($this,'custom_admin_thumb_size')); |
| 253 |
} |
| 254 |
} |
| 255 |
/** |
| 256 |
* Custom thumbnail size for awsm_team_member |
| 257 |
* @since 1.0 |
| 258 |
*/ |
| 259 |
function custom_admin_thumb_size($thumb_size){ |
| 260 |
global $post_type,$post; |
| 261 |
if($post_type == 'awsm_team_member'){ |
| 262 |
$thumb_size = "awsm_team"; |
| 263 |
} |
| 264 |
return $thumb_size; |
| 265 |
} |
| 266 |
/** |
| 267 |
* Image size help text |
| 268 |
* @since 1.0 |
| 269 |
*/ |
| 270 |
function image_help($content){ |
| 271 |
global $post_type,$post; |
| 272 |
if ($post_type == 'awsm_team_member') { |
| 273 |
if(!has_post_thumbnail( $post->ID )){ |
| 274 |
$content .= '<p>'.__('Please upload square-cropped photos with a minimum dimension of 500px','awsm-team').'</p>'; |
| 275 |
} |
| 276 |
} |
| 277 |
return $content; |
| 278 |
} |
| 279 |
/** |
| 280 |
* Custom column on member table. |
| 281 |
* @since 1.0 |
| 282 |
*/ |
| 283 |
function custom_columns_member($columns){ |
| 284 |
$columns = array( |
| 285 |
'cb' => '<input type="checkbox" />', |
| 286 |
'title' => __('Name','awsm-team'), |
| 287 |
'featured_image' => __('Photo','awsm-team'), |
| 288 |
'designation' => __('Designation','awsm-team'), |
| 289 |
'date' => 'Date' |
| 290 |
); |
| 291 |
return $columns; |
| 292 |
} |
| 293 |
/** |
| 294 |
* Custom member table data. |
| 295 |
* @since 1.0 |
| 296 |
*/ |
| 297 |
function custom_columns_member_data($column,$post_ID){ |
| 298 |
$options = $this->get_options('awsm_team_member',$post_ID ); |
| 299 |
switch ( $column ) { |
| 300 |
case 'featured_image': |
| 301 |
echo the_post_thumbnail( 'thumbnail' ); |
| 302 |
break; |
| 303 |
case 'designation': |
| 304 |
echo $options['awsm-team-designation']; |
| 305 |
break; |
| 306 |
} |
| 307 |
} |
| 308 |
/** |
| 309 |
* Custom member column for team. |
| 310 |
* @since 1.0 |
| 311 |
*/ |
| 312 |
function custom_columns_team($columns){ |
| 313 |
$columns = array( |
| 314 |
'cb' => '<input type="checkbox" />', |
| 315 |
'title' => __('Name','awsm-team'), |
| 316 |
'members' => __('Members','awsm-team'), |
| 317 |
'preset' => __('Preset','awsm-team'), |
| 318 |
'style' => __('Style','awsm-team'), |
| 319 |
'shortcode' =>__('Shortcode','awsm-team') |
| 320 |
); |
| 321 |
return $columns; |
| 322 |
} |
| 323 |
/** |
| 324 |
* Custom member column data for team. |
| 325 |
* @since 1.0 |
| 326 |
*/ |
| 327 |
function custom_columns_team_data($column,$post_ID){ |
| 328 |
$options = $this->get_options('awsm_team',$post_ID ); |
| 329 |
$post = get_post( $post_ID ); |
| 330 |
switch ( $column ) { |
| 331 |
case 'members': |
| 332 |
echo count($options['memberlist']); |
| 333 |
break; |
| 334 |
case 'preset': |
| 335 |
echo $options['team-style']; |
| 336 |
break; |
| 337 |
case 'style': |
| 338 |
echo $options['preset']; |
| 339 |
break; |
| 340 |
case 'shortcode': |
| 341 |
printf('<code>[awsmteam id="%s"]</code>',$post_ID); |
| 342 |
break; |
| 343 |
} |
| 344 |
} |
| 345 |
/** |
| 346 |
* Shortcode preview on team edit page |
| 347 |
* @since 1.0 |
| 348 |
*/ |
| 349 |
public function shortcode_preview($post) |
| 350 |
{ |
| 351 |
if ('awsm_team' == $post->post_type && 'publish' == $post->post_status) { |
| 352 |
printf('<p>%1$s: <code>[awsmteam id="%2$s"]</code><button id="copy-awsm" type="button" data-clipboard-text="[awsmteam id="%2$s"]" class="button">%3$s</button></p>', __("Shortcode", 'awsm-team'), $post->ID, __("Copy", 'awsm-team')); |
| 353 |
} |
| 354 |
return; |
| 355 |
} |
| 356 |
/** |
| 357 |
* Loads meta box helper scripts |
| 358 |
* since 1.0 |
| 359 |
*/ |
| 360 |
public function meta_box_scripts() |
| 361 |
{ |
| 362 |
global $pagenow, $typenow, $post; |
| 363 |
if (empty($typenow) && !empty($_GET['post'])) { |
| 364 |
$post = get_post($_GET['post']); |
| 365 |
$typenow = $post->post_type; |
| 366 |
} |
| 367 |
if (($pagenow == 'post-new.php' or $pagenow == 'post.php') and ($typenow == 'awsm_team_member' or $typenow == 'awsm_team')) { |
| 368 |
wp_enqueue_style('awsm-team-admin', plugins_url('css/admin.css', $this->settings['plugin_file']), false, $this->settings['plugin_version'], 'all'); |
| 369 |
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']); |
| 370 |
wp_enqueue_script('select2', plugins_url('js/select2.min.js', $this->settings['plugin_file']), array( 'jquery' ), $this->settings['plugin_version']); |
| 371 |
wp_enqueue_style('select2', plugins_url('css/select2.min.css', $this->settings['plugin_file']), false, $this->settings['plugin_version'], 'all'); |
| 372 |
wp_enqueue_style('awsm-team-icomoon-css', plugins_url('css/icomoon.css', $this->settings['plugin_file']), false, $this->settings['plugin_version'], 'all'); |
| 373 |
} |
| 374 |
|
| 375 |
} |
| 376 |
/** |
| 377 |
* Adding submenu items |
| 378 |
* @since 1.0.0 |
| 379 |
*/ |
| 380 |
public function add_submenu_items() |
| 381 |
{ |
| 382 |
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'); |
| 383 |
} |
| 384 |
/** |
| 385 |
* Register meta box |
| 386 |
* @since 1.0.0 |
| 387 |
*/ |
| 388 |
public function register_metaboxes() |
| 389 |
{ |
| 390 |
add_meta_box('member_details', __('Member Details', 'awsm-team'), array( $this, 'member_details_meta' ), 'awsm_team_member'); |
| 391 |
add_meta_box('team_details', __('Team Details', 'awsm-team'), array( $this, 'team_details_meta' ), 'awsm_team', 'normal', 'high'); |
| 392 |
add_meta_box('awsm_team_pro', __('Upgrade to AWSM Team Pro', 'awsm-team'), array( $this, 'pro_metabox' ), 'awsm_team', 'side', 'default'); |
| 393 |
} |
| 394 |
public function pro_metabox(){ |
| 395 |
include $this->settings['plugin_path'] . 'includes/pro-features.php'; |
| 396 |
} |
| 397 |
/** |
| 398 |
* Meta box display callback - Member details. |
| 399 |
* @since 1.0.0 |
| 400 |
* @param WP_Post $post Current post object. |
| 401 |
*/ |
| 402 |
public function member_details_meta($post) |
| 403 |
{ |
| 404 |
wp_nonce_field(basename(__FILE__), 'awsm_meta_details'); |
| 405 |
$awsm_contact = get_post_meta($post->ID, 'awsm_contact', true); |
| 406 |
$awsm_social = get_post_meta($post->ID, 'awsm_social', true); |
| 407 |
$socialicons = array('mail', 'link', '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'); |
| 408 |
include $this->settings['plugin_path'] . 'includes/member-details.php'; |
| 409 |
} |
| 410 |
/** |
| 411 |
* Meta box display callback - Team details. |
| 412 |
* @since 1.0.0 |
| 413 |
* @param WP_Post $post Current post object. |
| 414 |
*/ |
| 415 |
public function team_details_meta($post) |
| 416 |
{ |
| 417 |
wp_nonce_field(basename(__FILE__), 'awsm_meta_details'); |
| 418 |
$args = array( |
| 419 |
'post_type' => 'awsm_team_member', |
| 420 |
'posts_per_page' => -1 |
| 421 |
); |
| 422 |
$members = new WP_Query($args); |
| 423 |
$options = $this->get_options('awsm_team', $post->ID); |
| 424 |
$defaultimage = $this->settings['plugin_url'] . 'images/default-user.png'; |
| 425 |
include $this->settings['plugin_path'] . 'includes/team-details.php'; |
| 426 |
} |
| 427 |
/** |
| 428 |
* Save metabox |
| 429 |
* @param Int $post_id id of the post |
| 430 |
* @param Object $post Post Object |
| 431 |
* @since 1.0 |
| 432 |
*/ |
| 433 |
public function save_metabox_data($post_id, $post) |
| 434 |
{ |
| 435 |
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
| 436 |
return; |
| 437 |
} |
| 438 |
if (!isset($_POST['awsm_meta_details']) || !wp_verify_nonce($_POST['awsm_meta_details'], basename(__FILE__))) { |
| 439 |
return $post_id; |
| 440 |
} |
| 441 |
$post_type = get_post_type_object($post->post_type); |
| 442 |
if (!current_user_can($post_type->cap->edit_post, $post_id)) { |
| 443 |
return $post_id; |
| 444 |
} |
| 445 |
if ($post->post_type == 'awsm_team_member') { |
| 446 |
$team_repeater = array( |
| 447 |
'awsm_contact' => array( |
| 448 |
'label' => 'awsm-team-label', |
| 449 |
'content' => 'awsm-team-content' |
| 450 |
), |
| 451 |
'awsm_social' => array( |
| 452 |
'icon' => 'awsm-team-icon', |
| 453 |
'link' => 'awsm-team-link' |
| 454 |
) |
| 455 |
); |
| 456 |
$team_meta = array( |
| 457 |
'awsm-team-designation', |
| 458 |
'awsm-team-short-desc' |
| 459 |
); |
| 460 |
foreach ($team_repeater as $key => $value) { |
| 461 |
$olddata = get_post_meta($post_id, $key, true); |
| 462 |
$newdata = $item = array(); |
| 463 |
foreach ($value as $k => $v) { |
| 464 |
$item[$k] = $_POST[$v]; |
| 465 |
} |
| 466 |
$count = count(reset($item)); |
| 467 |
for ($i = 0; $i < $count; $i++) { |
| 468 |
foreach ($value as $k => $v) { |
| 469 |
if ($item[$k][$i] != '') { |
| 470 |
$newdata[$i][$k] = stripslashes(strip_tags($item[$k][$i])); |
| 471 |
} |
| 472 |
} |
| 473 |
} |
| 474 |
if (!empty($newdata) && $newdata != $olddata) { |
| 475 |
update_post_meta($post_id, $key, $newdata); |
| 476 |
} elseif (empty($newdata) && $olddata) { |
| 477 |
delete_post_meta($post_id, $key, $olddata); |
| 478 |
} |
| 479 |
|
| 480 |
} |
| 481 |
} elseif ($post->post_type == 'awsm_team') { |
| 482 |
$team_meta = array('memberlist', 'team-style', 'preset', 'columns', 'custom_css'); |
| 483 |
} |
| 484 |
foreach ($team_meta as $meta_key) { |
| 485 |
$olddata = get_post_meta($post_id, $meta_key, true); |
| 486 |
$newdata = array(); |
| 487 |
if (isset($_POST[$meta_key])) { |
| 488 |
if (is_array($_POST[$meta_key])) { |
| 489 |
$newdata = $_POST[$meta_key]; |
| 490 |
} else { |
| 491 |
$newdata = stripslashes(strip_tags($_POST[$meta_key])); |
| 492 |
} |
| 493 |
if (!empty($newdata) && $newdata != $olddata) { |
| 494 |
update_post_meta($post_id, $meta_key, $newdata); |
| 495 |
} elseif (empty($newdata) && $olddata) { |
| 496 |
delete_post_meta($post_id, $meta_key, $olddata); |
| 497 |
} |
| 498 |
} else { |
| 499 |
delete_post_meta($post_id, $meta_key, $olddata); |
| 500 |
} |
| 501 |
} |
| 502 |
} |
| 503 |
/** |
| 504 |
* Dropdown Builder |
| 505 |
* @since 1.0 |
| 506 |
*/ |
| 507 |
public function selectbuilder($name, $options, $selected = "", $selecttext = "", $class = "", $optionvalue = 'value') |
| 508 |
{ |
| 509 |
if (is_array($options)): |
| 510 |
$select_html = "<select name=\"$name\" id=\"$name\" class=\"$class\">"; |
| 511 |
if ($selecttext) { |
| 512 |
$select_html .= '<option value="">' . $selecttext . '</option>'; |
| 513 |
} |
| 514 |
foreach ($options as $key => $option) { |
| 515 |
if ($optionvalue == 'value') { |
| 516 |
$value = $option; |
| 517 |
} else { |
| 518 |
$value = $key; |
| 519 |
} |
| 520 |
$select_html .= "<option value=\"$value\""; |
| 521 |
if ($value == $selected) { |
| 522 |
$select_html .= ' selected="selected"'; |
| 523 |
} |
| 524 |
$select_html .= ">$option</option>\n"; |
| 525 |
} |
| 526 |
$select_html .= '</select>'; |
| 527 |
echo $select_html; |
| 528 |
else: |
| 529 |
endif; |
| 530 |
} |
| 531 |
/** |
| 532 |
* Get options |
| 533 |
* @param String $postype Post type slug |
| 534 |
* @param Int $post_id ID of post |
| 535 |
* @since 1.0 |
| 536 |
*/ |
| 537 |
public function get_options($postype, $post_id) |
| 538 |
{ |
| 539 |
$post = get_post($post_id); |
| 540 |
|
| 541 |
if (!$post) { |
| 542 |
return false; |
| 543 |
} |
| 544 |
|
| 545 |
$metakeys['awsm_team_member'] = array( |
| 546 |
'awsm_contact', |
| 547 |
'awsm_social', |
| 548 |
'awsm-team-designation', |
| 549 |
'awsm-team-short-desc' |
| 550 |
); |
| 551 |
$metakeys['awsm_team'] = array( |
| 552 |
'memberlist', |
| 553 |
'team-style', |
| 554 |
'preset', |
| 555 |
'columns', |
| 556 |
'custom_css' |
| 557 |
); |
| 558 |
$options['awsm_team_member'] = array( |
| 559 |
'awsm_contact' => array(), |
| 560 |
'awsm_social' => array(), |
| 561 |
'awsm-team-designation' => '', |
| 562 |
'awsm-team-short-desc' => '' |
| 563 |
); |
| 564 |
$options['awsm_team'] = array( |
| 565 |
'memberlist' => array(), |
| 566 |
'team-style' => 'cards', |
| 567 |
'preset' => '', |
| 568 |
'columns' => '', |
| 569 |
'custom_css' => '' |
| 570 |
); |
| 571 |
foreach ($metakeys[$postype] as $key => $value) { |
| 572 |
$metavalue = get_post_meta($post_id, $value, true); |
| 573 |
if ($metavalue) { |
| 574 |
$options[$postype][$value] = $metavalue; |
| 575 |
} |
| 576 |
} |
| 577 |
return $options[$postype]; |
| 578 |
} |
| 579 |
/** |
| 580 |
* Get team thumbnail |
| 581 |
* @param Int $team_id Post id of tram |
| 582 |
* @param string $thumbnail thumbnail size |
| 583 |
* @since 1.0 |
| 584 |
*/ |
| 585 |
public function team_thumbnail($team_id, $thumbnail = "awsm_team") |
| 586 |
{ |
| 587 |
$defaultimage = $this->settings['plugin_url'] . 'images/default-user.png'; |
| 588 |
$member_image = get_post_thumbnail_id($team_id); |
| 589 |
if ($member_image) { |
| 590 |
$member_image_url = wp_get_attachment_image_src($member_image, $thumbnail, true); |
| 591 |
$member_image_url = $member_image_url[0]; |
| 592 |
} else { |
| 593 |
$member_image_url = $defaultimage; |
| 594 |
} |
| 595 |
return $member_image_url; |
| 596 |
} |
| 597 |
/** |
| 598 |
* Item stle generator |
| 599 |
* @since 1.0 |
| 600 |
*/ |
| 601 |
public function item_style($options, $custom = "") |
| 602 |
{ |
| 603 |
$style = array( |
| 604 |
$options['team-style'] . '-style', |
| 605 |
$options['preset'], |
| 606 |
'grid-' . $options['columns'] . '-col', |
| 607 |
$custom |
| 608 |
); |
| 609 |
return implode(' ', $style); |
| 610 |
} |
| 611 |
/** |
| 612 |
* Class generator |
| 613 |
* @param Array $class classnames |
| 614 |
* @since 1.0 |
| 615 |
*/ |
| 616 |
public function addclass($class) |
| 617 |
{ |
| 618 |
return implode(' ', $class); |
| 619 |
} |
| 620 |
/** |
| 621 |
* ID generator |
| 622 |
* @param Array $id |
| 623 |
* @since 1.0 |
| 624 |
*/ |
| 625 |
public function add_id($id) |
| 626 |
{ |
| 627 |
return implode('-', $id); |
| 628 |
} |
| 629 |
/** |
| 630 |
* Print the meta data after checking it's existence |
| 631 |
* @since 1.0 |
| 632 |
*/ |
| 633 |
public function checkprint($template, $value, $return = false) |
| 634 |
{ |
| 635 |
if ($value) { |
| 636 |
if ($return) { |
| 637 |
return sprintf($template, $value); |
| 638 |
} else { |
| 639 |
echo sprintf($template, $value); |
| 640 |
} |
| 641 |
|
| 642 |
} |
| 643 |
} |
| 644 |
} |
| 645 |
function awms_team_activation(){ |
| 646 |
if ( !class_exists('Awsm_team') ) { |
| 647 |
Awsm_team_lite::get_instance(); |
| 648 |
} |
| 649 |
} |
| 650 |
function awms_team__disable_self(){ |
| 651 |
if ( class_exists( 'Awsm_team' ) ) { |
| 652 |
deactivate_plugins( plugin_basename( __FILE__ ) ); |
| 653 |
add_action( 'admin_notices', 'awms_team_disable_notice' ); |
| 654 |
} |
| 655 |
} |
| 656 |
function awms_team_disable_notice(){ |
| 657 |
$class = 'notice is-dismissible notice-warning'; |
| 658 |
$message = __( 'Thanks for upgrading AWSM Team Pro! The free version ‘AWSM Team’ has now been deactivated.', 'awsm-team' ); |
| 659 |
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message ); |
| 660 |
} |
| 661 |
// Plugin activation hook |
| 662 |
add_action( 'plugins_loaded', 'awms_team_activation' ); |
| 663 |
add_action( 'admin_init', 'awms_team__disable_self' ); |
| 664 |
endif; |