|
| 1 | +<?php |
| 2 | + |
| 3 | +if ( ! class_exists( 'Walker_Nav_Menu ' ) ) { |
| 4 | + return; |
| 5 | +} |
| 6 | + |
| 7 | +class Shapely_Walker_Nav_Menu_Edit extends Walker_Nav_Menu { |
| 8 | + |
| 9 | + public function start_lvl( &$output, $depth = 0, $args = array() ) { |
| 10 | + } |
| 11 | + |
| 12 | + public function end_lvl( &$output, $depth = 0, $args = array() ) { |
| 13 | + } |
| 14 | + |
| 15 | + public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
| 16 | + global $_wp_nav_menu_max_depth; |
| 17 | + $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; |
| 18 | + |
| 19 | + ob_start(); |
| 20 | + $item_id = esc_attr( $item->ID ); |
| 21 | + $removed_args = array( |
| 22 | + 'action', |
| 23 | + 'customlink-tab', |
| 24 | + 'edit-menu-item', |
| 25 | + 'menu-item', |
| 26 | + 'page-tab', |
| 27 | + '_wpnonce', |
| 28 | + ); |
| 29 | + |
| 30 | + $original_title = false; |
| 31 | + if ( 'taxonomy' == $item->type ) { |
| 32 | + $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); |
| 33 | + if ( is_wp_error( $original_title ) ) { |
| 34 | + $original_title = false; |
| 35 | + } |
| 36 | + } elseif ( 'post_type' == $item->type ) { |
| 37 | + $original_object = get_post( $item->object_id ); |
| 38 | + $original_title = get_the_title( $original_object->ID ); |
| 39 | + } elseif ( 'post_type_archive' == $item->type ) { |
| 40 | + $original_object = get_post_type_object( $item->object ); |
| 41 | + if ( $original_object ) { |
| 42 | + $original_title = $original_object->labels->archives; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + $extra = get_post_meta( $item_id, '_menu_item_extra', true ); |
| 47 | + $widget = get_post_meta( $item_id, '_menu_item_widget', true ); |
| 48 | + |
| 49 | + if ( 'shapely-section' == $extra ) { |
| 50 | + $item->type_label = __( 'Homepage Widget', 'shapely-companion' ); |
| 51 | + } |
| 52 | + |
| 53 | + $classes = array( |
| 54 | + 'menu-item menu-item-depth-' . $depth, |
| 55 | + 'menu-item-' . esc_attr( $item->object ), |
| 56 | + 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ), |
| 57 | + ); |
| 58 | + |
| 59 | + $title = $item->title; |
| 60 | + |
| 61 | + if ( ! empty( $item->_invalid ) ) { |
| 62 | + $classes[] = 'menu-item-invalid'; |
| 63 | + /* translators: %s: title of menu item which is invalid */ |
| 64 | + $title = sprintf( __( '%s (Invalid)', 'shapely-companion' ), $item->title ); |
| 65 | + } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) { |
| 66 | + $classes[] = 'pending'; |
| 67 | + /* translators: %s: title of menu item in draft status */ |
| 68 | + $title = sprintf( __( '%s (Pending)', 'shapely-companion' ), $item->title ); |
| 69 | + } |
| 70 | + |
| 71 | + $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label; |
| 72 | + |
| 73 | + $submenu_text = ''; |
| 74 | + if ( 0 == $depth ) { |
| 75 | + $submenu_text = 'style="display: none;"'; |
| 76 | + } |
| 77 | + $move_up_url = wp_nonce_url( add_query_arg( |
| 78 | + array( |
| 79 | + 'action' => 'move-up-menu-item', |
| 80 | + 'menu-item' => $item_id, |
| 81 | + ), |
| 82 | + remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) |
| 83 | + ), 'move-menu_item' ); |
| 84 | + $move_down_url = wp_nonce_url( add_query_arg( |
| 85 | + array( |
| 86 | + 'action' => 'move-down-menu-item', |
| 87 | + 'menu-item' => $item_id, |
| 88 | + ), |
| 89 | + remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) |
| 90 | + ), 'move-menu_item' ); |
| 91 | + |
| 92 | + ?> |
| 93 | + <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>"> |
| 94 | + <div class="menu-item-bar"> |
| 95 | + <div class="menu-item-handle"> |
| 96 | + <span class="item-title"> |
| 97 | + <span class="menu-item-title"> |
| 98 | + <?php echo esc_html( $title ); ?> |
| 99 | + </span> |
| 100 | + <span class="is-submenu" <?php echo $submenu_text; ?>> <?php _e( 'sub item', 'shapely-companion' ); ?></span> |
| 101 | + </span> <span class="item-controls"> |
| 102 | + <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span> |
| 103 | + <span class="item-order hide-if-js"> |
| 104 | + <a href="<?php echo $move_up_url; ?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up', 'shapely-companion' ); ?>">↑</a> |
| 105 | + | |
| 106 | + <a href="<?php echo $move_down_url; ?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down', 'shapely-companion' ); ?>">↓</a> |
| 107 | + </span> |
| 108 | + <a class="item-edit" id="edit-<?php echo $item_id; ?>" href="<?php echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) ); ?>" aria-label="<?php esc_attr_e( 'Edit menu item', 'shapely-companion' ); ?>"><span class="screen-reader-text"><?php _e( 'Edit', 'shapely-companion' ); ?></span></a> |
| 109 | + </span> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + |
| 113 | + <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>"> |
| 114 | + <?php if ( 'custom' == $item->type ) : ?> |
| 115 | + <p class="field-url description description-wide"> |
| 116 | + <label for="edit-menu-item-url-<?php echo $item_id; ?>"> |
| 117 | + <?php _e( 'URL', 'shapely-companion' ); ?><br/> |
| 118 | + <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>"/> |
| 119 | + </label> |
| 120 | + </p> |
| 121 | + <?php endif; ?> |
| 122 | + <p class="description description-wide"> |
| 123 | + <label for="edit-menu-item-title-<?php echo $item_id; ?>"> |
| 124 | + <?php _e( 'Navigation Label', 'shapely-companion' ); ?><br/> |
| 125 | + <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>"/> |
| 126 | + </label> |
| 127 | + </p> |
| 128 | + <p class="field-title-attribute field-attr-title description description-wide"> |
| 129 | + <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> |
| 130 | + <?php _e( 'Title Attribute', 'shapely-companion' ); ?><br/> |
| 131 | + <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>"/> |
| 132 | + </label> |
| 133 | + </p> |
| 134 | + <p class="field-link-target description"> |
| 135 | + <label for="edit-menu-item-target-<?php echo $item_id; ?>"> |
| 136 | + <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> /> |
| 137 | + <?php _e( 'Open link in a new tab', 'shapely-companion' ); ?> |
| 138 | + </label> |
| 139 | + </p> |
| 140 | + <p class="field-css-classes description description-thin"> |
| 141 | + <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> |
| 142 | + <?php _e( 'CSS Classes (optional)', 'shapely-companion' ); ?><br/> |
| 143 | + <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode( ' ', $item->classes ) ); ?>"/> |
| 144 | + </label> |
| 145 | + </p> |
| 146 | + <p class="field-xfn description description-thin"> |
| 147 | + <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> |
| 148 | + <?php _e( 'Link Relationship (XFN)', 'shapely-companion' ); ?><br/> |
| 149 | + <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>"/> |
| 150 | + </label> |
| 151 | + </p> |
| 152 | + <p class="field-description description description-wide"> |
| 153 | + <label for="edit-menu-item-description-<?php echo $item_id; ?>"> |
| 154 | + <?php _e( 'Description', 'shapely-companion' ); ?><br/> |
| 155 | + <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); ?></textarea> |
| 156 | + <span class="description"><?php _e( 'The description will be displayed in the menu if the current theme supports it.', 'shapely-companion' ); ?></span> |
| 157 | + </label> |
| 158 | + </p> |
| 159 | + |
| 160 | + <fieldset class="field-move hide-if-no-js description description-wide"> |
| 161 | + <span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move', 'shapely-companion' ); ?></span> |
| 162 | + <button type="button" class="button-link menus-move menus-move-up" data-dir="up"><?php _e( 'Up one', 'shapely-companion' ); ?></button> |
| 163 | + <button type="button" class="button-link menus-move menus-move-down" data-dir="down"><?php _e( 'Down one', 'shapely-companion' ); ?></button> |
| 164 | + <button type="button" class="button-link menus-move menus-move-left" data-dir="left"></button> |
| 165 | + <button type="button" class="button-link menus-move menus-move-right" data-dir="right"></button> |
| 166 | + <button type="button" class="button-link menus-move menus-move-top" data-dir="top"><?php _e( 'To the top', 'shapely-companion' ); ?></button> |
| 167 | + </fieldset> |
| 168 | + |
| 169 | + <div class="menu-item-actions description-wide submitbox"> |
| 170 | + <?php if ( 'custom' != $item->type && false !== $original_title ) : ?> |
| 171 | + <p class="link-to-original"> |
| 172 | + <?php printf( __( 'Original: %s', 'shapely-companion' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> |
| 173 | + </p> |
| 174 | + <?php endif; ?> |
| 175 | + <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href=" |
| 176 | + <?php |
| 177 | + echo wp_nonce_url( add_query_arg( |
| 178 | + array( |
| 179 | + 'action' => 'delete-menu-item', |
| 180 | + 'menu-item' => $item_id, |
| 181 | + ), |
| 182 | + admin_url( 'nav-menus.php' ) |
| 183 | + ), 'delete-menu_item_' . $item_id ); |
| 184 | + ?> |
| 185 | + "><?php _e( 'Remove', 'shapely-companion' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> |
| 186 | + <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href=" |
| 187 | + <?php |
| 188 | + echo esc_url( add_query_arg( array( |
| 189 | + 'edit-menu-item' => $item_id, |
| 190 | + 'cancel' => time(), |
| 191 | + ), admin_url( 'nav-menus.php' ) ) ); |
| 192 | + ?> |
| 193 | + #menu-item-settings-<?php echo $item_id; ?>"><?php _e( 'Cancel', 'shapely-companion' ); ?></a> |
| 194 | + </div> |
| 195 | + |
| 196 | + <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>"/> |
| 197 | + <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>"/> |
| 198 | + <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>"/> |
| 199 | + <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>"/> |
| 200 | + <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>"/> |
| 201 | + <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>"/> |
| 202 | + </div><!-- .menu-item-settings--> |
| 203 | + <ul class="menu-item-transport"></ul> |
| 204 | + <?php |
| 205 | + $output .= ob_get_clean(); |
| 206 | + } |
| 207 | + |
| 208 | +} // Shapely_Walker_Nav_Menu_Edit |
0 commit comments