Automattic\WooCommerce\Internal\Admin

Marketing::reorder_marketing_submenu()publicWC 1.0

Order marketing menu items alphabetically. Overview should be first, and Coupons should be second, followed by other marketing menu items.

Метод класса: Marketing{}

Хуков нет.

Возвращает

null. Ничего (null).

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

$Marketing = new Marketing();
$Marketing->reorder_marketing_submenu();

Код Marketing::reorder_marketing_submenu() WC 9.5.1

public function reorder_marketing_submenu() {
	global $submenu;

	if ( ! isset( $submenu['woocommerce-marketing'] ) ) {
		return;
	}

	$marketing_submenu = $submenu['woocommerce-marketing'];
	$new_menu_order    = array();

	// Overview should be first.
	$overview_key = array_search( 'Overview', array_column( $marketing_submenu, self::SUBMENU_NAME_KEY ), true );

	if ( false === $overview_key ) {
		/*
		 * If Overview is not found, we may be on a site with a different language.
		 * We can use a fallback and try to find the overview page by its path.
		 */
		$overview_key = array_search( 'admin.php?page=wc-admin&path=/marketing', array_column( $marketing_submenu, self::SUBMENU_LOCATION_KEY ), true );
	}

	if ( false !== $overview_key ) {
		$new_menu_order[] = $marketing_submenu[ $overview_key ];
		array_splice( $marketing_submenu, $overview_key, 1 );
	}

	// Coupons should be second.
	$coupons_key = array_search( 'Coupons', array_column( $marketing_submenu, self::SUBMENU_NAME_KEY ), true );

	if ( false === $coupons_key ) {
		/*
		 * If Coupons is not found, we may be on a site with a different language.
		 * We can use a fallback and try to find the coupons page by its path.
		 */
		$coupons_key = array_search( 'edit.php?post_type=shop_coupon', array_column( $marketing_submenu, self::SUBMENU_LOCATION_KEY ), true );
	}

	if ( false !== $coupons_key ) {
		$new_menu_order[] = $marketing_submenu[ $coupons_key ];
		array_splice( $marketing_submenu, $coupons_key, 1 );
	}

	// Sort the rest of the items alphabetically.
	usort(
		$marketing_submenu,
		function ( $a, $b ) {
			return strcmp( $a[0], $b[0] );
		}
	);

	$new_menu_order = array_merge( $new_menu_order, $marketing_submenu );

	$submenu['woocommerce-marketing'] = $new_menu_order;  //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
}