Nav Menu Roles - Version 1.7.4

Version Description

  • Change language in metabox to try to explain min caps versus strict role checking
  • keep tweaking the FAQ
Download this release

Release Info

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

Code changes from version 1.7.3 to 1.7.4

inc/class.Nav_Menu_Roles_Import.php CHANGED
@@ -1,309 +1,309 @@
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
- screen_icon();
250
- echo '<h2>' . __( 'Import Nav Menu Roles', 'nav-menu-roles' ) . '</h2>';
251
-
252
- $updates = get_plugin_updates();
253
- $basename = plugin_basename(__FILE__);
254
- if ( isset( $updates[$basename] ) ) {
255
- $update = $updates[$basename];
256
- echo '<div class="error"><p><strong>';
257
- 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 );
258
- echo '</strong></p></div>';
259
- }
260
- }
261
-
262
- // Close div.wrap
263
- function footer() {
264
- echo '</div>';
265
- }
266
-
267
- /**
268
- * Display introductory text and file upload form
269
- */
270
- function greet() {
271
- echo '<div class="narrow">';
272
- 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>';
273
- echo '<p>'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'nav-menu-roles' ).'</p>';
274
- wp_import_upload_form( 'admin.php?import=nav_menu_roles&amp;step=1' );
275
- echo '</div>';
276
- }
277
-
278
- /**
279
- * Decide if the given meta key maps to information we will want to import
280
- *
281
- * @param string $key The meta key to check
282
- * @return string|bool The key if we do want to import, false if not
283
- */
284
- function is_valid_meta_key( $key ) {
285
- // skip attachment metadata since we'll regenerate it from scratch
286
- // skip _edit_lock as not relevant for import
287
- if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) )
288
- return false;
289
- return $key;
290
- }
291
-
292
-
293
- /**
294
- * Added to http_request_timeout filter to force timeout at 60 seconds during import
295
- * @param int $val
296
- * @return int
297
- */
298
- public function bump_request_timeout( $val ) {
299
- return 60;
300
- }
301
-
302
- // return the difference in length between two strings
303
- function cmpr_strlen( $a, $b ) {
304
- return strlen($b) - strlen($a);
305
- }
306
-
307
-
308
- } // end class
309
  } // 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
+ screen_icon();
250
+ echo '<h2>' . __( 'Import Nav Menu Roles', 'nav-menu-roles' ) . '</h2>';
251
+
252
+ $updates = get_plugin_updates();
253
+ $basename = plugin_basename(__FILE__);
254
+ if ( isset( $updates[$basename] ) ) {
255
+ $update = $updates[$basename];
256
+ echo '<div class="error"><p><strong>';
257
+ 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 );
258
+ echo '</strong></p></div>';
259
+ }
260
+ }
261
+
262
+ // Close div.wrap
263
+ function footer() {
264
+ echo '</div>';
265
+ }
266
+
267
+ /**
268
+ * Display introductory text and file upload form
269
+ */
270
+ function greet() {
271
+ echo '<div class="narrow">';
272
+ 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>';
273
+ echo '<p>'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'nav-menu-roles' ).'</p>';
274
+ wp_import_upload_form( 'admin.php?import=nav_menu_roles&amp;step=1' );
275
+ echo '</div>';
276
+ }
277
+
278
+ /**
279
+ * Decide if the given meta key maps to information we will want to import
280
+ *
281
+ * @param string $key The meta key to check
282
+ * @return string|bool The key if we do want to import, false if not
283
+ */
284
+ function is_valid_meta_key( $key ) {
285
+ // skip attachment metadata since we'll regenerate it from scratch
286
+ // skip _edit_lock as not relevant for import
287
+ if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) )
288
+ return false;
289
+ return $key;
290
+ }
291
+
292
+
293
+ /**
294
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
295
+ * @param int $val
296
+ * @return int
297
+ */
298
+ public function bump_request_timeout( $val ) {
299
+ return 60;
300
+ }
301
+
302
+ // return the difference in length between two strings
303
+ function cmpr_strlen( $a, $b ) {
304
+ return strlen($b) - strlen($a);
305
+ }
306
+
307
+
308
+ } // end class
309
  } // end if
inc/class.Walker_Nav_Menu_Edit_Roles.php CHANGED
@@ -1,237 +1,237 @@
1
- <?php
2
-
3
- /**
4
- * Create HTML list of nav menu input items.
5
- * Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/nav-menu.php
6
- *
7
- * @package nav-menu-roles
8
- * @since 1.0
9
- * @uses Walker_Nav_Menu
10
- */
11
-
12
- class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
13
- /**
14
- * Starts the list before the elements are added.
15
- *
16
- * @see Walker_Nav_Menu::start_lvl()
17
- *
18
- * @since 3.0.0
19
- *
20
- * @param string $output Passed by reference.
21
- * @param int $depth Depth of menu item. Used for padding.
22
- * @param array $args Not used.
23
- */
24
- function start_lvl( &$output, $depth = 0, $args = array() ) {}
25
-
26
- /**
27
- * Ends the list of after the elements are added.
28
- *
29
- * @see Walker_Nav_Menu::end_lvl()
30
- *
31
- * @since 3.0.0
32
- *
33
- * @param string $output Passed by reference.
34
- * @param int $depth Depth of menu item. Used for padding.
35
- * @param array $args Not used.
36
- */
37
- function end_lvl( &$output, $depth = 0, $args = array() ) {}
38
-
39
- /**
40
- * Start the element output.
41
- *
42
- * @see Walker_Nav_Menu::start_el()
43
- * @since 3.0.0
44
- *
45
- * @param string $output Passed by reference. Used to append additional content.
46
- * @param object $item Menu item data object.
47
- * @param int $depth Depth of menu item. Used for padding.
48
- * @param array $args Not used.
49
- * @param int $id Not used.
50
- */
51
- function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
52
- global $_wp_nav_menu_max_depth;
53
- $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
54
-
55
- ob_start();
56
- $item_id = esc_attr( $item->ID );
57
- $removed_args = array(
58
- 'action',
59
- 'customlink-tab',
60
- 'edit-menu-item',
61
- 'menu-item',
62
- 'page-tab',
63
- '_wpnonce',
64
- );
65
-
66
- $original_title = '';
67
- if ( 'taxonomy' == $item->type ) {
68
- $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
69
- if ( is_wp_error( $original_title ) )
70
- $original_title = false;
71
- } elseif ( 'post_type' == $item->type ) {
72
- $original_object = get_post( $item->object_id );
73
- $original_title = get_the_title( $original_object->ID );
74
- }
75
-
76
- $classes = array(
77
- 'menu-item menu-item-depth-' . $depth,
78
- 'menu-item-' . esc_attr( $item->object ),
79
- 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
80
- );
81
-
82
- $title = $item->title;
83
-
84
- if ( ! empty( $item->_invalid ) ) {
85
- $classes[] = 'menu-item-invalid';
86
- /* translators: %s: title of menu item which is invalid */
87
- $title = sprintf( __( '%s (Invalid)' , 'nav-menu-roles' ), $item->title );
88
- } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
89
- $classes[] = 'pending';
90
- /* translators: %s: title of menu item in draft status */
91
- $title = sprintf( __('%s (Pending)', 'nav-menu-roles' ), $item->title );
92
- }
93
-
94
- $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
95
-
96
- $submenu_text = '';
97
- if ( 0 == $depth )
98
- $submenu_text = 'style="display: none;"';
99
-
100
- ?>
101
- <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
102
- <dl class="menu-item-bar">
103
- <dt class="menu-item-handle">
104
- <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>
105
- <span class="item-controls">
106
- <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
107
- <span class="item-order hide-if-js">
108
- <a href="<?php
109
- echo wp_nonce_url(
110
- add_query_arg(
111
- array(
112
- 'action' => 'move-up-menu-item',
113
- 'menu-item' => $item_id,
114
- ),
115
- remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
116
- ),
117
- 'move-menu_item'
118
- );
119
- ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up', 'nav-menu-roles' ); ?>">&#8593;</abbr></a>
120
- |
121
- <a href="<?php
122
- echo wp_nonce_url(
123
- add_query_arg(
124
- array(
125
- 'action' => 'move-down-menu-item',
126
- 'menu-item' => $item_id,
127
- ),
128
- remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
129
- ),
130
- 'move-menu_item'
131
- );
132
- ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down', 'nav-menu-roles' ); ?>">&#8595;</abbr></a>
133
- </span>
134
- <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item', 'nav-menu-roles' ); ?>" href="<?php
135
- 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 ) ) );
136
- ?>"><?php _e( 'Edit Menu Item' , 'nav-menu-roles' ); ?></a>
137
- </span>
138
- </dt>
139
- </dl>
140
-
141
- <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
142
- <?php if( 'custom' == $item->type ) : ?>
143
- <p class="field-url description description-wide">
144
- <label for="edit-menu-item-url-<?php echo $item_id; ?>">
145
- <?php _e( 'URL' , 'nav-menu-roles' ); ?><br />
146
- <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 ); ?>" />
147
- </label>
148
- </p>
149
- <?php endif; ?>
150
- <p class="description description-thin">
151
- <label for="edit-menu-item-title-<?php echo $item_id; ?>">
152
- <?php _e( 'Navigation Label' , 'nav-menu-roles' ); ?><br />
153
- <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 ); ?>" />
154
- </label>
155
- </p>
156
- <p class="description description-thin">
157
- <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
158
- <?php _e( 'Title Attribute' , 'nav-menu-roles' ); ?><br />
159
- <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 ); ?>" />
160
- </label>
161
- </p>
162
- <p class="field-link-target description">
163
- <label for="edit-menu-item-target-<?php echo $item_id; ?>">
164
- <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' ); ?> />
165
- <?php _e( 'Open link in a new window/tab' , 'nav-menu-roles' ); ?>
166
- </label>
167
- </p>
168
- <p class="field-css-classes description description-thin">
169
- <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
170
- <?php _e( 'CSS Classes (optional)' , 'nav-menu-roles' ); ?><br />
171
- <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 ) ); ?>" />
172
- </label>
173
- </p>
174
- <p class="field-xfn description description-thin">
175
- <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
176
- <?php _e( 'Link Relationship (XFN)' , 'nav-menu-roles' ); ?><br />
177
- <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 ); ?>" />
178
- </label>
179
- </p>
180
- <p class="field-description description description-wide">
181
- <label for="edit-menu-item-description-<?php echo $item_id; ?>">
182
- <?php _e( 'Description' , 'nav-menu-roles' ); ?><br />
183
- <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>
184
- <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles' ); ?></span>
185
- </label>
186
- </p>
187
-
188
- <?php
189
- // This is the added section
190
- do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
191
- // end added section
192
- ?>
193
-
194
- <p class="field-move hide-if-no-js description description-wide">
195
- <label>
196
- <span><?php _e( 'Move' , 'nav-menu-roles' ); ?></span>
197
- <a href="#" class="menus-move-up"><?php _e( 'Up one' , 'nav-menu-roles' ); ?></a>
198
- <a href="#" class="menus-move-down"><?php _e( 'Down one' , 'nav-menu-roles' ); ?></a>
199
- <a href="#" class="menus-move-left"></a>
200
- <a href="#" class="menus-move-right"></a>
201
- <a href="#" class="menus-move-top"><?php _e( 'To the top' , 'nav-menu-roles' ); ?></a>
202
- </label>
203
- </p>
204
-
205
- <div class="menu-item-actions description-wide submitbox">
206
- <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
207
- <p class="link-to-original">
208
- <?php printf( __('Original: %s', 'nav-menu-roles' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
209
- </p>
210
- <?php endif; ?>
211
- <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
212
- echo wp_nonce_url(
213
- add_query_arg(
214
- array(
215
- 'action' => 'delete-menu-item',
216
- 'menu-item' => $item_id,
217
- ),
218
- admin_url( 'nav-menus.php' )
219
- ),
220
- 'delete-menu_item_' . $item_id
221
- ); ?>"><?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' ) ) );
222
- ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel', 'nav-menu-roles' ); ?></a>
223
- </div>
224
-
225
- <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
226
- <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 ); ?>" />
227
- <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
228
- <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 ); ?>" />
229
- <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
230
- <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
231
- </div><!-- .menu-item-settings-->
232
- <ul class="menu-item-transport"></ul>
233
- <?php
234
- $output .= ob_get_clean();
235
- }
236
-
237
  } // Walker_Nav_Menu_Edit
