Nav Menu Roles - Version 1.9.1

Version Description

  • Update donation link
  • Update required and tested against versions
Download this release

Release Info

Developer helgatheviking
Plugin Icon 128x128 Nav Menu Roles
Version 1.9.1
Comparing to
See all releases

Code changes from version 1.8.6 to 1.9.1

inc/class.Nav_Menu_Roles_Import.php CHANGED
@@ -1,308 +1,308 @@
1
- <?php
2
- /**
3
- * Nav Menu Roles Importer - import menu item meta
4
- *
5
- * @author Kathy Darling
6
- * @since 1.3
7
- */
8
-
9
- // Exit if accessed directly
10
- if ( ! defined( 'ABSPATH' ) ) {
11
- exit;
12
- }
13
-
14
- if ( ! defined( 'WP_LOAD_IMPORTERS' ) ){
15
- return;
16
- }
17
-
18
- /** Display verbose errors */
19
- if( ! defined( 'IMPORT_DEBUG' ) ){
20
- define( 'IMPORT_DEBUG', false );
21
- }
22
-
23
- // Load Importer API
24
- require_once ABSPATH . 'wp-admin/includes/import.php';
25
-
26
- if ( ! class_exists( 'WP_Importer' ) ) {
27
- $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
28
- if ( file_exists( $class_wp_importer ) )
29
- require $class_wp_importer;
30
- }
31
-
32
- if ( class_exists( 'WP_Importer' ) && ! class_exists( 'Nav_Menu_Roles_Import' ) ) {
33
- class Nav_Menu_Roles_Import extends WP_Importer {
34
-
35
- var $max_wxr_version = 1.2; // max. supported WXR version
36
-
37
- var $id; // WXR attachment ID
38
-
39
- // information to import from WXR file
40
- var $version;
41
- var $posts = array();
42
- var $base_url = '';
43
-
44
-
45
- /**
46
- * __construct function.
47
- *
48
- * @access public
49
- * @return void
50
- */
51
- public function __construct() {
52
- $this->import_page = 'woocommerce_tax_rate_csv';
53
- }
54
-
55
- /**
56
- * Registered callback function for the WordPress Importer
57
- *
58
- * Manages the three separate stages of the WXR import process
59
- */
60
- function dispatch() {
61
- $this->header();
62
-
63
- $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
64
- switch ( $step ) {
65
- case 0:
66
- $this->greet();
67
- break;
68
- case 1:
69
- check_admin_referer( 'import-upload' );
70
- if ( $this->handle_upload() ) {
71
- $file = get_attached_file( $this->id );
72
- set_time_limit(0);
73
- $this->import( $file );
74
- }
75
- break;
76
- }
77
-
78
- $this->footer();
79
- }
80
-
81
- /**
82
- * The main controller for the actual import stage.
83
- *
84
- * @param string $file Path to the WXR file for importing
85
- */
86
- function import( $file ) {
87
- add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
88
- add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
89
-
90
- $this->import_start( $file );
91
-
92
- wp_suspend_cache_invalidation( true );
93
- $this->process_nav_menu_meta();
94
- wp_suspend_cache_invalidation( false );
95
-
96
- $this->import_end();
97
- }
98
-
99
- /**
100
- * Parses the WXR file and prepares us for the task of processing parsed data
101
- *
102
- * @param string $file Path to the WXR file for importing
103
- */
104
- function import_start( $file ) {
105
- if ( ! is_file($file) ) {
106
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
107
- echo __( 'The file does not exist, please try again.', 'nav-menu-roles' ) . '</p>';
108
- $this->footer();
109
- die();
110
- }
111
-
112
- $import_data = $this->parse( $file );
113
-
114
- if ( is_wp_error( $import_data ) ) {
115
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
116
- echo esc_html( $import_data->get_error_message() ) . '</p>';
117
- $this->footer();
118
- die();
119
- }
120
-
121
- $this->version = $import_data['version'];
122
- $this->posts = $import_data['posts'];
123
- $this->base_url = esc_url( $import_data['base_url'] );
124
-
125
- wp_defer_term_counting( true );
126
- wp_defer_comment_counting( true );
127
-
128
- do_action( 'import_start' );
129
- }
130
-
131
- /**
132
- * Performs post-import cleanup of files and the cache
133
- */
134
- function import_end() {
135
- wp_import_cleanup( $this->id );
136
-
137
- wp_cache_flush();
138
- foreach ( get_taxonomies() as $tax ) {
139
- delete_option( "{$tax}_children" );
140
- _get_term_hierarchy( $tax );
141
- }
142
-
143
- wp_defer_term_counting( false );
144
- wp_defer_comment_counting( false );
145
-
146
- echo '<p>' . __( 'All done.', 'nav-menu-roles' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'nav-menu-roles' ) . '</a>' . '</p>';
147
-
148
- do_action( 'import_end' );
149
- }
150
-
151
- /**
152
- * Handles the WXR upload and initial parsing of the file to prepare for
153
- * displaying author import options
154
- *
155
- * @return bool False if error uploading or invalid file, true otherwise
156
- */
157
- function handle_upload() {
158
- $file = wp_import_handle_upload();
159
-
160
- if ( isset( $file['error'] ) ) {
161
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
162
- echo esc_html( $file['error'] ) . '</p>';
163
- return false;
164
- } else if ( ! file_exists( $file['file'] ) ) {
165
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
166
- printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'nav-menu-roles' ), esc_html( $file['file'] ) );
167
- echo '</p>';
168
- return false;
169
- }
170
-
171
- $this->id = (int) $file['id'];
172
- $import_data = $this->parse( $file['file'] );
173
- if ( is_wp_error( $import_data ) ) {
174
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
175
- echo esc_html( $import_data->get_error_message() ) . '</p>';
176
- return false;
177
- }
178
-
179
- $this->version = $import_data['version'];
180
- if ( $this->version > $this->max_wxr_version ) {
181
- echo '<div class="error"><p><strong>';
182
- printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'nav-menu-roles' ), esc_html($import_data['version']) );
183
- echo '</strong></p></div>';
184
- }
185
-
186
- return true;
187
- }
188
-
189
-
190
-
191
- /**
192
- * Create new posts based on import information
193
- *
194
- * Posts marked as having a parent which doesn't exist will become top level items.
195
- * Doesn't create a new post if: the post type doesn't exist, the given post ID
196
- * is already noted as imported or a post with the same title and date already exists.
197
- * Note that new/updated terms, comments and meta are imported for the last of the above.
198
- */
199
- function process_nav_menu_meta() {
200
- foreach ( $this->posts as $post ) {
201
-
202
- // we only want to deal with the nav_menu_item posts
203
- if ( 'nav_menu_item' != $post['post_type'] || ! empty( $post['post_id'] ) )
204
- continue;
205
-
206
- // ok we've got a nav_menu_item
207
- $post_id = (int) $post['post_id'];
208
-
209
- // add/update post meta
210
- if ( isset( $post['postmeta'] ) ) {
211
- foreach ( $post['postmeta'] as $meta ) {
212
- $key = apply_filters( 'import_post_meta_key', $meta['key'] );
213
- $value = false;
214
-
215
-
216
- if ( $key ) {
217
- // export gets meta straight from the DB so could have a serialized string
218
- if ( ! $value )
219
- $value = maybe_unserialize( $meta['value'] );
220
-
221
- update_post_meta( $post_id, $key, $value );
222
- do_action( 'import_post_meta', $post_id, $key, $value );
223
-
224
- }
225
- }
226
- }
227
- }
228
-
229
- unset( $this->posts );
230
- }
231
-
232
-
233
-
234
-
235
- /**
236
- * Parse a WXR file
237
- *
238
- * @param string $file Path to WXR file for parsing
239
- * @return array Information gathered from the WXR file
240
- */
241
- function parse( $file ) {
242
- $parser = new WXR_Parser();
243
- return $parser->parse( $file );
244
- }
245
-
246
- // Display import page title
247
- function header() {
248
- echo '<div class="wrap">';
249
- echo '<h2>' . __( 'Import Nav Menu Roles', 'nav-menu-roles' ) . '</h2>';
250
-
251
- $updates = get_plugin_updates();
252
- $basename = plugin_basename(__FILE__);
253
- if ( isset( $updates[$basename] ) ) {
254
- $update = $updates[$basename];
255
- echo '<div class="error"><p><strong>';
256
- printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'nav-menu-roles' ), $update->update->new_version );
257
- echo '</strong></p></div>';
258
- }
259
- }
260
-
261
- // Close div.wrap
262
- function footer() {
263
- echo '</div>';
264
- }
265
-
266
- /**
267
- * Display introductory text and file upload form
268
- */
269
- function greet() {
270
- echo '<div class="narrow">';
271
- echo '<p>'.__( 'Re-Upload your normal WordPress eXtended RSS (WXR) file and we&#8217;ll import the Nav Menu Roles and any other missing post meta for the Nav Menu items.', 'nav-menu-roles' ).'</p>';
272
- echo '<p>'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'nav-menu-roles' ).'</p>';
273
- wp_import_upload_form( 'admin.php?import=nav_menu_roles&amp;step=1' );
274
- echo '</div>';
275
- }
276
-
277
- /**
278
- * Decide if the given meta key maps to information we will want to import
279
- *
280
- * @param string $key The meta key to check
281
- * @return string|bool The key if we do want to import, false if not
282
- */
283
- function is_valid_meta_key( $key ) {
284
- // skip attachment metadata since we'll regenerate it from scratch
285
- // skip _edit_lock as not relevant for import
286
- if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) )
287
- return false;
288
- return $key;
289
- }
290
-
291
-
292
- /**
293
- * Added to http_request_timeout filter to force timeout at 60 seconds during import
294
- * @param int $val
295
- * @return int
296
- */
297
- public function bump_request_timeout( $val ) {
298
- return 60;
299
- }
300
-
301
- // return the difference in length between two strings
302
- function cmpr_strlen( $a, $b ) {
303
- return strlen($b) - strlen($a);
304
- }
305
-
306
-
307
- } // end class
308
  } // end if
1
+ <?php
2
+ /**
3
+ * Nav Menu Roles Importer - import menu item meta
4
+ *
5
+ * @author Kathy Darling
6
+ * @since 1.3
7
+ */
8
+
9
+ // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit;
12
+ }
13
+
14
+ if ( ! defined( 'WP_LOAD_IMPORTERS' ) ){
15
+ return;
16
+ }
17
+
18
+ /** Display verbose errors */
19
+ if( ! defined( 'IMPORT_DEBUG' ) ){
20
+ define( 'IMPORT_DEBUG', false );
21
+ }
22
+
23
+ // Load Importer API
24
+ require_once ABSPATH . 'wp-admin/includes/import.php';
25
+
26
+ if ( ! class_exists( 'WP_Importer' ) ) {
27
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
28
+ if ( file_exists( $class_wp_importer ) )
29
+ require $class_wp_importer;
30
+ }
31
+
32
+ if ( class_exists( 'WP_Importer' ) && ! class_exists( 'Nav_Menu_Roles_Import' ) ) {
33
+ class Nav_Menu_Roles_Import extends WP_Importer {
34
+
35
+ var $max_wxr_version = 1.2; // max. supported WXR version
36
+
37
+ var $id; // WXR attachment ID
38
+
39
+ // information to import from WXR file
40
+ var $version;
41
+ var $posts = array();
42
+ var $base_url = '';
43
+
44
+
45
+ /**
46
+ * __construct function.
47
+ *
48
+ * @access public
49
+ * @return void
50
+ */
51
+ public function __construct() {
52
+ $this->import_page = 'woocommerce_tax_rate_csv';
53
+ }
54
+
55
+ /**
56
+ * Registered callback function for the WordPress Importer
57
+ *
58
+ * Manages the three separate stages of the WXR import process
59
+ */
60
+ function dispatch() {
61
+ $this->header();
62
+
63
+ $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
64
+ switch ( $step ) {
65
+ case 0:
66
+ $this->greet();
67
+ break;
68
+ case 1:
69
+ check_admin_referer( 'import-upload' );
70
+ if ( $this->handle_upload() ) {
71
+ $file = get_attached_file( $this->id );
72
+ set_time_limit(0);
73
+ $this->import( $file );
74
+ }
75
+ break;
76
+ }
77
+
78
+ $this->footer();
79
+ }
80
+
81
+ /**
82
+ * The main controller for the actual import stage.
83
+ *
84
+ * @param string $file Path to the WXR file for importing
85
+ */
86
+ function import( $file ) {
87
+ add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
88
+ add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
89
+
90
+ $this->import_start( $file );
91
+
92
+ wp_suspend_cache_invalidation( true );
93
+ $this->process_nav_menu_meta();
94
+ wp_suspend_cache_invalidation( false );
95
+
96
+ $this->import_end();
97
+ }
98
+
99
+ /**
100
+ * Parses the WXR file and prepares us for the task of processing parsed data
101
+ *
102
+ * @param string $file Path to the WXR file for importing
103
+ */
104
+ function import_start( $file ) {
105
+ if ( ! is_file($file) ) {
106
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
107
+ echo __( 'The file does not exist, please try again.', 'nav-menu-roles' ) . '</p>';
108
+ $this->footer();
109
+ die();
110
+ }
111
+
112
+ $import_data = $this->parse( $file );
113
+
114
+ if ( is_wp_error( $import_data ) ) {
115
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
116
+ echo esc_html( $import_data->get_error_message() ) . '</p>';
117
+ $this->footer();
118
+ die();
119
+ }
120
+
121
+ $this->version = $import_data['version'];
122
+ $this->posts = $import_data['posts'];
123
+ $this->base_url = esc_url( $import_data['base_url'] );
124
+
125
+ wp_defer_term_counting( true );
126
+ wp_defer_comment_counting( true );
127
+
128
+ do_action( 'import_start' );
129
+ }
130
+
131
+ /**
132
+ * Performs post-import cleanup of files and the cache
133
+ */
134
+ function import_end() {
135
+ wp_import_cleanup( $this->id );
136
+
137
+ wp_cache_flush();
138
+ foreach ( get_taxonomies() as $tax ) {
139
+ delete_option( "{$tax}_children" );
140
+ _get_term_hierarchy( $tax );
141
+ }
142
+
143
+ wp_defer_term_counting( false );
144
+ wp_defer_comment_counting( false );
145
+
146
+ echo '<p>' . __( 'All done.', 'nav-menu-roles' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'nav-menu-roles' ) . '</a>' . '</p>';
147
+
148
+ do_action( 'import_end' );
149
+ }
150
+
151
+ /**
152
+ * Handles the WXR upload and initial parsing of the file to prepare for
153
+ * displaying author import options
154
+ *
155
+ * @return bool False if error uploading or invalid file, true otherwise
156
+ */
157
+ function handle_upload() {
158
+ $file = wp_import_handle_upload();
159
+
160
+ if ( isset( $file['error'] ) ) {
161
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
162
+ echo esc_html( $file['error'] ) . '</p>';
163
+ return false;
164
+ } else if ( ! file_exists( $file['file'] ) ) {
165
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
166
+ printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'nav-menu-roles' ), esc_html( $file['file'] ) );
167
+ echo '</p>';
168
+ return false;
169
+ }
170
+
171
+ $this->id = (int) $file['id'];
172
+ $import_data = $this->parse( $file['file'] );
173
+ if ( is_wp_error( $import_data ) ) {
174
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
175
+ echo esc_html( $import_data->get_error_message() ) . '</p>';
176
+ return false;
177
+ }
178
+
179
+ $this->version = $import_data['version'];
180
+ if ( $this->version > $this->max_wxr_version ) {
181
+ echo '<div class="error"><p><strong>';
182
+ printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'nav-menu-roles' ), esc_html($import_data['version']) );
183
+ echo '</strong></p></div>';
184
+ }
185
+
186
+ return true;
187
+ }
188
+
189
+
190
+
191
+ /**
192
+ * Create new posts based on import information
193
+ *
194
+ * Posts marked as having a parent which doesn't exist will become top level items.
195
+ * Doesn't create a new post if: the post type doesn't exist, the given post ID
196
+ * is already noted as imported or a post with the same title and date already exists.
197
+ * Note that new/updated terms, comments and meta are imported for the last of the above.
198
+ */
199
+ function process_nav_menu_meta() {
200
+ foreach ( $this->posts as $post ) {
201
+
202
+ // we only want to deal with the nav_menu_item posts
203
+ if ( 'nav_menu_item' != $post['post_type'] || ! empty( $post['post_id'] ) )
204
+ continue;
205
+
206
+ // ok we've got a nav_menu_item
207
+ $post_id = (int) $post['post_id'];
208
+
209
+ // add/update post meta
210
+ if ( isset( $post['postmeta'] ) ) {
211
+ foreach ( $post['postmeta'] as $meta ) {
212
+ $key = apply_filters( 'import_post_meta_key', $meta['key'] );
213
+ $value = false;
214
+
215
+
216
+ if ( $key ) {
217
+ // export gets meta straight from the DB so could have a serialized string
218
+ if ( ! $value )
219
+ $value = maybe_unserialize( $meta['value'] );
220
+
221
+ update_post_meta( $post_id, $key, $value );
222
+ do_action( 'import_post_meta', $post_id, $key, $value );
223
+
224
+ }
225
+ }
226
+ }
227
+ }
228
+
229
+ unset( $this->posts );
230
+ }
231
+
232
+
233
+
234
+
235
+ /**
236
+ * Parse a WXR file
237
+ *
238
+ * @param string $file Path to WXR file for parsing
239
+ * @return array Information gathered from the WXR file
240
+ */
241
+ function parse( $file ) {
242
+ $parser = new WXR_Parser();
243
+ return $parser->parse( $file );
244
+ }
245
+
246
+ // Display import page title
247
+ function header() {
248
+ echo '<div class="wrap">';
249
+ echo '<h2>' . __( 'Import Nav Menu Roles', 'nav-menu-roles' ) . '</h2>';
250
+
251
+ $updates = get_plugin_updates();
252
+ $basename = plugin_basename(__FILE__);
253
+ if ( isset( $updates[$basename] ) ) {
254
+ $update = $updates[$basename];
255
+ echo '<div class="error"><p><strong>';
256
+ printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'nav-menu-roles' ), $update->update->new_version );
257
+ echo '</strong></p></div>';
258
+ }
259
+ }
260
+
261
+ // Close div.wrap
262
+ function footer() {
263
+ echo '</div>';
264
+ }
265
+
266
+ /**
267
+ * Display introductory text and file upload form
268
+ */
269
+ function greet() {
270
+ echo '<div class="narrow">';
271
+ echo '<p>'.__( 'Re-Upload your normal WordPress eXtended RSS (WXR) file and we&#8217;ll import the Nav Menu Roles and any other missing post meta for the Nav Menu items.', 'nav-menu-roles' ).'</p>';
272
+ echo '<p>'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'nav-menu-roles' ).'</p>';
273
+ wp_import_upload_form( 'admin.php?import=nav_menu_roles&amp;step=1' );
274
+ echo '</div>';
275
+ }
276
+
277
+ /**
278
+ * Decide if the given meta key maps to information we will want to import
279
+ *
280
+ * @param string $key The meta key to check
281
+ * @return string|bool The key if we do want to import, false if not
282
+ */
283
+ function is_valid_meta_key( $key ) {
284
+ // skip attachment metadata since we'll regenerate it from scratch
285
+ // skip _edit_lock as not relevant for import
286
+ if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) )
287
+ return false;
288
+ return $key;
289
+ }
290
+
291
+
292
+ /**
293
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
294
+ * @param int $val
295
+ * @return int
296
+ */
297
+ public function bump_request_timeout( $val ) {
298
+ return 60;
299
+ }
300
+
301
+ // return the difference in length between two strings
302
+ function cmpr_strlen( $a, $b ) {
303
+ return strlen($b) - strlen($a);
304
+ }
305
+
306
+
307
+ } // end class
308
  } // end if
inc/class.Walker_Nav_Menu_Edit_Roles.php CHANGED
@@ -1,245 +1,245 @@
1
- <?php
2
-
3
- /**
4
- * Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
5
- *
6
- * Create HTML list of nav menu input items.
7
- * Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/nav-menu.php
8
- *
9
- * @package nav-menu-roles
10
- * @since 1.0
11
- * @since WordPress 4.4.0
12
- * @uses Walker_Nav_Menu
13
- */
14
-
15
- class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
16
- /**
17
- * Starts the list before the elements are added.
18
- *
19
- * @see Walker_Nav_Menu::start_lvl()
20
- *
21
- * @since 3.0.0
22
- *
23
- * @param string $output Passed by reference.
24
- * @param int $depth Depth of menu item. Used for padding.
25
- * @param array $args Not used.
26
- */
27
- public function start_lvl( &$output, $depth = 0, $args = array() ) {}
28
-
29
- /**
30
- * Ends the list of after the elements are added.
31
- *
32
- * @see Walker_Nav_Menu::end_lvl()
33
- *
34
- * @since 3.0.0
35
- *
36
- * @param string $output Passed by reference.
37
- * @param int $depth Depth of menu item. Used for padding.
38
- * @param array $args Not used.
39
- */
40
- public function end_lvl( &$output, $depth = 0, $args = array() ) {}
41
-
42
- /**
43
- * Start the element output.
44
- *
45
- * @see Walker_Nav_Menu::start_el()
46
- * @since 3.0.0
47
- *
48
- * @global int $_wp_nav_menu_max_depth
49
- *
50
- * @param string $output Passed by reference. Used to append additional content.
51
- * @param object $item Menu item data object.
52
- * @param int $depth Depth of menu item. Used for padding.
53
- * @param array $args Not used.
54
- * @param int $id Not used.
55
- */
56
- public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
57
- global $_wp_nav_menu_max_depth;
58
- $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
59
-
60
- ob_start();
61
- $item_id = esc_attr( $item->ID );
62
- $removed_args = array(
63
- 'action',
64
- 'customlink-tab',
65
- 'edit-menu-item',
66
- 'menu-item',
67
- 'page-tab',
68
- '_wpnonce',
69
- );
70
-
71
- $original_title = '';
72
- if ( 'taxonomy' == $item->type ) {
73
- $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
74
- if ( is_wp_error( $original_title ) )
75
- $original_title = false;
76
- } elseif ( 'post_type' == $item->type ) {
77
- $original_object = get_post( $item->object_id );
78
- $original_title = get_the_title( $original_object->ID );
79
- } elseif ( 'post_type_archive' == $item->type ) {
80
- $original_object = get_post_type_object( $item->object );
81
- $original_title = $original_object->labels->archives;
82
- }
83
-
84
- $classes = array(
85
- 'menu-item menu-item-depth-' . $depth,
86
- 'menu-item-' . esc_attr( $item->object ),
87
- 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
88
- );
89
-
90
- $title = $item->title;
91
-
92
- if ( ! empty( $item->_invalid ) ) {
93
- $classes[] = 'menu-item-invalid';
94
- /* translators: %s: title of menu item which is invalid */
95
- $title = sprintf( __( '%s (Invalid)' , 'nav-menu-roles' ), $item->title );
96
- } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
97
- $classes[] = 'pending';
98
- /* translators: %s: title of menu item in draft status */
99
- $title = sprintf( __('%s (Pending)', 'nav-menu-roles' ), $item->title );
100
- }
101
-
102
- $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
103
-
104
- $submenu_text = '';
105
- if ( 0 == $depth )
106
- $submenu_text = 'style="display: none;"';
107
-
108
- ?>
109
- <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
110
- <div class="menu-item-bar">
111
- <div class="menu-item-handle">
112
- <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' , 'nav-menu-roles' ); ?></span></span>
113
- <span class="item-controls">
114
- <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
115
- <span class="item-order hide-if-js">
116
- <a href="<?php
117
- echo wp_nonce_url(
118
- add_query_arg(
119
- array(
120
- 'action' => 'move-up-menu-item',
121
- 'menu-item' => $item_id,
122
- ),
123
- remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
124
- ),
125
- 'move-menu_item'
126
- );
127
- ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up', 'nav-menu-roles' ); ?>">&#8593;</abbr></a>
128
- |
129
- <a href="<?php
130
- echo wp_nonce_url(
131
- add_query_arg(
132
- array(
133
- 'action' => 'move-down-menu-item',
134
- 'menu-item' => $item_id,
135
- ),
136
- remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
137
- ),
138
- 'move-menu_item'
139
- );
140
- ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down', 'nav-menu-roles' ); ?>">&#8595;</abbr></a>
141
- </span>
142
- <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item', 'nav-menu-roles' ); ?>" href="<?php
143
- 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 ) ) );
144
- ?>"><?php _e( 'Edit Menu Item' , 'nav-menu-roles' ); ?></a>
145
- </span>
146
- </div>
147
- </div>
148
-
149
- <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
150
- <?php if ( 'custom' == $item->type ) : ?>
151
- <p class="field-url description description-wide">
152
- <label for="edit-menu-item-url-<?php echo $item_id; ?>">
153
- <?php _e( 'URL' , 'nav-menu-roles' ); ?><br />
154
- <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 ); ?>" />
155
- </label>
156
- </p>
157
- <?php endif; ?>
158
- <p class="description description-wide">
159
- <label for="edit-menu-item-title-<?php echo $item_id; ?>">
160
- <?php _e( 'Navigation Label' , 'nav-menu-roles' ); ?><br />
161
- <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 ); ?>" />
162
- </label>
163
- </p>
164
- <p class="field-title-attribute description description-wide">
165
- <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
166
- <?php _e( 'Title Attribute' , 'nav-menu-roles' ); ?><br />
167
- <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 ); ?>" />
168
- </label>
169
- </p>
170
- <p class="field-link-target description">
171
- <label for="edit-menu-item-target-<?php echo $item_id; ?>">
172
- <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' ); ?> />
173
- <?php _e( 'Open link in a new tab' , 'nav-menu-roles' ); ?>
174
- </label>
175
- </p>
176
- <p class="field-css-classes description description-thin">
177
- <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
178
- <?php _e( 'CSS Classes (optional)' , 'nav-menu-roles' ); ?><br />
179
- <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 ) ); ?>" />
180
- </label>
181
- </p>
182
- <p class="field-xfn description description-thin">
183
- <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
184
- <?php _e( 'Link Relationship (XFN)' , 'nav-menu-roles' ); ?><br />
185
- <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 ); ?>" />
186
- </label>
187
- </p>
188
- <p class="field-description description description-wide">
189
- <label for="edit-menu-item-description-<?php echo $item_id; ?>">
190
- <?php _e( 'Description' , 'nav-menu-roles' ); ?><br />
191
- <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_escaped ?></textarea>
192
- <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles' ); ?></span>
193
- </label>
194
- </p>
195
-
196
- <?php
197
- // This is the added section
198
- do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
199
- // end added section
200
- ?>
201
-
202
- <p class="field-move hide-if-no-js description description-wide">
203
- <label>
204
- <span><?php _e( 'Move' , 'nav-menu-roles' ); ?></span>
205
- <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' , 'nav-menu-roles' ); ?></a>
206
- <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' , 'nav-menu-roles' ); ?></a>
207
- <a href="#" class="menus-move menus-move-left" data-dir="left"></a>
208
- <a href="#" class="menus-move menus-move-right" data-dir="right"></a>
209
- <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' , 'nav-menu-roles' ); ?></a>
210
- </label>
211
- </p>
212
-
213
- <div class="menu-item-actions description-wide submitbox">
214
- <?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
215
- <p class="link-to-original">
216
- <?php printf( __('Original: %s', 'nav-menu-roles' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
217
- </p>
218
- <?php endif; ?>
219
- <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
220
- echo wp_nonce_url(
221
- add_query_arg(
222
- array(
223
- 'action' => 'delete-menu-item',
224
- 'menu-item' => $item_id,
225
- ),
226
- admin_url( 'nav-menus.php' )
227
- ),
228
- 'delete-menu_item_' . $item_id
229
- ); ?>"><?php _e( 'Remove' , 'nav-menu-roles' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
230
- ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel', 'nav-menu-roles' ); ?></a>
231
- </div>
232
-
233
- <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
234
- <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 ); ?>" />
235
- <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
236
- <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 ); ?>" />
237
- <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
238
- <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
239
- </div><!-- .menu-item-settings-->
240
- <ul class="menu-item-transport"></ul>
241
- <?php
242
- $output .= ob_get_clean();
243
- }
244
-
245
- } // Walker_Nav_Menu_Edit
1
+ <?php
2
+
3
+ /**
4
+ * Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
5
+ *
6
+ * Create HTML list of nav menu input items.
7
+ * Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/nav-menu.php
8
+ *
9
+ * @package nav-menu-roles
10
+ * @since 1.0
11
+ * @since WordPress 4.4.0
12
+ * @uses Walker_Nav_Menu
13
+ */
14
+
15
+ class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
16
+ /**
17
+ * Starts the list before the elements are added.
18
+ *
19
+ * @see Walker_Nav_Menu::start_lvl()
20
+ *
21
+ * @since 3.0.0
22
+ *
23
+ * @param string $output Passed by reference.
24
+ * @param int $depth Depth of menu item. Used for padding.
25
+ * @param array $args Not used.
26
+ */
27
+ public function start_lvl( &$output, $depth = 0, $args = array() ) {}
28
+
29
+ /**
30
+ * Ends the list of after the elements are added.
31
+ *
32
+ * @see Walker_Nav_Menu::end_lvl()
33
+ *
34
+ * @since 3.0.0
35
+ *
36
+ * @param string $output Passed by reference.
37
+ * @param int $depth Depth of menu item. Used for padding.
38
+ * @param array $args Not used.
39
+ */
40
+ public function end_lvl( &$output, $depth = 0, $args = array() ) {}
41
+
42
+ /**
43
+ * Start the element output.
44
+ *
45
+ * @see Walker_Nav_Menu::start_el()
46
+ * @since 3.0.0
47
+ *
48
+ * @global int $_wp_nav_menu_max_depth
49
+ *
50
+ * @param string $output Passed by reference. Used to append additional content.
51
+ * @param object $item Menu item data object.
52
+ * @param int $depth Depth of menu item. Used for padding.
53
+ * @param array $args Not used.
54
+ * @param int $id Not used.
55
+ */
56
+ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
57
+ global $_wp_nav_menu_max_depth;
58
+ $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
59
+
60
+ ob_start();
61
+ $item_id = esc_attr( $item->ID );
62
+ $removed_args = array(
63
+ 'action',
64
+ 'customlink-tab',
65
+ 'edit-menu-item',
66
+ 'menu-item',
67
+ 'page-tab',
68
+ '_wpnonce',
69
+ );
70
+
71
+ $original_title = '';
72
+ if ( 'taxonomy' == $item->type ) {
73
+ $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
74
+ if ( is_wp_error( $original_title ) )
75
+ $original_title = false;
76
+ } elseif ( 'post_type' == $item->type ) {
77
+ $original_object = get_post( $item->object_id );
78
+ $original_title = get_the_title( $original_object->ID );
79
+ } elseif ( 'post_type_archive' == $item->type ) {
80
+ $original_object = get_post_type_object( $item->object );
81
+ $original_title = $original_object->labels->archives;
82
+ }
83
+
84
+ $classes = array(
85
+ 'menu-item menu-item-depth-' . $depth,
86
+ 'menu-item-' . esc_attr( $item->object ),
87
+ 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
88
+ );
89
+
90
+ $title = $item->title;
91
+
92
+ if ( ! empty( $item->_invalid ) ) {
93
+ $classes[] = 'menu-item-invalid';
94
+ /* translators: %s: title of menu item which is invalid */
95
+ $title = sprintf( __( '%s (Invalid)' , 'nav-menu-roles' ), $item->title );
96
+ } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
97
+ $classes[] = 'pending';
98
+ /* translators: %s: title of menu item in draft status */
99
+ $title = sprintf( __('%s (Pending)', 'nav-menu-roles' ), $item->title );
100
+ }
101
+
102
+ $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
103
+
104
+ $submenu_text = '';
105
+ if ( 0 == $depth )
106
+ $submenu_text = 'style="display: none;"';
107
+
108
+ ?>
109
+ <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
110
+ <div class="menu-item-bar">
111
+ <div class="menu-item-handle">
112
+ <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' , 'nav-menu-roles' ); ?></span></span>
113
+ <span class="item-controls">
114
+ <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
115
+ <span class="item-order hide-if-js">
116
+ <a href="<?php
117
+ echo wp_nonce_url(
118
+ add_query_arg(
119
+ array(
120
+ 'action' => 'move-up-menu-item',
121
+ 'menu-item' => $item_id,
122
+ ),
123
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
124
+ ),
125
+ 'move-menu_item'
126
+ );
127
+ ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up', 'nav-menu-roles' ); ?>">&#8593;</abbr></a>
128
+ |
129
+ <a href="<?php
130
+ echo wp_nonce_url(
131
+ add_query_arg(
132
+ array(
133
+ 'action' => 'move-down-menu-item',
134
+ 'menu-item' => $item_id,
135
+ ),
136
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
137
+ ),
138
+ 'move-menu_item'
139
+ );
140
+ ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down', 'nav-menu-roles' ); ?>">&#8595;</abbr></a>
141
+ </span>
142
+ <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item', 'nav-menu-roles' ); ?>" href="<?php
143
+ 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 ) ) );
144
+ ?>"><?php _e( 'Edit Menu Item' , 'nav-menu-roles' ); ?></a>
145
+ </span>
146
+ </div>
147
+ </div>
148
+
149
+ <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
150
+ <?php if ( 'custom' == $item->type ) : ?>
151
+ <p class="field-url description description-wide">
152
+ <label for="edit-menu-item-url-<?php echo $item_id; ?>">
153
+ <?php _e( 'URL' , 'nav-menu-roles' ); ?><br />
154
+ <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 ); ?>" />
155
+ </label>
156
+ </p>
157
+ <?php endif; ?>
158
+ <p class="description description-wide">
159
+ <label for="edit-menu-item-title-<?php echo $item_id; ?>">
160
+ <?php _e( 'Navigation Label' , 'nav-menu-roles' ); ?><br />
161
+ <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 ); ?>" />
162
+ </label>
163
+ </p>
164
+ <p class="field-title-attribute description description-wide">
165
+ <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
166
+ <?php _e( 'Title Attribute' , 'nav-menu-roles' ); ?><br />
167
+ <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 ); ?>" />
168
+ </label>
169
+ </p>
170
+ <p class="field-link-target description">
171
+ <label for="edit-menu-item-target-<?php echo $item_id; ?>">
172
+ <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' ); ?> />
173
+ <?php _e( 'Open link in a new tab' , 'nav-menu-roles' ); ?>
174
+ </label>
175
+ </p>
176
+ <p class="field-css-classes description description-thin">
177
+ <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
178
+ <?php _e( 'CSS Classes (optional)' , 'nav-menu-roles' ); ?><br />
179
+ <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 ) ); ?>" />
180
+ </label>
181
+ </p>
182
+ <p class="field-xfn description description-thin">
183
+ <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
184
+ <?php _e( 'Link Relationship (XFN)' , 'nav-menu-roles' ); ?><br />
185
+ <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 ); ?>" />
186
+ </label>
187
+ </p>
188
+ <p class="field-description description description-wide">
189
+ <label for="edit-menu-item-description-<?php echo $item_id; ?>">
190
+ <?php _e( 'Description' , 'nav-menu-roles' ); ?><br />
191
+ <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_escaped ?></textarea>
192
+ <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles' ); ?></span>
193
+ </label>
194
+ </p>
195
+
196
+ <?php
197
+ // This is the added section
198
+ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
199
+ // end added section
200
+ ?>
201
+
202
+ <p class="field-move hide-if-no-js description description-wide">
203
+ <label>
204
+ <span><?php _e( 'Move' , 'nav-menu-roles' ); ?></span>
205
+ <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' , 'nav-menu-roles' ); ?></a>
206
+ <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' , 'nav-menu-roles' ); ?></a>
207
+ <a href="#" class="menus-move menus-move-left" data-dir="left"></a>
208
+ <a href="#" class="menus-move menus-move-right" data-dir="right"></a>
209
+ <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' , 'nav-menu-roles' ); ?></a>
210
+ </label>
211
+ </p>
212
+
213
+ <div class="menu-item-actions description-wide submitbox">
214
+ <?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
215
+ <p class="link-to-original">
216
+ <?php printf( __('Original: %s', 'nav-menu-roles' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
217
+ </p>
218
+ <?php endif; ?>
219
+ <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
220
+ echo wp_nonce_url(
221
+ add_query_arg(
222
+ array(
223
+ 'action' => 'delete-menu-item',
224
+ 'menu-item' => $item_id,
225
+ ),
226
+ admin_url( 'nav-menus.php' )
227
+ ),
228
+ 'delete-menu_item_' . $item_id
229
+ ); ?>"><?php _e( 'Remove' , 'nav-menu-roles' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
230
+ ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel', 'nav-menu-roles' ); ?></a>
231
+ </div>
232
+
233
+ <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
234
+ <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 ); ?>" />
235
+ <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
236
+ <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 ); ?>" />
237
+ <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
238
+ <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
239
+ </div><!-- .menu-item-settings-->
240
+ <ul class="menu-item-transport"></ul>
241
+ <?php
242
+ $output .= ob_get_clean();
243
+ }
244
+
245
+ } // Walker_Nav_Menu_Edit
inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php CHANGED
@@ -1,248 +1,248 @@
1
- <?php
2
-
3
- /**
4
- * Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
5
- *
6
- * Create HTML list of nav menu input items.
7
- * Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/class-walker-nav-menu-edit.php
8
- *
9
- * @package nav-menu-roles
10
- * @since 1.0
11
- * @since WordPress 4.5.0
12
- * @uses Walker_Nav_Menu_Edit
13
- */
14
-
15
- class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
16
-
17
- /**
18
- * Starts the list before the elements are added.
19
- *
20
- * @see Walker_Nav_Menu::start_lvl()
21
- *
22
- * @since 3.0.0
23
- *
24
- * @param string $output Passed by reference.
25
- * @param int $depth Depth of menu item. Used for padding.
26
- * @param array $args Not used.
27
- */
28
- public function start_lvl( &$output, $depth = 0, $args = array() ) {}
29
-
30
- /**
31
- * Ends the list of after the elements are added.
32
- *
33
- * @see Walker_Nav_Menu::end_lvl()
34
- *
35
- * @since 3.0.0
36
- *
37
- * @param string $output Passed by reference.
38
- * @param int $depth Depth of menu item. Used for padding.
39
- * @param array $args Not used.
40
- */
41
- public function end_lvl( &$output, $depth = 0, $args = array() ) {}
42
-
43
- /**
44
- * Start the element output.
45
- *
46
- * @see Walker_Nav_Menu::start_el()
47
- * @since 3.0.0
48
- *
49
- * @global int $_wp_nav_menu_max_depth
50
- *
51
- * @param string $output Passed by reference. Used to append additional content.
52
- * @param object $item Menu item data object.
53
- * @param int $depth Depth of menu item. Used for padding.
54
- * @param array $args Not used.
55
- * @param int $id Not used.
56
- */
57
- public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
58
- global $_wp_nav_menu_max_depth;
59
- $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
60
-
61
- ob_start();
62
- $item_id = esc_attr( $item->ID );
63
- $removed_args = array(
64
- 'action',
65
- 'customlink-tab',
66
- 'edit-menu-item',
67
- 'menu-item',
68
- 'page-tab',
69
- '_wpnonce',
70
- );
71
-
72
- $original_title = '';
73
- if ( 'taxonomy' == $item->type ) {
74
- $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
75
- if ( is_wp_error( $original_title ) )
76
- $original_title = false;
77
- } elseif ( 'post_type' == $item->type ) {
78
- $original_object = get_post( $item->object_id );
79
- $original_title = get_the_title( $original_object->ID );
80
- } elseif ( 'post_type_archive' == $item->type ) {
81
- $original_object = get_post_type_object( $item->object );
82
- if ( $original_object ) {
83
- $original_title = $original_object->labels->archives;
84
- }
85
- }
86
-
87
- $classes = array(
88
- 'menu-item menu-item-depth-' . $depth,
89
- 'menu-item-' . esc_attr( $item->object ),
90
- 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
91
- );
92
-
93
- $title = $item->title;
94
-
95
- if ( ! empty( $item->_invalid ) ) {
96
- $classes[] = 'menu-item-invalid';
97
- /* translators: %s: title of menu item which is invalid */
98
- $title = sprintf( __( '%s (Invalid)', 'nav-menu-roles' ), $item->title );
99
- } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
100
- $classes[] = 'pending';
101
- /* translators: %s: title of menu item in draft status */
102
- $title = sprintf( __('%s (Pending)', 'nav-menu-roles'), $item->title );
103
- }
104
-
105
- $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
106
-
107
- $submenu_text = '';
108
- if ( 0 == $depth )
109
- $submenu_text = 'style="display: none;"';
110
-
111
- ?>
112
- <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
113
- <div class="menu-item-bar">
114
- <div class="menu-item-handle">
115
- <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item', 'nav-menu-roles' ); ?></span></span>
116
- <span class="item-controls">
117
- <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
118
- <span class="item-order hide-if-js">
119
- <a href="<?php
120
- echo wp_nonce_url(
121
- add_query_arg(
122
- array(
123
- 'action' => 'move-up-menu-item',
124
- 'menu-item' => $item_id,
125
- ),
126
- remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
127
- ),
128
- 'move-menu_item'
129
- );
130
- ?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up', 'nav-menu-roles' ) ?>">&#8593;</a>
131
- |
132
- <a href="<?php
133
- echo wp_nonce_url(
134
- add_query_arg(
135
- array(
136
- 'action' => 'move-down-menu-item',
137
- 'menu-item' => $item_id,
138
- ),
139
- remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
140
- ),
141
- 'move-menu_item'
142
- );
143
- ?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down', 'nav-menu-roles' ) ?>">&#8595;</a>
144
- </span>
145
- <a class="item-edit" id="edit-<?php echo $item_id; ?>" href="<?php
146
- 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 ) ) );
147
- ?>" aria-label="<?php esc_attr_e( 'Edit menu item', 'nav-menu-roles' ); ?>"><?php _e( 'Edit', 'nav-menu-roles' ); ?></a>
148
- </span>
149
- </div>
150
- </div>
151
-
152
- <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
153
- <?php if ( 'custom' == $item->type ) : ?>
154
- <p class="field-url description description-wide">
155
- <label for="edit-menu-item-url-<?php echo $item_id; ?>">
156
- <?php _e( 'URL', 'nav-menu-roles' ); ?><br />
157
- <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 ); ?>" />
158
- </label>
159
- </p>
160
- <?php endif; ?>
161
- <p class="description description-wide">
162
- <label for="edit-menu-item-title-<?php echo $item_id; ?>">
163
- <?php _e( 'Navigation Label', 'nav-menu-roles' ); ?><br />
164
- <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 ); ?>" />
165
- </label>
166
- </p>
167
- <p class="field-title-attribute field-attr-title description description-wide">
168
- <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
169
- <?php _e( 'Title Attribute', 'nav-menu-roles' ); ?><br />
170
- <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 ); ?>" />
171
- </label>
172
- </p>
173
- <p class="field-link-target description">
174
- <label for="edit-menu-item-target-<?php echo $item_id; ?>">
175
- <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' ); ?> />
176
- <?php _e( 'Open link in a new tab', 'nav-menu-roles' ); ?>
177
- </label>
178
- </p>
179
- <p class="field-css-classes description description-thin">
180
- <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
181
- <?php _e( 'CSS Classes (optional)', 'nav-menu-roles' ); ?><br />
182
- <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 ) ); ?>" />
183
- </label>
184
- </p>
185
- <p class="field-xfn description description-thin">
186
- <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
187
- <?php _e( 'Link Relationship (XFN)', 'nav-menu-roles' ); ?><br />
188
- <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 ); ?>" />
189
- </label>
190
- </p>
191
- <p class="field-description description description-wide">
192
- <label for="edit-menu-item-description-<?php echo $item_id; ?>">
193
- <?php _e( 'Description', 'nav-menu-roles' ); ?><br />
194
- <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_escaped ?></textarea>
195
- <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles'); ?></span>
196
- </label>
197
- </p>
198
-
199
- <?php
200
- // This is the added section
201
- do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
202
- // end added section
203
- ?>
204
-
205
- <p class="field-move hide-if-no-js description description-wide">
206
- <label>
207
- <span><?php _e( 'Move', 'nav-menu-roles' ); ?></span>
208
- <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one', 'nav-menu-roles' ); ?></a>
209
- <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one', 'nav-menu-roles' ); ?></a>
210
- <a href="#" class="menus-move menus-move-left" data-dir="left"></a>
211
- <a href="#" class="menus-move menus-move-right" data-dir="right"></a>
212
- <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top', 'nav-menu-roles' ); ?></a>
213
- </label>
214
- </p>
215
-
216
- <div class="menu-item-actions description-wide submitbox">
217
- <?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
218
- <p class="link-to-original">
219
- <?php printf( __('Original: %s', 'nav-menu-roles'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
220
- </p>
221
- <?php endif; ?>
222
- <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
223
- echo wp_nonce_url(
224
- add_query_arg(
225
- array(
226
- 'action' => 'delete-menu-item',
227
- 'menu-item' => $item_id,
228
- ),
229
- admin_url( 'nav-menus.php' )
230
- ),
231
- 'delete-menu_item_' . $item_id
232
- ); ?>"><?php _e( 'Remove', 'nav-menu-roles' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
233
- ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel', 'nav-menu-roles'); ?></a>
234
- </div>
235
-
236
- <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
237
- <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 ); ?>" />
238
- <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
239
- <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 ); ?>" />
240
- <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
241
- <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
242
- </div><!-- .menu-item-settings-->
243
- <ul class="menu-item-transport"></ul>
244
- <?php
245
- $output .= ob_get_clean();
246
- }
247
-
248
- } // Walker_Nav_Menu_Edit
1
+ <?php
2
+
3
+ /**
4
+ * Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
5
+ *
6
+ * Create HTML list of nav menu input items.
7
+ * Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/class-walker-nav-menu-edit.php
8
+ *
9
+ * @package nav-menu-roles
10
+ * @since 1.0
11
+ * @since WordPress 4.5.0
12
+ * @uses Walker_Nav_Menu_Edit
13
+ */
14
+
15
+ class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
16
+
17
+ /**
18
+ * Starts the list before the elements are added.
19
+ *
20
+ * @see Walker_Nav_Menu::start_lvl()
21
+ *
22
+ * @since 3.0.0
23
+ *
24
+ * @param string $output Passed by reference.
25
+ * @param int $depth Depth of menu item. Used for padding.
26
+ * @param array $args Not used.
27
+ */
28
+ public function start_lvl( &$output, $depth = 0, $args = array() ) {}
29
+
30
+ /**
31
+ * Ends the list of after the elements are added.
32
+ *
33
+ * @see Walker_Nav_Menu::end_lvl()
34
+ *
35
+ * @since 3.0.0
36
+ *
37
+ * @param string $output Passed by reference.
38
+ * @param int $depth Depth of menu item. Used for padding.
39
+ * @param array $args Not used.
40
+ */
41
+ public function end_lvl( &$output, $depth = 0, $args = array() ) {}
42
+
43
+ /**
44
+ * Start the element output.
45
+ *
46
+ * @see Walker_Nav_Menu::start_el()
47
+ * @since 3.0.0
48
+ *
49
+ * @global int $_wp_nav_menu_max_depth
50
+ *
51
+ * @param string $output Passed by reference. Used to append additional content.
52
+ * @param object $item Menu item data object.
53
+ * @param int $depth Depth of menu item. Used for padding.
54
+ * @param array $args Not used.
55
+ * @param int $id Not used.
56
+ */
57
+ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
58
+ global $_wp_nav_menu_max_depth;
59
+ $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
60
+
61
+ ob_start();
62
+ $item_id = esc_attr( $item->ID );
63
+ $removed_args = array(
64
+ 'action',
65
+ 'customlink-tab',
66
+ 'edit-menu-item',
67
+ 'menu-item',
68
+ 'page-tab',
69
+ '_wpnonce',
70
+ );
71
+
72
+ $original_title = '';
73
+ if ( 'taxonomy' == $item->type ) {
74
+ $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
75
+ if ( is_wp_error( $original_title ) )
76
+ $original_title = false;
77
+ } elseif ( 'post_type' == $item->type ) {
78
+ $original_object = get_post( $item->object_id );
79
+ $original_title = get_the_title( $original_object->ID );
80
+ } elseif ( 'post_type_archive' == $item->type ) {
81
+ $original_object = get_post_type_object( $item->object );
82
+ if ( $original_object ) {
83
+ $original_title = $original_object->labels->archives;
84
+ }
85
+ }
86
+
87
+ $classes = array(
88
+ 'menu-item menu-item-depth-' . $depth,
89
+ 'menu-item-' . esc_attr( $item->object ),
90
+ 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
91
+ );
92
+
93
+ $title = $item->title;
94
+
95
+ if ( ! empty( $item->_invalid ) ) {
96
+ $classes[] = 'menu-item-invalid';
97
+ /* translators: %s: title of menu item which is invalid */
98
+ $title = sprintf( __( '%s (Invalid)', 'nav-menu-roles' ), $item->title );
99
+ } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
100
+ $classes[] = 'pending';
101
+ /* translators: %s: title of menu item in draft status */
102
+ $title = sprintf( __('%s (Pending)', 'nav-menu-roles'), $item->title );
103
+ }
104
+
105
+ $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
106
+
107
+ $submenu_text = '';
108
+ if ( 0 == $depth )
109
+ $submenu_text = 'style="display: none;"';
110
+
111
+ ?>
112
+ <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
113
+ <div class="menu-item-bar">
114
+ <div class="menu-item-handle">
115
+ <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item', 'nav-menu-roles' ); ?></span></span>
116
+ <span class="item-controls">
117
+ <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
118
+ <span class="item-order hide-if-js">
119
+ <a href="<?php
120
+ echo wp_nonce_url(
121
+ add_query_arg(
122
+ array(
123
+ 'action' => 'move-up-menu-item',
124
+ 'menu-item' => $item_id,
125
+ ),
126
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
127
+ ),
128
+ 'move-menu_item'
129
+ );
130
+ ?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up', 'nav-menu-roles' ) ?>">&#8593;</a>
131
+ |
132
+ <a href="<?php
133
+ echo wp_nonce_url(
134
+ add_query_arg(
135
+ array(
136
+ 'action' => 'move-down-menu-item',
137
+ 'menu-item' => $item_id,
138
+ ),
139
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
140
+ ),
141
+ 'move-menu_item'
142
+ );
143
+ ?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down', 'nav-menu-roles' ) ?>">&#8595;</a>
144
+ </span>
145
+ <a class="item-edit" id="edit-<?php echo $item_id; ?>" href="<?php
146
+ 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 ) ) );
147
+ ?>" aria-label="<?php esc_attr_e( 'Edit menu item', 'nav-menu-roles' ); ?>"><?php _e( 'Edit', 'nav-menu-roles' ); ?></a>
148
+ </span>
149
+ </div>
150
+ </div>
151
+
152
+ <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
153
+ <?php if ( 'custom' == $item->type ) : ?>
154
+ <p class="field-url description description-wide">
155
+ <label for="edit-menu-item-url-<?php echo $item_id; ?>">
156
+ <?php _e( 'URL', 'nav-menu-roles' ); ?><br />
157
+ <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 ); ?>" />
158
+ </label>
159
+ </p>
160
+ <?php endif; ?>
161
+ <p class="description description-wide">
162
+ <label for="edit-menu-item-title-<?php echo $item_id; ?>">
163
+ <?php _e( 'Navigation Label', 'nav-menu-roles' ); ?><br />
164
+ <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 ); ?>" />
165
+ </label>
166
+ </p>
167
+ <p class="field-title-attribute field-attr-title description description-wide">
168
+ <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
169
+ <?php _e( 'Title Attribute', 'nav-menu-roles' ); ?><br />
170
+ <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 ); ?>" />
171
+ </label>
172
+ </p>
173
+ <p class="field-link-target description">
174
+ <label for="edit-menu-item-target-<?php echo $item_id; ?>">
175
+ <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' ); ?> />
176
+ <?php _e( 'Open link in a new tab', 'nav-menu-roles' ); ?>
177
+ </label>
178
+ </p>
179
+ <p class="field-css-classes description description-thin">
180
+ <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
181
+ <?php _e( 'CSS Classes (optional)', 'nav-menu-roles' ); ?><br />
182
+ <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 ) ); ?>" />
183
+ </label>
184
+ </p>
185
+ <p class="field-xfn description description-thin">
186
+ <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
187
+ <?php _e( 'Link Relationship (XFN)', 'nav-menu-roles' ); ?><br />
188
+ <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 ); ?>" />
189
+ </label>
190
+ </p>
191
+ <p class="field-description description description-wide">
192
+ <label for="edit-menu-item-description-<?php echo $item_id; ?>">
193
+ <?php _e( 'Description', 'nav-menu-roles' ); ?><br />
194
+ <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_escaped ?></textarea>
195
+ <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles'); ?></span>
196
+ </label>
197
+ </p>
198
+
199
+ <?php
200
+ // This is the added section
201
+ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
202
+ // end added section
203
+ ?>
204
+
205
+ <p class="field-move hide-if-no-js description description-wide">
206
+ <label>
207
+ <span><?php _e( 'Move', 'nav-menu-roles' ); ?></span>
208
+ <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one', 'nav-menu-roles' ); ?></a>
209
+ <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one', 'nav-menu-roles' ); ?></a>
210
+ <a href="#" class="menus-move menus-move-left" data-dir="left"></a>
211
+ <a href="#" class="menus-move menus-move-right" data-dir="right"></a>
212
+ <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top', 'nav-menu-roles' ); ?></a>
213
+ </label>
214
+ </p>
215
+
216
+ <div class="menu-item-actions description-wide submitbox">
217
+ <?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
218
+ <p class="link-to-original">
219
+ <?php printf( __('Original: %s', 'nav-menu-roles'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
220
+ </p>
221
+ <?php endif; ?>
222
+ <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
223
+ echo wp_nonce_url(
224
+ add_query_arg(
225
+ array(
226
+ 'action' => 'delete-menu-item',
227
+ 'menu-item' => $item_id,
228
+ ),
229
+ admin_url( 'nav-menus.php' )
230
+ ),
231
+ 'delete-menu_item_' . $item_id
232
+ ); ?>"><?php _e( 'Remove', 'nav-menu-roles' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
233
+ ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel', 'nav-menu-roles'); ?></a>
234
+ </div>
235
+
236
+ <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
237
+ <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 ); ?>" />
238
+ <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
239
+ <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 ); ?>" />
240
+ <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
241
+ <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
242
+ </div><!-- .menu-item-settings-->
243
+ <ul class="menu-item-transport"></ul>
244
+ <?php
245
+ $output .= ob_get_clean();
246
+ }
247
+
248
+ } // Walker_Nav_Menu_Edit
js/nav-menu-roles.js CHANGED
@@ -1,27 +1,27 @@
1
- ;(function($) {
2
-
3
- $('.nav_menu_logged_in_out_field').each(function(i){
4
-
5
- var $field = $(this);
6
-
7
- var id = $field.find('input.nav-menu-id').val();
8
-
9
- // if set to display by role (aka is null) then show the roles list, otherwise hide
10
- if( $field.find('input.nav-menu-logged-in-out:checked').val() === 'in' ){
11
- $field.next('.nav_menu_role_field').show();
12
- } else {
13
- $field.next('.nav_menu_role_field').hide();
14
- }
15
- });
16
-
17
- // on in/out/role change, hide/show the roles
18
- $('#menu-to-edit').on('change', 'input.nav-menu-logged-in-out', function() {
19
- if( $(this).val() === 'in' ){
20
- $(this).parentsUntil('.nav_menu_logged_in_out').next('.nav_menu_role_field').slideDown();
21
- } else {
22
- $(this).parentsUntil('.nav_menu_logged_in_out').next('.nav_menu_role_field').slideUp();
23
- }
24
- });
25
-
26
-
27
  })(jQuery);
1
+ ;(function($) {
2
+
3
+ $('.nav_menu_logged_in_out_field').each(function(i){
4
+
5
+ var $field = $(this);
6
+
7
+ var id = $field.find('input.nav-menu-id').val();
8
+
9
+ // if set to display by role (aka is null) then show the roles list, otherwise hide
10
+ if( $field.find('input.nav-menu-logged-in-out:checked').val() === 'in' ){
11
+ $field.next('.nav_menu_role_field').show();
12
+ } else {
13
+ $field.next('.nav_menu_role_field').hide();
14
+ }
15
+ });
16
+
17
+ // on in/out/role change, hide/show the roles
18
+ $('#menu-to-edit').on('change', 'input.nav-menu-logged-in-out', function() {
19
+ if( $(this).val() === 'in' ){
20
+ $(this).parentsUntil('.nav_menu_logged_in_out').next('.nav_menu_role_field').slideDown();
21
+ } else {
22
+ $(this).parentsUntil('.nav_menu_logged_in_out').next('.nav_menu_role_field').slideUp();
23
+ }
24
+ });
25
+
26
+
27
  })(jQuery);
js/nav-menu-roles.min.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! nav-menu-roles 1.8.6 */
2
  !function(a){a(".nav_menu_logged_in_out_field").each(function(b){var c=a(this);c.find("input.nav-menu-id").val();"in"===c.find("input.nav-menu-logged-in-out:checked").val()?c.next(".nav_menu_role_field").show():c.next(".nav_menu_role_field").hide()}),a("#menu-to-edit").on("change","input.nav-menu-logged-in-out",function(){"in"===a(this).val()?a(this).parentsUntil(".nav_menu_logged_in_out").next(".nav_menu_role_field").slideDown():a(this).parentsUntil(".nav_menu_logged_in_out").next(".nav_menu_role_field").slideUp()})}(jQuery);
1
+ /*! nav-menu-roles 1.8.6 */
2
  !function(a){a(".nav_menu_logged_in_out_field").each(function(b){var c=a(this);c.find("input.nav-menu-id").val();"in"===c.find("input.nav-menu-logged-in-out:checked").val()?c.next(".nav_menu_role_field").show():c.next(".nav_menu_role_field").hide()}),a("#menu-to-edit").on("change","input.nav-menu-logged-in-out",function(){"in"===a(this).val()?a(this).parentsUntil(".nav_menu_logged_in_out").next(".nav_menu_role_field").slideDown():a(this).parentsUntil(".nav_menu_logged_in_out").next(".nav_menu_role_field").slideUp()})}(jQuery);
languages/nav-menu-roles.pot CHANGED
@@ -1,242 +1,242 @@
1
- # Copyright (C) 2016 Kathy Darling
2
- # This file is distributed under the GPL-3.0.
3
- msgid ""
4
- msgstr ""
5
- "Project-Id-Version: Nav Menu Roles 1.8.6\n"
6
- "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/nav-menu-roles\n"
7
- "POT-Creation-Date: 2016-12-08 18:08:13+00:00\n"
8
- "MIME-Version: 1.0\n"
9
- "Content-Type: text/plain; charset=utf-8\n"
10
- "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
12
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
- "Language-Team: LANGUAGE <LL@li.org>\n"
14
- "X-Generator: grunt-wp-i18n 0.5.4\n"
15
-
16
- #: inc/class.Nav_Menu_Roles_Import.php:106
17
- #: inc/class.Nav_Menu_Roles_Import.php:115
18
- #: inc/class.Nav_Menu_Roles_Import.php:161
19
- #: inc/class.Nav_Menu_Roles_Import.php:165
20
- #: inc/class.Nav_Menu_Roles_Import.php:174
21
- msgid "Sorry, there has been an error."
22
- msgstr ""
23
-
24
- #: inc/class.Nav_Menu_Roles_Import.php:107
25
- msgid "The file does not exist, please try again."
26
- msgstr ""
27
-
28
- #: inc/class.Nav_Menu_Roles_Import.php:146
29
- msgid "All done."
30
- msgstr ""
31
-
32
- #: inc/class.Nav_Menu_Roles_Import.php:146
33
- msgid "Have fun!"
34
- msgstr ""
35
-
36
- #: inc/class.Nav_Menu_Roles_Import.php:166
37
- msgid ""
38
- "The export file could not be found at <code>%s</code>. It is likely that "
39
- "this was caused by a permissions problem."
40
- msgstr ""
41
-
42
- #: inc/class.Nav_Menu_Roles_Import.php:182
43
- msgid ""
44
- "This WXR file (version %s) may not be supported by this version of the "
45
- "importer. Please consider updating."
46
- msgstr ""
47
-
48
- #: inc/class.Nav_Menu_Roles_Import.php:249
49
- msgid "Import Nav Menu Roles"
50
- msgstr ""
51
-
52
- #: inc/class.Nav_Menu_Roles_Import.php:256
53
- msgid ""
54
- "A new version of this importer is available. Please update to version %s to "
55
- "ensure compatibility with newer export files."
56
- msgstr ""
57
-
58
- #: inc/class.Nav_Menu_Roles_Import.php:271
59
- msgid ""
60
- "Re-Upload your normal WordPress eXtended RSS (WXR) file and we&#8217;ll "
61
- "import the Nav Menu Roles and any other missing post meta for the Nav Menu "
62
- "items."
63
- msgstr ""
64
-
65
- #: inc/class.Nav_Menu_Roles_Import.php:272
66
- msgid "Choose a WXR (.xml) file to upload, then click Upload file and import."
67
- msgstr ""
68
-
69
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:95
70
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:98
71
- #. translators: %s: title of menu item which is invalid
72
- msgid "%s (Invalid)"
73
- msgstr ""
74
-
75
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:99
76
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:102
77
- #. translators: %s: title of menu item in draft status
78
- msgid "%s (Pending)"
79
- msgstr ""
80
-
81
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:112
82
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:115
83
- msgid "sub item"
84
- msgstr ""
85
-
86
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:127
87
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:130
88
- msgid "Move up"
89
- msgstr ""
90
-
91
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:140
92
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:143
93
- msgid "Move down"
94
- msgstr ""
95
-
96
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:142
97
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:144
98
- msgid "Edit Menu Item"
99
- msgstr ""
100
-
101
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:153
102
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:156
103
- msgid "URL"
104
- msgstr ""
105
-
106
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:160
107
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:163
108
- msgid "Navigation Label"
109
- msgstr ""
110
-
111
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:166
112
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:169
113
- msgid "Title Attribute"
114
- msgstr ""
115
-
116
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:173
117
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:176
118
- msgid "Open link in a new tab"
119
- msgstr ""
120
-
121
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:178
122
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:181
123
- msgid "CSS Classes (optional)"
124
- msgstr ""
125
-
126
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:184
127
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:187
128
- msgid "Link Relationship (XFN)"
129
- msgstr ""
130
-
131
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:190
132
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:193
133
- msgid "Description"
134
- msgstr ""
135
-
136
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:192
137
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:195
138
- msgid ""
139
- "The description will be displayed in the menu if the current theme supports "
140
- "it."
141
- msgstr ""
142
-
143
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:204
144
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:207
145
- msgid "Move"
146
- msgstr ""
147
-
148
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:205
149
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:208
150
- msgid "Up one"
151
- msgstr ""
152
-
153
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:206
154
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:209
155
- msgid "Down one"
156
- msgstr ""
157
-
158
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:209
159
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:212
160
- msgid "To the top"
161
- msgstr ""
162
-
163
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:216
164
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:219
165
- msgid "Original: %s"
166
- msgstr ""
167
-
168
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:229
169
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:232
170
- msgid "Remove"
171
- msgstr ""
172
-
173
- #: inc/class.Walker_Nav_Menu_Edit_Roles.php:230
174
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:233
175
- msgid "Cancel"
176
- msgstr ""
177
-
178
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:147
179
- msgid "Edit menu item"
180
- msgstr ""
181
-
182
- #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:147
183
- msgid "Edit"
184
- msgstr ""
185
-
186
- #: nav-menu-roles.php:82 nav-menu-roles.php:91
187
- msgid "Cheatin&#8217; huh?"
188
- msgstr ""
189
-
190
- #. Plugin Name of the plugin/theme
191
- msgid "Nav Menu Roles"
192
- msgstr ""
193
-
194
- #: nav-menu-roles.php:166
195
- msgid ""
196
- "Import %snav menu roles%s and other menu item meta skipped by the default "
197
- "importer"
198
- msgstr ""
199
-
200
- #: nav-menu-roles.php:219
201
- msgid "FAQ"
202
- msgstr ""
203
-
204
- #: nav-menu-roles.php:220
205
- msgid "Donate"
206
- msgstr ""
207
-
208
- #: nav-menu-roles.php:299
209
- msgid "Display Mode"
210
- msgstr ""
211
-
212
- #: nav-menu-roles.php:307
213
- msgid "Logged In Users"
214
- msgstr ""
215
-
216
- #: nav-menu-roles.php:314
217
- msgid "Logged Out Users"
218
- msgstr ""
219
-
220
- #: nav-menu-roles.php:321
221
- msgid "Everyone"
222
- msgstr ""
223
-
224
- #: nav-menu-roles.php:328
225
- msgid "Restrict menu item to a minimum role"
226
- msgstr ""
227
-
228
- #. Plugin URI of the plugin/theme
229
- msgid "http://www.kathyisawesome.com/449/nav-menu-roles/"
230
- msgstr ""
231
-
232
- #. Description of the plugin/theme
233
- msgid "Hide custom menu items based on user roles."
234
- msgstr ""
235
-
236
- #. Author of the plugin/theme
237
- msgid "Kathy Darling"
238
- msgstr ""
239
-
240
- #. Author URI of the plugin/theme
241
- msgid "http://www.kathyisawesome.com"
242
  msgstr ""
1
+ # Copyright (C) 2016 Kathy Darling
2
+ # This file is distributed under the GPL-3.0.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Nav Menu Roles 1.8.6\n"
6
+ "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/nav-menu-roles\n"
7
+ "POT-Creation-Date: 2016-12-08 18:08:13+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=utf-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "X-Generator: grunt-wp-i18n 0.5.4\n"
15
+
16
+ #: inc/class.Nav_Menu_Roles_Import.php:106
17
+ #: inc/class.Nav_Menu_Roles_Import.php:115
18
+ #: inc/class.Nav_Menu_Roles_Import.php:161
19
+ #: inc/class.Nav_Menu_Roles_Import.php:165
20
+ #: inc/class.Nav_Menu_Roles_Import.php:174
21
+ msgid "Sorry, there has been an error."
22
+ msgstr ""
23
+
24
+ #: inc/class.Nav_Menu_Roles_Import.php:107
25
+ msgid "The file does not exist, please try again."
26
+ msgstr ""
27
+
28
+ #: inc/class.Nav_Menu_Roles_Import.php:146
29
+ msgid "All done."
30
+ msgstr ""
31
+
32
+ #: inc/class.Nav_Menu_Roles_Import.php:146
33
+ msgid "Have fun!"
34
+ msgstr ""
35
+
36
+ #: inc/class.Nav_Menu_Roles_Import.php:166
37
+ msgid ""
38
+ "The export file could not be found at <code>%s</code>. It is likely that "
39
+ "this was caused by a permissions problem."
40
+ msgstr ""
41
+
42
+ #: inc/class.Nav_Menu_Roles_Import.php:182
43
+ msgid ""
44
+ "This WXR file (version %s) may not be supported by this version of the "
45
+ "importer. Please consider updating."
46
+ msgstr ""
47
+
48
+ #: inc/class.Nav_Menu_Roles_Import.php:249
49
+ msgid "Import Nav Menu Roles"
50
+ msgstr ""
51
+
52
+ #: inc/class.Nav_Menu_Roles_Import.php:256
53
+ msgid ""
54
+ "A new version of this importer is available. Please update to version %s to "
55
+ "ensure compatibility with newer export files."
56
+ msgstr ""
57
+
58
+ #: inc/class.Nav_Menu_Roles_Import.php:271
59
+ msgid ""
60
+ "Re-Upload your normal WordPress eXtended RSS (WXR) file and we&#8217;ll "
61
+ "import the Nav Menu Roles and any other missing post meta for the Nav Menu "
62
+ "items."
63
+ msgstr ""
64
+
65
+ #: inc/class.Nav_Menu_Roles_Import.php:272
66
+ msgid "Choose a WXR (.xml) file to upload, then click Upload file and import."
67
+ msgstr ""
68
+
69
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:95
70
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:98
71
+ #. translators: %s: title of menu item which is invalid
72
+ msgid "%s (Invalid)"
73
+ msgstr ""
74
+
75
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:99
76
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:102
77
+ #. translators: %s: title of menu item in draft status
78
+ msgid "%s (Pending)"
79
+ msgstr ""
80
+
81
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:112
82
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:115
83
+ msgid "sub item"
84
+ msgstr ""
85
+
86
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:127
87
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:130
88
+ msgid "Move up"
89
+ msgstr ""
90
+
91
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:140
92
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:143
93
+ msgid "Move down"
94
+ msgstr ""
95
+
96
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:142
97
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:144
98
+ msgid "Edit Menu Item"
99
+ msgstr ""
100
+
101
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:153
102
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:156
103
+ msgid "URL"
104
+ msgstr ""
105
+
106
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:160
107
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:163
108
+ msgid "Navigation Label"
109
+ msgstr ""
110
+
111
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:166
112
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:169
113
+ msgid "Title Attribute"
114
+ msgstr ""
115
+
116
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:173
117
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:176
118
+ msgid "Open link in a new tab"
119
+ msgstr ""
120
+
121
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:178
122
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:181
123
+ msgid "CSS Classes (optional)"
124
+ msgstr ""
125
+
126
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:184
127
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:187
128
+ msgid "Link Relationship (XFN)"
129
+ msgstr ""
130
+
131
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:190
132
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:193
133
+ msgid "Description"
134
+ msgstr ""
135
+
136
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:192
137
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:195
138
+ msgid ""
139
+ "The description will be displayed in the menu if the current theme supports "
140
+ "it."
141
+ msgstr ""
142
+
143
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:204
144
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:207
145
+ msgid "Move"
146
+ msgstr ""
147
+
148
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:205
149
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:208
150
+ msgid "Up one"
151
+ msgstr ""
152
+
153
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:206
154
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:209
155
+ msgid "Down one"
156
+ msgstr ""
157
+
158
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:209
159
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:212
160
+ msgid "To the top"
161
+ msgstr ""
162
+
163
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:216
164
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:219
165
+ msgid "Original: %s"
166
+ msgstr ""
167
+
168
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:229
169
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:232
170
+ msgid "Remove"
171
+ msgstr ""
172
+
173
+ #: inc/class.Walker_Nav_Menu_Edit_Roles.php:230
174
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:233
175
+ msgid "Cancel"
176
+ msgstr ""
177
+
178
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:147
179
+ msgid "Edit menu item"
180
+ msgstr ""
181
+
182
+ #: inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php:147
183
+ msgid "Edit"
184
+ msgstr ""
185
+
186
+ #: nav-menu-roles.php:82 nav-menu-roles.php:91
187
+ msgid "Cheatin&#8217; huh?"
188
+ msgstr ""
189
+
190
+ #. Plugin Name of the plugin/theme
191
+ msgid "Nav Menu Roles"
192
+ msgstr ""
193
+
194
+ #: nav-menu-roles.php:166
195
+ msgid ""
196
+ "Import %snav menu roles%s and other menu item meta skipped by the default "
197
+ "importer"
198
+ msgstr ""
199
+
200
+ #: nav-menu-roles.php:219
201
+ msgid "FAQ"
202
+ msgstr ""
203
+
204
+ #: nav-menu-roles.php:220
205
+ msgid "Donate"
206
+ msgstr ""
207
+
208
+ #: nav-menu-roles.php:299
209
+ msgid "Display Mode"
210
+ msgstr ""
211
+
212
+ #: nav-menu-roles.php:307
213
+ msgid "Logged In Users"
214
+ msgstr ""
215
+
216
+ #: nav-menu-roles.php:314
217
+ msgid "Logged Out Users"
218
+ msgstr ""
219
+
220
+ #: nav-menu-roles.php:321
221
+ msgid "Everyone"
222
+ msgstr ""
223
+
224
+ #: nav-menu-roles.php:328
225
+ msgid "Restrict menu item to a minimum role"
226
+ msgstr ""
227
+
228
+ #. Plugin URI of the plugin/theme
229
+ msgid "http://www.kathyisawesome.com/449/nav-menu-roles/"
230
+ msgstr ""
231
+
232
+ #. Description of the plugin/theme
233
+ msgid "Hide custom menu items based on user roles."
234
+ msgstr ""
235
+
236
+ #. Author of the plugin/theme
237
+ msgid "Kathy Darling"
238
+ msgstr ""
239
+
240
+ #. Author URI of the plugin/theme
241
+ msgid "http://www.kathyisawesome.com"
242
  msgstr ""
nav-menu-roles.php CHANGED
@@ -1,521 +1,541 @@
1
- <?php
2
- /*
3
- Plugin Name: Nav Menu Roles
4
- Plugin URI: http://www.kathyisawesome.com/449/nav-menu-roles/
5
- Description: Hide custom menu items based on user roles.
6
- Version: 1.8.6
7
- Author: Kathy Darling
8
- Author URI: http://www.kathyisawesome.com
9
- License: GPL-3.0
10
- Text Domain: nav-menu-roles
11
-
12
- Copyright 2014 Kathy Darling(email: kathy.darling@gmail.com)
13
-
14
- This program is free software; you can redistribute it and/or modify
15
- it under the terms of the GNU General Public License, version 2, as
16
- published by the Free Software Foundation.
17
-
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
21
- GNU General Public License for more details.
22
-
23
- You should have received a copy of the GNU General Public License
24
- along with this program; if not, write to the Free Software
25
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA02110-1301USA
26
- */
27
-
28
-
29
- // don't load directly
30
- if ( ! function_exists( 'is_admin' ) ) {
31
- header( 'Status: 403 Forbidden' );
32
- header( 'HTTP/1.1 403 Forbidden' );
33
- exit();
34
- }
35
-
36
-
37
- if ( ! class_exists( "Nav_Menu_Roles" ) ) :
38
-
39
- class Nav_Menu_Roles {
40
-
41
- /**
42
- * @var Nav_Menu_Roles The single instance of the class
43
- * @since 1.5
44
- */
45
- protected static $_instance = null;
46
-
47
- /**
48
- * @constant string donate url
49
- * @since 1.5
50
- */
51
- CONST DONATE_URL = "https://inspirepay.com/pay/helgatheviking/10";
52
-
53
- /**
54
- * @constant string version number
55
- * @since 1.7.1
56
- */
57
- CONST VERSION = '1.8.6';
58
-
59
- /**
60
- * Main Nav Menu Roles Instance
61
- *
62
- * Ensures only one instance of Nav Menu Roles is loaded or can be loaded.
63
- *
64
- * @since 1.5
65
- * @static
66
- * @see Nav_Menu_Roles()
67
- * @return Nav_Menu_Roles - Main instance
68
- */
69
- public static function instance() {
70
- if ( is_null( self::$_instance ) ) {
71
- self::$_instance = new self();
72
- }
73
- return self::$_instance;
74
- }
75
-
76
- /**
77
- * Cloning is forbidden.
78
- *
79
- * @since 1.5
80
- */
81
- public function __clone() {
82
- _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' , 'nav-menu-roles'), '1.5' );
83
- }
84
-
85
- /**
86
- * Unserializing instances of this class is forbidden.
87
- *
88
- * @since 1.5
89
- */
90
- public function __wakeup() {
91
- _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' , 'nav-menu-roles'), '1.5' );
92
- }
93
-
94
- /**
95
- * Nav_Menu_Roles Constructor.
96
- * @access public
97
- * @return Nav_Menu_Roles
98
- * @since 1.0
99
- */
100
- public function __construct(){
101
-
102
- // Admin functions
103
- add_action( 'admin_init', array( $this, 'admin_init' ) );
104
-
105
- // load the textdomain
106
- add_action( 'plugins_loaded', array( $this, 'load_text_domain' ) );
107
-
108
- // add FAQ and Donate link to plugin
109
- add_filter( 'plugin_row_meta', array( $this, 'add_action_links' ), 10, 2 );
110
-
111
- // switch the admin walker
112
- add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
113
-
114
- // add new fields via hook
115
- add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'custom_fields' ), 10, 4 );
116
-
117
- // add some JS
118
- add_action( 'admin_enqueue_scripts' , array( $this, 'enqueue_scripts' ) );
119
-
120
- // save the menu item meta
121
- add_action( 'wp_update_nav_menu_item', array( $this, 'nav_update'), 10, 2 );
122
-
123
- // add meta to menu item
124
- add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_nav_item' ) );
125
-
126
- // exclude items via filter instead of via custom Walker
127
- if ( ! is_admin() ) {
128
- $priority = 20; // Because WP_Customize_Nav_Menu_Item_Setting::filter_wp_get_nav_menu_items() runs at 10.
129
- add_filter( 'wp_get_nav_menu_items', array( $this, 'exclude_menu_items' ), $priority );
130
- }
131
-
132
- // upgrade routine
133
- add_action( 'plugins_loaded', array( $this, 'maybe_upgrade' ) );
134
-
135
- }
136
-
137
- /**
138
- * Include the custom admin walker
139
- *
140
- * @access public
141
- * @return void
142
- */
143
- public function admin_init() {
144
-
145
- // Register Importer
146
- $this->register_importer();
147
-
148
- }
149
-
150
-
151
- /**
152
- * Register the Importer
153
- * the regular Importer skips post meta for the menu items
154
- *
155
- * @access private
156
- * @return void
157
- */
158
- public function register_importer(){
159
- // Register the new importer
160
- if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
161
-
162
- include_once( plugin_dir_path( __FILE__ ) . 'inc/class.Nav_Menu_Roles_Import.php');
163
- // Register the custom importer we've created.
164
- $roles_import = new Nav_Menu_Roles_Import();
165
-
166
- register_importer('nav_menu_roles', __('Nav Menu Roles', 'nav-menu-roles'), sprintf( __('Import %snav menu roles%s and other menu item meta skipped by the default importer', 'nav-menu-roles'), '<strong>', '</strong>'), array( $roles_import, 'dispatch' ) );
167
-
168
- }
169
-
170
- }
171
-
172
- /**
173
- * Make Plugin Translation-ready
174
- * CALLBACK FUNCTION FOR: add_action( 'plugins_loaded', array( $this,'load_text_domain'));
175
- * @since 1.0
176
- */
177
-
178
- public function load_text_domain() {
179
- load_plugin_textdomain( 'nav-menu-roles', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
180
- }
181
-
182
-
183
- /**
184
- * Display a Notice if plugin conflicts with another
185
- * @since 1.5
186
- * @deprecated will removed in 2.0
187
- */
188
- public function admin_notice() {
189
- _deprecated_function( __METHOD__, '1.7.8' );
190
- }
191
-
192
-
193
- /**
194
- * Allow the notice to be dismissable
195
- * @since 1.6
196
- * @deprecated will removed in 2.0
197
- */
198
- public function nag_ignore() {
199
- _deprecated_function( __METHOD__, '1.7.8' );
200
- }
201
-
202
- /**
203
- * Delete the transient when a plugin is activated or deactivated
204
- * @since 1.5
205
- * @deprecated will removed in 2.0
206
- */
207
- public function delete_transient() {
208
- _deprecated_function( __METHOD__, '1.7.8' );
209
- delete_transient( 'nav_menu_roles_conflicts' );
210
- }
211
-
212
-
213
- /**
214
- * Add docu link
215
- * @since 1.7.3
216
- */
217
- public function add_action_links( $plugin_meta, $plugin_file ) {
218
- if( $plugin_file == plugin_basename(__FILE__) ){
219
- $plugin_meta[] = sprintf( '<a class="dashicons-before dashicons-welcome-learn-more" href="https://wordpress.org/plugins/nav-menu-roles/faq/#conflict">%s</a>', __( 'FAQ', 'nav-menu-roles' ) );
220
- $plugin_meta[] = '<a class="dashicons-before dashicons-awards" href="' . self::DONATE_URL . '" target="_blank">' . __( 'Donate', 'nav-menu-roles' ) . '</a>';
221
- }
222
- return $plugin_meta;
223
- }
224
-
225
-
226
- /**
227
- * Override the Admin Menu Walker
228
- * @since 1.0
229
- */
230
- public function edit_nav_menu_walker( $walker ) {
231
- if( ! class_exists( 'Walker_Nav_Menu_Edit_Roles' ) ){
232
- global $wp_version;
233
- if ( version_compare( $wp_version, '4.7', '>=' ) ){
234
- require_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles_4.7.php');
235
- } else if ( version_compare( $wp_version, '4.5', '>=' ) ){
236
- require_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php');
237
- } else {
238
- require_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles.php');
239
- }
240
- }
241
- return 'Walker_Nav_Menu_Edit_Roles';
242
- }
243
-
244
-
245
- /**
246
- * Add fields to hook added in Walker
247
- * This will allow us to play nicely with any other plugin that is adding the same hook
248
- * @params obj $item - the menu item
249
- * @params array $args
250
- * @since 1.6.0
251
- */
252
- public function custom_fields( $item_id, $item, $depth, $args ) {
253
- global $wp_roles;
254
-
255
- /**
256
- * Pass the menu item to the filter function.
257
- * This change is suggested as it allows the use of information from the menu item (and
258
- * by extension the target object) to further customize what filters appear during menu
259
- * construction.
260
- */
261
- $display_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names, $item );
262
-
263
-
264
- /**
265
- * If no roles are being used, don't display the role selection radio buttons at all.
266
- * Unless something deliberately removes the WordPress roles from this list, nothing will
267
- * be functionally altered to the end user.
268
- * This change is suggested for the benefit of users constructing granular admin permissions
269
- * using extensive custom roles as it is an effective means of stopping admins with partial
270
- * permissions to the menu from accidentally removing all restrictions from a menu item to
271
- * which they do not have access.
272
- */
273
- if( ! $display_roles ) return;
274
-
275
- /* Get the roles saved for the post. */
276
- $roles = get_post_meta( $item->ID, '_nav_menu_role', true );
277
-
278
- // by default nothing is checked (will match "everyone" radio)
279
- $logged_in_out = '';
280
-
281
- // specific roles are saved as an array, so "in" or an array equals "in" is checked
282
- if( is_array( $roles ) || $roles == 'in' ){
283
- $logged_in_out = 'in';
284
- } else if ( $roles == 'out' ){
285
- $logged_in_out = 'out';
286
- }
287
-
288
- // the specific roles to check
289
- $checked_roles = is_array( $roles ) ? $roles : false;
290
-
291
- // whether to display the role checkboxes
292
- $hidden = $logged_in_out == 'in' ? '' : 'display: none;';
293
-
294
- ?>
295
-
296
- <input type="hidden" name="nav-menu-role-nonce" value="<?php echo wp_create_nonce( 'nav-menu-nonce-name' ); ?>" />
297
-
298
- <div class="field-nav_menu_role nav_menu_logged_in_out_field description-wide" style="margin: 5px 0;">
299
- <span class="description"><?php _e( "Display Mode", 'nav-menu-roles' ); ?></span>
300
- <br />
301
-
302
- <input type="hidden" class="nav-menu-id" value="<?php echo $item->ID ;?>" />
303
-
304
- <div class="logged-input-holder" style="float: left; width: 35%;">
305
- <input type="radio" class="nav-menu-logged-in-out" name="nav-menu-logged-in-out[<?php echo $item->ID ;?>]" id="nav_menu_logged_in-for-<?php echo $item->ID ;?>" <?php checked( 'in', $logged_in_out ); ?> value="in" />
306
- <label for="nav_menu_logged_in-for-<?php echo $item->ID ;?>">
307
- <?php _e( 'Logged In Users', 'nav-menu-roles'); ?>
308
- </label>
309
- </div>
310
-
311
- <div class="logged-input-holder" style="float: left; width: 35%;">
312
- <input type="radio" class="nav-menu-logged-in-out" name="nav-menu-logged-in-out[<?php echo $item->ID ;?>]" id="nav_menu_logged_out-for-<?php echo $item->ID ;?>" <?php checked( 'out', $logged_in_out ); ?> value="out" />
313
- <label for="nav_menu_logged_out-for-<?php echo $item->ID ;?>">
314
- <?php _e( 'Logged Out Users', 'nav-menu-roles'); ?>
315
- </label>
316
- </div>
317
-
318
- <div class="logged-input-holder" style="float: left; width: 30%;">
319
- <input type="radio" class="nav-menu-logged-in-out" name="nav-menu-logged-in-out[<?php echo $item->ID ;?>]" id="nav_menu_by_role-for-<?php echo $item->ID ;?>" <?php checked( '', $logged_in_out ); ?> value="" />
320
- <label for="nav_menu_by_role-for-<?php echo $item->ID ;?>">
321
- <?php _e( 'Everyone', 'nav-menu-roles'); ?>
322
- </label>
323
- </div>
324
-
325
- </div>
326
-
327
- <div class="field-nav_menu_role nav_menu_role_field description-wide" style="margin: 5px 0; <?php echo $hidden;?>">
328
- <span class="description"><?php _e( "Restrict menu item to a minimum role", 'nav-menu-roles' ); ?></span>
329
- <br />
330
-
331
- <?php
332
-
333
- $i = 1;
334
-
335
- /* Loop through each of the available roles. */
336
- foreach ( $display_roles as $role => $name ) {
337
-
338
- /* If the role has been selected, make sure it's checked. */
339
- $checked = checked( true, ( is_array( $checked_roles ) && in_array( $role, $checked_roles ) ), false );
340
-
341
- ?>
342
-
343
- <div class="role-input-holder" style="float: left; width: 33.3%; margin: 2px 0;">
344
- <input type="checkbox" name="nav-menu-role[<?php echo $item->ID ;?>][<?php echo $i; ?>]" id="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>" <?php echo $checked; ?> value="<?php echo $role; ?>" />
345
- <label for="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>">
346
- <?php echo esc_html( $name ); ?>
347
- <?php $i++; ?>
348
- </label>
349
- </div>
350
-
351
- <?php } ?>
352
-
353
- </div>
354
-
355
- <?php
356
- }
357
-
358
-
359
- /**
360
- * Save the roles as menu item meta
361
- * @return null
362
- * @since 1.4
363
- *
364
- */
365
- public function enqueue_scripts( $hook ){
366
- if ( $hook == 'nav-menus.php' ){
367
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
368
- wp_enqueue_script( 'nav-menu-roles', plugins_url( 'js/nav-menu-roles' . $suffix . '.js' , __FILE__ ), array( 'jquery' ), self::VERSION, true );
369
- }
370
- }
371
-
372
- /**
373
- * Save the roles as menu item meta
374
- * @return string
375
- * @since 1.0
376
- */
377
- public function nav_update( $menu_id, $menu_item_db_id ) {
378
- global $wp_roles;
379
-
380
- $allowed_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names );
381
-
382
- // verify this came from our screen and with proper authorization.
383
- if ( ! isset( $_POST['nav-menu-role-nonce'] ) || ! wp_verify_nonce( $_POST['nav-menu-role-nonce'], 'nav-menu-nonce-name' ) ){
384
- return;
385
- }
386
-
387
- $saved_data = false;
388
-
389
- if ( isset( $_POST['nav-menu-logged-in-out'][$menu_item_db_id] ) && $_POST['nav-menu-logged-in-out'][$menu_item_db_id] == 'in' && ! empty ( $_POST['nav-menu-role'][$menu_item_db_id] ) ) {
390
-
391
- $custom_roles = array();
392
-
393
- // only save allowed roles
394
- foreach( (array) $_POST['nav-menu-role'][$menu_item_db_id] as $role ) {
395
- if ( array_key_exists ( $role, $allowed_roles ) ) {
396
- $custom_roles[] = $role;
397
- }
398
- }
399
- if ( ! empty ( $custom_roles ) ) {
400
- $saved_data = $custom_roles;
401
- }
402
- } else if ( isset( $_POST['nav-menu-logged-in-out'][$menu_item_db_id] ) && in_array( $_POST['nav-menu-logged-in-out'][$menu_item_db_id], array( 'in', 'out' ) ) ) {
403
- $saved_data = $_POST['nav-menu-logged-in-out'][$menu_item_db_id];
404
- }
405
-
406
- if ( $saved_data ) {
407
- update_post_meta( $menu_item_db_id, '_nav_menu_role', $saved_data );
408
- } else {
409
- delete_post_meta( $menu_item_db_id, '_nav_menu_role' );
410
- }
411
- }
412
-
413
- /**
414
- * Adds value of new field to $item object
415
- * is be passed to Walker_Nav_Menu_Edit_Custom
416
- * @since 1.0
417
- */
418
- public function setup_nav_item( $menu_item ) {
419
-
420
- $roles = get_post_meta( $menu_item->ID, '_nav_menu_role', true );
421
-
422
- if ( ! empty( $roles ) ) {
423
- $menu_item->roles = $roles;
424
- }
425
- return $menu_item;
426
- }
427
-
428
- /**
429
- * Exclude menu items via wp_get_nav_menu_items filter
430
- * this fixes plugin's incompatibility with theme's that use their own custom Walker
431
- * Thanks to Evan Stein @vanpop http://vanpop.com/
432
- * @since 1.2
433
- */
434
- public function exclude_menu_items( $items ) {
435
-
436
- $hide_children_of = array();
437
-
438
- // Iterate over the items to search and destroy
439
- foreach ( $items as $key => $item ) {
440
-
441
- $visible = true;
442
-
443
- // hide any item that is the child of a hidden item
444
- if( in_array( $item->menu_item_parent, $hide_children_of ) ){
445
- $visible = false;
446
- $hide_children_of[] = $item->ID; // for nested menus
447
- }
448
-
449
- // check any item that has NMR roles set
450
- if( $visible && isset( $item->roles ) ) {
451
-
452
- // check all logged in, all logged out, or role
453
- switch( $item->roles ) {
454
- case 'in' :
455
- $visible = is_user_logged_in() ? true : false;
456
- break;
457
- case 'out' :
458
- $visible = ! is_user_logged_in() ? true : false;
459
- break;
460
- default:
461
- $visible = false;
462
- if ( is_array( $item->roles ) && ! empty( $item->roles ) ) {
463
- foreach ( $item->roles as $role ) {
464
- if ( current_user_can( $role ) )
465
- $visible = true;
466
- }
467
- }
468
-
469
- break;
470
- }
471
-
472
- }
473
-
474
- // add filter to work with plugins that don't use traditional roles
475
- $visible = apply_filters( 'nav_menu_roles_item_visibility', $visible, $item );
476
-
477
- // unset non-visible item
478
- if ( ! $visible ) {
479
- $hide_children_of[] = $item->ID; // store ID of item
480
- unset( $items[$key] ) ;
481
- }
482
-
483
- }
484
-
485
- return $items;
486
- }
487
-
488
-
489
- /**
490
- * Maybe upgrade
491
- *
492
- * @access public
493
- * @return void
494
- */
495
- public function maybe_upgrade() {
496
- $db_version = get_option( 'nav_menu_roles_db_version', false );
497
-
498
- // 1.7.7 upgrade: changed the debug notice so the old transient is invalid
499
- if ( $db_version === false || version_compare( '1.7.7', $db_version, '<' ) ) {
500
- update_option( 'nav_menu_roles_db_version', self::VERSION );
501
- }
502
- }
503
-
504
- } // end class
505
-
506
- endif; // class_exists check
507
-
508
-
509
- /**
510
- * Launch the whole plugin
511
- * Returns the main instance of Nav Menu Roles to prevent the need to use globals.
512
- *
513
- * @since 1.5
514
- * @return Nav_Menu_Roles
515
- */
516
- function Nav_Menu_Roles() {
517
- return Nav_Menu_Roles::instance();
518
- }
519
-
520
- // Global for backwards compatibility.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
  $GLOBALS['Nav_Menu_Roles'] = Nav_Menu_Roles();
