| 1 |
<?php |
| 2 |
/** |
| 3 |
* Scripts |
| 4 |
* |
| 5 |
* @package AutomatorWP\AI_Assistant\Scripts |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 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_ai_assistant_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-ai-assistant-css', AUTOMATORWP_AI_ASSISTANT_URL . 'assets/css/automatorwp-ai-assistant' . $suffix . '.css', array( ), AUTOMATORWP_AI_ASSISTANT_VER, 'all' ); |
| 25 |
|
| 26 |
// Scripts |
| 27 |
wp_register_script( 'automatorwp-ai-assistant-showdown-js', AUTOMATORWP_AI_ASSISTANT_URL . 'assets/libs/showdown.min.js', array(), AUTOMATORWP_AI_ASSISTANT_VER, true ); |
| 28 |
wp_register_script( 'automatorwp-ai-assistant-js', AUTOMATORWP_AI_ASSISTANT_URL . 'assets/js/automatorwp-ai-assistant' . $suffix . '.js', array( 'jquery', 'automatorwp-ai-assistant-showdown-js' ), AUTOMATORWP_AI_ASSISTANT_VER, true ); |
| 29 |
|
| 30 |
} |
| 31 |
add_action( 'admin_init', 'automatorwp_ai_assistant_admin_register_scripts' ); |
| 32 |
|
| 33 |
/** |
| 34 |
* Enqueue admin scripts |
| 35 |
* |
| 36 |
* @since 1.0.0 |
| 37 |
* |
| 38 |
* @param string $hook |
| 39 |
* |
| 40 |
* @return void |
| 41 |
*/ |
| 42 |
function automatorwp_ai_assistant_admin_enqueue_scripts( $hook ) { |
| 43 |
|
| 44 |
if( ! automatorwp_ai_assistant_is_valid_page() ) return; |
| 45 |
|
| 46 |
// Stylesheets |
| 47 |
wp_enqueue_style( 'automatorwp-ai-assistant-css' ); |
| 48 |
|
| 49 |
// Scripts (libs) |
| 50 |
wp_enqueue_script( 'automatorwp-ai-assistant-showdown-js' ); |
| 51 |
|
| 52 |
// Localize scripts |
| 53 |
wp_localize_script( 'automatorwp-ai-assistant-js', 'automatorwp_ai_assistant', array( |
| 54 |
'nonce' => automatorwp_get_admin_nonce(), |
| 55 |
'i18n' => array( |
| 56 |
'first_message' => __( 'Hi! What can I help you with today?', 'automatorwp' ), |
| 57 |
'loading' => __( 'Thinking', 'automatorwp' ), |
| 58 |
'error_message' => __( 'Oops! Something went wrong. Please, try again.', 'automatorwp' ), |
| 59 |
), |
| 60 |
) ); |
| 61 |
|
| 62 |
// Scripts |
| 63 |
wp_enqueue_script( 'automatorwp-ai-assistant-js' ); |
| 64 |
|
| 65 |
} |
| 66 |
add_action( 'admin_enqueue_scripts', 'automatorwp_ai_assistant_admin_enqueue_scripts' ); |