Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Custom Sidebars
- */
- add_action('add_meta_boxes', 'sidebar_meta_boxes');
- function sidebar_meta_boxes()
- {
- add_meta_box( 'sidebar_metabox-1', __( 'Custom sidebar' ), 'sidebar_meta_box_content', 'page', 'normal', 'high');
- }
- function show_custom_sidebar($post_id = 0)
- {
- global $post;
- // No post ID
- if ($post_id < 1) {
- $post_id = get_the_ID();
- }
- $sidebar = get_post_meta($post_id, 'menu-sidebar', true);
- if ( !empty($sidebar) ) {
- dynamic_sidebar($sidebar);
- }
- }
- // }}}
- // {{{
- function sidebar_meta_box_content()
- {
- global $post;
- global $wp_registered_sidebars;
- $selected = get_post_meta($post->ID, 'menu-sidebar', true);
- wp_nonce_field('sidebar_save', 'sidebar_nonce');
- ?>
- <div class="jaxtag">
- <div class="ajaxtag hide-if-no-js">
- <table style="width: 100%">
- <tr>
- <td width="25%">
- <label for="menusidebar"><?php _e('Menu sidebar') ?>:</label>
- <label class="screen-reader-text" for="menusidebar"><?php _e('Menu sidebar') ?>:</label>
- </td>
- <td width="75%">
- <select name="menusidebar" id="menusidebar">
- <?php foreach ($wp_registered_sidebars as $sidebar) : ?>
- <option value="<?php echo $sidebar['id'] ?>" <?php echo (($selected == $sidebar['id']) ? 'selected="selected"' : '') ?>><?php echo $sidebar['name'] ?></option>
- <?php endforeach ?>
- </select>
- </td>
- </tr>
- </table>
- </div>
- </div>
- <?php
- }
- add_action('save_post', 'sidebar_save_postdata', 10, 2);
- function sidebar_save_postdata( $post_id )
- {
- global $wpdb;
- if ( !wp_verify_nonce( $_POST['sidebar_nonce'], 'sidebar_save' ) ) {
- return $post_id;
- }
- if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
- return $post_id;
- }
- // Check permissions ....
- /*
- * Sidebar
- */
- $menusidebar = trim($_POST['menusidebar']);
- if ( !empty($menusidebar) ) {
- update_post_meta($post_id, 'menu-sidebar', $menusidebar);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement