/** * Constructs Fancier Author Box tab. * * Used as helper function, to generate Fancier Author Box before or after posts. * * @since 1.0 * * @param string $context Above or below posts. * @param integer $authorid User ID. * @param array $show_tabs Array of required tabs. * @return string Bio tab HTML. */ function ts_fab_construct_fab($context = '', $authorid = '', $show_tabs = array('bio', 'latest_posts')) { if ($authorid == '') { global $authordata; $author = $authordata; } else { $author = get_userdata($authorid); } $ts_fab = '<div id="ts-fab-' . $context . '" class="ts-fab-wrapper">'; // Construct tabs list $ts_fab .= '<span class="screen-reader-text">' . __('The following two tabs change content below.', 'ts-fab') . '</span>'; $ts_fab .= '<ul class="ts-fab-list">'; $ts_fab .= '<li class="ts-fab-bio-link"><a href="#ts-fab-bio-' . $context . '">' . __('Bio', 'ts-fab') . '</a></li>'; $ts_fab .= '<li class="ts-fab-latest-posts-link"><a href="#ts-fab-latest-posts-' . $context . '">' . __('Latest Posts', 'ts-fab') . '</a></li>'; $ts_fab .= '</ul>'; // Construct individual tabs $ts_fab .= '<div class="ts-fab-tabs">'; $ts_fab .= ts_fab_show_bio($context, $author->ID); $ts_fab .= ts_fab_show_latest_posts($context, $author->ID); $ts_fab .= ' </div> </div>'; return $ts_fab; }
/** * 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; }