1
+ <?php
2
+
3
+ /**
4
+ * Create HTML list of nav menu input items.
5
+ * Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/nav-menu.php
6
+ *
7
+ * @package nav-menu-roles
8
+ * @since 1.0
9
+ * @uses Walker_Nav_Menu
10
+ */
11
+
12
+ class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
13
+ /**
14
+ * Starts the list before the elements are added.
15
+ *
16
+ * @see Walker_Nav_Menu::start_lvl()
17
+ *
18
+ * @since 3.0.0
19
+ *
20
+ * @param string $output Passed by reference.
21
+ * @param int $depth Depth of menu item. Used for padding.
22
+ * @param array $args Not used.
23
+ */
24
+ function start_lvl( &$output, $depth = 0, $args = array() ) {}
25
+
26
+ /**
27
+ * Ends the list of after the elements are added.
28
+ *
29
+ * @see Walker_Nav_Menu::end_lvl()
30
+ *
31
+ * @since 3.0.0
32
+ *
33
+ * @param string $output Passed by reference.
34
+ * @param int $depth Depth of menu item. Used for padding.
35
+ * @param array $args Not used.
36
+ */
37
+ function end_lvl( &$output, $depth = 0, $args = array() ) {}
38
+
39
+ /**
40
+ * Start the element output.
41
+ *
42
+ * @see Walker_Nav_Menu::start_el()
43
+ * @since 3.0.0
44
+ *
45
+ * @param string $output Passed by reference. Used to append additional content.
46
+ * @param object $item Menu item data object.
47
+ * @param int $depth Depth of menu item. Used for padding.
48
+ * @param array $args Not used.
49
+ * @param int $id Not used.
50
+ */
51
+ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
52
+ global $_wp_nav_menu_max_depth;
53
+ $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
54
+
55
+ ob_start();
56
+ $item_id = esc_attr( $item->ID );
57
+ $removed_args = array(
58
+ 'action',
59
+ 'customlink-tab',
60
+ 'edit-menu-item',
61
+ 'menu-item',
62
+ 'page-tab',
63
+ '_wpnonce',
64
+ );
65
+
66
+ $original_title = '';
67
+ if ( 'taxonomy' == $item->type ) {
68
+ $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
69
+ if ( is_wp_error( $original_title ) )
70
+ $original_title = false;
71
+ } elseif ( 'post_type' == $item->type ) {
72
+ $original_object = get_post( $item->object_id );
73
+ $original_title = get_the_title( $original_object->ID );
74
+ }
75
+
76
+ $classes = array(
77
+ 'menu-item menu-item-depth-' . $depth,
78
+ 'menu-item-' . esc_attr( $item->object ),
79
+ 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
80
+ );
81
+
82
+ $title = $item->title;
83
+
84
+ if ( ! empty( $item->_invalid ) ) {
85
+ $classes[] = 'menu-item-invalid';
86
+ /* translators: %s: title of menu item which is invalid */
87
+ $title = sprintf( __( '%s (Invalid)' , 'nav-menu-roles' ), $item->title );
88
+ } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
89
+ $classes[] = 'pending';
90
+ /* translators: %s: title of menu item in draft status */
91
+ $title = sprintf( __('%s (Pending)', 'nav-menu-roles' ), $item->title );
92
+ }
93
+
94
+ $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
95
+
96
+ $submenu_text = '';
97
+ if ( 0 == $depth )
98
+ $submenu_text = 'style="display: none;"';
99
+
100
+ ?>
101
+ <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
102
+ <dl class="menu-item-bar">
103
+ <dt class="menu-item-handle">
104
+ <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>
105
+ <span class="item-controls">
106
+ <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
107
+ <span class="item-order hide-if-js">
108
+ <a href="<?php
109
+ echo wp_nonce_url(
110
+ add_query_arg(
111
+ array(
112
+ 'action' => 'move-up-menu-item',
113
+ 'menu-item' => $item_id,
114
+ ),
115
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
116
+ ),
117
+ 'move-menu_item'
118
+ );
119
+ ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up', 'nav-menu-roles' ); ?>">&#8593;</abbr></a>
120
+ |
121
+ <a href="<?php
122
+ echo wp_nonce_url(
123
+ add_query_arg(
124
+ array(
125
+ 'action' => 'move-down-menu-item',
126
+ 'menu-item' => $item_id,
127
+ ),
128
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
129
+ ),
130
+ 'move-menu_item'
131
+ );
132
+ ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down', 'nav-menu-roles' ); ?>">&#8595;</abbr></a>
133
+ </span>
134
+ <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item', 'nav-menu-roles' ); ?>" href="<?php
135
+ 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 ) ) );
136
+ ?>"><?php _e( 'Edit Menu Item' , 'nav-menu-roles' ); ?></a>
137
+ </span>
138
+ </dt>
139
+ </dl>
140
+
141
+ <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
142
+ <?php if( 'custom' == $item->type ) : ?>
143
+ <p class="field-url description description-wide">
144
+ <label for="edit-menu-item-url-<?php echo $item_id; ?>">
145
+ <?php _e( 'URL' , 'nav-menu-roles' ); ?><br />
146
+ <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 ); ?>" />
147
+ </label>
148
+ </p>
149
+ <?php endif; ?>
150
+ <p class="description description-thin">
151
+ <label for="edit-menu-item-title-<?php echo $item_id; ?>">
152
+ <?php _e( 'Navigation Label' , 'nav-menu-roles' ); ?><br />
153
+ <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 ); ?>" />
154
+ </label>
155
+ </p>
156
+ <p class="description description-thin">
157
+ <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
158
+ <?php _e( 'Title Attribute' , 'nav-menu-roles' ); ?><br />
159
+ <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 ); ?>" />
160
+ </label>
161
+ </p>
162
+ <p class="field-link-target description">
163
+ <label for="edit-menu-item-target-<?php echo $item_id; ?>">
164
+ <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' ); ?> />
165
+ <?php _e( 'Open link in a new window/tab' , 'nav-menu-roles' ); ?>
166
+ </label>
167
+ </p>
168
+ <p class="field-css-classes description description-thin">
169
+ <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
170
+ <?php _e( 'CSS Classes (optional)' , 'nav-menu-roles' ); ?><br />
171
+ <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 ) ); ?>" />
172
+ </label>
173
+ </p>
174
+ <p class="field-xfn description description-thin">
175
+ <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
176
+ <?php _e( 'Link Relationship (XFN)' , 'nav-menu-roles' ); ?><br />
177
+ <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 ); ?>" />
178
+ </label>
179
+ </p>
180
+ <p class="field-description description description-wide">
181
+ <label for="edit-menu-item-description-<?php echo $item_id; ?>">
182
+ <?php _e( 'Description' , 'nav-menu-roles' ); ?><br />
183
+ <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>
184
+ <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles' ); ?></span>
185
+ </label>
186
+ </p>
187
+
188
+ <?php
189
+ // This is the added section
190
+ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
191
+ // end added section
192
+ ?>
193
+
194
+ <p class="field-move hide-if-no-js description description-wide">
195
+ <label>
196
+ <span><?php _e( 'Move' , 'nav-menu-roles' ); ?></span>
197
+ <a href="#" class="menus-move-up"><?php _e( 'Up one' , 'nav-menu-roles' ); ?></a>
198
+ <a href="#" class="menus-move-down"><?php _e( 'Down one' , 'nav-menu-roles' ); ?></a>
199
+ <a href="#" class="menus-move-left"></a>
200
+ <a href="#" class="menus-move-right"></a>
201
+ <a href="#" class="menus-move-top"><?php _e( 'To the top' , 'nav-menu-roles' ); ?></a>
202
+ </label>
203
+ </p>
204
+
205
+ <div class="menu-item-actions description-wide submitbox">
206
+ <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
207
+ <p class="link-to-original">
208
+ <?php printf( __('Original: %s', 'nav-menu-roles' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
209
+ </p>
210
+ <?php endif; ?>
211
+ <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
212
+ echo wp_nonce_url(
213
+ add_query_arg(
214
+ array(
215
+ 'action' => 'delete-menu-item',
216
+ 'menu-item' => $item_id,
217
+ ),
218
+ admin_url( 'nav-menus.php' )
219
+ ),
220
+ 'delete-menu_item_' . $item_id
221
+ ); ?>"><?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' ) ) );
222
+ ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel', 'nav-menu-roles' ); ?></a>
223
+ </div>
224
+
225
+ <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
226
+ <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 ); ?>" />
227
+ <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
228
+ <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 ); ?>" />
229
+ <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
230
+ <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
231
+ </div><!-- .menu-item-settings-->
232
+ <ul class="menu-item-transport"></ul>
233
+ <?php
234
+ $output .= ob_get_clean();
235
+ }
236
+
237
  } // 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.7.0 */
