| @@ -1,234 +1,119 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Admin Init. | |
| 4 | - * | |
| 5 | - * @package RadiusTheme\SB | |
| 6 | - */ | |
| 7 | - | |
| 8 | -namespace RadiusTheme\SB\Controllers\Admin; | |
| 9 | - | |
| 10 | -defined( 'ABSPATH' ) || exit(); | |
| 11 | - | |
| 12 | -use RadiusTheme\SB\Helpers\Fns; | |
| 13 | -use RadiusTheme\SB\Traits\SingletonTrait; | |
| 14 | -use RadiusTheme\SB\Controllers\Admin\Ajax as Ajax; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * Admin Init. | |
| 18 | - */ | |
| 19 | -class AdminInit { | |
| 20 | - /** | |
| 21 | - * Parent Menu Page Slug | |
| 22 | - */ | |
| 23 | - const MENU_PAGE_SLUG = 'rtsb'; | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * Menu capability | |
| 27 | - */ | |
| 28 | - const MENU_CAPABILITY = 'manage_options'; | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * Parent Menu Hook | |
| 32 | - * | |
| 33 | - * @var string | |
| 34 | - */ | |
| 35 | - public static $parent_menu_hook = ''; | |
| 36 | - | |
| 37 | - use SingletonTrait; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * Class constructor. | |
| 41 | - */ | |
| 42 | - public function __construct() { | |
| 43 | - $this->init(); | |
| 44 | - $this->ajax_actions(); | |
| 45 | - $this->upgrade(); | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * Admin Ajax hooks. | |
| 50 | - * | |
| 51 | - * @return void | |
| 52 | - */ | |
| 53 | - public function ajax_actions() { | |
| 54 | - Ajax\DefaultTemplate::instance(); | |
| 55 | - if ( defined( 'ELEMENTOR_VERSION' ) ) { // Elementor Check. | |
| 56 | - Ajax\CreateTemplate::instance(); | |
| 57 | - } | |
| 58 | - Ajax\ModalTemplate::instance(); | |
| 59 | - Ajax\AdminSettings::instance(); | |
| 60 | - } | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * Upgrade Notice. | |
| 64 | - * | |
| 65 | - * @return void | |
| 66 | - */ | |
| 67 | - public function upgrade() { | |
| 68 | - Notice\Upgrade::instance(); | |
| 69 | - // phpcs:ignore Squiz.PHP.CommentedOutCode.Found | |
| 70 | - // Notice\BFDiscount::instance();. | |
| 71 | - // phpcs:ignore Squiz.PHP.CommentedOutCode.Found | |
| 72 | - // Notice\BlackFridayV2::instance();. | |
| 73 | - Notice\Review::instance(); | |
| 74 | - Notice\CachePermission::instance(); | |
| 75 | - } | |
| 76 | - | |
| 77 | - /** | |
| 78 | - * Init. | |
| 79 | - * | |
| 80 | - * @return void | |
| 81 | - */ | |
| 82 | - public function init() { | |
| 83 | - add_action( 'admin_menu', [ $this, 'add_menu' ], 25 ); | |
| 84 | - add_action( 'in_admin_header', [ $this, 'in_admin_header_functionality' ], 1000 ); | |
| 85 | - // PluginRow registered earlier in ShopBuilder::init() so it survives dependency failures. | |
| 86 | - } | |
| 87 | - | |
| 88 | - /** | |
| 89 | - * Add menu. | |
| 90 | - * | |
| 91 | - * @return void | |
| 92 | - */ | |
| 93 | - public function add_menu() { | |
| 94 | - self::$parent_menu_hook = add_menu_page( | |
| 95 | - esc_html__( 'ShopBuilder', 'shopbuilder' ), | |
| 96 | - esc_html__( 'ShopBuilder', 'shopbuilder' ), | |
| 97 | - self::MENU_CAPABILITY, | |
| 98 | - self::MENU_PAGE_SLUG, | |
| 99 | - null, | |
| 100 | - RTSB_URL . '/assets/images/icon/shopbuilder-logo-white.svg', | |
| 101 | - '55.6' | |
| 102 | - ); | |
| 103 | - | |
| 104 | - add_submenu_page( | |
| 105 | - self::MENU_PAGE_SLUG, | |
| 106 | - esc_html__( 'Settings', 'shopbuilder' ), | |
| 107 | - esc_html__( 'Settings', 'shopbuilder' ), | |
| 108 | - self::MENU_CAPABILITY, | |
| 109 | - 'rtsb-settings', | |
| 110 | - [ $this, 'settings_page' ], | |
| 111 | - ); | |
| 112 | - add_submenu_page( | |
| 113 | - self::MENU_PAGE_SLUG, | |
| 114 | - esc_html__( 'Get Help', 'shopbuilder' ), | |
| 115 | - esc_html__( 'Get Help', 'shopbuilder' ), | |
| 116 | - self::MENU_CAPABILITY, | |
| 117 | - 'rtsb-get-help', | |
| 118 | - [ $this, 'get_help_page' ], | |
| 119 | - ); | |
| 120 | - add_submenu_page( | |
| 121 | - self::MENU_PAGE_SLUG, | |
| 122 | - esc_html__( 'Themes', 'shopbuilder' ), | |
| 123 | - esc_html__( 'Themes', 'shopbuilder' ), | |
| 124 | - self::MENU_CAPABILITY, | |
| 125 | - 'rtsb-themes', | |
| 126 | - [ $this, 'get_themes_page' ], | |
| 127 | - ); | |
| 128 | - do_action( 'rtsb/add/more/submenu', self::MENU_PAGE_SLUG, self::MENU_CAPABILITY ); | |
| 129 | - | |
| 130 | - // Remove Parent Submenu. | |
| 131 | - remove_submenu_page( self::MENU_PAGE_SLUG, self::MENU_PAGE_SLUG ); | |
| 132 | - } | |
| 133 | - | |
| 134 | - /** | |
| 135 | - * Redirect to content. | |
| 136 | - * | |
| 137 | - * @return void | |
| 138 | - */ | |
| 139 | - public function redirect_to_content() { | |
| 140 | - wp_redirect( admin_url( 'admin.php?page=rtsb-settings' ) ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect | |
| 141 | - } | |
| 142 | - | |
| 143 | - /** | |
| 144 | - * Settings Page. | |
| 145 | - * | |
| 146 | - * @return void | |
| 147 | - */ | |
| 148 | - public function settings_page() { | |
| 149 | - ?> | |
| 150 | - <div class="wrap rtsb-admin-wrap"> | |
| 151 | - <div id="rtsb-admin-app"></div> | |
| 152 | - </div> | |
| 153 | - <?php | |
| 154 | - } | |
| 155 | - | |
| 156 | - /** | |
| 157 | - * Help Page. | |
| 158 | - * | |
| 159 | - * @return void | |
| 160 | - */ | |
| 161 | - public function get_help_page() { | |
| 162 | - Fns::renderView( 'help' ); | |
| 163 | - } | |
| 164 | - | |
| 165 | - /** | |
| 166 | - * Themes Page. | |
| 167 | - * | |
| 168 | - * @return void | |
| 169 | - */ | |
| 170 | - public function get_themes_page() { | |
| 171 | - Fns::renderView( 'themes' ); | |
| 172 | - } | |
| 173 | - | |
| 174 | - /** | |
| 175 | - * Admin Header | |
| 176 | - */ | |
| 177 | - public function in_admin_header_functionality() { | |
| 178 | - $screen = get_current_screen(); | |
| 179 | - $isBuilderTemplate = 'edit-rtsb_builder' === $screen->id; | |
| 180 | - $pages = [ | |
| 181 | - 'shopbuilder_page_rtsb-get-help', | |
| 182 | - 'shopbuilder_page_rtsb-settings', | |
| 183 | - 'shopbuilder_page_rtsb-license', | |
| 184 | - 'shopbuilder_page_rtsb-themes', | |
| 185 | - ]; | |
| 186 | - $isSettingsPage = in_array( $screen->base, $pages, true ); | |
| 187 | - if ( $isBuilderTemplate || $isSettingsPage ) { | |
| 188 | - remove_all_actions( 'admin_notices' ); | |
| 189 | - remove_all_actions( 'all_admin_notices' ); | |
| 190 | - } | |
| 191 | - | |
| 192 | - $load_elementor_scripts = Fns::should_load_elementor_scripts(); | |
| 193 | - | |
| 194 | - if ( $isBuilderTemplate ) { | |
| 195 | - if ( ! defined( 'ELEMENTOR_VERSION' ) && $load_elementor_scripts ) { | |
| 196 | - ?> | |
| 197 | - <div class='rtsb-message-for-elementor-missing'> | |
| 198 | - <div class="rtsb-builder-notice-content"> | |
| 199 | - <?php | |
| 200 | - echo sprintf( | |
| 201 | - /* translators: %s: Elementor */ | |
| 202 | - esc_html__( 'To build your WooCommerce pages, please Install and Activate the %s Plugin.', 'shopbuilder' ), | |
| 203 | - '<a href="' . esc_url( admin_url( 'plugin-install.php?s=elementor&tab=search&type=term' ) ) . '" target="_blank">' . esc_html__( 'Elementor Website Builder', 'shopbuilder' ) . '</a>' | |
| 204 | - ); | |
| 205 | - ?> | |
| 206 | - </div> | |
| 207 | - </div> | |
| 208 | - <?php | |
| 209 | - } elseif ( defined( 'ELEMENTOR_VERSION' ) && ! $load_elementor_scripts ) { | |
| 210 | - ?> | |
| 211 | - <div class='rtsb-message-for-elementor-missing'> | |
| 212 | - <div class="rtsb-builder-notice-content"> | |
| 213 | - <?php esc_html_e( 'Elementor is installed, but script loading is disabled. Please enable "Load Elementor Scripts" in the Advanced Optimization Settings.', 'shopbuilder' ); ?> | |
| 214 | - </div> | |
| 215 | - </div> | |
| 216 | - <?php | |
| 217 | - } elseif ( ! defined( 'ELEMENTOR_VERSION' ) && ! $load_elementor_scripts ) { | |
| 218 | - ?> | |
| 219 | - <div class='rtsb-message-for-elementor-missing'> | |
| 220 | - <div class="rtsb-builder-notice-content"> | |
| 221 | - <?php | |
| 222 | - echo sprintf( | |
| 223 | - /* translators: %s: Elementor */ | |
| 224 | - esc_html__( 'To build your WooCommerce pages, please Install and Activate the %s Plugin.', 'shopbuilder' ), | |
| 225 | - '<a href="' . esc_url( admin_url( 'plugin-install.php?s=Elementor%2520Website%2520Builder&tab=search&type=term' ) ) . '" target="_blank">' . esc_html__( 'Elementor Website Builder', 'shopbuilder' ) . '</a>' | |
| 226 | - ); | |
| 227 | - ?> | |
| 228 | - </div> | |
| 229 | - </div> | |
| 230 | - <?php | |
| 231 | - } | |
| 232 | - } | |
| 233 | - } | |
| 234 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace RadiusTheme\SB\Controllers\Admin; | |
| 4 | + | |
| 5 | +defined( 'ABSPATH' ) || exit(); | |
| 6 | + | |
| 7 | +use RadiusTheme\SB\Controllers\Admin\Ajax as Ajax; | |
| 8 | +use RadiusTheme\SB\Traits\SingletonTrait; | |
| 9 | + | |
| 10 | +class AdminInit { | |
| 11 | + /** | |
| 12 | + * Parent Menu Page Slug | |
| 13 | + */ | |
| 14 | + const MENU_PAGE_SLUG = 'rtsb'; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * Menu capability | |
| 18 | + */ | |
| 19 | + const MENU_CAPABILITY = 'manage_options'; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * Parent Menu Hook | |
| 23 | + * | |
| 24 | + * @var string | |
| 25 | + */ | |
| 26 | + static $parent_menu_hook = ''; | |
| 27 | + | |
| 28 | + private $menu_link_part; | |
| 29 | + | |
| 30 | + use SingletonTrait; | |
| 31 | + | |
| 32 | + public function __construct() { | |
| 33 | + $this->menu_link_part = admin_url( 'admin.php?page=rtsb' ); | |
| 34 | + $this->remove_all_notices(); | |
| 35 | + $this->init(); | |
| 36 | + $this->ajax_actions(); | |
| 37 | + $this->upgrade(); | |
| 38 | + } | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Admin Ajax hooks. | |
| 42 | + * | |
| 43 | + * @return void | |
| 44 | + */ | |
| 45 | + public function ajax_actions() { | |
| 46 | + Ajax\DefaultTemplate::instance(); | |
| 47 | + Ajax\ModalTemplate::instance(); | |
| 48 | + Ajax\CreateTemplate::instance(); | |
| 49 | + Ajax\AdminSettings::instance(); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Upgrade Notice. | |
| 54 | + * | |
| 55 | + * @return void | |
| 56 | + */ | |
| 57 | + public function upgrade() { | |
| 58 | + Notice\Upgrade::instance(); | |
| 59 | + } | |
| 60 | + | |
| 61 | + public function init() { | |
| 62 | + add_action( 'admin_menu', [ $this, 'add_menu' ], 25 ); | |
| 63 | + } | |
| 64 | + | |
| 65 | + public function add_menu() { | |
| 66 | + self::$parent_menu_hook = add_menu_page( | |
| 67 | + esc_html__( 'ShopBuilder', 'shopbuilder' ), | |
| 68 | + esc_html__( 'ShopBuilder', 'shopbuilder' ), | |
| 69 | + self::MENU_CAPABILITY, | |
| 70 | + self::MENU_PAGE_SLUG, | |
| 71 | + null, | |
| 72 | + RTSB_URL . '/assets/images/icon/shopbuilder-logo-white.svg', | |
| 73 | + '55.6' | |
| 74 | + ); | |
| 75 | + | |
| 76 | + add_submenu_page( | |
| 77 | + self::MENU_PAGE_SLUG, | |
| 78 | + esc_html__( 'Settings', 'shopbuilder' ), | |
| 79 | + esc_html__( 'Settings', 'shopbuilder' ), | |
| 80 | + self::MENU_CAPABILITY, | |
| 81 | + 'rtsb-settings', | |
| 82 | + [ $this, 'settings_page' ], | |
| 83 | + ); | |
| 84 | + | |
| 85 | + // Remove Parent Submenu | |
| 86 | + remove_submenu_page( self::MENU_PAGE_SLUG, self::MENU_PAGE_SLUG ); | |
| 87 | + } | |
| 88 | + | |
| 89 | + function redirect_to_content() { | |
| 90 | + wp_redirect( admin_url( 'admin.php?page=rtsb-settings' ) ); | |
| 91 | + } | |
| 92 | + | |
| 93 | + | |
| 94 | + public function settings_page() { | |
| 95 | + ?> | |
| 96 | + <div class="wrap rtsb-admin-wrap"> | |
| 97 | + <div id="rtsb-admin-app"></div> | |
| 98 | + </div> | |
| 99 | + <?php | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Remove admin notices | |
| 104 | + */ | |
| 105 | + public function remove_all_notices() { | |
| 106 | + add_action( | |
| 107 | + 'in_admin_header', | |
| 108 | + function () { | |
| 109 | + $screen = get_current_screen(); | |
| 110 | + if ( 'shopbuilder_page_rtsb-settings' === $screen->base ) { | |
| 111 | + remove_all_actions( 'admin_notices' ); | |
| 112 | + remove_all_actions( 'all_admin_notices' ); | |
| 113 | + } | |
| 114 | + }, | |
| 115 | + 1000 | |
| 116 | + ); | |
| 117 | + } | |
| 118 | + | |
| 119 | +} | |