| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Todo: remove |
| 9 |
* |
| 10 |
* Head custom JS |
| 11 |
* |
| 12 |
*/ |
| 13 |
function merchant_head_custom_js_first() { |
| 14 |
// Custom JS First - runs at the beginning of Merchant |
| 15 |
$custom_js_first = Merchant_Option::get( 'global-settings', 'custom_js_first', '' ); |
| 16 |
|
| 17 |
if ( ! empty( $custom_js_first ) ) { |
| 18 |
wp_add_inline_script( 'merchant', wp_kses( $custom_js_first, array() ), 'before' ); |
| 19 |
} |
| 20 |
} |
| 21 |
// add_action( 'wp_enqueue_scripts', 'merchant_head_custom_js_first', 11 ); |
| 22 |
|
| 23 |
/** |
| 24 |
* Head Custom JS |
| 25 |
* |
| 26 |
*/ |
| 27 |
function merchant_head_custom_js() { |
| 28 |
$custom_js = Merchant_Option::get( 'global-settings', 'custom_js', '' ); |
| 29 |
|
| 30 |
$custom_js = html_entity_decode( $custom_js, ENT_QUOTES, 'UTF-8' ); |
| 31 |
|
| 32 |
if ( ! empty( $custom_js ) ) { |
| 33 |
// Simple minification |
| 34 |
$minified_js = preg_replace( |
| 35 |
array( '/\/\/.*/', '/\/\*.*?\*\//s', '/\s+/' ), |
| 36 |
array( '', '', ' ' ), |
| 37 |
$custom_js |
| 38 |
); |
| 39 |
|
| 40 |
wp_add_inline_script( 'merchant', $minified_js ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* `merchant_head_custom_js_priority` |
| 46 |
* |
| 47 |
* @since 2.0.0 |
| 48 |
*/ |
| 49 |
add_action( 'wp_enqueue_scripts', 'merchant_head_custom_js', apply_filters( 'merchant_head_custom_js_priority', 12 ) ); |
| 50 |
|
| 51 |
/** |
| 52 |
* Todo: remove |
| 53 |
* |
| 54 |
* Head Custom JS Later |
| 55 |
* |
| 56 |
*/ |
| 57 |
function merchant_head_custom_js_later() { |
| 58 |
|
| 59 |
// Custom JS Last - runs at the end of Merchant |
| 60 |
$custom_js_last = Merchant_Option::get( 'global-settings', 'custom_js_last', '' ); |
| 61 |
|
| 62 |
if ( ! empty( $custom_js_last ) ) { |
| 63 |
wp_add_inline_script( 'merchant', wp_kses( $custom_js_last, array() ), 'after' ); |
| 64 |
} |
| 65 |
} |
| 66 |
// add_action( 'wp_enqueue_scripts', 'merchant_head_custom_js_later', 13 ); |
| 67 |
|