base.php
130 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Core\Settings; |
| 4 | |
| 5 | use ShopEngine\Base\Common; |
| 6 | use ShopEngine\Traits\Singleton; |
| 7 | use ShopEngine\Core\Template_Cpt; |
| 8 | |
| 9 | defined('ABSPATH') || exit; |
| 10 | |
| 11 | class Base { |
| 12 | use Singleton; |
| 13 | |
| 14 | private $menu_link_part; |
| 15 | |
| 16 | |
| 17 | /** |
| 18 | * |
| 19 | * @since 1.0.0 |
| 20 | * |
| 21 | */ |
| 22 | public function init() { |
| 23 | new Api(); |
| 24 | |
| 25 | $this->menu_link_part = admin_url('edit.php?post_type=' . \ShopEngine\Core\Template_Cpt::TYPE); |
| 26 | |
| 27 | // check permission for manage user |
| 28 | if(current_user_can('manage_options')) { |
| 29 | add_action('admin_menu', [$this, 'admin_menu']); |
| 30 | } |
| 31 | |
| 32 | add_action('admin_enqueue_scripts', [$this, 'js_css_admin']); |
| 33 | add_action('admin_footer', [$this, 'content']); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | public function js_css_admin() { |
| 38 | |
| 39 | wp_enqueue_style('shopengine-admin-style-common', \ShopEngine::plugin_url() . 'assets/css/admin-style-common.css', false, \ShopEngine::version()); |
| 40 | |
| 41 | // get screen id |
| 42 | $screen = get_current_screen(); |
| 43 | |
| 44 | $cptName = \ShopEngine\Core\Template_Cpt::TYPE; |
| 45 | |
| 46 | $dashboardPage = 'toplevel_page_shopengine-settings'; |
| 47 | |
| 48 | if(in_array($screen->id, ['edit-' . $cptName, 'shopengine_page_mt-form-settings', $dashboardPage])) { |
| 49 | |
| 50 | wp_enqueue_script('htm', \ShopEngine::plugin_url() . 'assets/js/htm.js', null, \ShopEngine::version(), true); |
| 51 | |
| 52 | wp_enqueue_script('shopengine-admin-js', \ShopEngine::plugin_url() . 'assets/js/app.js', array('htm', 'jquery', 'wp-element'), \ShopEngine::version(), true); |
| 53 | |
| 54 | wp_localize_script('shopengine-admin-js', 'shopengine_admin_var', [ |
| 55 | 'version' => \ShopEngine::version(), |
| 56 | 'package_type' => \ShopEngine::package_type(), |
| 57 | 'license_status' => \ShopEngine::license_status(), |
| 58 | 'license_activated_message' => sprintf( esc_html__('Congratulations! Your product is activated for "%s"', 'shopengine'), parse_url(home_url(), PHP_URL_HOST)), |
| 59 | 'cpt' => $cptName, |
| 60 | 'resturl' => get_rest_url(), |
| 61 | 'adminurl' => get_admin_url(), |
| 62 | 'siteurl' => get_option('siteurl'), |
| 63 | 'rest_nonce' => wp_create_nonce('wp_rest'), |
| 64 | 'plugin_url' => \ShopEngine::plugin_url(), |
| 65 | 'form_prefix' => \ShopEngine::SHOPENGINE_PREFIX, |
| 66 | 'template_types' => json_encode(\ShopEngine\Core\Builders\Templates::get_template_types()), |
| 67 | ]); |
| 68 | |
| 69 | wp_enqueue_style('shopengine-admin-style', \ShopEngine::plugin_url() . 'assets/css/admin-style.css', false, \ShopEngine::version()); |
| 70 | } |
| 71 | |
| 72 | if($screen->id == 'edit-shopengine-entry' || $screen->id == 'shopengine-entry') { |
| 73 | wp_enqueue_style('shopengine-ui', \ShopEngine::plugin_url() . 'assets/css/design-ui.css', false, \ShopEngine::version()); |
| 74 | wp_enqueue_script('shopengine-entry-script', \ShopEngine::plugin_url() . 'assets/js/admin-entry-script.js', array(), \ShopEngine::version(), true); |
| 75 | } |
| 76 | |
| 77 | } |
| 78 | |
| 79 | |
| 80 | function admin_menu() { |
| 81 | |
| 82 | add_menu_page( |
| 83 | esc_html__('ShopEngine', 'shopengine'), |
| 84 | esc_html__('ShopEngine', 'shopengine'), |
| 85 | 'manage_options', |
| 86 | 'shopengine-settings', |
| 87 | [$this, 'redirect_to_content'], |
| 88 | \ShopEngine::plugin_url() . 'assets/images/icons/shopengine_icon_white.svg', |
| 89 | '58.7' |
| 90 | ); |
| 91 | |
| 92 | add_submenu_page( |
| 93 | 'shopengine-settings', |
| 94 | esc_html__('Getting Started', 'shopengine'), |
| 95 | esc_html__('Getting Started', 'shopengine'), |
| 96 | 'manage_options', |
| 97 | $this->menu_link_part . '#getting-started' |
| 98 | ); |
| 99 | |
| 100 | add_submenu_page( |
| 101 | 'shopengine-settings', |
| 102 | esc_html__('Widgets', 'shopengine'), |
| 103 | esc_html__('Widgets', 'shopengine'), |
| 104 | 'manage_options', |
| 105 | $this->menu_link_part . '#shopengine-widgets' |
| 106 | ); |
| 107 | |
| 108 | add_submenu_page( |
| 109 | 'shopengine-settings', |
| 110 | esc_html__('Modules', 'shopengine'), |
| 111 | esc_html__('Modules', 'shopengine'), |
| 112 | 'manage_options', |
| 113 | $this->menu_link_part . '#shopengine-modules' |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | function redirect_to_content() { |
| 118 | wp_redirect($this->menu_link_part . '#getting-started'); |
| 119 | } |
| 120 | |
| 121 | function content() { |
| 122 | $screen = get_current_screen(); |
| 123 | |
| 124 | if($screen->id == 'edit-' . Template_Cpt::TYPE) { |
| 125 | include_once \ShopEngine::plugin_dir() . 'core/settings/screens/default.php'; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | } |
| 130 |