2
  !function(a){a(".nav_menu_logged_in_out_field").each(function(){{var b=a(this);b.find("input.nav-menu-id").val()}"in"===b.find("input.nav-menu-logged-in-out:checked").val()?b.next(".nav_menu_role_field").show():b.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.7.0 */
2
  !function(a){a(".nav_menu_logged_in_out_field").each(function(){{var b=a(this);b.find("input.nav-menu-id").val()}"in"===b.find("input.nav-menu-logged-in-out:checked").val()?b.next(".nav_menu_role_field").show():b.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
@@ -2,9 +2,9 @@
2
  # This file is distributed under the same license as the Nav Menu Roles package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Nav Menu Roles 1.7.3\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/nav-menu-roles\n"
7
- "POT-Creation-Date: 2015-11-17 12:54:54+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -196,7 +196,7 @@ msgid "Everyone"
196
  msgstr ""
197
 
198
  #: nav-menu-roles.php:365
199
- msgid "Limit logged in users to specific roles"
200
  msgstr ""
201
 
202
  #. Plugin URI of the plugin/theme
2
  # This file is distributed under the same license as the Nav Menu Roles package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Nav Menu Roles 1.7.4\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/nav-menu-roles\n"
7
+ "POT-Creation-Date: 2015-12-05 04:33:21+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
196
  msgstr ""
197
 
198
  #: nav-menu-roles.php:365
199
+ msgid "Restrict menu item to a minimum role"
200
  msgstr ""
201
 
202
  #. Plugin URI of the plugin/theme
nav-menu-roles.php CHANGED
@@ -1,532 +1,532 @@
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. PLEASE READ THE [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/#conflict) IF YOU ARE NOT SEEING THE SETTINGS.
6
- Version: 1.7.3
7
- Author: Kathy Darling
8
- Author URI: http://www.kathyisawesome.com
9
- License: GPL2
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
- * @var string donate url
49
- * @since 1.5
50
- */
51
- public static $donate_url = "https://inspirepay.com/pay/helgatheviking";
52
-
53
- /**
54
- * @var string version number
55
- * @since 1.7.1
56
- */
57
- public $version = '1.7.3';
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 a notice that NMR is conflicting with another plugin
109
- add_action( 'admin_notices', array( $this, 'admin_notice' ) );
110
- add_action( 'activated_plugin', array( $this, 'delete_transient' ) );
111
- add_action( 'deactivated_plugin', array( $this, 'delete_transient' ) );
112
-
113
- // add FAQ link to plugin
114
- add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'add_action_links' ) );
115
-
116
- // switch the admin walker
117
- add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
118
-
119
- // add new fields via hook
120
- add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'custom_fields' ), 10, 4 );
121
-
122
- // add some JS
123
- add_action( 'admin_enqueue_scripts' , array( $this, 'enqueue_scripts' ) );
124
-
125
- // save the menu item meta
126
- add_action( 'wp_update_nav_menu_item', array( $this, 'nav_update'), 10, 2 );
127
-
128
- // add meta to menu item
129
- add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_nav_item' ) );
130
-
131
- // exclude items via filter instead of via custom Walker
132
- if ( ! is_admin() ) {
133
- add_filter( 'wp_get_nav_menu_items', array( $this, 'exclude_menu_items' ) );
134
- }
135
-
136
- }
137
-
138
- /**
139
- * Include the custom admin walker
140
- *
141
- * @access public
142
- * @return void
143
- */
144
- public function admin_init() {
145
- include_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles.php');
146
-
147
- // Register Importer
148
- $this->register_importer();
149
-
150
- // save user notice
151
- $this->nag_ignore();
152
- }
153
-
154
-
155
- /**
156
- * Register the Importer
157
- * the regular Importer skips post meta for the menu items
158
- *
159
- * @access private
160
- * @return void
161
- */
162
- public function register_importer(){
163
-
164
- include_once( plugin_dir_path( __FILE__ ) . 'inc/class.Nav_Menu_Roles_Import.php');
165
-
166
- // Register the new importer
167
- if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
168
-
169
- // Register the custom importer we've created.
170
- $roles_import = new Nav_Menu_Roles_Import();
171
-
172
- 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' ) );
173
-
174
- }
175
-
176
- }
177
-
178
- /**
179
- * Make Plugin Translation-ready
180
- * CALLBACK FUNCTION FOR: add_action( 'plugins_loaded', array( $this,'load_text_domain'));
181
- * @since 1.0
182
- */
183
-
184
- public function load_text_domain() {
185
- load_plugin_textdomain( 'nav-menu-roles', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
186
- }
187
-
188
-
189
- /**
190
- * Display a Notice if plugin conflicts with another
191
- * @since 1.5
192
- */
193
- public function admin_notice() {
194
- global $pagenow, $wp_filter;
195
-
196
- // quit early if not on the menus page, or if not an admin
197
- if( ! in_array( $pagenow, array( 'nav-menus.php', 'plugins.php' ) ) || ! current_user_can( 'manage_options' ) ){
198
- return;
199
- }
200
-
201
- // Get any existing copy of our transient data
202
- if ( false === ( $conflicts = get_transient( 'nav_menu_roles_conflicts' ) ) ) {
203
-
204
- // It wasn't there, so regenerate the data and save the transient
205
- global $wp_filter;
206
-
207
- $filters = is_array( $wp_filter['wp_edit_nav_menu_walker'] ) ? array_shift( $wp_filter['wp_edit_nav_menu_walker'] ) : array();
208
-
209
- foreach( $filters as $filter ){
210
- // we expect to see NVR so collect everything else
211
- if( ! is_a( $filter['function'][0], 'Nav_Menu_Roles') ) {
212
- $conflicts[] = is_object( $filter['function'][0] ) ? get_class( $filter['function'][0] ) : $filter['function'][0];
213
- }
214
-
215
- }
216
- }
217
-
218
-
219
- // Check Transient for conflicts and show error
220
- if ( ! empty ( $conflicts ) ) {
221
- global $current_user ;
222
- $user_id = $current_user->ID;
223
-
224
- if ( ! get_user_meta( $user_id, 'nmr_ignore_notice' ) ) {
225
-
226
- echo '<div class="error">
227
- <p>';
228
- printf ( __( 'Nav Menu Roles has detected a possible conflict with the following functions or classes: %1$s. Please direct the author of the conflicting theme or plugin to the %2$sFAQ%3$s for a solution. | %4$sHide Notice%3$s', 'nav-menu-roles' ),
229
- '<code>' . implode( $conflicts, ', ' ) . '</code>',
230
- '<a href="http://wordpress.org/plugins/nav-menu-roles/faq#conflict" target="_blank">',
231
- '</a>',
232
- '<a href="?nmr_nag_ignore=0">' );
233
- echo '</p>
234
- </div>';
235
-
236
- }
237
-
238
- }
239
-
240
- }
241
-
242
-
243
- /**
244
- * Allow the notice to be dismissable
245
- * @since 1.6
246
- */
247
- public function nag_ignore() {
248
- global $current_user;
249
- $user_id = $current_user->ID;
250
- /* If user clicks to ignore the notice, add that to their user meta */
251
- if ( isset($_GET['nmr_nag_ignore']) && '0' == $_GET['nmr_nag_ignore'] ) {
252
- add_user_meta( $user_id, 'nmr_ignore_notice', 'true', true );
253
- }
254
- }
255
-
256
- /**
257
- * Delete the transient when a plugin is activated or deactivated
258
- * @since 1.5
259
- */
260
- public function delete_transient() {
261
- delete_transient( 'nav_menu_roles_conflicts' );
262
- }
263
-
264
-
265
- /**
266
- * Add docu link
267
- * @since 1.7.3
268
- */
269
- public function add_action_links( $links ) {
270
- $new_link = array(
271
- sprintf( '<a href="https://wordpress.org/plugins/nav-menu-roles/faq/#conflict">%s</a>', __( 'FAQ', 'nav-menu-roles' ) ),
272
- );
273
- return array_merge( $links, $new_link );
274
- }
275
-
276
- /**
277
- * Override the Admin Menu Walker
278
- * @since 1.0
279
- */
280
- public function edit_nav_menu_walker( $walker ) {
281
- return 'Walker_Nav_Menu_Edit_Roles';
282
- }
283
-
284
-
285
- /**
286
- * Add fields to hook added in Walker
287
- * This will allow us to play nicely with any other plugin that is adding the same hook
288
- * @params obj $item - the menu item
289
- * @params array $args
290
- * @since 1.6.0
291
- */
292
- public function custom_fields( $item_id, $item, $depth, $args ) {
293
- global $wp_roles;
294
-
295
- /**
296
- * Pass the menu item to the filter function.
297
- * This change is suggested as it allows the use of information from the menu item (and
298
- * by extension the target object) to further customize what filters appear during menu
299
- * construction.
300
- */
301
- $display_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names, $item );
302
-
303
-
304
- /**
305
- * If no roles are being used, don't display the role selection radio buttons at all.
306
- * Unless something deliberately removes the WordPress roles from this list, nothing will
307
- * be functionally altered to the end user.
308
- * This change is suggested for the benefit of users constructing granular admin permissions
309
- * using extensive custom roles as it is an effective means of stopping admins with partial
310
- * permissions to the menu from accidentally removing all restrictions from a menu item to
311
- * which they do not have access.
312
- */
313
- if( ! $display_roles ) return;
314
-
315
- /* Get the roles saved for the post. */
316
- $roles = get_post_meta( $item->ID, '_nav_menu_role', true );
317
-
318
- // by default nothing is checked (will match "everyone" radio)
319
- $logged_in_out = '';
320
-
321
- // specific roles are saved as an array, so "in" or an array equals "in" is checked
322
- if( is_array( $roles ) || $roles == 'in' ){
323
- $logged_in_out = 'in';
324
- } else if ( $roles == 'out' ){
325
- $logged_in_out = 'out';
326
- }
327
-
328
- // the specific roles to check
329
- $checked_roles = is_array( $roles ) ? $roles : false;
330
-
331
- ?>
332
-
333
- <input type="hidden" name="nav-menu-role-nonce" value="<?php echo wp_create_nonce( 'nav-menu-nonce-name' ); ?>" />
334
-
335
- <div class="field-nav_menu_role nav_menu_logged_in_out_field description-wide" style="margin: 5px 0;">
336
- <span class="description"><?php _e( "Display Mode", 'nav-menu-roles' ); ?></span>
337
- <br />
338
-
339
- <input type="hidden" class="nav-menu-id" value="<?php echo $item->ID ;?>" />
340
-
341
- <div class="logged-input-holder" style="float: left; width: 35%;">
342
- <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" />
343
- <label for="nav_menu_logged_in-for-<?php echo $item->ID ;?>">
344
- <?php _e( 'Logged In Users', 'nav-menu-roles'); ?>
345
- </label>
346
- </div>
347
-
348
- <div class="logged-input-holder" style="float: left; width: 35%;">
349
- <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" />
350
- <label for="nav_menu_logged_out-for-<?php echo $item->ID ;?>">
351
- <?php _e( 'Logged Out Users', 'nav-menu-roles'); ?>
352
- </label>
353
- </div>
354
-
355
- <div class="logged-input-holder" style="float: left; width: 30%;">
356
- <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="" />
357
- <label for="nav_menu_by_role-for-<?php echo $item->ID ;?>">
358
- <?php _e( 'Everyone', 'nav-menu-roles'); ?>
359
- </label>
360
- </div>
361
-
362
- </div>
363
-
364
- <div class="field-nav_menu_role nav_menu_role_field description-wide" style="margin: 5px 0;">
365
- <span class="description"><?php _e( "Limit logged in users to specific roles", 'nav-menu-roles' ); ?></span>
366
- <br />
367
-
368
- <?php
369
-
370
- /* Loop through each of the available roles. */
371
- foreach ( $display_roles as $role => $name ) {
372
-
373
- /* If the role has been selected, make sure it's checked. */
374
- $checked = checked( true, ( is_array( $checked_roles ) && in_array( $role, $checked_roles ) ), false );
375
-
376
- ?>
377
-
378
- <div class="role-input-holder" style="float: left; width: 33.3%; margin: 2px 0;">
379
- <input type="checkbox" name="nav-menu-role[<?php echo $item->ID ;?>][<?php echo $role; ?>]" id="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>" <?php echo $checked; ?> value="<?php echo $role; ?>" />
380
- <label for="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>">
381
- <?php echo esc_html( $name ); ?>
382
- </label>
383
- </div>
384
-
385
- <?php } ?>
386
-
387
- </div>
388
-
389
- <?php
390
- }
391
-
392
-
393
- /**
394
- * Save the roles as menu item meta
395
- * @return null
396
- * @since 1.4
397
- *
398
- */
399
- public function enqueue_scripts( $hook ){
400
- if ( $hook == 'nav-menus.php' ){
401
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
402
- wp_enqueue_script( 'nav-menu-roles', plugins_url( 'js/nav-menu-roles' . $suffix . '.js' , __FILE__ ), array( 'jquery' ), $this->version, true );
403
- }
404
- }
405
-
406
- /**
407
- * Save the roles as menu item meta
408
- * @return string
409
- * @since 1.0
410
- */
411
- public function nav_update( $menu_id, $menu_item_db_id ) {
412
- global $wp_roles;
413
-
414
- $allowed_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names );
415
-
416
- // verify this came from our screen and with proper authorization.
417
- if ( ! isset( $_POST['nav-menu-role-nonce'] ) || ! wp_verify_nonce( $_POST['nav-menu-role-nonce'], 'nav-menu-nonce-name' ) )
418
- return;
419
-
420
- $saved_data = false;
421
-
422
- 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] ) ) {
423
- $custom_roles = array();
424
- // only save allowed roles
425
- foreach( $_POST['nav-menu-role'][$menu_item_db_id] as $role ) {
426
- if ( array_key_exists ( $role, $allowed_roles ) ) $custom_roles[] = $role;
427
- }
428
- if ( ! empty ( $custom_roles ) ) $saved_data = $custom_roles;
429
- } 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' ) ) ) {
430
- $saved_data = $_POST['nav-menu-logged-in-out'][$menu_item_db_id];
431
- }
432
-
433
- if ( $saved_data ) {
434
- update_post_meta( $menu_item_db_id, '_nav_menu_role', $saved_data );
435
- } else {
436
- delete_post_meta( $menu_item_db_id, '_nav_menu_role' );
437
- }
438
- }
439
-
440
- /**
441
- * Adds value of new field to $item object
442
- * is be passed to Walker_Nav_Menu_Edit_Custom
443
- * @since 1.0
444
- */
445
- public function setup_nav_item( $menu_item ) {
446
-
447
- $roles = get_post_meta( $menu_item->ID, '_nav_menu_role', true );
448
-
449
- if ( ! empty( $roles ) ) {
450
- $menu_item->roles = $roles;
451
- }
452
- return $menu_item;
453
- }
454
-
455
- /**
456
- * Exclude menu items via wp_get_nav_menu_items filter
457
- * this fixes plugin's incompatibility with theme's that use their own custom Walker
458
- * Thanks to Evan Stein @vanpop http://vanpop.com/
459
- * @since 1.2
460
- */
461
- public function exclude_menu_items( $items ) {
462
-
463
- $hide_children_of = array();
464
-
465
- // Iterate over the items to search and destroy
466
- foreach ( $items as $key => $item ) {
467
-
468
- $visible = true;
469
-
470
- // hide any item that is the child of a hidden item
471
- if( in_array( $item->menu_item_parent, $hide_children_of ) ){
472
- $visible = false;
473
- $hide_children_of[] = $item->ID; // for nested menus
474
- }
475
-
476
- // check any item that has NMR roles set
477
- if( $visible && isset( $item->roles ) ) {
478
-
479
- // check all logged in, all logged out, or role
480
- switch( $item->roles ) {
481
- case 'in' :
482
- $visible = is_user_logged_in() ? true : false;
483
- break;
484
- case 'out' :
485
- $visible = ! is_user_logged_in() ? true : false;
486
- break;
487
- default:
488
- $visible = false;
489
- if ( is_array( $item->roles ) && ! empty( $item->roles ) ) {
490
- foreach ( $item->roles as $role ) {
491
- if ( current_user_can( $role ) )
492
- $visible = true;
493
- }
494
- }
495
-
496
- break;
497
- }
498
-
499
- }
500
-
501
- // add filter to work with plugins that don't use traditional roles
502
- $visible = apply_filters( 'nav_menu_roles_item_visibility', $visible, $item );
503
-
504
- // unset non-visible item
505
- if ( ! $visible ) {
506
- $hide_children_of[] = $item->ID; // store ID of item
507
- unset( $items[$key] ) ;
508
- }
509
-
510
- }
511
-
512
- return $items;
513
- }
514
-
515
- } // end class
516
-
517
- endif; // class_exists check
518
-
519
-
520
- /**
521
- * Launch the whole plugin
522
- * Returns the main instance of Nav Menu Roles to prevent the need to use globals.
523
- *
524
- * @since 1.5
525
- * @return Nav_Menu_Roles
526
- */
527
- function Nav_Menu_Roles() {
528
- return Nav_Menu_Roles::instance();
529
- }
530
-
531
- // Global for backwards compatibility.
532
  $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. PLEASE READ THE [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/#conflict) IF YOU ARE NOT SEEING THE SETTINGS.
6
+ Version: 1.7.4
7
+ Author: Kathy Darling
8
+ Author URI: http://www.kathyisawesome.com
9
+ License: GPL2
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
+ * @var string donate url
49
+ * @since 1.5
50
+ */
51
+ public static $donate_url = "https://inspirepay.com/pay/helgatheviking";
52
+
53
+ /**
54
+ * @var string version number
55
+ * @since 1.7.1
56
+ */
57
+ public $version = '1.7.4';
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 a notice that NMR is conflicting with another plugin
109
+ add_action( 'admin_notices', array( $this, 'admin_notice' ) );
110
+ add_action( 'activated_plugin', array( $this, 'delete_transient' ) );
111
+ add_action( 'deactivated_plugin', array( $this, 'delete_transient' ) );
112
+
113
+ // add FAQ link to plugin
114
+ add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'add_action_links' ) );
115
+
116
+ // switch the admin walker
117
+ add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
118
+
119
+ // add new fields via hook
120
+ add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'custom_fields' ), 10, 4 );
121
+
122
+ // add some JS
123
+ add_action( 'admin_enqueue_scripts' , array( $this, 'enqueue_scripts' ) );
124
+
125
+ // save the menu item meta
126
+ add_action( 'wp_update_nav_menu_item', array( $this, 'nav_update'), 10, 2 );
127
+
128
+ // add meta to menu item
129
+ add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_nav_item' ) );
130
+
131
+ // exclude items via filter instead of via custom Walker
132
+ if ( ! is_admin() ) {
133
+ add_filter( 'wp_get_nav_menu_items', array( $this, 'exclude_menu_items' ) );
134
+ }
135
+
136
+ }
137
+
138
+ /**
139
+ * Include the custom admin walker
140
+ *
141
+ * @access public
142
+ * @return void
143
+ */
144
+ public function admin_init() {
145
+ include_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles.php');
146
+
147
+ // Register Importer
148
+ $this->register_importer();
149
+
150
+ // save user notice
151
+ $this->nag_ignore();
152
+ }
153
+
154
+
155
+ /**
156
+ * Register the Importer
157
+ * the regular Importer skips post meta for the menu items
158
+ *
159
+ * @access private
160
+ * @return void
161
+ */
162
+ public function register_importer(){
163
+
164
+ include_once( plugin_dir_path( __FILE__ ) . 'inc/class.Nav_Menu_Roles_Import.php');
165
+
166
+ // Register the new importer
167
+ if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
168
+
169
+ // Register the custom importer we've created.
170
+ $roles_import = new Nav_Menu_Roles_Import();
171
+
172
+ 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' ) );
173
+
174
+ }
175
+
176
+ }
177
+
178
+ /**
179
+ * Make Plugin Translation-ready
180
+ * CALLBACK FUNCTION FOR: add_action( 'plugins_loaded', array( $this,'load_text_domain'));
181
+ * @since 1.0
182
+ */
183
+
184
+ public function load_text_domain() {
185
+ load_plugin_textdomain( 'nav-menu-roles', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
186
+ }
187
+
188
+
189
+ /**
190
+ * Display a Notice if plugin conflicts with another
191
+ * @since 1.5
192
+ */
193
+ public function admin_notice() {
194
+ global $pagenow, $wp_filter;
195
+
196
+ // quit early if not on the menus page, or if not an admin
197
+ if( ! in_array( $pagenow, array( 'nav-menus.php', 'plugins.php' ) ) || ! current_user_can( 'manage_options' ) ){
198
+ return;
199
+ }
200
+
201
+ // Get any existing copy of our transient data
202
+ if ( false === ( $conflicts = get_transient( 'nav_menu_roles_conflicts' ) ) ) {
203
+
204
+ // It wasn't there, so regenerate the data and save the transient
205
+ global $wp_filter;
206
+
207
+ $filters = is_array( $wp_filter['wp_edit_nav_menu_walker'] ) ? array_shift( $wp_filter['wp_edit_nav_menu_walker'] ) : array();
208
+
209
+ foreach( $filters as $filter ){
210
+ // we expect to see NVR so collect everything else
211
+ if( ! is_a( $filter['function'][0], 'Nav_Menu_Roles') ) {
212
+ $conflicts[] = is_object( $filter['function'][0] ) ? get_class( $filter['function'][0] ) : $filter['function'][0];
213
+ }
214
+
215
+ }
216
+ }
217
+
218
+
219
+ // Check Transient for conflicts and show error
220
+ if ( ! empty ( $conflicts ) ) {
221
+ global $current_user ;
222
+ $user_id = $current_user->ID;
223
+
224
+ if ( ! get_user_meta( $user_id, 'nmr_ignore_notice' ) ) {
225
+
226
+ echo '<div class="error">
227
+ <p>';
228
+ printf ( __( 'Nav Menu Roles has detected a possible conflict with the following functions or classes: %1$s. Please direct the author of the conflicting theme or plugin to the %2$sFAQ%3$s for a solution. | %4$sHide Notice%3$s', 'nav-menu-roles' ),
229
+ '<code>' . implode( $conflicts, ', ' ) . '</code>',
230
+ '<a href="http://wordpress.org/plugins/nav-menu-roles/faq#conflict" target="_blank">',
231
+ '</a>',
232
+ '<a href="?nmr_nag_ignore=0">' );
233
+ echo '</p>
234
+ </div>';
235
+
236
+ }
237
+
238
+ }
239
+
240
+ }
241
+
242
+
243
+ /**
244
+ * Allow the notice to be dismissable
245
+ * @since 1.6
246
+ */
247
+ public function nag_ignore() {
248
+ global $current_user;
249
+ $user_id = $current_user->ID;
250
+ /* If user clicks to ignore the notice, add that to their user meta */
251
+ if ( isset($_GET['nmr_nag_ignore']) && '0' == $_GET['nmr_nag_ignore'] ) {
252
+ add_user_meta( $user_id, 'nmr_ignore_notice', 'true', true );
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Delete the transient when a plugin is activated or deactivated
258
+ * @since 1.5
259
+ */
260
+ public function delete_transient() {
261
+ delete_transient( 'nav_menu_roles_conflicts' );
262
+ }
263
+
264
+
265
+ /**
266
+ * Add docu link
267
+ * @since 1.7.3
268
+ */
269
+ public function add_action_links( $links ) {
270
+ $new_link = array(
271
+ sprintf( '<a href="https://wordpress.org/plugins/nav-menu-roles/faq/#conflict">%s</a>', __( 'FAQ', 'nav-menu-roles' ) ),
272
+ );
273
+ return array_merge( $links, $new_link );
274
+ }
275
+
276
+ /**
277
+ * Override the Admin Menu Walker
278
+ * @since 1.0
279
+ */
280
+ public function edit_nav_menu_walker( $walker ) {
281
+ return 'Walker_Nav_Menu_Edit_Roles';
282
+ }
283
+
284
+
285
+ /**
286
+ * Add fields to hook added in Walker
287
+ * This will allow us to play nicely with any other plugin that is adding the same hook
288
+ * @params obj $item - the menu item
289
+ * @params array $args
290
+ * @since 1.6.0
291
+ */
292
+ public function custom_fields( $item_id, $item, $depth, $args ) {
293
+ global $wp_roles;
294
+
295
+ /**
296
+ * Pass the menu item to the filter function.
297
+ * This change is suggested as it allows the use of information from the menu item (and
298
+ * by extension the target object) to further customize what filters appear during menu
299
+ * construction.
300
+ */
301
+ $display_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names, $item );
302
+
303
+
304
+ /**
305
+ * If no roles are being used, don't display the role selection radio buttons at all.
306
+ * Unless something deliberately removes the WordPress roles from this list, nothing will
307
+ * be functionally altered to the end user.
308
+ * This change is suggested for the benefit of users constructing granular admin permissions
309
+ * using extensive custom roles as it is an effective means of stopping admins with partial
310
+ * permissions to the menu from accidentally removing all restrictions from a menu item to
311
+ * which they do not have access.
312
+ */
313
+ if( ! $display_roles ) return;
314
+
315
+ /* Get the roles saved for the post. */
316
+ $roles = get_post_meta( $item->ID, '_nav_menu_role', true );
317
+
318
+ // by default nothing is checked (will match "everyone" radio)
319
+ $logged_in_out = '';
320
+
321
+ // specific roles are saved as an array, so "in" or an array equals "in" is checked
322
+ if( is_array( $roles ) || $roles == 'in' ){
323
+ $logged_in_out = 'in';
324
+ } else if ( $roles == 'out' ){
325
+ $logged_in_out = 'out';
326
+ }
327
+
328
+ // the specific roles to check
329
+ $checked_roles = is_array( $roles ) ? $roles : false;
330
+
331
+ ?>
332
+
333
+ <input type="hidden" name="nav-menu-role-nonce" value="<?php echo wp_create_nonce( 'nav-menu-nonce-name' ); ?>" />
334
+
335
+ <div class="field-nav_menu_role nav_menu_logged_in_out_field description-wide" style="margin: 5px 0;">
336
+ <span class="description"><?php _e( "Display Mode", 'nav-menu-roles' ); ?></span>
337
+ <br />
338
+
339
+ <input type="hidden" class="nav-menu-id" value="<?php echo $item->ID ;?>" />
340
+
341
+ <div class="logged-input-holder" style="float: left; width: 35%;">
342
+ <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" />
343
+ <label for="nav_menu_logged_in-for-<?php echo $item->ID ;?>">
344
+ <?php _e( 'Logged In Users', 'nav-menu-roles'); ?>
345
+ </label>
346
+ </div>
347
+
348
+ <div class="logged-input-holder" style="float: left; width: 35%;">
349
+ <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" />
350
+ <label for="nav_menu_logged_out-for-<?php echo $item->ID ;?>">
351
+ <?php _e( 'Logged Out Users', 'nav-menu-roles'); ?>
352
+ </label>
353
+ </div>
354
+
355
+ <div class="logged-input-holder" style="float: left; width: 30%;">
356
+ <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="" />
357
+ <label for="nav_menu_by_role-for-<?php echo $item->ID ;?>">
358
+ <?php _e( 'Everyone', 'nav-menu-roles'); ?>
359
+ </label>
360
+ </div>
361
+
362
+ </div>
363
+
364
+ <div class="field-nav_menu_role nav_menu_role_field description-wide" style="margin: 5px 0;">
365
+ <span class="description"><?php _e( "Restrict menu item to a minimum role", 'nav-menu-roles' ); ?></span>
366
+ <br />
367
+
368
+ <?php
369
+
370
+ /* Loop through each of the available roles. */
371
+ foreach ( $display_roles as $role => $name ) {
372
+
373
+ /* If the role has been selected, make sure it's checked. */
374
+ $checked = checked( true, ( is_array( $checked_roles ) && in_array( $role, $checked_roles ) ), false );
375
+
376
+ ?>
377
+
378
+ <div class="role-input-holder" style="float: left; width: 33.3%; margin: 2px 0;">
379
+ <input type="checkbox" name="nav-menu-role[<?php echo $item->ID ;?>][<?php echo $role; ?>]" id="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>" <?php echo $checked; ?> value="<?php echo $role; ?>" />
380
+ <label for="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>">
381
+ <?php echo esc_html( $name ); ?>
382
+ </label>
383
+ </div>
384
+
385
+ <?php } ?>
386
+
387
+ </div>
388
+
389
+ <?php
390
+ }
391
+
392
+
393
+ /**
394
+ * Save the roles as menu item meta
395
+ * @return null
396
+ * @since 1.4
397
+ *
398
+ */
399
+ public function enqueue_scripts( $hook ){
400
+ if ( $hook == 'nav-menus.php' ){
401
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
402
+ wp_enqueue_script( 'nav-menu-roles', plugins_url( 'js/nav-menu-roles' . $suffix . '.js' , __FILE__ ), array( 'jquery' ), $this->version, true );
403
+ }
404
+ }
405
+
406
+ /**
407
+ * Save the roles as menu item meta
408
+ * @return string
409
+ * @since 1.0
410
+ */
411
+ public function nav_update( $menu_id, $menu_item_db_id ) {
412
+ global $wp_roles;
413
+
414
+ $allowed_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names );
415
+
416
+ // verify this came from our screen and with proper authorization.
417
+ if ( ! isset( $_POST['nav-menu-role-nonce'] ) || ! wp_verify_nonce( $_POST['nav-menu-role-nonce'], 'nav-menu-nonce-name' ) )
418
+ return;
419
+
420
+ $saved_data = false;
421
+
422
+ 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] ) ) {
423
+ $custom_roles = array();
424
+ // only save allowed roles
425
+ foreach( $_POST['nav-menu-role'][$menu_item_db_id] as $role ) {
426
+ if ( array_key_exists ( $role, $allowed_roles ) ) $custom_roles[] = $role;
427
+ }
428
+ if ( ! empty ( $custom_roles ) ) $saved_data = $custom_roles;
429
+ } 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' ) ) ) {
430
+ $saved_data = $_POST['nav-menu-logged-in-out'][$menu_item_db_id];
431
+ }
432
+
433
+ if ( $saved_data ) {
434
+ update_post_meta( $menu_item_db_id, '_nav_menu_role', $saved_data );
435
+ } else {
436
+ delete_post_meta( $menu_item_db_id, '_nav_menu_role' );
437
+ }
438
+ }
439
+
440
+ /**
441
+ * Adds value of new field to $item object
442
+ * is be passed to Walker_Nav_Menu_Edit_Custom
443
+ * @since 1.0
444
+ */
445
+ public function setup_nav_item( $menu_item ) {
446
+
447
+ $roles = get_post_meta( $menu_item->ID, '_nav_menu_role', true );
448
+
449
+ if ( ! empty( $roles ) ) {
450
+ $menu_item->roles = $roles;
451
+ }
452
+ return $menu_item;
453
+ }
454
+
455
+ /**
456
+ * Exclude menu items via wp_get_nav_menu_items filter
457
+ * this fixes plugin's incompatibility with theme's that use their own custom Walker
458
+ * Thanks to Evan Stein @vanpop http://vanpop.com/
459
+ * @since 1.2
460
+ */
461
+ public function exclude_menu_items( $items ) {
462
+
463
+ $hide_children_of = array();
464
+
465
+ // Iterate over the items to search and destroy
466
+ foreach ( $items as $key => $item ) {
467
+
468
+ $visible = true;
469
+
470
+ // hide any item that is the child of a hidden item
471
+ if( in_array( $item->menu_item_parent, $hide_children_of ) ){
472
+ $visible = false;
473
+ $hide_children_of[] = $item->ID; // for nested menus
474
+ }
475
+
476
+ // check any item that has NMR roles set
477
+ if( $visible && isset( $item->roles ) ) {
478
+
479
+ // check all logged in, all logged out, or role
480
+ switch( $item->roles ) {
481
+ case 'in' :
482
+ $visible = is_user_logged_in() ? true : false;
483
+ break;
484
+ case 'out' :
485
+ $visible = ! is_user_logged_in() ? true : false;
486
+ break;
487
+ default:
488
+ $visible = false;
489
+ if ( is_array( $item->roles ) && ! empty( $item->roles ) ) {
490
+ foreach ( $item->roles as $role ) {
491
+ if ( current_user_can( $role ) )
492
+ $visible = true;
493
+ }
494
+ }
495
+
496
+ break;
497
+ }
498
+
499
+ }
500
+
501
+ // add filter to work with plugins that don't use traditional roles
502
+ $visible = apply_filters( 'nav_menu_roles_item_visibility', $visible, $item );
503
+
504
+ // unset non-visible item
505
+ if ( ! $visible ) {
506
+ $hide_children_of[] = $item->ID; // store ID of item
507
+ unset( $items[$key] ) ;
508
+ }
509
+
510
+ }
511
+
512
+ return $items;
513
+ }
514
+
515
+ } // end class
516
+
517
+ endif; // class_exists check
518
+
519
+
520
+ /**
521
+ * Launch the whole plugin
522
+ * Returns the main instance of Nav Menu Roles to prevent the need to use globals.
523
+ *
524
+ * @since 1.5
525
+ * @return Nav_Menu_Roles
526
+ */
527
+ function Nav_Menu_Roles() {
528
+ return Nav_Menu_Roles::instance();
529
+ }
530
+
531
+ // Global for backwards compatibility.
532
  $GLOBALS['Nav_Menu_Roles'] = Nav_Menu_Roles();
