Changeset 3418538
- Timestamp:
- 12/12/2025 08:45:23 PM (2 months ago)
- Location:
- if-menu-visibility
- Files:
-
- 3 added
- 2 edited
-
tags/1.0.5 (added)
-
tags/1.0.5/if-menu-visibility.php (added)
-
tags/1.0.5/readme.txt (added)
-
trunk/if-menu-visibility.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
if-menu-visibility/trunk/if-menu-visibility.php
r3317885 r3418538 4 4 Plugin Name: IF Menu Visibility 5 5 Description: Show menu items only for logged-in or logged-out users. 6 Version: 1.0. 46 Version: 1.0.5 7 7 Author: Valeri Kluger 8 8 Author URI: https://premium-plugin.com/ … … 11 11 Text Domain: if-menu-visibility 12 12 */ 13 14 // Damit "Visibility" in den Screen Options (oben rechts) erscheint 15 add_filter('manage_nav-menus_columns', function ($columns) { 16 $columns['if-menu-visibility'] = __('Visibility', 'if-menu-visibility'); 17 return $columns; 18 }, 999); 19 20 // Optional: nicht "von Grund auf" verstecken lassen (falls ein Plugin es in hidden-columns schiebt) 21 add_filter('get_user_option_managenav-menuscolumnshidden', function ($hidden) { 22 if (!is_array($hidden)) return $hidden; 23 return array_values(array_diff($hidden, ['if-menu-visibility'])); 24 }, 999); 25 26 // Fallback: Wenn ein Theme/Plugin den Admin-Menu-Walker ersetzt und 27 // wp_nav_menu_item_custom_fields NICHT mehr ausführt, injizieren wir das Feld trotzdem. 28 add_filter('wp_edit_nav_menu_walker', function ($walker) { 29 30 if (!is_admin()) return $walker; 31 32 // Walker-Klasse evtl. noch nicht geladen -> dann nichts ändern 33 if (!class_exists($walker)) return $walker; 34 35 $new = 'IFMV_Walker_' . md5($walker); 36 if (class_exists($new)) return $new; 37 38 $code = ' 39 class ' . $new . ' extends ' . $walker . ' { 40 41 private function ifmv_field_html($item_id, $current) { 42 if (!current_user_can("edit_theme_options")) return ""; 43 44 $html = \'<p class="field-if-menu-visibility description description-wide">\'; 45 $html .= \'<label for="edit-menu-item-if-visibility-\' . esc_attr($item_id) . \'">\'; 46 $html .= esc_html__("Visibility:", "if-menu-visibility"); 47 $html .= \'<select id="edit-menu-item-if-visibility-\' . esc_attr($item_id) . \'" class="widefat" name="menu-item-if-visibility[\' . esc_attr($item_id) . \']">\'; 48 $html .= \'<option value="" \' . selected($current, "", false) . \'>\' . esc_html__("Always show", "if-menu-visibility") . \'</option>\'; 49 $html .= \'<option value="logged_in" \' . selected($current, "logged_in", false) . \'>\' . esc_html__("Only when logged in", "if-menu-visibility") . \'</option>\'; 50 $html .= \'<option value="logged_out" \' . selected($current, "logged_out", false) . \'>\' . esc_html__("Only when logged out", "if-menu-visibility") . \'</option>\'; 51 $html .= \'</select></label></p>\'; 52 53 return $html; 54 } 55 56 public function start_el(&$output, $item, $depth = 0, $args = null, $id = 0) { 57 58 $before_len = strlen($output); 59 parent::start_el($output, $item, $depth, $args, $id); 60 61 // Nur den frisch hinzugefügten Teil bearbeiten 62 $chunk = substr($output, $before_len); 63 64 // Wenn unser Feld schon drin ist (z.B. weil Action doch feuert) -> nichts tun 65 if (strpos($chunk, "field-if-menu-visibility") !== false) { 66 return; 67 } 68 69 $current = get_post_meta($item->ID, "_if_menu_visibility", true); 70 $field = $this->ifmv_field_html($item->ID, $current); 71 72 if (!$field) return; 73 74 // 1) Core-Closing-Comment (häufig vorhanden) 75 $new_chunk = preg_replace("/(\\s*<\\/div>\\s*<!--\\s*\\.menu-item-settings\\s*-->)/", $field . "$1", $chunk, 1, $count); 76 77 // 2) Fallback: vor "Move" Feld 78 if (!$count) { 79 $new_chunk = preg_replace("/(\\s*<p[^>]*class=\\"field-move\\b[^\\"]*\\"[^>]*>)/", $field . "$1", $chunk, 1, $count2); 80 if (!$count2) { 81 // 3) Notfalls ans Ende hängen 82 $new_chunk = $chunk . $field; 83 } 84 } 85 86 $output = substr($output, 0, $before_len) . $new_chunk; 87 } 88 }'; 89 90 eval($code); 91 return $new; 92 93 }, 999); 94 95 13 96 14 97 // Menüpunkt erweitern (Backend) … … 36 119 $visibility = $item->if_menu_visibility ?? ''; 37 120 ?> 38 <p class=" description description-wide">121 <p class="field-if-menu-visibility description description-wide"> 39 122 <label for="edit-menu-item-if-visibility-<?php echo esc_attr($item_id); ?>"> 40 123 <?php esc_html_e('Visibility:', 'if-menu-visibility'); ?> -
if-menu-visibility/trunk/readme.txt
r3317886 r3418538 4 4 Tags: if menu, menu visibility, conditional menu, logged in, logged out 5 5 Requires at least: 5.0 6 Tested up to: 6. 87 Stable tag: 1.0. 46 Tested up to: 6.9 7 Stable tag: 1.0.5 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 34 34 == Changelog == 35 35 36 = 1.0.5 = 37 * Fixed menu item “Visibility” field not showing when themes/plugins override the nav menu admin walker (fallback walker injection) 38 * Ensured the “Visibility” option appears in Screen Options and is not forcibly hidden by other plugins 39 36 40 = 1.0.4 = 37 41 * Added ABSPATH check to prevent direct file access
Note: See TracChangeset
for help on using the changeset viewer.