screens
3 years ago
action.php
3 years ago
api.php
3 years ago
base.php
3 years ago
plugin-status.php
3 years ago
base.php
191 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', ['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 | 'cpt' => $cptName, |
| 85 | 'resturl' => get_rest_url(), |
| 86 | 'adminurl' => get_admin_url(), |
| 87 | 'siteurl' => get_option('siteurl'), |
| 88 | 'rest_nonce' => wp_create_nonce('wp_rest'), |
| 89 | 'plugin_url' => \ShopEngine::plugin_url(), |
| 90 | 'pricing_page' => \ShopEngine::landing_page(), |
| 91 | 'form_prefix' => \ShopEngine::SHOPENGINE_PREFIX, |
| 92 | 'template_types' => json_encode($page_templates), |
| 93 | 'elementor_installed' => did_action('elementor/loaded') ? 'yes' : 'no', |
| 94 | 'supported_builders' => [ |
| 95 | \ShopEngine\Core\Builders\Action::EDIT_WITH_ELEMENTOR => 'Elementor', |
| 96 | \ShopEngine\Core\Builders\Action::EDIT_WITH_GUTENBERG => 'Gutenberg', |
| 97 | ], |
| 98 | 'default_builder' => did_action('elementor/loaded') ? \ShopEngine\Core\Builders\Action::EDIT_WITH_ELEMENTOR : \ShopEngine\Core\Builders\Action::EDIT_WITH_GUTENBERG, |
| 99 | 'license_activated_message' => sprintf(esc_html__('Congratulations! Your product is activated for "%s"', 'shopengine'), parse_url(home_url(), PHP_URL_HOST)), |
| 100 | 'is_rtl' => is_rtl() ? 'true' : 'false', |
| 101 | ]); |
| 102 | |
| 103 | wp_enqueue_style('shopengine-admin-style', \ShopEngine::plugin_url() . 'assets/css/admin-style.css', false, \ShopEngine::version()); |
| 104 | } |
| 105 | |
| 106 | if($screen->id == 'edit-shopengine-entry' || $screen->id == 'shopengine-entry') { |
| 107 | wp_enqueue_style('shopengine-ui', \ShopEngine::plugin_url() . 'assets/css/design-ui.css', false, \ShopEngine::version()); |
| 108 | wp_enqueue_script('shopengine-entry-script', \ShopEngine::plugin_url() . 'assets/js/admin-entry-script.js', [], \ShopEngine::version(), true); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | |
| 113 | function menu_getting_started() { |
| 114 | add_menu_page( |
| 115 | esc_html__('ShopEngine', 'shopengine'), |
| 116 | esc_html__('ShopEngine', 'shopengine'), |
| 117 | 'manage_options', |
| 118 | 'shopengine-settings', |
| 119 | [$this, 'redirect_to_content'], |
| 120 | \ShopEngine::plugin_url() . 'assets/images/icons/shopengine_icon_white.svg', |
| 121 | '58.7' |
| 122 | ); |
| 123 | |
| 124 | add_submenu_page( |
| 125 | 'shopengine-settings', |
| 126 | esc_html__('Getting Started', 'shopengine'), |
| 127 | esc_html__('Getting Started', 'shopengine'), |
| 128 | 'manage_options', |
| 129 | $this->menu_link_part . '#getting-started' |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | public function menu_others() { |
| 134 | add_submenu_page( |
| 135 | 'shopengine-settings', |
| 136 | esc_html__('Modules', 'shopengine'), |
| 137 | esc_html__('Modules', 'shopengine'), |
| 138 | 'manage_options', |
| 139 | $this->menu_link_part . '#shopengine-modules' |
| 140 | ); |
| 141 | |
| 142 | add_submenu_page( |
| 143 | 'shopengine-settings', |
| 144 | esc_html__('Widgets', 'shopengine'), |
| 145 | esc_html__('Widgets', 'shopengine'), |
| 146 | 'manage_options', |
| 147 | $this->menu_link_part . '#shopengine-widgets' |
| 148 | ); |
| 149 | |
| 150 | add_submenu_page( |
| 151 | 'shopengine-settings', |
| 152 | esc_html__('Get Help', 'shopengine'), |
| 153 | esc_html__('Get Help', 'shopengine'), |
| 154 | 'manage_options', |
| 155 | $this->menu_link_part . '#shopengine-get-help' |
| 156 | ); |
| 157 | |
| 158 | // license activation & go premium menu links |
| 159 | if(\ShopEngine::package_type() != 'free') { // is pro |
| 160 | add_submenu_page( |
| 161 | 'shopengine-settings', |
| 162 | '<span style="color: #49dd85;" class="shopengine_pro_license pro">' . esc_html__('License', 'shopengine') . '</span>', |
| 163 | '<span style="color: #49dd85;" class="shopengine_pro_license pro">' . esc_html__('License', 'shopengine') . '</span>', |
| 164 | 'manage_options', |
| 165 | $this->menu_link_part . '#shopengine-license' |
| 166 | ); |
| 167 | } else { // is free |
| 168 | add_submenu_page( |
| 169 | 'shopengine-settings', |
| 170 | '<span style="color: #f9b015;" class="shopengine_pro_aware pro">' . esc_html__('Upgrade to Premium', 'shopengine') . '</span>', |
| 171 | '<span style="color: #f9b015;" class="shopengine_pro_aware pro">' . esc_html__('Upgrade to Premium', 'shopengine') . '</span>', |
| 172 | 'manage_options', |
| 173 | \ShopEngine::landing_page() |
| 174 | ); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | function redirect_to_content() { |
| 179 | wp_redirect($this->menu_link_part . '#getting-started'); |
| 180 | } |
| 181 | |
| 182 | function content() { |
| 183 | $screen = get_current_screen(); |
| 184 | |
| 185 | if($screen->id == 'edit-' . Template_Cpt::TYPE) { |
| 186 | include_once \ShopEngine::plugin_dir() . 'core/settings/screens/default.php'; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | } |
| 191 |