| 1 |
<?php |
| 2 |
class Meow_SCLEGN_Admin extends MeowKit_SCLEGN_Admin { |
| 3 |
|
| 4 |
public $core; |
| 5 |
|
| 6 |
public function __construct( $core ) { |
| 7 |
parent::__construct( SCLEGN_PREFIX, SCLEGN_ENTRY, SCLEGN_DOMAIN, class_exists( 'MeowPro_SCLEGN_Core' ) ); |
| 8 |
if ( is_admin() ) { |
| 9 |
add_action( 'admin_menu', array( $this, 'app_menu' ) ); |
| 10 |
|
| 11 |
// Load the scripts only if they are needed by the current screen |
| 12 |
$page = isset( $_GET["page"] ) ? $_GET["page"] : null; |
| 13 |
$is_sclegn_screen = in_array( $page, [ 'sclegn_settings', 'sclegn_dashboard' ] ); |
| 14 |
$is_meowapps_dashboard = $page === 'meowapps-main-menu'; |
| 15 |
|
| 16 |
global $pagenow; |
| 17 |
$is_page_all_posts = $pagenow === 'edit.php' && (!isset($_GET['post_type']) || $_GET['post_type'] === 'post'); |
| 18 |
$is_page_all_custom_posts = $pagenow === 'edit.php' && isset($_GET['post_type']); |
| 19 |
|
| 20 |
if ( $is_meowapps_dashboard || $is_sclegn_screen || $is_page_all_posts || $is_page_all_custom_posts ) { |
| 21 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 22 |
} |
| 23 |
} |
| 24 |
$this->core = $core; |
| 25 |
} |
| 26 |
|
| 27 |
function admin_enqueue_scripts() { |
| 28 |
// Load the scripts |
| 29 |
$physical_file = SCLEGN_PATH . '/app/index.js'; |
| 30 |
$cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : SCLEGN_VERSION; |
| 31 |
wp_register_script( 'sclegn_social_engine-vendor', SCLEGN_URL . 'app/vendor.js', |
| 32 |
['wp-element', 'wp-i18n'], $cache_buster |
| 33 |
); |
| 34 |
wp_register_script( 'sclegn_social_engine', SCLEGN_URL . 'app/index.js', |
| 35 |
['sclegn_social_engine-vendor', 'wp-i18n'], $cache_buster |
| 36 |
); |
| 37 |
wp_set_script_translations( 'sclegn_social_engine', 'social-engine' ); |
| 38 |
wp_enqueue_script('sclegn_social_engine' ); |
| 39 |
|
| 40 |
// Load the fonts |
| 41 |
wp_register_style( 'meow-neko-ui-lato-font', '//fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap'); |
| 42 |
wp_enqueue_style( 'meow-neko-ui-lato-font' ); |
| 43 |
|
| 44 |
// Localize and options |
| 45 |
wp_localize_script( 'sclegn_social_engine', 'sclegn_social_engine', [ |
| 46 |
'api_url' => rest_url( 'social-engine/v1' ), |
| 47 |
'rest_url' => rest_url(), |
| 48 |
'plugin_url' => SCLEGN_URL, |
| 49 |
'prefix' => SCLEGN_PREFIX, |
| 50 |
'domain' => SCLEGN_DOMAIN, |
| 51 |
'is_pro' => class_exists( 'MeowPro_SCLEGN_Core' ), |
| 52 |
'is_registered' => !!$this->is_registered(), |
| 53 |
'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
| 54 |
'post_types' => $this->core->make_post_type_list( $this->core->get_post_types() ), |
| 55 |
'post_tags' => $this->core->get_post_tags(), |
| 56 |
'languages' => $this->core->get_available_languages(), |
| 57 |
'options' => $this->core->get_all_options(), |
| 58 |
]); |
| 59 |
} |
| 60 |
|
| 61 |
function is_registered() { |
| 62 |
return apply_filters( SCLEGN_PREFIX . '_meowapps_is_registered', false, SCLEGN_PREFIX ); |
| 63 |
} |
| 64 |
|
| 65 |
function app_menu() { |
| 66 |
add_submenu_page( 'meowapps-main-menu', 'Social Engine', 'Social Engine', 'manage_options', |
| 67 |
'sclegn_settings', array( $this, 'admin_settings' ) ); |
| 68 |
} |
| 69 |
|
| 70 |
function admin_settings() { |
| 71 |
echo wp_kses_post( '<div id="sclegn-admin-settings"></div>' ); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
?> |