Automattic\WooCommerce\Admin
PageController::get_current_screen_id()
Returns the current screen ID.
This is slightly different from WP's get_current_screen, in that it attaches an action, so certain pages like 'add new' pages can have different breadcrumbs or handling. It also catches some more unique dynamic pages like taxonomy/attribute management.
Format:
- {$current_screen->action}-{$current_screen->action}-tab-section
- {$current_screen->action}-{$current_screen->action}-tab
- {$current_screen->action}-{$current_screen->action} if no tab is present
- {$current_screen->action} if no action or tab is present
Method of the class: PageController{}
Hooks from the method
Return
String
. Current screen ID.
Usage
$PageController = new PageController(); $PageController->get_current_screen_id();
PageController::get_current_screen_id() PageController::get current screen id code WC 9.6.1
public function get_current_screen_id() { $current_screen = get_current_screen(); if ( ! $current_screen ) { // Filter documentation below. return apply_filters( 'woocommerce_navigation_current_screen_id', false, $current_screen ); } $screen_pieces = array( $current_screen->id ); if ( $current_screen->action ) { $screen_pieces[] = $current_screen->action; } if ( ! empty( $current_screen->taxonomy ) && isset( $current_screen->post_type ) && 'product' === $current_screen->post_type ) { // Editing a product attribute. if ( 0 === strpos( $current_screen->taxonomy, 'pa_' ) ) { $screen_pieces = array( 'product_page_product_attribute-edit' ); } // Editing a product taxonomy term. if ( ! empty( $_GET['tag_ID'] ) ) { $screen_pieces = array( $current_screen->taxonomy ); } } // Pages with default tab values. $pages_with_tabs = apply_filters( 'woocommerce_navigation_pages_with_tabs', array( 'wc-reports' => 'orders', 'wc-settings' => 'general', 'wc-status' => 'status', 'wc-addons' => 'browse-extensions', ) ); // Tabs that have sections as well. $wc_emails = \WC_Emails::instance(); $wc_email_ids = array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) ); $tabs_with_sections = apply_filters( 'woocommerce_navigation_page_tab_sections', array( 'products' => array( '', 'inventory', 'downloadable' ), 'shipping' => array( '', 'options', 'classes' ), 'checkout' => array( 'bacs', 'cheque', 'cod', 'paypal' ), 'email' => $wc_email_ids, 'advanced' => array( '', 'keys', 'webhooks', 'legacy_api', 'woocommerce_com', ), 'browse-extensions' => array( 'helper' ), ) ); if ( ! empty( $_GET['page'] ) ) { $page = wc_clean( wp_unslash( $_GET['page'] ) ); if ( in_array( $page, array_keys( $pages_with_tabs ) ) ) { if ( ! empty( $_GET['tab'] ) ) { $tab = wc_clean( wp_unslash( $_GET['tab'] ) ); } else { $tab = $pages_with_tabs[ $page ]; } $screen_pieces[] = $tab; if ( ! empty( $_GET['section'] ) ) { $section = wc_clean( wp_unslash( $_GET['section'] ) ); if ( isset( $tabs_with_sections[ $tab ] ) && in_array( $section, array_keys( $tabs_with_sections[ $tab ] ) ) ) { $screen_pieces[] = $section; } } // Editing a shipping zone. if ( ( 'shipping' === $tab ) && isset( $_GET['zone_id'] ) ) { $screen_pieces[] = 'edit_zone'; } } } /** * The current screen id. * * Used for identifying pages to render the WooCommerce Admin header. * * @param string|boolean $screen_id The screen id or false if not identified. * @param WP_Screen $current_screen The current WP_Screen. */ return apply_filters( 'woocommerce_navigation_current_screen_id', implode( '-', $screen_pieces ), $current_screen ); }