-
-
Save GarySwift/5b8c40c5cb0815a95d3e0a0716bb0406 to your computer and use it in GitHub Desktop.
Revisions
-
carlodaniele revised this gist
Sep 8, 2016 . No changes.There are no files selected for viewing
-
carlodaniele renamed this gist
Sep 8, 2016 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ <?php /** * @package Custom_menu_admin * @version 1.0 */ /* Plugin Name: Custom menu admin Plugin URI: http://wordpress.org/extend/plugins/# Description: This is an example plugin Author: Carlo Daniele Version: 1.0 Author URI: http://carlodaniele.it/en/ @@ -18,14 +18,14 @@ * @param object $object The meta box object * @link https://developer.wordpress.org/reference/functions/add_meta_box/ */ function custom_add_menu_meta_box( $object ) { add_meta_box( 'custom-menu-metabox', __( 'Authors' ), 'custom_menu_meta_box', 'nav-menus', 'side', 'default' ); return $object; } add_filter( 'nav_menu_meta_box_object', 'custom_add_menu_meta_box', 10, 1); /** * Displays a metabox for authors menu item. @@ -36,7 +36,7 @@ function sm_add_menu_meta_box( $object ) { * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/class-walker-nav-menu-edit.php * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/class-walker-nav-menu-checklist.php */ function custom_menu_meta_box(){ global $nav_menu_selected_id; $walker = new Walker_Nav_Menu_Checklist(); -
carlodaniele revised this gist
Jul 20, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,7 +56,7 @@ function sm_menu_meta_box(){ foreach ( $authors as &$author ) { $author->classes = array(); $author->type = 'custom'; $author->object_id = $author->ID; $author->title = $author->nickname . ' - ' . implode(', ', $author->roles); $author->object = 'custom'; $author->url = get_author_posts_url( $author->ID ); -
carlodaniele revised this gist
Jul 13, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ function sm_add_menu_meta_box( $object ) { /** * Displays a metabox for authors menu item. * * @global int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu * * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/nav-menu.php * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/class-walker-nav-menu-edit.php -
carlodaniele revised this gist
Jul 13, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ function sm_add_menu_meta_box( $object ) { add_filter( 'nav_menu_meta_box_object', 'sm_add_menu_meta_box', 10, 1); /** * Displays a metabox for authors menu item. * * @global int|string $nav_menu_selected_id * -
carlodaniele revised this gist
Jun 6, 2016 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,15 +30,14 @@ function sm_add_menu_meta_box( $object ) { /** * Displays a metabox for an author menu item. * * @global int|string $nav_menu_selected_id * * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/nav-menu.php * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/class-walker-nav-menu-edit.php * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/class-walker-nav-menu-checklist.php */ function sm_menu_meta_box(){ global $nav_menu_selected_id; $walker = new Walker_Nav_Menu_Checklist(); -
carlodaniele revised this gist
Jun 4, 2016 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,11 +16,9 @@ * Add menu meta box * * @param object $object The meta box object * @link https://developer.wordpress.org/reference/functions/add_meta_box/ */ function sm_add_menu_meta_box( $object ) { add_meta_box( 'sm-menu-metabox', __( 'Authors' ), 'sm_menu_meta_box', 'nav-menus', 'side', 'default' ); -
carlodaniele revised this gist
Apr 17, 2016 . 1 changed file with 5 additions and 72 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,66 +12,6 @@ Author URI: http://carlodaniele.it/en/ */ /** * Add menu meta box * @@ -106,7 +46,7 @@ function sm_menu_meta_box(){ $current_tab = 'all'; $authors = get_users( array( 'orderby' => 'nicename', 'order' => 'ASC', 'who' => 'authors' ) ); $admins = array(); if ( isset( $_REQUEST['authorarchive-tab'] ) && 'admins' == $_REQUEST['authorarchive-tab'] ) { $current_tab = 'admins'; @@ -120,21 +60,14 @@ function sm_menu_meta_box(){ $author->classes = array(); $author->type = 'custom'; $author->object_id = $author->nickname; $author->title = $author->nickname . ' - ' . implode(', ', $author->roles); $author->object = 'custom'; $author->url = get_author_posts_url( $author->ID ); $author->attr_title = $author->displayname; if( $author->has_cap( 'edit_users' ) ){ $admins[] = $author; } } $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce' ); -
carlodaniele revised this gist
Apr 16, 2016 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -95,6 +95,9 @@ function sm_add_menu_meta_box( $object ) { * @global int $_nav_menu_placeholder * @global int|string $nav_menu_selected_id * * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/nav-menu.php * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/class-walker-nav-menu-edit.php * @link https://core.trac.wordpress.org/browser/tags/4.5/src/wp-admin/includes/class-walker-nav-menu-checklist.php */ function sm_menu_meta_box(){ global $_nav_menu_placeholder, $nav_menu_selected_id; @@ -142,13 +145,13 @@ function sm_menu_meta_box(){ <a class="nav-tab-link" data-type="tabs-panel-authorarchive-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url( add_query_arg( 'authorarchive-tab', 'all', remove_query_arg( $removed_args ) ) ); ?>#tabs-panel-authorarchive-all"> <?php _e( 'View All' ); ?> </a> </li><!-- /.tabs --> <li <?php echo ( 'admins' == $current_tab ? ' class="tabs"' : '' ); ?>> <a class="nav-tab-link" data-type="tabs-panel-authorarchive-admins" href="<?php if ( $nav_menu_selected_id ) echo esc_url( add_query_arg( 'authorarchive-tab', 'admins', remove_query_arg( $removed_args ) ) ); ?>#tabs-panel-authorarchive-admins"> <?php _e( 'Admins' ); ?> </a> </li><!-- /.tabs --> </ul> @@ -158,15 +161,15 @@ function sm_menu_meta_box(){ echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $authors), 0, (object) array( 'walker' => $walker) ); ?> </ul> </div><!-- /.tabs-panel --> <div id="tabs-panel-authorarchive-admins" class="tabs-panel tabs-panel-view-admins <?php echo ( 'admins' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"> <ul id="authorarchive-checklist-admins" class="categorychecklist form-no-clear"> <?php echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $admins), 0, (object) array( 'walker' => $walker) ); ?> </ul> </div><!-- /.tabs-panel --> <p class="button-controls wp-clearfix"> <span class="list-controls"> @@ -177,8 +180,7 @@ function sm_menu_meta_box(){ <span class="spinner"></span> </span> </p> </div><!-- /.categorydiv --> <?php } -
carlodaniele revised this gist
Apr 16, 2016 . 1 changed file with 13 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -163,17 +163,22 @@ function sm_menu_meta_box(){ <div id="tabs-panel-authorarchive-admins" class="tabs-panel tabs-panel-view-admins <?php echo ( 'admins' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"> <ul id="authorarchive-checklist-admins" class="categorychecklist form-no-clear"> <?php echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $admins), 0, (object) array( 'walker' => $walker) ); ?> </ul> </div> <p class="button-controls wp-clearfix"> <span class="list-controls"> <a href="<?php echo esc_url( add_query_arg( array( 'authorarchive-tab' => 'all', 'selectall' => 1, ), remove_query_arg( $removed_args ) )); ?>#authorarchive" class="select-all"><?php _e('Select All'); ?></a> </span> <span class="add-to-menu"> <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-authorarchive-menu-item" id="submit-authorarchive" /> <span class="spinner"></span> </span> </p> </div><!-- /.categorydiv --> <?php } -
carlodaniele revised this gist
Apr 16, 2016 . 1 changed file with 74 additions and 37 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,6 @@ */ /** * Register custom post types * @@ -24,23 +23,23 @@ function sm_register_cpt() { $args = array( 'label' => __( 'Event', 'smashing_plugin' ), 'labels' => array( 'name' => __( 'Events', 'smashing_plugin' ), 'singular_name' => __( 'Event', 'smashing_plugin' ), 'add_new_item' => __( 'Add New Event', 'smashing_plugin' ) ), 'public' => true, 'show_ui' => true, 'has_archive' => true, 'show_in_menu' => true, 'exclude_from_search' => false, 'capability_type' => 'post', 'map_meta_cap' => true, 'hierarchical' => false, 'rewrite' => array( 'slug' => 'event', 'with_front' => true ), 'query_var' => true, 'menu_icon' => 'dashicons-calendar-alt', 'supports' => array( 'title', 'editor', 'thumbnail', 'author', 'custom-fields' ), 'taxonomies' => array( 'typology' ) ); register_post_type( 'event', $args ); @@ -53,27 +52,26 @@ function sm_register_cpt() { function sm_register_custom_taxonomies() { $labels = array( 'name' => __( 'Typologies', 'smashing_plugin' ), 'label' => __( 'Typologies', 'smashing_plugin' ), 'add_new_item' => __( 'Add new Typology', 'smashing_plugin' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'label' => __( 'Typologies', 'smashing_plugin' ), 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'typology', 'with_front' => true ), 'show_admin_column' => true, ); register_taxonomy( 'typology', array( 'event' ), $args ); } add_action( 'init', 'sm_register_custom_taxonomies' ); /** * Add menu meta box * @@ -101,11 +99,18 @@ function sm_add_menu_meta_box( $object ) { function sm_menu_meta_box(){ global $_nav_menu_placeholder, $nav_menu_selected_id; $walker = new Walker_Nav_Menu_Checklist(); $current_tab = 'all'; $authors = get_users( array( 'orderby' => 'nicename', 'order' => 'ASC', 'who' => 'authors' ) ); $admins = get_users( array( 'role' => 'administrator', 'orderby' => 'nicename', 'order' => 'ASC' ) ); if ( isset( $_REQUEST['authorarchive-tab'] ) && 'admins' == $_REQUEST['authorarchive-tab'] ) { $current_tab = 'admins'; }elseif ( isset( $_REQUEST['authorarchive-tab'] ) && 'all' == $_REQUEST['authorarchive-tab'] ) { $current_tab = 'all'; } /* set values to required item properties */ foreach ( $authors as &$author ) { @@ -114,23 +119,55 @@ function sm_menu_meta_box(){ $author->object_id = $author->nickname; $author->title = $author->nickname; $author->object = 'custom'; $author->url = get_author_posts_url( $author->ID ); $author->attr_title = $author->displayname; } /* set values to required item properties */ foreach ( $admins as &$admin ) { $admin->classes = array(); $admin->type = 'custom'; $admin->object_id = $admin->nickname; $admin->title = $admin->nickname; $admin->object = 'custom'; $admin->url = get_author_posts_url( $admin->ID ); $admin->attr_title = $admin->displayname; } $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce' ); ?> <div id="authorarchive" class="categorydiv"> <ul id="authorarchive-tabs" class="authorarchive-tabs add-menu-item-tabs"> <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>> <a class="nav-tab-link" data-type="tabs-panel-authorarchive-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url( add_query_arg( 'authorarchive-tab', 'all', remove_query_arg( $removed_args ) ) ); ?>#tabs-panel-authorarchive-all"> <?php _e( 'View All' ); ?> </a> </li> <li <?php echo ( 'admins' == $current_tab ? ' class="tabs"' : '' ); ?>> <a class="nav-tab-link" data-type="tabs-panel-authorarchive-admins" href="<?php if ( $nav_menu_selected_id ) echo esc_url( add_query_arg( 'authorarchive-tab', 'admins', remove_query_arg( $removed_args ) ) ); ?>#tabs-panel-authorarchive-admins"> <?php _e( 'Admins' ); ?> </a> </li> </ul> <div id="tabs-panel-authorarchive-all" class="tabs-panel tabs-panel-view-all <?php echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"> <ul id="authorarchive-checklist-all" class="categorychecklist form-no-clear"> <?php echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $authors), 0, (object) array( 'walker' => $walker) ); ?> </ul> </div> <div id="tabs-panel-authorarchive-admins" class="tabs-panel tabs-panel-view-admins <?php echo ( 'admins' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"> <ul id="authorarchive-checklist-admins" class="categorychecklist form-no-clear"> <?php echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $admins), 0, (object) array( 'walker' => $walker) ); ?> </ul> </div> </div><!-- /.tabs-panel --> <p class="button-controls wp-clearfix"> <span class="add-to-menu"> -
carlodaniele revised this gist
Apr 15, 2016 . 1 changed file with 26 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,23 +24,23 @@ function sm_register_cpt() { $args = array( 'label' => __( 'Event', 'smashing_plugin' ), 'labels' => array( 'name' => __( 'Events', 'smashing_plugin' ), 'singular_name' => __( 'Event', 'smashing_plugin' ), 'add_new_item' => __( 'Add New Event', 'smashing_plugin' ) ), 'public' => true, 'show_ui' => true, 'has_archive' => true, 'show_in_menu' => true, 'exclude_from_search' => false, 'capability_type' => 'post', 'map_meta_cap' => true, 'hierarchical' => false, 'rewrite' => array( 'slug' => 'event', 'with_front' => true ), 'query_var' => true, 'menu_icon' => 'dashicons-calendar-alt', 'supports' => array( 'title', 'editor', 'thumbnail', 'author', 'custom-fields' ), 'taxonomies' => array( 'typology' ) ); register_post_type( 'event', $args ); @@ -53,19 +53,19 @@ function sm_register_cpt() { function sm_register_custom_taxonomies() { $labels = array( 'name' => __( 'Typologies', 'smashing_plugin' ), 'label' => __( 'Typologies', 'smashing_plugin' ), 'add_new_item' => __( 'Add new Typology', 'smashing_plugin' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'label' => __( 'Typologies', 'smashing_plugin' ), 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'typology', 'with_front' => true ), 'show_admin_column' => true, ); register_taxonomy( 'typology', array( 'event' ), $args ); -
carlodaniele created this gist
Apr 15, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,142 @@ <?php /** * @package Smashing_menu_admin * @version 1.0 */ /* Plugin Name: Smashing menu admin Plugin URI: http://wordpress.org/extend/plugins/# Description: This is an example plugin for Smashing Magazine readers Author: Carlo Daniele Version: 1.0 Author URI: http://carlodaniele.it/en/ */ /** * Register custom post types * * @link https://codex.wordpress.org/Function_Reference/register_post_type */ function sm_register_cpt() { $args = array( 'label' => __( 'Event', 'smashing_plugin' ), 'labels' => array( 'name' => __( 'Events', 'smashing_plugin' ), 'singular_name' => __( 'Event', 'smashing_plugin' ), 'add_new_item' => __( 'Add New Event', 'smashing_plugin' ) ), 'public' => true, 'show_ui' => true, 'has_archive' => true, 'show_in_menu' => true, 'exclude_from_search' => false, 'capability_type' => 'post', 'map_meta_cap' => true, 'hierarchical' => false, 'rewrite' => array( 'slug' => 'event', 'with_front' => true ), 'query_var' => true, 'menu_icon' => 'dashicons-calendar-alt', 'supports' => array( 'title', 'editor', 'thumbnail', 'author', 'custom-fields' ), 'taxonomies' => array( 'typology' ) ); register_post_type( 'event', $args ); } add_action( 'init', 'sm_register_cpt', 10, 0); /** * Register custom taxonomy */ function sm_register_custom_taxonomies() { $labels = array( 'name' => __( 'Typologies', 'smashing_plugin' ), 'label' => __( 'Typologies', 'smashing_plugin' ), 'add_new_item' => __( 'Add new Typology', 'smashing_plugin' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'label' => __( 'Typologies', 'smashing_plugin' ), 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'typology', 'with_front' => true ), 'show_admin_column' => true, ); register_taxonomy( 'typology', array( 'event' ), $args ); } add_action( 'init', 'sm_register_custom_taxonomies' ); /** * Add menu meta box * * @param object $object The meta box object * @link https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes */ function sm_add_menu_meta_box( $object ) { /* get triggered only once */ //remove_filter( 'nav_menu_meta_box_object', 'inject_cpt_archives_menu_meta_box', 10, 1); add_meta_box( 'sm-menu-metabox', __( 'Authors' ), 'sm_menu_meta_box', 'nav-menus', 'side', 'default' ); return $object; } add_filter( 'nav_menu_meta_box_object', 'sm_add_menu_meta_box', 10, 1); /** * Displays a metabox for an author menu item. * * @global int $_nav_menu_placeholder * @global int|string $nav_menu_selected_id * */ function sm_menu_meta_box(){ global $_nav_menu_placeholder, $nav_menu_selected_id; $authors = get_users( array( 'orderby' => 'nicename', 'order' => 'ASC', 'who' => 'authors' ) ); $args = array( 'post_status' => array( 'publish' ), 'post_type' => 'event', 'posts_per_page' => -1 ); $walker = new Walker_Nav_Menu_Checklist(); /* set values to required item properties */ foreach ( $authors as &$author ) { $author->classes = array(); $author->type = 'custom'; $author->object_id = $author->nickname; $author->title = $author->nickname; $author->object = 'custom'; $author->menu_item_parent = null; $author->url = get_author_posts_url( $author->ID ); $author->xfn = null; $author->db_id = null; $author->target = null; $author->attr_title = $author->displayname; } ?> <div id="authorarchive" class="authorarchivediv"> <div id="tabs-panel-author-archive" class="tabs-panel tabs-panel-active"> <ul id="author-archive-checklist" class="categorychecklist form-no-clear"> <?php echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $authors), 0, (object) array( 'walker' => $walker) ); ?> </ul> </div> </div><!-- /.tabs-panel --> <p class="button-controls wp-clearfix"> <span class="add-to-menu"> <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-authorarchive-menu-item" id="submit-authorarchive" /> <span class="spinner"></span> </span> </p> <?php }