/** * Tell WordPress about the custom sidebars. */ public function register_custom_sidebars() { $sb = self::get_custom_sidebars(); $sb = CustomSidebars::sort_sidebars_by_name($sb); foreach ($sb as $sidebar) { /** * Filter sidebar options for custom sidebars. * * @since 2.0 * * @param array $sidebar Options used by WordPress to display * the sidebar. */ $sidebar = apply_filters('cs_sidebar_params', $sidebar); register_sidebar($sidebar); } }
} ?> <?php } else { ?> <p> <?php _e('Here you can replace the default sidebars. Simply select what ' . 'sidebar you want to show for this post!', 'custom-sidebars'); ?> </p> <?php if (!empty($sidebars)) { global $wp_registered_sidebars; $available = CustomSidebars::sort_sidebars_by_name($wp_registered_sidebars); foreach ($sidebars as $s) { ?> <?php $sb_name = $available[$s]['name']; ?> <p> <label for="cs_replacement_<?php echo esc_attr($s); ?> "> <b><?php echo esc_html($sb_name); ?> </b>: </label>
/** * Returns a list of all sidebars available. * Depending on the parameter this will be either all sidebars or only * sidebars defined by the current theme. * * @param string $type [all|cust|theme] What kind of sidebars to return. */ public static function get_sidebars($type = 'theme') { global $wp_registered_sidebars; $allsidebars = CustomSidebars::sort_sidebars_by_name($wp_registered_sidebars); $result = array(); // Remove inactive sidebars. foreach ($allsidebars as $sb_id => $sidebar) { if (false !== strpos($sidebar['class'], 'inactive-sidebar')) { unset($allsidebars[$sb_id]); } } ksort($allsidebars); if ('all' == $type) { $result = $allsidebars; } elseif ('cust' == $type) { foreach ($allsidebars as $key => $sb) { // Only keep custom sidebars in the results. if (substr($key, 0, 3) == self::$sidebar_prefix) { $result[$key] = $sb; } } } elseif ('theme' == $type) { foreach ($allsidebars as $key => $sb) { // Remove custom sidebars from results. if (substr($key, 0, 3) != self::$sidebar_prefix) { $result[$key] = $sb; } } } return $result; }
/** * Renders the Custom Sidebars form. * * @param int $post_id The post-ID to display * @param string $type Which form to display. 'metabox/quick-edit/col-sidebars'. */ protected function print_sidebars_form($post_id, $type = 'metabox') { global $wp_registered_sidebars; $available = CustomSidebars::sort_sidebars_by_name($wp_registered_sidebars); $replacements = self::get_replacements($post_id); $sidebars = self::get_options('modifiable'); $selected = array(); if (!empty($sidebars)) { foreach ($sidebars as $s) { if (isset($replacements[$s])) { $selected[$s] = $replacements[$s]; } else { $selected[$s] = ''; } } } switch ($type) { case 'col-sidebars': include CSB_VIEWS_DIR . 'col-sidebars.php'; break; case 'quick-edit': include CSB_VIEWS_DIR . 'quick-edit.php'; break; default: include CSB_VIEWS_DIR . 'metabox.php'; break; } }