admin.php
3 years ago
ai.php
3 years ago
answer.php
3 years ago
core.php
3 years ago
init.php
3 years ago
query.php
3 years ago
rest.php
3 years ago
shortcodes.php
3 years ago
ui.php
3 years ago
admin.php
71 lines
| 1 | <?php |
| 2 | class Meow_MWAI_Admin extends MeowCommon_Admin { |
| 3 | |
| 4 | public $core; |
| 5 | |
| 6 | public function __construct( $core ) { |
| 7 | $this->core = $core; |
| 8 | |
| 9 | parent::__construct( MWAI_PREFIX, MWAI_ENTRY, MWAI_DOMAIN, class_exists( 'MeowPro_MWAI_Core' ) ); |
| 10 | if ( is_admin() ) { |
| 11 | add_action( 'admin_menu', array( $this, 'app_menu' ) ); |
| 12 | |
| 13 | // Load the scripts only if they are needed by the current screen |
| 14 | $page = isset( $_GET["page"] ) ? sanitize_text_field( $_GET["page"] ) : null; |
| 15 | |
| 16 | // We can check if the screen is used by AI Engine |
| 17 | $is_mwai_screen = in_array( $page, [ 'mwai_settings', 'mwai_dashboard' ] ); |
| 18 | $is_meowapps_dashboard = $page === 'meowapps-main-menu'; |
| 19 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | function admin_enqueue_scripts() { |
| 24 | |
| 25 | // Load the scripts |
| 26 | $physical_file = MWAI_PATH . '/app/index.js'; |
| 27 | $cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : MWAI_VERSION; |
| 28 | wp_register_script( 'mwai_meow_plugin-vendor', MWAI_URL . 'app/vendor.js', |
| 29 | ['wp-element', 'wp-i18n'], $cache_buster |
| 30 | ); |
| 31 | wp_register_script( 'mwai_meow_plugin', MWAI_URL . 'app/index.js', |
| 32 | ['mwai_meow_plugin-vendor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-edit-post', |
| 33 | 'wp-element', 'wp-i18n', 'wp-plugins'], $cache_buster |
| 34 | ); |
| 35 | wp_set_script_translations( 'mwai_meow_plugin', 'ai-engine' ); |
| 36 | wp_enqueue_script('mwai_meow_plugin' ); |
| 37 | |
| 38 | // Load the fonts |
| 39 | // wp_register_style( 'meow-neko-ui-lato-font', |
| 40 | // '//fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap'); |
| 41 | // wp_enqueue_style( 'meow-neko-ui-lato-font' ); |
| 42 | |
| 43 | // Localize and options |
| 44 | wp_localize_script( 'mwai_meow_plugin', 'mwai_meow_plugin', [ |
| 45 | 'api_url' => rest_url( 'ai-engine/v1' ), |
| 46 | 'rest_url' => rest_url(), |
| 47 | 'plugin_url' => MWAI_URL, |
| 48 | 'prefix' => MWAI_PREFIX, |
| 49 | 'domain' => MWAI_DOMAIN, |
| 50 | 'is_pro' => class_exists( 'MeowPro_MWAI_Core' ), |
| 51 | 'is_registered' => !!$this->is_registered(), |
| 52 | 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
| 53 | 'options' => $this->core->get_all_options(), |
| 54 | ] ); |
| 55 | } |
| 56 | |
| 57 | function is_registered() { |
| 58 | return apply_filters( MWAI_PREFIX . '_meowapps_is_registered', false, MWAI_PREFIX ); |
| 59 | } |
| 60 | |
| 61 | function app_menu() { |
| 62 | add_submenu_page( 'meowapps-main-menu', 'AI Engine', 'AI Engine', 'manage_options', |
| 63 | 'mwai_settings', array( $this, 'admin_settings' ) ); |
| 64 | } |
| 65 | |
| 66 | function admin_settings() { |
| 67 | echo '<div id="mwai-admin-settings"></div>'; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | ?> |