1
+ <?php
2
+ /*
3
+ Plugin Name: Nav Menu Roles
4
+ Plugin URI: http://www.kathyisawesome.com/449/nav-menu-roles/
5
+ Description: Hide custom menu items based on user roles.
6
+ Version: 1.9.1
7
+ Author: Kathy Darling
8
+ Author URI: http://www.kathyisawesome.com
9
+ License: GPL-3.0
10
+ Text Domain: nav-menu-roles
11
+
12
+ Copyright 2014 Kathy Darling(email: kathy.darling@gmail.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License, version 2, as
16
+ published by the Free Software Foundation.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA02110-1301USA
26
+ */
27
+
28
+
29
+ // don't load directly
30
+ if ( ! function_exists( 'is_admin' ) ) {
31
+ header( 'Status: 403 Forbidden' );
32
+ header( 'HTTP/1.1 403 Forbidden' );
33
+ exit();
34
+ }
35
+
36
+
37
+ if ( ! class_exists( "Nav_Menu_Roles" ) ) :
38
+
39
+ class Nav_Menu_Roles {
40
+
41
+ /**
42
+ * @var Nav_Menu_Roles The single instance of the class
43
+ * @since 1.5
44
+ */
45
+ protected static $_instance = null;
46
+
47
+ /**
48
+ * @constant string donate url
49
+ * @since 1.5
50
+ */
51
+ CONST DONATE_URL = "https://paypal.me/kathyisawesome/20";
52
+
53
+ /**
54
+ * @constant string version number
55
+ * @since 1.7.0
56
+ */
57
+ CONST VERSION = '1.9.1';
58
+
59
+ /**
60
+ * Main Nav Menu Roles Instance
61
+ *
62
+ * Ensures only one instance of Nav Menu Roles is loaded or can be loaded.
63
+ *
64
+ * @since 1.5
65
+ * @static
66
+ * @see Nav_Menu_Roles()
67
+ * @return Nav_Menu_Roles - Main instance
68
+ */
69
+ public static function instance() {
70
+ if ( is_null( self::$_instance ) ) {
71
+ self::$_instance = new self();
72
+ }
73
+ return self::$_instance;
74
+ }
75
+
76
+ /**
77
+ * Cloning is forbidden.
78
+ *
79
+ * @since 1.5
80
+ */
81
+ public function __clone() {
82
+ _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' , 'nav-menu-roles'), '1.5' );
83
+ }
84
+
85
+ /**
86
+ * Unserializing instances of this class is forbidden.
87
+ *
88
+ * @since 1.5
89
+ */
90
+ public function __wakeup() {
91
+ _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' , 'nav-menu-roles'), '1.5' );
92
+ }
93
+
94
+ /**
95
+ * Nav_Menu_Roles Constructor.
96
+ * @access public
97
+ * @return Nav_Menu_Roles
98
+ * @since 1.0
99
+ */
100
+ public function __construct(){
101
+
102
+ // Admin functions
103
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
104
+
105
+ // load the textdomain
106
+ add_action( 'init', array( $this, 'load_text_domain' ) );
107
+
108
+ // add FAQ and Donate link to plugin
109
+ add_filter( 'plugin_row_meta', array( $this, 'add_action_links' ), 10, 2 );
110
+
111
+ // switch the admin walker
112
+ add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
113
+
114
+ // add new fields via hook
115
+ add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'custom_fields' ), 10, 4 );
116
+
117
+ // add some JS
118
+ add_action( 'admin_enqueue_scripts' , array( $this, 'enqueue_scripts' ) );
119
+
120
+ // save the menu item meta
121
+ add_action( 'wp_update_nav_menu_item', array( $this, 'nav_update'), 10, 2 );
122
+
123
+ // add meta to menu item
124
+ add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_nav_item' ) );
125
+