nav-menu-settings.php
110 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Outputs the Admin Navigation Customization Settings, with specific settings for each user role |
| 4 | */ |
| 5 | $c = 1; |
| 6 | foreach ( $this->admin_menu_settings->roles as $role ) : |
| 7 | $menu = $this->admin_menu_settings->np_menu_original; |
| 8 | $menu = ( isset($menu[$role['name']]) ) ? $menu[$role['name']] : $menu['default']; |
| 9 | $role_capabilities = $this->user_repo->getSingleRoleCapabilities($role['name']); |
| 10 | $hidden = $this->settings->adminMenuHidden($role['name']); |
| 11 | if ( !$hidden ) $hidden = []; |
| 12 | ?> |
| 13 | <div class="np-menu-customization" <?php if ( $c == 1 ) echo ' style="display:block;"'; ?> data-np-nav-menu-customization="menu_role_<?php echo $role['name']; ?>"> |
| 14 | |
| 15 | <?php include(NestedPages\Helpers::view('settings/partials/nav-menu-settings/header')); ?> |
| 16 | |
| 17 | <ul class="np-nav-menu-settings" data-np-sortable-admin-nav> |
| 18 | |
| 19 | <?php |
| 20 | $i = 0; // Counter for order |
| 21 | foreach ( $menu as $menu_item ) : |
| 22 | |
| 23 | // This role doesn't have access to this item |
| 24 | if ( !array_key_exists($menu_item[1], $role_capabilities) || !$role_capabilities[$menu_item[1]] ) continue; |
| 25 | |
| 26 | $item_data = $this->admin_menu_settings->menuItemData($menu_item, $role); |
| 27 | ?> |
| 28 | <li class="np-nav-preview <?php if ( in_array($item_data['id'], $hidden) ) echo 'disabled'; ?><?php if ( $item_data['separator'] ) echo ' separator';?>" <?php if ( $item_data['separator'] ) echo 'data-np-separator-row'; ?>> |
| 29 | <div class="menu-item"> |
| 30 | <div class="submenu-toggle"> |
| 31 | <?php if ( $item_data['submenu'] ) : ?> |
| 32 | <a href="#" data-np-nav-menu-customization-submenu-toggle><span class="arrow"></span></a> |
| 33 | <?php endif; ?> |
| 34 | </div> |
| 35 | <div class="handle"> |
| 36 | <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class=" np-icon-menu"><path d="M0 0h24v24H0z" fill="none" /><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" class="bars" /></svg> |
| 37 | </div> |
| 38 | <div class="title"><div class="menu-icon dashicons-before <?php echo $item_data['icon']; ?>"></div> |
| 39 | <p> |
| 40 | <?php if ( $item_data['separator'] ) : ?> |
| 41 | <?php |
| 42 | echo ( $menu_item[4] !== 'wp-menu-separator woocommerce' ) ? __('Separator', 'wp-nested-pages') : __('Separator (WooCommerce)', 'wp-nested-pages'); |
| 43 | ?> |
| 44 | <button class="button button-small details-button" data-np-remove-separator-button><?php _e('Remove', 'wp-nested-pages'); ?></button> |
| 45 | <?php else : ?> |
| 46 | <input type="text" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][label]" value="<?php if ( $item_data['custom_label'] ) echo esc_attr($item_data['custom_label']); ?>" placeholder="<?php esc_html_e($item_data['original_text']); ?>" class="menu-title-field" /> |
| 47 | <button class="button button-small details-button" data-np-extra-options-button><?php _e('Details', 'wp-nested-pages');?></button> |
| 48 | <?php endif; ?> |
| 49 | </p> |
| 50 | </div><!-- .title --> |
| 51 | </div><!-- .menu-item --> |
| 52 | <?php if ( !$item_data['separator'] ) : ?> |
| 53 | <div class="hide-checkbox"> |
| 54 | <?php if ( $item_data['original_link'] !== 'options-general.php' ) : ?> |
| 55 | <input type="checkbox" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][hidden]" value="<?php echo $item_data['id']; ?>" data-nestedpages-admin-nav-item-checkbox <?php if ( in_array($item_data['id'], $hidden) ) echo 'checked'; ?> /> |
| 56 | <?php endif; ?> |
| 57 | </div> |
| 58 | <?php else : ?> |
| 59 | <input type="hidden" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>]" value="true"> |
| 60 | <?php endif; ?> |
| 61 | <input type="hidden" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][order]" value="<?php echo $i; ?>" data-np-menu-order> |
| 62 | <?php if ( !$item_data['separator'] ) : ?> |
| 63 | <div class="np-extra-options" data-np-extra-options> |
| 64 | <div class="half"> |
| 65 | <label><?php _e('Icon CSS Class', 'wp-nested-pages'); ?> <em>(<a href="https://developer.wordpress.org/resource/dashicons/#admin-site" target="_blank"><?php _e('Reference', 'wp-nested-pages'); ?></a>)</em></label> |
| 66 | <input type="text" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][icon]" value="<?php if ( $item_data['custom_icon'] ) echo esc_attr(sanitize_text_field($item_data['custom_icon'])); ?>" placeholder="<?php echo sanitize_text_field($item_data['original_icon']); ?>" /> |
| 67 | </div><!-- .half --> |
| 68 | <div class="half right" style="display:none;"> |
| 69 | <input type="hidden" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][link]" value="<?php echo esc_attr($item_data['original_link']); ?>"> |
| 70 | <input type="hidden" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][original_link]" value="<?php echo esc_attr($item_data['original_link']); ?>"> |
| 71 | </div> |
| 72 | </div><!-- .np-extra-options --> |
| 73 | <?php endif; ?> |
| 74 | |
| 75 | <?php if ( $item_data['submenu'] ) : ?> |
| 76 | <ul class="submenu-listing" data-np-sortable-admin-subnav> |
| 77 | <?php |
| 78 | $si = 0; |
| 79 | foreach ( $item_data['submenu_items'] as $submenu ) : |
| 80 | $label = ( $item_data['has_custom_submenu'] ) ? $submenu['label'] : $submenu[0]; |
| 81 | $role_name = ( $item_data['has_custom_submenu'] ) ? $submenu['role'] : $submenu[1]; |
| 82 | $link = ( $item_data['has_custom_submenu'] ) ? $submenu['link'] : $submenu[2]; |
| 83 | $hidden_sub = ( $item_data['has_custom_submenu'] && isset($submenu['hidden']) && $submenu['hidden'] == 'true' ) ? true : false; |
| 84 | if ( !array_key_exists($role_name, $role_capabilities) || !$role_capabilities[$role_name] ) continue; // This role doesn't have access to this item |
| 85 | ?> |
| 86 | <li class="np-nav-preview <?php if ( $hidden_sub ) echo 'disabled'; ?> submenu-item" data-np-sortable-admin-nav> |
| 87 | <div class="menu-item"> |
| 88 | <div class="handle"> |
| 89 | <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class=" np-icon-menu"><path d="M0 0h24v24H0z" fill="none" /><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" class="bars" /></svg> |
| 90 | </div> |
| 91 | <div class="title"><p><?php echo $label; ?></p></div> |
| 92 | <div class="hide-checkbox"> |
| 93 | <input type="hidden" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][submenu][<?php echo $si; ?>][label]" value="<?php echo esc_attr($label); ?>" /> |
| 94 | <input type="hidden" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][submenu][<?php echo $si; ?>][role]" value="<?php echo esc_attr($role_name); ?>" /> |
| 95 | <input type="hidden" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][submenu][<?php echo $si; ?>][link]" value="<?php echo esc_attr($link); ?>" /> |
| 96 | <input type="hidden" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][submenu][<?php echo $si; ?>][order]" value="<?php echo $si; ?>" data-np-submenu-order> |
| 97 | <?php if ( $link !== 'nested-pages-settings' ) : ?> |
| 98 | <input type="checkbox" name="nestedpages_admin[nav_menu_options][<?php echo $role['name']; ?>][<?php echo $item_data['id']; ?>][submenu][<?php echo $si; ?>][hidden]" value="true" data-nestedpages-admin-nav-item-checkbox <?php if ( $hidden_sub ) echo 'checked'; ?>/> |
| 99 | <?php endif; ?> |
| 100 | </div> |
| 101 | </div><!-- .menu-item --> |
| 102 | </li> |
| 103 | <?php $si++; endforeach; ?> |
| 104 | </ul> |
| 105 | <?php endif; // Submenu ?> |
| 106 | </li> |
| 107 | <?php $i++; endforeach; ?> |
| 108 | </ul> |
| 109 | </div><!-- .np-menu-customization --> |
| 110 | <?php $c++; endforeach; |