bp_admin_wp_nav_menu_restrict_items()

Restrict various items from view if editing a BuddyPress menu.

Description

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.

Source

File: bp-core/admin/bp-core-admin-functions.php

function bp_admin_wp_nav_menu_restrict_items() {
?>
	<script>
		jQuery( '#menu-to-edit').on( 'click', 'a.item-edit', function() {
			var settings  = jQuery(this).closest( '.menu-item-bar' ).next( '.menu-item-settings' );
			var css_class = settings.find( '.edit-menu-item-classes' );

			if( css_class.val().indexOf( 'bp-menu' ) === 0 ) {
				css_class.attr( 'readonly', 'readonly' );
				settings.find( '.field-url' ).css( 'display', 'none' );
			}
		});
	</script>
<?php
}

Changelog

Changelog
Version Description
BuddyPress 1.9.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.