is_dev() ) { add_action( 'wp_nav_menu_item_custom_fields_customize_template', [ __CLASS__, 'custom_fields_customize_template' ] ); // add_action( 'customize_controls_print_footer_scripts', [ __CLASS__, 'print_scripts' ] ); } } static function enqueue_admin_script($hook_suffix) { if ($hook_suffix !== 'nav-menus.php') { return; } amem_register_script( 'amem-menus', amem_get_url("amem-menus{$min}.js", 'assets/js'), ['jquery'], AMEM_VERSION, ['in_footer' => true, 'asset_path' => amem_get_path('', 'assets/js')] ); wp_enqueue_script( 'amem-menus' ); } /** * Render fields for each menu item. * * @param int $item_id Item ID. * @param object $item Item object. * @param int $depth Current menu item depth. * @param array $args Additional array of arguments. */ public static function fields( $item_id, $item, $depth, $args ) { $allowed_user_roles = amem_allowed_roles(); wp_nonce_field( 'amem-menu-nonce', 'amem-menu-nonce' ); $filter_users = [ '' => __( 'Everyone', 'advanced-members' ), 'logged_out' => __( 'Logged Out Users', 'advanced-members' ), 'logged_in' => __( 'Logged In Users', 'advanced-members' ), ]; $none_amem = true; $menu_type = false; $roleCSS = (isset($item->filter_users) && $item->filter_users == 'logged_in') ? '' : ' acf-hidden'; // if ( $item->object == 'page' ) { // $menu_type = array_search( $item->object_id, amem()->options->get_core_pages() ); // } ?>


$label ) : ?>

$role ) { if ( ! array_key_exists( $role, $allowed_roles ) ) { unset( $item_options['roles'][ $key ] ); } } } else { unset( $item_options['roles'] ); } // Remove empty options to save space. $item_options = array_filter( $item_options ); if ( ! empty( $item_options ) ) { update_post_meta( $item_id, '_amem_nav_item', $item_options ); } else { delete_post_meta( $item_id, '_amem_nav_item' ); } } static function custom_fields_customize_template() { $allowed_user_roles = amem_allowed_roles(); wp_nonce_field( 'amem-menu-nonce', 'amem-menu-nonce' ); $filter_users = [ '' => __( 'Everyone', 'advanced-members' ), 'logged_out' => __( 'Logged Out Users', 'advanced-members' ), 'logged_in' => __( 'Logged In Users', 'advanced-members' ), ]; ?> <# var filterUsers = , filterRoles = , menuItemAMem = _wpCustomizeSettings.settings['nav_menu_item['+ data.menu_item_id +']'] || {}, amemFilterUser = menuItemAMem.value.filter_users || {}, amemFilterRole = menuItemAMem.value.roles || {}, roleCSS = (amemFilterUser != 'logged_in') ? 'acf-hidden' : ''; #>


<# _.each( filterRoles, function(value, key, $) { is_checked = _.some(amemFilterRole, function(f) { return f == key; }); checked = (is_checked) ? 'checked="checked"' : ''; #> <# } ); #>