ACF_Walker_Nav_Menu_Edit{}ACF 1.0

Хуки из класса

Использование

$ACF_Walker_Nav_Menu_Edit = new ACF_Walker_Nav_Menu_Edit();
// use class methods

Методы

  1. public get_fields( $item, $depth, $args = array(), $id = 0 )
  2. public start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )

Код ACF_Walker_Nav_Menu_Edit{} ACF 5.10.2

class ACF_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {

	/**
	 * Starts the element output.
	 *
	 * Calls the Walker_Nav_Menu_Edit start_el function and then injects the custom field HTML
	 *
	 * @since 5.0.0
	 * @since 5.7.2 Added preg_replace based on https://github.com/ineagu/wp-menu-item-custom-fields
	 *
	 * @param string   $output Used to append additional content (passed by reference).
	 * @param WP_Post  $item   Menu item data object.
	 * @param int      $depth  Depth of menu item. Used for padding.
	 * @param stdClass $args   An object of wp_nav_menu() arguments.
	 * @param int      $id     Current item ID.
	 */
	function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {

		// vars
		$item_output = '';

		// call parent function
		parent::start_el( $item_output, $item, $depth, $args, $id );

		// inject custom field HTML
		$output .= preg_replace(
		// NOTE: Check this regex from time to time!
			'/(?=<(fieldset|p)[^>]+class="[^"]*field-move)/',
			$this->get_fields( $item, $depth, $args, $id ),
			$item_output
		);
	}


	/**
	 * Get custom fields HTML
	 *
	 * @since 5.0.0
	 * @since 5.7.2 Added action based on https://github.com/ineagu/wp-menu-item-custom-fields
	 *
	 * @param object $item   Menu item data object.
	 * @param int    $depth  Depth of menu item. Used for padding.
	 * @param array  $args   Menu item args.
	 * @param int    $id     Nav menu ID.
	 * @return string
	 */
	function get_fields( $item, $depth, $args = array(), $id = 0 ) {
		ob_start();

		/**
		 * Get menu item custom fields from plugins/themes
		 *
		 * @since 5.7.2
		 *
		 * @param int    $item_id   post ID of menu
		 * @param object $item      Menu item data object.
		 * @param int    $depth     Depth of menu item. Used for padding.
		 * @param array  $args      Menu item args.
		 * @param int    $id        Nav menu ID.
		 */
		do_action( 'wp_nav_menu_item_custom_fields', $item->ID, $item, $depth, $args, $id );
		return ob_get_clean();
	}
}