bp_admin_wp_nav_menu_restrict_items

Restrict various items from view if editing a BuddyPress menu.

Description

bp_admin_wp_nav_menu_restrict_items(); 

If a person is editing a BP menu item, that person should not be able to see or edit the following fields:

- CSS Classes - We use the bp-menu CSS class to determine if the menu item belongs to BP, so we cannot allow manipulation of this field to occur. - URL - This field is automatically generated by BP on output, so this field is useless and can cause confusion.

Note: These restrictions are only enforced if JavaScript is enabled.


Usage

  1. if ( !function_exists( 'bp_admin_wp_nav_menu_restrict_items' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/admin/bp-core-admin-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_admin_wp_nav_menu_restrict_items(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-core/admin/bp-core-admin-functions.php  
  1. function bp_admin_wp_nav_menu_restrict_items() { 
  2. ?> 
  3. <script type="text/javascript"> 
  4. jQuery( '#menu-to-edit').on( 'click', 'a.item-edit', function() { 
  5. var settings = jQuery(this).closest( '.menu-item-bar' ).next( '.menu-item-settings' ); 
  6. var css_class = settings.find( '.edit-menu-item-classes' ); 
  7.  
  8. if( css_class.val().indexOf( 'bp-menu' ) === 0 ) { 
  9. css_class.attr( 'readonly', 'readonly' ); 
  10. settings.find( '.field-url' ).css( 'display', 'none' ); 
  11. }); 
  12. </script> 
  13. <?php