| 1 |
<?php |
| 2 |
class Meow_MWCODE_Admin extends MeowCommon_Admin { |
| 3 |
|
| 4 |
public $core; |
| 5 |
|
| 6 |
public function __construct( $core ) { |
| 7 |
$this->core = $core; |
| 8 |
|
| 9 |
parent::__construct( MWCODE_PREFIX, MWCODE_ENTRY, MWCODE_DOMAIN, class_exists( 'MeowPro_MWCODE_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 |
// $is_mwcode_screen = in_array( $page, [ 'mwcode_settings' ] ); |
| 16 |
// $is_meowapps_dashboard = $page === 'meowapps-main-menu'; |
| 17 |
|
| 18 |
|
| 19 |
// if ( $is_meowapps_dashboard || $is_mwcode_screen ) { |
| 20 |
// add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 21 |
// } |
| 22 |
|
| 23 |
$can_access_settings = $this->core->can_access_settings(); |
| 24 |
$can_access_features = $this->core->can_access_features(); |
| 25 |
|
| 26 |
if ( $can_access_settings || $can_access_features ) { |
| 27 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
function admin_enqueue_scripts() { |
| 33 |
|
| 34 |
// Load the scripts |
| 35 |
$physical_file = MWCODE_PATH . '/app/index.js'; |
| 36 |
$cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : MWCODE_VERSION; |
| 37 |
wp_register_script( 'mwcode_snippet_vault-vendor', MWCODE_URL . 'app/vendor.js', |
| 38 |
['wp-element', 'wp-i18n'], $cache_buster |
| 39 |
); |
| 40 |
wp_register_script( 'mwcode_snippet_vault', MWCODE_URL . 'app/index.js', |
| 41 |
['mwcode_snippet_vault-vendor', 'wp-i18n'], $cache_buster |
| 42 |
); |
| 43 |
wp_set_script_translations( 'mwcode_snippet_vault', 'code-engine' ); |
| 44 |
wp_enqueue_script('mwcode_snippet_vault' ); |
| 45 |
|
| 46 |
// Load the fonts |
| 47 |
wp_register_style( 'meow-neko-ui-lato-font', '//fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap'); |
| 48 |
wp_enqueue_style( 'meow-neko-ui-lato-font' ); |
| 49 |
|
| 50 |
// Localize and options |
| 51 |
wp_localize_script( 'mwcode_snippet_vault', 'mwcode_snippet_vault', [ |
| 52 |
'api_url' => rest_url( 'code-engine/v1' ), |
| 53 |
'rest_url' => rest_url(), |
| 54 |
'plugin_url' => MWCODE_URL, |
| 55 |
'prefix' => MWCODE_PREFIX, |
| 56 |
'domain' => MWCODE_DOMAIN, |
| 57 |
'is_pro' => class_exists( 'MeowPro_MWCODE_Core' ), |
| 58 |
'is_registered' => !!$this->is_registered(), |
| 59 |
'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
| 60 |
'options' => $this->core->get_all_options(), |
| 61 |
] ); |
| 62 |
} |
| 63 |
|
| 64 |
function is_registered() { |
| 65 |
return apply_filters( MWCODE_PREFIX . '_meowapps_is_registered', false, MWCODE_PREFIX ); |
| 66 |
} |
| 67 |
|
| 68 |
function app_menu() { |
| 69 |
add_submenu_page( 'meowapps-main-menu', 'Code Engine', 'Code Engine', 'manage_options', |
| 70 |
'mwcode_settings', array( $this, 'admin_settings' ) ); |
| 71 |
} |
| 72 |
|
| 73 |
function admin_settings() { |
| 74 |
echo '<div id="mwcode-admin-settings"></div>'; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
?> |