WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() WP 4.3.0

Get the value emulated into a WP_Post and set up as a nav_menu_item.

Это метод класса: WP_Customize_Nav_Menu_Item_Setting

Возвращает

WP_Post. With wp_setup_nav_menu_item() applied.

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

$WP_Customize_Nav_Menu_Item_Setting = new WP_Customize_Nav_Menu_Item_Setting();
$var = $WP_Customize_Nav_Menu_Item_Setting->value_as_wp_post_nav_menu_item();

Список изменений

С версии 4.3.0 Введена.

Код WP Customize Nav Menu Item Setting::value as wp post nav menu item: wp-includes/customize/class-wp-customize-nav-menu-item-setting.php WP 5.3.2

<?php
public function value_as_wp_post_nav_menu_item() {
	$item = (object) $this->value();
	unset( $item->nav_menu_term_id );

	$item->post_status = $item->status;
	unset( $item->status );

	$item->post_type  = 'nav_menu_item';
	$item->menu_order = $item->position;
	unset( $item->position );

	if ( empty( $item->original_title ) ) {
		$item->original_title = $this->get_original_title( $item );
	}
	if ( empty( $item->title ) && ! empty( $item->original_title ) ) {
		$item->title = $item->original_title;
	}
	if ( $item->title ) {
		$item->post_title = $item->title;
	}

	$item->ID    = $this->post_id;
	$item->db_id = $this->post_id;
	$post        = new WP_Post( (object) $item );

	if ( empty( $post->post_author ) ) {
		$post->post_author = get_current_user_id();
	}

	if ( ! isset( $post->type_label ) ) {
		$post->type_label = $this->get_type_label( $post );
	}

	// Ensure nav menu item URL is set according to linked object.
	if ( 'post_type' === $post->type && ! empty( $post->object_id ) ) {
		$post->url = get_permalink( $post->object_id );
	} elseif ( 'taxonomy' === $post->type && ! empty( $post->object ) && ! empty( $post->object_id ) ) {
		$post->url = get_term_link( (int) $post->object_id, $post->object );
	} elseif ( 'post_type_archive' === $post->type && ! empty( $post->object ) ) {
		$post->url = get_post_type_archive_link( $post->object );
	}
	if ( is_wp_error( $post->url ) ) {
		$post->url = '';
	}

	/** This filter is documented in wp-includes/nav-menu.php */
	$post->attr_title = apply_filters( 'nav_menu_attr_title', $post->attr_title );

	/** This filter is documented in wp-includes/nav-menu.php */
	$post->description = apply_filters( 'nav_menu_description', wp_trim_words( $post->description, 200 ) );

	/** This filter is documented in wp-includes/nav-menu.php */
	$post = apply_filters( 'wp_setup_nav_menu_item', $post );

	return $post;
}