| @@ -1,0 +1,50 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Scripts | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\ConvertKit\Scripts | |
| 6 | + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Register admin scripts | |
| 14 | + * | |
| 15 | + * @since 1.0.0 | |
| 16 | + * @return void | |
| 17 | + */ | |
| 18 | +function automatorwp_convertkit_admin_register_scripts() { | |
| 19 | + | |
| 20 | + // Use minified libraries if SCRIPT_DEBUG is turned off | |
| 21 | + $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; | |
| 22 | + | |
| 23 | + // Stylesheets | |
| 24 | + wp_register_style( 'automatorwp-convertkit-css', AUTOMATORWP_CONVERTKIT_URL . 'assets/css/automatorwp-convertkit' . $suffix . '.css', array(), AUTOMATORWP_CONVERTKIT_VER, 'all' ); | |
| 25 | + | |
| 26 | + // Scripts | |
| 27 | + wp_register_script( 'automatorwp-convertkit-js', AUTOMATORWP_CONVERTKIT_URL . 'assets/js/automatorwp-convertkit' . $suffix . '.js', array( 'jquery' ), AUTOMATORWP_CONVERTKIT_VER, true ); | |
| 28 | + | |
| 29 | +} | |
| 30 | +add_action( 'admin_init', 'automatorwp_convertkit_admin_register_scripts' ); | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * Enqueue admin scripts | |
| 34 | + * | |
| 35 | + * @since 1.0.0 | |
| 36 | + * @return void | |
| 37 | + */ | |
| 38 | +function automatorwp_convertkit_admin_enqueue_scripts( $hook ) { | |
| 39 | + | |
| 40 | + // Stylesheets | |
| 41 | + wp_enqueue_style( 'automatorwp-convertkit-css' ); | |
| 42 | + | |
| 43 | + wp_localize_script( 'automatorwp-convertkit-js', 'automatorwp_convertkit', array( | |
| 44 | + 'nonce' => automatorwp_get_admin_nonce(), | |
| 45 | + ) ); | |
| 46 | + | |
| 47 | + wp_enqueue_script( 'automatorwp-convertkit-js' ); | |
| 48 | + | |
| 49 | +} | |
| 50 | +add_action( 'admin_enqueue_scripts', 'automatorwp_convertkit_admin_enqueue_scripts', 100 ); | |