[2.5] Error handling for screen ids

Fixes #10280
This commit is contained in:
Mike Jolley 2016-02-05 12:16:41 +00:00
parent 787d36dee4
commit 3cef28efe8
7 changed files with 30 additions and 22 deletions

View File

@ -35,6 +35,7 @@ class WC_Admin_Assets {
global $wp_scripts;
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
$jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2';
// Register admin styles
@ -48,17 +49,17 @@ class WC_Admin_Assets {
wp_enqueue_style( 'woocommerce_admin_menu_styles' );
// Admin styles for WC pages only
if ( in_array( $screen->id, wc_get_screen_ids() ) ) {
if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
wp_enqueue_style( 'woocommerce_admin_styles' );
wp_enqueue_style( 'jquery-ui-style' );
wp_enqueue_style( 'wp-color-picker' );
}
if ( in_array( $screen->id, array( 'dashboard' ) ) ) {
if ( in_array( $screen_id, array( 'dashboard' ) ) ) {
wp_enqueue_style( 'woocommerce_admin_dashboard_styles' );
}
if ( in_array( $screen->id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) {
if ( in_array( $screen_id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) {
wp_enqueue_style( 'woocommerce_admin_print_reports_styles' );
}
@ -80,6 +81,7 @@ class WC_Admin_Assets {
global $wp_query, $post;
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
@ -132,7 +134,7 @@ class WC_Admin_Assets {
) );
// WooCommerce admin pages
if ( in_array( $screen->id, wc_get_screen_ids() ) ) {
if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
wp_enqueue_script( 'iris' );
wp_enqueue_script( 'woocommerce_admin' );
wp_enqueue_script( 'wc-enhanced-select' );
@ -155,18 +157,18 @@ class WC_Admin_Assets {
}
// Edit product category pages
if ( in_array( $screen->id, array( 'edit-product_cat' ) ) ) {
if ( in_array( $screen_id, array( 'edit-product_cat' ) ) ) {
wp_enqueue_media();
}
// Products
if ( in_array( $screen->id, array( 'edit-product' ) ) ) {
if ( in_array( $screen_id, array( 'edit-product' ) ) ) {
wp_register_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_enqueue_script( 'woocommerce_quick-edit' );
}
// Meta boxes
if ( in_array( $screen->id, array( 'product', 'edit-product' ) ) ) {
if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) {
wp_enqueue_media();
wp_register_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'media-models' ), WC_VERSION );
wp_register_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'serializejson', 'media-models' ), WC_VERSION );
@ -207,7 +209,7 @@ class WC_Admin_Assets {
wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
}
if ( in_array( str_replace( 'edit-', '', $screen->id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
wp_register_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
wp_register_script( 'wc-admin-order-meta-boxes-modal', WC()->plugin_url() . '/assets/js/admin/order-backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util', 'wc-admin-order-meta-boxes' ), WC_VERSION );
@ -221,11 +223,11 @@ class WC_Admin_Assets {
wp_localize_script( 'wc-admin-order-meta-boxes', 'woocommerce_admin_meta_boxes_order', $params );
}
if ( in_array( $screen->id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
wp_register_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
wp_enqueue_script( 'wc-admin-coupon-meta-boxes' );
}
if ( in_array( str_replace( 'edit-', '', $screen->id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) {
if ( in_array( str_replace( 'edit-', '', $screen_id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) {
$params = array(
'remove_item_notice' => __( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce' ),
'i18n_select_items' => __( 'Please select some items.', 'woocommerce' ),
@ -285,7 +287,7 @@ class WC_Admin_Assets {
}
// Term ordering - only when sorting by term_order
if ( ( strstr( $screen->id, 'edit-pa_' ) || ( ! empty( $_GET['taxonomy'] ) && in_array( $_GET['taxonomy'], apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ) ) ) ) && ! isset( $_GET['orderby'] ) ) {
if ( ( strstr( $screen_id, 'edit-pa_' ) || ( ! empty( $_GET['taxonomy'] ) && in_array( $_GET['taxonomy'], apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ) ) ) ) && ! isset( $_GET['orderby'] ) ) {
wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION );
wp_enqueue_script( 'woocommerce_term_ordering' );
@ -300,13 +302,13 @@ class WC_Admin_Assets {
}
// Product sorting - only when sorting by menu order on the products page
if ( current_user_can( 'edit_others_pages' ) && $screen->id == 'edit-product' && isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) {
if ( current_user_can( 'edit_others_pages' ) && $screen_id == 'edit-product' && isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) {
wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION, true );
wp_enqueue_script( 'woocommerce_product_ordering' );
}
// Reports Pages
if ( in_array( $screen->id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) ) {
if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) ) {
wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), WC_VERSION );
wp_enqueue_script( 'wc-reports' );
@ -318,7 +320,7 @@ class WC_Admin_Assets {
}
// API settings
if ( $wc_screen_id . '_page_wc-settings' === $screen->id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'zeroclipboard' ), WC_VERSION, true );
wp_enqueue_script( 'wc-api-keys' );
wp_localize_script(
@ -332,11 +334,11 @@ class WC_Admin_Assets {
}
// System status
if ( $wc_screen_id . '_page_wc-status' === $screen->id ) {
if ( $wc_screen_id . '_page_wc-status' === $screen_id ) {
wp_enqueue_script( 'zeroclipboard' );
}
if ( in_array( $screen->id, array( 'user-edit', 'profile' ) ) ) {
if ( in_array( $screen_id, array( 'user-edit', 'profile' ) ) ) {
wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select' ), WC_VERSION, true );
wp_enqueue_script( 'wc-users' );
wp_localize_script(

View File

@ -32,7 +32,7 @@ class WC_Admin_Help {
public function add_tabs() {
$screen = get_current_screen();
if ( ! in_array( $screen->id, wc_get_screen_ids() ) ) {
if ( ! $screen || ! in_array( $screen->id, wc_get_screen_ids() ) ) {
return;
}

View File

@ -118,7 +118,7 @@ class WC_Admin_Menus {
break;
case 'product' :
$screen = get_current_screen();
if ( taxonomy_is_product_attribute( $screen->taxonomy ) ) {
if ( $screen && taxonomy_is_product_attribute( $screen->taxonomy ) ) {
$submenu_file = 'product_attributes';
$parent_file = 'edit.php?post_type=product';
}

View File

@ -112,6 +112,8 @@ class WC_Admin_Meta_Boxes {
* Add WC Meta boxes.
*/
public function add_meta_boxes() {
$screen = get_current_screen();
// Products
add_meta_box( 'postexcerpt', __( 'Product Short Description', 'woocommerce' ), 'WC_Meta_Box_Product_Short_Description::output', 'product', 'normal' );
add_meta_box( 'woocommerce-product-data', __( 'Product Data', 'woocommerce' ), 'WC_Meta_Box_Product_Data::output', 'product', 'normal', 'high' );
@ -132,7 +134,7 @@ class WC_Admin_Meta_Boxes {
add_meta_box( 'woocommerce-coupon-data', __( 'Coupon Data', 'woocommerce' ), 'WC_Meta_Box_Coupon_Data::output', 'shop_coupon', 'normal', 'high' );
// Reviews
if ( 'comment' == get_current_screen()->id && isset( $_GET['c'] ) ) {
if ( $screen && 'comment' === $screen->id && isset( $_GET['c'] ) ) {
if ( get_comment_meta( intval( $_GET['c'] ), 'rating', true ) ) {
add_meta_box( 'woocommerce-rating', __( 'Rating', 'woocommerce' ), 'WC_Meta_Box_Order_Reviews::output', 'comment', 'normal', 'high' );
}

View File

@ -28,7 +28,9 @@ class WC_Admin_Pointers {
* Setup pointers for screen.
*/
public function setup_pointers_for_screen() {
$screen = get_current_screen();
if ( ! $screen = get_current_screen() ) {
return;
}
switch ( $screen->id ) {
case 'product' :

View File

@ -2288,7 +2288,7 @@ class WC_Admin_Post_Types {
public function disable_dfw_feature_pointer() {
$screen = get_current_screen();
if ( 'product' === $screen->id && 'post' === $screen->base ) {
if ( $screen && 'product' === $screen->id && 'post' === $screen->base ) {
remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp410_dfw' ) );
}
}

View File

@ -70,7 +70,9 @@ class WC_Admin {
* Include admin files conditionally.
*/
public function conditional_includes() {
$screen = get_current_screen();
if ( ! $screen = get_current_screen() ) {
return;
}
switch ( $screen->id ) {
case 'dashboard' :