Created
April 20, 2017 12:02
-
-
Save igorbenic/ea28efdd930e92262f3edcc1e21cc073 to your computer and use it in GitHub Desktop.
Add a Custom Menu Panel with Easy Digital Download Pages | http://www.ibenic.com/custom-menu-panel-edd-pages
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 characters
| <?php | |
| add_action( 'load-nav-menus.php', 'ibenic_add_edd_menu_panel' ); | |
| /** | |
| * Adding the menu panel metabox | |
| */ | |
| function ibenic_add_edd_menu_panel() { | |
| add_meta_box( | |
| 'edd-menu-panel', | |
| __( 'Easy Digital Downloads', 'edd-menu-panel' ), // Menu Panel Title | |
| 'ibenic_render_edd_menu_panel', // Rendering Function, HTML | |
| 'nav-menus', | |
| 'side', | |
| 'default'); | |
| } |
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 characters
| <?php | |
| function ibenic_render_edd_menu_panel() { | |
| global $nav_menu_selected_id; // The current menu selected ID | |
| $walker = new EDD_Menu_Panel_Walker( false ); // Custom Walker | |
| $args = array( 'walker' => $walker ); // Arguments for the Walker | |
| $edd_pages = array(); | |
| // Here we will define our pages | |
| $edd_pages = apply_filters( 'edd_menu_panel_pages', $edd_pages ); | |
| ?> | |
| <!-- Custom Panel with id #edd-menu-panel --> | |
| <div id="edd-menu-panel" class="posttypediv"> | |
| <p><?php _e( '<em>Links defined in Easy Digital Downloads Settings</em>', 'edd-menu-panel' ); ?></p> | |
| <!-- Holding the Pages --> | |
| <div id="tabs-panel-posttype-edd-menu" class="tabs-panel tabs-panel-active"> | |
| <ul id="edd-menu-checklist-loggedin" class="categorychecklist form-no-clear"> | |
| <!-- Walker --> | |
| <?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $edd_pages ), 0, (object) $args );?> | |
| </ul> | |
| </div> | |
| <?php | |
| $removed_args = array( | |
| 'action', | |
| 'customlink-tab', | |
| 'edit-menu-item', | |
| 'menu-item', | |
| 'page-tab', | |
| '_wpnonce', | |
| ); | |
| ?> | |
| <p class="button-controls"> | |
| <span class="list-controls"> | |
| <!-- Adding a Select All option --> | |
| <a href="<?php | |
| echo esc_url( add_query_arg( | |
| array( | |
| 'edd-menu-tab' => 'all', | |
| 'selectall' => 1, | |
| ), | |
| remove_query_arg( $removed_args ) | |
| ) ); | |
| ?>#edd-menu-panel" class="select-all"><?php _e( 'Select All', 'edd-menu-panel' ); ?></a> | |
| </span> | |
| <span class="add-to-menu"> | |
| <input type="submit"<?php if ( function_exists( 'wp_nav_menu_disabled_check' ) ) : wp_nav_menu_disabled_check( $nav_menu_selected_id ); endif; ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu', 'edd-menu-panel' ); ?>" name="add-custom-menu-item" id="submit-edd-menu-panel" /> | |
| <span class="spinner"></span> | |
| </span> | |
| </p> | |
| </div><!-- /#buddypress-menu --> | |
| <?php | |
| } | |
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 characters
| <?php | |
| // ... | |
| $edd_pages = array(); | |
| $edd_checkout = edd_get_option( 'purchase_page' ); | |
| if( $edd_checkout ) { | |
| $page = get_post( $edd_checkout ); | |
| $edd_pages[ $page->post_name ] = $page; | |
| } | |
| $edd_success = edd_get_option( 'success_page' ); | |
| if( $edd_success ) { | |
| $page = get_post( $edd_success ); | |
| $edd_pages[ $page->post_name ] = $page; | |
| } | |
| $edd_failed = edd_get_option( 'failure_page' ); | |
| if( $edd_failed ) { | |
| $page = get_post( $edd_failed ); | |
| $edd_pages[ $page->post_name ] = $page; | |
| } | |
| $edd_history = edd_get_option( 'purchase_history_page' ); | |
| if( $edd_history ) { | |
| $page = get_post( $edd_history ); | |
| $edd_pages[ $page->post_name ] = $page; | |
| } | |
| $edd_login_redirect = edd_get_option( 'login_redirect_page' ); | |
| if( $edd_login_redirect ) { | |
| $page = get_post( $edd_login_redirect ); | |
| $edd_pages[ $page->post_name ] = $page; | |
| } | |
| $edd_pages = apply_filters( 'edd_menu_panel_pages', $edd_pages ); | |
| // ... |
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 characters
| <?php | |
| /** | |
| * Custom Walker for EDD Pages | |
| */ | |
| class EDD_Menu_Panel_Walker extends Walker_Nav_Menu { | |
| /** | |
| * Create the markup to start an element. | |
| * | |
| * @see Walker::start_el() for description of parameters. | |
| * | |
| * @param string $output Passed by reference. Used to append additional | |
| * content. | |
| * @param object $item Menu item data object. | |
| * @param int $depth Depth of menu item. Used for padding. | |
| * @param object|array $args See {@Walker::start_el()}. | |
| * @param int $id See {@Walker::start_el()}. | |
| */ | |
| function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { | |
| global $_nav_menu_placeholder; | |
| $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; | |
| $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; | |
| $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; | |
| $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; | |
| $output .= $indent . '<li>'; | |
| $output .= '<label class="menu-item-title">'; | |
| $output .= '<input type="checkbox" class="menu-item-checkbox'; | |
| if ( property_exists( $item, 'label' ) ) { | |
| $title = $item->label; | |
| } | |
| $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> '; | |
| $output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title ); | |
| $output .= '</label>'; | |
| if ( empty( $item->url ) ) { | |
| $item->url = $item->guid; | |
| } | |
| if ( ! in_array( array( 'edd-menu', 'edd-'. $item->post_name .'-nav' ), $item->classes ) ) { | |
| $item->classes[] = 'edd-menu'; | |
| $item->classes[] = 'edd-'. $item->post_name .'-nav'; | |
| } | |
| // Menu item hidden fields. | |
| $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />'; | |
| $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />'; | |
| $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />'; | |
| $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />'; | |
| $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />'; | |
| $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />'; | |
| $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />'; | |
| $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />'; | |
| $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />'; | |
| $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment