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); }
function form($instance) { $tabs_settings = ts_fab_get_tabs_settings(); $instance = wp_parse_args((array) $instance, array('title' => '', 'author' => '', 'bio' => $tabs_settings['bio'], 'twitter' => $tabs_settings['twitter'], 'facebook' => $tabs_settings['facebook'], 'googleplus' => $tabs_settings['googleplus'], 'linkedin' => $tabs_settings['linkedin'], 'latest_posts' => $tabs_settings['latest_posts'], 'custom' => $tabs_settings['custom'], 'float_photo' => '')); $title = strip_tags($instance['title']); $author = $instance['author']; $bio = $instance['bio'] ? 'checked="checked"' : ''; $twitter = $instance['twitter'] ? 'checked="checked"' : ''; $facebook = $instance['facebook'] ? 'checked="checked"' : ''; $googleplus = $instance['googleplus'] ? 'checked="checked"' : ''; $linkedin = $instance['linkedin'] ? 'checked="checked"' : ''; $latest_posts = $instance['latest_posts'] ? 'checked="checked"' : ''; $custom = $instance['custom'] ? 'checked="checked"' : ''; $float_photo = $instance['float_photo'] ? 'checked="checked"' : ''; ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "> <?php _e('Title: ', 'ts-fab'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="text" value="<?php echo esc_attr($title); ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('author'); ?> "> <?php _e('Select Author:', 'ts-fab'); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('author'); ?> " name="<?php echo $this->get_field_name('author'); ?> "> <?php $blogusers = get_users(array('blog_id' => $GLOBALS['blog_id'], 'orderby' => 'nicename')); foreach ($blogusers as $user) { $selected = $instance['author'] == $user->ID ? 'selected="selected"' : ''; echo '<option value="' . $user->ID . '"' . $selected . '>' . $user->display_name . '</option>'; } $selected = $instance['author'] == 'random' ? 'selected="selected"' : ''; echo '<option value="random"' . $selected . '>' . __('Random author', 'ts-fab') . '</option>'; ?> </select></p> <p> <input class="checkbox" type="checkbox" <?php echo $bio; ?> id="<?php echo $this->get_field_id('bio'); ?> " name="<?php echo $this->get_field_name('bio'); ?> " /> <label for="<?php echo $this->get_field_id('bio'); ?> "><?php _e('Bio tab', 'ts-fab'); ?> </label> <br/> <input class="checkbox" type="checkbox" <?php echo $twitter; ?> id="<?php echo $this->get_field_id('twitter'); ?> " name="<?php echo $this->get_field_name('twitter'); ?> " /> <label for="<?php echo $this->get_field_id('twitter'); ?> "><?php _e('Twitter tab', 'ts-fab'); ?> </label> <br/> <input class="checkbox" type="checkbox" <?php echo $facebook; ?> id="<?php echo $this->get_field_id('facebook'); ?> " name="<?php echo $this->get_field_name('facebook'); ?> " /> <label for="<?php echo $this->get_field_id('facebook'); ?> "><?php _e('Facebook tab', 'ts-fab'); ?> </label> <br/> <input class="checkbox" type="checkbox" <?php echo $googleplus; ?> id="<?php echo $this->get_field_id('googleplus'); ?> " name="<?php echo $this->get_field_name('googleplus'); ?> " /> <label for="<?php echo $this->get_field_id('googleplus'); ?> "><?php _e('Google+ tab', 'ts-fab'); ?> </label> <br/> <input class="checkbox" type="checkbox" <?php echo $linkedin; ?> id="<?php echo $this->get_field_id('linkedin'); ?> " name="<?php echo $this->get_field_name('linkedin'); ?> " /> <label for="<?php echo $this->get_field_id('linkedin'); ?> "><?php _e('LinkedIn tab', 'ts-fab'); ?> </label> <br/> <input class="checkbox" type="checkbox" <?php echo $latest_posts; ?> id="<?php echo $this->get_field_id('latest_posts'); ?> " name="<?php echo $this->get_field_name('latest_posts'); ?> " /> <label for="<?php echo $this->get_field_id('latest_posts'); ?> "><?php _e('Latest posts tab', 'ts-fab'); ?> </label> <br/> <input class="checkbox" type="checkbox" <?php echo $custom; ?> id="<?php echo $this->get_field_id('custom'); ?> " name="<?php echo $this->get_field_name('custom'); ?> " /> <label for="<?php echo $this->get_field_id('custom'); ?> "><?php _e('Custom tab', 'ts-fab'); ?> </label> <br/> <br/> <input class="checkbox" type="checkbox" <?php echo $float_photo; ?> id="<?php echo $this->get_field_id('float_photo'); ?> " name="<?php echo $this->get_field_name('float_photo'); ?> " /> <label for="<?php echo $this->get_field_id('float_photo'); ?> "><?php _e('Float photo (uncheck for narrow sidebars)', 'ts-fab'); ?> </label> <br/> </p> <?php }
/** * Construct Fanciest Author Box * Used as helper function, to generate Fanciest Author Box before or after posts, as shortcode, widget or template tag * * @since 1.0 */ function ts_fab_construct_fab($context = '', $authorid = '', $show_tabs = array('bio', 'twitter', 'facebook', 'googleplus', 'linkedin', 'latest_posts', 'custom')) { if ($authorid == '') { global $authordata; $author = $authordata; } else { $author = get_userdata($authorid); } $options = ts_fab_get_tabs_settings(); $display_options = ts_fab_get_display_settings(); if (isset($display_options['tabs_style']) && $display_options['tabs_style'] == 'icons') { $tabs_class = 'ts-fab-icons-only'; } else { $tabs_class = 'ts-fab-icons-text'; } // Set custom tab title, based on whether users can override it if (isset($options['custom_tab_override']) && $options['custom_tab_override'] == 1) { if (get_user_meta($author->ID, 'ts_fab_custom_tab_title', true)) { $custom_title = get_user_meta($author->ID, 'ts_fab_custom_tab_title', true); } elseif ($options['custom_tab_title'] != '') { $custom_title = $options['custom_tab_title']; } } elseif (isset($options['custom_tab_title'])) { $custom_title = $options['custom_tab_title']; } $ts_fab = '<!-- Fanciest Author Box v' . FAB_VERSION . ' -->'; $ts_fab .= '<div id="ts-fab-' . $context . '" class="ts-fab-wrapper ' . $tabs_class . '">'; // Do not show tabs list if there's only one tab if (count($show_tabs) > 1) { // Construct tabs list $ts_fab .= '<ul class="ts-fab-list">'; foreach ($show_tabs as $show_tab) { // Check if it's a default tab if (in_array($show_tab, ts_fab_default_tabs())) { switch ($show_tab) { case 'bio': $ts_fab .= '<li class="ts-fab-bio-link"><a href="#ts-fab-bio-' . $context . '">' . __('Bio', 'ts-fab') . '</a></li>'; break; case 'twitter': // Check if Twitter tab needs to be shown and user has entered Twitter details if (in_array('twitter', $show_tabs) && get_user_meta($author->ID, 'ts_fab_twitter', true)) { $ts_fab .= '<li class="ts-fab-twitter-link"><a href="#ts-fab-twitter-' . $context . '">Twitter</a></li>'; } break; case 'googleplus': // Check if Google+ tab needs to be shown and user has entered Google+ details if (in_array('googleplus', $show_tabs) && get_user_meta($author->ID, 'ts_fab_googleplus', true)) { add_action('wp_print_footer_scripts', 'ts_fab_googleplus_head'); $ts_fab .= '<li class="ts-fab-googleplus-link"><a href="#ts-fab-googleplus-' . $context . '">Google+</a></li>'; } break; case 'facebook': // Check if Facebook tab needs to be shown and user has entered Facebook details if (in_array('facebook', $show_tabs) && get_user_meta($author->ID, 'ts_fab_facebook', true)) { $ts_fab .= '<li class="ts-fab-facebook-link"><a href="#ts-fab-facebook-' . $context . '">Facebook</a></li>'; } break; case 'linkedin': // Check if LinkedIn tab needs to be shown and user has entered LinkedIn details if (in_array('linkedin', $show_tabs) && get_user_meta($author->ID, 'ts_fab_linkedin', true)) { $ts_fab .= '<li class="ts-fab-linkedin-link"><a href="#ts-fab-linkedin-' . $context . '">LinkedIn</a></li>'; } break; case 'latest_posts': $ts_fab .= '<li class="ts-fab-latest-posts-link"><a href="#ts-fab-latest-posts-' . $context . '">' . __('Latest Posts', 'ts-fab') . '</a></li>'; break; case 'custom': if ($options['custom'] == 1) { if (in_array('custom', $show_tabs)) { if (isset($custom_title)) { $ts_fab .= '<li class="ts-fab-custom-link"><a href="#ts-fab-custom-' . $context . '">' . strip_tags(stripslashes($custom_title)) . '</a></li>'; } } } break; } // end switch // else it's an additional tab } else { // Tabs added by themes or other plugins $additional_tabs = ts_fab_additional_tabs(); // Check if there are any additional tabs if (!empty($additional_tabs)) { foreach ($additional_tabs as $additional_tab_key => $additional_tab_value) { // Check if checkbox for this tab is checked if (isset($options[$additional_tab_key]) && $show_tab == $additional_tab_key) { // Check tab conditional function to determine whether tab should be shown for this user if (isset($additional_tab_value['conditional_callback'])) { // Sets a flag based on what conditional function returns $conditional_function_output = $additional_tab_value['conditional_callback']($author->ID); } // end conditional function check // Show tab if conditional function doesn't return false if (isset($conditional_function_output) && !$conditional_function_output == false) { $ts_fab .= '<li class="ts-fab-' . $additional_tab_key . '-link ts-fab-additional-link"><a href="#ts-fab-' . $additional_tab_key . '-' . $context . '">' . strip_tags(stripslashes($additional_tab_value['name'])) . '</a></li>'; } // End conditional flag check } // end check if option is checked } // end foreach } // end if } } // end foreach $ts_fab .= '</ul>'; } // End if only one tab check // Construct individual tabs $ts_fab .= '<div class="ts-fab-tabs">'; foreach ($show_tabs as $show_tab) { // Check if it's a default tab if (in_array($show_tab, ts_fab_default_tabs())) { switch ($show_tab) { case 'bio': $ts_fab .= ts_fab_show_bio($context, $author->ID); break; case 'twitter': // Check if Twitter tab needs to be shown and user has entered Twitter details if (get_user_meta($author->ID, 'ts_fab_twitter', true)) { $ts_fab .= ts_fab_show_twitter($context, $author->ID); } break; case 'facebook': // Check if Facebook tab needs to be shown and user has entered Facebook details if (get_user_meta($author->ID, 'ts_fab_facebook', true)) { $ts_fab .= ts_fab_show_facebook($context, $author->ID); } break; case 'googleplus': // Check if Google+ tab needs to be shown and user has entered Google+ details if (get_user_meta($author->ID, 'ts_fab_googleplus', true)) { $ts_fab .= ts_fab_show_googleplus($context, $author->ID); } break; case 'linkedin': // Check if LinkedIn tab needs to be shown and user has entered LinkedIn details if (get_user_meta($author->ID, 'ts_fab_linkedin', true)) { $ts_fab .= ts_fab_show_linkedin($context, $author->ID); } break; case 'latest_posts': $ts_fab .= ts_fab_show_latest_posts($context, $author->ID); break; case 'custom': $ts_fab .= ts_fab_show_custom($context, $author->ID); break; } // end switch // else, it's an additional tab } else { // Tabs added by themes or other plugins $additional_tabs = ts_fab_additional_tabs(); // Check if there are any additional tabs if (!empty($additional_tabs)) { foreach ($additional_tabs as $additional_tab_key => $additional_tab_value) { if ($show_tab == $additional_tab_key) { // Check tab conditional function to determine whether tab should be shown for this user if (isset($additional_tab_value['conditional_callback'])) { // Sets a flag based on what conditional function returns $conditional_function_output = $additional_tab_value['conditional_callback']($author->ID); } // end conditional function check // Show tab if conditional function doesn't return false if (isset($conditional_function_output) && !$conditional_function_output == false) { $ts_fab .= ' <div class="ts-fab-tab ts-fab-additional-tab" id="ts-fab-' . $additional_tab_key . '-' . $context . '">'; // Additional tab callback function $ts_fab .= $additional_tab_value['callback'](); $ts_fab .= '</div>'; } // End conditional flag check } } // end foreach } // end if } } // end foreach $ts_fab .= ' </div> </div>'; return $ts_fab; }
/** * Show latest posts tab field callback * * @since 1.0 */ function ts_fab_show_custom_tab_callback($args) { $options = ts_fab_get_tabs_settings(); ?> <label for="custom" style="display:block;margin-bottom:10px"> <input type="checkbox" id="custom" name="ts_fab_tabs_settings[custom]" value="1" <?php checked(1, $options['custom'], true); ?> /> <?php echo $args[0]; ?> </label> <?php $hide_custom_extra = $options['custom'] != 1 ? 'style="display:none"' : ''; ?> <div id="ts_fab_custom_tab_extra" <?php echo $hide_custom_extra; ?> > <label for="custom_tab_title" style="display:block;margin-bottom:10px"> <?php echo $args[1]; ?> <br /> <input type="text" id="custom_tab_title" name="ts_fab_tabs_settings[custom_tab_title]" <?php if (isset($options['custom_tab_title'])) { echo 'value="' . $options['custom_tab_title'] . '"'; } ?> /><br /> <span class="description"><?php echo $args[4]; ?> </span> </label> <label for="custom_tab_content" style="display:block;margin-bottom:10px"> <?php echo $args[2]; ?> <br /> <textarea id="custom_tab_content" rows="5" cols="50" name="ts_fab_tabs_settings[custom_tab_content]"><?php if (isset($options['custom_tab_content'])) { echo $options['custom_tab_content']; } ?> </textarea> </label> <div><?php echo $args[3]; ?> </div> <div> <label for="custom_tab_override_no"> <input type="radio" id="custom_tab_override_no" name="ts_fab_tabs_settings[custom_tab_override]" value="no" <?php if (isset($options['custom_tab_override'])) { checked('no', $options['custom_tab_override'], true); } ?> /> No </label> <div> <label for="custom_tab_override_content"> <input type="radio" id="custom_tab_override_content" name="ts_fab_tabs_settings[custom_tab_override]" value="content" <?php if (isset($options['custom_tab_override'])) { checked('content', $options['custom_tab_override'], true); } ?> /> Only content </label> <div> </div> <label for="custom_tab_override_both"> <input type="radio" id="custom_tab_override_both" name="ts_fab_tabs_settings[custom_tab_override]" value="1" <?php if (isset($options['custom_tab_override'])) { checked(1, $options['custom_tab_override'], true); } ?> /> Both title and content </label> </div> </div> <?php }
function ts_fab_extra_user_details($user) { ?> <?php if (user_can($user, 'edit_posts')) { ?> <h3>Fanciest Author Box <?php _e('User Details', 'ts-fab'); ?> </h3> <table class="form-table"> <?php $userid = $user->ID; $user_hide = get_user_meta($userid, 'ts_fab_user_hide', false); $user_hide == true ? $checked = 'checked="checked"' : ($checked = ''); ?> <tr> <th><?php _e('Display Fanciest Author Box', 'ts-fab'); ?> </th> <td> <label for="ts_fab_user_hide"> <input type="checkbox" name="ts_fab_user_hide" id="ts_fab_user_hide" value="true" <?php echo $checked; ?> /> <?php _e('Do not automatically add Fanciest Author Box to your posts, pages and custom posts.', 'ts-fab'); ?> </label> </td> </tr> <tr> <th><label for="ts_fab_photo_url">Photo URL</label></th> <td> <input type="text" name="ts_fab_photo_url" id="ts_fab_photo_url" value="<?php echo esc_attr(get_the_author_meta('ts_fab_photo_url', $user->ID)); ?> " class="regular-text" /><br /> <span class="description"><?php _e('Photo URL (optional, if left empty Gravatar image will be used), ideally image should be 64x64 px.', 'ts-fab'); ?> </span> </td> </tr> <tr> <th><label for="ts_fab_twitter">Twitter</label></th> <td> <input type="text" name="ts_fab_twitter" id="ts_fab_twitter" value="<?php echo esc_attr(get_the_author_meta('ts_fab_twitter', $user->ID)); ?> " class="regular-text" /><br /> <span class="description"><?php _e('Your Twitter username (example: thematosoup).', 'ts-fab'); ?> </span> </td> </tr> <?php $userid = $user->ID; $facebook_widget = get_user_meta($userid, 'ts_fab_facebook_button', true); if ($facebook_widget == 'like') { $like = 'checked="checked"'; $subscribe = ' '; } else { $subscribe = 'checked="checked"'; $like = ' '; } ?> <tr> <th><?php _e('Facebook widget type', 'ts-fab'); ?> </th> <td> <label style="margin-right: 15px" for="ts_fab_facebook_subscribe"> <input type="radio" name="ts_fab_facebook_button" id="ts_fab_facebook_subscribe" value="subscribe" <?php echo $subscribe; ?> /> <?php _e('Subscribe', 'ts-fab'); ?> </label> <label for="ts_fab_facebook_like"> <input type="radio" name="ts_fab_facebook_button" id="ts_fab_facebook_like" value="like" <?php echo $like; ?> /> <?php _e('Like', 'ts-fab'); ?> </label> </td> </tr> <tr> <th><label for="ts_fab_facebook">Facebook</label></th> <td> <input type="text" name="ts_fab_facebook" id="ts_fab_facebook" value="<?php echo esc_attr(get_the_author_meta('ts_fab_facebook', $user->ID)); ?> " class="regular-text" /><br /> <span class="description"><?php _e('Your Facebook username or ID. (example: thematosoup)', 'ts-fab'); ?> </span> </td> </tr> <tr> <th><label for="ts_fab_googleplus">Google+</label></th> <td> <input type="text" name="ts_fab_googleplus" id="ts_fab_googleplus" value="<?php echo esc_attr(get_the_author_meta('ts_fab_googleplus', $user->ID)); ?> " class="regular-text" /><br /> <span class="description"><?php _e('Your Google+ ID. (example: 104360438826479763912)', 'ts-fab'); ?> </span> </td> </tr> <tr> <th><label for="ts_fab_linkedin">LinkedIn</label></th> <td> <input type="text" name="ts_fab_linkedin" id="ts_fab_linkedin" value="<?php echo esc_attr(get_the_author_meta('ts_fab_linkedin', $user->ID)); ?> " class="regular-text" /><br /> <span class="description"><?php _e('Your LinkedIn username. (example: slobodanmanic)', 'ts-fab'); ?> </span> </td> </tr> <tr> <th><label for="ts_fab_position"><?php _e('Position', 'ts-fab'); ?> </label></th> <td> <input type="text" name="ts_fab_position" id="ts_fab_position" value="<?php echo esc_attr(get_the_author_meta('ts_fab_position', $user->ID)); ?> " class="regular-text" /><br /> <span class="description"><?php _e('Your position.', 'ts-fab'); ?> </span> </td> </tr> <tr> <th><label for="ts_fab_company"><?php _e('Company', 'ts-fab'); ?> </label></th> <td> <input type="text" name="ts_fab_company" id="ts_fab_company" value="<?php echo esc_attr(get_the_author_meta('ts_fab_company', $user->ID)); ?> " class="regular-text" /><br /> <span class="description"><?php _e('Your company.', 'ts-fab'); ?> </span> </td> </tr> <tr> <th><label for="ts_fab_company_url"><?php _e('Company URL', 'ts-fab'); ?> </label></th> <td> <input type="text" name="ts_fab_company_url" id="ts_fab_company_url" value="<?php echo esc_attr(get_the_author_meta('ts_fab_company_url', $user->ID)); ?> " class="regular-text" /><br /> <span class="description"><?php _e('Your company URL.', 'ts-fab'); ?> </span> </td> </tr> <?php $options = ts_fab_get_tabs_settings(); if (isset($options['custom_tab_override']) && isset($options['custom'])) { if ($options['custom_tab_override'] == 1 || $options['custom_tab_override'] == 'content') { ?> <tr> <th> <?php // If users can only edit content, show them custom tab title set by admin if ($options['custom_tab_override'] == 'content' && isset($options['custom_tab_title'])) { ?> <label for="ts_fab_custom_tab_title"><?php _e('Custom tab', 'ts-fab'); ?> (<?php echo $options['custom_tab_title']; ?> )</label> <?php } else { ?> <label for="ts_fab_custom_tab_title"><?php _e('Custom tab', 'ts-fab'); ?> </label> <?php } ?> </th> <td> <?php if ($options['custom_tab_override'] == 1) { ?> <input type="text" name="ts_fab_custom_tab_title" id="ts_fab_custom_tab_title" value="<?php echo esc_attr(get_the_author_meta('ts_fab_custom_tab_title', $user->ID)); ?> " class="regular-text" /> <div><span class="description"><?php _e('Custom tab title (if not provided by either you or website admin, custom tab will not be visible)', 'ts-fab'); ?> </span></div> <?php } ?> <textarea id="ts_fab_custom_tab_content" style="margin-bottom:1px" rows="5" cols="50" name="ts_fab_custom_tab_content"><?php echo esc_attr(get_the_author_meta('ts_fab_custom_tab_content', $user->ID)); ?> </textarea> <div><span class="description"><?php _e('Custom tab content', 'ts-fab'); ?> </span></div> </td> </tr> <?php } } ?> </table> <?php } // end if ?> <?php }