base.php
185 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Core\Settings; |
| 4 | |
| 5 | use ShopEngine\Core\PageTemplates\Page_Templates; |
| 6 | use ShopEngine\Core\Template_Cpt; |
| 7 | use ShopEngine\Traits\Singleton; |
| 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 | |
| 24 | new Api(); |
| 25 | |
| 26 | $this->menu_link_part = admin_url('edit.php?post_type=' . \ShopEngine\Core\Template_Cpt::TYPE); |
| 27 | |
| 28 | // check permission for manage user |
| 29 | if(current_user_can('manage_options')) { |
| 30 | add_action('admin_menu', [$this, 'menu_getting_started']); |
| 31 | add_action('admin_menu', [$this, 'menu_others'], 100); |
| 32 | } |
| 33 | |
| 34 | add_action('admin_enqueue_scripts', function(){ |
| 35 | |
| 36 | if(isset($_REQUEST['post_type']) && $_REQUEST['post_type'] === \ShopEngine\Core\Template_Cpt::TYPE) { |
| 37 | |
| 38 | if(function_exists('wc_get_products') && !\ShopEngine\Core\Builders\Templates::has_simple_product()) { |
| 39 | |
| 40 | \ShopEngine\Core\Builders\Templates::create_wc_simple_product(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | }, 0); |
| 45 | |
| 46 | add_action('admin_head', [ $this, 'admin_head_enqueue_scripts']); |
| 47 | add_action('admin_enqueue_scripts', [$this, 'js_css_admin']); |
| 48 | add_action('admin_footer', [$this, 'content']); |
| 49 | } |
| 50 | |
| 51 | public function admin_head_enqueue_scripts() { |
| 52 | echo "<script> |
| 53 | jQuery(document).ready( function($) { |
| 54 | $('.toplevel_page_shopengine-settings').find('.wp-first-item').css({display:'none'}); |
| 55 | $('.shopengine_pro_aware').parent().attr('target','_blank'); |
| 56 | }); |
| 57 | </script>"; |
| 58 | } |
| 59 | |
| 60 | public function js_css_admin() { |
| 61 | |
| 62 | wp_enqueue_style('shopengine-admin-style-common', \ShopEngine::plugin_url() . 'assets/css/admin-style-common.css', false, \ShopEngine::version()); |
| 63 | |
| 64 | // get screen id |
| 65 | $screen = get_current_screen(); |
| 66 | |
| 67 | $cptName = \ShopEngine\Core\Template_Cpt::TYPE; |
| 68 | |
| 69 | $dashboardPage = 'toplevel_page_shopengine-settings'; |
| 70 | |
| 71 | if(in_array($screen->id, ['edit-' . $cptName, 'shopengine_page_mt-form-settings', $dashboardPage])) { |
| 72 | |
| 73 | wp_enqueue_script('htm', \ShopEngine::plugin_url() . 'assets/js/htm.js', null, \ShopEngine::version(), true); |
| 74 | |
| 75 | wp_enqueue_script('shopengine-admin-js', \ShopEngine::plugin_url() . 'assets/js/app.js', array('htm', 'jquery', 'wp-element'), \ShopEngine::version(), true); |
| 76 | |
| 77 | // page template lists |
| 78 | $page_templates = Page_Templates::instance()->getTemplates() ; |
| 79 | |
| 80 | wp_localize_script('shopengine-admin-js', 'shopengine_admin_var', [ |
| 81 | 'version' => \ShopEngine::version(), |
| 82 | 'package_type' => \ShopEngine::package_type(), |
| 83 | 'license_status' => \ShopEngine::license_status(), |
| 84 | 'license_activated_message' => sprintf( esc_html__('Congratulations! Your product is activated for "%s"', 'shopengine'), parse_url(home_url(), PHP_URL_HOST)), |
| 85 | 'cpt' => $cptName, |
| 86 | 'resturl' => get_rest_url(), |
| 87 | 'adminurl' => get_admin_url(), |
| 88 | 'siteurl' => get_option('siteurl'), |
| 89 | 'rest_nonce' => wp_create_nonce('wp_rest'), |
| 90 | 'plugin_url' => \ShopEngine::plugin_url(), |
| 91 | 'pricing_page' => \ShopEngine::landing_page(), |
| 92 | 'form_prefix' => \ShopEngine::SHOPENGINE_PREFIX, |
| 93 | 'template_types' => json_encode($page_templates), |
| 94 | ]); |
| 95 | |
| 96 | wp_enqueue_style('shopengine-admin-style', \ShopEngine::plugin_url() . 'assets/css/admin-style.css', false, \ShopEngine::version()); |
| 97 | } |
| 98 | |
| 99 | if($screen->id == 'edit-shopengine-entry' || $screen->id == 'shopengine-entry') { |
| 100 | wp_enqueue_style('shopengine-ui', \ShopEngine::plugin_url() . 'assets/css/design-ui.css', false, \ShopEngine::version()); |
| 101 | wp_enqueue_script('shopengine-entry-script', \ShopEngine::plugin_url() . 'assets/js/admin-entry-script.js', array(), \ShopEngine::version(), true); |
| 102 | } |
| 103 | |
| 104 | } |
| 105 | |
| 106 | |
| 107 | function menu_getting_started() { |
| 108 | add_menu_page( |
| 109 | esc_html__('ShopEngine', 'shopengine'), |
| 110 | esc_html__('ShopEngine', 'shopengine'), |
| 111 | 'manage_options', |
| 112 | 'shopengine-settings', |
| 113 | [$this, 'redirect_to_content'], |
| 114 | \ShopEngine::plugin_url() . 'assets/images/icons/shopengine_icon_white.svg', |
| 115 | '58.7' |
| 116 | ); |
| 117 | |
| 118 | add_submenu_page( |
| 119 | 'shopengine-settings', |
| 120 | esc_html__('Getting Started', 'shopengine'), |
| 121 | esc_html__('Getting Started', 'shopengine'), |
| 122 | 'manage_options', |
| 123 | $this->menu_link_part . '#getting-started' |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | public function menu_others(){ |
| 128 | add_submenu_page( |
| 129 | 'shopengine-settings', |
| 130 | esc_html__('Modules', 'shopengine'), |
| 131 | esc_html__('Modules', 'shopengine'), |
| 132 | 'manage_options', |
| 133 | $this->menu_link_part . '#shopengine-modules' |
| 134 | ); |
| 135 | |
| 136 | add_submenu_page( |
| 137 | 'shopengine-settings', |
| 138 | esc_html__('Widgets', 'shopengine'), |
| 139 | esc_html__('Widgets', 'shopengine'), |
| 140 | 'manage_options', |
| 141 | $this->menu_link_part . '#shopengine-widgets' |
| 142 | ); |
| 143 | |
| 144 | add_submenu_page( |
| 145 | 'shopengine-settings', |
| 146 | esc_html__('Get Help', 'shopengine'), |
| 147 | esc_html__('Get Help', 'shopengine'), |
| 148 | 'manage_options', |
| 149 | $this->menu_link_part . '#shopengine-get-help' |
| 150 | ); |
| 151 | |
| 152 | // license activation & go premium menu links |
| 153 | if(\ShopEngine::package_type() != 'free'){ // is pro |
| 154 | add_submenu_page( |
| 155 | 'shopengine-settings', |
| 156 | '<span style="color: #49dd85;" class="shopengine_pro_license pro">'.esc_html__('License', 'shopengine').'</span>', |
| 157 | '<span style="color: #49dd85;" class="shopengine_pro_license pro">'.esc_html__('License', 'shopengine').'</span>', |
| 158 | 'manage_options', |
| 159 | $this->menu_link_part . '#shopengine-license' |
| 160 | ); |
| 161 | }else{ // is free |
| 162 | add_submenu_page( |
| 163 | 'shopengine-settings', |
| 164 | '<span style="color: #f9b015;" class="shopengine_pro_aware pro">'.esc_html__('Upgrade to Premium', 'shopengine').'</span>', |
| 165 | '<span style="color: #f9b015;" class="shopengine_pro_aware pro">'.esc_html__('Upgrade to Premium', 'shopengine').'</span>', |
| 166 | 'manage_options', |
| 167 | \ShopEngine::landing_page() |
| 168 | ); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | function redirect_to_content() { |
| 173 | wp_redirect($this->menu_link_part . '#getting-started'); |
| 174 | } |
| 175 | |
| 176 | function content() { |
| 177 | $screen = get_current_screen(); |
| 178 | |
| 179 | if($screen->id == 'edit-' . Template_Cpt::TYPE) { |
| 180 | include_once \ShopEngine::plugin_dir() . 'core/settings/screens/default.php'; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | } |
| 185 |