class-acf-location-nav-menu-item.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Location_Nav_Menu_Item' ) ) :
  6. class ACF_Location_Nav_Menu_Item extends ACF_Location {
  7. /**
  8. * Initializes props.
  9. *
  10. * @date 5/03/2014
  11. * @since 5.0.0
  12. *
  13. * @param void
  14. * @return void
  15. */
  16. public function initialize() {
  17. $this->name = 'nav_menu_item';
  18. $this->label = __( 'Menu Item', 'acf' );
  19. $this->category = 'forms';
  20. $this->object_type = 'menu_item';
  21. }
  22. /**
  23. * Matches the provided rule against the screen args returning a bool result.
  24. *
  25. * @date 9/4/20
  26. * @since 5.9.0
  27. *
  28. * @param array $rule The location rule.
  29. * @param array $screen The screen args.
  30. * @param array $field_group The field group settings.
  31. * @return bool
  32. */
  33. public function match( $rule, $screen, $field_group ) {
  34. // Check screen args.
  35. if ( isset( $screen['nav_menu_item'] ) ) {
  36. $nav_menu_item = $screen['nav_menu_item'];
  37. } else {
  38. return false;
  39. }
  40. // Append "nav_menu" global data to $screen and call 'nav_menu' logic.
  41. if ( ! isset( $screen['nav_menu'] ) ) {
  42. $screen['nav_menu'] = acf_get_data( 'nav_menu_id' );
  43. }
  44. return acf_get_location_type( 'nav_menu' )->match( $rule, $screen, $field_group );
  45. }
  46. /**
  47. * Returns an array of possible values for this rule type.
  48. *
  49. * @date 9/4/20
  50. * @since 5.9.0
  51. *
  52. * @param array $rule A location rule.
  53. * @return array
  54. */
  55. public function get_values( $rule ) {
  56. return acf_get_location_type( 'nav_menu' )->get_values( $rule );
  57. }
  58. }
  59. // Register.
  60. acf_register_location_type( 'ACF_Location_Nav_Menu_Item' );
  61. endif; // class_exists check