id : null; if ( in_array( $post_type, $post_types, true ) || in_array( $taxonomy, $taxonomies, true ) || self::is_woocommerce_core_taxonomy( $taxonomy ) || in_array( $current_screen_id, $screen_ids, true ) ) { return true; } return false; } /** * Check if a given taxonomy is a WooCommerce core related taxonomy. * * @param string $taxonomy Taxonomy. * @return bool */ public static function is_woocommerce_core_taxonomy( $taxonomy ) { if ( in_array( $taxonomy, array( 'product_cat', 'product_tag' ), true ) ) { return true; } if ( 'pa_' === substr( $taxonomy, 0, 3 ) ) { return true; } return false; } /** * Add navigation classes to body. * * @param string $classes Classes. * @return string */ public function add_body_class( $classes ) { if ( self::is_woocommerce_page() ) { $classes .= ' has-woocommerce-navigation'; /** * Adds the ability to skip disabling of the WP toolbar. * * @param boolean $bool WP Toolbar disabled. */ if ( apply_filters( 'woocommerce_navigation_wp_toolbar_disabled', true ) ) { $classes .= ' is-wp-toolbar-disabled'; } } return $classes; } /** * Adds a screen ID to the list of screens that use the navigtion. * Finds the parent if none is given to grab the correct screen ID. * * @param string $callback Callback or URL for page. * @param string|null $parent Parent screen ID. */ public static function add_screen( $callback, $parent = null ) { global $submenu; $plugin_page = self::get_plugin_page( $callback ); if ( ! $parent ) { $parent = Menu::get_parent_key( $callback ); } $screen_id = get_plugin_page_hookname( $plugin_page, $parent ); // This screen has already been added. if ( in_array( $screen_id, self::$screen_ids, true ) ) { return; } self::$screen_ids[] = $screen_id; } /** * Get the plugin page slug. * * @param string $callback Callback. * @return string */ public static function get_plugin_page( $callback ) { $url = Menu::get_callback_url( $callback ); $parts = wp_parse_url( $url ); if ( ! isset( $parts['query'] ) ) { return $callback; } parse_str( $parts['query'], $query ); if ( ! isset( $query['page'] ) ) { return $callback; } $plugin_page = wp_unslash( $query['page'] ); $plugin_page = plugin_basename( $plugin_page ); return $plugin_page; } /** * Register post type for use in WooCommerce Navigation screens. * * @param string $post_type Post type to add. */ public static function register_post_type( $post_type ) { if ( ! in_array( $post_type, self::$post_types, true ) ) { self::$post_types[] = $post_type; } } /** * Register taxonomy for use in WooCommerce Navigation screens. * * @param string $taxonomy Taxonomy to add. */ public static function register_taxonomy( $taxonomy ) { if ( ! in_array( $taxonomy, self::$taxonomies, true ) ) { self::$taxonomies[] = $taxonomy; } } }