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