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