Example #1
0
 /**
  * Builds a dropdown menu of the custom sidebars for use on custom landing pages
  * Used in the meta box on post/page edit screen
  * $skip_default was deprecated in Largo 0.4
  *
  * @param $left_or_right string one of 'left' or 'right' to signal which landing page region to build a dropdown for
  * @param $selected string the id of the sidebar that should be marked as selected when the dropdown is generated
  * @param $post_id integer optionally specify which custom landing page post ID you want to generate a dropdown for
  * @since 0.4
  */
 function largo_landing_page_custom_sidebars_dropdown($left_or_right, $selected, $post_id = null)
 {
     global $wp_registered_sidebars, $post;
     $the_id = $post_id ? $post_id : $post->ID;
     $custom = $selected ? $selected : get_post_meta($the_id, 'custom_sidebar', true);
     // for the ultimate in backwards compatibility, if nothing's set or using deprecated 'default'
     $default = of_get_option('single_template') == 'classic' ? 'sidebar-single' : 'none';
     $val = $default;
     // for new posts
     if ($admin_page->action == 'add') {
         $val = 'none';
     }
     // for posts and taxonomies with values set
     if ($custom && $custom !== 'default') {
         $val = $custom;
     }
     $admin_page = get_current_screen();
     $output = '';
     if (isset($admin_page->post_type) and $admin_page->post_type == 'cftl-tax-landing') {
         $default = of_get_option('landing_' . $left_or_right . '_region_default', $left_or_right == 'right' ? 'sidebar-main' : 'sidebar-single');
         $default_label = sprintf(__('Default (%s)', 'largo'), $wp_registered_sidebars[$default]['name']);
         $output .= '<option value="' . $default . '" ';
         $output .= selected('none', $val, false);
         $output .= '>' . $default_label . '</option>';
     }
     // Filter list of sidebars to exclude those we don't want users to choose
     $excluded = largo_get_excluded_sidebars();
     // Fill the select element with all registered sidebars that are custom
     foreach ($wp_registered_sidebars as $sidebar_id => $sidebar) {
         if ($sidebar_id == $default) {
             continue;
         }
         if (in_array($sidebar_id, $excluded) || in_array($sidebar['name'], $excluded)) {
             continue;
         }
         $output .= '<option value="' . $sidebar_id . '" ' . selected($sidebar_id, $val, false) . '>' . $sidebar['name'] . '</option>';
     }
     echo $output;
 }
Example #2
0
 function largo_custom_sidebars_dropdown($selected = '', $skip_default = false, $post_id = NULL)
 {
     global $wp_registered_sidebars, $post;
     $the_id = $post_id ? $post_id : $post->ID;
     $custom = $selected ? $selected : get_post_meta($the_id, 'custom_sidebar', true);
     // for the ultimate in backwards compatibility, if nothing's set or using deprecated 'default'
     $default = of_get_option('single_template') == 'classic' ? 'sidebar-single' : 'none';
     $val = $default;
     // for new posts
     if ($admin_page->action == 'add') {
         $val = 'none';
     }
     // for posts and taxonomies with values set
     if ($custom && $custom !== 'default') {
         $val = $custom;
     }
     $admin_page = get_current_screen();
     $output = '';
     if ($admin_page->base == 'post') {
         // Add a default option for one column post/page layout (e.g. no sidebar)
         $default_template = of_get_option('single_template');
         $custom_template = get_post_meta($the_id, '_wp_post_template', true);
         $one_column_layout_test = in_array($default_template, array('normal')) && in_array($custom_template, array('', 'single-one-column.php', 'full-page.php')) || $custom_template == 'single-one-column.php';
         if ($one_column_layout_test) {
             $default_label = __('Default (no sidebar)', 'largo');
         } else {
             // Posts with classic layout should default to single sidebar
             $default_label = sprintf(__('Default (%s)', 'largo'), $wp_registered_sidebars['sidebar-single']['name']);
         }
         $output .= '<option value="none" ';
         $output .= selected('none', $val, false);
         $output .= '>' . $default_label . '</option>';
     }
     if ($admin_page->base == 'edit-tags') {
         if (of_get_option('use_topic_sidebar') && is_active_sidebar('topic-sidebar')) {
             $default_label = sprintf(__('Default (%s)', 'largo'), $wp_registered_sidebars['topic-sidebar']['name']);
         } else {
             $default_label = sprintf(__('Default (%s)', 'largo'), $wp_registered_sidebars['sidebar-main']['name']);
         }
         $output .= '<option value="none" ';
         $output .= selected('none', $val, false);
         $output .= '>' . $default_label . '</option>';
     }
     // Filter list of sidebars to exclude those we don't want users to choose
     $excluded = largo_get_excluded_sidebars();
     // Fill the select element with all registered sidebars that are custom
     foreach ($wp_registered_sidebars as $sidebar_id => $sidebar) {
         if (in_array($sidebar_id, $excluded) || in_array($sidebar['name'], $excluded)) {
             continue;
         }
         $output .= '<option value="' . $sidebar_id . '" ' . selected($sidebar_id, $val, false) . '>' . $sidebar['name'] . '</option>';
     }
     echo $output;
 }