Automattic\WooCommerce\Internal\Admin

LegacyReportsMenu::handle_admin_menu │ public │ WC 1.0

Hide the Reports menu item at the end of admin_menu.

Runs on admin_menu rather than admin_head, since requests that only build the menu, such as the Calypso sidebar's /wpcom/v2/admin-menu endpoint, never reach admin_head.

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

Хуков нет.

Возвращает

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

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

$LegacyReportsMenu = new LegacyReportsMenu();
$LegacyReportsMenu->handle_admin_menu(): void;

Код LegacyReportsMenu::handle_admin_menu() WC 11.3.0

public function handle_admin_menu(): void {
	if ( ! current_user_can( 'view_woocommerce_reports' ) || $this->should_show() ) {
		return;
	}

	global $menu, $submenu;

	if ( ! empty( $submenu['woocommerce'] ) && is_array( $submenu['woocommerce'] ) ) {
		$first_index = array_key_first( $submenu['woocommerce'] );
		foreach ( $submenu['woocommerce'] as $index => $item ) {
			// WordPress links the WooCommerce parent item to its first submenu entry, hidden or not.
			if ( 'wc-reports' === ( $item[2] ?? null ) && $index !== $first_index ) {
				$submenu['woocommerce'][ $index ][4] = self::add_hide_class( $item[4] ?? '' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
			}
		}
	}

	if ( ! empty( $menu ) && is_array( $menu ) ) {
		foreach ( $menu as $index => $item ) {
			if ( 'wc-reports' === ( $item[2] ?? null ) ) {
				$menu[ $index ][4] = self::add_hide_class( $item[4] ?? '' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
			}
		}
	}
}