Automattic\WooCommerce\Admin\Features\Navigation

Menu::get_post_type_items()public staticWC 1.0

Get menu item templates for a given post type.

Method of the class: Menu{}

No Hooks.

Return

Array.

Usage

$result = Menu::get_post_type_items( $post_type, $menu_args );
$post_type(string) (required)
Post type to add.
$menu_args(array)
Arguments merged with the returned menu items.
Default: array()

Menu::get_post_type_items() code WC 8.7.0

public static function get_post_type_items( $post_type, $menu_args = array() ) {
	$post_type_object = get_post_type_object( $post_type );

	if ( ! $post_type_object || ! $post_type_object->show_in_menu ) {
		return;
	}

	$parent           = isset( $menu_args['parent'] ) ? $menu_args['parent'] . '-' : '';
	$match_expression = isset( $_GET['post'] ) && get_post_type( intval( $_GET['post'] ) ) === $post_type // phpcs:ignore WordPress.Security.NonceVerification
		? '(edit.php|post.php)'
		: null;

	return array(
		'default' => array_merge(
			array(
				'title'           => esc_attr( $post_type_object->labels->menu_name ),
				'capability'      => $post_type_object->cap->edit_posts,
				'id'              => $parent . $post_type,
				'url'             => "edit.php?post_type={$post_type}",
				'matchExpression' => $match_expression,
			),
			$menu_args
		),
		'all'     => array_merge(
			array(
				'title'           => esc_attr( $post_type_object->labels->all_items ),
				'capability'      => $post_type_object->cap->edit_posts,
				'id'              => "{$parent}{$post_type}-all-items",
				'url'             => "edit.php?post_type={$post_type}",
				'order'           => 10,
				'matchExpression' => $match_expression,
			),
			$menu_args
		),
		'new'     => array_merge(
			array(
				'title'      => esc_attr( $post_type_object->labels->add_new ),
				'capability' => $post_type_object->cap->create_posts,
				'id'         => "{$parent}{$post_type}-add-new",
				'url'        => "post-new.php?post_type={$post_type}",
				'order'      => 20,
			),
			$menu_args
		),
	);
}