elementor
1 year ago
class-simple-author-box-admin-page.php
1 month ago
class-simple-author-box-block.php
1 year ago
class-simple-author-box-helper.php
1 year ago
class-simple-author-box-previewer.php
1 year ago
class-simple-author-box-social.php
1 year ago
class-simple-author-box-user-profile.php
1 year ago
class-simple-author-box-widget.php
1 year ago
class-simple-author-box.php
3 months ago
functions.php
3 years ago
class-simple-author-box.php
737 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Our main plugin class |
| 5 | */ |
| 6 | if (!defined('ABSPATH')) exit; |
| 7 | |
| 8 | class Simple_Author_Box |
| 9 | { |
| 10 | |
| 11 | private static $instance = null; |
| 12 | private $options; |
| 13 | public $version; |
| 14 | public $themes; |
| 15 | /** |
| 16 | * Function constructor |
| 17 | */ |
| 18 | function __construct() |
| 19 | { |
| 20 | |
| 21 | $this->load_dependencies(); |
| 22 | $this->define_admin_hooks(); |
| 23 | |
| 24 | add_action('init', array($this, 'define_public_hooks')); |
| 25 | add_action('widgets_init', array($this, 'sab_lite_register_widget')); |
| 26 | |
| 27 | add_action('wp_ajax_sab_dismiss_pointer', array($this, 'dismiss_pointer_ajax')); |
| 28 | register_activation_hook(SIMPLE_AUTHOR_BOX_SLUG, array($this, 'activate_plugin')); |
| 29 | add_action('in_admin_footer', array($this, 'admin_footer_js')); |
| 30 | |
| 31 | add_filter('admin_footer_text', array($this, 'admin_footer_text')); |
| 32 | |
| 33 | $current_version = $this->get_plugin_version(); |
| 34 | $installed_version = get_option('sab_version'); |
| 35 | if(false === $installed_version || true === version_compare($installed_version, $current_version, '<')){ |
| 36 | update_option('sab_version', $current_version); |
| 37 | $this->reset_pointers(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | function sab_picker_footer_js() |
| 42 | { |
| 43 | echo '<style>.saboxplugin-wrap{ |
| 44 | display:none; |
| 45 | }'; |
| 46 | } |
| 47 | |
| 48 | function admin_footer_js() |
| 49 | { |
| 50 | ?> |
| 51 | <script type='text/javascript'> |
| 52 | jQuery(document).ready(function() { |
| 53 | jQuery('#wp-admin-bar-edit-profile').after('<li id="wp-admin-bar-edit-profile"><a class="ab-item" href="' + jQuery('#wp-admin-bar-edit-profile > a').attr('href') + '#sabox-custom-profile-image">Edit SAB Profile</a></li>'); |
| 54 | }); |
| 55 | </script> |
| 56 | <?php |
| 57 | } |
| 58 | |
| 59 | public function admin_footer_text($text) |
| 60 | { |
| 61 | if (!$this->is_plugin_page()) { |
| 62 | return $text; |
| 63 | } |
| 64 | |
| 65 | $text = '<i class="wfsab-footer"><a href="' . $this->generate_web_link('admin_footer') . '" title="' . __('Visit Simple Author Box page for more info', 'simple-author-box') . '" target="_blank">Simple Author Box</a> v' . $this->get_plugin_version() . '. Please <a target="_blank" href="https://wordpress.org/support/plugin/simple-author-box/reviews/#new-post" title="Rate the plugin">rate the plugin <span>� |
| 66 | � |
| 67 | � |
| 68 | � |
| 69 | � |
| 70 | </span></a> to help us spread the word. Thank you from the Simple Author Box team!</i>'; |
| 71 | |
| 72 | return $text; |
| 73 | } // admin_footer_text |
| 74 | |
| 75 | public function generate_web_link($placement = '', $page = '/', $params = array(), $anchor = '') |
| 76 | { |
| 77 | $base_url = 'https://wpauthorbox.com'; |
| 78 | |
| 79 | if ('/' != $page) { |
| 80 | $page = '/' . trim($page, '/') . '/'; |
| 81 | } |
| 82 | if ($page == '//') { |
| 83 | $page = '/'; |
| 84 | } |
| 85 | |
| 86 | $parts = array_merge(array('utm_source' => 'sab-free', 'utm_content' => $placement), $params); |
| 87 | |
| 88 | if (!empty($anchor)) { |
| 89 | $anchor = '#' . trim($anchor, '#'); |
| 90 | } |
| 91 | |
| 92 | $out = $base_url . $page . '?' . http_build_query($parts, '', '&') . $anchor; |
| 93 | |
| 94 | return $out; |
| 95 | } // generate_web_link |
| 96 | |
| 97 | public function is_plugin_page() |
| 98 | { |
| 99 | $current_screen = get_current_screen(); |
| 100 | |
| 101 | if ($current_screen->id == 'appearance_page_simple-author-box') { |
| 102 | return true; |
| 103 | } else { |
| 104 | return false; |
| 105 | } |
| 106 | } // is_plugin_page |
| 107 | |
| 108 | function activate_plugin() |
| 109 | { |
| 110 | $this->reset_pointers(); |
| 111 | } |
| 112 | |
| 113 | static function reset_pointers() |
| 114 | { |
| 115 | $pointers = array(); |
| 116 | $sab_plugin_name = apply_filters('sab_plugin_name', __('Simple Author Box', 'simple-author-box')); |
| 117 | $pointers['welcome'] = array('target' => '#menu-appearance', 'edge' => 'left', 'align' => 'right', 'content' => 'Thank you for installing the <b style="font-weight: 800; font-variant: small-caps;">' . $sab_plugin_name . '</b> plugin! Please open <a href="' . admin_url('themes.php?page=simple-author-box') . '">Appearance - ' . $sab_plugin_name . '</a> to configure your author box.'); |
| 118 | update_option(SIMPLE_AUTHOR_POINTERS, $pointers); |
| 119 | } // reset_pointers |
| 120 | |
| 121 | static function dismiss_pointer_ajax() |
| 122 | { |
| 123 | delete_option(SIMPLE_AUTHOR_POINTERS); |
| 124 | } |
| 125 | |
| 126 | // Register Simple Author Box widget |
| 127 | public function sab_lite_register_widget() |
| 128 | { |
| 129 | register_widget('Simple_Author_Box_Widget_LITE'); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Get plugin version |
| 134 | * |
| 135 | * @since 5.0 |
| 136 | * |
| 137 | * @return int plugin version |
| 138 | * |
| 139 | */ |
| 140 | public function get_plugin_version() |
| 141 | { |
| 142 | if (isset($this->version)) { |
| 143 | return $this->version; |
| 144 | } |
| 145 | |
| 146 | $plugin_data = get_file_data(SIMPLE_AUTHOR_BOX_FILE, array('version' => 'Version'), 'plugin'); |
| 147 | $this->version = $plugin_data['version']; |
| 148 | |
| 149 | return $plugin_data['version']; |
| 150 | } // get_plugin_version |
| 151 | |
| 152 | /** |
| 153 | * Singleton pattern |
| 154 | * |
| 155 | * @return void |
| 156 | */ |
| 157 | public static function get_instance() |
| 158 | { |
| 159 | if (is_null(self::$instance)) { |
| 160 | self::$instance = new self(); |
| 161 | } |
| 162 | |
| 163 | return self::$instance; |
| 164 | } |
| 165 | |
| 166 | private function load_dependencies() |
| 167 | { |
| 168 | |
| 169 | require_once SIMPLE_AUTHOR_BOX_PATH . 'inc/class-simple-author-box-social.php'; |
| 170 | require_once SIMPLE_AUTHOR_BOX_PATH . 'inc/class-simple-author-box-helper.php'; |
| 171 | require_once SIMPLE_AUTHOR_BOX_PATH . 'inc/functions.php'; |
| 172 | require_once SIMPLE_AUTHOR_BOX_PATH . '/inc/elementor/class-simple-author-box-elementor-check.php'; |
| 173 | require_once SIMPLE_AUTHOR_BOX_PATH . 'inc/class-simple-author-box-widget.php'; |
| 174 | |
| 175 | if (apply_filters('sabox_remove_lite_block', true)) { |
| 176 | require_once SIMPLE_AUTHOR_BOX_PATH . 'inc/class-simple-author-box-block.php'; |
| 177 | } |
| 178 | |
| 179 | // everything below this line gets loaded only in the admin back-end |
| 180 | if (is_admin()) { |
| 181 | require_once SIMPLE_AUTHOR_BOX_PATH . 'inc/class-simple-author-box-admin-page.php'; |
| 182 | require_once SIMPLE_AUTHOR_BOX_PATH . 'inc/class-simple-author-box-user-profile.php'; |
| 183 | require_once SIMPLE_AUTHOR_BOX_PATH . 'inc/class-simple-author-box-previewer.php'; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | |
| 188 | /** |
| 189 | * Admin hooks |
| 190 | * |
| 191 | * @return void |
| 192 | */ |
| 193 | private function define_admin_hooks() |
| 194 | { |
| 195 | |
| 196 | /** |
| 197 | * everything hooked here loads on both front-end & back-end |
| 198 | */ |
| 199 | add_filter('get_avatar', array($this, 'replace_gravatar_image'), 10, 6); |
| 200 | add_filter('amp_post_template_data', array($this, 'sab_amp_css')); // @since 2.0.7 |
| 201 | |
| 202 | /** |
| 203 | * Only load when we're in the admin panel |
| 204 | */ |
| 205 | if (is_admin()) { |
| 206 | add_action('init', array($this, 'initialize_admin')); |
| 207 | add_action('admin_enqueue_scripts', array($this, 'admin_style_and_scripts')); |
| 208 | add_filter('user_contactmethods', array($this, 'add_extra_fields')); |
| 209 | add_filter('plugin_action_links_' . SIMPLE_AUTHOR_BOX_SLUG, array($this, 'settings_link')); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | public function initialize_admin() |
| 214 | { |
| 215 | global $simple_author_box_admin; |
| 216 | // Class that handles admin page |
| 217 | $simple_author_box_admin = new Simple_Author_Box_Admin_Page(); |
| 218 | |
| 219 | // Class that handles author box previewer |
| 220 | new Simple_Author_Box_Previewer(); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | /** |
| 225 | * See this: https://codex.wordpress.org/Plugin_API/Filter_Reference/get_avatar |
| 226 | * |
| 227 | * Custom function to overwrite WordPress's get_avatar function |
| 228 | * |
| 229 | * @param [type] $avatar |
| 230 | * @param [type] $id_or_email |
| 231 | * @param [type] $size |
| 232 | * @param [type] $default |
| 233 | * @param [type] $alt |
| 234 | * @param [type] $args |
| 235 | * |
| 236 | * @return void |
| 237 | */ |
| 238 | public function replace_gravatar_image($avatar, $id_or_email, $size, $default, $alt, $args = array()) |
| 239 | { |
| 240 | |
| 241 | // Process the user identifier. |
| 242 | $user = false; |
| 243 | if (is_numeric($id_or_email)) { |
| 244 | $user = get_user_by('id', absint($id_or_email)); |
| 245 | } elseif (is_string($id_or_email)) { |
| 246 | |
| 247 | $user = get_user_by('email', $id_or_email); |
| 248 | } elseif ($id_or_email instanceof WP_User) { |
| 249 | // User Object |
| 250 | $user = $id_or_email; |
| 251 | } elseif ($id_or_email instanceof WP_Post) { |
| 252 | // Post Object |
| 253 | $user = get_user_by('id', (int) $id_or_email->post_author); |
| 254 | } elseif ($id_or_email instanceof WP_Comment) { |
| 255 | |
| 256 | if (!empty($id_or_email->user_id)) { |
| 257 | $user = get_user_by('id', (int) $id_or_email->user_id); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | if (!$user || is_wp_error($user)) { |
| 262 | return $avatar; |
| 263 | } |
| 264 | |
| 265 | $custom_profile_image = get_user_meta($user->ID, 'sabox-profile-image', true); |
| 266 | $class = array('avatar', 'avatar-' . (int) $args['size'], 'photo'); |
| 267 | |
| 268 | if (!$args['found_avatar'] || $args['force_default']) { |
| 269 | $class[] = 'avatar-default'; |
| 270 | } |
| 271 | |
| 272 | if ($args['class']) { |
| 273 | if (is_array($args['class'])) { |
| 274 | $class = array_merge($class, $args['class']); |
| 275 | } else { |
| 276 | $class[] = $args['class']; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | $class[] = 'sab-custom-avatar'; |
| 281 | |
| 282 | if ('' !== $custom_profile_image && true !== $args['force_default']) { |
| 283 | |
| 284 | $avatar = sprintf( |
| 285 | "<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>", |
| 286 | esc_attr($args['alt']), |
| 287 | esc_url($custom_profile_image), |
| 288 | esc_url($custom_profile_image) . ' 2x', |
| 289 | esc_attr(join(' ', $class)), |
| 290 | (int) $args['height'], |
| 291 | (int) $args['width'], |
| 292 | $args['extra_attr'] |
| 293 | ); |
| 294 | } |
| 295 | |
| 296 | return $avatar; |
| 297 | } |
| 298 | |
| 299 | public function define_public_hooks() |
| 300 | { |
| 301 | |
| 302 | $this->options = Simple_Author_Box_Helper::get_option('saboxplugin_options'); |
| 303 | |
| 304 | add_action('wp_enqueue_scripts', array($this, 'saboxplugin_author_box_style'), 10); |
| 305 | add_shortcode('simple-author-box', array($this, 'shortcode')); |
| 306 | add_filter('sabox_hide_social_icons', array($this, 'show_social_media_icons'), 10, 2); |
| 307 | add_filter('sabox_check_if_show', array($this, 'check_if_show_archive'), 10); |
| 308 | |
| 309 | if ('0' == $this->options['sab_autoinsert']) { |
| 310 | add_filter('the_content', 'wpsabox_author_box'); |
| 311 | } |
| 312 | |
| 313 | if (isset($this->options['sab_footer_inline_style']) && '0' == $this->options['sab_footer_inline_style']) { |
| 314 | add_action( |
| 315 | 'wp_footer', |
| 316 | array( |
| 317 | $this, |
| 318 | 'inline_style', |
| 319 | ), |
| 320 | 13 |
| 321 | ); |
| 322 | } else { |
| 323 | add_action('wp_head', array($this, 'inline_style'), 15); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | public function settings_link($links) |
| 328 | { |
| 329 | if (is_array($links)) { |
| 330 | $sab = sprintf('<a href="%s">%s</a>', admin_url('themes.php?page=simple-author-box'), __('Configure', 'simple-author-box')); |
| 331 | $buy = sprintf('<a href="%s"><b>%s</b></a>', admin_url('themes.php?page=simple-author-box#get-pro'), __('Get PRO', 'simple-author-box')); |
| 332 | |
| 333 | array_unshift($links, $buy); |
| 334 | array_unshift($links, $sab); |
| 335 | } |
| 336 | |
| 337 | return $links; |
| 338 | } |
| 339 | |
| 340 | public function admin_style_and_scripts($hook) |
| 341 | { |
| 342 | |
| 343 | $suffix = ''; |
| 344 | if (SIMPLE_AUTHOR_SCRIPT_DEBUG) { |
| 345 | $suffix = ''; |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
| 350 | // globally loaded |
| 351 | wp_enqueue_style('sabox-css', SIMPLE_AUTHOR_BOX_ASSETS . 'css/sabox.css', array(), SIMPLE_AUTHOR_BOX_VERSION); |
| 352 | |
| 353 | |
| 354 | // loaded only on plugin page |
| 355 | if ('appearance_page_simple-author-box' == $hook) { |
| 356 | // todo: maybe uncomment later |
| 357 | delete_option(SIMPLE_AUTHOR_POINTERS); |
| 358 | |
| 359 | // Styles |
| 360 | wp_enqueue_style('saboxplugin-admin-style', SIMPLE_AUTHOR_BOX_ASSETS . 'css/sabox-admin-style' . $suffix . '.css', array(), SIMPLE_AUTHOR_BOX_VERSION); |
| 361 | wp_enqueue_style('saboxplugin-admin-font', 'https://fonts.bunny.net/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&display=swap'); |
| 362 | |
| 363 | wp_enqueue_style('wp-color-picker'); |
| 364 | wp_enqueue_style('saboxplugin-sweetalert', SIMPLE_AUTHOR_BOX_ASSETS . 'css/sweetalert2.min.css', array(), SIMPLE_AUTHOR_BOX_VERSION); |
| 365 | |
| 366 | wp_enqueue_style('wp-jquery-ui-dialog'); |
| 367 | wp_enqueue_script('jquery-ui-dialog'); |
| 368 | |
| 369 | // Scripts |
| 370 | wp_enqueue_script( |
| 371 | 'sabox-admin-js', |
| 372 | SIMPLE_AUTHOR_BOX_ASSETS . 'js/sabox-admin.js', |
| 373 | array( |
| 374 | 'jquery-ui-slider', |
| 375 | 'wp-color-picker', |
| 376 | ), |
| 377 | SIMPLE_AUTHOR_BOX_VERSION, |
| 378 | true |
| 379 | ); |
| 380 | |
| 381 | wp_enqueue_script( |
| 382 | 'sabox-sweetalert', |
| 383 | SIMPLE_AUTHOR_BOX_ASSETS . 'js/sweetalert2.min.js', |
| 384 | array( |
| 385 | 'jquery-ui-slider', |
| 386 | 'wp-color-picker', |
| 387 | ), |
| 388 | SIMPLE_AUTHOR_BOX_VERSION, |
| 389 | true |
| 390 | ); |
| 391 | |
| 392 | $sabox_admin['sab_is_plugin_page'] = true; |
| 393 | |
| 394 | wp_localize_script('sabox-sweetalert', 'sabox_admin', $sabox_admin); |
| 395 | |
| 396 | wp_dequeue_style('uiStyleSheet'); |
| 397 | wp_dequeue_style('wpcufpnAdmin'); |
| 398 | wp_dequeue_style('unifStyleSheet'); |
| 399 | wp_dequeue_style('wpcufpn_codemirror'); |
| 400 | wp_dequeue_style('wpcufpn_codemirrorTheme'); |
| 401 | wp_dequeue_style('collapse-admin-css'); |
| 402 | wp_dequeue_style('jquery-ui-css'); |
| 403 | wp_dequeue_style('tribe-common-admin'); |
| 404 | wp_dequeue_style('file-manager__jquery-ui-css'); |
| 405 | wp_dequeue_style('file-manager__jquery-ui-css-theme'); |
| 406 | wp_dequeue_style('wpmegmaps-jqueryui'); |
| 407 | wp_dequeue_style('wp-botwatch-css'); |
| 408 | wp_dequeue_style('njt-filebird-admin'); |
| 409 | wp_dequeue_style('ihc_jquery-ui.min.css'); |
| 410 | wp_dequeue_style('badgeos-juqery-autocomplete-css'); |
| 411 | wp_dequeue_style('mainwp'); |
| 412 | wp_dequeue_style('mainwp-responsive-layouts'); |
| 413 | wp_dequeue_style('jquery-ui-style'); |
| 414 | wp_dequeue_style('additional_style'); |
| 415 | wp_dequeue_style('wobd-jqueryui-style'); |
| 416 | wp_dequeue_style('wpdp-style3'); |
| 417 | wp_dequeue_style('jquery_smoothness_ui'); |
| 418 | wp_dequeue_style('uap_main_admin_style'); |
| 419 | wp_dequeue_style('uap_font_awesome'); |
| 420 | wp_dequeue_style('uap_jquery-ui.min.css'); |
| 421 | // loaded only on user profile page |
| 422 | } elseif ('profile.php' == $hook || 'user-edit.php' == $hook) { |
| 423 | |
| 424 | wp_enqueue_style('saboxplugin-admin-style', SIMPLE_AUTHOR_BOX_ASSETS . 'css/sabox-admin-style' . $suffix . '.css'); |
| 425 | |
| 426 | wp_enqueue_media(); |
| 427 | wp_enqueue_editor(); |
| 428 | wp_enqueue_script('sabox-admin-editor-js', SIMPLE_AUTHOR_BOX_ASSETS . 'js/sabox-editor.js', array(), false, true); |
| 429 | $sabox_js_helper = array(); |
| 430 | $social_icons = apply_filters('sabox_social_icons', Simple_Author_Box_Helper::$social_icons); |
| 431 | unset($social_icons['user_email']); |
| 432 | |
| 433 | $sabox_js_helper['socialIcons'] = $social_icons; |
| 434 | wp_localize_script('sabox-admin-editor-js', 'SABHelper', $sabox_js_helper); |
| 435 | } |
| 436 | |
| 437 | $pointers = get_option(SIMPLE_AUTHOR_POINTERS); |
| 438 | |
| 439 | if ($pointers && 'appearance_page_simple-author-box' != $hook) { |
| 440 | $pointers['_nonce_dismiss_pointer'] = wp_create_nonce('sab_dismiss_pointer'); |
| 441 | $pointers['plugin_name'] = apply_filters('sab_plugin_name', __('Simple Author Box', 'simple-author-box')); |
| 442 | wp_enqueue_script('sab-pointers', SIMPLE_AUTHOR_BOX_ASSETS . 'js/sab-pointers.js', array(), false, true); |
| 443 | wp_enqueue_script('wp-pointer'); |
| 444 | wp_enqueue_style('wp-pointer'); |
| 445 | wp_localize_script('wp-pointer', 'sab_pointers', $pointers); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | public function add_extra_fields($extra_fields) |
| 450 | { |
| 451 | |
| 452 | unset($extra_fields['aim']); |
| 453 | unset($extra_fields['jabber']); |
| 454 | unset($extra_fields['yim']); |
| 455 | |
| 456 | return $extra_fields; |
| 457 | } |
| 458 | |
| 459 | /*---------------------------------------------------------------------------------------------------------- |
| 460 | Adding the author box main CSS |
| 461 | -----------------------------------------------------------------------------------------------------------*/ |
| 462 | public function saboxplugin_author_box_style() |
| 463 | { |
| 464 | |
| 465 | $suffix = '.min'; |
| 466 | if (SIMPLE_AUTHOR_SCRIPT_DEBUG) { |
| 467 | $suffix = ''; |
| 468 | } |
| 469 | |
| 470 | $sab_protocol = is_ssl() ? 'https' : 'http'; |
| 471 | $sab_box_subset = Simple_Author_Box_Helper::get_option('sab_box_subset'); |
| 472 | |
| 473 | /** |
| 474 | * Check for duplicate font families, remove duplicates & re-work the font enqueue procedure |
| 475 | * |
| 476 | * @since 2.0.4 |
| 477 | */ |
| 478 | if ('none' != strtolower($sab_box_subset)) { |
| 479 | $sab_subset = '&subset=' . strtolower($sab_box_subset); |
| 480 | } else { |
| 481 | $sab_subset = '&subset=latin'; |
| 482 | } |
| 483 | |
| 484 | $sab_author_font = Simple_Author_Box_Helper::get_option('sab_box_name_font'); |
| 485 | $sab_desc_font = Simple_Author_Box_Helper::get_option('sab_box_desc_font'); |
| 486 | $sab_web_font = Simple_Author_Box_Helper::get_option('sab_box_web_font'); |
| 487 | |
| 488 | $bunny_fonts = array(); |
| 489 | |
| 490 | if ($sab_author_font && 'none' != strtolower($sab_author_font)) { |
| 491 | $bunny_fonts[] = str_replace(' ', '+', esc_attr($sab_author_font)); |
| 492 | } |
| 493 | |
| 494 | if ($sab_desc_font && 'none' != strtolower($sab_desc_font)) { |
| 495 | $bunny_fonts[] = str_replace(' ', '+', esc_attr($sab_desc_font)); |
| 496 | } |
| 497 | |
| 498 | if ('1' == $this->options['sab_web'] && $sab_web_font && 'none' != strtolower($sab_web_font)) { |
| 499 | $bunny_fonts[] = str_replace(' ', '+', esc_attr($sab_web_font)); |
| 500 | } |
| 501 | |
| 502 | $bunny_fonts = apply_filters('sabox_bunny_fonts', $bunny_fonts); |
| 503 | |
| 504 | $bunny_fonts = array_unique($bunny_fonts); |
| 505 | |
| 506 | if (!empty($bunny_fonts)) { // let's check the array's not empty before actually loading; we want to avoid loading 'none' font-familes |
| 507 | $final_bunny_fonts = array(); |
| 508 | |
| 509 | foreach ($bunny_fonts as $v) { |
| 510 | $final_bunny_fonts[] = $v . ':400,700,400italic,700italic'; |
| 511 | } |
| 512 | |
| 513 | wp_register_style('sab-font', $sab_protocol . '://fonts.bunny.net/css?family=' . implode('|', $final_bunny_fonts) . $sab_subset, array(), null); |
| 514 | } |
| 515 | /** |
| 516 | * end changes introduced in 2.0.4 |
| 517 | */ |
| 518 | |
| 519 | if (!is_single() && !is_page() && !is_author() && !is_archive()) { |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | if (!empty($bunny_fonts)) { |
| 524 | wp_enqueue_style('sab-font'); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | |
| 529 | public function inline_style() |
| 530 | { |
| 531 | |
| 532 | if (!is_single() && !is_page() && !is_author() && !is_archive()) { |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | $style = '<style type="text/css">'; |
| 537 | $style .= Simple_Author_Box_Helper::generate_inline_css(); |
| 538 | $style .= '</style>'; |
| 539 | |
| 540 | wpsabox_wp_kses_wf($style); |
| 541 | } |
| 542 | |
| 543 | public function shortcode($atts) |
| 544 | { |
| 545 | $defaults = array( |
| 546 | 'ids' => '', |
| 547 | ); |
| 548 | |
| 549 | $atts = wp_parse_args($atts, $defaults); |
| 550 | |
| 551 | if ('' != $atts['ids']) { |
| 552 | |
| 553 | |
| 554 | if ('all' != $atts['ids']) { |
| 555 | $ids = explode(',', $atts['ids']); |
| 556 | } else { |
| 557 | $ids = get_users(array('fields' => 'ID')); |
| 558 | } |
| 559 | |
| 560 | ob_start(); |
| 561 | $sabox_options = Simple_Author_Box_Helper::get_option('saboxplugin_options'); |
| 562 | if (!empty($ids)) { |
| 563 | foreach ($ids as $user_id) { |
| 564 | |
| 565 | $template = Simple_Author_Box_Helper::get_template(); |
| 566 | $sabox_author_id = $user_id; |
| 567 | echo '<div class="sabox-plus-item">'; |
| 568 | include($template); |
| 569 | echo '</div>'; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | $html = ob_get_clean(); |
| 574 | } else { |
| 575 | $html = wpsabox_author_box(); |
| 576 | } |
| 577 | |
| 578 | return $html; |
| 579 | } |
| 580 | |
| 581 | |
| 582 | public function show_social_media_icons($return, $user) |
| 583 | { |
| 584 | if (isset($user->roles) && in_array('sab-guest-author', (array) $user->roles)) { |
| 585 | return false; |
| 586 | } |
| 587 | |
| 588 | return true; |
| 589 | } |
| 590 | |
| 591 | public function check_if_show_archive() |
| 592 | { |
| 593 | |
| 594 | if (!is_single() && !is_author() && !is_archive()) { |
| 595 | return false; |
| 596 | } |
| 597 | |
| 598 | if (1 == $this->options['sab_hide_on_archive'] && !is_single()) { |
| 599 | return false; |
| 600 | } |
| 601 | |
| 602 | return true; |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * AMP compatibility |
| 607 | * @since 2.0 |
| 608 | * |
| 609 | * @param $data |
| 610 | * |
| 611 | * @return mixed |
| 612 | */ |
| 613 | |
| 614 | function sab_amp_css($data) |
| 615 | { |
| 616 | |
| 617 | $options = Simple_Author_Box_Helper::get_option('saboxplugin_options'); |
| 618 | |
| 619 | $icon_size = absint(Simple_Author_Box_Helper::get_option('sab_box_icon_size')); |
| 620 | if ('1' == $options['sab_colored']) { |
| 621 | $icon_size = $icon_size * 2; |
| 622 | } |
| 623 | |
| 624 | $data['post_amp_styles'] = array( |
| 625 | '.saboxplugin-wrap .saboxplugin-gravatar' => array( |
| 626 | 'float: left', |
| 627 | 'padding:0 20px 20px 20px', |
| 628 | ), |
| 629 | '.saboxplugin-wrap .saboxplugin-gravatar img' => array( |
| 630 | 'max-width: 100px', |
| 631 | 'height: auto', |
| 632 | ), |
| 633 | '.saboxplugin-wrap .saboxplugin-authorname' => array( |
| 634 | 'font-size: 18px', |
| 635 | 'line-height: 1', |
| 636 | 'margin: 20px 0 0 20px', |
| 637 | 'display: block', |
| 638 | ), |
| 639 | '.saboxplugin-wrap .saboxplugin-authorname a' => array( |
| 640 | 'text-decoration: none', |
| 641 | ), |
| 642 | '.saboxplugin-wrap .saboxplugin-desc' => array( |
| 643 | 'display: block', |
| 644 | 'margin: 5px 20px', |
| 645 | ), |
| 646 | '.saboxplugin-wrap .saboxplugin-desc a' => array( |
| 647 | 'text-decoration: none', |
| 648 | ), |
| 649 | '.saboxplugin-wrap .saboxplugin-desc p' => array( |
| 650 | 'margin: 5px 0 12px 0', |
| 651 | 'font-size: ' . absint(Simple_Author_Box_Helper::get_option('sab_box_desc_size')) . 'px', |
| 652 | 'line-height: ' . absint(Simple_Author_Box_Helper::get_option('sab_box_desc_size') + 7) . 'px', |
| 653 | ), |
| 654 | '.saboxplugin-wrap .saboxplugin-web' => array( |
| 655 | 'margin: 0 20px 15px', |
| 656 | 'text-align: left', |
| 657 | ), |
| 658 | '.saboxplugin-wrap .saboxplugin-socials' => array( |
| 659 | 'position: relative', |
| 660 | 'display: block', |
| 661 | 'background: #fcfcfc', |
| 662 | 'padding: 5px', |
| 663 | 'border-top: 1px solid #eee;', |
| 664 | ), |
| 665 | '.saboxplugin-wrap .saboxplugin-socials a' => array( |
| 666 | 'text-decoration: none', |
| 667 | 'box-shadow: none', |
| 668 | 'padding: 0', |
| 669 | 'margin: 0', |
| 670 | 'border: 0', |
| 671 | 'transition: opacity 0.4s', |
| 672 | '-webkit-transition: opacity 0.4s', |
| 673 | '-moz-transition: opacity 0.4s', |
| 674 | '-o-transition: opacity 0.4s', |
| 675 | 'display: inline-block', |
| 676 | ), |
| 677 | '.saboxplugin-wrap .saboxplugin-socials .saboxplugin-icon-grey' => array( |
| 678 | 'display: inline-block', |
| 679 | 'vertical-align: middle', |
| 680 | 'margin: 10px 5px', |
| 681 | 'color: #444', |
| 682 | 'fill: #444', |
| 683 | ), |
| 684 | '.saboxplugin-wrap .saboxplugin-socials a svg' => array( |
| 685 | 'width:' . absint($icon_size) . 'px;', |
| 686 | 'height:' . absint($icon_size) . 'px', |
| 687 | 'display:block' |
| 688 | ), |
| 689 | '.saboxplugin-wrap .saboxplugin-socials.sabox-colored .saboxplugin-icon-color' => array( |
| 690 | 'color: #FFF', |
| 691 | 'margin: 5px', |
| 692 | 'vertical-align: middle', |
| 693 | 'display: inline-block', |
| 694 | ), |
| 695 | '.saboxplugin-wrap .clearfix' => array( |
| 696 | 'clear:both;', |
| 697 | ), |
| 698 | '.saboxplugin-wrap .saboxplugin-socials a svg .st2' => array( |
| 699 | 'fill: #fff;' |
| 700 | ), |
| 701 | '.saboxplugin-wrap .saboxplugin-socials a svg .st1' => array( |
| 702 | 'fill: rgba( 0, 0, 0, .3 );' |
| 703 | ), |
| 704 | 'img.sab-custom-avatar' => array( |
| 705 | 'max-width:75px;' |
| 706 | ), |
| 707 | // custom paddings & margins |
| 708 | '.saboxplugin-wrap' => array( |
| 709 | 'margin-top: ' . absint(Simple_Author_Box_Helper::get_option('sab_box_margin_top')) . 'px', |
| 710 | 'margin-bottom: ' . absint(Simple_Author_Box_Helper::get_option('sab_box_margin_bottom')) . 'px', |
| 711 | 'padding: ' . absint(Simple_Author_Box_Helper::get_option('sab_box_padding_top_bottom')) . 'px ' . absint(Simple_Author_Box_Helper::get_option('sab_box_padding_left_right')) . 'px', |
| 712 | 'box-sizing: border-box', |
| 713 | 'border: 1px solid #EEE', |
| 714 | 'width: 100%', |
| 715 | 'clear: both', |
| 716 | 'overflow : hidden', |
| 717 | 'word-wrap: break-word', |
| 718 | 'position: relative', |
| 719 | ), |
| 720 | '.sab-edit-settings' => array( |
| 721 | 'display: none;', |
| 722 | ), |
| 723 | '.sab-profile-edit' => array( |
| 724 | 'display: none;', |
| 725 | ), |
| 726 | ); |
| 727 | |
| 728 | if ('1' == $options['sab_colored'] && '1' != $options['sab_box_long_shadow']) { |
| 729 | $data['post_amp_styles']['.saboxplugin-wrap .saboxplugin-socials .saboxplugin-icon-color .st1'] = array( |
| 730 | 'display: none;', |
| 731 | ); |
| 732 | } |
| 733 | |
| 734 | return $data; |
| 735 | } |
| 736 | } |
| 737 |