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