diff --git a/includes/admin/class-wc-admin-addons.php b/includes/admin/class-wc-admin-addons.php index 452a30f4e1c..ec00b88eaa3 100644 --- a/includes/admin/class-wc-admin-addons.php +++ b/includes/admin/class-wc-admin-addons.php @@ -52,8 +52,8 @@ class WC_Admin_Addons { $paramters = array( 'category' => $category, - 'term' => $term, - 'country' => $country, + 'term' => $term, + 'country' => $country, ); return '?' . http_build_query( $paramters ); @@ -69,7 +69,7 @@ class WC_Admin_Addons { * @return array of extensions */ public static function get_extension_data( $category, $term, $country ) { - $parameters = self::build_parameter_string( $category, $term, $country ); + $parameters = self::build_parameter_string( $category, $term, $country ); $raw_extensions = wp_remote_get( 'https://woocommerce.com/wp-json/wccom-extensions/1.0/search' . $parameters ); @@ -166,12 +166,14 @@ class WC_Admin_Addons { $utm_content = 'nostorefront'; } - $url = add_query_arg( array( - 'utm_source' => 'addons', - 'utm_medium' => 'product', - 'utm_campaign' => 'woocommerceplugin', - 'utm_content' => $utm_content, - ), $url ); + $url = add_query_arg( + array( + 'utm_source' => 'addons', + 'utm_medium' => 'product', + 'utm_campaign' => 'woocommerceplugin', + 'utm_content' => $utm_content, + ), $url + ); echo '' . esc_html( $text ) . '' . "\n"; } @@ -284,7 +286,7 @@ class WC_Admin_Addons { public static function output_small_light_block( $block ) { ?>
- +

title ); ?>

description ); ?>

@@ -355,9 +357,11 @@ class WC_Admin_Addons { } $button_url = wp_nonce_url( - add_query_arg( array( - 'install-addon' => 'woocommerce-services', - ) ), + add_query_arg( + array( + 'install-addon' => 'woocommerce-services', + ) + ), 'install-addon_woocommerce-services' ); @@ -377,22 +381,26 @@ class WC_Admin_Addons { 'image' => WC()->plugin_url() . '/assets/images/wcs-truck-banner-3x.png', 'title' => __( 'Show Canada Post shipping rates', 'woocommerce' ), 'description' => __( 'Display live rates from Canada Post at checkout to make shipping a breeze. Powered by WooCommerce Services.', 'woocommerce' ), - 'logos' => array_merge( $defaults['logos'], array( - array( - 'link' => WC()->plugin_url() . '/assets/images/wcs-canada-post-logo.jpg', - 'alt' => 'Canada Post logo', - ), - ) ), + 'logos' => array_merge( + $defaults['logos'], array( + array( + 'link' => WC()->plugin_url() . '/assets/images/wcs-canada-post-logo.jpg', + 'alt' => 'Canada Post logo', + ), + ) + ), ); break; case 'US': $local_defaults = array( - 'logos' => array_merge( $defaults['logos'], array( - array( - 'link' => WC()->plugin_url() . '/assets/images/wcs-usps-logo.png', - 'alt' => 'USPS logo', - ), - ) ), + 'logos' => array_merge( + $defaults['logos'], array( + array( + 'link' => WC()->plugin_url() . '/assets/images/wcs-usps-logo.png', + 'alt' => 'USPS logo', + ), + ) + ), ); break; default: @@ -479,7 +487,7 @@ class WC_Admin_Addons { public static function output_button( $url, $text, $theme, $plugin = '' ) { $theme = __( 'Free', 'woocommerce' ) === $text ? 'addons-button-outline-green' : $theme; $theme = is_plugin_active( $plugin ) ? 'addons-button-installed' : $theme; - $text = is_plugin_active( $plugin ) ? __( 'Installed', 'woocommerce' ) : $text; + $text = is_plugin_active( $plugin ) ? __( 'Installed', 'woocommerce' ) : $text; ?> countries->get_base_country(); - $addons = self::get_extension_data( $category, $term, $country ); + $term = isset( $_GET['search'] ) ? $_GET['search'] : null; + $country = WC()->countries->get_base_country(); + $addons = self::get_extension_data( $category, $term, $country ); } /** @@ -523,7 +531,7 @@ class WC_Admin_Addons { * @uses $theme * @uses $current_section */ - include_once( dirname( __FILE__ ) . '/views/html-admin-page-addons.php' ); + include_once dirname( __FILE__ ) . '/views/html-admin-page-addons.php'; } /** diff --git a/includes/admin/class-wc-admin-api-keys-table-list.php b/includes/admin/class-wc-admin-api-keys-table-list.php index e70b5e10027..03760898136 100644 --- a/includes/admin/class-wc-admin-api-keys-table-list.php +++ b/includes/admin/class-wc-admin-api-keys-table-list.php @@ -21,11 +21,13 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table { * Initialize the API key table list. */ public function __construct() { - parent::__construct( array( - 'singular' => 'key', - 'plural' => 'keys', - 'ajax' => false, - ) ); + parent::__construct( + array( + 'singular' => 'key', + 'plural' => 'keys', + 'ajax' => false, + ) + ); } /** @@ -85,9 +87,15 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table { /* translators: %s: API key ID. */ 'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $key['key_id'] ), 'edit' => '' . __( 'View/Edit', 'woocommerce' ) . '', - 'trash' => '' . esc_html__( 'Revoke', 'woocommerce' ) . '', + 'trash' => '' . esc_html__( 'Revoke', 'woocommerce' ) . '', ); $row_actions = array(); @@ -212,10 +220,12 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table { $this->items = $keys; // Set the pagination. - $this->set_pagination_args( array( - 'total_items' => $count, - 'per_page' => $per_page, - 'total_pages' => ceil( $count / $per_page ), - ) ); + $this->set_pagination_args( + array( + 'total_items' => $count, + 'per_page' => $per_page, + 'total_pages' => ceil( $count / $per_page ), + ) + ); } } diff --git a/includes/admin/class-wc-admin-api-keys.php b/includes/admin/class-wc-admin-api-keys.php index 7455e60719c..b6a90cd48e3 100644 --- a/includes/admin/class-wc-admin-api-keys.php +++ b/includes/admin/class-wc-admin-api-keys.php @@ -57,10 +57,12 @@ class WC_Admin_API_Keys { $keys_table_list = new WC_Admin_API_Keys_Table_List(); // Add screen option. - add_screen_option( 'per_page', array( - 'default' => 10, - 'option' => 'woocommerce_keys_per_page', - ) ); + add_screen_option( + 'per_page', array( + 'default' => 10, + 'option' => 'woocommerce_keys_per_page', + ) + ); } } @@ -117,11 +119,14 @@ class WC_Admin_API_Keys { return $empty; } - $key = $wpdb->get_row( $wpdb->prepare( " - SELECT key_id, user_id, description, permissions, truncated_key, last_access - FROM {$wpdb->prefix}woocommerce_api_keys - WHERE key_id = %d - ", $key_id ), ARRAY_A ); + $key = $wpdb->get_row( + $wpdb->prepare( + "SELECT key_id, user_id, description, permissions, truncated_key, last_access + FROM {$wpdb->prefix}woocommerce_api_keys + WHERE key_id = %d", + $key_id + ), ARRAY_A + ); if ( is_null( $key ) ) { return $empty; diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index 4fa6fcccfea..6b958715ddf 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -14,384 +14,400 @@ if ( ! defined( 'ABSPATH' ) ) { if ( ! class_exists( 'WC_Admin_Assets', false ) ) : -/** - * WC_Admin_Assets Class. - */ -class WC_Admin_Assets { - /** - * Hook in tabs. + * WC_Admin_Assets Class. */ - public function __construct() { - add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) ); - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); - } + class WC_Admin_Assets { - /** - * Enqueue styles. - */ - public function admin_styles() { - global $wp_scripts; - - $screen = get_current_screen(); - $screen_id = $screen ? $screen->id : ''; - - // Register admin styles - wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), WC_VERSION ); - wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION ); - wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui.min.css', array(), WC_VERSION ); - wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), WC_VERSION ); - wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), WC_VERSION, 'print' ); - - // Add RTL support for admin styles - wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' ); - wp_style_add_data( 'woocommerce_admin_styles', 'rtl', 'replace' ); - wp_style_add_data( 'woocommerce_admin_dashboard_styles', 'rtl', 'replace' ); - wp_style_add_data( 'woocommerce_admin_print_reports_styles', 'rtl', 'replace' ); - - // Sitewide menu CSS - wp_enqueue_style( 'woocommerce_admin_menu_styles' ); - - // Admin styles for WC pages only - 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' ) ) ) { - wp_enqueue_style( 'woocommerce_admin_dashboard_styles' ); - } - - if ( in_array( $screen_id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) { - wp_enqueue_style( 'woocommerce_admin_print_reports_styles' ); + /** + * Hook in tabs. + */ + public function __construct() { + add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); } /** - * @deprecated 2.3 + * Enqueue styles. */ - if ( has_action( 'woocommerce_admin_css' ) ) { - do_action( 'woocommerce_admin_css' ); - wc_deprecated_function( 'The woocommerce_admin_css action', '2.3', 'admin_enqueue_scripts' ); - } - } + public function admin_styles() { + global $wp_scripts; + $screen = get_current_screen(); + $screen_id = $screen ? $screen->id : ''; - /** - * Enqueue scripts. - */ - public function admin_scripts() { - global $wp_query, $post; + // Register admin styles + wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), WC_VERSION ); + wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION ); + wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui.min.css', array(), WC_VERSION ); + wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), WC_VERSION ); + wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), WC_VERSION, 'print' ); - $screen = get_current_screen(); - $screen_id = $screen ? $screen->id : ''; - $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ); - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + // Add RTL support for admin styles + wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' ); + wp_style_add_data( 'woocommerce_admin_styles', 'rtl', 'replace' ); + wp_style_add_data( 'woocommerce_admin_dashboard_styles', 'rtl', 'replace' ); + wp_style_add_data( 'woocommerce_admin_print_reports_styles', 'rtl', 'replace' ); - // Register scripts - wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION ); - wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); - wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true ); - wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), WC_VERSION ); - wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array( 'jquery' ), '2.8.1' ); - wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); - wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); - wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); - wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); - wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION ); - wp_register_script( 'wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util' ), WC_VERSION ); - wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), WC_VERSION ); - wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), WC_VERSION ); - wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), WC_VERSION ); - wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' ); - wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.3' ); - wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION ); - wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array( - 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ), - 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ), - 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ), - 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ), - 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ), - 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ), - 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ), - 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ), - 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ), - 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ), - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'search_products_nonce' => wp_create_nonce( 'search-products' ), - 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), - 'search_categories_nonce' => wp_create_nonce( 'search-categories' ), - ) ); + // Sitewide menu CSS + wp_enqueue_style( 'woocommerce_admin_menu_styles' ); - wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' ); - wp_localize_script( 'accounting', 'accounting_params', array( - 'mon_decimal_point' => wc_get_price_decimal_separator(), - ) ); - - wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION ); - wp_localize_script( 'wc-orders', 'wc_orders_params', array( - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'preview_nonce' => wp_create_nonce( 'woocommerce-preview-order' ), - ) ); - - // WooCommerce admin pages. - if ( in_array( $screen_id, wc_get_screen_ids() ) ) { - wp_enqueue_script( 'iris' ); - wp_enqueue_script( 'woocommerce_admin' ); - wp_enqueue_script( 'wc-enhanced-select' ); - wp_enqueue_script( 'jquery-ui-sortable' ); - wp_enqueue_script( 'jquery-ui-autocomplete' ); - - $locale = localeconv(); - $decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.'; - - $params = array( - /* translators: %s: decimal */ - 'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ), - /* translators: %s: price decimal separator */ - 'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ), - 'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ), - 'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ), - 'i18_delete_product_notice' => __( 'This product has produced sales and may be linked to existing orders. Are you sure you want to delete it?', 'woocommerce' ), - 'decimal_point' => $decimal, - 'mon_decimal_point' => wc_get_price_decimal_separator(), - 'strings' => array( - 'import_products' => __( 'Import', 'woocommerce' ), - 'export_products' => __( 'Export', 'woocommerce' ), - ), - 'urls' => array( - 'import_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ), - 'export_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ), - ), - ); - - wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params ); - } - - // Edit product category pages - if ( in_array( $screen_id, array( 'edit-product_cat' ) ) ) { - wp_enqueue_media(); - } - - // Products - if ( in_array( $screen_id, array( 'edit-product' ) ) ) { - wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), WC_VERSION ); - - $params = array( - 'strings' => array( - 'allow_reviews' => esc_js( __( 'Enable reviews', 'woocommerce' ) ), - ), - ); - - wp_localize_script( 'woocommerce_quick-edit', 'woocommerce_quick_edit', $params ); - } - - // Meta boxes - 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 ); - - wp_enqueue_script( 'wc-admin-product-meta-boxes' ); - wp_enqueue_script( 'wc-admin-variation-meta-boxes' ); - - $params = array( - 'post_id' => isset( $post->ID ) ? $post->ID : '', - 'plugin_url' => WC()->plugin_url(), - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'woocommerce_placeholder_img_src' => wc_placeholder_img_src(), - 'add_variation_nonce' => wp_create_nonce( 'add-variation' ), - 'link_variation_nonce' => wp_create_nonce( 'link-variations' ), - 'delete_variations_nonce' => wp_create_nonce( 'delete-variations' ), - 'load_variations_nonce' => wp_create_nonce( 'load-variations' ), - 'save_variations_nonce' => wp_create_nonce( 'save-variations' ), - 'bulk_edit_variations_nonce' => wp_create_nonce( 'bulk-edit-variations' ), - 'i18n_link_all_variations' => esc_js( sprintf( __( 'Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max %d per run).', 'woocommerce' ), defined( 'WC_MAX_LINKED_VARIATIONS' ) ? WC_MAX_LINKED_VARIATIONS : 50 ) ), - 'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ), - 'i18n_enter_menu_order' => esc_js( __( 'Variation menu order (determines position in the list of variations)', 'woocommerce' ) ), - 'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ), - 'i18n_delete_all_variations' => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ), - 'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ), - 'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ), - 'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ), - 'i18n_variation_added' => esc_js( __( "variation added", 'woocommerce' ) ), - 'i18n_variations_added' => esc_js( __( "variations added", 'woocommerce' ) ), - 'i18n_no_variations_added' => esc_js( __( "No variations added", 'woocommerce' ) ), - 'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) ), - 'i18n_scheduled_sale_start' => esc_js( __( 'Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ), - 'i18n_scheduled_sale_end' => esc_js( __( 'Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ), - 'i18n_edited_variations' => esc_js( __( 'Save changes before changing page?', 'woocommerce' ) ), - 'i18n_variation_count_single' => esc_js( __( '%qty% variation', 'woocommerce' ) ), - 'i18n_variation_count_plural' => esc_js( __( '%qty% variations', 'woocommerce' ) ), - 'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) ), - ); - - 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' ) ) ) { - $default_location = wc_get_customer_default_location(); - - wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), WC_VERSION ); - wp_localize_script( 'wc-admin-order-meta-boxes', 'woocommerce_admin_meta_boxes_order', array( - 'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ), - 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ), - 'default_country' => isset( $default_location['country'] ) ? $default_location['country'] : '', - 'default_state' => isset( $default_location['state'] ) ? $default_location['state'] : '', - 'placeholder_name' => esc_attr__( 'Name (required)', 'woocommerce' ), - 'placeholder_value' => esc_attr__( 'Value (required)', 'woocommerce' ), - ) ); - } - if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) { - wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION ); - } - if ( in_array( str_replace( 'edit-', '', $screen_id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) { - $post_id = isset( $post->ID ) ? $post->ID : ''; - $currency = ''; - - if ( $post_id && in_array( get_post_type( $post_id ), wc_get_order_types( 'order-meta-boxes' ) ) && ( $order = wc_get_order( $post_id ) ) ) { - $currency = $order->get_currency(); + // Admin styles for WC pages only + 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' ); } - $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' ), - 'i18n_do_refund' => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce' ), - 'i18n_delete_refund' => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce' ), - 'i18n_delete_tax' => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce' ), - 'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce' ), - 'remove_attribute' => __( 'Remove this attribute?', 'woocommerce' ), - 'name_label' => __( 'Name', 'woocommerce' ), - 'remove_label' => __( 'Remove', 'woocommerce' ), - 'click_to_toggle' => __( 'Click to toggle', 'woocommerce' ), - 'values_label' => __( 'Value(s)', 'woocommerce' ), - 'text_attribute_tip' => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce' ), - 'visible_label' => __( 'Visible on the product page', 'woocommerce' ), - 'used_for_variations_label' => __( 'Used for variations', 'woocommerce' ), - 'new_attribute_prompt' => __( 'Enter a name for the new attribute term:', 'woocommerce' ), - 'calc_totals' => __( 'Recalculate totals? This will calculate taxes based on the customers country (or the store base country) and update totals.', 'woocommerce' ), - 'copy_billing' => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce' ), - 'load_billing' => __( "Load the customer's billing information? This will remove any currently entered billing information.", 'woocommerce' ), - 'load_shipping' => __( "Load the customer's shipping information? This will remove any currently entered shipping information.", 'woocommerce' ), - 'featured_label' => __( 'Featured', 'woocommerce' ), - 'prices_include_tax' => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ), - 'tax_based_on' => esc_attr( get_option( 'woocommerce_tax_based_on' ) ), - 'round_at_subtotal' => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ), - 'no_customer_selected' => __( 'No customer selected', 'woocommerce' ), - 'plugin_url' => WC()->plugin_url(), - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'order_item_nonce' => wp_create_nonce( 'order-item' ), - 'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ), - 'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ), - 'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ), - 'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ), - 'search_products_nonce' => wp_create_nonce( 'search-products' ), - 'grant_access_nonce' => wp_create_nonce( 'grant-access' ), - 'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ), - 'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ), - 'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ), - 'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png', - 'post_id' => isset( $post->ID ) ? $post->ID : '', - 'base_country' => WC()->countries->get_base_country(), - 'currency_format_num_decimals' => wc_get_price_decimals(), - 'currency_format_symbol' => get_woocommerce_currency_symbol( $currency ), - 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ), - 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ), - 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS - 'rounding_precision' => wc_get_rounding_precision(), - 'tax_rounding_mode' => wc_get_tax_rounding_mode(), - 'product_types' => array_unique( array_merge( array( 'simple', 'grouped', 'variable', 'external' ), array_keys( wc_get_product_types() ) ) ), - 'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ), - 'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ), - 'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce' ), - 'i18n_delete_note' => __( 'Are you sure you wish to delete this note? This action cannot be undone.', 'woocommerce' ), - 'i18n_apply_coupon' => __( 'Enter a coupon code to apply to this order.', 'woocommerce' ), - 'i18n_add_fee' => __( 'Enter a fixed amount or percentage to apply as a fee.', 'woocommerce' ), - ); + if ( in_array( $screen_id, array( 'dashboard' ) ) ) { + wp_enqueue_style( 'woocommerce_admin_dashboard_styles' ); + } - wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params ); + if ( in_array( $screen_id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) { + wp_enqueue_style( 'woocommerce_admin_print_reports_styles' ); + } + + /** + * @deprecated 2.3 + */ + if ( has_action( 'woocommerce_admin_css' ) ) { + do_action( 'woocommerce_admin_css' ); + wc_deprecated_function( 'The woocommerce_admin_css action', '2.3', 'admin_enqueue_scripts' ); + } } - // 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'] ) ) { - 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' ); + /** + * Enqueue scripts. + */ + public function admin_scripts() { + global $wp_query, $post; - $taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( $_GET['taxonomy'] ) : ''; + $screen = get_current_screen(); + $screen_id = $screen ? $screen->id : ''; + $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ); + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; - $woocommerce_term_order_params = array( - 'taxonomy' => $taxonomy, - ); - - wp_localize_script( 'woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params ); - } - - // Product sorting - only when sorting by menu order on the products page - if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) { - 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' ) ) ) ) { - 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' ); - wp_enqueue_script( 'flot' ); - wp_enqueue_script( 'flot-resize' ); - wp_enqueue_script( 'flot-time' ); - wp_enqueue_script( 'flot-pie' ); - wp_enqueue_script( 'flot-stack' ); - } - - // API settings - 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', 'wc-clipboard' ), WC_VERSION, true ); - wp_enqueue_script( 'wc-api-keys' ); + // Register scripts + wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION ); + wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); + wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true ); + wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); + wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), WC_VERSION ); + wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); + wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); + wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); + wp_register_script( 'serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array( 'jquery' ), '2.8.1' ); + wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); + wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); + wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); + wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); + wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION ); + wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION ); + wp_register_script( 'wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util' ), WC_VERSION ); + wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), WC_VERSION ); + wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), WC_VERSION ); + wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), WC_VERSION ); + wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); + wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' ); + wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.3' ); + wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION ); wp_localize_script( - 'wc-api-keys', - 'woocommerce_admin_api_keys', + 'wc-enhanced-select', + 'wc_enhanced_select_params', array( - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'update_api_nonce' => wp_create_nonce( 'update-api-key' ), - 'clipboard_failed' => esc_html__( 'Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'woocommerce' ), + 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ), + 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ), + 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ), + 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ), + 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ), + 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ), + 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ), + 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ), + 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ), + 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ), + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'search_products_nonce' => wp_create_nonce( 'search-products' ), + 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), + 'search_categories_nonce' => wp_create_nonce( 'search-categories' ), ) ); - } - // System status. - if ( $wc_screen_id . '_page_wc-status' === $screen_id ) { - wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), WC_VERSION ); - wp_enqueue_script( 'wc-admin-system-status' ); + wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' ); wp_localize_script( - 'wc-admin-system-status', - 'woocommerce_admin_system_status', + 'accounting', + 'accounting_params', array( - 'delete_log_confirmation' => esc_js( __( 'Are you sure you want to delete this log?', 'woocommerce' ) ), + 'mon_decimal_point' => wc_get_price_decimal_separator(), ) ); - } - 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', 'selectWoo' ), WC_VERSION, true ); - wp_enqueue_script( 'wc-users' ); + wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION ); wp_localize_script( - 'wc-users', - 'wc_users_params', + 'wc-orders', + 'wc_orders_params', array( - 'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ), - 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ), + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'preview_nonce' => wp_create_nonce( 'woocommerce-preview-order' ), ) ); + + // WooCommerce admin pages. + if ( in_array( $screen_id, wc_get_screen_ids() ) ) { + wp_enqueue_script( 'iris' ); + wp_enqueue_script( 'woocommerce_admin' ); + wp_enqueue_script( 'wc-enhanced-select' ); + wp_enqueue_script( 'jquery-ui-sortable' ); + wp_enqueue_script( 'jquery-ui-autocomplete' ); + + $locale = localeconv(); + $decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.'; + + $params = array( + /* translators: %s: decimal */ + 'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ), + /* translators: %s: price decimal separator */ + 'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ), + 'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ), + 'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ), + 'i18_delete_product_notice' => __( 'This product has produced sales and may be linked to existing orders. Are you sure you want to delete it?', 'woocommerce' ), + 'decimal_point' => $decimal, + 'mon_decimal_point' => wc_get_price_decimal_separator(), + 'strings' => array( + 'import_products' => __( 'Import', 'woocommerce' ), + 'export_products' => __( 'Export', 'woocommerce' ), + ), + 'urls' => array( + 'import_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ), + 'export_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ), + ), + ); + + wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params ); + } + + // Edit product category pages + if ( in_array( $screen_id, array( 'edit-product_cat' ) ) ) { + wp_enqueue_media(); + } + + // Products + if ( in_array( $screen_id, array( 'edit-product' ) ) ) { + wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), WC_VERSION ); + + $params = array( + 'strings' => array( + 'allow_reviews' => esc_js( __( 'Enable reviews', 'woocommerce' ) ), + ), + ); + + wp_localize_script( 'woocommerce_quick-edit', 'woocommerce_quick_edit', $params ); + } + + // Meta boxes + 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 ); + + wp_enqueue_script( 'wc-admin-product-meta-boxes' ); + wp_enqueue_script( 'wc-admin-variation-meta-boxes' ); + + $params = array( + 'post_id' => isset( $post->ID ) ? $post->ID : '', + 'plugin_url' => WC()->plugin_url(), + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'woocommerce_placeholder_img_src' => wc_placeholder_img_src(), + 'add_variation_nonce' => wp_create_nonce( 'add-variation' ), + 'link_variation_nonce' => wp_create_nonce( 'link-variations' ), + 'delete_variations_nonce' => wp_create_nonce( 'delete-variations' ), + 'load_variations_nonce' => wp_create_nonce( 'load-variations' ), + 'save_variations_nonce' => wp_create_nonce( 'save-variations' ), + 'bulk_edit_variations_nonce' => wp_create_nonce( 'bulk-edit-variations' ), + 'i18n_link_all_variations' => esc_js( sprintf( __( 'Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max %d per run).', 'woocommerce' ), defined( 'WC_MAX_LINKED_VARIATIONS' ) ? WC_MAX_LINKED_VARIATIONS : 50 ) ), + 'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ), + 'i18n_enter_menu_order' => esc_js( __( 'Variation menu order (determines position in the list of variations)', 'woocommerce' ) ), + 'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ), + 'i18n_delete_all_variations' => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ), + 'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ), + 'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ), + 'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ), + 'i18n_variation_added' => esc_js( __( 'variation added', 'woocommerce' ) ), + 'i18n_variations_added' => esc_js( __( 'variations added', 'woocommerce' ) ), + 'i18n_no_variations_added' => esc_js( __( 'No variations added', 'woocommerce' ) ), + 'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) ), + 'i18n_scheduled_sale_start' => esc_js( __( 'Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ), + 'i18n_scheduled_sale_end' => esc_js( __( 'Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ), + 'i18n_edited_variations' => esc_js( __( 'Save changes before changing page?', 'woocommerce' ) ), + 'i18n_variation_count_single' => esc_js( __( '%qty% variation', 'woocommerce' ) ), + 'i18n_variation_count_plural' => esc_js( __( '%qty% variations', 'woocommerce' ) ), + 'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) ), + ); + + 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' ) ) ) { + $default_location = wc_get_customer_default_location(); + + wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), WC_VERSION ); + wp_localize_script( + 'wc-admin-order-meta-boxes', + 'woocommerce_admin_meta_boxes_order', + array( + 'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ), + 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ), + 'default_country' => isset( $default_location['country'] ) ? $default_location['country'] : '', + 'default_state' => isset( $default_location['state'] ) ? $default_location['state'] : '', + 'placeholder_name' => esc_attr__( 'Name (required)', 'woocommerce' ), + 'placeholder_value' => esc_attr__( 'Value (required)', 'woocommerce' ), + ) + ); + } + if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) { + wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION ); + } + if ( in_array( str_replace( 'edit-', '', $screen_id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) { + $post_id = isset( $post->ID ) ? $post->ID : ''; + $currency = ''; + + if ( $post_id && in_array( get_post_type( $post_id ), wc_get_order_types( 'order-meta-boxes' ) ) && ( $order = wc_get_order( $post_id ) ) ) { + $currency = $order->get_currency(); + } + + $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' ), + 'i18n_do_refund' => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce' ), + 'i18n_delete_refund' => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce' ), + 'i18n_delete_tax' => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce' ), + 'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce' ), + 'remove_attribute' => __( 'Remove this attribute?', 'woocommerce' ), + 'name_label' => __( 'Name', 'woocommerce' ), + 'remove_label' => __( 'Remove', 'woocommerce' ), + 'click_to_toggle' => __( 'Click to toggle', 'woocommerce' ), + 'values_label' => __( 'Value(s)', 'woocommerce' ), + 'text_attribute_tip' => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce' ), + 'visible_label' => __( 'Visible on the product page', 'woocommerce' ), + 'used_for_variations_label' => __( 'Used for variations', 'woocommerce' ), + 'new_attribute_prompt' => __( 'Enter a name for the new attribute term:', 'woocommerce' ), + 'calc_totals' => __( 'Recalculate totals? This will calculate taxes based on the customers country (or the store base country) and update totals.', 'woocommerce' ), + 'copy_billing' => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce' ), + 'load_billing' => __( "Load the customer's billing information? This will remove any currently entered billing information.", 'woocommerce' ), + 'load_shipping' => __( "Load the customer's shipping information? This will remove any currently entered shipping information.", 'woocommerce' ), + 'featured_label' => __( 'Featured', 'woocommerce' ), + 'prices_include_tax' => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ), + 'tax_based_on' => esc_attr( get_option( 'woocommerce_tax_based_on' ) ), + 'round_at_subtotal' => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ), + 'no_customer_selected' => __( 'No customer selected', 'woocommerce' ), + 'plugin_url' => WC()->plugin_url(), + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'order_item_nonce' => wp_create_nonce( 'order-item' ), + 'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ), + 'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ), + 'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ), + 'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ), + 'search_products_nonce' => wp_create_nonce( 'search-products' ), + 'grant_access_nonce' => wp_create_nonce( 'grant-access' ), + 'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ), + 'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ), + 'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ), + 'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png', + 'post_id' => isset( $post->ID ) ? $post->ID : '', + 'base_country' => WC()->countries->get_base_country(), + 'currency_format_num_decimals' => wc_get_price_decimals(), + 'currency_format_symbol' => get_woocommerce_currency_symbol( $currency ), + 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ), + 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ), + 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS + 'rounding_precision' => wc_get_rounding_precision(), + 'tax_rounding_mode' => wc_get_tax_rounding_mode(), + 'product_types' => array_unique( array_merge( array( 'simple', 'grouped', 'variable', 'external' ), array_keys( wc_get_product_types() ) ) ), + 'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ), + 'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ), + 'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce' ), + 'i18n_delete_note' => __( 'Are you sure you wish to delete this note? This action cannot be undone.', 'woocommerce' ), + 'i18n_apply_coupon' => __( 'Enter a coupon code to apply to this order.', 'woocommerce' ), + 'i18n_add_fee' => __( 'Enter a fixed amount or percentage to apply as a fee.', 'woocommerce' ), + ); + + wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params ); + } + + // 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'] ) ) { + + 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' ); + + $taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( $_GET['taxonomy'] ) : ''; + + $woocommerce_term_order_params = array( + 'taxonomy' => $taxonomy, + ); + + wp_localize_script( 'woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params ); + } + + // Product sorting - only when sorting by menu order on the products page + if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) { + 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' ) ) ) ) { + 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' ); + wp_enqueue_script( 'flot' ); + wp_enqueue_script( 'flot-resize' ); + wp_enqueue_script( 'flot-time' ); + wp_enqueue_script( 'flot-pie' ); + wp_enqueue_script( 'flot-stack' ); + } + + // API settings + 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', 'wc-clipboard' ), WC_VERSION, true ); + wp_enqueue_script( 'wc-api-keys' ); + wp_localize_script( + 'wc-api-keys', + 'woocommerce_admin_api_keys', + array( + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'update_api_nonce' => wp_create_nonce( 'update-api-key' ), + 'clipboard_failed' => esc_html__( 'Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'woocommerce' ), + ) + ); + } + + // System status. + if ( $wc_screen_id . '_page_wc-status' === $screen_id ) { + wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), WC_VERSION ); + wp_enqueue_script( 'wc-admin-system-status' ); + wp_localize_script( + 'wc-admin-system-status', + 'woocommerce_admin_system_status', + array( + 'delete_log_confirmation' => esc_js( __( 'Are you sure you want to delete this log?', 'woocommerce' ) ), + ) + ); + } + + 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', 'selectWoo' ), WC_VERSION, true ); + wp_enqueue_script( 'wc-users' ); + wp_localize_script( + 'wc-users', + 'wc_users_params', + array( + 'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ), + 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ), + ) + ); + } } } -} endif; diff --git a/includes/admin/class-wc-admin-attributes.php b/includes/admin/class-wc-admin-attributes.php index ce79f083643..27a608f80ec 100644 --- a/includes/admin/class-wc-admin-attributes.php +++ b/includes/admin/class-wc-admin-attributes.php @@ -39,15 +39,15 @@ class WC_Admin_Attributes { } switch ( $action ) { - case 'add' : + case 'add': $result = self::process_add_attribute(); - break; - case 'edit' : + break; + case 'edit': $result = self::process_edit_attribute(); - break; - case 'delete' : + break; + case 'delete': $result = self::process_delete_attribute(); - break; + break; } if ( is_wp_error( $result ) ) { @@ -69,11 +69,11 @@ class WC_Admin_Attributes { */ private static function get_posted_attribute() { $attribute = array( - 'attribute_label' => isset( $_POST['attribute_label'] ) ? wc_clean( stripslashes( $_POST['attribute_label'] ) ) : '', - 'attribute_name' => isset( $_POST['attribute_name'] ) ? wc_sanitize_taxonomy_name( stripslashes( $_POST['attribute_name'] ) ) : '', - 'attribute_type' => isset( $_POST['attribute_type'] ) ? wc_clean( $_POST['attribute_type'] ) : 'select', + 'attribute_label' => isset( $_POST['attribute_label'] ) ? wc_clean( stripslashes( $_POST['attribute_label'] ) ) : '', + 'attribute_name' => isset( $_POST['attribute_name'] ) ? wc_sanitize_taxonomy_name( stripslashes( $_POST['attribute_name'] ) ) : '', + 'attribute_type' => isset( $_POST['attribute_type'] ) ? wc_clean( $_POST['attribute_type'] ) : 'select', 'attribute_orderby' => isset( $_POST['attribute_orderby'] ) ? wc_clean( $_POST['attribute_orderby'] ) : '', - 'attribute_public' => isset( $_POST['attribute_public'] ) ? 1 : 0, + 'attribute_public' => isset( $_POST['attribute_public'] ) ? 1 : 0, ); if ( empty( $attribute['attribute_type'] ) ) { @@ -166,11 +166,11 @@ class WC_Admin_Attributes { $edit = absint( $_GET['edit'] ); - $attribute_to_edit = $wpdb->get_row( "SELECT attribute_type, attribute_label, attribute_name, attribute_orderby, attribute_public FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = '$edit'" ); + $attribute_to_edit = $wpdb->get_row( 'SELECT attribute_type, attribute_label, attribute_name, attribute_orderby, attribute_public FROM ' . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = '$edit'" ); ?>
-

+

- +

