public function save_post($post_id) { $sidebar_id = $_POST['custom-sidebar-select']; if (isset($_POST['custom-sidebar'])) { $sidebar_id = Custom_Sidebars::get_sidebar_id($post_id); } update_post_meta($post_id, '_custom_sidebar', (bool) $_POST['custom-sidebar']); update_post_meta($post_id, '_custom_sidebar_id', sanitize_text_field($sidebar_id)); }
/** * Register a default sidebar to use when a post has no specific sidebar assigned */ public static function register_default_sidebar($sidebar_id) { self::$default_sidebar_id = $sidebar_id; }
<label for="custom-sidebar"><?php _e('Register custom sidebar for this post?', 'custom-sidebars'); ?> </label> <input type="checkbox" name="custom-sidebar" value="1" <?php checked(Custom_Sidebars_Details::has_custom_sidebar(), 1); ?> /> <label for="custom-sidebar-select"><?php _e('Use the following sidebar for this page:', 'custom-sidebars'); ?> </label> <select name="custom-sidebar-select"> <option value=""><?php _e('Default Sidebar', 'custom-sidebars'); ?> </option> <option value="none" <?php selected(Custom_Sidebars::get_sidebar(), 'none'); ?> ><?php /* translators: as in 'No sidebar' */ _e('None', 'custom-sidebars'); ?> </option> <?php $metabox->sidebar_select_options(); ?> </select>