123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Location_Nav_Menu' ) ) :
- class ACF_Location_Nav_Menu extends ACF_Location {
-
- public function initialize() {
- $this->name = 'nav_menu';
- $this->label = __( 'Menu', 'acf' );
- $this->category = 'forms';
- $this->object_type = 'menu';
- }
-
- public function match( $rule, $screen, $field_group ) {
-
- if ( isset( $screen['nav_menu'] ) ) {
- $nav_menu = $screen['nav_menu'];
- } else {
- return false;
- }
-
- $bits = explode( '/', $rule['value'] );
- if ( $bits[0] === 'location' ) {
- $location = $bits[1];
-
- $menu_locations = get_nav_menu_locations();
- if ( isset( $menu_locations[ $location ] ) ) {
- $rule['value'] = $menu_locations[ $location ];
- }
- }
-
- return $this->compare_to_rule( $nav_menu, $rule );
- }
-
- public function get_values( $rule ) {
- $choices = array(
- 'all' => __( 'All', 'acf' ),
- );
-
- $nav_locations = get_registered_nav_menus();
- if ( $nav_locations ) {
- $cat = __( 'Menu Locations', 'acf' );
- foreach ( $nav_locations as $slug => $title ) {
- $choices[ $cat ][ "location/$slug" ] = $title;
- }
- }
-
- $nav_menus = wp_get_nav_menus();
- if ( $nav_menus ) {
- $cat = __( 'Menus', 'acf' );
- foreach ( $nav_menus as $nav_menu ) {
- $choices[ $cat ][ $nav_menu->term_id ] = $nav_menu->name;
- }
- }
-
- return $choices;
- }
- }
-
- acf_register_location_type( 'ACF_Location_Nav_Menu' );
- endif;
|