@@ -303,7 +303,8 @@ class WC_Admin_Attributes { + ?> + attribute_label ); ?> @@ -313,60 +314,65 @@ class WC_Admin_Attributes { attribute_type ) ); ?> attribute_public ? esc_html__( '(Public)', 'woocommerce' ) : ''; ?> - attribute_orderby ) { - case 'name' : - esc_html_e( 'Name', 'woocommerce' ); - break; - case 'name_num' : - esc_html_e( 'Name (numeric)', 'woocommerce' ); - break; - case 'id' : - esc_html_e( 'Term ID', 'woocommerce' ); - break; - default: - esc_html_e( 'Custom ordering', 'woocommerce' ); - break; - } - ?> + + attribute_orderby ) { + case 'name': + esc_html_e( 'Name', 'woocommerce' ); + break; + case 'name_num': + esc_html_e( 'Name (numeric)', 'woocommerce' ); + break; + case 'id': + esc_html_e( 'Term ID', 'woocommerce' ); + break; + default: + esc_html_e( 'Custom ordering', 'woocommerce' ); + break; + } + ?> - attribute_name ); + attribute_name ); - if ( taxonomy_exists( $taxonomy ) ) { - if ( 'menu_order' === wc_attribute_orderby( $taxonomy ) ) { - $terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=ASC' ); + if ( taxonomy_exists( $taxonomy ) ) { + if ( 'menu_order' === wc_attribute_orderby( $taxonomy ) ) { + $terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=ASC' ); + } else { + $terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=false' ); + } + + switch ( $tax->attribute_orderby ) { + case 'name_num': + usort( $terms, '_wc_get_product_terms_name_num_usort_callback' ); + break; + case 'parent': + usort( $terms, '_wc_get_product_terms_parent_usort_callback' ); + break; + } + + $terms_string = implode( ', ', wp_list_pluck( $terms, 'name' ) ); + if ( $terms_string ) { + echo esc_html( $terms_string ); + } else { + echo ''; + } } else { - $terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=false' ); + echo ''; } - - switch ( $tax->attribute_orderby ) { - case 'name_num' : - usort( $terms, '_wc_get_product_terms_name_num_usort_callback' ); - break; - case 'parent' : - usort( $terms, '_wc_get_product_terms_parent_usort_callback' ); - break; - } - - $terms_string = implode( ', ', wp_list_pluck( $terms, 'name' ) ); - if ( $terms_string ) { - echo esc_html( $terms_string ); - } else { - echo ''; - } - } else { - echo ''; - } - ?> -
+ ?> +
+ + + + @@ -379,7 +385,7 @@ class WC_Admin_Attributes {

- +
@@ -442,7 +448,7 @@ class WC_Admin_Attributes {

- +

diff --git a/includes/admin/class-wc-admin-customize.php b/includes/admin/class-wc-admin-customize.php index 1c4f81d6db6..32d540952b1 100644 --- a/includes/admin/class-wc-admin-customize.php +++ b/includes/admin/class-wc-admin-customize.php @@ -14,84 +14,84 @@ if ( ! defined( 'ABSPATH' ) ) { if ( ! class_exists( 'WC_Admin_Customize', false ) ) : -/** - * WC_Admin_Customize Class. - */ -class WC_Admin_Customize { - /** - * Initialize customize actions. + * WC_Admin_Customize Class. */ - public function __construct() { - // Include custom items to customizer nav menu settings. - add_filter( 'customize_nav_menu_available_item_types', array( $this, 'register_customize_nav_menu_item_types' ) ); - add_filter( 'customize_nav_menu_available_items', array( $this, 'register_customize_nav_menu_items' ), 10, 4 ); - } + class WC_Admin_Customize { - /** - * Register customize new nav menu item types. - * This will register WooCommerce account endpoints as a nav menu item type. - * - * @since 3.1.0 - * @param array $item_types Menu item types. - * @return array - */ - public function register_customize_nav_menu_item_types( $item_types ) { - $item_types[] = array( - 'title' => __( 'WooCommerce endpoints', 'woocommerce' ), - 'type_label' => __( 'WooCommerce endpoint', 'woocommerce' ), - 'type' => 'woocommerce_nav', - 'object' => 'woocommerce_endpoint', - ); - - return $item_types; - } - - /** - * Register account endpoints to customize nav menu items. - * - * @since 3.1.0 - * @param array $items List of nav menu items. - * @param string $type Nav menu type. - * @param string $object Nav menu object. - * @param integer $page Page number. - * @return array - */ - public function register_customize_nav_menu_items( $items = array(), $type = '', $object = '', $page = 0 ) { - if ( 'woocommerce_endpoint' !== $object ) { - return $items; + /** + * Initialize customize actions. + */ + public function __construct() { + // Include custom items to customizer nav menu settings. + add_filter( 'customize_nav_menu_available_item_types', array( $this, 'register_customize_nav_menu_item_types' ) ); + add_filter( 'customize_nav_menu_available_items', array( $this, 'register_customize_nav_menu_items' ), 10, 4 ); } - // Don't allow pagination since all items are loaded at once. - if ( 0 < $page ) { - return $items; - } - - // Get items from account menu. - $endpoints = wc_get_account_menu_items(); - - // Remove dashboard item. - if ( isset( $endpoints['dashboard'] ) ) { - unset( $endpoints['dashboard'] ); - } - - // Include missing lost password. - $endpoints['lost-password'] = __( 'Lost password', 'woocommerce' ); - - $endpoints = apply_filters( 'woocommerce_custom_nav_menu_items', $endpoints ); - - foreach ( $endpoints as $endpoint => $title ) { - $items[] = array( - 'id' => $endpoint, - 'title' => $title, - 'type_label' => __( 'Custom Link', 'woocommerce' ), - 'url' => esc_url_raw( wc_get_account_endpoint_url( $endpoint ) ), + /** + * Register customize new nav menu item types. + * This will register WooCommerce account endpoints as a nav menu item type. + * + * @since 3.1.0 + * @param array $item_types Menu item types. + * @return array + */ + public function register_customize_nav_menu_item_types( $item_types ) { + $item_types[] = array( + 'title' => __( 'WooCommerce endpoints', 'woocommerce' ), + 'type_label' => __( 'WooCommerce endpoint', 'woocommerce' ), + 'type' => 'woocommerce_nav', + 'object' => 'woocommerce_endpoint', ); + + return $item_types; } - return $items; + /** + * Register account endpoints to customize nav menu items. + * + * @since 3.1.0 + * @param array $items List of nav menu items. + * @param string $type Nav menu type. + * @param string $object Nav menu object. + * @param integer $page Page number. + * @return array + */ + public function register_customize_nav_menu_items( $items = array(), $type = '', $object = '', $page = 0 ) { + if ( 'woocommerce_endpoint' !== $object ) { + return $items; + } + + // Don't allow pagination since all items are loaded at once. + if ( 0 < $page ) { + return $items; + } + + // Get items from account menu. + $endpoints = wc_get_account_menu_items(); + + // Remove dashboard item. + if ( isset( $endpoints['dashboard'] ) ) { + unset( $endpoints['dashboard'] ); + } + + // Include missing lost password. + $endpoints['lost-password'] = __( 'Lost password', 'woocommerce' ); + + $endpoints = apply_filters( 'woocommerce_custom_nav_menu_items', $endpoints ); + + foreach ( $endpoints as $endpoint => $title ) { + $items[] = array( + 'id' => $endpoint, + 'title' => $title, + 'type_label' => __( 'Custom Link', 'woocommerce' ), + 'url' => esc_url_raw( wc_get_account_endpoint_url( $endpoint ) ), + ); + } + + return $items; + } } -} endif; diff --git a/includes/admin/class-wc-admin-dashboard.php b/includes/admin/class-wc-admin-dashboard.php index 40b35baad7e..1cf6bbe7c7a 100644 --- a/includes/admin/class-wc-admin-dashboard.php +++ b/includes/admin/class-wc-admin-dashboard.php @@ -14,103 +14,105 @@ if ( ! defined( 'ABSPATH' ) ) { if ( ! class_exists( 'WC_Admin_Dashboard', false ) ) : -/** - * WC_Admin_Dashboard Class. - */ -class WC_Admin_Dashboard { - /** - * Hook in tabs. + * WC_Admin_Dashboard Class. */ - public function __construct() { - // Only hook in admin parts if the user has admin access - if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'manage_woocommerce' ) || current_user_can( 'publish_shop_orders' ) ) { - // If on network admin, only load the widget that works in that context and skip the rest. - if ( is_multisite() && is_network_admin() ) { - add_action( 'wp_network_dashboard_setup', array( $this, 'register_network_order_widget' ) ); - } else { - add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); + class WC_Admin_Dashboard { + + /** + * Hook in tabs. + */ + public function __construct() { + // Only hook in admin parts if the user has admin access + if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'manage_woocommerce' ) || current_user_can( 'publish_shop_orders' ) ) { + // If on network admin, only load the widget that works in that context and skip the rest. + if ( is_multisite() && is_network_admin() ) { + add_action( 'wp_network_dashboard_setup', array( $this, 'register_network_order_widget' ) ); + } else { + add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); + } } } - } - /** - * Init dashboard widgets. - */ - public function init() { - if ( current_user_can( 'publish_shop_orders' ) && post_type_supports( 'product', 'comments' ) ) { - wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce recent reviews', 'woocommerce' ), array( $this, 'recent_reviews' ) ); + /** + * Init dashboard widgets. + */ + public function init() { + if ( current_user_can( 'publish_shop_orders' ) && post_type_supports( 'product', 'comments' ) ) { + wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce recent reviews', 'woocommerce' ), array( $this, 'recent_reviews' ) ); + } + wp_add_dashboard_widget( 'woocommerce_dashboard_status', __( 'WooCommerce status', 'woocommerce' ), array( $this, 'status_widget' ) ); + + // Network Order Widget. + if ( is_multisite() ) { + $this->register_network_order_widget(); + } } - wp_add_dashboard_widget( 'woocommerce_dashboard_status', __( 'WooCommerce status', 'woocommerce' ), array( $this, 'status_widget' ) ); - // Network Order Widget. - if ( is_multisite() ) { - $this->register_network_order_widget(); + /** + * Register the network order dashboard widget. + */ + public function register_network_order_widget() { + wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce network orders', 'woocommerce' ), array( $this, 'network_orders' ) ); } - } - /** - * Register the network order dashboard widget. - */ - public function register_network_order_widget() { - wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce network orders', 'woocommerce' ), array( $this, 'network_orders' ) ); - } + /** + * Get top seller from DB. + * + * @return object + */ + private function get_top_seller() { + global $wpdb; - /** - * Get top seller from DB. - * @return object - */ - private function get_top_seller() { - global $wpdb; - - $query = array(); - $query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id + $query = array(); + $query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id FROM {$wpdb->posts} as posts"; - $query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id "; - $query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id "; - $query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id "; - $query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) "; - $query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) "; - $query['where'] .= "AND order_item_meta.meta_key = '_qty' "; - $query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' "; - $query['where'] .= "AND posts.post_date >= '" . date( 'Y-m-01', current_time( 'timestamp' ) ) . "' "; - $query['where'] .= "AND posts.post_date <= '" . date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) . "' "; - $query['groupby'] = "GROUP BY product_id"; - $query['orderby'] = "ORDER BY qty DESC"; - $query['limits'] = "LIMIT 1"; + $query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id "; + $query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id "; + $query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id "; + $query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) "; + $query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) "; + $query['where'] .= "AND order_item_meta.meta_key = '_qty' "; + $query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' "; + $query['where'] .= "AND posts.post_date >= '" . date( 'Y-m-01', current_time( 'timestamp' ) ) . "' "; + $query['where'] .= "AND posts.post_date <= '" . date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) . "' "; + $query['groupby'] = 'GROUP BY product_id'; + $query['orderby'] = 'ORDER BY qty DESC'; + $query['limits'] = 'LIMIT 1'; - return $wpdb->get_row( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_top_seller_query', $query ) ) ); - } + return $wpdb->get_row( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_top_seller_query', $query ) ) ); + } - /** - * Get sales report data. - * @return object - */ - private function get_sales_report_data() { - include_once( dirname( __FILE__ ) . '/reports/class-wc-report-sales-by-date.php' ); + /** + * Get sales report data. + * + * @return object + */ + private function get_sales_report_data() { + include_once dirname( __FILE__ ) . '/reports/class-wc-report-sales-by-date.php'; - $sales_by_date = new WC_Report_Sales_By_Date(); - $sales_by_date->start_date = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) ); - $sales_by_date->end_date = current_time( 'timestamp' ); - $sales_by_date->chart_groupby = 'day'; - $sales_by_date->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)'; + $sales_by_date = new WC_Report_Sales_By_Date(); + $sales_by_date->start_date = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) ); + $sales_by_date->end_date = current_time( 'timestamp' ); + $sales_by_date->chart_groupby = 'day'; + $sales_by_date->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)'; - return $sales_by_date->get_report_data(); - } + return $sales_by_date->get_report_data(); + } - /** - * Show status widget. - */ - public function status_widget() { - include_once( dirname( __FILE__ ) . '/reports/class-wc-admin-report.php' ); + /** + * Show status widget. + */ + public function status_widget() { + include_once dirname( __FILE__ ) . '/reports/class-wc-admin-report.php'; - $reports = new WC_Admin_Report(); + $reports = new WC_Admin_Report(); - echo ''; - } - - /** - * Show order data is status widget. - */ - private function status_widget_order_rows() { - if ( ! current_user_can( 'edit_shop_orders' ) ) { - return; - } - $on_hold_count = 0; - $processing_count = 0; - - foreach ( wc_get_order_types( 'order-count' ) as $type ) { - $counts = (array) wp_count_posts( $type ); - $on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0; - $processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0; - } - ?> -
  • + foreach ( wc_get_order_types( 'order-count' ) as $type ) { + $counts = (array) wp_count_posts( $type ); + $on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0; + $processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0; + } + ?> +
  • - -
  • -
  • - + +
  • +
  • + - -
  • - posts} as posts - INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id - INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id - WHERE 1=1 - AND posts.post_type IN ( 'product', 'product_variation' ) - AND posts.post_status = 'publish' - AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' - AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' - AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}' - " ); - $lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); - set_transient( $transient_name, $lowinstock_count, DAY_IN_SECONDS * 30 ); + + + posts} as posts - INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id - INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id - WHERE 1=1 - AND posts.post_type IN ( 'product', 'product_variation' ) - AND posts.post_status = 'publish' - AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' - AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}' - " ); - $outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); - set_transient( $transient_name, $outofstock_count, DAY_IN_SECONDS * 30 ); - } - ?> -
  • + // Get products using a query - this is too advanced for get_posts :( + $stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) ); + $nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) ); + $transient_name = 'wc_low_stock_count'; + + if ( false === ( $lowinstock_count = get_transient( $transient_name ) ) ) { + $query_from = apply_filters( + 'woocommerce_report_low_in_stock_query_from', + "FROM {$wpdb->posts} as posts + INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id + INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id + WHERE 1=1 + AND posts.post_type IN ( 'product', 'product_variation' ) + AND posts.post_status = 'publish' + AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' + AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' + AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}'" + ); + $lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); + set_transient( $transient_name, $lowinstock_count, DAY_IN_SECONDS * 30 ); + } + + $transient_name = 'wc_outofstock_count'; + + if ( false === ( $outofstock_count = get_transient( $transient_name ) ) ) { + $query_from = apply_filters( + 'woocommerce_report_out_of_stock_query_from', + "FROM {$wpdb->posts} as posts + INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id + INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id + WHERE 1=1 + AND posts.post_type IN ( 'product', 'product_variation' ) + AND posts.post_status = 'publish' + AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' + AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}'" + ); + $outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); + set_transient( $transient_name, $outofstock_count, DAY_IN_SECONDS * 30 ); + } + ?> +
  • - -
  • -
  • - + +
  • +
  • + - -
  • - comments} comments - LEFT JOIN {$wpdb->posts} posts ON (comments.comment_post_ID = posts.ID) - WHERE comments.comment_approved = '1' - AND comments.comment_type = '' - AND posts.post_password = '' - AND posts.post_type = 'product' - AND comments.comment_parent = 0 - ORDER BY comments.comment_date_gmt DESC - LIMIT 5 - " ); - - $comments = $wpdb->get_results( " - SELECT posts.ID, posts.post_title, comments.comment_author, comments.comment_ID, comments.comment_content - {$query_from}; - " ); - - if ( $comments ) { - echo '
      '; - foreach ( $comments as $comment ) { - - echo '
    • '; - - echo get_avatar( $comment->comment_author, '32' ); - - $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ); - - /* translators: %s: rating */ - echo '
      ' . sprintf( __( '%s out of 5', 'woocommerce' ), $rating ) . '
      '; - - /* translators: %s: review author */ - echo '

      ' . esc_html( apply_filters( 'woocommerce_admin_dashboard_recent_reviews', $comment->post_title, $comment ) ) . ' ' . sprintf( __( 'reviewed by %s', 'woocommerce' ), esc_html( $comment->comment_author ) ) . '

      '; - echo '
      ' . wp_kses_data( $comment->comment_content ) . '
    • '; - - } - echo '
    '; - } else { - echo '

    ' . __( 'There are no product reviews yet.', 'woocommerce' ) . '

    '; + + + plugin_url() . '/assets/css/network-order-widget.css', array(), WC_VERSION ); + $query_from = apply_filters( + 'woocommerce_report_recent_reviews_query_from', + "FROM {$wpdb->comments} comments + LEFT JOIN {$wpdb->posts} posts ON (comments.comment_post_ID = posts.ID) + WHERE comments.comment_approved = '1' + AND comments.comment_type = '' + AND posts.post_password = '' + AND posts.post_type = 'product' + AND comments.comment_parent = 0 + ORDER BY comments.comment_date_gmt DESC + LIMIT 5" + ); - wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), WC_VERSION, true ); + $comments = $wpdb->get_results( + "SELECT posts.ID, posts.post_title, comments.comment_author, comments.comment_ID, comments.comment_content {$query_from};" + ); - $user = wp_get_current_user(); - $blogs = get_blogs_of_user( $user->ID ); - $blog_ids = wp_list_pluck( $blogs, 'userblog_id' ); + if ( $comments ) { + echo '
      '; + foreach ( $comments as $comment ) { - wp_localize_script( 'wc-network-orders', 'woocommerce_network_orders', array( - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'sites' => array_values( $blog_ids ), - 'order_endpoint' => get_rest_url( null, 'wc/v2/orders/network' ), - ) ); - ?> -
      + echo '
    • '; + + echo get_avatar( $comment->comment_author, '32' ); + + $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ); + + /* translators: %s: rating */ + echo '
      ' . sprintf( __( '%s out of 5', 'woocommerce' ), $rating ) . '
      '; + + /* translators: %s: review author */ + echo '

      ' . esc_html( apply_filters( 'woocommerce_admin_dashboard_recent_reviews', $comment->post_title, $comment ) ) . ' ' . sprintf( __( 'reviewed by %s', 'woocommerce' ), esc_html( $comment->comment_author ) ) . '

      '; + echo '
      ' . wp_kses_data( $comment->comment_content ) . '
    • '; + + } + echo '
    '; + } else { + echo '

    ' . __( 'There are no product reviews yet.', 'woocommerce' ) . '

    '; + } + } + + /** + * Network orders widget. + */ + public function network_orders() { + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + + wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), WC_VERSION ); + + wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), WC_VERSION, true ); + + $user = wp_get_current_user(); + $blogs = get_blogs_of_user( $user->ID ); + $blog_ids = wp_list_pluck( $blogs, 'userblog_id' ); + + wp_localize_script( + 'wc-network-orders', 'woocommerce_network_orders', array( + 'nonce' => wp_create_nonce( 'wp_rest' ), + 'sites' => array_values( $blog_ids ), + 'order_endpoint' => get_rest_url( null, 'wc/v2/orders/network' ), + ) + ); + ?> +

    @@ -367,9 +376,9 @@ class WC_Admin_Dashboard {

    plugin_url() . '/assets/js/admin/wc-product-export' . $suffix . '.js', array( 'jquery' ), WC_VERSION ); - wp_localize_script( 'wc-product-export', 'wc_product_export_params', array( - 'export_nonce' => wp_create_nonce( 'wc-product-export' ), - ) ); + wp_localize_script( + 'wc-product-export', + 'wc_product_export_params', + array( + 'export_nonce' => wp_create_nonce( 'wc-product-export' ), + ) + ); } /** * Export page UI. */ public function product_exporter() { - include_once( WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php' ); - include_once( dirname( __FILE__ ) . '/views/html-admin-page-product-export.php' ); + include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php'; + include_once dirname( __FILE__ ) . '/views/html-admin-page-product-export.php'; } /** @@ -91,7 +95,7 @@ class WC_Admin_Exporters { */ public function download_export_file() { if ( isset( $_GET['action'], $_GET['nonce'] ) && wp_verify_nonce( wp_unslash( $_GET['nonce'] ), 'product-csv' ) && 'download_product_csv' === wp_unslash( $_GET['action'] ) ) { // WPCS: input var ok, sanitization ok. - include_once( WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php' ); + include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php'; $exporter = new WC_Product_CSV_Exporter(); if ( ! empty( $_GET['filename'] ) ) { // WPCS: input var ok. @@ -112,7 +116,7 @@ class WC_Admin_Exporters { wp_die( -1 ); } - include_once( WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php' ); + include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php'; $step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; // WPCS: input var ok, sanitization ok. $exporter = new WC_Product_CSV_Exporter(); @@ -140,20 +144,31 @@ class WC_Admin_Exporters { $exporter->set_page( $step ); $exporter->generate_file(); - $query_args = apply_filters( 'woocommerce_export_get_ajax_query_args', array( 'nonce' => wp_create_nonce( 'product-csv' ), 'action' => 'download_product_csv', 'filename' => $exporter->get_filename() ) ); + $query_args = apply_filters( + 'woocommerce_export_get_ajax_query_args', + array( + 'nonce' => wp_create_nonce( 'product-csv' ), + 'action' => 'download_product_csv', + 'filename' => $exporter->get_filename(), + ) + ); if ( 100 === $exporter->get_percent_complete() ) { - wp_send_json_success( array( - 'step' => 'done', - 'percentage' => 100, - 'url' => add_query_arg( $query_args, admin_url( 'edit.php?post_type=product&page=product_exporter' ) ), - ) ); + wp_send_json_success( + array( + 'step' => 'done', + 'percentage' => 100, + 'url' => add_query_arg( $query_args, admin_url( 'edit.php?post_type=product&page=product_exporter' ) ), + ) + ); } else { - wp_send_json_success( array( - 'step' => ++$step, - 'percentage' => $exporter->get_percent_complete(), - 'columns' => $exporter->get_column_names(), - ) ); + wp_send_json_success( + array( + 'step' => ++$step, + 'percentage' => $exporter->get_percent_complete(), + 'columns' => $exporter->get_column_names(), + ) + ); } } } diff --git a/includes/admin/class-wc-admin-help.php b/includes/admin/class-wc-admin-help.php index f4e579c900a..26d9b39c486 100644 --- a/includes/admin/class-wc-admin-help.php +++ b/includes/admin/class-wc-admin-help.php @@ -36,55 +36,63 @@ class WC_Admin_Help { return; } - $screen->add_help_tab( array( - 'id' => 'woocommerce_support_tab', - 'title' => __( 'Help & Support', 'woocommerce' ), - 'content' => - '

    ' . __( 'Help & Support', 'woocommerce' ) . '

    ' . - '

    ' . sprintf( - /* translators: %s: Documentation URL */ - __( 'Should you need help understanding, using, or extending WooCommerce, please read our documentation. You will find all kinds of resources including snippets, tutorials and much more.', 'woocommerce' ), - 'https://docs.woocommerce.com/documentation/plugins/woocommerce/?utm_source=helptab&utm_medium=product&utm_content=docs&utm_campaign=woocommerceplugin' - ) . '

    ' . - '

    ' . sprintf( - /* translators: %s: Forum URL */ - __( 'For further assistance with WooCommerce core you can use the community forum. If you need help with premium extensions sold by WooCommerce, please use our helpdesk.', 'woocommerce' ), - 'https://wordpress.org/support/plugin/woocommerce', - 'https://woocommerce.com/my-account/tickets/?utm_source=helptab&utm_medium=product&utm_content=tickets&utm_campaign=woocommerceplugin' - ) . '

    ' . - '

    ' . __( 'Before asking for help we recommend checking the system status page to identify any problems with your configuration.', 'woocommerce' ) . '

    ' . - '

    ' . __( 'System status', 'woocommerce' ) . ' ' . __( 'Community forum', 'woocommerce' ) . ' ' . __( 'WooCommerce helpdesk', 'woocommerce' ) . '

    ', - ) ); + $screen->add_help_tab( + array( + 'id' => 'woocommerce_support_tab', + 'title' => __( 'Help & Support', 'woocommerce' ), + 'content' => + '

    ' . __( 'Help & Support', 'woocommerce' ) . '

    ' . + '

    ' . sprintf( + /* translators: %s: Documentation URL */ + __( 'Should you need help understanding, using, or extending WooCommerce, please read our documentation. You will find all kinds of resources including snippets, tutorials and much more.', 'woocommerce' ), + 'https://docs.woocommerce.com/documentation/plugins/woocommerce/?utm_source=helptab&utm_medium=product&utm_content=docs&utm_campaign=woocommerceplugin' + ) . '

    ' . + '

    ' . sprintf( + /* translators: %s: Forum URL */ + __( 'For further assistance with WooCommerce core you can use the community forum. If you need help with premium extensions sold by WooCommerce, please use our helpdesk.', 'woocommerce' ), + 'https://wordpress.org/support/plugin/woocommerce', + 'https://woocommerce.com/my-account/tickets/?utm_source=helptab&utm_medium=product&utm_content=tickets&utm_campaign=woocommerceplugin' + ) . '

    ' . + '

    ' . __( 'Before asking for help we recommend checking the system status page to identify any problems with your configuration.', 'woocommerce' ) . '

    ' . + '

    ' . __( 'System status', 'woocommerce' ) . ' ' . __( 'Community forum', 'woocommerce' ) . ' ' . __( 'WooCommerce helpdesk', 'woocommerce' ) . '

    ', + ) + ); - $screen->add_help_tab( array( - 'id' => 'woocommerce_bugs_tab', - 'title' => __( 'Found a bug?', 'woocommerce' ), - 'content' => - '

    ' . __( 'Found a bug?', 'woocommerce' ) . '

    ' . - /* translators: 1: GitHub issues URL 2: GitHub contribution guide URL 3: System status report URL */ - '

    ' . sprintf( __( 'If you find a bug within WooCommerce core you can create a ticket via Github issues. Ensure you read the contribution guide prior to submitting your report. To help us solve your issue, please be as descriptive as possible and include your system status report.', 'woocommerce' ), 'https://github.com/woocommerce/woocommerce/issues?state=open', 'https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md', admin_url( 'admin.php?page=wc-status' ) ) . '

    ' . - '

    ' . __( 'Report a bug', 'woocommerce' ) . ' ' . __( 'System status', 'woocommerce' ) . '

    ', + $screen->add_help_tab( + array( + 'id' => 'woocommerce_bugs_tab', + 'title' => __( 'Found a bug?', 'woocommerce' ), + 'content' => + '

    ' . __( 'Found a bug?', 'woocommerce' ) . '

    ' . + /* translators: 1: GitHub issues URL 2: GitHub contribution guide URL 3: System status report URL */ + '

    ' . sprintf( __( 'If you find a bug within WooCommerce core you can create a ticket via Github issues. Ensure you read the contribution guide prior to submitting your report. To help us solve your issue, please be as descriptive as possible and include your system status report.', 'woocommerce' ), 'https://github.com/woocommerce/woocommerce/issues?state=open', 'https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md', admin_url( 'admin.php?page=wc-status' ) ) . '

    ' . + '

    ' . __( 'Report a bug', 'woocommerce' ) . ' ' . __( 'System status', 'woocommerce' ) . '

    ', - ) ); + ) + ); - $screen->add_help_tab( array( - 'id' => 'woocommerce_education_tab', - 'title' => __( 'Education', 'woocommerce' ), - 'content' => - '

    ' . __( 'Education', 'woocommerce' ) . '

    ' . - '

    ' . __( 'If you would like to learn about using WooCommerce from an expert, consider following a WooCommerce course offered by one of our educational partners.', 'woocommerce' ) . '

    ' . - '

    ' . __( 'View education partners', 'woocommerce' ) . '

    ', - ) ); + $screen->add_help_tab( + array( + 'id' => 'woocommerce_education_tab', + 'title' => __( 'Education', 'woocommerce' ), + 'content' => + '

    ' . __( 'Education', 'woocommerce' ) . '

    ' . + '

    ' . __( 'If you would like to learn about using WooCommerce from an expert, consider following a WooCommerce course offered by one of our educational partners.', 'woocommerce' ) . '

    ' . + '

    ' . __( 'View education partners', 'woocommerce' ) . '

    ', + ) + ); - $screen->add_help_tab( array( - 'id' => 'woocommerce_onboard_tab', - 'title' => __( 'Setup wizard', 'woocommerce' ), - 'content' => - '

    ' . __( 'Setup wizard', 'woocommerce' ) . '

    ' . - '

    ' . __( 'If you need to access the setup wizard again, please click on the button below.', 'woocommerce' ) . '

    ' . - '

    ' . __( 'Setup wizard', 'woocommerce' ) . '

    ', + $screen->add_help_tab( + array( + 'id' => 'woocommerce_onboard_tab', + 'title' => __( 'Setup wizard', 'woocommerce' ), + 'content' => + '

    ' . __( 'Setup wizard', 'woocommerce' ) . '

    ' . + '

    ' . __( 'If you need to access the setup wizard again, please click on the button below.', 'woocommerce' ) . '

    ' . + '

    ' . __( 'Setup wizard', 'woocommerce' ) . '

    ', - ) ); + ) + ); $screen->set_help_sidebar( '

    ' . __( 'For more information:', 'woocommerce' ) . '

    ' . diff --git a/includes/admin/class-wc-admin-importers.php b/includes/admin/class-wc-admin-importers.php index 43d88fa4d66..7829a1efed3 100644 --- a/includes/admin/class-wc-admin-importers.php +++ b/includes/admin/class-wc-admin-importers.php @@ -89,8 +89,8 @@ class WC_Admin_Importers { exit; } - include_once( WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php' ); - include_once( WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php' ); + include_once WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php'; + include_once WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php'; $importer = new WC_Product_CSV_Importer_Controller(); $importer->dispatch(); @@ -102,7 +102,7 @@ class WC_Admin_Importers { public function register_importers() { if ( defined( 'WP_LOAD_IMPORTERS' ) ) { add_action( 'import_start', array( $this, 'post_importer_compatibility' ) ); - register_importer( 'woocommerce_product_csv', __( 'WooCommerce products (CSV)', 'woocommerce' ), __( 'Import products to your store via a csv file.', 'woocommerce' ), array( $this, 'product_importer' ) ); + register_importer( 'woocommerce_product_csv', __( 'WooCommerce products (CSV)', 'woocommerce' ), __( 'Import products to your store via a csv file.', 'woocommerce' ), array( $this, 'product_importer' ) ); register_importer( 'woocommerce_tax_rate_csv', __( 'WooCommerce tax rates (CSV)', 'woocommerce' ), __( 'Import tax rates to your store via a csv file.', 'woocommerce' ), array( $this, 'tax_rates_importer' ) ); } } @@ -123,7 +123,7 @@ class WC_Admin_Importers { } // includes - require( dirname( __FILE__ ) . '/importers/class-wc-tax-rate-importer.php' ); + require dirname( __FILE__ ) . '/importers/class-wc-tax-rate-importer.php'; // Dispatch $importer = new WC_Tax_Rate_Importer(); @@ -158,25 +158,29 @@ class WC_Admin_Importers { // Create the taxonomy if ( ! in_array( $attribute_name, wc_get_attribute_taxonomies() ) ) { - wc_create_attribute( array( - 'name' => $attribute_name, - 'slug' => $attribute_name, - 'type' => 'select', - 'order_by' => 'menu_order', - 'has_archives' => false, - ) ); + wc_create_attribute( + array( + 'name' => $attribute_name, + 'slug' => $attribute_name, + 'type' => 'select', + 'order_by' => 'menu_order', + 'has_archives' => false, + ) + ); } // Register the taxonomy now so that the import works! register_taxonomy( $term['domain'], apply_filters( 'woocommerce_taxonomy_objects_' . $term['domain'], array( 'product' ) ), - apply_filters( 'woocommerce_taxonomy_args_' . $term['domain'], array( - 'hierarchical' => true, - 'show_ui' => false, - 'query_var' => true, - 'rewrite' => false, - ) ) + apply_filters( + 'woocommerce_taxonomy_args_' . $term['domain'], array( + 'hierarchical' => true, + 'show_ui' => false, + 'query_var' => true, + 'rewrite' => false, + ) + ) ); } } @@ -198,8 +202,8 @@ class WC_Admin_Importers { wp_die( -1 ); } - include_once( WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php' ); - include_once( WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php' ); + include_once WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php'; + include_once WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php'; $file = wc_clean( $_POST['file'] ); $params = array( @@ -228,36 +232,40 @@ class WC_Admin_Importers { if ( 100 === $percent_complete ) { // Clear temp meta. $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_original_id' ) ); - $wpdb->query( " - DELETE {$wpdb->posts}, {$wpdb->postmeta}, {$wpdb->term_relationships} + $wpdb->query( + "DELETE {$wpdb->posts}, {$wpdb->postmeta}, {$wpdb->term_relationships} FROM {$wpdb->posts} LEFT JOIN {$wpdb->term_relationships} ON ( {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id ) LEFT JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id ) LEFT JOIN {$wpdb->term_taxonomy} ON ( {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id ) LEFT JOIN {$wpdb->terms} ON ( {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id ) WHERE {$wpdb->posts}.post_type IN ( 'product', 'product_variation' ) - AND {$wpdb->posts}.post_status = 'importing' - " ); + AND {$wpdb->posts}.post_status = 'importing'" + ); // Send success. - wp_send_json_success( array( - 'position' => 'done', - 'percentage' => 100, - 'url' => add_query_arg( array( 'nonce' => wp_create_nonce( 'product-csv' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ), - 'imported' => count( $results['imported'] ), - 'failed' => count( $results['failed'] ), - 'updated' => count( $results['updated'] ), - 'skipped' => count( $results['skipped'] ), - ) ); + wp_send_json_success( + array( + 'position' => 'done', + 'percentage' => 100, + 'url' => add_query_arg( array( 'nonce' => wp_create_nonce( 'product-csv' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ), + 'imported' => count( $results['imported'] ), + 'failed' => count( $results['failed'] ), + 'updated' => count( $results['updated'] ), + 'skipped' => count( $results['skipped'] ), + ) + ); } else { - wp_send_json_success( array( - 'position' => $importer->get_file_position(), - 'percentage' => $percent_complete, - 'imported' => count( $results['imported'] ), - 'failed' => count( $results['failed'] ), - 'updated' => count( $results['updated'] ), - 'skipped' => count( $results['skipped'] ), - ) ); + wp_send_json_success( + array( + 'position' => $importer->get_file_position(), + 'percentage' => $percent_complete, + 'imported' => count( $results['imported'] ), + 'failed' => count( $results['failed'] ), + 'updated' => count( $results['updated'] ), + 'skipped' => count( $results['skipped'] ), + ) + ); } } } diff --git a/includes/admin/class-wc-admin-log-table-list.php b/includes/admin/class-wc-admin-log-table-list.php index afc7f8a3e76..b518318064d 100644 --- a/includes/admin/class-wc-admin-log-table-list.php +++ b/includes/admin/class-wc-admin-log-table-list.php @@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) { } if ( ! class_exists( 'WP_List_Table' ) ) { - require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; } class WC_Admin_Log_Table_List extends WP_List_Table { @@ -22,11 +22,13 @@ class WC_Admin_Log_Table_List extends WP_List_Table { * Initialize the log table list. */ public function __construct() { - parent::__construct( array( - 'singular' => 'log', - 'plural' => 'logs', - 'ajax' => false, - ) ); + parent::__construct( + array( + 'singular' => 'log', + 'plural' => 'logs', + 'ajax' => false, + ) + ); } /** @@ -37,14 +39,38 @@ class WC_Admin_Log_Table_List extends WP_List_Table { public function level_dropdown() { $levels = array( - array( 'value' => WC_Log_Levels::EMERGENCY, 'label' => __( 'Emergency', 'woocommerce' ) ), - array( 'value' => WC_Log_Levels::ALERT, 'label' => __( 'Alert', 'woocommerce' ) ), - array( 'value' => WC_Log_Levels::CRITICAL, 'label' => __( 'Critical', 'woocommerce' ) ), - array( 'value' => WC_Log_Levels::ERROR, 'label' => __( 'Error', 'woocommerce' ) ), - array( 'value' => WC_Log_Levels::WARNING, 'label' => __( 'Warning', 'woocommerce' ) ), - array( 'value' => WC_Log_Levels::NOTICE, 'label' => __( 'Notice', 'woocommerce' ) ), - array( 'value' => WC_Log_Levels::INFO, 'label' => __( 'Info', 'woocommerce' ) ), - array( 'value' => WC_Log_Levels::DEBUG, 'label' => __( 'Debug', 'woocommerce' ) ), + array( + 'value' => WC_Log_Levels::EMERGENCY, + 'label' => __( 'Emergency', 'woocommerce' ), + ), + array( + 'value' => WC_Log_Levels::ALERT, + 'label' => __( 'Alert', 'woocommerce' ), + ), + array( + 'value' => WC_Log_Levels::CRITICAL, + 'label' => __( 'Critical', 'woocommerce' ), + ), + array( + 'value' => WC_Log_Levels::ERROR, + 'label' => __( 'Error', 'woocommerce' ), + ), + array( + 'value' => WC_Log_Levels::WARNING, + 'label' => __( 'Warning', 'woocommerce' ), + ), + array( + 'value' => WC_Log_Levels::NOTICE, + 'label' => __( 'Notice', 'woocommerce' ), + ), + array( + 'value' => WC_Log_Levels::INFO, + 'label' => __( 'Info', 'woocommerce' ), + ), + array( + 'value' => WC_Log_Levels::DEBUG, + 'label' => __( 'Debug', 'woocommerce' ), + ), ); $selected_level = isset( $_REQUEST['level'] ) ? $_REQUEST['level'] : ''; @@ -52,13 +78,16 @@ class WC_Admin_Log_Table_List extends WP_List_Table { '', 'timestamp' => __( 'Timestamp', 'woocommerce' ), - 'level' => __( 'Level', 'woocommerce' ), - 'message' => __( 'Message', 'woocommerce' ), - 'source' => __( 'Source', 'woocommerce' ), + 'level' => __( 'Level', 'woocommerce' ), + 'message' => __( 'Message', 'woocommerce' ), + 'source' => __( 'Source', 'woocommerce' ), ); } @@ -95,10 +124,12 @@ class WC_Admin_Log_Table_List extends WP_List_Table { * @return string */ public function column_timestamp( $log ) { - return esc_html( mysql2date( - get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), - $log['timestamp'] - ) ); + return esc_html( + mysql2date( + get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), + $log['timestamp'] + ) + ); } /** @@ -111,17 +142,17 @@ class WC_Admin_Log_Table_List extends WP_List_Table { $level_key = WC_Log_Levels::get_severity_level( $log['level'] ); $levels = array( 'emergency' => __( 'Emergency', 'woocommerce' ), - 'alert' => __( 'Alert', 'woocommerce' ), - 'critical' => __( 'Critical', 'woocommerce' ), - 'error' => __( 'Error', 'woocommerce' ), - 'warning' => __( 'Warning', 'woocommerce' ), - 'notice' => __( 'Notice', 'woocommerce' ), - 'info' => __( 'Info', 'woocommerce' ), - 'debug' => __( 'Debug', 'woocommerce' ), + 'alert' => __( 'Alert', 'woocommerce' ), + 'critical' => __( 'Critical', 'woocommerce' ), + 'error' => __( 'Error', 'woocommerce' ), + 'warning' => __( 'Warning', 'woocommerce' ), + 'notice' => __( 'Notice', 'woocommerce' ), + 'info' => __( 'Info', 'woocommerce' ), + 'debug' => __( 'Debug', 'woocommerce' ), ); if ( isset( $levels[ $level_key ] ) ) { - $level = $levels[ $level_key ]; + $level = $levels[ $level_key ]; $level_class = sanitize_html_class( 'log-level--' . $level_key ); return '' . esc_html( $level ) . ''; } else { @@ -183,8 +214,8 @@ class WC_Admin_Log_Table_List extends WP_List_Table { protected function get_sortable_columns() { return array( 'timestamp' => array( 'timestamp', true ), - 'level' => array( 'level', true ), - 'source' => array( 'source', true ), + 'level' => array( 'level', true ), + 'source' => array( 'source', true ), ); } @@ -196,12 +227,12 @@ class WC_Admin_Log_Table_List extends WP_List_Table { protected function source_dropdown() { global $wpdb; - $sources = $wpdb->get_col( " - SELECT DISTINCT source + $sources = $wpdb->get_col( + "SELECT DISTINCT source FROM {$wpdb->prefix}woocommerce_log WHERE source != '' - ORDER BY source ASC - " ); + ORDER BY source ASC" + ); if ( ! empty( $sources ) ) { $selected_source = isset( $_REQUEST['source'] ) ? $_REQUEST['source'] : ''; @@ -209,13 +240,16 @@ class WC_Admin_Log_Table_List extends WP_List_Table { prefix}woocommerce_log {$where}"; $total_items = $wpdb->get_var( $query_count ); - $this->set_pagination_args( array( - 'total_items' => $total_items, - 'per_page' => $per_page, - 'total_pages' => ceil( $total_items / $per_page ), - ) ); + $this->set_pagination_args( + array( + 'total_items' => $total_items, + 'per_page' => $per_page, + 'total_pages' => ceil( $total_items / $per_page ), + ) + ); } /** @@ -280,7 +316,7 @@ class WC_Admin_Log_Table_List extends WP_List_Table { protected function get_items_query_offset() { global $wpdb; - $per_page = $this->get_items_per_page( 'woocommerce_status_log_items_per_page', 10 ); + $per_page = $this->get_items_per_page( 'woocommerce_status_log_items_per_page', 10 ); $current_page = $this->get_pagenum(); if ( 1 < $current_page ) { $offset = $per_page * ( $current_page - 1 ); diff --git a/includes/admin/class-wc-admin-menus.php b/includes/admin/class-wc-admin-menus.php index fb14a868cb5..ca700685fd9 100644 --- a/includes/admin/class-wc-admin-menus.php +++ b/includes/admin/class-wc-admin-menus.php @@ -353,12 +353,14 @@ class WC_Admin_Menus { } // Add an option to visit the store. - $wp_admin_bar->add_node( array( - 'parent' => 'site-name', - 'id' => 'view-store', - 'title' => __( 'Visit Store', 'woocommerce' ), - 'href' => wc_get_page_permalink( 'shop' ), - ) ); + $wp_admin_bar->add_node( + array( + 'parent' => 'site-name', + 'id' => 'view-store', + 'title' => __( 'Visit Store', 'woocommerce' ), + 'href' => wc_get_page_permalink( 'shop' ), + ) + ); } } diff --git a/includes/admin/class-wc-admin-meta-boxes.php b/includes/admin/class-wc-admin-meta-boxes.php index e5e7e5bdd94..e70a1cbafd9 100644 --- a/includes/admin/class-wc-admin-meta-boxes.php +++ b/includes/admin/class-wc-admin-meta-boxes.php @@ -31,7 +31,7 @@ class WC_Admin_Meta_Boxes { * * @var array */ - public static $meta_box_errors = array(); + public static $meta_box_errors = array(); /** * Constructor. @@ -74,6 +74,7 @@ class WC_Admin_Meta_Boxes { /** * Add an error message. + * * @param string $text */ public static function add_error( $text ) { @@ -177,7 +178,7 @@ class WC_Admin_Meta_Boxes { /** * Check if we're saving, the trigger an action based on the post type. * - * @param int $post_id + * @param int $post_id * @param object $post */ public function save_meta_boxes( $post_id, $post ) { diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 49f66e2dab1..762a03af3c6 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -19,12 +19,14 @@ class WC_Admin_Notices { /** * Stores notices. + * * @var array */ private static $notices = array(); /** * Array of notices - name => callback. + * * @var array */ private static $core_notices = array( @@ -62,6 +64,7 @@ class WC_Admin_Notices { /** * Get notices + * * @return array */ public static function get_notices() { @@ -91,6 +94,7 @@ class WC_Admin_Notices { /** * Show a notice. + * * @param string $name */ public static function add_notice( $name ) { @@ -99,6 +103,7 @@ class WC_Admin_Notices { /** * Remove a notice from being displayed. + * * @param string $name */ public static function remove_notice( $name ) { @@ -108,7 +113,8 @@ class WC_Admin_Notices { /** * See if a notice is being shown. - * @param string $name + * + * @param string $name * @return boolean */ public static function has_notice( $name ) { @@ -162,6 +168,7 @@ class WC_Admin_Notices { /** * Add a custom notice. + * * @param string $name * @param string $notice_html */ @@ -182,7 +189,7 @@ class WC_Admin_Notices { $notice_html = get_option( 'woocommerce_admin_notice_' . $notice ); if ( $notice_html ) { - include( 'views/html-notice-custom.php' ); + include 'views/html-notice-custom.php'; } } } @@ -196,12 +203,12 @@ class WC_Admin_Notices { if ( version_compare( get_option( 'woocommerce_db_version' ), WC_VERSION, '<' ) ) { $updater = new WC_Background_Updater(); if ( $updater->is_updating() || ! empty( $_GET['do_update_woocommerce'] ) ) { - include( 'views/html-notice-updating.php' ); + include 'views/html-notice-updating.php'; } else { - include( 'views/html-notice-update.php' ); + include 'views/html-notice-update.php'; } } else { - include( 'views/html-notice-updated.php' ); + include 'views/html-notice-updated.php'; } } @@ -209,7 +216,7 @@ class WC_Admin_Notices { * If we have just installed, show a message with the install pages button. */ public static function install_notice() { - include( 'views/html-notice-install.php' ); + include 'views/html-notice-install.php'; } /** @@ -221,7 +228,7 @@ class WC_Admin_Notices { wc_deprecated_function( 'WC_Admin_Notices::theme_check_notice', '3.3.0' ); if ( ! current_theme_supports( 'woocommerce' ) ) { - include( 'views/html-notice-theme-support.php' ); + include 'views/html-notice-theme-support.php'; } } @@ -257,7 +264,7 @@ class WC_Admin_Notices { } if ( $outdated ) { - include( 'views/html-notice-template-check.php' ); + include 'views/html-notice-template-check.php'; } else { self::remove_notice( 'template_files' ); } @@ -278,7 +285,7 @@ class WC_Admin_Notices { } if ( $enabled ) { - include( 'views/html-notice-legacy-shipping.php' ); + include 'views/html-notice-legacy-shipping.php'; } else { self::remove_notice( 'template_files' ); } @@ -293,7 +300,7 @@ class WC_Admin_Notices { $method_count = wc_get_shipping_method_count(); if ( $product_count->publish > 0 && 0 === $method_count ) { - include( 'views/html-notice-no-shipping-methods.php' ); + include 'views/html-notice-no-shipping-methods.php'; } if ( $method_count > 0 ) { @@ -313,7 +320,7 @@ class WC_Admin_Notices { return; } if ( empty( $_GET['action'] ) ) { - include( 'views/html-notice-simplify-commerce.php' ); + include 'views/html-notice-simplify-commerce.php'; } } @@ -321,7 +328,7 @@ class WC_Admin_Notices { * Notice shown when regenerating thumbnails background process is running. */ public static function regenerating_thumbnails_notice() { - include( 'views/html-notice-regenerating-thumbnails.php' ); + include 'views/html-notice-regenerating-thumbnails.php'; } } diff --git a/includes/admin/class-wc-admin-permalink-settings.php b/includes/admin/class-wc-admin-permalink-settings.php index 64e78fef273..ec6534cc142 100644 --- a/includes/admin/class-wc-admin-permalink-settings.php +++ b/includes/admin/class-wc-admin-permalink-settings.php @@ -73,7 +73,7 @@ class WC_Admin_Permalink_Settings { */ public function product_category_slug_input() { ?> - + - + shop would make your product links like %sshop/sample-product/. This setting affects product URLs only, not things such as product categories.', 'woocommerce' ), esc_url( home_url( '/' ) ) ) ) ); - $shop_page_id = wc_get_page_id( 'shop' ); - $base_slug = urldecode( ( $shop_page_id > 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' ) ); - $product_base = _x( 'product', 'default-slug', 'woocommerce' ); + $shop_page_id = wc_get_page_id( 'shop' ); + $base_slug = urldecode( ( $shop_page_id > 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' ) ); + $product_base = _x( 'product', 'default-slug', 'woocommerce' ); $structures = array( 0 => '', diff --git a/includes/admin/class-wc-admin-pointers.php b/includes/admin/class-wc-admin-pointers.php index c4e7f2d4f62..af01866da68 100644 --- a/includes/admin/class-wc-admin-pointers.php +++ b/includes/admin/class-wc-admin-pointers.php @@ -33,9 +33,9 @@ class WC_Admin_Pointers { } switch ( $screen->id ) { - case 'product' : + case 'product': $this->create_product_tutorial(); - break; + break; } } @@ -49,8 +49,8 @@ class WC_Admin_Pointers { // These pointers will chain - they will not be shown at once. $pointers = array( 'pointers' => array( - 'title' => array( - 'target' => "#title", + 'title' => array( + 'target' => '#title', 'next' => 'content', 'next_trigger' => array( 'target' => '#title', @@ -65,8 +65,8 @@ class WC_Admin_Pointers { ), ), ), - 'content' => array( - 'target' => "#wp-content-editor-container", + 'content' => array( + 'target' => '#wp-content-editor-container', 'next' => 'product-type', 'next_trigger' => array(), 'options' => array( @@ -78,14 +78,14 @@ class WC_Admin_Pointers { ), ), ), - 'product-type' => array( - 'target' => "#product-type", + 'product-type' => array( + 'target' => '#product-type', 'next' => 'virtual', 'next_trigger' => array( - 'target' => "#product-type", + 'target' => '#product-type', 'event' => 'change blur click', ), - 'options' => array( + 'options' => array( 'content' => '

    ' . esc_html__( 'Choose product type', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( 'Choose a type for this product. Simple is suitable for most physical goods and services (we recommend setting up a simple product for now).', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( 'Variable is for more complex products such as t-shirts with multiple sizes.', 'woocommerce' ) . '

    ' . @@ -97,14 +97,14 @@ class WC_Admin_Pointers { ), ), ), - 'virtual' => array( - 'target' => "#_virtual", + 'virtual' => array( + 'target' => '#_virtual', 'next' => 'downloadable', 'next_trigger' => array( - 'target' => "#_virtual", + 'target' => '#_virtual', 'event' => 'change', ), - 'options' => array( + 'options' => array( 'content' => '

    ' . esc_html__( 'Virtual products', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( 'Check the "Virtual" box if this is a non-physical item, for example a service, which does not need shipping.', 'woocommerce' ) . '

    ', 'position' => array( @@ -113,14 +113,14 @@ class WC_Admin_Pointers { ), ), ), - 'downloadable' => array( - 'target' => "#_downloadable", + 'downloadable' => array( + 'target' => '#_downloadable', 'next' => 'regular_price', 'next_trigger' => array( - 'target' => "#_downloadable", + 'target' => '#_downloadable', 'event' => 'change', ), - 'options' => array( + 'options' => array( 'content' => '

    ' . esc_html__( 'Downloadable products', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( 'If purchasing this product gives a customer access to a downloadable file, e.g. software, check this box.', 'woocommerce' ) . '

    ', 'position' => array( @@ -129,14 +129,14 @@ class WC_Admin_Pointers { ), ), ), - 'regular_price' => array( - 'target' => "#_regular_price", + 'regular_price' => array( + 'target' => '#_regular_price', 'next' => 'postexcerpt', 'next_trigger' => array( - 'target' => "#_regular_price", + 'target' => '#_regular_price', 'event' => 'input', ), - 'options' => array( + 'options' => array( 'content' => '

    ' . esc_html__( 'Prices', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( 'Next you need to give your product a price.', 'woocommerce' ) . '

    ', 'position' => array( @@ -145,14 +145,14 @@ class WC_Admin_Pointers { ), ), ), - 'postexcerpt' => array( - 'target' => "#postexcerpt", + 'postexcerpt' => array( + 'target' => '#postexcerpt', 'next' => 'postimagediv', 'next_trigger' => array( - 'target' => "#postexcerpt", + 'target' => '#postexcerpt', 'event' => 'input', ), - 'options' => array( + 'options' => array( 'content' => '

    ' . esc_html__( 'Product short description', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( 'Add a quick summary for your product here. This will appear on the product page under the product name.', 'woocommerce' ) . '

    ', 'position' => array( @@ -161,9 +161,9 @@ class WC_Admin_Pointers { ), ), ), - 'postimagediv' => array( - 'target' => "#postimagediv", - 'next' => 'product_tag', + 'postimagediv' => array( + 'target' => '#postimagediv', + 'next' => 'product_tag', 'options' => array( 'content' => '

    ' . esc_html__( 'Product images', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( "Upload or assign an image to your product here. This image will be shown in your store's catalog.", 'woocommerce' ) . '

    ', @@ -173,9 +173,9 @@ class WC_Admin_Pointers { ), ), ), - 'product_tag' => array( - 'target' => "#tagsdiv-product_tag", - 'next' => 'product_catdiv', + 'product_tag' => array( + 'target' => '#tagsdiv-product_tag', + 'next' => 'product_catdiv', 'options' => array( 'content' => '

    ' . esc_html__( 'Product tags', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( 'You can optionally "tag" your products here. Tags are a method of labeling your products to make them easier for customers to find.', 'woocommerce' ) . '

    ', @@ -186,8 +186,8 @@ class WC_Admin_Pointers { ), ), 'product_catdiv' => array( - 'target' => "#product_catdiv", - 'next' => 'submitdiv', + 'target' => '#product_catdiv', + 'next' => 'submitdiv', 'options' => array( 'content' => '

    ' . esc_html__( 'Product categories', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( 'Optionally assign categories to your products to make them easier to browse through and find in your store.', 'woocommerce' ) . '

    ', @@ -197,9 +197,9 @@ class WC_Admin_Pointers { ), ), ), - 'submitdiv' => array( - 'target' => "#submitdiv", - 'next' => '', + 'submitdiv' => array( + 'target' => '#submitdiv', + 'next' => '', 'options' => array( 'content' => '

    ' . esc_html__( 'Publish your product!', 'woocommerce' ) . '

    ' . '

    ' . esc_html__( 'When you are finished editing your product, hit the "Publish" button to publish your product to your store.', 'woocommerce' ) . '

    ', @@ -217,14 +217,15 @@ class WC_Admin_Pointers { /** * Enqueue pointers and add script to page. + * * @param array $pointers */ public function enqueue_pointers( $pointers ) { $pointers = wp_json_encode( $pointers ); wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'wp-pointer' ); - wc_enqueue_js( " - jQuery( function( $ ) { + wc_enqueue_js( + "jQuery( function( $ ) { var wc_pointers = {$pointers}; setTimeout( init_wc_pointers, 800 ); @@ -277,8 +278,8 @@ class WC_Admin_Pointers { }); } } - }); - " ); + });" + ); } } diff --git a/includes/admin/class-wc-admin-post-types.php b/includes/admin/class-wc-admin-post-types.php index 68f048c6acd..ca82662f569 100644 --- a/includes/admin/class-wc-admin-post-types.php +++ b/includes/admin/class-wc-admin-post-types.php @@ -28,10 +28,10 @@ class WC_Admin_Post_Types { * Constructor. */ public function __construct() { - include_once( dirname( __FILE__ ) . '/class-wc-admin-meta-boxes.php' ); + include_once dirname( __FILE__ ) . '/class-wc-admin-meta-boxes.php'; if ( ! function_exists( 'duplicate_post_plugin_activation' ) ) { - include_once( 'class-wc-admin-duplicate-product.php' ); + include_once 'class-wc-admin-duplicate-product.php'; } // Load correct list table classes for current screen. @@ -65,7 +65,7 @@ class WC_Admin_Post_Types { // Bulk / quick edit. add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 ); - add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 ); + add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 ); add_action( 'save_post', array( $this, 'bulk_and_quick_edit_hook' ), 10, 2 ); add_action( 'woocommerce_product_bulk_and_quick_edit', array( $this, 'bulk_and_quick_edit_save_post' ), 10, 2 ); } @@ -88,16 +88,16 @@ class WC_Admin_Post_Types { } switch ( $screen_id ) { - case 'edit-shop_order' : - include_once( 'list-tables/class-wc-admin-list-table-orders.php' ); + case 'edit-shop_order': + include_once 'list-tables/class-wc-admin-list-table-orders.php'; new WC_Admin_List_Table_Orders(); break; - case 'edit-shop_coupon' : - include_once( 'list-tables/class-wc-admin-list-table-coupons.php' ); + case 'edit-shop_coupon': + include_once 'list-tables/class-wc-admin-list-table-coupons.php'; new WC_Admin_List_Table_Coupons(); break; - case 'edit-product' : - include_once( 'list-tables/class-wc-admin-list-table-products.php' ); + case 'edit-product': + include_once 'list-tables/class-wc-admin-list-table-products.php'; new WC_Admin_List_Table_Products(); break; } @@ -117,18 +117,18 @@ class WC_Admin_Post_Types { global $post; $messages['product'] = array( - 0 => '', // Unused. Messages start at index 1. - 1 => sprintf( __( 'Product updated. View Product', 'woocommerce' ), esc_url( get_permalink( $post->ID ) ) ), - 2 => __( 'Custom field updated.', 'woocommerce' ), - 3 => __( 'Custom field deleted.', 'woocommerce' ), - 4 => __( 'Product updated.', 'woocommerce' ), - 5 => __( 'Revision restored.', 'woocommerce' ), + 0 => '', // Unused. Messages start at index 1. + 1 => sprintf( __( 'Product updated. View Product', 'woocommerce' ), esc_url( get_permalink( $post->ID ) ) ), + 2 => __( 'Custom field updated.', 'woocommerce' ), + 3 => __( 'Custom field deleted.', 'woocommerce' ), + 4 => __( 'Product updated.', 'woocommerce' ), + 5 => __( 'Revision restored.', 'woocommerce' ), /* translators: %s: product url */ - 6 => sprintf( __( 'Product published. View Product', 'woocommerce' ), esc_url( get_permalink( $post->ID ) ) ), - 7 => __( 'Product saved.', 'woocommerce' ), + 6 => sprintf( __( 'Product published. View Product', 'woocommerce' ), esc_url( get_permalink( $post->ID ) ) ), + 7 => __( 'Product saved.', 'woocommerce' ), /* translators: %s: product url */ - 8 => sprintf( __( 'Product submitted. Preview product', 'woocommerce' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ), - 9 => sprintf( + 8 => sprintf( __( 'Product submitted. Preview product', 'woocommerce' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ), + 9 => sprintf( /* translators: 1: date 2: product url */ __( 'Product scheduled for: %1$s. Preview product', 'woocommerce' ), '' . date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post->ID ) ) . '' @@ -138,16 +138,16 @@ class WC_Admin_Post_Types { ); $messages['shop_order'] = array( - 0 => '', // Unused. Messages start at index 1. - 1 => __( 'Order updated.', 'woocommerce' ), - 2 => __( 'Custom field updated.', 'woocommerce' ), - 3 => __( 'Custom field deleted.', 'woocommerce' ), - 4 => __( 'Order updated.', 'woocommerce' ), - 5 => __( 'Revision restored.', 'woocommerce' ), - 6 => __( 'Order updated.', 'woocommerce' ), - 7 => __( 'Order saved.', 'woocommerce' ), - 8 => __( 'Order submitted.', 'woocommerce' ), - 9 => sprintf( + 0 => '', // Unused. Messages start at index 1. + 1 => __( 'Order updated.', 'woocommerce' ), + 2 => __( 'Custom field updated.', 'woocommerce' ), + 3 => __( 'Custom field deleted.', 'woocommerce' ), + 4 => __( 'Order updated.', 'woocommerce' ), + 5 => __( 'Revision restored.', 'woocommerce' ), + 6 => __( 'Order updated.', 'woocommerce' ), + 7 => __( 'Order saved.', 'woocommerce' ), + 8 => __( 'Order submitted.', 'woocommerce' ), + 9 => sprintf( /* translators: %s: date */ __( 'Order scheduled for: %s.', 'woocommerce' ), '' . date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $post->post_date ) ) . '' @@ -157,16 +157,16 @@ class WC_Admin_Post_Types { ); $messages['shop_coupon'] = array( - 0 => '', // Unused. Messages start at index 1. - 1 => __( 'Coupon updated.', 'woocommerce' ), - 2 => __( 'Custom field updated.', 'woocommerce' ), - 3 => __( 'Custom field deleted.', 'woocommerce' ), - 4 => __( 'Coupon updated.', 'woocommerce' ), - 5 => __( 'Revision restored.', 'woocommerce' ), - 6 => __( 'Coupon updated.', 'woocommerce' ), - 7 => __( 'Coupon saved.', 'woocommerce' ), - 8 => __( 'Coupon submitted.', 'woocommerce' ), - 9 => sprintf( + 0 => '', // Unused. Messages start at index 1. + 1 => __( 'Coupon updated.', 'woocommerce' ), + 2 => __( 'Custom field updated.', 'woocommerce' ), + 3 => __( 'Custom field deleted.', 'woocommerce' ), + 4 => __( 'Coupon updated.', 'woocommerce' ), + 5 => __( 'Revision restored.', 'woocommerce' ), + 6 => __( 'Coupon updated.', 'woocommerce' ), + 7 => __( 'Coupon saved.', 'woocommerce' ), + 8 => __( 'Coupon submitted.', 'woocommerce' ), + 9 => sprintf( /* translators: %s: date */ __( 'Coupon scheduled for: %s.', 'woocommerce' ), '' . date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $post->post_date ) ) . '' @@ -238,11 +238,13 @@ class WC_Admin_Post_Types { return; } - $shipping_class = get_terms( 'product_shipping_class', array( - 'hide_empty' => false, - ) ); + $shipping_class = get_terms( + 'product_shipping_class', array( + 'hide_empty' => false, + ) + ); - include( WC()->plugin_path() . '/includes/admin/views/html-bulk-edit-product.php' ); + include WC()->plugin_path() . '/includes/admin/views/html-bulk-edit-product.php'; } /** @@ -256,11 +258,13 @@ class WC_Admin_Post_Types { return; } - $shipping_class = get_terms( 'product_shipping_class', array( - 'hide_empty' => false, - ) ); + $shipping_class = get_terms( + 'product_shipping_class', array( + 'hide_empty' => false, + ) + ); - include( WC()->plugin_path() . '/includes/admin/views/html-quick-edit-product.php' ); + include WC()->plugin_path() . '/includes/admin/views/html-quick-edit-product.php'; } /** @@ -497,7 +501,7 @@ class WC_Admin_Post_Types { } // Handle price - remove dates and set to lowest. - $change_price_product_types = apply_filters( 'woocommerce_bulk_edit_save_price_product_types', array( 'simple', 'external' ) ); + $change_price_product_types = apply_filters( 'woocommerce_bulk_edit_save_price_product_types', array( 'simple', 'external' ) ); $can_product_type_change_price = false; foreach ( $change_price_product_types as $product_type ) { if ( $product->is_type( $product_type ) ) { @@ -521,7 +525,7 @@ class WC_Admin_Post_Types { break; case 2: if ( $is_percentage ) { - $percent = $regular_price / 100; + $percent = $regular_price / 100; $new_price = $old_regular_price + ( round( $old_regular_price * $percent, wc_get_price_decimals() ) ); } else { $new_price = $old_regular_price + $regular_price; @@ -529,7 +533,7 @@ class WC_Admin_Post_Types { break; case 3: if ( $is_percentage ) { - $percent = $regular_price / 100; + $percent = $regular_price / 100; $new_price = max( 0, $old_regular_price - ( round( $old_regular_price * $percent, wc_get_price_decimals() ) ) ); } else { $new_price = max( 0, $old_regular_price - $regular_price ); @@ -542,7 +546,7 @@ class WC_Admin_Post_Types { if ( isset( $new_price ) && $new_price !== $old_regular_price ) { $price_changed = true; - $new_price = round( $new_price, wc_get_price_decimals() ); + $new_price = round( $new_price, wc_get_price_decimals() ); $product->set_regular_price( $new_price ); } } @@ -559,7 +563,7 @@ class WC_Admin_Post_Types { break; case 2: if ( $is_percentage ) { - $percent = $sale_price / 100; + $percent = $sale_price / 100; $new_price = $old_sale_price + ( $old_sale_price * $percent ); } else { $new_price = $old_sale_price + $sale_price; @@ -567,7 +571,7 @@ class WC_Admin_Post_Types { break; case 3: if ( $is_percentage ) { - $percent = $sale_price / 100; + $percent = $sale_price / 100; $new_price = max( 0, $old_sale_price - ( $old_sale_price * $percent ) ); } else { $new_price = max( 0, $old_sale_price - $sale_price ); @@ -575,7 +579,7 @@ class WC_Admin_Post_Types { break; case 4: if ( $is_percentage ) { - $percent = $sale_price / 100; + $percent = $sale_price / 100; $new_price = max( 0, $product->regular_price - ( $product->regular_price * $percent ) ); } else { $new_price = max( 0, $product->regular_price - $sale_price ); @@ -588,7 +592,7 @@ class WC_Admin_Post_Types { if ( isset( $new_price ) && $new_price !== $old_sale_price ) { $price_changed = true; - $new_price = ! empty( $new_price ) || '0' === $new_price ? round( $new_price, wc_get_price_decimals() ) : ''; + $new_price = ! empty( $new_price ) || '0' === $new_price ? round( $new_price, wc_get_price_decimals() ) : ''; $product->set_sale_price( $new_price ); } } @@ -732,14 +736,17 @@ class WC_Admin_Post_Types { $visibility_options = wc_get_product_visibility_options(); ?>
    - + + + if ( 'yes' === $current_featured ) { + echo ', ' . esc_html__( 'Featured', 'woocommerce' ); + } + ?> + diff --git a/includes/admin/class-wc-admin-profile.php b/includes/admin/class-wc-admin-profile.php index 5fe788b599f..ae23d2dbad9 100644 --- a/includes/admin/class-wc-admin-profile.php +++ b/includes/admin/class-wc-admin-profile.php @@ -14,229 +14,230 @@ if ( ! defined( 'ABSPATH' ) ) { if ( ! class_exists( 'WC_Admin_Profile', false ) ) : -/** - * WC_Admin_Profile Class. - */ -class WC_Admin_Profile { - /** - * Hook in tabs. + * WC_Admin_Profile Class. */ - public function __construct() { - add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ) ); - add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ) ); + class WC_Admin_Profile { - add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); - add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); - } + /** + * Hook in tabs. + */ + public function __construct() { + add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ) ); + add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ) ); - /** - * Get Address Fields for the edit user pages. - * - * @return array Fields to display which are filtered through woocommerce_customer_meta_fields before being returned - */ - public function get_customer_meta_fields() { - $show_fields = apply_filters('woocommerce_customer_meta_fields', array( - 'billing' => array( - 'title' => __( 'Customer billing address', 'woocommerce' ), - 'fields' => array( - 'billing_first_name' => array( - 'label' => __( 'First name', 'woocommerce' ), - 'description' => '', - ), - 'billing_last_name' => array( - 'label' => __( 'Last name', 'woocommerce' ), - 'description' => '', - ), - 'billing_company' => array( - 'label' => __( 'Company', 'woocommerce' ), - 'description' => '', - ), - 'billing_address_1' => array( - 'label' => __( 'Address line 1', 'woocommerce' ), - 'description' => '', - ), - 'billing_address_2' => array( - 'label' => __( 'Address line 2', 'woocommerce' ), - 'description' => '', - ), - 'billing_city' => array( - 'label' => __( 'City', 'woocommerce' ), - 'description' => '', - ), - 'billing_postcode' => array( - 'label' => __( 'Postcode / ZIP', 'woocommerce' ), - 'description' => '', - ), - 'billing_country' => array( - 'label' => __( 'Country', 'woocommerce' ), - 'description' => '', - 'class' => 'js_field-country', - 'type' => 'select', - 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(), - ), - 'billing_state' => array( - 'label' => __( 'State / County', 'woocommerce' ), - 'description' => __( 'State / County or state code', 'woocommerce' ), - 'class' => 'js_field-state', - ), - 'billing_phone' => array( - 'label' => __( 'Phone', 'woocommerce' ), - 'description' => '', - ), - 'billing_email' => array( - 'label' => __( 'Email address', 'woocommerce' ), - 'description' => '', - ), - ), - ), - 'shipping' => array( - 'title' => __( 'Customer shipping address', 'woocommerce' ), - 'fields' => array( - 'copy_billing' => array( - 'label' => __( 'Copy from billing address', 'woocommerce' ), - 'description' => '', - 'class' => 'js_copy-billing', - 'type' => 'button', - 'text' => __( 'Copy', 'woocommerce' ), - ), - 'shipping_first_name' => array( - 'label' => __( 'First name', 'woocommerce' ), - 'description' => '', - ), - 'shipping_last_name' => array( - 'label' => __( 'Last name', 'woocommerce' ), - 'description' => '', - ), - 'shipping_company' => array( - 'label' => __( 'Company', 'woocommerce' ), - 'description' => '', - ), - 'shipping_address_1' => array( - 'label' => __( 'Address line 1', 'woocommerce' ), - 'description' => '', - ), - 'shipping_address_2' => array( - 'label' => __( 'Address line 2', 'woocommerce' ), - 'description' => '', - ), - 'shipping_city' => array( - 'label' => __( 'City', 'woocommerce' ), - 'description' => '', - ), - 'shipping_postcode' => array( - 'label' => __( 'Postcode / ZIP', 'woocommerce' ), - 'description' => '', - ), - 'shipping_country' => array( - 'label' => __( 'Country', 'woocommerce' ), - 'description' => '', - 'class' => 'js_field-country', - 'type' => 'select', - 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(), - ), - 'shipping_state' => array( - 'label' => __( 'State / County', 'woocommerce' ), - 'description' => __( 'State / County or state code', 'woocommerce' ), - 'class' => 'js_field-state', - ), - ), - ), - ) ); - return $show_fields; - } - - /** - * Show Address Fields on edit user pages. - * - * @param WP_User $user - */ - public function add_customer_meta_fields( $user ) { - if ( ! current_user_can( 'manage_woocommerce' ) ) { - return; + add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); + add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); } - $show_fields = $this->get_customer_meta_fields(); + /** + * Get Address Fields for the edit user pages. + * + * @return array Fields to display which are filtered through woocommerce_customer_meta_fields before being returned + */ + public function get_customer_meta_fields() { + $show_fields = apply_filters( + 'woocommerce_customer_meta_fields', array( + 'billing' => array( + 'title' => __( 'Customer billing address', 'woocommerce' ), + 'fields' => array( + 'billing_first_name' => array( + 'label' => __( 'First name', 'woocommerce' ), + 'description' => '', + ), + 'billing_last_name' => array( + 'label' => __( 'Last name', 'woocommerce' ), + 'description' => '', + ), + 'billing_company' => array( + 'label' => __( 'Company', 'woocommerce' ), + 'description' => '', + ), + 'billing_address_1' => array( + 'label' => __( 'Address line 1', 'woocommerce' ), + 'description' => '', + ), + 'billing_address_2' => array( + 'label' => __( 'Address line 2', 'woocommerce' ), + 'description' => '', + ), + 'billing_city' => array( + 'label' => __( 'City', 'woocommerce' ), + 'description' => '', + ), + 'billing_postcode' => array( + 'label' => __( 'Postcode / ZIP', 'woocommerce' ), + 'description' => '', + ), + 'billing_country' => array( + 'label' => __( 'Country', 'woocommerce' ), + 'description' => '', + 'class' => 'js_field-country', + 'type' => 'select', + 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(), + ), + 'billing_state' => array( + 'label' => __( 'State / County', 'woocommerce' ), + 'description' => __( 'State / County or state code', 'woocommerce' ), + 'class' => 'js_field-state', + ), + 'billing_phone' => array( + 'label' => __( 'Phone', 'woocommerce' ), + 'description' => '', + ), + 'billing_email' => array( + 'label' => __( 'Email address', 'woocommerce' ), + 'description' => '', + ), + ), + ), + 'shipping' => array( + 'title' => __( 'Customer shipping address', 'woocommerce' ), + 'fields' => array( + 'copy_billing' => array( + 'label' => __( 'Copy from billing address', 'woocommerce' ), + 'description' => '', + 'class' => 'js_copy-billing', + 'type' => 'button', + 'text' => __( 'Copy', 'woocommerce' ), + ), + 'shipping_first_name' => array( + 'label' => __( 'First name', 'woocommerce' ), + 'description' => '', + ), + 'shipping_last_name' => array( + 'label' => __( 'Last name', 'woocommerce' ), + 'description' => '', + ), + 'shipping_company' => array( + 'label' => __( 'Company', 'woocommerce' ), + 'description' => '', + ), + 'shipping_address_1' => array( + 'label' => __( 'Address line 1', 'woocommerce' ), + 'description' => '', + ), + 'shipping_address_2' => array( + 'label' => __( 'Address line 2', 'woocommerce' ), + 'description' => '', + ), + 'shipping_city' => array( + 'label' => __( 'City', 'woocommerce' ), + 'description' => '', + ), + 'shipping_postcode' => array( + 'label' => __( 'Postcode / ZIP', 'woocommerce' ), + 'description' => '', + ), + 'shipping_country' => array( + 'label' => __( 'Country', 'woocommerce' ), + 'description' => '', + 'class' => 'js_field-country', + 'type' => 'select', + 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(), + ), + 'shipping_state' => array( + 'label' => __( 'State / County', 'woocommerce' ), + 'description' => __( 'State / County or state code', 'woocommerce' ), + 'class' => 'js_field-state', + ), + ), + ), + ) + ); + return $show_fields; + } - foreach ( $show_fields as $fieldset_key => $fieldset ) : - ?> -

    - - $field ) : - ?> - - - - - get_customer_meta_fields(); + + foreach ( $show_fields as $fieldset_key => $fieldset ) : ?> -
    - - - - ID, $key, true ), 1, true ); ?> /> - - - - - -
    - -
    - + + $field ) : ?> + + + + + +
    + + + + + + ID, $key, true ), 1, true ); ?> /> + + + + + +
    + +
    + get_customer_meta_fields(); + /** + * Save Address Fields on edit user pages. + * + * @param int $user_id User ID of the user being saved + */ + public function save_customer_meta_fields( $user_id ) { + $save_fields = $this->get_customer_meta_fields(); - foreach ( $save_fields as $fieldset ) { + foreach ( $save_fields as $fieldset ) { - foreach ( $fieldset['fields'] as $key => $field ) { + foreach ( $fieldset['fields'] as $key => $field ) { - if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { - update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) ); - } elseif ( isset( $_POST[ $key ] ) ) { - update_user_meta( $user_id, $key, wc_clean( $_POST[ $key ] ) ); + if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { + update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) ); + } elseif ( isset( $_POST[ $key ] ) ) { + update_user_meta( $user_id, $key, wc_clean( $_POST[ $key ] ) ); + } } } } - } - /** - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. - * - * @since 3.1.0 - * @param int $user_id User ID of the user being edited - * @param string $key Key for user meta field - * @return string - */ - protected function get_user_meta( $user_id, $key ) { - $value = get_user_meta( $user_id, $key, true ); - $existing_fields = array( 'billing_first_name', 'billing_last_name' ); - if ( ! $value && in_array( $key, $existing_fields ) ) { - $value = get_user_meta( $user_id, str_replace( 'billing_', '', $key ), true ); - } elseif ( ! $value && ( 'billing_email' === $key ) ) { - $user = get_userdata( $user_id ); - $value = $user->user_email; + /** + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. + * + * @since 3.1.0 + * @param int $user_id User ID of the user being edited + * @param string $key Key for user meta field + * @return string + */ + protected function get_user_meta( $user_id, $key ) { + $value = get_user_meta( $user_id, $key, true ); + $existing_fields = array( 'billing_first_name', 'billing_last_name' ); + if ( ! $value && in_array( $key, $existing_fields ) ) { + $value = get_user_meta( $user_id, str_replace( 'billing_', '', $key ), true ); + } elseif ( ! $value && ( 'billing_email' === $key ) ) { + $user = get_userdata( $user_id ); + $value = $user->user_email; + } + + return $value; } - - return $value; } -} endif; diff --git a/includes/admin/class-wc-admin-reports.php b/includes/admin/class-wc-admin-reports.php index 5034515018f..c8594097dbc 100644 --- a/includes/admin/class-wc-admin-reports.php +++ b/includes/admin/class-wc-admin-reports.php @@ -32,8 +32,8 @@ class WC_Admin_Reports { $current_tab = ! empty( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : $first_tab[0]; $current_report = isset( $_GET['report'] ) ? sanitize_title( $_GET['report'] ) : current( array_keys( $reports[ $current_tab ]['reports'] ) ); - include_once( dirname( __FILE__ ) . '/reports/class-wc-admin-report.php' ); - include_once( dirname( __FILE__ ) . '/views/html-admin-page-reports.php' ); + include_once dirname( __FILE__ ) . '/reports/class-wc-admin-report.php'; + include_once dirname( __FILE__ ) . '/views/html-admin-page-reports.php'; } /** @@ -43,16 +43,16 @@ class WC_Admin_Reports { */ public static function get_reports() { $reports = array( - 'orders' => array( - 'title' => __( 'Orders', 'woocommerce' ), + 'orders' => array( + 'title' => __( 'Orders', 'woocommerce' ), 'reports' => array( - 'sales_by_date' => array( + 'sales_by_date' => array( 'title' => __( 'Sales by date', 'woocommerce' ), 'description' => '', 'hide_title' => true, 'callback' => array( __CLASS__, 'get_report' ), ), - 'sales_by_product' => array( + 'sales_by_product' => array( 'title' => __( 'Sales by product', 'woocommerce' ), 'description' => '', 'hide_title' => true, @@ -64,13 +64,13 @@ class WC_Admin_Reports { 'hide_title' => true, 'callback' => array( __CLASS__, 'get_report' ), ), - 'coupon_usage' => array( + 'coupon_usage' => array( 'title' => __( 'Coupons by date', 'woocommerce' ), 'description' => '', 'hide_title' => true, 'callback' => array( __CLASS__, 'get_report' ), ), - 'downloads' => array( + 'downloads' => array( 'title' => __( 'Customer downloads', 'woocommerce' ), 'description' => '', 'hide_title' => true, @@ -79,9 +79,9 @@ class WC_Admin_Reports { ), ), 'customers' => array( - 'title' => __( 'Customers', 'woocommerce' ), + 'title' => __( 'Customers', 'woocommerce' ), 'reports' => array( - 'customers' => array( + 'customers' => array( 'title' => __( 'Customers vs. guests', 'woocommerce' ), 'description' => '', 'hide_title' => true, @@ -96,7 +96,7 @@ class WC_Admin_Reports { ), ), 'stock' => array( - 'title' => __( 'Stock', 'woocommerce' ), + 'title' => __( 'Stock', 'woocommerce' ), 'reports' => array( 'low_in_stock' => array( 'title' => __( 'Low in stock', 'woocommerce' ), @@ -122,7 +122,7 @@ class WC_Admin_Reports { if ( wc_tax_enabled() ) { $reports['taxes'] = array( - 'title' => __( 'Taxes', 'woocommerce' ), + 'title' => __( 'Taxes', 'woocommerce' ), 'reports' => array( 'taxes_by_code' => array( 'title' => __( 'Taxes by code', 'woocommerce' ), @@ -167,7 +167,7 @@ class WC_Admin_Reports { $name = sanitize_title( str_replace( '_', '-', $name ) ); $class = 'WC_Report_' . str_replace( '-', '_', $name ); - include_once( apply_filters( 'wc_admin_reports_path', 'reports/class-wc-report-' . $name . '.php', $name, $class ) ); + include_once apply_filters( 'wc_admin_reports_path', 'reports/class-wc-report-' . $name . '.php', $name, $class ); if ( ! class_exists( $class ) ) { return; diff --git a/includes/admin/class-wc-admin-setup-wizard.php b/includes/admin/class-wc-admin-setup-wizard.php index 4f435f4c637..69486dff09c 100644 --- a/includes/admin/class-wc-admin-setup-wizard.php +++ b/includes/admin/class-wc-admin-setup-wizard.php @@ -88,16 +88,18 @@ class WC_Admin_Setup_Wizard { * @return boolean */ protected function is_default_theme() { - return wc_is_active_theme( array( - 'twentyseventeen', - 'twentysixteen', - 'twentyfifteen', - 'twentyfourteen', - 'twentythirteen', - 'twentyeleven', - 'twentytwelve', - 'twentyten', - ) ); + return wc_is_active_theme( + array( + 'twentyseventeen', + 'twentysixteen', + 'twentyfifteen', + 'twentyfourteen', + 'twentythirteen', + 'twentyeleven', + 'twentytwelve', + 'twentyten', + ) + ); } /** @@ -185,28 +187,36 @@ class WC_Admin_Setup_Wizard { wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.0' ); wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION ); - wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array( - 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ), - 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ), - 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ), - 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ), - 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ), - 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ), - 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ), - 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ), - 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ), - 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ), - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'search_products_nonce' => wp_create_nonce( 'search-products' ), - 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), - ) ); + wp_localize_script( + 'wc-enhanced-select', + 'wc_enhanced_select_params', + array( + 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ), + 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ), + 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ), + 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ), + 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ), + 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ), + 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ), + 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ), + 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ), + 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ), + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'search_products_nonce' => wp_create_nonce( 'search-products' ), + 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), + ) + ); wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION ); wp_enqueue_style( 'wc-setup', WC()->plugin_url() . '/assets/css/wc-setup.css', array( 'dashicons', 'install' ), WC_VERSION ); wp_register_script( 'wc-setup', WC()->plugin_url() . '/assets/js/admin/wc-setup' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'jquery-blockui', 'wp-util' ), WC_VERSION ); - wp_localize_script( 'wc-setup', 'wc_setup_params', array( - 'pending_jetpack_install' => $pending_jetpack ? 'yes' : 'no', - ) ); + wp_localize_script( + 'wc-setup', + 'wc_setup_params', + array( + 'pending_jetpack_install' => $pending_jetpack ? 'yes' : 'no', + ) + ); // @codingStandardsIgnoreStart if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { @@ -601,10 +611,13 @@ class WC_Admin_Setup_Wizard { add_action( 'shutdown', array( $this, 'run_deferred_actions' ) ); } - array_push( $this->deferred_actions, array( - 'func' => array( 'WC_Install', 'background_installer' ), - 'args' => array( $plugin_id, $plugin_info ), - ) ); + array_push( + $this->deferred_actions, + array( + 'func' => array( 'WC_Install', 'background_installer' ), + 'args' => array( $plugin_id, $plugin_info ), + ) + ); // Set the background installation flag for this plugin. update_option( 'woocommerce_setup_background_installing_' . $plugin_id, true ); @@ -620,21 +633,27 @@ class WC_Admin_Setup_Wizard { if ( empty( $this->deferred_actions ) ) { add_action( 'shutdown', array( $this, 'run_deferred_actions' ) ); } - array_push( $this->deferred_actions, array( - 'func' => array( 'WC_Install', 'theme_background_installer' ), - 'args' => array( $theme_id ), - ) ); + array_push( + $this->deferred_actions, + array( + 'func' => array( 'WC_Install', 'theme_background_installer' ), + 'args' => array( $theme_id ), + ) + ); } /** * Helper method to install Jetpack. */ protected function install_jetpack() { - $this->install_plugin( 'jetpack', array( - 'file' => 'jetpack/jetpack.php', - 'name' => __( 'Jetpack', 'woocommerce' ), - 'repo-slug' => 'jetpack', - ) ); + $this->install_plugin( + 'jetpack', + array( + 'file' => 'jetpack/jetpack.php', + 'name' => __( 'Jetpack', 'woocommerce' ), + 'repo-slug' => 'jetpack', + ) + ); } /** @@ -642,11 +661,14 @@ class WC_Admin_Setup_Wizard { */ protected function install_woocommerce_services() { $this->install_jetpack(); - $this->install_plugin( 'woocommerce-services', array( - 'file' => 'woocommerce-services/woocommerce-services.php', - 'name' => __( 'WooCommerce Services', 'woocommerce' ), - 'repo-slug' => 'woocommerce-services', - ) ); + $this->install_plugin( + 'woocommerce-services', + array( + 'file' => 'woocommerce-services/woocommerce-services.php', + 'name' => __( 'WooCommerce Services', 'woocommerce' ), + 'repo-slug' => 'woocommerce-services', + ) + ); } /** @@ -853,10 +875,12 @@ class WC_Admin_Setup_Wizard {

    @@ -871,10 +895,12 @@ class WC_Admin_Setup_Wizard {

    diff --git a/includes/admin/class-wc-admin-status.php b/includes/admin/class-wc-admin-status.php index f249f66aa46..e4b25a3a87c 100644 --- a/includes/admin/class-wc-admin-status.php +++ b/includes/admin/class-wc-admin-status.php @@ -19,14 +19,14 @@ class WC_Admin_Status { * Handles output of the reports page in admin. */ public static function output() { - include_once( dirname( __FILE__ ) . '/views/html-admin-page-status.php' ); + include_once dirname( __FILE__ ) . '/views/html-admin-page-status.php'; } /** * Handles output of report. */ public static function status_report() { - include_once( dirname( __FILE__ ) . '/views/html-admin-page-status-report.php' ); + include_once dirname( __FILE__ ) . '/views/html-admin-page-status-report.php'; } /** @@ -36,13 +36,16 @@ class WC_Admin_Status { $tools = self::get_tools(); if ( ! empty( $_GET['action'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'debug_action' ) ) { - $tools_controller = new WC_REST_System_Status_Tools_Controller; + $tools_controller = new WC_REST_System_Status_Tools_Controller(); $action = wc_clean( $_GET['action'] ); if ( array_key_exists( $action, $tools ) ) { $response = $tools_controller->execute_tool( $action ); } else { - $response = array( 'success' => false, 'message' => __( 'Tool does not exist.', 'woocommerce' ) ); + $response = array( + 'success' => false, + 'message' => __( 'Tool does not exist.', 'woocommerce' ), + ); } if ( $response['success'] ) { @@ -57,15 +60,16 @@ class WC_Admin_Status { echo '

    ' . __( 'Your changes have been saved.', 'woocommerce' ) . '

    '; } - include_once( dirname( __FILE__ ) . '/views/html-admin-page-status-tools.php' ); + include_once dirname( __FILE__ ) . '/views/html-admin-page-status-tools.php'; } /** * Get tools. + * * @return array of tools */ public static function get_tools() { - $tools_controller = new WC_REST_System_Status_Tools_Controller; + $tools_controller = new WC_REST_System_Status_Tools_Controller(); return $tools_controller->get_tools(); } @@ -99,7 +103,7 @@ class WC_Admin_Status { self::remove_log(); } - include_once( 'views/html-admin-page-status-logs.php' ); + include_once 'views/html-admin-page-status-logs.php'; } /** @@ -120,11 +124,12 @@ class WC_Admin_Status { $log_table_list = new WC_Admin_Log_Table_List(); $log_table_list->prepare_items(); - include_once( 'views/html-admin-page-status-logs-db.php' ); + include_once 'views/html-admin-page-status-logs-db.php'; } /** * Retrieve metadata from a file. Based on WP Core's get_file_data function. + * * @since 2.1.1 * @param string $file Path to the file * @return string @@ -153,7 +158,7 @@ class WC_Admin_Status { $version = _cleanup_header_comment( $match[1] ); } - return $version ; + return $version; } /** @@ -168,6 +173,7 @@ class WC_Admin_Status { /** * Scan the template files. + * * @param string $template_path * @return array */ @@ -180,7 +186,7 @@ class WC_Admin_Status { foreach ( $files as $key => $value ) { - if ( ! in_array( $value, array( ".", ".." ) ) ) { + if ( ! in_array( $value, array( '.', '..' ) ) ) { if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); @@ -198,6 +204,7 @@ class WC_Admin_Status { /** * Scan the log files. + * * @return array */ public static function scan_log_files() { @@ -221,41 +228,48 @@ class WC_Admin_Status { /** * Get latest version of a theme by slug. + * * @param object $theme WP_Theme object. * @return string Version number if found. */ public static function get_latest_theme_version( $theme ) { - include_once( ABSPATH . 'wp-admin/includes/theme.php' ); + include_once ABSPATH . 'wp-admin/includes/theme.php'; - $api = themes_api( 'theme_information', array( - 'slug' => $theme->get_stylesheet(), - 'fields' => array( - 'sections' => false, - 'tags' => false, - ), - ) ); + $api = themes_api( + 'theme_information', + array( + 'slug' => $theme->get_stylesheet(), + 'fields' => array( + 'sections' => false, + 'tags' => false, + ), + ) + ); $update_theme_version = 0; // Check .org for updates. if ( is_object( $api ) && ! is_wp_error( $api ) ) { $update_theme_version = $api->version; - - // Check WooThemes Theme Version. - } elseif ( strstr( $theme->{'Author URI'}, 'woothemes' ) ) { - $theme_dir = substr( strtolower( str_replace( ' ','', $theme->Name ) ), 0, 45 ); + } elseif ( strstr( $theme->{'Author URI'}, 'woothemes' ) ) { // Check WooThemes Theme Version. + $theme_dir = substr( strtolower( str_replace( ' ', '', $theme->Name ) ), 0, 45 ); if ( false === ( $theme_version_data = get_transient( $theme_dir . '_version_data' ) ) ) { $theme_changelog = wp_safe_remote_get( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $theme_dir . '/changelog.txt' ); - $cl_lines = explode( "\n", wp_remote_retrieve_body( $theme_changelog ) ); + $cl_lines = explode( "\n", wp_remote_retrieve_body( $theme_changelog ) ); if ( ! empty( $cl_lines ) ) { foreach ( $cl_lines as $line_num => $cl_line ) { if ( preg_match( '/^[0-9]/', $cl_line ) ) { - $theme_date = str_replace( '.' , '-' , trim( substr( $cl_line , 0 , strpos( $cl_line , '-' ) ) ) ); - $theme_version = preg_replace( '~[^0-9,.]~' , '' ,stristr( $cl_line , "version" ) ); - $theme_update = trim( str_replace( "*" , "" , $cl_lines[ $line_num + 1 ] ) ); - $theme_version_data = array( 'date' => $theme_date , 'version' => $theme_version , 'update' => $theme_update , 'changelog' => $theme_changelog ); - set_transient( $theme_dir . '_version_data', $theme_version_data , DAY_IN_SECONDS ); + $theme_date = str_replace( '.', '-', trim( substr( $cl_line, 0, strpos( $cl_line, '-' ) ) ) ); + $theme_version = preg_replace( '~[^0-9,.]~', '', stristr( $cl_line, 'version' ) ); + $theme_update = trim( str_replace( '*', '', $cl_lines[ $line_num + 1 ] ) ); + $theme_version_data = array( + 'date' => $theme_date, + 'version' => $theme_version, + 'update' => $theme_update, + 'changelog' => $theme_changelog, + ); + set_transient( $theme_dir . '_version_data', $theme_version_data, DAY_IN_SECONDS ); break; } } diff --git a/includes/admin/class-wc-admin-taxonomies.php b/includes/admin/class-wc-admin-taxonomies.php index 887acb30882..694f572d4e4 100644 --- a/includes/admin/class-wc-admin-taxonomies.php +++ b/includes/admin/class-wc-admin-taxonomies.php @@ -59,8 +59,8 @@ class WC_Admin_Taxonomies { /** * Order term when created (put in position 0). * - * @param mixed $term_id - * @param mixed $tt_id + * @param mixed $term_id + * @param mixed $tt_id * @param string $taxonomy */ public function create_term( $term_id, $tt_id = '', $taxonomy = '' ) { @@ -132,9 +132,9 @@ class WC_Admin_Taxonomies { // Create the media frame. file_frame = wp.media.frames.downloadable_file = wp.media({ - title: '', + title: '', button: { - text: '' + text: '' }, multiple: false }); @@ -242,9 +242,9 @@ class WC_Admin_Taxonomies { // Create the media frame. file_frame = wp.media.frames.downloadable_file = wp.media({ - title: '', + title: '', button: { - text: '' + text: '' }, multiple: false }); @@ -280,8 +280,8 @@ class WC_Admin_Taxonomies { /** * save_category_fields function. * - * @param mixed $term_id Term ID being saved - * @param mixed $tt_id + * @param mixed $term_id Term ID being saved + * @param mixed $tt_id * @param string $taxonomy */ public function save_category_fields( $term_id, $tt_id = '', $taxonomy = '' ) { @@ -310,7 +310,7 @@ class WC_Admin_Taxonomies { ?>

    -
    +
    'webhook', - 'plural' => 'webhooks', - 'ajax' => false, - ) ); + parent::__construct( + array( + 'singular' => 'webhook', + 'plural' => 'webhooks', + 'ajax' => false, + ) + ); } /** @@ -79,9 +81,15 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table { 'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $webhook->get_id() ), 'edit' => '' . esc_html__( 'Edit', 'woocommerce' ) . '', /* translators: %s: webhook name */ - 'delete' => 'get_name() ) ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( - 'delete' => $webhook->get_id(), - ), admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks' ) ), 'delete-webhook' ) ) . '">' . esc_html__( 'Delete permanently', 'woocommerce' ) . '', + 'delete' => 'get_name() ) ) . '" href="' . esc_url( + wp_nonce_url( + add_query_arg( + array( + 'delete' => $webhook->get_id(), + ), admin_url( 'admin.php?page=wc-settings&tab=api§ion=webhooks' ) + ), 'delete-webhook' + ) + ) . '">' . esc_html__( 'Delete permanently', 'woocommerce' ) . '', ); $actions = apply_filters( 'webhook_row_actions', $actions, $webhook ); @@ -237,9 +245,12 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table { echo '

    '; } @@ -276,10 +287,12 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table { $total_items = count( $data_store->search_webhooks( $args ) ); // Set the pagination. - $this->set_pagination_args( array( - 'total_items' => $total_items, - 'per_page' => $per_page, - 'total_pages' => ceil( $total_items / $per_page ), - ) ); + $this->set_pagination_args( + array( + 'total_items' => $total_items, + 'per_page' => $per_page, + 'total_pages' => ceil( $total_items / $per_page ), + ) + ); } } diff --git a/includes/admin/class-wc-admin-webhooks.php b/includes/admin/class-wc-admin-webhooks.php index b3215eef7a8..9d09ac13050 100644 --- a/includes/admin/class-wc-admin-webhooks.php +++ b/includes/admin/class-wc-admin-webhooks.php @@ -276,10 +276,13 @@ class WC_Admin_Webhooks { $webhooks_table_list = new WC_Admin_Webhooks_Table_List(); // Add screen option. - add_screen_option( 'per_page', array( - 'default' => 10, - 'option' => 'woocommerce_webhooks_per_page', - ) ); + add_screen_option( + 'per_page', + array( + 'default' => 10, + 'option' => 'woocommerce_webhooks_per_page', + ) + ); } } diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index bab0a82db55..0d95cb3b097 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -44,46 +44,46 @@ class WC_Admin { * Include any classes we need within admin. */ public function includes() { - include_once( dirname( __FILE__ ) . '/wc-admin-functions.php' ); - include_once( dirname( __FILE__ ) . '/wc-meta-box-functions.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-post-types.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-taxonomies.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-menus.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-customize.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-notices.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-assets.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-api-keys.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-webhooks.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-pointers.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-importers.php' ); - include_once( dirname( __FILE__ ) . '/class-wc-admin-exporters.php' ); + include_once dirname( __FILE__ ) . '/wc-admin-functions.php'; + include_once dirname( __FILE__ ) . '/wc-meta-box-functions.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-post-types.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-taxonomies.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-menus.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-customize.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-notices.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-assets.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-api-keys.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-webhooks.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-pointers.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-importers.php'; + include_once dirname( __FILE__ ) . '/class-wc-admin-exporters.php'; // Help Tabs if ( apply_filters( 'woocommerce_enable_admin_help_tab', true ) ) { - include_once( dirname( __FILE__ ) . '/class-wc-admin-help.php' ); + include_once dirname( __FILE__ ) . '/class-wc-admin-help.php'; } // Setup/welcome if ( ! empty( $_GET['page'] ) ) { switch ( $_GET['page'] ) { - case 'wc-setup' : - include_once( dirname( __FILE__ ) . '/class-wc-admin-setup-wizard.php' ); - break; + case 'wc-setup': + include_once dirname( __FILE__ ) . '/class-wc-admin-setup-wizard.php'; + break; } } // Importers if ( defined( 'WP_LOAD_IMPORTERS' ) ) { - include_once( dirname( __FILE__ ) . '/class-wc-admin-importers.php' ); + include_once dirname( __FILE__ ) . '/class-wc-admin-importers.php'; } // Helper - include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-options.php' ); - include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-api.php' ); - include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-updater.php' ); - include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-plugin-info.php' ); - include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-compat.php' ); - include_once( dirname( __FILE__ ) . '/helper/class-wc-helper.php' ); + include_once dirname( __FILE__ ) . '/helper/class-wc-helper-options.php'; + include_once dirname( __FILE__ ) . '/helper/class-wc-helper-api.php'; + include_once dirname( __FILE__ ) . '/helper/class-wc-helper-updater.php'; + include_once dirname( __FILE__ ) . '/helper/class-wc-helper-plugin-info.php'; + include_once dirname( __FILE__ ) . '/helper/class-wc-helper-compat.php'; + include_once dirname( __FILE__ ) . '/helper/class-wc-helper.php'; } /** @@ -95,25 +95,25 @@ class WC_Admin { } switch ( $screen->id ) { - case 'dashboard' : - case 'dashboard-network' : - include( 'class-wc-admin-dashboard.php' ); - break; - case 'options-permalink' : - include( 'class-wc-admin-permalink-settings.php' ); - break; - case 'plugins' : - include ( 'plugin-updates/class-wc-plugins-screen-updates.php' ); - break; - case 'update-core' : - include( 'plugin-updates/class-wc-updates-screen-updates.php' ); - break; - case 'users' : - case 'user' : - case 'profile' : - case 'user-edit' : - include( 'class-wc-admin-profile.php' ); - break; + case 'dashboard': + case 'dashboard-network': + include 'class-wc-admin-dashboard.php'; + break; + case 'options-permalink': + include 'class-wc-admin-permalink-settings.php'; + break; + case 'plugins': + include 'plugin-updates/class-wc-plugins-screen-updates.php'; + break; + case 'update-core': + include 'plugin-updates/class-wc-updates-screen-updates.php'; + break; + case 'users': + case 'user': + case 'profile': + case 'user-edit': + include 'class-wc-admin-profile.php'; + break; } } @@ -160,7 +160,7 @@ class WC_Admin { public function prevent_admin_access() { $prevent_access = false; - if ( 'yes' === get_option( 'woocommerce_lock_down_admin', 'yes' ) && ! is_ajax() && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) { + if ( 'yes' === get_option( 'woocommerce_lock_down_admin', 'yes' ) && ! is_ajax() && basename( $_SERVER['SCRIPT_FILENAME'] ) !== 'admin-post.php' ) { $has_cap = false; $access_caps = array( 'edit_posts', 'manage_woocommerce', 'view_admin_dashboard' ); @@ -193,21 +193,21 @@ class WC_Admin { } // load the mailer class - $mailer = WC()->mailer(); + $mailer = WC()->mailer(); // get the preview email subject $email_heading = __( 'HTML email template', 'woocommerce' ); // get the preview email content ob_start(); - include( 'views/html-email-template-preview.php' ); - $message = ob_get_clean(); + include 'views/html-email-template-preview.php'; + $message = ob_get_clean(); // create a new email - $email = new WC_Email(); + $email = new WC_Email(); // wrap the content with the email template and then add styles - $message = apply_filters( 'woocommerce_mail_content', $email->style_inline( $mailer->wrap_message( $email_heading, $message ) ) ); + $message = apply_filters( 'woocommerce_mail_content', $email->style_inline( $mailer->wrap_message( $email_heading, $message ) ) ); // print the preview email echo $message; @@ -242,12 +242,12 @@ class WC_Admin { sprintf( '%s', esc_html__( 'WooCommerce', 'woocommerce' ) ), '★★★★★' ); - wc_enqueue_js( " - jQuery( 'a.wc-rating-link' ).click( function() { + wc_enqueue_js( + "jQuery( 'a.wc-rating-link' ).click( function() { jQuery.post( '" . WC()->ajax_url() . "', { action: 'woocommerce_rated' } ); jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) ); - }); - " ); + });" + ); } else { $footer_text = __( 'Thank you for selling with WooCommerce.', 'woocommerce' ); } @@ -264,9 +264,11 @@ class WC_Admin { public function setup_wizard_check_jetpack() { $jetpack_active = class_exists( 'Jetpack' ); - wp_send_json_success( array( - 'is_active' => $jetpack_active ? 'yes' : 'no', - ) ); + wp_send_json_success( + array( + 'is_active' => $jetpack_active ? 'yes' : 'no', + ) + ); } } diff --git a/includes/admin/helper/class-wc-helper-api.php b/includes/admin/helper/class-wc-helper-api.php index 014b693d4b3..a5f159f95b9 100644 --- a/includes/admin/helper/class-wc-helper-api.php +++ b/includes/admin/helper/class-wc-helper-api.php @@ -26,7 +26,7 @@ class WC_Helper_API { * Perform an HTTP request to the Helper API. * * @param string $endpoint The endpoint to request. - * @param array $args Additional data for the request. Set authenticated to a truthy value to enable auth. + * @param array $args Additional data for the request. Set authenticated to a truthy value to enable auth. * * @return array|WP_Error The response from wp_safe_remote_request() */ @@ -53,7 +53,7 @@ class WC_Helper_API { * Adds authentication headers to an HTTP request. * * @param string $url The request URI. - * @param array $args By-ref, the args that will be passed to wp_remote_request(). + * @param array $args By-ref, the args that will be passed to wp_remote_request(). * @return bool Were the headers added? */ private static function _authenticate( $url, &$args ) { @@ -86,7 +86,7 @@ class WC_Helper_API { } $args['headers'] = array( - 'Authorization' => 'Bearer ' . $auth['access_token'], + 'Authorization' => 'Bearer ' . $auth['access_token'], 'X-Woo-Signature' => $signature, ); @@ -97,7 +97,7 @@ class WC_Helper_API { * Wrapper for self::request(). * * @param string $endpoint The helper API endpoint to request. - * @param array $args Arguments passed to wp_remote_request(). + * @param array $args Arguments passed to wp_remote_request(). * * @return array The response object from wp_safe_remote_request(). */ @@ -110,7 +110,7 @@ class WC_Helper_API { * Wrapper for self::request(). * * @param string $endpoint The helper API endpoint to request. - * @param array $args Arguments passed to wp_remote_request(). + * @param array $args Arguments passed to wp_remote_request(). * * @return array The response object from wp_safe_remote_request(). */ diff --git a/includes/admin/helper/class-wc-helper-compat.php b/includes/admin/helper/class-wc-helper-compat.php index 4b4727a2e4f..e967da65e95 100644 --- a/includes/admin/helper/class-wc-helper-compat.php +++ b/includes/admin/helper/class-wc-helper-compat.php @@ -70,12 +70,15 @@ class WC_Helper_Compat { return; } - $request = WC_Helper_API::post( 'oauth/migrate', array( - 'body' => array( - 'home_url' => home_url(), - 'master_key' => $master_key, - ), - ) ); + $request = WC_Helper_API::post( + 'oauth/migrate', + array( + 'body' => array( + 'home_url' => home_url(), + 'master_key' => $master_key, + ), + ) + ); if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) { WC_Helper::log( 'Call to oauth/migrate returned a non-200 response code' ); @@ -89,13 +92,16 @@ class WC_Helper_Compat { } // Obtain an access token. - $request = WC_Helper_API::post( 'oauth/access_token', array( - 'body' => array( - 'request_token' => $request_token, - 'home_url' => home_url(), - 'migrate' => true, - ), - ) ); + $request = WC_Helper_API::post( + 'oauth/access_token', + array( + 'body' => array( + 'request_token' => $request_token, + 'home_url' => home_url(), + 'migrate' => true, + ), + ) + ); if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) { WC_Helper::log( 'Call to oauth/access_token returned a non-200 response code' ); @@ -108,13 +114,16 @@ class WC_Helper_Compat { return; } - WC_Helper_Options::update( 'auth', array( - 'access_token' => $access_token['access_token'], - 'access_token_secret' => $access_token['access_token_secret'], - 'site_id' => $access_token['site_id'], - 'user_id' => null, // Set this later - 'updated' => time(), - ) ); + WC_Helper_Options::update( + 'auth', + array( + 'access_token' => $access_token['access_token'], + 'access_token_secret' => $access_token['access_token_secret'], + 'site_id' => $access_token['site_id'], + 'user_id' => null, // Set this later + 'updated' => time(), + ) + ); // Obtain the connected user info. if ( ! WC_Helper::_flush_authentication_cache() ) { @@ -128,7 +137,7 @@ class WC_Helper_Compat { * Attempt to deactivate the legacy helper plugin. */ public static function deactivate_plugin() { - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + include_once ABSPATH . 'wp-admin/includes/plugin.php'; if ( ! function_exists( 'deactivate_plugins' ) ) { return; } @@ -175,11 +184,13 @@ class WC_Helper_Compat { * Render the legacy helper compat view. */ public static function render_compat_menu() { - $helper_url = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - ), admin_url( 'admin.php' ) ); - include( WC_Helper::get_view_filename( 'html-helper-compat.php' ) ); + $helper_url = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + ), admin_url( 'admin.php' ) + ); + include WC_Helper::get_view_filename( 'html-helper-compat.php' ); } } diff --git a/includes/admin/helper/class-wc-helper-options.php b/includes/admin/helper/class-wc-helper-options.php index b11612f4fd5..f0e811d8aeb 100644 --- a/includes/admin/helper/class-wc-helper-options.php +++ b/includes/admin/helper/class-wc-helper-options.php @@ -23,12 +23,12 @@ class WC_Helper_Options { * is not thread-safe, use with caution. * * @param string $key The key to update. - * @param mixed $value The new option value. + * @param mixed $value The new option value. * * @return bool True if the option has been updated. */ public static function update( $key, $value ) { - $options = get_option( self::$option_name, array() ); + $options = get_option( self::$option_name, array() ); $options[ $key ] = $value; return update_option( self::$option_name, $options, true ); } @@ -39,7 +39,7 @@ class WC_Helper_Options { * @see self::update * * @param string $key The key to fetch. - * @param mixed $default The default option to return if the key does not exist. + * @param mixed $default The default option to return if the key does not exist. * * @return mixed An option or the default. */ diff --git a/includes/admin/helper/class-wc-helper-plugin-info.php b/includes/admin/helper/class-wc-helper-plugin-info.php index e9c437f8790..ef7b9204bcf 100644 --- a/includes/admin/helper/class-wc-helper-plugin-info.php +++ b/includes/admin/helper/class-wc-helper-plugin-info.php @@ -45,7 +45,7 @@ class WC_Helper_Plugin_Info { // Look through update data by slug. $update_data = WC_Helper_Updater::get_update_data(); - $products = wp_list_filter( $update_data, array( 'slug' => $clean_slug ) ); + $products = wp_list_filter( $update_data, array( 'slug' => $clean_slug ) ); if ( empty( $products ) ) { return $response; @@ -55,9 +55,13 @@ class WC_Helper_Plugin_Info { $product_id = array_shift( $product_id ); // Fetch the product information from the Helper API. - $request = WC_Helper_API::get( add_query_arg( array( - 'product_id' => absint( $product_id ), - ), 'info' ), array( 'authenticated' => true ) ); + $request = WC_Helper_API::get( + add_query_arg( + array( + 'product_id' => absint( $product_id ), + ), 'info' + ), array( 'authenticated' => true ) + ); $results = json_decode( wp_remote_retrieve_body( $request ), true ); if ( ! empty( $results ) ) { diff --git a/includes/admin/helper/class-wc-helper-updater.php b/includes/admin/helper/class-wc-helper-updater.php index 5734886ad43..02544b15dcb 100644 --- a/includes/admin/helper/class-wc-helper-updater.php +++ b/includes/admin/helper/class-wc-helper-updater.php @@ -36,16 +36,16 @@ class WC_Helper_Updater { continue; } - $data = $update_data[ $plugin['_product_id'] ]; + $data = $update_data[ $plugin['_product_id'] ]; $filename = $plugin['_filename']; $item = array( - 'id' => 'woocommerce-com-' . $plugin['_product_id'], - 'slug' => 'woocommerce-com-' . $data['slug'], - 'plugin' => $filename, - 'new_version' => $data['version'], - 'url' => $data['url'], - 'package' => '', + 'id' => 'woocommerce-com-' . $plugin['_product_id'], + 'slug' => 'woocommerce-com-' . $data['slug'], + 'plugin' => $filename, + 'new_version' => $data['version'], + 'url' => $data['url'], + 'package' => '', 'upgrade_notice' => $data['upgrade_notice'], ); @@ -85,10 +85,10 @@ class WC_Helper_Updater { $slug = $theme['_stylesheet']; $item = array( - 'theme' => $slug, + 'theme' => $slug, 'new_version' => $data['version'], - 'url' => $data['url'], - 'package' => '', + 'url' => $data['url'], + 'package' => '', ); if ( self::_has_active_subscription( $theme['_product_id'] ) ) { @@ -122,7 +122,7 @@ class WC_Helper_Updater { foreach ( WC_Helper::get_subscriptions() as $subscription ) { $payload[ $subscription['product_id'] ] = array( 'product_id' => $subscription['product_id'], - 'file_id' => '', + 'file_id' => '', ); } @@ -171,16 +171,18 @@ class WC_Helper_Updater { } $data = array( - 'hash' => $hash, - 'updated' => time(), + 'hash' => $hash, + 'updated' => time(), 'products' => array(), - 'errors' => array(), + 'errors' => array(), ); - $request = WC_Helper_API::post( 'update-check', array( - 'body' => json_encode( array( 'products' => $payload ) ), - 'authenticated' => true, - ) ); + $request = WC_Helper_API::post( + 'update-check', array( + 'body' => json_encode( array( 'products' => $payload ) ), + 'authenticated' => true, + ) + ); if ( wp_remote_retrieve_response_code( $request ) !== 200 ) { $data['errors'][] = 'http-error'; @@ -250,7 +252,7 @@ class WC_Helper_Updater { return 0; } - $count = 0; + $count = 0; $update_data = self::get_update_data(); if ( empty( $update_data ) ) { diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index 84e4dcba250..665a08051fd 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -49,7 +49,7 @@ class WC_Helper { * Render the helper section content based on context. */ public static function render_helper_output() { - $auth = WC_Helper_Options::get( 'auth' ); + $auth = WC_Helper_Options::get( 'auth' ); $auth_user_data = WC_Helper_Options::get( 'auth_user_data' ); // Return success/error notices. @@ -57,68 +57,78 @@ class WC_Helper { // No active connection. if ( empty( $auth['access_token'] ) ) { - $connect_url = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'wc-helper-connect' => 1, - 'wc-helper-nonce' => wp_create_nonce( 'connect' ), - ), admin_url( 'admin.php' ) ); + $connect_url = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'wc-helper-connect' => 1, + 'wc-helper-nonce' => wp_create_nonce( 'connect' ), + ), admin_url( 'admin.php' ) + ); - include( self::get_view_filename( 'html-oauth-start.php' ) ); + include self::get_view_filename( 'html-oauth-start.php' ); return; } - $disconnect_url = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'wc-helper-disconnect' => 1, - 'wc-helper-nonce' => wp_create_nonce( 'disconnect' ), - ), admin_url( 'admin.php' ) ); + $disconnect_url = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'wc-helper-disconnect' => 1, + 'wc-helper-nonce' => wp_create_nonce( 'disconnect' ), + ), admin_url( 'admin.php' ) + ); $current_filter = self::get_current_filter(); - $refresh_url = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'filter' => $current_filter, - 'wc-helper-refresh' => 1, - 'wc-helper-nonce' => wp_create_nonce( 'refresh' ), - ), admin_url( 'admin.php' ) ); + $refresh_url = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'filter' => $current_filter, + 'wc-helper-refresh' => 1, + 'wc-helper-nonce' => wp_create_nonce( 'refresh' ), + ), admin_url( 'admin.php' ) + ); // Installed plugins and themes, with or without an active subscription. $woo_plugins = self::get_local_woo_plugins(); - $woo_themes = self::get_local_woo_themes(); + $woo_themes = self::get_local_woo_themes(); - $site_id = absint( $auth['site_id'] ); - $subscriptions = self::get_subscriptions(); - $updates = WC_Helper_Updater::get_update_data(); + $site_id = absint( $auth['site_id'] ); + $subscriptions = self::get_subscriptions(); + $updates = WC_Helper_Updater::get_update_data(); $subscriptions_product_ids = wp_list_pluck( $subscriptions, 'product_id' ); foreach ( $subscriptions as &$subscription ) { $subscription['active'] = in_array( $site_id, $subscription['connections'] ); - $subscription['activate_url'] = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'filter' => $current_filter, - 'wc-helper-activate' => 1, - 'wc-helper-product-key' => $subscription['product_key'], - 'wc-helper-product-id' => $subscription['product_id'], - 'wc-helper-nonce' => wp_create_nonce( 'activate:' . $subscription['product_key'] ), - ), admin_url( 'admin.php' ) ); + $subscription['activate_url'] = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'filter' => $current_filter, + 'wc-helper-activate' => 1, + 'wc-helper-product-key' => $subscription['product_key'], + 'wc-helper-product-id' => $subscription['product_id'], + 'wc-helper-nonce' => wp_create_nonce( 'activate:' . $subscription['product_key'] ), + ), admin_url( 'admin.php' ) + ); - $subscription['deactivate_url'] = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'filter' => $current_filter, - 'wc-helper-deactivate' => 1, - 'wc-helper-product-key' => $subscription['product_key'], - 'wc-helper-product-id' => $subscription['product_id'], - 'wc-helper-nonce' => wp_create_nonce( 'deactivate:' . $subscription['product_key'] ), - ), admin_url( 'admin.php' ) ); + $subscription['deactivate_url'] = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'filter' => $current_filter, + 'wc-helper-deactivate' => 1, + 'wc-helper-product-key' => $subscription['product_key'], + 'wc-helper-product-id' => $subscription['product_id'], + 'wc-helper-nonce' => wp_create_nonce( 'deactivate:' . $subscription['product_key'] ), + ), admin_url( 'admin.php' ) + ); $subscription['local'] = array( 'installed' => false, - 'active' => false, - 'version' => null, + 'active' => false, + 'version' => null, ); $subscription['update_url'] = admin_url( 'update-core.php' ); @@ -126,9 +136,9 @@ class WC_Helper { $local = wp_list_filter( array_merge( $woo_plugins, $woo_themes ), array( '_product_id' => $subscription['product_id'] ) ); if ( ! empty( $local ) ) { - $local = array_shift( $local ); + $local = array_shift( $local ); $subscription['local']['installed'] = true; - $subscription['local']['version'] = $local['Version']; + $subscription['local']['version'] = $local['Version']; if ( 'plugin' == $local['_type'] ) { if ( is_plugin_active( $local['_filename'] ) ) { @@ -156,7 +166,7 @@ class WC_Helper { } $subscription['download_primary'] = true; - $subscription['download_url'] = $subscription['product_url']; + $subscription['download_url'] = $subscription['product_url']; if ( ! $subscription['local']['installed'] && ! empty( $updates[ $subscription['product_id'] ] ) ) { $subscription['download_url'] = $updates[ $subscription['product_id'] ]['package']; } @@ -166,18 +176,18 @@ class WC_Helper { if ( $subscription['has_update'] && ! $subscription['expired'] ) { $action = array( /* translators: %s: version number */ - 'message' => sprintf( __( 'Version %s is available.', 'woocommerce' ), esc_html( $updates[ $subscription['product_id'] ]['version'] ) ), + 'message' => sprintf( __( 'Version %s is available.', 'woocommerce' ), esc_html( $updates[ $subscription['product_id'] ]['version'] ) ), 'button_label' => __( 'Update', 'woocommerce' ), - 'button_url' => $subscription['update_url'], - 'status' => 'update-available', - 'icon' => 'dashicons-update', + 'button_url' => $subscription['update_url'], + 'status' => 'update-available', + 'icon' => 'dashicons-update', ); // Subscription is not active on this site. if ( ! $subscription['active'] ) { - $action['message'] .= ' ' . __( 'To enable this update you need to activate this subscription.', 'woocommerce' ); + $action['message'] .= ' ' . __( 'To enable this update you need to activate this subscription.', 'woocommerce' ); $action['button_label'] = null; - $action['button_url'] = null; + $action['button_url'] = null; } $subscription['actions'][] = $action; @@ -187,30 +197,30 @@ class WC_Helper { $action = array( /* translators: %s: version number */ 'message' => sprintf( __( 'Version %s is available.', 'woocommerce' ), esc_html( $updates[ $subscription['product_id'] ]['version'] ) ), - 'status' => 'expired', - 'icon' => 'dashicons-info', + 'status' => 'expired', + 'icon' => 'dashicons-info', ); - $action['message'] .= ' ' . __( 'To enable this update you need to purchase a new subscription.', 'woocommerce' ); + $action['message'] .= ' ' . __( 'To enable this update you need to purchase a new subscription.', 'woocommerce' ); $action['button_label'] = __( 'Purchase', 'woocommerce' ); - $action['button_url'] = $subscription['product_url']; + $action['button_url'] = $subscription['product_url']; $subscription['actions'][] = $action; } elseif ( $subscription['expired'] && ! empty( $subscription['master_user_email'] ) ) { $action = array( 'message' => sprintf( __( 'This subscription has expired. Contact the owner to renew the subscription to receive updates and support.', 'woocommerce' ) ), - 'status' => 'expired', - 'icon' => 'dashicons-info', + 'status' => 'expired', + 'icon' => 'dashicons-info', ); $subscription['actions'][] = $action; } elseif ( $subscription['expired'] ) { $action = array( - 'message' => sprintf( __( 'This subscription has expired. Please renew to receive updates and support.', 'woocommerce' ) ), + 'message' => sprintf( __( 'This subscription has expired. Please renew to receive updates and support.', 'woocommerce' ) ), 'button_label' => __( 'Renew', 'woocommerce' ), - 'button_url' => 'https://woocommerce.com/my-account/my-subscriptions/', - 'status' => 'expired', - 'icon' => 'dashicons-info', + 'button_url' => 'https://woocommerce.com/my-account/my-subscriptions/', + 'status' => 'expired', + 'icon' => 'dashicons-info', ); $subscription['actions'][] = $action; @@ -218,26 +228,26 @@ class WC_Helper { if ( $subscription['expiring'] && ! $subscription['autorenew'] ) { $action = array( - 'message' => __( 'Subscription is expiring soon.', 'woocommerce' ), + 'message' => __( 'Subscription is expiring soon.', 'woocommerce' ), 'button_label' => __( 'Enable auto-renew', 'woocommerce' ), - 'button_url' => 'https://woocommerce.com/my-account/my-subscriptions/', - 'status' => 'expired', - 'icon' => 'dashicons-info', + 'button_url' => 'https://woocommerce.com/my-account/my-subscriptions/', + 'status' => 'expired', + 'icon' => 'dashicons-info', ); $subscription['download_primary'] = false; - $subscription['actions'][] = $action; + $subscription['actions'][] = $action; } elseif ( $subscription['expiring'] ) { $action = array( - 'message' => sprintf( __( 'This subscription is expiring soon. Please renew to continue receiving updates and support.', 'woocommerce' ) ), + 'message' => sprintf( __( 'This subscription is expiring soon. Please renew to continue receiving updates and support.', 'woocommerce' ) ), 'button_label' => __( 'Renew', 'woocommerce' ), - 'button_url' => 'https://woocommerce.com/my-account/my-subscriptions/', - 'status' => 'expired', - 'icon' => 'dashicons-info', + 'button_url' => 'https://woocommerce.com/my-account/my-subscriptions/', + 'status' => 'expired', + 'icon' => 'dashicons-info', ); $subscription['download_primary'] = false; - $subscription['actions'][] = $action; + $subscription['actions'][] = $action; } // Mark the first action primary. @@ -260,7 +270,7 @@ class WC_Helper { } $data['_product_url'] = '#'; - $data['_has_update'] = false; + $data['_has_update'] = false; if ( ! empty( $updates[ $data['_product_id'] ] ) ) { $data['_has_update'] = version_compare( $updates[ $data['_product_id'] ]['version'], $data['Version'], '>' ); @@ -276,22 +286,22 @@ class WC_Helper { if ( $data['_has_update'] ) { $action = array( - 'message' => sprintf( __( 'Version %s is available. To enable this update you need to purchase a new subscription.', 'woocommerce' ), esc_html( $updates[ $data['_product_id'] ]['version'] ) ), + 'message' => sprintf( __( 'Version %s is available. To enable this update you need to purchase a new subscription.', 'woocommerce' ), esc_html( $updates[ $data['_product_id'] ]['version'] ) ), 'button_label' => __( 'Purchase', 'woocommerce' ), - 'button_url' => $data['_product_url'], - 'status' => 'expired', - 'icon' => 'dashicons-info', + 'button_url' => $data['_product_url'], + 'status' => 'expired', + 'icon' => 'dashicons-info', ); $data['_actions'][] = $action; } else { $action = array( /* translators: 1: subscriptions docs 2: subscriptions docs */ - 'message' => sprintf( __( 'To receive updates and support for this extension, you need to purchase a new subscription or consolidate your extensions to one connected account by sharing or transferring this extension to this connected account.', 'woocommerce' ), 'https://docs.woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-10', 'https://docs.woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-5' ), + 'message' => sprintf( __( 'To receive updates and support for this extension, you need to purchase a new subscription or consolidate your extensions to one connected account by sharing or transferring this extension to this connected account.', 'woocommerce' ), 'https://docs.woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-10', 'https://docs.woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-5' ), 'button_label' => __( 'Purchase', 'woocommerce' ), - 'button_url' => $data['_product_url'], - 'status' => 'expired', - 'icon' => 'dashicons-info', + 'button_url' => $data['_product_url'], + 'status' => 'expired', + 'icon' => 'dashicons-info', ); $data['_actions'][] = $action; @@ -315,7 +325,7 @@ class WC_Helper { self::_filter( $subscriptions, self::get_current_filter() ); // We have an active connection. - include( self::get_view_filename( 'html-main.php' ) ); + include self::get_view_filename( 'html-main.php' ); return; } @@ -326,14 +336,14 @@ class WC_Helper { */ public static function get_filters() { $filters = array( - 'all' => __( 'All', 'woocommerce' ), - 'active' => __( 'Active', 'woocommerce' ), - 'inactive' => __( 'Inactive', 'woocommerce' ), - 'installed' => __( 'Installed', 'woocommerce' ), + 'all' => __( 'All', 'woocommerce' ), + 'active' => __( 'Active', 'woocommerce' ), + 'inactive' => __( 'Inactive', 'woocommerce' ), + 'installed' => __( 'Installed', 'woocommerce' ), 'update-available' => __( 'Update Available', 'woocommerce' ), - 'expiring' => __( 'Expiring Soon', 'woocommerce' ), - 'expired' => __( 'Expired', 'woocommerce' ), - 'download' => __( 'Download', 'woocommerce' ), + 'expiring' => __( 'Expiring Soon', 'woocommerce' ), + 'expired' => __( 'Expired', 'woocommerce' ), + 'download' => __( 'Download', 'woocommerce' ), ); return $filters; @@ -374,7 +384,7 @@ class WC_Helper { */ public static function get_current_filter() { $current_filter = 'all'; - $valid_filters = array_keys( self::get_filters() ); + $valid_filters = array_keys( self::get_filters() ); if ( ! empty( $_GET['filter'] ) && in_array( $_GET['filter'], $valid_filters ) ) { $current_filter = $_GET['filter']; @@ -386,7 +396,7 @@ class WC_Helper { /** * Filter an array of subscriptions by $filter. * - * @param array $subscriptions The subscriptions array, passed by ref. + * @param array $subscriptions The subscriptions array, passed by ref. * @param string $filter The filter. */ private static function _filter( &$subscriptions, $filter ) { @@ -451,106 +461,122 @@ class WC_Helper { */ private static function _get_return_notices() { $return_status = isset( $_GET['wc-helper-status'] ) ? $_GET['wc-helper-status'] : null; - $notices = array(); + $notices = array(); switch ( $return_status ) { case 'activate-success': $subscription = self::_get_subscriptions_from_product_id( absint( $_GET['wc-helper-product-id'] ) ); - $notices[] = array( - 'type' => 'updated', + $notices[] = array( + 'type' => 'updated', /* translators: %s: product name */ - 'message' => sprintf( __( '%s activated successfully. You will now receive updates for this product.', 'woocommerce' ), - '' . esc_html( $subscription['product_name'] ) . '' ), + 'message' => sprintf( + __( '%s activated successfully. You will now receive updates for this product.', 'woocommerce' ), + '' . esc_html( $subscription['product_name'] ) . '' + ), ); break; case 'activate-error': $subscription = self::_get_subscriptions_from_product_id( absint( $_GET['wc-helper-product-id'] ) ); - $notices[] = array( - 'type' => 'error', + $notices[] = array( + 'type' => 'error', /* translators: %s: product name */ - 'message' => sprintf( __( 'An error has occurred when activating %s. Please try again later.', 'woocommerce' ), - '' . esc_html( $subscription['product_name'] ) . '' ), + 'message' => sprintf( + __( 'An error has occurred when activating %s. Please try again later.', 'woocommerce' ), + '' . esc_html( $subscription['product_name'] ) . '' + ), ); break; case 'deactivate-success': $subscription = self::_get_subscriptions_from_product_id( absint( $_GET['wc-helper-product-id'] ) ); - $local = self::_get_local_from_product_id( absint( $_GET['wc-helper-product-id'] ) ); + $local = self::_get_local_from_product_id( absint( $_GET['wc-helper-product-id'] ) ); /* translators: %s: product name */ - $message = sprintf( __( 'Subscription for %s deactivated successfully. You will no longer receive updates for this product.', 'woocommerce' ), - '' . esc_html( $subscription['product_name'] ) . '' ); + $message = sprintf( + __( 'Subscription for %s deactivated successfully. You will no longer receive updates for this product.', 'woocommerce' ), + '' . esc_html( $subscription['product_name'] ) . '' + ); if ( $local && is_plugin_active( $local['_filename'] ) && current_user_can( 'activate_plugins' ) ) { - $deactivate_plugin_url = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'filter' => self::get_current_filter(), - 'wc-helper-deactivate-plugin' => 1, - 'wc-helper-product-id' => $subscription['product_id'], - 'wc-helper-nonce' => wp_create_nonce( 'deactivate-plugin:' . $subscription['product_id'] ), - ), admin_url( 'admin.php' ) ); + $deactivate_plugin_url = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'filter' => self::get_current_filter(), + 'wc-helper-deactivate-plugin' => 1, + 'wc-helper-product-id' => $subscription['product_id'], + 'wc-helper-nonce' => wp_create_nonce( 'deactivate-plugin:' . $subscription['product_id'] ), + ), admin_url( 'admin.php' ) + ); /* translators: %1$s: product name, %2$s: deactivate url */ - $message = sprintf( __( 'Subscription for %1$s deactivated successfully. You will no longer receive updates for this product. Click here if you wish to deactivate the plugin as well.', 'woocommerce' ), - '' . esc_html( $subscription['product_name'] ) . '', esc_url( $deactivate_plugin_url ) ); + $message = sprintf( + __( 'Subscription for %1$s deactivated successfully. You will no longer receive updates for this product. Click here if you wish to deactivate the plugin as well.', 'woocommerce' ), + '' . esc_html( $subscription['product_name'] ) . '', esc_url( $deactivate_plugin_url ) + ); } $notices[] = array( 'message' => $message, - 'type' => 'updated', + 'type' => 'updated', ); break; case 'deactivate-error': $subscription = self::_get_subscriptions_from_product_id( absint( $_GET['wc-helper-product-id'] ) ); - $notices[] = array( - 'type' => 'error', + $notices[] = array( + 'type' => 'error', /* translators: %s: product name */ - 'message' => sprintf( __( 'An error has occurred when deactivating the subscription for %s. Please try again later.', 'woocommerce' ), - '' . esc_html( $subscription['product_name'] ) . '' ), + 'message' => sprintf( + __( 'An error has occurred when deactivating the subscription for %s. Please try again later.', 'woocommerce' ), + '' . esc_html( $subscription['product_name'] ) . '' + ), ); break; case 'deactivate-plugin-success': $subscription = self::_get_subscriptions_from_product_id( absint( $_GET['wc-helper-product-id'] ) ); - $notices[] = array( - 'type' => 'updated', + $notices[] = array( + 'type' => 'updated', /* translators: %s: product name */ - 'message' => sprintf( __( 'The extension %s has been deactivated successfully.', 'woocommerce' ), - '' . esc_html( $subscription['product_name'] ) . '' ), + 'message' => sprintf( + __( 'The extension %s has been deactivated successfully.', 'woocommerce' ), + '' . esc_html( $subscription['product_name'] ) . '' + ), ); break; case 'deactivate-plugin-error': $subscription = self::_get_subscriptions_from_product_id( absint( $_GET['wc-helper-product-id'] ) ); - $notices[] = array( - 'type' => 'error', + $notices[] = array( + 'type' => 'error', /* translators: %1$s: product name, %2$s: plugins screen url */ - 'message' => sprintf( __( 'An error has occurred when deactivating the extension %1$s. Please proceed to the Plugins screen to deactivate it manually.', 'woocommerce' ), - '' . esc_html( $subscription['product_name'] ) . '', admin_url( 'plugins.php' ) ), + 'message' => sprintf( + __( 'An error has occurred when deactivating the extension %1$s. Please proceed to the Plugins screen to deactivate it manually.', 'woocommerce' ), + '' . esc_html( $subscription['product_name'] ) . '', admin_url( 'plugins.php' ) + ), ); break; case 'helper-connected': $notices[] = array( 'message' => __( 'You have successfully connected your store to WooCommerce.com', 'woocommerce' ), - 'type' => 'updated', + 'type' => 'updated', ); break; case 'helper-disconnected': $notices[] = array( 'message' => __( 'You have successfully disconnected your store from WooCommerce.com', 'woocommerce' ), - 'type' => 'updated', + 'type' => 'updated', ); break; case 'helper-refreshed': $notices[] = array( 'message' => __( 'Authentication and subscription caches refreshed successfully.', 'woocommerce' ), - 'type' => 'updated', + 'type' => 'updated', ); break; } @@ -610,19 +636,23 @@ class WC_Helper { wp_die( 'Could not verify nonce' ); } - $redirect_uri = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'wc-helper-return' => 1, - 'wc-helper-nonce' => wp_create_nonce( 'connect' ), - ), admin_url( 'admin.php' ) ); + $redirect_uri = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'wc-helper-return' => 1, + 'wc-helper-nonce' => wp_create_nonce( 'connect' ), + ), admin_url( 'admin.php' ) + ); - $request = WC_Helper_API::post( 'oauth/request_token', array( - 'body' => array( - 'home_url' => home_url(), - 'redirect_uri' => $redirect_uri, - ), - ) ); + $request = WC_Helper_API::post( + 'oauth/request_token', array( + 'body' => array( + 'home_url' => home_url(), + 'redirect_uri' => $redirect_uri, + ), + ) + ); $code = wp_remote_retrieve_response_code( $request ); @@ -637,11 +667,13 @@ class WC_Helper { wp_die( 'Something went wrong' ); } - $connect_url = add_query_arg( array( - 'home_url' => rawurlencode( home_url() ), - 'redirect_uri' => rawurlencode( $redirect_uri ), - 'secret' => rawurlencode( $secret ), - ), WC_Helper_API::url( 'oauth/authorize' ) ); + $connect_url = add_query_arg( + array( + 'home_url' => rawurlencode( home_url() ), + 'redirect_uri' => rawurlencode( $redirect_uri ), + 'secret' => rawurlencode( $secret ), + ), WC_Helper_API::url( 'oauth/authorize' ) + ); wp_redirect( esc_url_raw( $connect_url ) ); die(); @@ -669,12 +701,14 @@ class WC_Helper { } // Obtain an access token. - $request = WC_Helper_API::post( 'oauth/access_token', array( - 'body' => array( - 'request_token' => $_GET['request_token'], - 'home_url' => home_url(), - ), - ) ); + $request = WC_Helper_API::post( + 'oauth/access_token', array( + 'body' => array( + 'request_token' => $_GET['request_token'], + 'home_url' => home_url(), + ), + ) + ); $code = wp_remote_retrieve_response_code( $request ); @@ -689,13 +723,15 @@ class WC_Helper { wp_die( 'Something went wrong' ); } - WC_Helper_Options::update( 'auth', array( - 'access_token' => $access_token['access_token'], - 'access_token_secret' => $access_token['access_token_secret'], - 'site_id' => $access_token['site_id'], - 'user_id' => get_current_user_id(), - 'updated' => time(), - ) ); + WC_Helper_Options::update( + 'auth', array( + 'access_token' => $access_token['access_token'], + 'access_token_secret' => $access_token['access_token_secret'], + 'site_id' => $access_token['site_id'], + 'user_id' => get_current_user_id(), + 'updated' => time(), + ) + ); // Obtain the connected user info. if ( ! self::_flush_authentication_cache() ) { @@ -712,11 +748,15 @@ class WC_Helper { WC_Tracker::send_tracking_data( true ); } - wp_safe_redirect( add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'wc-helper-status' => 'helper-connected', - ), admin_url( 'admin.php' ) ) ); + wp_safe_redirect( + add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'wc-helper-status' => 'helper-connected', + ), admin_url( 'admin.php' ) + ) + ); die(); } @@ -729,15 +769,19 @@ class WC_Helper { wp_die( 'Could not verify nonce' ); } - $redirect_uri = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'wc-helper-status' => 'helper-disconnected', - ), admin_url( 'admin.php' ) ); + $redirect_uri = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'wc-helper-status' => 'helper-disconnected', + ), admin_url( 'admin.php' ) + ); - WC_Helper_API::post( 'oauth/invalidate_token', array( - 'authenticated' => true, - ) ); + WC_Helper_API::post( + 'oauth/invalidate_token', array( + 'authenticated' => true, + ) + ); WC_Helper_Options::update( 'auth', array() ); WC_Helper_Options::update( 'auth_user_data', array() ); @@ -761,12 +805,14 @@ class WC_Helper { wp_die( 'Could not verify nonce' ); } - $redirect_uri = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'filter' => self::get_current_filter(), - 'wc-helper-status' => 'helper-refreshed', - ), admin_url( 'admin.php' ) ); + $redirect_uri = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'filter' => self::get_current_filter(), + 'wc-helper-status' => 'helper-refreshed', + ), admin_url( 'admin.php' ) + ); self::_flush_authentication_cache(); self::_flush_subscriptions_cache(); @@ -781,22 +827,26 @@ class WC_Helper { */ private static function _helper_subscription_activate() { $product_key = $_GET['wc-helper-product-key']; - $product_id = absint( $_GET['wc-helper-product-id'] ); + $product_id = absint( $_GET['wc-helper-product-id'] ); if ( empty( $_GET['wc-helper-nonce'] ) || ! wp_verify_nonce( $_GET['wc-helper-nonce'], 'activate:' . $product_key ) ) { self::log( 'Could not verify nonce in _helper_subscription_activate' ); wp_die( 'Could not verify nonce' ); } - $request = WC_Helper_API::post( 'activate', array( - 'authenticated' => true, - 'body' => json_encode( array( - 'product_key' => $product_key, - ) ), - ) ); + $request = WC_Helper_API::post( + 'activate', array( + 'authenticated' => true, + 'body' => json_encode( + array( + 'product_key' => $product_key, + ) + ), + ) + ); $activated = wp_remote_retrieve_response_code( $request ) === 200; - $body = json_decode( wp_remote_retrieve_body( $request ), true ); + $body = json_decode( wp_remote_retrieve_body( $request ), true ); if ( ! $activated && ! empty( $body['code'] ) && 'already_connected' == $body['code'] ) { $activated = true; } @@ -808,13 +858,15 @@ class WC_Helper { } self::_flush_subscriptions_cache(); - $redirect_uri = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'filter' => self::get_current_filter(), - 'wc-helper-status' => $activated ? 'activate-success' : 'activate-error', - 'wc-helper-product-id' => $product_id, - ), admin_url( 'admin.php' ) ); + $redirect_uri = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'filter' => self::get_current_filter(), + 'wc-helper-status' => $activated ? 'activate-success' : 'activate-error', + 'wc-helper-product-id' => $product_id, + ), admin_url( 'admin.php' ) + ); wp_safe_redirect( $redirect_uri ); die(); @@ -825,34 +877,40 @@ class WC_Helper { */ private static function _helper_subscription_deactivate() { $product_key = $_GET['wc-helper-product-key']; - $product_id = absint( $_GET['wc-helper-product-id'] ); + $product_id = absint( $_GET['wc-helper-product-id'] ); if ( empty( $_GET['wc-helper-nonce'] ) || ! wp_verify_nonce( $_GET['wc-helper-nonce'], 'deactivate:' . $product_key ) ) { self::log( 'Could not verify nonce in _helper_subscription_deactivate' ); wp_die( 'Could not verify nonce' ); } - $request = WC_Helper_API::post( 'deactivate', array( - 'authenticated' => true, - 'body' => json_encode( array( - 'product_key' => $product_key, - ) ), - ) ); + $request = WC_Helper_API::post( + 'deactivate', array( + 'authenticated' => true, + 'body' => json_encode( + array( + 'product_key' => $product_key, + ) + ), + ) + ); - $code = wp_remote_retrieve_response_code( $request ); + $code = wp_remote_retrieve_response_code( $request ); $deactivated = 200 === $code; if ( ! $deactivated ) { self::log( sprintf( 'Deactivate API call returned a non-200 response code (%d)', $code ) ); } self::_flush_subscriptions_cache(); - $redirect_uri = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'filter' => self::get_current_filter(), - 'wc-helper-status' => $deactivated ? 'deactivate-success' : 'deactivate-error', - 'wc-helper-product-id' => $product_id, - ), admin_url( 'admin.php' ) ); + $redirect_uri = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'filter' => self::get_current_filter(), + 'wc-helper-status' => $deactivated ? 'deactivate-success' : 'deactivate-error', + 'wc-helper-product-id' => $product_id, + ), admin_url( 'admin.php' ) + ); wp_safe_redirect( $redirect_uri ); die(); @@ -862,7 +920,7 @@ class WC_Helper { * Deactivate a plugin. */ private static function _helper_plugin_deactivate() { - $product_id = absint( $_GET['wc-helper-product-id'] ); + $product_id = absint( $_GET['wc-helper-product-id'] ); $deactivated = false; if ( empty( $_GET['wc-helper-nonce'] ) || ! wp_verify_nonce( $_GET['wc-helper-nonce'], 'deactivate-plugin:' . $product_id ) ) { @@ -874,8 +932,12 @@ class WC_Helper { wp_die( 'You are not allowed to manage plugins on this site.' ); } - $local = wp_list_filter( array_merge( self::get_local_woo_plugins(), - self::get_local_woo_themes() ), array( '_product_id' => $product_id ) ); + $local = wp_list_filter( + array_merge( + self::get_local_woo_plugins(), + self::get_local_woo_themes() + ), array( '_product_id' => $product_id ) + ); // Attempt to deactivate this plugin or theme. if ( ! empty( $local ) ) { @@ -887,13 +949,15 @@ class WC_Helper { $deactivated = ! is_plugin_active( $local['_filename'] ); } - $redirect_uri = add_query_arg( array( - 'page' => 'wc-addons', - 'section' => 'helper', - 'filter' => self::get_current_filter(), - 'wc-helper-status' => $deactivated ? 'deactivate-plugin-success' : 'deactivate-plugin-error', - 'wc-helper-product-id' => $product_id, - ), admin_url( 'admin.php' ) ); + $redirect_uri = add_query_arg( + array( + 'page' => 'wc-addons', + 'section' => 'helper', + 'filter' => self::get_current_filter(), + 'wc-helper-status' => $deactivated ? 'deactivate-plugin-success' : 'deactivate-plugin-error', + 'wc-helper-product-id' => $product_id, + ), admin_url( 'admin.php' ) + ); wp_safe_redirect( $redirect_uri ); die(); @@ -907,8 +971,12 @@ class WC_Helper { * @return array|bool The array containing the local plugin/theme data or false. */ private static function _get_local_from_product_id( $product_id ) { - $local = wp_list_filter( array_merge( self::get_local_woo_plugins(), - self::get_local_woo_themes() ), array( '_product_id' => $product_id ) ); + $local = wp_list_filter( + array_merge( + self::get_local_woo_plugins(), + self::get_local_woo_themes() + ), array( '_product_id' => $product_id ) + ); if ( ! empty( $local ) ) { return array_shift( $local ); @@ -923,7 +991,7 @@ class WC_Helper { * first one in the list, so you can use this method to get things like extension * name, version, etc. * - * @param int $product_id The product id. + * @param int $product_id The product id. * @param bool $single Whether to return a single subscription or all matching a product id. * * @return array|bool The array containing sub data or false. @@ -952,10 +1020,10 @@ class WC_Helper { */ public static function get_local_woo_plugins() { if ( ! function_exists( 'get_plugins' ) ) { - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + require_once ABSPATH . 'wp-admin/includes/plugin.php'; } - $plugins = get_plugins(); + $plugins = get_plugins(); $woo_plugins = array(); // Backwards compatibility for woothemes_queue_update(). @@ -964,7 +1032,7 @@ class WC_Helper { foreach ( $GLOBALS['woothemes_queued_updates'] as $_compat_plugin ) { $_compat[ $_compat_plugin->file ] = array( 'product_id' => $_compat_plugin->product_id, - 'file_id' => $_compat_plugin->file_id, + 'file_id' => $_compat_plugin->file_id, ); } } @@ -983,10 +1051,10 @@ class WC_Helper { continue; } - $data['_filename'] = $filename; - $data['_product_id'] = absint( $product_id ); - $data['_file_id'] = $file_id; - $data['_type'] = 'plugin'; + $data['_filename'] = $filename; + $data['_product_id'] = absint( $product_id ); + $data['_file_id'] = $file_id; + $data['_type'] = 'plugin'; $woo_plugins[ $filename ] = $data; } @@ -997,7 +1065,7 @@ class WC_Helper { * Get locally installed Woo themes. */ public static function get_local_woo_themes() { - $themes = wp_get_themes(); + $themes = wp_get_themes(); $woo_themes = array(); foreach ( $themes as $theme ) { @@ -1008,7 +1076,7 @@ class WC_Helper { $txt = $theme->get_stylesheet_directory() . '/theme_info.txt'; if ( is_readable( $txt ) ) { $txt = file_get_contents( $txt ); - $txt = preg_split( "#\s#", $txt ); + $txt = preg_split( '#\s#', $txt ); if ( count( $txt ) >= 2 ) { $header = sprintf( '%d:%s', $txt[0], $txt[1] ); } @@ -1025,15 +1093,15 @@ class WC_Helper { } $data = array( - 'Name' => $theme->get( 'Name' ), - 'Version' => $theme->get( 'Version' ), - 'Woo' => $header, + 'Name' => $theme->get( 'Name' ), + 'Version' => $theme->get( 'Version' ), + 'Woo' => $header, - '_filename' => $theme->get_stylesheet() . '/style.css', + '_filename' => $theme->get_stylesheet() . '/style.css', '_stylesheet' => $theme->get_stylesheet(), '_product_id' => absint( $product_id ), - '_file_id' => $file_id, - '_type' => 'theme', + '_file_id' => $file_id, + '_type' => 'theme', ); $woo_themes[ $data['_filename'] ] = $data; @@ -1054,9 +1122,11 @@ class WC_Helper { } // Obtain the connected user info. - $request = WC_Helper_API::get( 'subscriptions', array( - 'authenticated' => true, - ) ); + $request = WC_Helper_API::get( + 'subscriptions', array( + 'authenticated' => true, + ) + ); if ( wp_remote_retrieve_response_code( $request ) !== 200 ) { set_transient( $cache_key, array(), 15 * MINUTE_IN_SECONDS ); @@ -1095,7 +1165,7 @@ class WC_Helper { return; } - $plugin = $plugins[ $filename ]; + $plugin = $plugins[ $filename ]; $subscriptions = self::_get_subscriptions_from_product_id( $plugin['_product_id'], false ); // No valid subscriptions for this product @@ -1126,15 +1196,19 @@ class WC_Helper { return; } - $request = WC_Helper_API::post( 'activate', array( - 'authenticated' => true, - 'body' => json_encode( array( - 'product_key' => $subscription['product_key'], - ) ), - ) ); + $request = WC_Helper_API::post( + 'activate', array( + 'authenticated' => true, + 'body' => json_encode( + array( + 'product_key' => $subscription['product_key'], + ) + ), + ) + ); $activated = wp_remote_retrieve_response_code( $request ) === 200; - $body = json_decode( wp_remote_retrieve_body( $request ), true ); + $body = json_decode( wp_remote_retrieve_body( $request ), true ); if ( ! $activated && ! empty( $body['code'] ) && 'already_connected' == $body['code'] ) { $activated = true; } @@ -1170,9 +1244,9 @@ class WC_Helper { return; } - $plugin = $plugins[ $filename ]; + $plugin = $plugins[ $filename ]; $subscriptions = self::_get_subscriptions_from_product_id( $plugin['_product_id'], false ); - $site_id = absint( $auth['site_id'] ); + $site_id = absint( $auth['site_id'] ); // No valid subscriptions for this product if ( empty( $subscriptions ) ) { @@ -1187,12 +1261,16 @@ class WC_Helper { continue; } - $request = WC_Helper_API::post( 'deactivate', array( - 'authenticated' => true, - 'body' => json_encode( array( - 'product_key' => $subscription['product_key'], - ) ), - ) ); + $request = WC_Helper_API::post( + 'deactivate', array( + 'authenticated' => true, + 'body' => json_encode( + array( + 'product_key' => $subscription['product_key'], + ) + ), + ) + ); if ( wp_remote_retrieve_response_code( $request ) === 200 ) { $deactivated++; @@ -1286,8 +1364,8 @@ class WC_Helper { * @return string|null The update notice or null if everything is up to date. */ private static function _get_extensions_update_notice() { - $plugins = self::get_local_woo_plugins(); - $updates = WC_Helper_Updater::get_update_data(); + $plugins = self::get_local_woo_plugins(); + $updates = WC_Helper_Updater::get_update_data(); $available = 0; foreach ( $plugins as $data ) { @@ -1306,8 +1384,10 @@ class WC_Helper { } /* translators: %1$s: helper url, %2$d: number of extensions */ - return sprintf( _n( 'Note: You currently have %2$d paid extension which should be updated first before updating WooCommerce.', 'Note: You currently have %2$d paid extensions which should be updated first before updating WooCommerce.', $available, 'woocommerce' ), - admin_url( 'admin.php?page=wc-addons§ion=helper' ), $available ); + return sprintf( + _n( 'Note: You currently have %2$d paid extension which should be updated first before updating WooCommerce.', 'Note: You currently have %2$d paid extensions which should be updated first before updating WooCommerce.', $available, 'woocommerce' ), + admin_url( 'admin.php?page=wc-addons§ion=helper' ), $available + ); } /** @@ -1346,9 +1426,11 @@ class WC_Helper { * @access private */ public static function _flush_authentication_cache() { - $request = WC_Helper_API::get( 'oauth/me', array( - 'authenticated' => true, - ) ); + $request = WC_Helper_API::get( + 'oauth/me', array( + 'authenticated' => true, + ) + ); if ( wp_remote_retrieve_response_code( $request ) !== 200 ) { return false; @@ -1359,10 +1441,12 @@ class WC_Helper { return false; } - WC_Helper_Options::update( 'auth_user_data', array( - 'name' => $user_data['name'], - 'email' => $user_data['email'], - ) ); + WC_Helper_Options::update( + 'auth_user_data', array( + 'name' => $user_data['name'], + 'email' => $user_data['email'], + ) + ); return true; } diff --git a/includes/admin/helper/views/html-main.php b/includes/admin/helper/views/html-main.php index c3b87239090..3023a192b14 100644 --- a/includes/admin/helper/views/html-main.php +++ b/includes/admin/helper/views/html-main.php @@ -1,35 +1,35 @@
    - +

    - +

    - +

    Plugins screen.', 'woocommerce' ), admin_url( 'plugins.php' ) ); ?>

      - $label ) : ?> - $label ) : + // Don't show empty filters. + if ( empty( $counts[ $key ] ) ) { + continue; + } - $url = admin_url( 'admin.php?page=wc-addons§ion=helper&filter=' . $key ); - $class_html = $current_filter === $key ? 'class="current"' : ''; + $url = admin_url( 'admin.php?page=wc-addons§ion=helper&filter=' . $key ); + $class_html = $current_filter === $key ? 'class="current"' : ''; ?>
    • href=""> @@ -47,8 +47,9 @@
      @@ -80,7 +81,7 @@
      - ' . __( 'Shared by %s', 'woocommerce' ), esc_html( $subscription['master_user_email'] ) ); } - ?> + ?>
      diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index 96e48ce495c..8bd7aa6e420 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -75,7 +75,7 @@ class WC_Product_CSV_Importer_Controller { */ public static function get_importer( $file, $args = array() ) { $importer_class = apply_filters( 'woocommerce_product_csv_importer_class', 'WC_Product_CSV_Importer' ); - $args = apply_filters( 'woocommerce_product_csv_importer_args', $args, $importer_class ); + $args = apply_filters( 'woocommerce_product_csv_importer_args', $args, $importer_class ); return new $importer_class( $file, $args ); } @@ -84,7 +84,7 @@ class WC_Product_CSV_Importer_Controller { */ public function __construct() { $default_steps = array( - 'upload' => array( + 'upload' => array( 'name' => __( 'Upload CSV file', 'woocommerce' ), 'view' => array( $this, 'upload_form' ), 'handler' => array( $this, 'upload_form_handler' ), @@ -94,12 +94,12 @@ class WC_Product_CSV_Importer_Controller { 'view' => array( $this, 'mapping_form' ), 'handler' => '', ), - 'import' => array( + 'import' => array( 'name' => __( 'Import', 'woocommerce' ), 'view' => array( $this, 'import' ), 'handler' => '', ), - 'done' => array( + 'done' => array( 'name' => __( 'Done!', 'woocommerce' ), 'view' => array( $this, 'done' ), 'handler' => '', @@ -121,6 +121,7 @@ class WC_Product_CSV_Importer_Controller { /** * Get the URL for the next step's screen. + * * @param string step slug (default: current step) * @return string URL for next step if a next step exists. * Admin URL if it's the last step. @@ -159,21 +160,21 @@ class WC_Product_CSV_Importer_Controller { * Output header view. */ protected function output_header() { - include( dirname( __FILE__ ) . '/views/html-csv-import-header.php' ); + include dirname( __FILE__ ) . '/views/html-csv-import-header.php'; } /** * Output steps view. */ protected function output_steps() { - include( dirname( __FILE__ ) . '/views/html-csv-import-steps.php' ); + include dirname( __FILE__ ) . '/views/html-csv-import-steps.php'; } /** * Output footer view. */ protected function output_footer() { - include( dirname( __FILE__ ) . '/views/html-csv-import-footer.php' ); + include dirname( __FILE__ ) . '/views/html-csv-import-footer.php'; } /** @@ -234,7 +235,7 @@ class WC_Product_CSV_Importer_Controller { $size = size_format( $bytes ); $upload_dir = wp_upload_dir(); - include( dirname( __FILE__ ) . '/views/html-product-csv-import-form.php' ); + include dirname( __FILE__ ) . '/views/html-product-csv-import-form.php'; } /** @@ -263,7 +264,12 @@ class WC_Product_CSV_Importer_Controller { * @return string|WP_Error */ public function handle_upload() { - $valid_filetypes = apply_filters( 'woocommerce_csv_product_import_valid_filetypes', array( 'csv' => 'text/csv', 'txt' => 'text/plain' ) ); + $valid_filetypes = apply_filters( + 'woocommerce_csv_product_import_valid_filetypes', array( + 'csv' => 'text/csv', + 'txt' => 'text/plain', + ) + ); if ( empty( $_POST['file_url'] ) ) { if ( ! isset( $_FILES['import'] ) ) { @@ -275,8 +281,11 @@ class WC_Product_CSV_Importer_Controller { return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) ); } - $overrides = array( 'test_form' => false, 'mimes' => $valid_filetypes ); - $upload = wp_handle_upload( $_FILES['import'], $overrides ); + $overrides = array( + 'test_form' => false, + 'mimes' => $valid_filetypes, + ); + $upload = wp_handle_upload( $_FILES['import'], $overrides ); if ( isset( $upload['error'] ) ) { return new WP_Error( 'woocommerce_product_csv_importer_upload_error', $upload['error'] ); @@ -318,7 +327,7 @@ class WC_Product_CSV_Importer_Controller { * Mapping step. */ protected function mapping_form() { - $args = array( + $args = array( 'lines' => 1, 'delimiter' => $this->delimiter, ); @@ -344,7 +353,7 @@ class WC_Product_CSV_Importer_Controller { return; } - include_once( dirname( __FILE__ ) . '/views/html-csv-import-mapping.php' ); + include_once dirname( __FILE__ ) . '/views/html-csv-import-mapping.php'; } /** @@ -367,19 +376,21 @@ class WC_Product_CSV_Importer_Controller { exit; } - wp_localize_script( 'wc-product-import', 'wc_product_import_params', array( - 'import_nonce' => wp_create_nonce( 'wc-product-import' ), - 'mapping' => array( - 'from' => $mapping_from, - 'to' => $mapping_to, - ), - 'file' => $this->file, - 'update_existing' => $this->update_existing, - 'delimiter' => $this->delimiter, - ) ); + wp_localize_script( + 'wc-product-import', 'wc_product_import_params', array( + 'import_nonce' => wp_create_nonce( 'wc-product-import' ), + 'mapping' => array( + 'from' => $mapping_from, + 'to' => $mapping_to, + ), + 'file' => $this->file, + 'update_existing' => $this->update_existing, + 'delimiter' => $this->delimiter, + ) + ); wp_enqueue_script( 'wc-product-import' ); - include_once( dirname( __FILE__ ) . '/views/html-csv-import-progress.php' ); + include_once dirname( __FILE__ ) . '/views/html-csv-import-progress.php'; } /** @@ -392,7 +403,7 @@ class WC_Product_CSV_Importer_Controller { $skipped = isset( $_GET['products-skipped'] ) ? absint( $_GET['products-skipped'] ) : 0; $errors = array_filter( (array) get_user_option( 'product_import_error_log' ) ); - include_once( dirname( __FILE__ ) . '/views/html-csv-import-done.php' ); + include_once dirname( __FILE__ ) . '/views/html-csv-import-done.php'; } /** @@ -419,69 +430,78 @@ class WC_Product_CSV_Importer_Controller { * @return array */ protected function auto_map_columns( $raw_headers, $num_indexes = true ) { - $weight_unit = get_option( 'woocommerce_weight_unit' ); - $dimension_unit = get_option( 'woocommerce_dimension_unit' ); + $weight_unit = get_option( 'woocommerce_weight_unit' ); + $dimension_unit = get_option( 'woocommerce_dimension_unit' ); - include( dirname( __FILE__ ) . '/mappings/mappings.php' ); + include dirname( __FILE__ ) . '/mappings/mappings.php'; /** * @hooked wc_importer_generic_mappings - 10 * @hooked wc_importer_wordpress_mappings - 10 * @hooked wc_importer_default_english_mappings - 100 */ - $default_columns = $this->normalize_columns_names( apply_filters( 'woocommerce_csv_product_import_mapping_default_columns', array( - __( 'ID', 'woocommerce' ) => 'id', - __( 'Type', 'woocommerce' ) => 'type', - __( 'SKU', 'woocommerce' ) => 'sku', - __( 'Name', 'woocommerce' ) => 'name', - __( 'Published', 'woocommerce' ) => 'published', - __( 'Is featured?', 'woocommerce' ) => 'featured', - __( 'Visibility in catalog', 'woocommerce' ) => 'catalog_visibility', - __( 'Short description', 'woocommerce' ) => 'short_description', - __( 'Description', 'woocommerce' ) => 'description', - __( 'Date sale price starts', 'woocommerce' ) => 'date_on_sale_from', - __( 'Date sale price ends', 'woocommerce' ) => 'date_on_sale_to', - __( 'Tax status', 'woocommerce' ) => 'tax_status', - __( 'Tax class', 'woocommerce' ) => 'tax_class', - __( 'In stock?', 'woocommerce' ) => 'stock_status', - __( 'Stock', 'woocommerce' ) => 'stock_quantity', - __( 'Backorders allowed?', 'woocommerce' ) => 'backorders', - __( 'Sold individually?', 'woocommerce' ) => 'sold_individually', - sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ) => 'weight', - sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ) => 'length', - sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ) => 'width', - sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ) => 'height', - __( 'Allow customer reviews?', 'woocommerce' ) => 'reviews_allowed', - __( 'Purchase note', 'woocommerce' ) => 'purchase_note', - __( 'Sale price', 'woocommerce' ) => 'sale_price', - __( 'Regular price', 'woocommerce' ) => 'regular_price', - __( 'Categories', 'woocommerce' ) => 'category_ids', - __( 'Tags', 'woocommerce' ) => 'tag_ids', - __( 'Shipping class', 'woocommerce' ) => 'shipping_class_id', - __( 'Images', 'woocommerce' ) => 'images', - __( 'Download limit', 'woocommerce' ) => 'download_limit', - __( 'Download expiry days', 'woocommerce' ) => 'download_expiry', - __( 'Parent', 'woocommerce' ) => 'parent_id', - __( 'Upsells', 'woocommerce' ) => 'upsell_ids', - __( 'Cross-sells', 'woocommerce' ) => 'cross_sell_ids', - __( 'Grouped products', 'woocommerce' ) => 'grouped_products', - __( 'External URL', 'woocommerce' ) => 'product_url', - __( 'Button text', 'woocommerce' ) => 'button_text', - __( 'Position', 'woocommerce' ) => 'menu_order', - ) ) ); - - $special_columns = $this->get_special_columns( $this->normalize_columns_names( apply_filters( 'woocommerce_csv_product_import_mapping_special_columns', - array( - __( 'Attribute %d name', 'woocommerce' ) => 'attributes:name', - __( 'Attribute %d value(s)', 'woocommerce' ) => 'attributes:value', - __( 'Attribute %d visible', 'woocommerce' ) => 'attributes:visible', - __( 'Attribute %d global', 'woocommerce' ) => 'attributes:taxonomy', - __( 'Attribute %d default', 'woocommerce' ) => 'attributes:default', - __( 'Download %d name', 'woocommerce' ) => 'downloads:name', - __( 'Download %d URL', 'woocommerce' ) => 'downloads:url', - __( 'Meta: %s', 'woocommerce' ) => 'meta:', + $default_columns = $this->normalize_columns_names( + apply_filters( + 'woocommerce_csv_product_import_mapping_default_columns', array( + __( 'ID', 'woocommerce' ) => 'id', + __( 'Type', 'woocommerce' ) => 'type', + __( 'SKU', 'woocommerce' ) => 'sku', + __( 'Name', 'woocommerce' ) => 'name', + __( 'Published', 'woocommerce' ) => 'published', + __( 'Is featured?', 'woocommerce' ) => 'featured', + __( 'Visibility in catalog', 'woocommerce' ) => 'catalog_visibility', + __( 'Short description', 'woocommerce' ) => 'short_description', + __( 'Description', 'woocommerce' ) => 'description', + __( 'Date sale price starts', 'woocommerce' ) => 'date_on_sale_from', + __( 'Date sale price ends', 'woocommerce' ) => 'date_on_sale_to', + __( 'Tax status', 'woocommerce' ) => 'tax_status', + __( 'Tax class', 'woocommerce' ) => 'tax_class', + __( 'In stock?', 'woocommerce' ) => 'stock_status', + __( 'Stock', 'woocommerce' ) => 'stock_quantity', + __( 'Backorders allowed?', 'woocommerce' ) => 'backorders', + __( 'Sold individually?', 'woocommerce' ) => 'sold_individually', + sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ) => 'weight', + sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ) => 'length', + sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ) => 'width', + sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ) => 'height', + __( 'Allow customer reviews?', 'woocommerce' ) => 'reviews_allowed', + __( 'Purchase note', 'woocommerce' ) => 'purchase_note', + __( 'Sale price', 'woocommerce' ) => 'sale_price', + __( 'Regular price', 'woocommerce' ) => 'regular_price', + __( 'Categories', 'woocommerce' ) => 'category_ids', + __( 'Tags', 'woocommerce' ) => 'tag_ids', + __( 'Shipping class', 'woocommerce' ) => 'shipping_class_id', + __( 'Images', 'woocommerce' ) => 'images', + __( 'Download limit', 'woocommerce' ) => 'download_limit', + __( 'Download expiry days', 'woocommerce' ) => 'download_expiry', + __( 'Parent', 'woocommerce' ) => 'parent_id', + __( 'Upsells', 'woocommerce' ) => 'upsell_ids', + __( 'Cross-sells', 'woocommerce' ) => 'cross_sell_ids', + __( 'Grouped products', 'woocommerce' ) => 'grouped_products', + __( 'External URL', 'woocommerce' ) => 'product_url', + __( 'Button text', 'woocommerce' ) => 'button_text', + __( 'Position', 'woocommerce' ) => 'menu_order', + ) ) - ) ) ); + ); + + $special_columns = $this->get_special_columns( + $this->normalize_columns_names( + apply_filters( + 'woocommerce_csv_product_import_mapping_special_columns', + array( + __( 'Attribute %d name', 'woocommerce' ) => 'attributes:name', + __( 'Attribute %d value(s)', 'woocommerce' ) => 'attributes:value', + __( 'Attribute %d visible', 'woocommerce' ) => 'attributes:visible', + __( 'Attribute %d global', 'woocommerce' ) => 'attributes:taxonomy', + __( 'Attribute %d default', 'woocommerce' ) => 'attributes:default', + __( 'Download %d name', 'woocommerce' ) => 'downloads:name', + __( 'Download %d URL', 'woocommerce' ) => 'downloads:url', + __( 'Meta: %s', 'woocommerce' ) => 'meta:', + ) + ) + ) + ); $headers = array(); foreach ( $raw_headers as $key => $field ) { @@ -599,11 +619,11 @@ class WC_Product_CSV_Importer_Controller { 'name' => __( 'Dimensions', 'woocommerce' ), 'options' => array( /* translators: %s: dimension unit */ - 'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ), + 'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ), /* translators: %s: dimension unit */ - 'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ), + 'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ), /* translators: %s: dimension unit */ - 'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ), + 'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ), ), ), 'category_ids' => __( 'Categories', 'woocommerce' ), @@ -617,8 +637,8 @@ class WC_Product_CSV_Importer_Controller { 'external' => array( 'name' => __( 'External product', 'woocommerce' ), 'options' => array( - 'product_url' => __( 'External URL', 'woocommerce' ), - 'button_text' => __( 'Button text', 'woocommerce' ), + 'product_url' => __( 'External URL', 'woocommerce' ), + 'button_text' => __( 'Button text', 'woocommerce' ), ), ), 'downloads' => array( diff --git a/includes/admin/importers/class-wc-tax-rate-importer.php b/includes/admin/importers/class-wc-tax-rate-importer.php index ef58490f24d..01923fe579c 100644 --- a/includes/admin/importers/class-wc-tax-rate-importer.php +++ b/includes/admin/importers/class-wc-tax-rate-importer.php @@ -248,14 +248,16 @@ class WC_Tax_Rate_Importer extends WP_Importer { $action = 'admin.php?import=woocommerce_tax_rate_csv&step=1'; - $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); - $size = size_format( $bytes ); + $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); + $size = size_format( $bytes ); $upload_dir = wp_upload_dir(); if ( ! empty( $upload_dir['error'] ) ) : - ?>

      -

      +
      +

      +

      +
      + diff --git a/includes/admin/importers/mappings/default.php b/includes/admin/importers/mappings/default.php index 6e9b548565a..50befb5e346 100644 --- a/includes/admin/importers/mappings/default.php +++ b/includes/admin/importers/mappings/default.php @@ -31,9 +31,9 @@ function wc_importer_default_english_mappings( $mappings ) { return $mappings; } - $weight_unit = get_option( 'woocommerce_weight_unit' ); - $dimension_unit = get_option( 'woocommerce_dimension_unit' ); - $new_mappings = array( + $weight_unit = get_option( 'woocommerce_weight_unit' ); + $dimension_unit = get_option( 'woocommerce_dimension_unit' ); + $new_mappings = array( 'ID' => 'id', 'Type' => 'type', 'SKU' => 'sku', diff --git a/includes/admin/importers/mappings/mappings.php b/includes/admin/importers/mappings/mappings.php index 1b965b5dc51..b236ddda46e 100644 --- a/includes/admin/importers/mappings/mappings.php +++ b/includes/admin/importers/mappings/mappings.php @@ -7,6 +7,6 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -include( dirname( __FILE__ ) . '/default.php' ); -include( dirname( __FILE__ ) . '/generic.php' ); -include( dirname( __FILE__ ) . '/wordpress.php' ); +require dirname( __FILE__ ) . '/default.php'; +require dirname( __FILE__ ) . '/generic.php'; +require dirname( __FILE__ ) . '/wordpress.php'; diff --git a/includes/admin/importers/views/html-csv-import-done.php b/includes/admin/importers/views/html-csv-import-done.php index 086d7cea0c7..66408e41001 100644 --- a/includes/admin/importers/views/html-csv-import-done.php +++ b/includes/admin/importers/views/html-csv-import-done.php @@ -9,46 +9,46 @@ if ( ! defined( 'ABSPATH' ) ) {
      ' . number_format_i18n( $imported ) . '' - ); - } + if ( 0 < $imported ) { + $results[] = sprintf( + /* translators: %d: products count */ + _n( '%s product imported', '%s products imported', $imported, 'woocommerce' ), + '' . number_format_i18n( $imported ) . '' + ); + } - if ( 0 < $updated ) { - $results[] = sprintf( - /* translators: %d: products count */ - _n( '%s product updated', '%s products updated', $updated, 'woocommerce' ), - '' . number_format_i18n( $updated ) . '' - ); - } + if ( 0 < $updated ) { + $results[] = sprintf( + /* translators: %d: products count */ + _n( '%s product updated', '%s products updated', $updated, 'woocommerce' ), + '' . number_format_i18n( $updated ) . '' + ); + } - if ( 0 < $skipped ) { - $results[] = sprintf( - /* translators: %d: products count */ - _n( '%s product was skipped', '%s products were skipped', $skipped, 'woocommerce' ), - '' . number_format_i18n( $skipped ) . '' - ); - } + if ( 0 < $skipped ) { + $results[] = sprintf( + /* translators: %d: products count */ + _n( '%s product was skipped', '%s products were skipped', $skipped, 'woocommerce' ), + '' . number_format_i18n( $skipped ) . '' + ); + } - if ( 0 < $failed ) { - $results [] = sprintf( - /* translators: %d: products count */ - _n( 'Failed to import %s product', 'Failed to import %s products', $failed, 'woocommerce' ), - '' . number_format_i18n( $failed ) . '' - ); - } + if ( 0 < $failed ) { + $results [] = sprintf( + /* translators: %d: products count */ + _n( 'Failed to import %s product', 'Failed to import %s products', $failed, 'woocommerce' ), + '' . number_format_i18n( $failed ) . '' + ); + } - if ( 0 < $failed || 0 < $skipped ) { - $results[] = '' . __( 'View import log', 'woocommerce' ) . ''; - } + if ( 0 < $failed || 0 < $skipped ) { + $results[] = '' . __( 'View import log', 'woocommerce' ) . ''; + } - /* translators: %d: import results */ - echo wp_kses_post( __( 'Import complete!', 'woocommerce' ) . ' ' . implode( '. ', $results ) ); + /* translators: %d: import results */ + echo wp_kses_post( __( 'Import complete!', 'woocommerce' ) . ' ' . implode( '. ', $results ) ); ?>
      get_error_data(); - ?> - - - - - get_error_data(); + ?> + + + + +
      get_error_message() ); ?>
      get_error_message() ); ?>
      diff --git a/includes/admin/importers/views/html-csv-import-mapping.php b/includes/admin/importers/views/html-csv-import-mapping.php index eec751ca3b7..e553c9c5c2d 100644 --- a/includes/admin/importers/views/html-csv-import-mapping.php +++ b/includes/admin/importers/views/html-csv-import-mapping.php @@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } ?> - +

      diff --git a/includes/admin/importers/views/html-csv-import-steps.php b/includes/admin/importers/views/html-csv-import-steps.php index 36d21f8c9d6..4c70611da91 100644 --- a/includes/admin/importers/views/html-csv-import-steps.php +++ b/includes/admin/importers/views/html-csv-import-steps.php @@ -8,12 +8,15 @@ if ( ! defined( 'ABSPATH' ) ) { ?>
        steps as $step_key => $step ) : ?> -
      1. + step ) { + $step_class = 'active'; + } elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) { + $step_class = 'done'; + } + ?> +
      2. + +
      diff --git a/includes/admin/importers/views/html-product-csv-import-form.php b/includes/admin/importers/views/html-product-csv-import-form.php index 756f6b4fc6e..b51c4dac3a2 100644 --- a/includes/admin/importers/views/html-product-csv-import-form.php +++ b/includes/admin/importers/views/html-product-csv-import-form.php @@ -26,10 +26,12 @@ if ( ! defined( 'ABSPATH' ) ) {
      + ?> +

      -
      + @@ -99,4 +101,4 @@ if ( ! defined( 'ABSPATH' ) ) {
      - \ No newline at end of file + diff --git a/includes/admin/list-tables/abstract-class-wc-admin-list-table.php b/includes/admin/list-tables/abstract-class-wc-admin-list-table.php index 2ac3e91d11a..b31708f4925 100644 --- a/includes/admin/list-tables/abstract-class-wc-admin-list-table.php +++ b/includes/admin/list-tables/abstract-class-wc-admin-list-table.php @@ -66,7 +66,7 @@ abstract class WC_Admin_List_Table { if ( $post_type === $this->list_table_type && 'bottom' === $which ) { $counts = (array) wp_count_posts( $post_type ); unset( $counts['auto-draft'] ); - $count = array_sum( $counts ); + $count = array_sum( $counts ); if ( 0 < $count ) { return; diff --git a/includes/admin/list-tables/class-wc-admin-list-table-coupons.php b/includes/admin/list-tables/class-wc-admin-list-table-coupons.php index b12d22b3652..3ae68c87876 100644 --- a/includes/admin/list-tables/class-wc-admin-list-table-coupons.php +++ b/includes/admin/list-tables/class-wc-admin-list-table-coupons.php @@ -17,7 +17,7 @@ if ( class_exists( 'WC_Admin_List_Table_Coupons', false ) ) { } if ( ! class_exists( 'WC_Admin_List_Table', false ) ) { - include_once( 'abstract-class-wc-admin-list-table.php' ); + include_once 'abstract-class-wc-admin-list-table.php'; } /** @@ -47,7 +47,7 @@ class WC_Admin_List_Table_Coupons extends WC_Admin_List_Table { echo '
      '; echo '

      ' . esc_html__( 'Coupons are a great way to offer discounts and rewards to your customers. They will appear here once created.', 'woocommerce' ) . '

      '; echo '' . esc_html__( 'Learn more about coupons', 'woocommerce' ) . ''; - echo '' . esc_html__( 'Create your first coupon', 'woocommerce' ) . ''; + echo '' . esc_html__( 'Create your first coupon', 'woocommerce' ) . ''; echo '
      '; } diff --git a/includes/admin/list-tables/class-wc-admin-list-table-products.php b/includes/admin/list-tables/class-wc-admin-list-table-products.php index 3a6422824ea..651f101a98b 100644 --- a/includes/admin/list-tables/class-wc-admin-list-table-products.php +++ b/includes/admin/list-tables/class-wc-admin-list-table-products.php @@ -458,8 +458,8 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table { // Search using CRUD. if ( ! empty( $query_vars['s'] ) ) { - $data_store = WC_Data_Store::load( 'product' ); - $ids = $data_store->search_products( wc_clean( $query_vars['s'] ), '', true, true ); + $data_store = WC_Data_Store::load( 'product' ); + $ids = $data_store->search_products( wc_clean( $query_vars['s'] ), '', true, true ); $query_vars['post__in'] = array_merge( $ids, array( 0 ) ); // So we know we are searching products. $query_vars['product_search'] = true; diff --git a/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php b/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php index 52161ed8314..0cbb9453761 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-coupon-data.php @@ -28,7 +28,9 @@ class WC_Meta_Box_Coupon_Data { wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); $coupon = new WC_Coupon( $post->ID ); + ?> + @@ -38,8 +40,9 @@ class WC_Meta_Box_Coupon_Data { -
      + 'discount_type', - 'label' => __( 'Discount type', 'woocommerce' ), - 'options' => wc_get_coupon_types(), - ) ); + // Type. + woocommerce_wp_select( + array( + 'id' => 'discount_type', + 'label' => __( 'Discount type', 'woocommerce' ), + 'options' => wc_get_coupon_types(), + ) + ); - // Amount - woocommerce_wp_text_input( array( - 'id' => 'coupon_amount', - 'label' => __( 'Coupon amount', 'woocommerce' ), - 'placeholder' => wc_format_localized_price( 0 ), - 'description' => __( 'Value of the coupon.', 'woocommerce' ), - 'data_type' => 'price', - 'desc_tip' => true, - ) ); + // Amount. + woocommerce_wp_text_input( + array( + 'id' => 'coupon_amount', + 'label' => __( 'Coupon amount', 'woocommerce' ), + 'placeholder' => wc_format_localized_price( 0 ), + 'description' => __( 'Value of the coupon.', 'woocommerce' ), + 'data_type' => 'price', + 'desc_tip' => true, + ) + ); - // Free Shipping + // Free Shipping. if ( wc_shipping_enabled() ) { - woocommerce_wp_checkbox( array( - 'id' => 'free_shipping', - 'label' => __( 'Allow free shipping', 'woocommerce' ), - 'description' => sprintf( __( 'Check this box if the coupon grants free shipping. A free shipping method must be enabled in your shipping zone and be set to require "a valid free shipping coupon" (see the "Free Shipping Requires" setting).', 'woocommerce' ), 'https://docs.woocommerce.com/document/free-shipping/' ), - ) ); + woocommerce_wp_checkbox( + array( + 'id' => 'free_shipping', + 'label' => __( 'Allow free shipping', 'woocommerce' ), + 'description' => sprintf( __( 'Check this box if the coupon grants free shipping. A free shipping method must be enabled in your shipping zone and be set to require "a valid free shipping coupon" (see the "Free Shipping Requires" setting).', 'woocommerce' ), 'https://docs.woocommerce.com/document/free-shipping/' ), + ) + ); } - // Expiry date + // Expiry date. $expiry_date = $coupon->get_date_expires() ? $coupon->get_date_expires()->date( 'Y-m-d' ) : ''; - woocommerce_wp_text_input( array( - 'id' => 'expiry_date', - 'value' => esc_attr( $expiry_date ), - 'label' => __( 'Coupon expiry date', 'woocommerce' ), - 'placeholder' => 'YYYY-MM-DD', - 'description' => '', - 'class' => 'date-picker', - 'custom_attributes' => array( - 'pattern' => apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ), - ), - ) ); + woocommerce_wp_text_input( + array( + 'id' => 'expiry_date', + 'value' => esc_attr( $expiry_date ), + 'label' => __( 'Coupon expiry date', 'woocommerce' ), + 'placeholder' => 'YYYY-MM-DD', + 'description' => '', + 'class' => 'date-picker', + 'custom_attributes' => array( + 'pattern' => apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ), + ), + ) + ); do_action( 'woocommerce_coupon_options', $coupon->get_id(), $coupon ); - ?>
      -
      +
      +
      + '; - // minimum spend - woocommerce_wp_text_input( array( - 'id' => 'minimum_amount', - 'label' => __( 'Minimum spend', 'woocommerce' ), - 'placeholder' => __( 'No minimum', 'woocommerce' ), - 'description' => __( 'This field allows you to set the minimum spend (subtotal) allowed to use the coupon.', 'woocommerce' ), - 'data_type' => 'price', - 'desc_tip' => true, - ) ); + // minimum spend. + woocommerce_wp_text_input( + array( + 'id' => 'minimum_amount', + 'label' => __( 'Minimum spend', 'woocommerce' ), + 'placeholder' => __( 'No minimum', 'woocommerce' ), + 'description' => __( 'This field allows you to set the minimum spend (subtotal) allowed to use the coupon.', 'woocommerce' ), + 'data_type' => 'price', + 'desc_tip' => true, + ) + ); - // maximum spend - woocommerce_wp_text_input( array( - 'id' => 'maximum_amount', - 'label' => __( 'Maximum spend', 'woocommerce' ), - 'placeholder' => __( 'No maximum', 'woocommerce' ), - 'description' => __( 'This field allows you to set the maximum spend (subtotal) allowed when using the coupon.', 'woocommerce' ), - 'data_type' => 'price', - 'desc_tip' => true, - ) ); + // maximum spend. + woocommerce_wp_text_input( + array( + 'id' => 'maximum_amount', + 'label' => __( 'Maximum spend', 'woocommerce' ), + 'placeholder' => __( 'No maximum', 'woocommerce' ), + 'description' => __( 'This field allows you to set the maximum spend (subtotal) allowed when using the coupon.', 'woocommerce' ), + 'data_type' => 'price', + 'desc_tip' => true, + ) + ); - // Individual use - woocommerce_wp_checkbox( array( - 'id' => 'individual_use', - 'label' => __( 'Individual use only', 'woocommerce' ), - 'description' => __( 'Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce' ), - ) ); + // Individual use. + woocommerce_wp_checkbox( + array( + 'id' => 'individual_use', + 'label' => __( 'Individual use only', 'woocommerce' ), + 'description' => __( 'Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce' ), + ) + ); - // Exclude Sale Products - woocommerce_wp_checkbox( array( - 'id' => 'exclude_sale_items', - 'label' => __( 'Exclude sale items', 'woocommerce' ), - 'description' => __( 'Check this box if the coupon should not apply to items on sale. Per-item coupons will only work if the item is not on sale. Per-cart coupons will only work if there are items in the cart that are not on sale.', 'woocommerce' ), - ) ); + // Exclude Sale Products. + woocommerce_wp_checkbox( + array( + 'id' => 'exclude_sale_items', + 'label' => __( 'Exclude sale items', 'woocommerce' ), + 'description' => __( 'Check this box if the coupon should not apply to items on sale. Per-item coupons will only work if the item is not on sale. Per-cart coupons will only work if there are items in the cart that are not on sale.', 'woocommerce' ), + ) + ); echo '
      '; - // Product ids + // Product ids. ?> -

      - + get_product_ids(); foreach ( $product_ids as $product_id ) { @@ -161,15 +187,16 @@ class WC_Meta_Box_Coupon_Data { echo ''; } } - ?> -

      - + + +

      - // Exclude Product ids - ?> -

      - + get_excluded_product_ids(); foreach ( $product_ids as $product_id ) { @@ -178,17 +205,20 @@ class WC_Meta_Box_Coupon_Data { echo ''; } } - ?> -

      + ?> + + +

      '; - // Categories + // Categories. ?> -

      - + get_product_categories(); $categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' ); @@ -197,15 +227,15 @@ class WC_Meta_Box_Coupon_Data { echo ''; } } - ?> -

      - + +

      - // Exclude Categories - ?> -

      - + get_excluded_product_categories(); $categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' ); @@ -214,89 +244,93 @@ class WC_Meta_Box_Coupon_Data { echo ''; } } - ?> -

      + ?> + + +

      +
      +
      '; 'customer_email', + 'label' => __( 'Email restrictions', 'woocommerce' ), + 'placeholder' => __( 'No restrictions', 'woocommerce' ), + 'description' => __( 'List of allowed emails to check against the customer billing email when an order is placed. Separate email addresses with commas.', 'woocommerce' ), + 'value' => implode( ', ', (array) $coupon->get_email_restrictions() ), + 'desc_tip' => true, + 'type' => 'email', + 'class' => '', + 'custom_attributes' => array( + 'multiple' => 'multiple', + ), + ) + ); + ?> +
      + get_id(), $coupon ); ?> +
      +
      +
      + 'usage_limit', + 'label' => __( 'Usage limit per coupon', 'woocommerce' ), + 'placeholder' => esc_attr__( 'Unlimited usage', 'woocommerce' ), + 'description' => __( 'How many times this coupon can be used before it is void.', 'woocommerce' ), + 'type' => 'number', + 'desc_tip' => true, + 'class' => 'short', + 'custom_attributes' => array( + 'step' => 1, + 'min' => 0, + ), + 'value' => $coupon->get_usage_limit() ? $coupon->get_usage_limit() : '', + ) + ); - echo '
      '; + // Usage limit per product. + woocommerce_wp_text_input( + array( + 'id' => 'limit_usage_to_x_items', + 'label' => __( 'Limit usage to X items', 'woocommerce' ), + 'placeholder' => esc_attr__( 'Apply to all qualifying items in cart', 'woocommerce' ), + 'description' => __( 'The maximum number of individual items this coupon can apply to when using product discounts. Leave blank to apply to all qualifying items in cart.', 'woocommerce' ), + 'desc_tip' => true, + 'class' => 'short', + 'type' => 'number', + 'custom_attributes' => array( + 'step' => 1, + 'min' => 0, + ), + 'value' => $coupon->get_limit_usage_to_x_items() ? $coupon->get_limit_usage_to_x_items() : '', + ) + ); - // Customers - woocommerce_wp_text_input( array( - 'id' => 'customer_email', - 'label' => __( 'Email restrictions', 'woocommerce' ), - 'placeholder' => __( 'No restrictions', 'woocommerce' ), - 'description' => __( 'List of allowed emails to check against the customer billing email when an order is placed. Separate email addresses with commas.', 'woocommerce' ), - 'value' => implode( ', ', (array) $coupon->get_email_restrictions() ), - 'desc_tip' => true, - 'type' => 'email', - 'class' => '', - 'custom_attributes' => array( - 'multiple' => 'multiple', - ), - ) ); - - echo '
      '; - - do_action( 'woocommerce_coupon_options_usage_restriction', $coupon->get_id(), $coupon ); - - ?>
      -
      '; - - // Usage limit per coupons - woocommerce_wp_text_input( array( - 'id' => 'usage_limit', - 'label' => __( 'Usage limit per coupon', 'woocommerce' ), - 'placeholder' => esc_attr__( 'Unlimited usage', 'woocommerce' ), - 'description' => __( 'How many times this coupon can be used before it is void.', 'woocommerce' ), - 'type' => 'number', - 'desc_tip' => true, - 'class' => 'short', - 'custom_attributes' => array( - 'step' => 1, - 'min' => 0, - ), - 'value' => $coupon->get_usage_limit() ? $coupon->get_usage_limit() : '', - ) ); - - // Usage limit per product - woocommerce_wp_text_input( array( - 'id' => 'limit_usage_to_x_items', - 'label' => __( 'Limit usage to X items', 'woocommerce' ), - 'placeholder' => esc_attr__( 'Apply to all qualifying items in cart', 'woocommerce' ), - 'description' => __( 'The maximum number of individual items this coupon can apply to when using product discounts. Leave blank to apply to all qualifying items in cart.', 'woocommerce' ), - 'desc_tip' => true, - 'class' => 'short', - 'type' => 'number', - 'custom_attributes' => array( - 'step' => 1, - 'min' => 0, - ), - 'value' => $coupon->get_limit_usage_to_x_items() ? $coupon->get_limit_usage_to_x_items() : '', - ) ); - - // Usage limit per users - woocommerce_wp_text_input( array( - 'id' => 'usage_limit_per_user', - 'label' => __( 'Usage limit per user', 'woocommerce' ), - 'placeholder' => esc_attr__( 'Unlimited usage', 'woocommerce' ), - 'description' => __( 'How many times this coupon can be used by an individual user. Uses billing email for guests, and user ID for logged in users.', 'woocommerce' ), - 'desc_tip' => true, - 'class' => 'short', - 'type' => 'number', - 'custom_attributes' => array( - 'step' => 1, - 'min' => 0, - ), - 'value' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : '', - ) ); - - echo '
      '; - - do_action( 'woocommerce_coupon_options_usage_limit', $coupon->get_id(), $coupon ); - - ?>
    + // Usage limit per users. + woocommerce_wp_text_input( + array( + 'id' => 'usage_limit_per_user', + 'label' => __( 'Usage limit per user', 'woocommerce' ), + 'placeholder' => esc_attr__( 'Unlimited usage', 'woocommerce' ), + 'description' => __( 'How many times this coupon can be used by an individual user. Uses billing email for guests, and user ID for logged in users.', 'woocommerce' ), + 'desc_tip' => true, + 'class' => 'short', + 'type' => 'number', + 'custom_attributes' => array( + 'step' => 1, + 'min' => 0, + ), + 'value' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : '', + ) + ); + ?> +
    + get_id(), $coupon ); ?> +
    get_id(), $coupon ); ?>
    @@ -306,11 +340,11 @@ class WC_Meta_Box_Coupon_Data { /** * Save meta box data. * - * @param int $post_id + * @param int $post_id * @param WP_Post $post */ public static function save( $post_id, $post ) { - // Check for dupe coupons + // Check for dupe coupons. $coupon_code = wc_format_coupon_code( $post->post_title ); $id_from_code = wc_get_coupon_id_by_code( $coupon_code, $post_id ); @@ -322,25 +356,27 @@ class WC_Meta_Box_Coupon_Data { $exclude_product_categories = isset( $_POST['exclude_product_categories'] ) ? (array) $_POST['exclude_product_categories'] : array(); $coupon = new WC_Coupon( $post_id ); - $coupon->set_props( array( - 'code' => $post->post_title, - 'discount_type' => wc_clean( $_POST['discount_type'] ), - 'amount' => wc_format_decimal( $_POST['coupon_amount'] ), - 'date_expires' => wc_clean( $_POST['expiry_date'] ), - 'individual_use' => isset( $_POST['individual_use'] ), - 'product_ids' => isset( $_POST['product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['product_ids'] ) ) : array(), - 'excluded_product_ids' => isset( $_POST['exclude_product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['exclude_product_ids'] ) ) : array(), - 'usage_limit' => absint( $_POST['usage_limit'] ), - 'usage_limit_per_user' => absint( $_POST['usage_limit_per_user'] ), - 'limit_usage_to_x_items' => absint( $_POST['limit_usage_to_x_items'] ), - 'free_shipping' => isset( $_POST['free_shipping'] ), - 'product_categories' => array_filter( array_map( 'intval', $product_categories ) ), - 'excluded_product_categories' => array_filter( array_map( 'intval', $exclude_product_categories ) ), - 'exclude_sale_items' => isset( $_POST['exclude_sale_items'] ), - 'minimum_amount' => wc_format_decimal( $_POST['minimum_amount'] ), - 'maximum_amount' => wc_format_decimal( $_POST['maximum_amount'] ), - 'email_restrictions' => array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) ), - ) ); + $coupon->set_props( + array( + 'code' => $post->post_title, + 'discount_type' => wc_clean( $_POST['discount_type'] ), + 'amount' => wc_format_decimal( $_POST['coupon_amount'] ), + 'date_expires' => wc_clean( $_POST['expiry_date'] ), + 'individual_use' => isset( $_POST['individual_use'] ), + 'product_ids' => isset( $_POST['product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['product_ids'] ) ) : array(), + 'excluded_product_ids' => isset( $_POST['exclude_product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['exclude_product_ids'] ) ) : array(), + 'usage_limit' => absint( $_POST['usage_limit'] ), + 'usage_limit_per_user' => absint( $_POST['usage_limit_per_user'] ), + 'limit_usage_to_x_items' => absint( $_POST['limit_usage_to_x_items'] ), + 'free_shipping' => isset( $_POST['free_shipping'] ), + 'product_categories' => array_filter( array_map( 'intval', $product_categories ) ), + 'excluded_product_categories' => array_filter( array_map( 'intval', $exclude_product_categories ) ), + 'exclude_sale_items' => isset( $_POST['exclude_sale_items'] ), + 'minimum_amount' => wc_format_decimal( $_POST['minimum_amount'] ), + 'maximum_amount' => wc_format_decimal( $_POST['maximum_amount'] ), + 'email_restrictions' => array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) ), + ) + ); $coupon->save(); do_action( 'woocommerce_coupon_options_save', $post_id, $coupon ); } diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php b/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php index 4a32bbed32b..c47eaa7af13 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php @@ -32,11 +32,13 @@ class WC_Meta_Box_Order_Actions { $theorder = wc_get_order( $post->ID ); } - $order_actions = apply_filters( 'woocommerce_order_actions', array( - 'send_order_details' => __( 'Email invoice / order details to customer', 'woocommerce' ), - 'send_order_details_admin' => __( 'Resend new order notification', 'woocommerce' ), - 'regenerate_download_permissions' => __( 'Regenerate download permissions', 'woocommerce' ), - ) ); + $order_actions = apply_filters( + 'woocommerce_order_actions', array( + 'send_order_details' => __( 'Email invoice / order details to customer', 'woocommerce' ), + 'send_order_details_admin' => __( 'Resend new order notification', 'woocommerce' ), + 'regenerate_download_permissions' => __( 'Regenerate download permissions', 'woocommerce' ), + ) + ); ?>
      @@ -62,7 +64,9 @@ class WC_Meta_Box_Order_Actions { } else { $delete_text = __( 'Move to trash', 'woocommerce' ); } - ?> + +
    diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-data.php b/includes/admin/meta-boxes/class-wc-meta-box-order-data.php index c242be95b11..f4fe56b0dcb 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-data.php @@ -4,9 +4,9 @@ * * Functions for displaying the order data meta box. * - * @author WooThemes - * @category Admin - * @package WooCommerce/Admin/Meta Boxes + * @author WooThemes + * @category Admin + * @package WooCommerce/Admin/Meta Boxes * @version 2.2.0 */ @@ -38,97 +38,101 @@ class WC_Meta_Box_Order_Data { */ public static function init_address_fields() { - self::$billing_fields = apply_filters( 'woocommerce_admin_billing_fields', array( - 'first_name' => array( - 'label' => __( 'First name', 'woocommerce' ), - 'show' => false, - ), - 'last_name' => array( - 'label' => __( 'Last name', 'woocommerce' ), - 'show' => false, - ), - 'company' => array( - 'label' => __( 'Company', 'woocommerce' ), - 'show' => false, - ), - 'address_1' => array( - 'label' => __( 'Address line 1', 'woocommerce' ), - 'show' => false, - ), - 'address_2' => array( - 'label' => __( 'Address line 2', 'woocommerce' ), - 'show' => false, - ), - 'city' => array( - 'label' => __( 'City', 'woocommerce' ), - 'show' => false, - ), - 'postcode' => array( - 'label' => __( 'Postcode / ZIP', 'woocommerce' ), - 'show' => false, - ), - 'country' => array( - 'label' => __( 'Country', 'woocommerce' ), - 'show' => false, - 'class' => 'js_field-country select short', - 'type' => 'select', - 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(), - ), - 'state' => array( - 'label' => __( 'State / County', 'woocommerce' ), - 'class' => 'js_field-state select short', - 'show' => false, - ), - 'email' => array( - 'label' => __( 'Email address', 'woocommerce' ), - ), - 'phone' => array( - 'label' => __( 'Phone', 'woocommerce' ), - ), - ) ); + self::$billing_fields = apply_filters( + 'woocommerce_admin_billing_fields', array( + 'first_name' => array( + 'label' => __( 'First name', 'woocommerce' ), + 'show' => false, + ), + 'last_name' => array( + 'label' => __( 'Last name', 'woocommerce' ), + 'show' => false, + ), + 'company' => array( + 'label' => __( 'Company', 'woocommerce' ), + 'show' => false, + ), + 'address_1' => array( + 'label' => __( 'Address line 1', 'woocommerce' ), + 'show' => false, + ), + 'address_2' => array( + 'label' => __( 'Address line 2', 'woocommerce' ), + 'show' => false, + ), + 'city' => array( + 'label' => __( 'City', 'woocommerce' ), + 'show' => false, + ), + 'postcode' => array( + 'label' => __( 'Postcode / ZIP', 'woocommerce' ), + 'show' => false, + ), + 'country' => array( + 'label' => __( 'Country', 'woocommerce' ), + 'show' => false, + 'class' => 'js_field-country select short', + 'type' => 'select', + 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(), + ), + 'state' => array( + 'label' => __( 'State / County', 'woocommerce' ), + 'class' => 'js_field-state select short', + 'show' => false, + ), + 'email' => array( + 'label' => __( 'Email address', 'woocommerce' ), + ), + 'phone' => array( + 'label' => __( 'Phone', 'woocommerce' ), + ), + ) + ); - self::$shipping_fields = apply_filters( 'woocommerce_admin_shipping_fields', array( - 'first_name' => array( - 'label' => __( 'First name', 'woocommerce' ), - 'show' => false, - ), - 'last_name' => array( - 'label' => __( 'Last name', 'woocommerce' ), - 'show' => false, - ), - 'company' => array( - 'label' => __( 'Company', 'woocommerce' ), - 'show' => false, - ), - 'address_1' => array( - 'label' => __( 'Address line 1', 'woocommerce' ), - 'show' => false, - ), - 'address_2' => array( - 'label' => __( 'Address line 2', 'woocommerce' ), - 'show' => false, - ), - 'city' => array( - 'label' => __( 'City', 'woocommerce' ), - 'show' => false, - ), - 'postcode' => array( - 'label' => __( 'Postcode / ZIP', 'woocommerce' ), - 'show' => false, - ), - 'country' => array( - 'label' => __( 'Country', 'woocommerce' ), - 'show' => false, - 'type' => 'select', - 'class' => 'js_field-country select short', - 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(), - ), - 'state' => array( - 'label' => __( 'State / County', 'woocommerce' ), - 'class' => 'js_field-state select short', - 'show' => false, - ), - ) ); + self::$shipping_fields = apply_filters( + 'woocommerce_admin_shipping_fields', array( + 'first_name' => array( + 'label' => __( 'First name', 'woocommerce' ), + 'show' => false, + ), + 'last_name' => array( + 'label' => __( 'Last name', 'woocommerce' ), + 'show' => false, + ), + 'company' => array( + 'label' => __( 'Company', 'woocommerce' ), + 'show' => false, + ), + 'address_1' => array( + 'label' => __( 'Address line 1', 'woocommerce' ), + 'show' => false, + ), + 'address_2' => array( + 'label' => __( 'Address line 2', 'woocommerce' ), + 'show' => false, + ), + 'city' => array( + 'label' => __( 'City', 'woocommerce' ), + 'show' => false, + ), + 'postcode' => array( + 'label' => __( 'Postcode / ZIP', 'woocommerce' ), + 'show' => false, + ), + 'country' => array( + 'label' => __( 'Country', 'woocommerce' ), + 'show' => false, + 'type' => 'select', + 'class' => 'js_field-country select short', + 'options' => array( '' => __( 'Select a country…', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(), + ), + 'state' => array( + 'label' => __( 'State / County', 'woocommerce' ), + 'class' => 'js_field-state select short', + 'show' => false, + ), + ) + ); } /** @@ -165,113 +169,128 @@ class WC_Meta_Box_Order_Data {
    -

    + labels->singular_name ), - esc_html( $order->get_order_number() ) - ); - - ?>

    -

    get_title() : $payment_method ) + /* translators: 1: order type 2: order number */ + printf( + esc_html__( '%1$s #%2$s details', 'woocommerce' ), + esc_html( $order_type_object->labels->singular_name ), + esc_html( $order->get_order_number() ) ); - if ( $transaction_id = $order->get_transaction_id() ) { - if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order ) ) ) { - $payment_method_string .= ' (' . esc_html( $transaction_id ) . ')'; - } else { - $payment_method_string .= ' (' . esc_html( $transaction_id ) . ')'; + ?> + +

    + get_title() : $payment_method ) + ); + + if ( $transaction_id = $order->get_transaction_id() ) { + if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order ) ) ) { + $payment_method_string .= ' (' . esc_html( $transaction_id ) . ')'; + } else { + $payment_method_string .= ' (' . esc_html( $transaction_id ) . ')'; + } } + + $meta_list[] = $payment_method_string; } - $meta_list[] = $payment_method_string; - } + if ( $order->get_date_paid() ) { + /* translators: 1: date 2: time */ + $meta_list[] = sprintf( + __( 'Paid on %1$s @ %2$s', 'woocommerce' ), + wc_format_datetime( $order->get_date_paid() ), + wc_format_datetime( $order->get_date_paid(), get_option( 'time_format' ) ) + ); + } - if ( $order->get_date_paid() ) { - /* translators: 1: date 2: time */ - $meta_list[] = sprintf( - __( 'Paid on %1$s @ %2$s', 'woocommerce' ), - wc_format_datetime( $order->get_date_paid() ), - wc_format_datetime( $order->get_date_paid(), get_option( 'time_format' ) ) - ); - } + if ( $ip_address = $order->get_customer_ip_address() ) { + /* translators: %s: IP address */ + $meta_list[] = sprintf( + __( 'Customer IP: %s', 'woocommerce' ), + '' . esc_html( $ip_address ) . '' + ); + } - if ( $ip_address = $order->get_customer_ip_address() ) { - /* translators: %s: IP address */ - $meta_list[] = sprintf( - __( 'Customer IP: %s', 'woocommerce' ), - '' . esc_html( $ip_address ) . '' - ); - } + echo wp_kses_post( implode( '. ', $meta_list ) ); - echo wp_kses_post( implode( '. ', $meta_list ) ); - - ?>

    + ?> +

    -

    +

    + @ ‎ - : - + : + - ‎

    -

    - + $status_name ) { echo ''; } - ?> -

    + ?> + +

    - + ?> + get_user_id() ) { - $user_id = absint( $order->get_user_id() ); - $user = get_user_by( 'id', $user_id ); + $user_id = absint( $order->get_user_id() ); + $user = get_user_by( 'id', $user_id ); /* translators: 1: user display name 2: user ID 3: user email */ $user_string = sprintf( esc_html__( '%1$s (#%2$s – %3$s)', 'woocommerce' ), @@ -296,43 +315,44 @@ class WC_Meta_Box_Order_Data { - '; +

    + get_formatted_billing_address() ) { - echo '

    ' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '

    '; + // Display values. + if ( $order->get_formatted_billing_address() ) { + echo '

    ' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '

    '; + } else { + echo '

    ' . __( 'Address:', 'woocommerce' ) . ' ' . __( 'No billing address set.', 'woocommerce' ) . '

    '; + } + + foreach ( self::$billing_fields as $key => $field ) { + if ( isset( $field['show'] ) && false === $field['show'] ) { + continue; + } + + $field_name = 'billing_' . $key; + + if ( is_callable( array( $order, 'get_' . $field_name ) ) ) { + $field_value = $order->{"get_$field_name"}( 'edit' ); } else { - echo '

    ' . __( 'Address:', 'woocommerce' ) . ' ' . __( 'No billing address set.', 'woocommerce' ) . '

    '; + $field_value = $order->get_meta( '_' . $field_name ); } - foreach ( self::$billing_fields as $key => $field ) { - if ( isset( $field['show'] ) && false === $field['show'] ) { - continue; - } - - $field_name = 'billing_' . $key; - - if ( is_callable( array( $order, 'get_' . $field_name ) ) ) { - $field_value = $order->{"get_$field_name"}( 'edit' ); - } else { - $field_value = $order->get_meta( '_' . $field_name ); - } - - if ( 'billing_phone' === $field_name ) { - $field_value = wc_make_phone_clickable( $field_value ); - } else { - $field_value = make_clickable( esc_html( $field_value ) ); - } - - echo '

    ' . esc_html( $field['label'] ) . ': ' . wp_kses_post( $field_value ) . '

    '; + if ( 'billing_phone' === $field_name ) { + $field_value = wc_make_phone_clickable( $field_value ); + } else { + $field_value = make_clickable( esc_html( $field_value ) ); } - echo '
    '; + echo '

    ' . esc_html( $field['label'] ) . ': ' . wp_kses_post( $field_value ) . '

    '; + } + ?> +
    - // Display form - echo '
    '; +
    + $field ) { if ( ! isset( $field['type'] ) ) { $field['type'] = 'text'; @@ -341,12 +361,12 @@ class WC_Meta_Box_Order_Data { $field['id'] = '_billing_' . $key; } switch ( $field['type'] ) { - case 'select' : + case 'select': woocommerce_wp_select( $field ); - break; - default : + break; + default: woocommerce_wp_text_input( $field ); - break; + break; } } ?> @@ -355,36 +375,39 @@ class WC_Meta_Box_Order_Data {

    '_transaction_id', 'label' => __( 'Transaction ID', 'woocommerce' ) ) ); + woocommerce_wp_text_input( + array( + 'id' => '_transaction_id', + 'label' => __( 'Transaction ID', 'woocommerce' ), + ) + ); + ?> - echo '
    '; - - do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); - ?> +
    +
    -

    @@ -393,43 +416,43 @@ class WC_Meta_Box_Order_Data {

    - '; +
    + get_formatted_shipping_address() ) { - echo '

    ' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '

    '; - } else { - echo '

    ' . __( 'Address:', 'woocommerce' ) . ' ' . __( 'No shipping address set.', 'woocommerce' ) . '

    '; - } + // Display values. + if ( $order->get_formatted_shipping_address() ) { + echo '

    ' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '

    '; + } else { + echo '

    ' . __( 'Address:', 'woocommerce' ) . ' ' . __( 'No shipping address set.', 'woocommerce' ) . '

    '; + } - if ( ! empty( self::$shipping_fields ) ) { - foreach ( self::$shipping_fields as $key => $field ) { - if ( isset( $field['show'] ) && false === $field['show'] ) { - continue; - } - - $field_name = 'shipping_' . $key; - - if ( is_callable( array( $order, 'get_' . $field_name ) ) ) { - $field_value = $order->{"get_$field_name"}( 'edit' ); - } else { - $field_value = $order->get_meta( '_' . $field_name ); - } - - echo '

    ' . esc_html( $field['label'] ) . ': ' . make_clickable( esc_html( $field_value ) ) . '

    '; + if ( ! empty( self::$shipping_fields ) ) { + foreach ( self::$shipping_fields as $key => $field ) { + if ( isset( $field['show'] ) && false === $field['show'] ) { + continue; } + + $field_name = 'shipping_' . $key; + + if ( is_callable( array( $order, 'get_' . $field_name ) ) ) { + $field_value = $order->{"get_$field_name"}( 'edit' ); + } else { + $field_value = $order->get_meta( '_' . $field_name ); + } + + echo '

    ' . esc_html( $field['label'] ) . ': ' . make_clickable( esc_html( $field_value ) ) . '

    '; } + } - if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) { - echo '

    ' . __( 'Customer provided note:', 'woocommerce' ) . ' ' . nl2br( esc_html( $post->post_excerpt ) ) . '

    '; - } - - echo '
    '; - - // Display form - echo '
    '; + if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) { + echo '

    ' . __( 'Customer provided note:', 'woocommerce' ) . ' ' . nl2br( esc_html( $post->post_excerpt ) ) . '

    '; + } + ?> +
    +
    + $field ) { if ( ! isset( $field['type'] ) ) { @@ -440,27 +463,26 @@ class WC_Meta_Box_Order_Data { } switch ( $field['type'] ) { - case 'select' : + case 'select': woocommerce_wp_select( $field ); - break; - default : + break; + default: woocommerce_wp_text_input( $field ); - break; + break; } } } - if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) { + if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) : ?> -

    -

    - + + +

    + +
    - echo '
    '; - - do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); - ?> +
    @@ -548,7 +570,7 @@ class WC_Meta_Box_Order_Data { $payment_method_title = $methods[ $payment_method ]->get_title(); } - $props['payment_method'] = $payment_method; + $props['payment_method'] = $payment_method; $props['payment_method_title'] = $payment_method_title; } diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php b/includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php index 062fe512cad..897842500c0 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-downloads.php @@ -26,12 +26,15 @@ class WC_Meta_Box_Order_Downloads { ?>
    -
    get_downloads( array( - 'order_id' => $post->ID, - 'orderby' => 'product_id', - ) ); +
    + get_downloads( + array( + 'order_id' => $post->ID, + 'orderby' => 'product_id', + ) + ); $product = null; $loop = 0; @@ -44,27 +47,30 @@ class WC_Meta_Box_Order_Downloads { $file_counter = 1; } - // don't show permissions to files that have since been removed + // don't show permissions to files that have since been removed. if ( ! $product || ! $product->exists() || ! $product->has_file( $download->get_download_id() ) ) { continue; } - // Show file title instead of count if set + // Show file title instead of count if set. $file = $product->get_file( $download->get_download_id() ); $file_count = isset( $file['name'] ) ? $file['name'] : sprintf( __( 'File %d', 'woocommerce' ), $file_counter ); - include( 'views/html-order-download-permission.php' ); + include 'views/html-order-download-permission.php'; $loop++; $file_counter++; } } - ?>
    + ?> +

    - +

    @@ -76,7 +82,7 @@ class WC_Meta_Box_Order_Downloads { /** * Save meta box data. * - * @param int $post_id + * @param int $post_id * @param WP_Post $post */ public static function save( $post_id, $post ) { diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-items.php b/includes/admin/meta-boxes/class-wc-meta-box-order-items.php index a8d83a6bfda..a70bea86889 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-items.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-items.php @@ -38,7 +38,7 @@ class WC_Meta_Box_Order_Items { $order = $theorder; $data = get_post_meta( $post->ID ); - include( 'views/html-order-items.php' ); + include 'views/html-order-items.php'; } /** diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-data.php b/includes/admin/meta-boxes/class-wc-meta-box-product-data.php index bef86bcce14..18d0d7aa99a 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-data.php @@ -28,11 +28,11 @@ class WC_Meta_Box_Product_Data { global $thepostid, $product_object; $thepostid = $post->ID; - $product_object = $thepostid ? wc_get_product( $thepostid ) : new WC_Product; + $product_object = $thepostid ? wc_get_product( $thepostid ) : new WC_Product(); wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); - include( 'views/html-product-data-panel.php' ); + include 'views/html-product-data-panel.php'; } /** @@ -41,86 +41,92 @@ class WC_Meta_Box_Product_Data { private static function output_tabs() { global $post, $thepostid, $product_object; - include( 'views/html-product-data-general.php' ); - include( 'views/html-product-data-inventory.php' ); - include( 'views/html-product-data-shipping.php' ); - include( 'views/html-product-data-linked-products.php' ); - include( 'views/html-product-data-attributes.php' ); - include( 'views/html-product-data-advanced.php' ); + include 'views/html-product-data-general.php'; + include 'views/html-product-data-inventory.php'; + include 'views/html-product-data-shipping.php'; + include 'views/html-product-data-linked-products.php'; + include 'views/html-product-data-attributes.php'; + include 'views/html-product-data-advanced.php'; } /** * Return array of product type options. + * * @return array */ private static function get_product_type_options() { - return apply_filters( 'product_type_options', array( - 'virtual' => array( - 'id' => '_virtual', - 'wrapper_class' => 'show_if_simple', - 'label' => __( 'Virtual', 'woocommerce' ), - 'description' => __( 'Virtual products are intangible and are not shipped.', 'woocommerce' ), - 'default' => 'no', - ), - 'downloadable' => array( - 'id' => '_downloadable', - 'wrapper_class' => 'show_if_simple', - 'label' => __( 'Downloadable', 'woocommerce' ), - 'description' => __( 'Downloadable products give access to a file upon purchase.', 'woocommerce' ), - 'default' => 'no', - ), - ) ); + return apply_filters( + 'product_type_options', array( + 'virtual' => array( + 'id' => '_virtual', + 'wrapper_class' => 'show_if_simple', + 'label' => __( 'Virtual', 'woocommerce' ), + 'description' => __( 'Virtual products are intangible and are not shipped.', 'woocommerce' ), + 'default' => 'no', + ), + 'downloadable' => array( + 'id' => '_downloadable', + 'wrapper_class' => 'show_if_simple', + 'label' => __( 'Downloadable', 'woocommerce' ), + 'description' => __( 'Downloadable products give access to a file upon purchase.', 'woocommerce' ), + 'default' => 'no', + ), + ) + ); } /** * Return array of tabs to show. + * * @return array */ private static function get_product_data_tabs() { - $tabs = apply_filters( 'woocommerce_product_data_tabs', array( - 'general' => array( - 'label' => __( 'General', 'woocommerce' ), - 'target' => 'general_product_data', - 'class' => array( 'hide_if_grouped' ), - 'priority' => 10, - ), - 'inventory' => array( - 'label' => __( 'Inventory', 'woocommerce' ), - 'target' => 'inventory_product_data', - 'class' => array( 'show_if_simple', 'show_if_variable', 'show_if_grouped', 'show_if_external' ), - 'priority' => 20, - ), - 'shipping' => array( - 'label' => __( 'Shipping', 'woocommerce' ), - 'target' => 'shipping_product_data', - 'class' => array( 'hide_if_virtual', 'hide_if_grouped', 'hide_if_external' ), - 'priority' => 30, - ), - 'linked_product' => array( - 'label' => __( 'Linked Products', 'woocommerce' ), - 'target' => 'linked_product_data', - 'class' => array(), - 'priority' => 40, - ), - 'attribute' => array( - 'label' => __( 'Attributes', 'woocommerce' ), - 'target' => 'product_attributes', - 'class' => array(), - 'priority' => 50, - ), - 'variations' => array( - 'label' => __( 'Variations', 'woocommerce' ), - 'target' => 'variable_product_options', - 'class' => array( 'variations_tab', 'show_if_variable' ), - 'priority' => 60, - ), - 'advanced' => array( - 'label' => __( 'Advanced', 'woocommerce' ), - 'target' => 'advanced_product_data', - 'class' => array(), - 'priority' => 70, - ), - ) ); + $tabs = apply_filters( + 'woocommerce_product_data_tabs', array( + 'general' => array( + 'label' => __( 'General', 'woocommerce' ), + 'target' => 'general_product_data', + 'class' => array( 'hide_if_grouped' ), + 'priority' => 10, + ), + 'inventory' => array( + 'label' => __( 'Inventory', 'woocommerce' ), + 'target' => 'inventory_product_data', + 'class' => array( 'show_if_simple', 'show_if_variable', 'show_if_grouped', 'show_if_external' ), + 'priority' => 20, + ), + 'shipping' => array( + 'label' => __( 'Shipping', 'woocommerce' ), + 'target' => 'shipping_product_data', + 'class' => array( 'hide_if_virtual', 'hide_if_grouped', 'hide_if_external' ), + 'priority' => 30, + ), + 'linked_product' => array( + 'label' => __( 'Linked Products', 'woocommerce' ), + 'target' => 'linked_product_data', + 'class' => array(), + 'priority' => 40, + ), + 'attribute' => array( + 'label' => __( 'Attributes', 'woocommerce' ), + 'target' => 'product_attributes', + 'class' => array(), + 'priority' => 50, + ), + 'variations' => array( + 'label' => __( 'Variations', 'woocommerce' ), + 'target' => 'variable_product_options', + 'class' => array( 'variations_tab', 'show_if_variable' ), + 'priority' => 60, + ), + 'advanced' => array( + 'label' => __( 'Advanced', 'woocommerce' ), + 'target' => 'advanced_product_data', + 'class' => array(), + 'priority' => 70, + ), + ) + ); // Sort tabs based on priority. uasort( $tabs, array( __CLASS__, 'product_data_tabs_sort' ) ); @@ -151,6 +157,7 @@ class WC_Meta_Box_Product_Data { /** * Filter callback for finding variation attributes. + * * @param WC_Product_Attribute $attribute * @return bool */ @@ -170,7 +177,7 @@ class WC_Meta_Box_Product_Data { $variations_per_page = absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) ); $variations_total_pages = ceil( $variations_count / $variations_per_page ); - include( 'views/html-product-data-variations.php' ); + include 'views/html-product-data-variations.php'; } /** @@ -191,9 +198,9 @@ class WC_Meta_Box_Product_Data { for ( $i = 0; $i < $file_url_size; $i ++ ) { if ( ! empty( $file_urls[ $i ] ) ) { $downloads[] = array( - 'name' => wc_clean( $file_names[ $i ] ), - 'file' => wp_unslash( trim( $file_urls[ $i ] ) ), - 'download_id' => wc_clean( $file_hashes[ $i ] ), + 'name' => wc_clean( $file_names[ $i ] ), + 'file' => wp_unslash( trim( $file_urls[ $i ] ) ), + 'download_id' => wc_clean( $file_hashes[ $i ] ), ); } } @@ -203,6 +210,7 @@ class WC_Meta_Box_Product_Data { /** * Prepare children for save. + * * @return array */ private static function prepare_children() { @@ -272,9 +280,10 @@ class WC_Meta_Box_Product_Data { /** * Prepare attributes for a specific variation or defaults. - * @param array $all_attributes + * + * @param array $all_attributes * @param string $key_prefix - * @param int $index + * @param int $index * @return array */ private static function prepare_set_attributes( $all_attributes, $key_prefix = 'attribute_', $index = null ) { @@ -309,7 +318,7 @@ class WC_Meta_Box_Product_Data { /** * Save meta box data. * - * @param int $post_id + * @param int $post_id * @param $post */ public static function save( $post_id, $post ) { @@ -330,45 +339,47 @@ class WC_Meta_Box_Product_Data { } } - $errors = $product->set_props( array( - 'sku' => isset( $_POST['_sku'] ) ? wc_clean( $_POST['_sku'] ) : null, - 'purchase_note' => wp_kses_post( stripslashes( $_POST['_purchase_note'] ) ), - 'downloadable' => isset( $_POST['_downloadable'] ), - 'virtual' => isset( $_POST['_virtual'] ), - 'featured' => isset( $_POST['_featured'] ), - 'catalog_visibility' => wc_clean( $_POST['_visibility'] ), - 'tax_status' => isset( $_POST['_tax_status'] ) ? wc_clean( $_POST['_tax_status'] ) : null, - 'tax_class' => isset( $_POST['_tax_class'] ) ? wc_clean( $_POST['_tax_class'] ) : null, - 'weight' => wc_clean( $_POST['_weight'] ), - 'length' => wc_clean( $_POST['_length'] ), - 'width' => wc_clean( $_POST['_width'] ), - 'height' => wc_clean( $_POST['_height'] ), - 'shipping_class_id' => absint( $_POST['product_shipping_class'] ), - 'sold_individually' => ! empty( $_POST['_sold_individually'] ), - 'upsell_ids' => isset( $_POST['upsell_ids'] ) ? array_map( 'intval', (array) $_POST['upsell_ids'] ) : array(), - 'cross_sell_ids' => isset( $_POST['crosssell_ids'] ) ? array_map( 'intval', (array) $_POST['crosssell_ids'] ) : array(), - 'regular_price' => wc_clean( $_POST['_regular_price'] ), - 'sale_price' => wc_clean( $_POST['_sale_price'] ), - 'date_on_sale_from' => wc_clean( $_POST['_sale_price_dates_from'] ), - 'date_on_sale_to' => wc_clean( $_POST['_sale_price_dates_to'] ), - 'manage_stock' => ! empty( $_POST['_manage_stock'] ), - 'backorders' => isset( $_POST['_backorders'] ) ? wc_clean( $_POST['_backorders'] ) : null, - 'stock_status' => wc_clean( $_POST['_stock_status'] ), - 'stock_quantity' => $stock, - 'download_limit' => '' === $_POST['_download_limit'] ? '' : absint( $_POST['_download_limit'] ), - 'download_expiry' => '' === $_POST['_download_expiry'] ? '' : absint( $_POST['_download_expiry'] ), - 'downloads' => self::prepare_downloads( - isset( $_POST['_wc_file_names'] ) ? $_POST['_wc_file_names'] : array(), - isset( $_POST['_wc_file_urls'] ) ? $_POST['_wc_file_urls'] : array(), - isset( $_POST['_wc_file_hashes'] ) ? $_POST['_wc_file_hashes'] : array() - ), - 'product_url' => esc_url_raw( $_POST['_product_url'] ), - 'button_text' => wc_clean( $_POST['_button_text'] ), - 'children' => 'grouped' === $product_type ? self::prepare_children() : null, - 'reviews_allowed' => ! empty( $_POST['comment_status'] ) && 'open' === $_POST['comment_status'], - 'attributes' => $attributes, - 'default_attributes' => self::prepare_set_attributes( $attributes, 'default_attribute_' ), - ) ); + $errors = $product->set_props( + array( + 'sku' => isset( $_POST['_sku'] ) ? wc_clean( $_POST['_sku'] ) : null, + 'purchase_note' => wp_kses_post( stripslashes( $_POST['_purchase_note'] ) ), + 'downloadable' => isset( $_POST['_downloadable'] ), + 'virtual' => isset( $_POST['_virtual'] ), + 'featured' => isset( $_POST['_featured'] ), + 'catalog_visibility' => wc_clean( $_POST['_visibility'] ), + 'tax_status' => isset( $_POST['_tax_status'] ) ? wc_clean( $_POST['_tax_status'] ) : null, + 'tax_class' => isset( $_POST['_tax_class'] ) ? wc_clean( $_POST['_tax_class'] ) : null, + 'weight' => wc_clean( $_POST['_weight'] ), + 'length' => wc_clean( $_POST['_length'] ), + 'width' => wc_clean( $_POST['_width'] ), + 'height' => wc_clean( $_POST['_height'] ), + 'shipping_class_id' => absint( $_POST['product_shipping_class'] ), + 'sold_individually' => ! empty( $_POST['_sold_individually'] ), + 'upsell_ids' => isset( $_POST['upsell_ids'] ) ? array_map( 'intval', (array) $_POST['upsell_ids'] ) : array(), + 'cross_sell_ids' => isset( $_POST['crosssell_ids'] ) ? array_map( 'intval', (array) $_POST['crosssell_ids'] ) : array(), + 'regular_price' => wc_clean( $_POST['_regular_price'] ), + 'sale_price' => wc_clean( $_POST['_sale_price'] ), + 'date_on_sale_from' => wc_clean( $_POST['_sale_price_dates_from'] ), + 'date_on_sale_to' => wc_clean( $_POST['_sale_price_dates_to'] ), + 'manage_stock' => ! empty( $_POST['_manage_stock'] ), + 'backorders' => isset( $_POST['_backorders'] ) ? wc_clean( $_POST['_backorders'] ) : null, + 'stock_status' => wc_clean( $_POST['_stock_status'] ), + 'stock_quantity' => $stock, + 'download_limit' => '' === $_POST['_download_limit'] ? '' : absint( $_POST['_download_limit'] ), + 'download_expiry' => '' === $_POST['_download_expiry'] ? '' : absint( $_POST['_download_expiry'] ), + 'downloads' => self::prepare_downloads( + isset( $_POST['_wc_file_names'] ) ? $_POST['_wc_file_names'] : array(), + isset( $_POST['_wc_file_urls'] ) ? $_POST['_wc_file_urls'] : array(), + isset( $_POST['_wc_file_hashes'] ) ? $_POST['_wc_file_hashes'] : array() + ), + 'product_url' => esc_url_raw( $_POST['_product_url'] ), + 'button_text' => wc_clean( $_POST['_button_text'] ), + 'children' => 'grouped' === $product_type ? self::prepare_children() : null, + 'reviews_allowed' => ! empty( $_POST['comment_status'] ) && 'open' === $_POST['comment_status'], + 'attributes' => $attributes, + 'default_attributes' => self::prepare_set_attributes( $attributes, 'default_attribute_' ), + ) + ); if ( is_wp_error( $errors ) ) { WC_Admin_Meta_Boxes::add_error( $errors->get_error_message() ); @@ -391,12 +402,12 @@ class WC_Meta_Box_Product_Data { /** * Save meta box data. * - * @param int $post_id + * @param int $post_id * @param WP_Post $post */ public static function save_variations( $post_id, $post ) { if ( isset( $_POST['variable_post_id'] ) ) { - $parent = wc_get_product( $post_id ); + $parent = wc_get_product( $post_id ); $parent->set_default_attributes( self::prepare_set_attributes( $parent->get_attributes(), 'default_attribute_' ) ); $parent->save(); @@ -423,37 +434,39 @@ class WC_Meta_Box_Product_Data { } } - $errors = $variation->set_props( array( - 'status' => isset( $_POST['variable_enabled'][ $i ] ) ? 'publish' : 'private', - 'menu_order' => wc_clean( $_POST['variation_menu_order'][ $i ] ), - 'regular_price' => wc_clean( $_POST['variable_regular_price'][ $i ] ), - 'sale_price' => wc_clean( $_POST['variable_sale_price'][ $i ] ), - 'virtual' => isset( $_POST['variable_is_virtual'][ $i ] ), - 'downloadable' => isset( $_POST['variable_is_downloadable'][ $i ] ), - 'date_on_sale_from' => wc_clean( $_POST['variable_sale_price_dates_from'][ $i ] ), - 'date_on_sale_to' => wc_clean( $_POST['variable_sale_price_dates_to'][ $i ] ), - 'description' => wp_kses_post( $_POST['variable_description'][ $i ] ), - 'download_limit' => wc_clean( $_POST['variable_download_limit'][ $i ] ), - 'download_expiry' => wc_clean( $_POST['variable_download_expiry'][ $i ] ), - 'downloads' => self::prepare_downloads( - isset( $_POST['_wc_variation_file_names'][ $variation_id ] ) ? $_POST['_wc_variation_file_names'][ $variation_id ] : array(), - isset( $_POST['_wc_variation_file_urls'][ $variation_id ] ) ? $_POST['_wc_variation_file_urls'][ $variation_id ] : array(), - isset( $_POST['_wc_variation_file_hashes'][ $variation_id ] ) ? $_POST['_wc_variation_file_hashes'][ $variation_id ] : array() - ), - 'manage_stock' => isset( $_POST['variable_manage_stock'][ $i ] ), - 'stock_quantity' => $stock, - 'backorders' => isset( $_POST['variable_backorders'], $_POST['variable_backorders'][ $i ] ) ? wc_clean( $_POST['variable_backorders'][ $i ] ) : null, - 'stock_status' => wc_clean( $_POST['variable_stock_status'][ $i ] ), - 'image_id' => wc_clean( $_POST['upload_image_id'][ $i ] ), - 'attributes' => self::prepare_set_attributes( $parent->get_attributes(), 'attribute_', $i ), - 'sku' => isset( $_POST['variable_sku'][ $i ] ) ? wc_clean( $_POST['variable_sku'][ $i ] ) : '', - 'weight' => isset( $_POST['variable_weight'][ $i ] ) ? wc_clean( $_POST['variable_weight'][ $i ] ) : '', - 'length' => isset( $_POST['variable_length'][ $i ] ) ? wc_clean( $_POST['variable_length'][ $i ] ) : '', - 'width' => isset( $_POST['variable_width'][ $i ] ) ? wc_clean( $_POST['variable_width'][ $i ] ) : '', - 'height' => isset( $_POST['variable_height'][ $i ] ) ? wc_clean( $_POST['variable_height'][ $i ] ) : '', - 'shipping_class_id' => wc_clean( $_POST['variable_shipping_class'][ $i ] ), - 'tax_class' => isset( $_POST['variable_tax_class'][ $i ] ) ? wc_clean( $_POST['variable_tax_class'][ $i ] ) : null, - ) ); + $errors = $variation->set_props( + array( + 'status' => isset( $_POST['variable_enabled'][ $i ] ) ? 'publish' : 'private', + 'menu_order' => wc_clean( $_POST['variation_menu_order'][ $i ] ), + 'regular_price' => wc_clean( $_POST['variable_regular_price'][ $i ] ), + 'sale_price' => wc_clean( $_POST['variable_sale_price'][ $i ] ), + 'virtual' => isset( $_POST['variable_is_virtual'][ $i ] ), + 'downloadable' => isset( $_POST['variable_is_downloadable'][ $i ] ), + 'date_on_sale_from' => wc_clean( $_POST['variable_sale_price_dates_from'][ $i ] ), + 'date_on_sale_to' => wc_clean( $_POST['variable_sale_price_dates_to'][ $i ] ), + 'description' => wp_kses_post( $_POST['variable_description'][ $i ] ), + 'download_limit' => wc_clean( $_POST['variable_download_limit'][ $i ] ), + 'download_expiry' => wc_clean( $_POST['variable_download_expiry'][ $i ] ), + 'downloads' => self::prepare_downloads( + isset( $_POST['_wc_variation_file_names'][ $variation_id ] ) ? $_POST['_wc_variation_file_names'][ $variation_id ] : array(), + isset( $_POST['_wc_variation_file_urls'][ $variation_id ] ) ? $_POST['_wc_variation_file_urls'][ $variation_id ] : array(), + isset( $_POST['_wc_variation_file_hashes'][ $variation_id ] ) ? $_POST['_wc_variation_file_hashes'][ $variation_id ] : array() + ), + 'manage_stock' => isset( $_POST['variable_manage_stock'][ $i ] ), + 'stock_quantity' => $stock, + 'backorders' => isset( $_POST['variable_backorders'], $_POST['variable_backorders'][ $i ] ) ? wc_clean( $_POST['variable_backorders'][ $i ] ) : null, + 'stock_status' => wc_clean( $_POST['variable_stock_status'][ $i ] ), + 'image_id' => wc_clean( $_POST['upload_image_id'][ $i ] ), + 'attributes' => self::prepare_set_attributes( $parent->get_attributes(), 'attribute_', $i ), + 'sku' => isset( $_POST['variable_sku'][ $i ] ) ? wc_clean( $_POST['variable_sku'][ $i ] ) : '', + 'weight' => isset( $_POST['variable_weight'][ $i ] ) ? wc_clean( $_POST['variable_weight'][ $i ] ) : '', + 'length' => isset( $_POST['variable_length'][ $i ] ) ? wc_clean( $_POST['variable_length'][ $i ] ) : '', + 'width' => isset( $_POST['variable_width'][ $i ] ) ? wc_clean( $_POST['variable_width'][ $i ] ) : '', + 'height' => isset( $_POST['variable_height'][ $i ] ) ? wc_clean( $_POST['variable_height'][ $i ] ) : '', + 'shipping_class_id' => wc_clean( $_POST['variable_shipping_class'][ $i ] ), + 'tax_class' => isset( $_POST['variable_tax_class'][ $i ] ) ? wc_clean( $_POST['variable_tax_class'][ $i ] ) : null, + ) + ); if ( is_wp_error( $errors ) ) { WC_Admin_Meta_Boxes::add_error( $errors->get_error_message() ); diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-images.php b/includes/admin/meta-boxes/class-wc-meta-box-product-images.php index 2790a3e4343..62639e9f43b 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-images.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-images.php @@ -28,48 +28,48 @@ class WC_Meta_Box_Product_Images { global $thepostid, $product_object; $thepostid = $post->ID; - $product_object = $thepostid ? wc_get_product( $thepostid ) : new WC_Product; + $product_object = $thepostid ? wc_get_product( $thepostid ) : new WC_Product(); wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); ?>
      get_gallery_image_ids( 'edit' ); + $product_image_gallery = $product_object->get_gallery_image_ids( 'edit' ); - $attachments = array_filter( $product_image_gallery ); - $update_meta = false; - $updated_gallery_ids = array(); + $attachments = array_filter( $product_image_gallery ); + $update_meta = false; + $updated_gallery_ids = array(); - if ( ! empty( $attachments ) ) { - foreach ( $attachments as $attachment_id ) { - $attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' ); + if ( ! empty( $attachments ) ) { + foreach ( $attachments as $attachment_id ) { + $attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' ); - // if attachment is empty skip - if ( empty( $attachment ) ) { - $update_meta = true; - continue; - } + // if attachment is empty skip. + if ( empty( $attachment ) ) { + $update_meta = true; + continue; + } - echo '
    • + echo '
    • ' . $attachment . '
    • '; - // rebuild ids to be saved - $updated_gallery_ids[] = $attachment_id; - } - - // need to update product meta to set new gallery ids - if ( $update_meta ) { - update_post_meta( $post->ID, '_product_image_gallery', implode( ',', $updated_gallery_ids ) ); - } + // rebuild ids to be saved. + $updated_gallery_ids[] = $attachment_id; } + + // need to update product meta to set new gallery ids + if ( $update_meta ) { + update_post_meta( $post->ID, '_product_image_gallery', implode( ',', $updated_gallery_ids ) ); + } + } ?>
    - +

    @@ -81,7 +81,7 @@ class WC_Meta_Box_Product_Images { /** * Save meta box data. * - * @param int $post_id + * @param int $post_id * @param WP_Post $post */ public static function save( $post_id, $post ) { diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-reviews.php b/includes/admin/meta-boxes/class-wc-meta-box-product-reviews.php index 0ec9111cb9d..2149441c93a 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-reviews.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-reviews.php @@ -28,9 +28,11 @@ class WC_Meta_Box_Product_Reviews { $current = get_comment_meta( $comment->comment_ID, 'rating', true ); ?>

    - + get_id() ), @@ -16,7 +17,8 @@ if ( ! defined( 'ABSPATH' ) ) { esc_html( wc_get_filename_from_url( $product->get_file_download_path( $download->get_download_id() ) ) ) ); printf( _n( 'Downloaded %s time', 'Downloaded %s times', $download->get_download_count(), 'woocommerce' ), esc_html( $download->get_download_count() ) ) - ?> + ?> + @@ -33,14 +35,16 @@ if ( ! defined( 'ABSPATH' ) ) { get_taxes() ) && wc_tax_enabled() ) { - foreach ( $order_taxes as $tax_item ) { - $tax_item_id = $tax_item->get_rate_id(); - $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : ''; - ?> - - - get_tax_refunded_for_item( $item_id, $tax_item_id, 'fee' ) ) { + echo '-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; + } + ?> + + + + + - + diff --git a/includes/admin/meta-boxes/views/html-order-shipping.php b/includes/admin/meta-boxes/views/html-order-shipping.php index a7a45fc6c98..b453a863eef 100644 --- a/includes/admin/meta-boxes/views/html-order-shipping.php +++ b/includes/admin/meta-boxes/views/html-order-shipping.php @@ -23,30 +23,30 @@ if ( ! defined( 'ABSPATH' ) ) { get_method_id(), $method->id ) ) ? $item->get_method_id() : $method->id; + foreach ( $shipping_methods as $method ) { + $current_method = ( 0 === strpos( $item->get_method_id(), $method->id ) ) ? $item->get_method_id() : $method->id; - echo ''; + echo ''; - if ( $item->get_method_id() === $current_method ) { - $found_method = true; - } + if ( $item->get_method_id() === $current_method ) { + $found_method = true; } + } - if ( ! $found_method && $item->get_method_id() ) { - echo ''; - } else { - echo ''; - } + if ( ! $found_method && $item->get_method_id() ) { + echo ''; + } else { + echo ''; + } ?> - + @@ -58,11 +58,11 @@ if ( ! defined( 'ABSPATH' ) ) { get_taxes() ) && wc_tax_enabled() ) { - foreach ( $order_taxes as $tax_item ) { - $tax_item_id = $tax_item->get_rate_id(); - $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : ''; - ?> - - get_taxes() ) && wc_tax_enabled() ) { + foreach ( $order_taxes as $tax_item ) { + $tax_item_id = $tax_item->get_rate_id(); + $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : ''; + ?> + + diff --git a/includes/admin/meta-boxes/views/html-product-data-advanced.php b/includes/admin/meta-boxes/views/html-product-data-advanced.php index 350dadcfa44..cde5ff9dd03 100644 --- a/includes/admin/meta-boxes/views/html-product-data-advanced.php +++ b/includes/admin/meta-boxes/views/html-product-data-advanced.php @@ -7,41 +7,47 @@ if ( ! defined( 'ABSPATH' ) ) {
    '_purchase_note', - 'value' => $product_object->get_purchase_note( 'edit' ), - 'label' => __( 'Purchase note', 'woocommerce' ), - 'desc_tip' => true, - 'description' => __( 'Enter an optional note to send the customer after purchase.', 'woocommerce' ), - ) ); + woocommerce_wp_textarea_input( + array( + 'id' => '_purchase_note', + 'value' => $product_object->get_purchase_note( 'edit' ), + 'label' => __( 'Purchase note', 'woocommerce' ), + 'desc_tip' => true, + 'description' => __( 'Enter an optional note to send the customer after purchase.', 'woocommerce' ), + ) + ); ?>
    'menu_order', - 'value' => $product_object->get_menu_order( 'edit' ), - 'label' => __( 'Menu order', 'woocommerce' ), - 'desc_tip' => true, - 'description' => __( 'Custom ordering position.', 'woocommerce' ), - 'type' => 'number', - 'custom_attributes' => array( - 'step' => '1', - ), - ) ); + woocommerce_wp_text_input( + array( + 'id' => 'menu_order', + 'value' => $product_object->get_menu_order( 'edit' ), + 'label' => __( 'Menu order', 'woocommerce' ), + 'desc_tip' => true, + 'description' => __( 'Custom ordering position.', 'woocommerce' ), + 'type' => 'number', + 'custom_attributes' => array( + 'step' => '1', + ), + ) + ); ?>
    'comment_status', - 'value' => $product_object->get_reviews_allowed( 'edit' ) ? 'open' : 'closed', - 'label' => __( 'Enable reviews', 'woocommerce' ), - 'cbvalue' => 'open', - ) ); + woocommerce_wp_checkbox( + array( + 'id' => 'comment_status', + 'value' => $product_object->get_reviews_allowed( 'edit' ) ? 'open' : 'closed', + 'label' => __( 'Enable reviews', 'woocommerce' ), + 'cbvalue' => 'open', + ) + ); do_action( 'woocommerce_product_options_reviews' ); ?>
    diff --git a/includes/admin/meta-boxes/views/html-product-data-attributes.php b/includes/admin/meta-boxes/views/html-product-data-attributes.php index e93151809be..f763e9469ca 100644 --- a/includes/admin/meta-boxes/views/html-product-data-attributes.php +++ b/includes/admin/meta-boxes/views/html-product-data-attributes.php @@ -11,39 +11,39 @@ if ( ! defined( 'ABSPATH' ) ) {
    get_attributes( 'edit' ); - $i = -1; + // Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set. + $attributes = $product_object->get_attributes( 'edit' ); + $i = -1; - foreach ( $attributes as $attribute ) { - $i++; - $metabox_class = array(); + foreach ( $attributes as $attribute ) { + $i++; + $metabox_class = array(); - if ( $attribute->is_taxonomy() ) { - $metabox_class[] = 'taxonomy'; - $metabox_class[] = $attribute->get_name(); - } - - include( 'html-product-attribute.php' ); + if ( $attribute->is_taxonomy() ) { + $metabox_class[] = 'taxonomy'; + $metabox_class[] = $attribute->get_name(); } + + include 'html-product-attribute.php'; + } ?>
    diff --git a/includes/admin/meta-boxes/views/html-product-data-general.php b/includes/admin/meta-boxes/views/html-product-data-general.php index 179d3a44996..25d586155fe 100644 --- a/includes/admin/meta-boxes/views/html-product-data-general.php +++ b/includes/admin/meta-boxes/views/html-product-data-general.php @@ -7,52 +7,60 @@ if ( ! defined( 'ABSPATH' ) ) {
    '_product_url', 'value' => is_callable( array( $product_object, 'get_product_url' ) ) ? $product_object->get_product_url( 'edit' ) : '', 'label' => __( 'Product URL', 'woocommerce' ), 'placeholder' => 'http://', 'description' => __( 'Enter the external URL to the product.', 'woocommerce' ), - ) ); + ) + ); - woocommerce_wp_text_input( array( + woocommerce_wp_text_input( + array( 'id' => '_button_text', 'value' => is_callable( array( $product_object, 'get_button_text' ) ) ? $product_object->get_button_text( 'edit' ) : '', 'label' => __( 'Button text', 'woocommerce' ), 'placeholder' => _x( 'Buy product', 'placeholder', 'woocommerce' ), 'description' => __( 'This text will be shown on the button linking to the external product.', 'woocommerce' ), - ) ); + ) + ); ?>
    @@ -73,7 +81,7 @@ if ( ! defined( 'ABSPATH' ) ) { $downloadable_files = $product_object->get_downloads( 'edit' ); if ( $downloadable_files ) { foreach ( $downloadable_files as $key => $file ) { - include( 'html-product-download.php' ); + include 'html-product-download.php'; } } ?> @@ -81,23 +89,26 @@ if ( ! defined( 'ABSPATH' ) ) {
    $download->get_product_id(), - 'order' => $download->get_order_key(), - 'email' => urlencode( $download->get_user_email() ), - 'key' => $download->get_download_id(), - ), trailingslashit( home_url() ) ); + $download_link = add_query_arg( + array( + 'download_file' => $download->get_product_id(), + 'order' => $download->get_order_key(), + 'email' => urlencode( $download->get_user_email() ), + 'key' => $download->get_download_id(), + ), trailingslashit( home_url() ) + ); ?> - + diff --git a/includes/admin/meta-boxes/views/html-order-fee.php b/includes/admin/meta-boxes/views/html-order-fee.php index a300126d93b..d5f3945d028 100644 --- a/includes/admin/meta-boxes/views/html-order-fee.php +++ b/includes/admin/meta-boxes/views/html-order-fee.php @@ -33,11 +33,11 @@ if ( ! defined( 'ABSPATH' ) ) {
    get_total(), array( 'currency' => $order->get_currency() ) ); + echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) ); - if ( $refunded = $order->get_total_refunded_for_item( $item_id, 'fee' ) ) { - echo '-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; - } + if ( $refunded = $order->get_total_refunded_for_item( $item_id, 'fee' ) ) { + echo '-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; + } ?>
    -
    - $order->get_currency() ) ) : '–'; + if ( ( $tax_data = $item->get_taxes() ) && wc_tax_enabled() ) { + foreach ( $order_taxes as $tax_item ) { + $tax_item_id = $tax_item->get_rate_id(); + $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : ''; + ?> +
    +
    + $order->get_currency() ) ) : '–'; - if ( $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id, 'fee' ) ) { - echo '-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; - } - ?> -
    - - -
    is_editable() ) : ?> diff --git a/includes/admin/meta-boxes/views/html-order-item-meta.php b/includes/admin/meta-boxes/views/html-order-item-meta.php index 1f9915c7e24..3dbd34a2a32 100644 --- a/includes/admin/meta-boxes/views/html-order-item-meta.php +++ b/includes/admin/meta-boxes/views/html-order-item-meta.php @@ -3,18 +3,20 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -$hidden_order_itemmeta = apply_filters( 'woocommerce_hidden_order_itemmeta', array( - '_qty', - '_tax_class', - '_product_id', - '_variation_id', - '_line_subtotal', - '_line_subtotal_tax', - '_line_total', - '_line_tax', - 'method_id', - 'cost', -) ); +$hidden_order_itemmeta = apply_filters( + 'woocommerce_hidden_order_itemmeta', array( + '_qty', + '_tax_class', + '_product_id', + '_variation_id', + '_line_subtotal', + '_line_subtotal_tax', + '_line_total', + '_line_tax', + 'method_id', + 'cost', + ) +); ?>
    get_formatted_meta_data( '' ) ) : ?> diff --git a/includes/admin/meta-boxes/views/html-order-item.php b/includes/admin/meta-boxes/views/html-order-item.php index 8f03707bb5f..b4c7c7e85e0 100644 --- a/includes/admin/meta-boxes/views/html-order-item.php +++ b/includes/admin/meta-boxes/views/html-order-item.php @@ -19,28 +19,28 @@ $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empt @@ -51,9 +51,9 @@ $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empt get_item_total( $item, false, true ), array( 'currency' => $order->get_currency() ) ); - if ( $item->get_subtotal() !== $item->get_total() ) { - echo '-' . wc_price( wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false ), '' ), array( 'currency' => $order->get_currency() ) ) . ''; - } + if ( $item->get_subtotal() !== $item->get_total() ) { + echo '-' . wc_price( wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false ), '' ), array( 'currency' => $order->get_currency() ) ) . ''; + } ?> @@ -62,9 +62,9 @@ $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empt × ' . esc_html( $item->get_quantity() ); - if ( $refunded_qty = $order->get_qty_refunded_for_item( $item_id ) ) { - echo '' . ( $refunded_qty * -1 ) . ''; - } + if ( $refunded_qty = $order->get_qty_refunded_for_item( $item_id ) ) { + echo '' . ( $refunded_qty * -1 ) . ''; + } ?> get_taxes() ) && wc_tax_enabled() ) { - foreach ( $order_taxes as $tax_item ) { - $tax_item_id = $tax_item->get_rate_id(); - $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : ''; - $tax_item_subtotal = isset( $tax_data['subtotal'][ $tax_item_id ] ) ? $tax_data['subtotal'][ $tax_item_id ] : ''; - ?> - - + + + $tax_item ) : - $tax_class = wc_get_tax_class_by_tax_id( $tax_item['rate_id'] ); - $tax_class_name = isset( $classes_options[ $tax_class ] ) ? $classes_options[ $tax_class ] : __( 'Tax', 'woocommerce' ); - $column_label = ! empty( $tax_item['label'] ) ? $tax_item['label'] : __( 'Tax', 'woocommerce' ); - /* translators: %1$s: tax item name %2$s: tax class name */ - $column_tip = sprintf( esc_html__( '%1$s (%2$s)', 'woocommerce' ), $tax_item['name'], $tax_class_name ); - ?> - - $tax_item ) : + $tax_class = wc_get_tax_class_by_tax_id( $tax_item['rate_id'] ); + $tax_class_name = isset( $classes_options[ $tax_class ] ) ? $classes_options[ $tax_class ] : __( 'Tax', 'woocommerce' ); + $column_label = ! empty( $tax_item['label'] ) ? $tax_item['label'] : __( 'Tax', 'woocommerce' ); + /* translators: %1$s: tax item name %2$s: tax class name */ + $column_tip = sprintf( esc_html__( '%1$s (%2$s)', 'woocommerce' ), $tax_item['name'], $tax_class_name ); + ?> + + - $item ) { do_action( 'woocommerce_before_order_item_' . $item->get_type() . '_html', $item_id, $item, $order ); - include( 'html-order-item.php' ); + include 'html-order-item.php'; do_action( 'woocommerce_order_item_' . $item->get_type() . '_html', $item_id, $item, $order ); } do_action( 'woocommerce_admin_order_items_after_line_items', $order->get_id() ); - ?> + ?> - shipping() ? WC()->shipping->load_shipping_methods() : array(); foreach ( $line_items_shipping as $item_id => $item ) { - include( 'html-order-shipping.php' ); + include 'html-order-shipping.php'; } do_action( 'woocommerce_admin_order_items_after_shipping', $order->get_id() ); - ?> + ?> - $item ) { - include( 'html-order-fee.php' ); + include 'html-order-fee.php'; } do_action( 'woocommerce_admin_order_items_after_fees', $order->get_id() ); - ?> + ?> - get_refunds() ) { foreach ( $refunds as $refund ) { - include( 'html-order-refund.php' ); + include 'html-order-refund.php'; } do_action( 'woocommerce_admin_order_items_after_refunds', $order->get_id() ); } - ?> + ?>
    ' . esc_html( $item->get_name() ) . '' : '
    ' . esc_html( $item->get_name() ) . '
    '; + echo $product_link ? '' . esc_html( $item->get_name() ) . '' : '
    ' . esc_html( $item->get_name() ) . '
    '; - if ( $product && $product->get_sku() ) { - echo '
    ' . esc_html__( 'SKU:', 'woocommerce' ) . ' ' . esc_html( $product->get_sku() ) . '
    '; - } + if ( $product && $product->get_sku() ) { + echo '
    ' . esc_html__( 'SKU:', 'woocommerce' ) . ' ' . esc_html( $product->get_sku() ) . '
    '; + } - if ( $item->get_variation_id() ) { - echo '
    ' . esc_html__( 'Variation ID:', 'woocommerce' ) . ' '; - if ( 'product_variation' === get_post_type( $item->get_variation_id() ) ) { - echo esc_html( $item->get_variation_id() ); - } else { - /* translators: %s: variation id */ - printf( esc_html__( '%s (No longer exists)', 'woocommerce' ), $item->get_variation_id() ); - } - echo '
    '; + if ( $item->get_variation_id() ) { + echo '
    ' . esc_html__( 'Variation ID:', 'woocommerce' ) . ' '; + if ( 'product_variation' === get_post_type( $item->get_variation_id() ) ) { + echo esc_html( $item->get_variation_id() ); + } else { + /* translators: %s: variation id */ + printf( esc_html__( '%s (No longer exists)', 'woocommerce' ), $item->get_variation_id() ); } + echo '
    '; + } ?> - +
    get_total(), array( 'currency' => $order->get_currency() ) ); + echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) ); - if ( $item->get_subtotal() !== $item->get_total() ) { - echo '-' . wc_price( wc_format_decimal( $item->get_subtotal() - $item->get_total(), '' ), array( 'currency' => $order->get_currency() ) ) . ''; - } + if ( $item->get_subtotal() !== $item->get_total() ) { + echo '-' . wc_price( wc_format_decimal( $item->get_subtotal() - $item->get_total(), '' ), array( 'currency' => $order->get_currency() ) ) . ''; + } - if ( $refunded = $order->get_total_refunded_for_item( $item_id ) ) { - echo '' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; - } + if ( $refunded = $order->get_total_refunded_for_item( $item_id ) ) { + echo '' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; + } ?>
    -
    - $order->get_currency() ) ); - } else { - echo '–'; - } + if ( ( $tax_data = $item->get_taxes() ) && wc_tax_enabled() ) { + foreach ( $order_taxes as $tax_item ) { + $tax_item_id = $tax_item->get_rate_id(); + $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : ''; + $tax_item_subtotal = isset( $tax_data['subtotal'][ $tax_item_id ] ) ? $tax_data['subtotal'][ $tax_item_id ] : ''; + ?> +
    +
    + $order->get_currency() ) ); + } else { + echo '–'; + } - if ( $item->get_subtotal() !== $item->get_total() ) { - if ( '' === $tax_item_total ) { - echo ''; - } else { - echo '-' . wc_price( wc_round_tax_total( $tax_item_subtotal - $tax_item_total ), array( 'currency' => $order->get_currency() ) ) . ''; - } - } + if ( $item->get_subtotal() !== $item->get_total() ) { + if ( '' === $tax_item_total ) { + echo ''; + } else { + echo '-' . wc_price( wc_round_tax_total( $tax_item_subtotal - $tax_item_total ), array( 'currency' => $order->get_currency() ) ) . ''; + } + } - if ( $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id ) ) { - echo '' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; - } - ?> -
    -
    diff --git a/includes/admin/meta-boxes/views/html-order-items.php b/includes/admin/meta-boxes/views/html-order-items.php index 20a46a95731..f7ad8772cfc 100644 --- a/includes/admin/meta-boxes/views/html-order-items.php +++ b/includes/admin/meta-boxes/views/html-order-items.php @@ -32,64 +32,64 @@ if ( wc_tax_enabled() ) {
    - - - - + + + +  
    @@ -107,33 +107,44 @@ if ( wc_tax_enabled() ) {
    get_items( 'coupon' ); - if ( $coupons ) : ?> -
    -
      -
    • - $item ) : - $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item->get_code() ) ); - $class = $order->is_editable() ? 'code editable' : 'code'; - ?> -
    • - - - get_code() ) ?> - - - - get_code() ) ?> - - - is_editable() ) : ?> - - -
    • - -
    -
    - + $coupons = $order->get_items( 'coupon' ); + if ( $coupons ) : + ?> +
    +
      +
    • + $item ) : + $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item->get_code() ) ); + $class = $order->is_editable() ? 'code editable' : 'code'; + ?> +
    • + + $post_id, + 'action' => 'edit', + ), + admin_url( 'post.php' ) + ); + ?> + + get_code() ); ?> + + + + get_code() ); ?> + + + is_editable() ) : ?> + + +
    • + +
    +
    + get_total_discount() ) : ?> @@ -159,7 +170,8 @@ if ( wc_tax_enabled() ) { } else { echo wc_price( $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) ); } - ?> + ?> + @@ -346,8 +358,8 @@ if ( wc_tax_enabled() ) { get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name LIMIT 100" ); - foreach ( $rates as $rate ) { - echo ' + foreach ( $rates as $rate ) { + echo ' @@ -356,7 +368,7 @@ if ( wc_tax_enabled() ) { '; - } + } ?>
    ' . WC_Tax::get_rate_percent( $rate ) . '
    get_var( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}woocommerce_tax_rates;" ) ) > 100 ) : ?> diff --git a/includes/admin/meta-boxes/views/html-order-refund.php b/includes/admin/meta-boxes/views/html-order-refund.php index 4f2d0cf6e67..8efb5c559a9 100644 --- a/includes/admin/meta-boxes/views/html-order-refund.php +++ b/includes/admin/meta-boxes/views/html-order-refund.php @@ -13,27 +13,27 @@ $who_refunded = new WP_User( $refund->get_refunded_by() );
    exists() ) { - printf( - /* translators: 1: refund id 2: refund date 3: username */ - esc_html__( 'Refund #%1$s - %2$s by %3$s', 'woocommerce' ), - $refund->get_id(), - wc_format_datetime( $refund->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) ), - sprintf( - '%2$s', - /* translators: 1: ID who refunded */ - sprintf( esc_attr__( 'ID: %d', 'woocommerce' ), absint( $who_refunded->ID ) ), - esc_html( $who_refunded->display_name ) - ) - ); - } else { - printf( - /* translators: 1: refund id 2: refund date */ - esc_html__( 'Refund #%1$s - %2$s', 'woocommerce' ), - $refund->get_id(), - wc_format_datetime( $refund->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) ) - ); - } + if ( $who_refunded->exists() ) { + printf( + /* translators: 1: refund id 2: refund date 3: username */ + esc_html__( 'Refund #%1$s - %2$s by %3$s', 'woocommerce' ), + $refund->get_id(), + wc_format_datetime( $refund->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) ), + sprintf( + '%2$s', + /* translators: 1: ID who refunded */ + sprintf( esc_attr__( 'ID: %d', 'woocommerce' ), absint( $who_refunded->ID ) ), + esc_html( $who_refunded->display_name ) + ) + ); + } else { + printf( + /* translators: 1: refund id 2: refund date */ + esc_html__( 'Refund #%1$s - %2$s', 'woocommerce' ), + $refund->get_id(), + wc_format_datetime( $refund->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) ) + ); + } ?> get_reason() ) : ?>

    get_reason() ); ?>

    @@ -52,7 +52,10 @@ $who_refunded = new WP_User( $refund->get_refunded_by() );
    get_total(), array( 'currency' => $order->get_currency() ) ); - $refunded = $order->get_total_refunded_for_item( $item_id, 'shipping' ); - if ( $refunded ) { - echo '-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; - } + echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) ); + $refunded = $order->get_total_refunded_for_item( $item_id, 'shipping' ); + if ( $refunded ) { + echo '-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; + } ?>
    -
    - $order->get_currency() ) ) : '–'; - $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id, 'shipping' ); - if ( $refunded ) { - echo '-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; - } - ?> -
    - - -
    +
    + $order->get_currency() ) ) : '–'; + $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id, 'shipping' ); + if ( $refunded ) { + echo '-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . ''; + } + ?> +
    + + +
    is_editable() ) : ?> diff --git a/includes/admin/meta-boxes/views/html-product-attribute.php b/includes/admin/meta-boxes/views/html-product-attribute.php index 19ff0304c36..600cacbb6aa 100644 --- a/includes/admin/meta-boxes/views/html-product-attribute.php +++ b/includes/admin/meta-boxes/views/html-product-attribute.php @@ -39,7 +39,7 @@ if ( ! defined( 'ABSPATH' ) ) { ?> + +
    - + ?> + ">
    '_download_limit', 'value' => -1 === $product_object->get_download_limit( 'edit' ) ? '' : $product_object->get_download_limit( 'edit' ), 'label' => __( 'Download limit', 'woocommerce' ), @@ -105,12 +116,14 @@ if ( ! defined( 'ABSPATH' ) ) { 'description' => __( 'Leave blank for unlimited re-downloads.', 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array( - 'step' => '1', - 'min' => '0', + 'step' => '1', + 'min' => '0', ), - ) ); + ) + ); - woocommerce_wp_text_input( array( + woocommerce_wp_text_input( + array( 'id' => '_download_expiry', 'value' => -1 === $product_object->get_download_expiry( 'edit' ) ? '' : $product_object->get_download_expiry( 'edit' ), 'label' => __( 'Download expiry', 'woocommerce' ), @@ -118,41 +131,46 @@ if ( ! defined( 'ABSPATH' ) ) { 'description' => __( 'Enter the number of days before a download link expires, or leave blank.', 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array( - 'step' => '1', - 'min' => '0', + 'step' => '1', + 'min' => '0', ), - ) ); + ) + ); - do_action( 'woocommerce_product_options_downloads' ); + do_action( 'woocommerce_product_options_downloads' ); ?>
    '_tax_status', - 'value' => $product_object->get_tax_status( 'edit' ), - 'label' => __( 'Tax status', 'woocommerce' ), - 'options' => array( - 'taxable' => __( 'Taxable', 'woocommerce' ), - 'shipping' => __( 'Shipping only', 'woocommerce' ), - 'none' => _x( 'None', 'Tax status', 'woocommerce' ), + woocommerce_wp_select( + array( + 'id' => '_tax_status', + 'value' => $product_object->get_tax_status( 'edit' ), + 'label' => __( 'Tax status', 'woocommerce' ), + 'options' => array( + 'taxable' => __( 'Taxable', 'woocommerce' ), + 'shipping' => __( 'Shipping only', 'woocommerce' ), + 'none' => _x( 'None', 'Tax status', 'woocommerce' ), ), - 'desc_tip' => 'true', - 'description' => __( 'Define whether or not the entire product is taxable, or just the cost of shipping it.', 'woocommerce' ), - ) ); + 'desc_tip' => 'true', + 'description' => __( 'Define whether or not the entire product is taxable, or just the cost of shipping it.', 'woocommerce' ), + ) + ); - woocommerce_wp_select( array( + woocommerce_wp_select( + array( 'id' => '_tax_class', 'value' => $product_object->get_tax_class( 'edit' ), 'label' => __( 'Tax class', 'woocommerce' ), 'options' => wc_get_product_tax_class_options(), 'desc_tip' => 'true', 'description' => __( 'Choose a tax class for this product. Tax classes are used to apply different tax rates specific to certain types of product.', 'woocommerce' ), - ) ); + ) + ); - do_action( 'woocommerce_product_options_tax' ); + do_action( 'woocommerce_product_options_tax' ); ?>
    diff --git a/includes/admin/meta-boxes/views/html-product-data-inventory.php b/includes/admin/meta-boxes/views/html-product-data-inventory.php index d7f46ab0ac8..30ece552b87 100644 --- a/includes/admin/meta-boxes/views/html-product-data-inventory.php +++ b/includes/admin/meta-boxes/views/html-product-data-inventory.php @@ -7,33 +7,38 @@ if ( ! defined( 'ABSPATH' ) ) {
    '_sku', 'value' => $product_object->get_sku( 'edit' ), 'label' => '' . esc_html__( 'SKU', 'woocommerce' ) . '', 'desc_tip' => true, 'description' => __( 'SKU refers to a Stock-keeping unit, a unique identifier for each distinct product and service that can be purchased.', 'woocommerce' ), - ) ); - } + ) + ); + } - do_action( 'woocommerce_product_options_sku' ); + do_action( 'woocommerce_product_options_sku' ); - if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) { + if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) { - woocommerce_wp_checkbox( array( + woocommerce_wp_checkbox( + array( 'id' => '_manage_stock', 'value' => $product_object->get_manage_stock( 'edit' ) ? 'yes' : 'no', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __( 'Manage stock?', 'woocommerce' ), 'description' => __( 'Enable stock management at product level', 'woocommerce' ), - ) ); + ) + ); - do_action( 'woocommerce_product_options_stock' ); + do_action( 'woocommerce_product_options_stock' ); - echo '
    '; + echo '
    '; - woocommerce_wp_text_input( array( + woocommerce_wp_text_input( + array( 'id' => '_stock', 'value' => wc_stock_amount( $product_object->get_stock_quantity( 'edit' ) ), 'label' => __( 'Stock quantity', 'woocommerce' ), @@ -41,52 +46,59 @@ if ( ! defined( 'ABSPATH' ) ) { 'description' => __( 'Stock quantity. If this is a variable product this value will be used to control stock for all variations, unless you define stock at variation level.', 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array( - 'step' => 'any', + 'step' => 'any', ), 'data_type' => 'stock', - ) ); + ) + ); - echo ''; + echo ''; - woocommerce_wp_select( array( + woocommerce_wp_select( + array( 'id' => '_backorders', 'value' => $product_object->get_backorders( 'edit' ), 'label' => __( 'Allow backorders?', 'woocommerce' ), 'options' => wc_get_product_backorder_options(), 'desc_tip' => true, 'description' => __( 'If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0.', 'woocommerce' ), - ) ); + ) + ); - do_action( 'woocommerce_product_options_stock_fields' ); + do_action( 'woocommerce_product_options_stock_fields' ); - echo '
    '; - } + echo '
    '; + } - woocommerce_wp_select( array( - 'id' => '_stock_status', - 'value' => $product_object->get_stock_status( 'edit' ), - 'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external', - 'label' => __( 'Stock status', 'woocommerce' ), - 'options' => wc_get_product_stock_status_options(), - 'desc_tip' => true, - 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ), - ) ); + woocommerce_wp_select( + array( + 'id' => '_stock_status', + 'value' => $product_object->get_stock_status( 'edit' ), + 'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external', + 'label' => __( 'Stock status', 'woocommerce' ), + 'options' => wc_get_product_stock_status_options(), + 'desc_tip' => true, + 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ), + ) + ); - do_action( 'woocommerce_product_options_stock_status' ); + do_action( 'woocommerce_product_options_stock_status' ); ?>
    '_sold_individually', 'value' => $product_object->get_sold_individually( 'edit' ) ? 'yes' : 'no', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __( 'Sold individually', 'woocommerce' ), 'description' => __( 'Enable this to only allow one of this item to be bought in a single order', 'woocommerce' ), - ) ); + ) + ); - do_action( 'woocommerce_product_options_sold_individually' ); + do_action( 'woocommerce_product_options_sold_individually' ); ?>
    diff --git a/includes/admin/meta-boxes/views/html-product-data-panel.php b/includes/admin/meta-boxes/views/html-product-data-panel.php index 87298031c9c..b2fe47c4965 100644 --- a/includes/admin/meta-boxes/views/html-product-data-panel.php +++ b/includes/admin/meta-boxes/views/html-product-data-panel.php @@ -16,7 +16,8 @@ if ( ! defined( 'ABSPATH' ) ) { - $option ) : + $option ) : if ( metadata_exists( 'post', $post->ID, '_' . $key ) ) { $selected_value = is_callable( array( $product_object, "is_$key" ) ) ? $product_object->{"is_$key"}() : 'yes' === get_post_meta( $post->ID, '_' . $key, true ); } else { @@ -32,7 +33,7 @@ if ( ! defined( 'ABSPATH' ) ) {