PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.3.7
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.3.7
0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.9 0.4.8 0.4.7 0.4.6 trunk 0.0.1 0.0.2 0.2.8 0.2.9 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 0.3.8 All 32 releases
← All changes | classes/admin.php +57 -30 0.0.10.3.7 View file →
@@ -1,51 +1,78 @@
1 1 <?php
2 -class Meow_CDEGN_Admin {
2 +class Meow_MWCODE_Admin extends MeowCommon_Admin {
3 3
4 4 public $core;
5 5
6 - /** @var Meow_CDEGN_List_Table */
7 - public $list_table;
8 -
9 - protected $menu_slug = 'cdegn_settings';
10 -
11 6 public function __construct( $core ) {
12 7 $this->core = $core;
13 8
9 + parent::__construct( MWCODE_PREFIX, MWCODE_ENTRY, MWCODE_DOMAIN, class_exists( 'MeowPro_MWCODE_Core' ) );
14 10 if ( is_admin() ) {
15 11 add_action( 'admin_menu', array( $this, 'app_menu' ) );
16 - add_filter( 'plugin_action_links_' . plugin_basename( CDEGN_ENTRY ), array( $this, 'plugin_action_links' ), 10, 2 );
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 + }
17 29 }
18 30 }
19 31
20 - public function app_menu() {
21 - // Needs to initialize the list before admin-header.php called.
22 - $this->list_table = new Meow_CDEGN_List_Table( $this->core );
32 + function admin_enqueue_scripts() {
23 33
24 - add_submenu_page( 'options-general.php', 'Code Engine', 'Code Engine', 'manage_options',
25 - $this->menu_slug, array( $this, 'admin_settings' ) );
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', 'wp-blocks', 'wp-block-editor', 'wp-components'], $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 + ] );
26 62 }
27 63
28 - public function admin_settings() {
29 - $this->list_table->prepare_items();
30 - include_once 'views/settings.php';
64 + function is_registered() {
65 + return apply_filters( MWCODE_PREFIX . '_meowapps_is_registered', false, MWCODE_PREFIX );
31 66 }
32 67
33 - public function plugin_action_links( array $actions, string $plugin_file ): array {
34 - if ( plugin_basename( CDEGN_ENTRY ) !== $plugin_file ) {
35 - return $actions;
36 - }
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 + }
37 72
38 - return array_merge(
39 - [
40 - sprintf(
41 - '<a href="%s">%s</a>',
42 - esc_url( add_query_arg( 'page', $this->menu_slug, admin_url( 'options-general.php' ) ) ),
43 - esc_html__( 'Settings', 'code-engine' )
44 - ),
45 - ],
46 - $actions,
47 - );
73 + function admin_settings() {
74 + echo '<div id="mwcode-admin-settings"></div>';
48 75 }
49 76 }
50 77
51 -?>
78 +?>