1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
<?php
defined( 'ABSPATH' ) || exit();
class WC_Stripe_Admin_Assets {
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'wp_print_scripts', array( __CLASS__, 'localize_scripts' ) );
add_action( 'admin_footer', array( __CLASS__, 'localize_scripts' ) );
add_action( 'wc_stripe_localize_stripe_advanced_settings', array( __CLASS__, 'localize_advanced_scripts' ) );
}
public function enqueue_scripts() {
global $current_section, $wc_stripe_subsection;
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
$js_path = stripe_wc()->assets_url() . 'js/';
$css_path = stripe_wc()->assets_url() . 'css/';
wp_register_script( 'wc-stripe-admin-settings', $js_path . 'admin/admin-settings.js', array(
'jquery',
'jquery-blockui'
), stripe_wc()->version, true );
wp_register_script( 'wc-stripe-meta-boxes-order', $js_path . 'admin/meta-boxes-order.js', array(
'jquery',
'jquery-blockui'
), stripe_wc()->version, true );
wp_register_script(
'wc-stripe-product-data',
$js_path . 'admin/meta-boxes-product-data.js',
array(
'jquery',
'jquery-blockui',
'jquery-ui-sortable',
'jquery-ui-widget',
'jquery-ui-core',
'jquery-tiptip',
),
stripe_wc()->version(),
true
);
wp_register_style( 'wc-stripe-admin-style', $css_path . 'admin/admin.css', array(), stripe_wc()->version );
if ( strpos( $screen_id, 'wc-settings' ) !== false ) {
if ( isset( $_REQUEST['section'] ) && preg_match( '/stripe_[\w]*/', $_REQUEST['section'] ) ) {
wp_enqueue_script( 'wc-stripe-admin-settings' );
wp_enqueue_style( 'wc-stripe-admin-style' );
wp_style_add_data( 'wc-stripe-admin-style', 'rtl', 'replace' );
wp_enqueue_script( 'stripe-help-widget', $js_path . 'admin/help-widget.js', array(), stripe_wc()->version(), true );
wp_localize_script(
'wc-stripe-admin-settings',
'wc_stripe_setting_params',
array(
'routes' => array(
'apple_domain' => WC_Stripe_Rest_API::get_admin_endpoint( stripe_wc()->rest_api->settings->rest_uri( 'apple-domain' ) ),
'create_webhook' => WC_Stripe_Rest_API::get_admin_endpoint( stripe_wc()->rest_api->settings->rest_uri( 'create-webhook' ) ),
'delete_webhook' => WC_Stripe_Rest_API::get_admin_endpoint( stripe_wc()->rest_api->settings->rest_uri( 'delete-webhook' ) ),
'connection_test' => WC_Stripe_Rest_API::get_admin_endpoint( stripe_wc()->rest_api->settings->rest_uri( 'connection-test' ) ),
),
'rest_nonce' => wp_create_nonce( 'wp_rest' ),
)
);
}
}
if ( $screen_id === 'shop_order' ) {
wp_enqueue_style( 'wc-stripe-admin-style' );
}
if ( $screen_id === 'product' ) {
wp_enqueue_script( 'wc-stripe-product-data' );
wp_enqueue_style( 'wc-stripe-admin-style' );
wp_localize_script(
'wc-stripe-product-data',
'wc_stripe_product_params',
array(
'_wpnonce' => wp_create_nonce( 'wp_rest' ),
'routes' => array(
'enable_gateway' => stripe_wc()->rest_api->product_data->rest_url( 'gateway' ),
'save' => stripe_wc()->rest_api->product_data->rest_url( 'save' ),
),
)
);
}
}
public static function localize_scripts() {
global $current_section, $wc_stripe_subsection;
if ( ! empty( $current_section ) ) {
$wc_stripe_subsection = isset( $_GET['sub_section'] ) ? sanitize_title( $_GET['sub_section'] ) : '';
do_action( 'wc_stripe_localize_' . $current_section . '_settings' );
remove_action( 'admin_footer', array( __CLASS__, 'localize_scripts' ) );
}
}
public static function localize_advanced_scripts() {
global $current_section, $wc_stripe_subsection;
do_action( 'wc_stripe_localize_' . $wc_stripe_subsection . '_settings' );
}
}
new WC_Stripe_Admin_Assets();