readme.txt CHANGED
@@ -1,291 +1,295 @@
1
- === Nav Menu Roles ===
2
-
3
- Contributors: helgatheviking
4
- Donate link: https://inspirepay.com/pay/helgatheviking
5
- Tags: menu, menus, nav menu, nav menus
6
- Requires at least: 3.8.0
7
- Tested up to: 4.4.0
8
- Stable tag: 1.7.4
9
- License: GPLv3
10
-
11
- Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
12
-
13
- == Description ==
14
-
15
- This plugin lets you hide custom menu items based on user roles. So if you have a link in the menu that you only want to show to logged in users, certain types of users, or even only to logged out users, this plugin is for you.
16
-
17
- Nav Menu Roles is very flexible. In addition to standard user roles, you can customize the functionality by adding your own check boxes with custom labels using the `nav_menu_roles` filter and then using the `nav_menu_roles_item_visibility` filter to check against whatever criteria you need. You can check against any user meta values (like capabilities) and any custom attributes added by other plugins. See the [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/#new-role).
18
-
19
- = IMPORTANT NOTE =
20
-
21
- In WordPress menu items and pages are completely separate entities. Nav Menu Roles does not restrict access to content. Nav Menu Roles is *only* for showing/hiding *nav menu* items. If you wish to restrict content then you need to also be using a membership plugin.
22
-
23
- = Usage =
24
-
25
- 1. Go to Appearance > Menus
26
- 1. Edit the menu items accordingly. First select whether you'd like to display the item to all logged in users, all logged out users or to customize by role.
27
- 1. If you chose customize by role, then you can check the boxes next to the roles you'd like to restrict visibility to.
28
- 1. If you choose 'By Role' and don't check any boxes, the item will be visible to everyone like normal.
29
-
30
- = Support =
31
-
32
- Support is handled in the [WordPress forums](https://wordpress.org/support/plugin/nav-menu-roles). Please note that support is limited and does not cover any custom implementation of the plugin. Before posting, please read the [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/). Also, please verify the problem with other plugins disabled and while using a default theme.
33
-
34
- Please report any bugs, errors, warnings, code problems to [Github](https://github.com/helgatheviking/nav-menu-roles/issues)
35
-
36
- == Installation ==
37
-
38
- 1. Upload the `plugin` folder to the `/wp-content/plugins/` directory
39
- 1. Activate the plugin through the 'Plugins' menu in WordPress
40
- 1. Go to Appearance > Menus
41
- 1. Edit the menu items accordingly. First select whether you'd like to display the item to Everyone, all logged out users, or all logged in users.
42
- 1. Logged in users can be further limited to specific roles by checking the boxes next to the roles you'd like to restrict visibility to.
43
-
44
- == Screenshots ==
45
-
46
- 1. Show the new options for the menu items in the admin menu customizer
47
-
48
- == Frequently Asked Questions ==
49
-
50
- = <a id="conflict"></a>I don't see the Nav Menu Roles options in the admin menu items? =
51
-
52
- This is because you have another plugin (or theme) that is also trying to alter the same code that creates the Menu section in the admin.
53
-
54
- WordPress does not have sufficient hooks in this area of the admin and until they do plugins are forced to replace everything via custom admin menu Walker, of which there can be only one. There's a [trac ticket](http://core.trac.wordpress.org/ticket/18584) for this, but it has been around a while.
55
-
56
- **A non-exhaustive list of known conflicts:**
57
-
58
- 1. UberMenu 2.x Mega Menus plugin
59
- 2. Add Descendants As Submenu Items plugin
60
- 3. Navception plugin
61
- 4. Suffusion theme
62
- 5. BeTheme
63
- 6. Yith Menu
64
- 7. Jupiter Theme
65
-
66
-
67
- = <a id="compatibility"></a>Workaround #1 =
68
- [Shazdeh](https://profiles.wordpress.org/shazdeh/) had the genius idea to not wait for a core hook and simply add the hook ourselves. If all plugin and theme authors use the same hook, we can make our plugins play together.
69
-
70
- Therefore, as of version 1.6 I am modifying my admin nav menu Walker to *only* adding the following lines (right after the description input):
71
-
72
- `
73
- <?php
74
- // Place this in your admin nav menu Walker
75
- do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
76
- // end added section
77
- ?>
78
- `
79
-
80
- **Ask your conflicting plugin/theme's author to add this code to his plugin or theme and our plugins will become compatible.**
81
-
82
- = <a id="patch"></a>Patching Your Plugin/Theme =
83
-
84
- Should you wish to attempt this patch yourself, you can modify your conflicting plugin/theme's admin menu Walker class. **Reminder: I do not provide support for fixing your plugin/theme. If you aren't comfortable with the following instructions, contact the developer of the conflicting plugin/theme!**
85
-
86
- 1. Find the class that extends the `Walker_Nav_Menu`. As a hint, it is filtering `wp_edit_nav_menu_walker` and you might even be getting a warning about it from Nav Menu Roles. Example:
87
-
88
- `
89
- add_filter( 'wp_edit_nav_menu_walker', 'sample_edit_nav_menu_walker');
90
- function sample_edit_nav_menu_walker( $walker ) {
91
- return 'Walker_Nav_Menu_Edit_Roles'; // this is the class name
92
- }
93
- `
94
-
95
- 2. Find the file for the extending class. In my plugin this is in a file located at `inc/class.Walker_Nav_Menu_Edit_Roles.php`. I can't know *where* this file is in your plugin/theme. Please don't ask me, but here's what the beginning of that class will look like:
96
-
97
- `class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {}`
98
-
99
- Note that the class name is the same as the class name you found in step 1.
100
-
101
- 3. Find the `start_el()` method
102
-
103
- In that file you will eventually see a class method that looks like:
104
-
105
- `function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {`
106
-
107
- 4. Paste my action hook somewhere in this method!
108
-
109
- In Nav Menu Roles, I have placed the hook directly after the description, ex:
110
-
111
- `
112
- <p class="field-description description description-wide">
113
- <label for="edit-menu-item-description-<?php echo $item_id; ?>">
114
- <?php _e( 'Description' ); ?><br />
115
- <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>
116
- <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
117
- </label>
118
- </p>
119
-
120
- <?php
121
- // Add this directly after the description paragraph in the start_el() method
122
- do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
123
- // end added section
124
- ?>
125
- `
126
-
127
- = Workaround #2 =
128
-
129
- As a workaround, you can switch to a default theme (or disable the conflicting plugin), edit the Nav Menu Roles, for each menu item, then revert to your original theme/ reenable the conflicting plugin. The front-end functionality of Nav Menu Roles will still work.
130
-
131
- = I'm using XYZ Membership plugin and I don't see its "levels"? =
132
-
133
- There are apparently a few membership plugins out there that *don't* use traditional WordPress roles/capabilities. My plugin will list any role registered in the traditional WordPress way. If your membership plugin is using some other system, then Nav Menu Roles won't work with it out of the box. Since 1.3.5 I've added a filter called `nav_menu_roles_item_visibility` just before my code decides whether to show/hide a menu item. There's also always been the `nav_menu_roles` filter which lets you modify the roles listed in the admin. Between these two, I believe you have enough to integrate Nav Menu Roles with any membership plugin.
134
-
135
- Here's an example where I've added a new pseudo role, creatively called "new-role". The first function adds it to the menu item admin screen. The second function is pretty generic and won't actually do anything because you need to supply your own logic based on the plugin you are using. Nav Menu Roles will save the new "role" info and add it to the item in an array to the `$item->roles` variable.
136
-
137
- = <a id="new-role"></a>Adding a new "role" =
138
-
139
- `
140
- /*
141
- * Add custom roles to Nav Menu Roles menu list
142
- * param: $roles an array of all available roles, by default is global $wp_roles
143
- * return: array
144
- */
145
- function kia_new_roles( $roles ){
146
- $roles['new-role-key'] = 'new-role';
147
- return $roles;
148
- }
149
- add_filter( 'nav_menu_roles', 'kia_new_roles' );
150
- `
151
-
152
- Note, if you want to add a WordPress capability the above is literally all you need. Because Nav Menu Roles checks whether a role has permission to view the menu item using `current_user_can($role) you do not need to right a custom callback for the `nav_menu_roles_item_visibility` filter.
153
-
154
- In case you *do* need to check your visibility status against something very custom, here is how you'd go about it:
155
-
156
- `
157
- /*
158
- * Change visibilty of each menu item
159
- * param: $visible boolean
160
- * param: $item object, the complete menu object. Nav Menu Roles adds its info to $item->roles
161
- * $item->roles can be "in" (all logged in), "out" (all logged out) or an array of specific roles
162
- * return boolean
163
- */
164
- function kia_item_visibility( $visible, $item ){
165
- if( isset( $item->roles ) && is_array( $item->roles ) && in_array( 'new-role-key', $item->roles ) ){
166
- /* if ( // your own custom check on the current user versus 'new-role' status ){
167
- $visible = true;
168
- } else {
169
- $visible = false;
170
- }
171
- */ }
172
- return $visible;
173
- }
174
- add_filter( 'nav_menu_roles_item_visibility', 'kia_item_visibility', 10, 2 );
175
- `
176
-
177
- Note that you have to generate your own if/then logic. I can't provide free support for custom integration with another plugin. You may [contact me](http://kathyisawesome.com/contact) to discuss hiring me, or I would suggest using a plugin that supports WordPress' roles, such as Justin Tadlock's [Members](http://wordpress.org/plugins/members).
178
-
179
- = The menu exploded? Why are all my pages displaying for logged out users? =
180
-
181
- If every item in your menu is configured to display to logged in users (either all logged in users, or by specific role), then when a logged out visitor comes to your site there are no items in the menu to display. `wp_nav_menu()` will then try check its `fallback_cb` argument... which defaults to `wp_page_menu`.
182
-
183
- Therefore, if you have no items to display, WordPress will end up displaying ALL your pages!!
184
-
185
- If you don't want this, you must set the fallback argument to be a null string.
186
-
187
- `
188
- wp_nav_menu( array( 'theme_location' => 'primary-menu', 'fallback_cb' => '' ) );
189
- `
190
-
191
- = What happened to my menu roles on import/export? =
192
-
193
- The Nav Menu Roles plugin stores 1 piece of post *meta* to every menu item/post. This is exported just fine by the default Export tool.
194
-
195
- However, the Import plugin only imports certain post meta for menu items. As of version 1.3, I've added a custom Importer to Nav Menu Roles as a work around.
196
-
197
- = How Do I Use the Custom Importer? =
198
-
199
- 1. Go to Tools>Export, choose to export All Content and download the Export file
200
- 1. Go to Tools>Import on your new site and perform your normal WordPress import
201
- 1. Return to Tools>Import and this time select the Nav Menu Roles importer.
202
- 1. Use the same .xml file and perform a second import
203
- 1. No duplicate posts will be created but all menu post meta (including your Nav Menu Roles info) will be imported
204
-
205
- == Changelog ==
206
-
207
- = 1.7.3 =
208
- * update readme, update error notice, add more links to the FAQ
209
-
210
- = 1.7.2 =
211
- * add Italian language. props @sododesign
212
-
213
- = 1.7.1 =
214
- * Updated FAQ with patch instructions for conflicting plugins/themes
215
- * add Portugeuse language. props @brunobarros
216
-
217
- = 1.7.0 =
218
- * adjust admin UI to be more user-friendly. Options are now: show to everyone, show to logged out users, and show to logged in users (optionally, logged in users by specific role)
219
-
220
- = 1.6.5 =
221
- * add Guajarati language. props @rohilmistry93
222
-
223
- = 1.6.4 =
224
- * more language issues -> sync svn+git version numbers
225
-
226
- = 1.6.3 =
227
- * Try again to add languages. Where'd they all go?
228
-
229
- = 1.6.2 =
230
- * Add French translation. Props @Philippe Gilles
231
-
232
- = 1.6.1 =
233
- * Update list of conflits
234
- * Don't display radio buttons if no roles - allows for granular permissions control
235
-
236
- = 1.6.0 =
237
- * Feature: Hiding a parent menu item will automatically hide all its children
238
- * Feature: Add compatibility with Menu Item Visibility Control plugin and any plugin/theme that is willing to add its inputs via the `wp_nav_menu_item_custom_fields` hook. See the [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/#compatibility) to make our plugins compatible.
239
-
240
- = 1.5.1 =
241
- * Hopefully fix missing nav-menu-roles.min.js SVN issue
242
-
243
- = 1.5.0 =
244
- * Switch to instance of plugin
245
- * Add notice when conflicting plugins are detected
246
- * Remove some extraneous parameters
247
- * Add Spanish translation thanks to @deskarrada
248
-
249
- = 1.4.1 =
250
- * update to WP 3.8 version of Walker_Nav_Menu_Edit (prolly not any different from 3.7.1)
251
- * minor CSS adjustment to admin menu items
252
- * checked against WP 3.8
253
-
254
- = 1.4 =
255
- * Add to FAQ
256
- * add JS flair to admin menu items
257
- * update to WP 3.7.1 version of Walker_Nav_Menu_Edit
258
-
259
- = 1.3.5 =
260
- * Add nav_menu_roles_item_visibility filter to work with plugins that don't use traditional roles
261
-
262
- = 1.3.4 =
263
- * Update admin language thanks to @hassanhamm
264
- * Add Arabic translation thanks to @hassanhamm
265
-
266
- = 1.3.3 =
267
- * Fix Nav_Menu_Roles_Import not found error
268
-
269
- = 1.3.2 =
270
- * Stupid comment error causing save issues
271
-
272
- = 1.3.1 =
273
- * SVN failure to include importer files!
274
-
275
- = 1.3 =
276
- * Added custom importer
277
-
278
- = 1.2 =
279
- * Major fix for theme's that use their own custom Walkers, thanks to Evan Stein @vanpop http://vanpop.com/
280
- * Instead of a custom nav Walker, menu items are controlled through the wp_get_nav_menu_items filter
281
- * Remove the custom nav Walker code
282
-
283
- = 1.1.1 =
284
- * Fix link to plugin site
285
- * Fix labels in admin Walker
286
-
287
- = 1.1 =
288
- * Clean up debug messages
289
-
290
- = 1.0 =
 
 
 
 
291
  * Initial release
1
+ === Nav Menu Roles ===
2
+
3
+ Contributors: helgatheviking
4
+ Donate link: https://www.paypal.me/helgatheviking
5
+ Tags: menu, menus, nav menu, nav menus
6
+ Requires at least: 3.8.0
7
+ Tested up to: 4.4.0
8
+ Stable tag: 1.7.4
9
+ License: GPLv3
10
+
11
+ Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
12
+
13
+ == Description ==
14
+
15
+ This plugin lets you hide custom menu items based on user roles. So if you have a link in the menu that you only want to show to logged in users, certain types of users, or even only to logged out users, this plugin is for you.
16
+
17
+ Nav Menu Roles is very flexible. In addition to standard user roles, you can customize the functionality by adding your own check boxes with custom labels using the `nav_menu_roles` filter and then using the `nav_menu_roles_item_visibility` filter to check against whatever criteria you need. You can check against any user meta values (like capabilities) and any custom attributes added by other plugins. See the [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/#new-role).
18
+
19
+ = IMPORTANT NOTE =
20
+
21
+ In WordPress menu items and pages are completely separate entities. Nav Menu Roles does not restrict access to content. Nav Menu Roles is *only* for showing/hiding *nav menu* items. If you wish to restrict content then you need to also be using a membership plugin.
22
+
23
+ = Usage =
24
+
25
+ 1. Go to Appearance > Menus
26
+ 1. Edit the menu items accordingly. First select whether you'd like to display the item to all logged in users, all logged out users or to customize by role.
27
+ 1. If you chose customize by role, then you can check the boxes next to the roles you'd like to restrict visibility to.
28
+ 1. If you choose 'By Role' and don't check any boxes, the item will be visible to everyone like normal.
29
+
30
+ = Support =
31
+
32
+ Support is handled in the [WordPress forums](https://wordpress.org/support/plugin/nav-menu-roles). Please note that support is limited and does not cover any custom implementation of the plugin. Before posting, please read the [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/). Also, please verify the problem with other plugins disabled and while using a default theme.
33
+
34
+ Please report any bugs, errors, warnings, code problems to [Github](https://github.com/helgatheviking/nav-menu-roles/issues)
35
+
36
+ == Installation ==
37
+
38
+ 1. Upload the `plugin` folder to the `/wp-content/plugins/` directory
39
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
40
+ 1. Go to Appearance > Menus
41
+ 1. Edit the menu items accordingly. First select whether you'd like to display the item to Everyone, all logged out users, or all logged in users.
42
+ 1. Logged in users can be further limited to specific roles by checking the boxes next to the roles you'd like to restrict visibility to.
43
+
44
+ == Screenshots ==
45
+
46
+ 1. Show the new options for the menu items in the admin menu customizer
47
+
48
+ == Frequently Asked Questions ==
49
+
50
+ = <a id="conflict"></a>I don't see the Nav Menu Roles options in the admin menu items? =
51
+
52
+ This is because you have another plugin (or theme) that is also trying to alter the same code that creates the Menu section in the admin.
53
+
54
+ WordPress does not have sufficient hooks in this area of the admin and until they do plugins are forced to replace everything via custom admin menu Walker, of which there can be only one. There's a [trac ticket](http://core.trac.wordpress.org/ticket/18584) for this, but it has been around a while.
55
+
56
+ **A non-exhaustive list of known conflicts:**
57
+
58
+ 1. UberMenu 2.x Mega Menus plugin
59
+ 2. Add Descendants As Submenu Items plugin
60
+ 3. Navception plugin
61
+ 4. Suffusion theme
62
+ 5. BeTheme
63
+ 6. Yith Menu
64
+ 7. Jupiter Theme
65
+
66
+
67
+ = <a id="compatibility"></a>Workaround #1 =
68
+ [Shazdeh](https://profiles.wordpress.org/shazdeh/) had the genius idea to not wait for a core hook and simply add the hook ourselves. If all plugin and theme authors use the same hook, we can make our plugins play together.
69
+
70
+ Therefore, as of version 1.6 I am modifying my admin nav menu Walker to *only* adding the following lines (right after the description input):
71
+
72
+ `
73
+ <?php
74
+ // Place this in your admin nav menu Walker
75
+ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
76
+ // end added section
77
+ ?>
78
+ `
79
+
80
+ **Ask your conflicting plugin/theme's author to add this code to his plugin or theme and our plugins will become compatible.**
81
+
82
+ = <a id="patch"></a>Patching Your Plugin/Theme =
83
+
84
+ Should you wish to attempt this patch yourself, you can modify your conflicting plugin/theme's admin menu Walker class. **Reminder: I do not provide support for fixing your plugin/theme. If you aren't comfortable with the following instructions, contact the developer of the conflicting plugin/theme!**
85
+
86
+ 1. Find the class that extends the `Walker_Nav_Menu`. As a hint, it is filtering `wp_edit_nav_menu_walker` and you might even be getting a warning about it from Nav Menu Roles. Example:
87
+
88
+ `
89
+ add_filter( 'wp_edit_nav_menu_walker', 'sample_edit_nav_menu_walker');
90
+ function sample_edit_nav_menu_walker( $walker ) {
91
+ return 'Walker_Nav_Menu_Edit_Roles'; // this is the class name
92
+ }
93
+ `
94
+
95
+ 2. Find the file for the extending class. In my plugin this is in a file located at `inc/class.Walker_Nav_Menu_Edit_Roles.php`. I can't know *where* this file is in your plugin/theme. Please don't ask me, but here's what the beginning of that class will look like:
96
+
97
+ `class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {}`
98
+
99
+ Note that the class name is the same as the class name you found in step 1.
100
+
101
+ 3. Find the `start_el()` method
102
+
103
+ In that file you will eventually see a class method that looks like:
104
+
105
+ `function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {`
106
+
107
+ 4. Paste my action hook somewhere in this method!
108
+
109
+ In Nav Menu Roles, I have placed the hook directly after the description, ex:
110
+
111
+ `
112
+ <p class="field-description description description-wide">
113
+ <label for="edit-menu-item-description-<?php echo $item_id; ?>">
114
+ <?php _e( 'Description' ); ?><br />
115
+ <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>
116
+ <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
117
+ </label>
118
+ </p>
119
+
120
+ <?php
121
+ // Add this directly after the description paragraph in the start_el() method
122
+ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
123
+ // end added section
124
+ ?>
125
+ `
126
+
127
+ = Workaround #2 =
128
+
129
+ As a workaround, you can switch to a default theme (or disable the conflicting plugin), edit the Nav Menu Roles, for each menu item, then revert to your original theme/ reenable the conflicting plugin. The front-end functionality of Nav Menu Roles will still work.
130
+
131
+ = I'm using XYZ Membership plugin and I don't see its "levels"? =
132
+
133
+ There are apparently a few membership plugins out there that *don't* use traditional WordPress roles/capabilities. My plugin will list any role registered in the traditional WordPress way. If your membership plugin is using some other system, then Nav Menu Roles won't work with it out of the box. Since 1.3.5 I've added a filter called `nav_menu_roles_item_visibility` just before my code decides whether to show/hide a menu item. There's also always been the `nav_menu_roles` filter which lets you modify the roles listed in the admin. Between these two, I believe you have enough to integrate Nav Menu Roles with any membership plugin.
134
+
135
+ Here's an example where I've added a new pseudo role, creatively called "new-role". The first function adds it to the menu item admin screen. The second function is pretty generic and won't actually do anything because you need to supply your own logic based on the plugin you are using. Nav Menu Roles will save the new "role" info and add it to the item in an array to the `$item->roles` variable.
136
+
137
+ = <a id="new-role"></a>Adding a new "role" =
138
+
139
+ `
140
+ /*
141
+ * Add custom roles to Nav Menu Roles menu list
142
+ * param: $roles an array of all available roles, by default is global $wp_roles
143
+ * return: array
144
+ */
145
+ function kia_new_roles( $roles ){
146
+ $roles['new-role-key'] = 'new-role';
147
+ return $roles;
148
+ }
149
+ add_filter( 'nav_menu_roles', 'kia_new_roles' );
150
+ `
151
+
152
+ Note, if you want to add a WordPress capability the above is literally all you need. Because Nav Menu Roles checks whether a role has permission to view the menu item using `current_user_can($role) you do not need to right a custom callback for the `nav_menu_roles_item_visibility` filter.
153
+
154
+ In case you *do* need to check your visibility status against something very custom, here is how you'd go about it:
155
+
156
+ `
157
+ /*
158
+ * Change visibilty of each menu item
159
+ * param: $visible boolean
160
+ * param: $item object, the complete menu object. Nav Menu Roles adds its info to $item->roles
161
+ * $item->roles can be "in" (all logged in), "out" (all logged out) or an array of specific roles
162
+ * return boolean
163
+ */
164
+ function kia_item_visibility( $visible, $item ){
165
+ if( isset( $item->roles ) && is_array( $item->roles ) && in_array( 'new-role-key', $item->roles ) ){
166
+ /* if ( // your own custom check on the current user versus 'new-role' status ){
167
+ $visible = true;
168
+ } else {
169
+ $visible = false;
170
+ }
171
+ */ }
172
+ return $visible;
173
+ }
174
+ add_filter( 'nav_menu_roles_item_visibility', 'kia_item_visibility', 10, 2 );
175
+ `
176
+
177
+ Note that you have to generate your own if/then logic. I can't provide free support for custom integration with another plugin. You may [contact me](http://kathyisawesome.com/contact) to discuss hiring me, or I would suggest using a plugin that supports WordPress' roles, such as Justin Tadlock's [Members](http://wordpress.org/plugins/members).
178
+
179
+ = The menu exploded? Why are all my pages displaying for logged out users? =
180
+
181
+ If every item in your menu is configured to display to logged in users (either all logged in users, or by specific role), then when a logged out visitor comes to your site there are no items in the menu to display. `wp_nav_menu()` will then try check its `fallback_cb` argument... which defaults to `wp_page_menu`.
182
+
183
+ Therefore, if you have no items to display, WordPress will end up displaying ALL your pages!!
184
+
185
+ If you don't want this, you must set the fallback argument to be a null string.
186
+
187
+ `
188
+ wp_nav_menu( array( 'theme_location' => 'primary-menu', 'fallback_cb' => '' ) );
189
+ `
190
+
191
+ = What happened to my menu roles on import/export? =
192
+
193
+ The Nav Menu Roles plugin stores 1 piece of post *meta* to every menu item/post. This is exported just fine by the default Export tool.
194
+
195
+ However, the Import plugin only imports certain post meta for menu items. As of version 1.3, I've added a custom Importer to Nav Menu Roles as a work around.
196
+
197
+ = How Do I Use the Custom Importer? =
198
+
199
+ 1. Go to Tools>Export, choose to export All Content and download the Export file
200
+ 1. Go to Tools>Import on your new site and perform your normal WordPress import
201
+ 1. Return to Tools>Import and this time select the Nav Menu Roles importer.
202
+ 1. Use the same .xml file and perform a second import
203
+ 1. No duplicate posts will be created but all menu post meta (including your Nav Menu Roles info) will be imported
204
+
205
+ == Changelog ==
206
+
207
+ = 1.7.4 =
208
+ * Change language in metabox to try to explain min caps versus strict role checking
209
+ * keep tweaking the FAQ
210
+
211
+ = 1.7.3 =
212
+ * update readme, update error notice, add more links to the FAQ
213
+
214
+ = 1.7.2 =
215
+ * add Italian language. props @sododesign
216
+
217
+ = 1.7.1 =
218
+ * Updated FAQ with patch instructions for conflicting plugins/themes
219
+ * add Portugeuse language. props @brunobarros
220
+
221
+ = 1.7.0 =
222
+ * adjust admin UI to be more user-friendly. Options are now: show to everyone, show to logged out users, and show to logged in users (optionally, logged in users by specific role)
223
+
224
+ = 1.6.5 =
225
+ * add Guajarati language. props @rohilmistry93
226
+
227
+ = 1.6.4 =
228
+ * more language issues -> sync svn+git version numbers
229
+
230
+ = 1.6.3 =
231
+ * Try again to add languages. Where'd they all go?
232
+
233
+ = 1.6.2 =
234
+ * Add French translation. Props @Philippe Gilles
235
+
236
+ = 1.6.1 =
237
+ * Update list of conflits
238
+ * Don't display radio buttons if no roles - allows for granular permissions control
239
+
240
+ = 1.6.0 =
241
+ * Feature: Hiding a parent menu item will automatically hide all its children
242
+ * Feature: Add compatibility with Menu Item Visibility Control plugin and any plugin/theme that is willing to add its inputs via the `wp_nav_menu_item_custom_fields` hook. See the [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/#compatibility) to make our plugins compatible.
243
+
244
+ = 1.5.1 =
245
+ * Hopefully fix missing nav-menu-roles.min.js SVN issue
246
+
247
+ = 1.5.0 =
248
+ * Switch to instance of plugin
249
+ * Add notice when conflicting plugins are detected
250
+ * Remove some extraneous parameters
251
+ * Add Spanish translation thanks to @deskarrada
252
+
253
+ = 1.4.1 =
254
+ * update to WP 3.8 version of Walker_Nav_Menu_Edit (prolly not any different from 3.7.1)
255
+ * minor CSS adjustment to admin menu items
256
+ * checked against WP 3.8
257
+
258
+ = 1.4 =
259
+ * Add to FAQ
260
+ * add JS flair to admin menu items
261
+ * update to WP 3.7.1 version of Walker_Nav_Menu_Edit
262
+
263
+ = 1.3.5 =
264
+ * Add nav_menu_roles_item_visibility filter to work with plugins that don't use traditional roles
265
+
266
+ = 1.3.4 =
267
+ * Update admin language thanks to @hassanhamm
268
+ * Add Arabic translation thanks to @hassanhamm
269
+
270
+ = 1.3.3 =
271
+ * Fix Nav_Menu_Roles_Import not found error
272
+
273
+ = 1.3.2 =
274