function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Author Spotlight', 'ts-fab') : $instance['title'], $instance, $this->id_base); $author = !empty($instance['author']) ? $instance['author'] : ''; $show_tabs = array(); !empty($instance['bio']) ? $show_tabs[] = 'bio' : ''; !empty($instance['twitter']) ? $show_tabs[] = 'twitter' : ''; !empty($instance['facebook']) ? $show_tabs[] = 'facebook' : ''; !empty($instance['googleplus']) ? $show_tabs[] = 'googleplus' : ''; !empty($instance['linkedin']) ? $show_tabs[] = 'linkedin' : ''; !empty($instance['latest_posts']) ? $show_tabs[] = 'latest_posts' : ''; !empty($instance['custom']) ? $show_tabs[] = 'custom' : ''; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <?php if ($instance['float_photo'] != 1) { echo '<div class="ts-fab-no-float">'; } // If set to show random author, get random author ID if ($instance['author'] == 'random') { // Get subscriber IDs, so they can be excluded $subscriber_ids = new WP_User_Query(array('role' => 'subscriber', 'fields' => 'ID')); // Get IDs of authors with surpressed author boxes, so they can be excluded as well $surpressed_ids = new WP_User_Query(array('meta_key' => 'ts_fab_user_hide', 'fields' => 'ID')); $authors_to_exclude = array_merge($subscriber_ids->results, $surpressed_ids->results); $args = array('blog_id' => $GLOBALS['blog_id'], 'exclude' => $authors_to_exclude); $users = get_users($args); $random_user = array_rand($users, 1); $authorobject = $users[$random_user]; $author = $authorobject->ID; } echo ts_fab_construct_fab('widget-' . $this->number, $author, $show_tabs); if ($instance['float_photo'] != 1) { echo '</div>'; } ?> <?php echo $after_widget; }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Author Spotlight', 'ts-fab') : $instance['title'], $instance, $this->id_base); $author = !empty($instance['author']) ? $instance['author'] : ''; $show_tabs = array(); !empty($instance['bio']) ? $show_tabs[] = 'bio' : ''; !empty($instance['twitter']) ? $show_tabs[] = 'twitter' : ''; !empty($instance['facebook']) ? $show_tabs[] = 'facebook' : ''; !empty($instance['googleplus']) ? $show_tabs[] = 'googleplus' : ''; !empty($instance['linkedin']) ? $show_tabs[] = 'linkedin' : ''; !empty($instance['latest_posts']) ? $show_tabs[] = 'latest_posts' : ''; !empty($instance['custom']) ? $show_tabs[] = 'custom' : ''; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <?php if ($instance['float_photo'] != 1) { echo '<div class="ts-fab-no-float">'; } // If set to show random author, get random author ID if ($instance['author'] == 'random') { $args = array('blog_id' => $GLOBALS['blog_id']); $users = get_users($args); $random_user = array_rand($users, 1); $authorobject = $users[$random_user]; $author = $authorobject->ID; } echo ts_fab_construct_fab('widget-' . $this->number, $author, $show_tabs); if ($instance['float_photo'] != 1) { echo '</div>'; } ?> <?php echo $after_widget; }
function ts_fab_shortcode($atts) { extract(shortcode_atts(array('authorid' => '', 'tabs' => '', 'avatar' => ''), $atts)); if ($authorid) { $authorid = absint($authorid); } else { return; } // List of allowed tabs $default_tabs = ts_fab_default_tabs(); // default tabs $additional_tabs = array_keys(ts_fab_additional_tabs()); // additional tabs $allowed_tabs = array_merge($default_tabs, $additional_tabs); // all tabs if ($tabs) { $selected_tabs = explode(',', $tabs); foreach ($selected_tabs as $selected_tab) { // Remove empty spaces $selected_tab = str_replace(' ', '', $selected_tab); // If tab name is one of allowed tab names, add it to $show_tabs array if (in_array($selected_tab, $allowed_tabs)) { $show_tabs[] = $selected_tab; } } } // Check if photo needs to be above text if ('above' == $avatar) { $float_attr = 'above'; } else { $float_attr = 'floated'; } // If no tabs are passed, use the ones set in Tabs Settings in plugin settings page if (!isset($show_tabs)) { $show_tabs = array_keys(ts_fab_get_tabs_settings(), 1); } $a = rand(100, 999); $b = rand(100, 999); $c = rand(100, 999); return ts_fab_construct_fab('shortcode-' . $a . '-' . $b . '-' . $c, $authorid, $show_tabs, $float_attr); }
/** * Adds Fancier Aurhot Box to content. * * @since 1.0 * * @param string $content Post content. * @return string $content Post content. */ function ts_fab_add_author_box($content) { if (is_main_query()) { // Only do it if main query global $authordata; global $post; // Use helper functions to get plugin settings $ts_fab_display_settings = ts_fab_get_display_settings(); if (is_singular()) { if (!get_user_meta($authordata->ID, 'ts_fab_user_hide', false) && !get_post_meta($post->ID, 'ts_fab_hide', false)) { // Show Fancier Author Box in posts if (is_singular('post')) { $show_in_posts = $ts_fab_display_settings['show_in_posts']; if ($show_in_posts == 'above') { $content = ts_fab_construct_fab('above', $authordata->ID) . $content; } elseif ($show_in_posts == 'below') { $content .= ts_fab_construct_fab('below', $authordata->ID); } elseif ($show_in_posts == 'both') { $content = ts_fab_construct_fab('above', $authordata->ID) . $content . ts_fab_construct_fab('below', $authordata->ID); } } // Show Fancier Author Box in pages if (is_singular('page')) { $show_in_pages = $ts_fab_display_settings['show_in_pages']; if ($show_in_pages == 'above') { $content = ts_fab_construct_fab('above', $authordata->ID) . $content; } elseif ($show_in_pages == 'below') { $content .= ts_fab_construct_fab('below', $authordata->ID); } elseif ($show_in_pages == 'both') { $content = ts_fab_construct_fab('above', $authordata->ID) . $content . ts_fab_construct_fab('below', $authordata->ID); } } // Show Fancier Author Box in custom post types $args = array('public' => true, '_builtin' => false); $output = 'names'; $operator = 'and'; $custom_post_types = get_post_types($args, $output, $operator); foreach ($custom_post_types as $custom_post_type) { if (is_singular($custom_post_type)) { $show_in_custom = $ts_fab_display_settings['show_in_' . $custom_post_type]; if ($show_in_custom == 'above') { $content = ts_fab_construct_fab('above', $authordata->ID) . $content; } elseif ($show_in_custom == 'below') { $content .= ts_fab_construct_fab('below', $authordata->ID); } elseif ($show_in_custom == 'both') { $content = ts_fab_construct_fab('above', $authordata->ID) . $content . ts_fab_construct_fab('below', $authordata->ID); } } } } } } return $content; }