| 1 |
<?php |
| 2 |
|
| 3 |
if (! defined("ABSPATH")) { |
| 4 |
exit; |
| 5 |
} // Exit if accessed directly |
| 6 |
|
| 7 |
if (class_exists("WCPN_Assets")) { |
| 8 |
return new WCPN_Assets(); |
| 9 |
} |
| 10 |
|
| 11 |
class WCPN_Assets |
| 12 |
{ |
| 13 |
|
| 14 |
public function __construct() |
| 15 |
{ |
| 16 |
add_action("admin_enqueue_scripts", [$this, "enqueue_admin_scripts_and_styles"], 9999); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Load styles & scripts |
| 21 |
*/ |
| 22 |
public function enqueue_admin_scripts_and_styles() |
| 23 |
{ |
| 24 |
global $post_type; |
| 25 |
$screen = get_current_screen(); |
| 26 |
|
| 27 |
if ($post_type === "shop_order" || (is_object($screen) && strpos($screen->id, "wcpn") !== false)) { |
| 28 |
// WC2.3+ load all WC scripts for shipping_method search! |
| 29 |
if (version_compare(WOOCOMMERCE_VERSION, "2.3", ">=")) { |
| 30 |
wp_enqueue_script("woocommerce_admin"); |
| 31 |
wp_enqueue_script("iris"); |
| 32 |
|
| 33 |
if (! wp_script_is("wc-enhanced-select", "registered")) { |
| 34 |
$suffix = defined("SCRIPT_DEBUG") && SCRIPT_DEBUG ? "" : ".min"; |
| 35 |
wp_register_script( |
| 36 |
"wc-enhanced-select", |
| 37 |
WC()->plugin_url() . "/assets/js/admin/wc-enhanced-select" . $suffix . ".js", |
| 38 |
["jquery", version_compare(WC()->version, "3.2.0", ">=") ? "selectWoo" : "select2"], |
| 39 |
WC_VERSION |
| 40 |
); |
| 41 |
} |
| 42 |
wp_enqueue_script("wc-enhanced-select"); |
| 43 |
wp_enqueue_script("jquery-ui-sortable"); |
| 44 |
wp_enqueue_script("jquery-ui-autocomplete"); |
| 45 |
wp_enqueue_style( |
| 46 |
"woocommerce_admin_styles", |
| 47 |
WC()->plugin_url() . "/assets/css/admin.css", |
| 48 |
[], |
| 49 |
WC_VERSION |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
wp_enqueue_script("thickbox"); |
| 54 |
wp_enqueue_style("thickbox"); |
| 55 |
wp_enqueue_script( |
| 56 |
"wcpn-admin", |
| 57 |
WCPOST()->plugin_url() . "/assets/js/wcpn-admin.js", |
| 58 |
["jquery", "thickbox"], |
| 59 |
WC_POSTNL_VERSION |
| 60 |
); |
| 61 |
|
| 62 |
wp_localize_script( |
| 63 |
"wcpn-admin", |
| 64 |
"wcpn", |
| 65 |
[ |
| 66 |
"api_url" => WCPN_Data::API_URL, |
| 67 |
"actions" => [ |
| 68 |
"export" => WCPN_Export::EXPORT, |
| 69 |
"add_return" => WCPN_Export::ADD_RETURN, |
| 70 |
"add_shipments" => WCPN_Export::ADD_SHIPMENTS, |
| 71 |
"get_labels" => WCPN_Export::GET_LABELS, |
| 72 |
"modal_dialog" => WCPN_Export::MODAL_DIALOG, |
| 73 |
], |
| 74 |
"bulk_actions" => [ |
| 75 |
"export" => WCPOST_Admin::BULK_ACTION_EXPORT, |
| 76 |
"print" => WCPOST_Admin::BULK_ACTION_PRINT, |
| 77 |
"export_print" => WCPOST_Admin::BULK_ACTION_EXPORT_PRINT, |
| 78 |
], |
| 79 |
"ajax_url" => admin_url("admin-ajax.php"), |
| 80 |
"nonce" => wp_create_nonce(WCPOST::NONCE_ACTION), |
| 81 |
"download_display" => WCPOST()->setting_collection->getByName( |
| 82 |
WCPOST_Settings::SETTING_DOWNLOAD_DISPLAY |
| 83 |
), |
| 84 |
"ask_for_print_position" => WCPOST()->setting_collection->isEnabled( |
| 85 |
WCPOST_Settings::SETTING_ASK_FOR_PRINT_POSITION |
| 86 |
), |
| 87 |
"strings" => [ |
| 88 |
"no_orders_selected" => __("You have not selected any orders!", "woocommerce-postnl"), |
| 89 |
], |
| 90 |
] |
| 91 |
); |
| 92 |
|
| 93 |
wp_enqueue_style( |
| 94 |
"wcpn-admin-styles", |
| 95 |
WCPOST()->plugin_url() . "/assets/css/wcpn-admin-styles.css", |
| 96 |
[], |
| 97 |
WC_POSTNL_VERSION, |
| 98 |
"all" |
| 99 |
); |
| 100 |
|
| 101 |
// Legacy styles (WC 2.1+ introduced MP6 style with larger buttons) |
| 102 |
if (version_compare(WOOCOMMERCE_VERSION, "2.1", "<=")) { |
| 103 |
wp_enqueue_style( |
| 104 |
"wcpn-admin-styles-legacy", |
| 105 |
WCPOST()->plugin_url() . "/assets/css/wcpn-admin-styles-legacy.css", |
| 106 |
[], |
| 107 |
WC_POSTNL_VERSION, |
| 108 |
"all" |
| 109 |
); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
return new WCPN_Assets(); |
| 116 |
|