| @@ -3,33 +3,22 @@ | ||
| 3 | 3 | namespace Elementor\Modules\Promotions; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Api; |
| 6 | 6 | use Elementor\Controls_Manager; |
| 7 | +use Elementor\Core\Admin\Menu\Admin_Menu_Manager; | |
| 7 | 8 | use Elementor\Core\Base\Module as Base_Module; |
| 8 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Code_Menu; | |
| 9 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Elements_Menu; | |
| 10 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Fonts_Menu; | |
| 11 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Icons_Menu; | |
| 12 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Popups_Menu; | |
| 13 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Submissions_Menu; | |
| 9 | +use Elementor\Modules\Promotions\AdminMenuItems\Custom_Code_Promotion_Item; | |
| 10 | +use Elementor\Modules\Promotions\AdminMenuItems\Custom_Fonts_Promotion_Item; | |
| 11 | +use Elementor\Modules\Promotions\AdminMenuItems\Custom_Icons_Promotion_Item; | |
| 12 | +use Elementor\Modules\Promotions\AdminMenuItems\Form_Submissions_Promotion_Item; | |
| 14 | 13 | use Elementor\Modules\Promotions\AdminMenuItems\Go_Pro_Promotion_Item; |
| 15 | -use Elementor\Modules\Promotions\Controls\Atomic_Promotion_Control; | |
| 16 | -use Elementor\Modules\Promotions\Conversion_Banner; | |
| 17 | -use Elementor\Modules\Promotions\Pointers\Birthday; | |
| 18 | -use Elementor\Modules\Promotions\Pointers\Black_Friday; | |
| 19 | -use Elementor\Modules\Promotions\PropTypes\Promotion_Prop_Type; | |
| 20 | -use Elementor\Modules\Promotions\Widgets\Ally_Dashboard_Widget; | |
| 21 | -use Elementor\Modules\Promotions\Widgets\Atomic_Form_Widget_Promotion; | |
| 22 | -use Elementor\Modules\Promotions\Widgets\Birthday_Easter_Egg_Promotion; | |
| 14 | +use Elementor\Modules\Promotions\AdminMenuItems\Popups_Promotion_Item; | |
| 23 | 15 | use Elementor\Widgets_Manager; |
| 24 | 16 | use Elementor\Utils; |
| 25 | 17 | use Elementor\Includes\EditorAssetsAPI; |
| 26 | -use Elementor\Plugin; | |
| 27 | -use Elementor\Modules\EditorOne\Classes\Menu_Config; | |
| 28 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 29 | 18 | |
| 30 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 31 | - exit; // Exit if accessed directly. | |
| 20 | + exit; // Exit if accessed directly | |
| 32 | 21 | } |
| 33 | 22 | |
| 34 | 23 | class Module extends Base_Module { |
| 35 | 24 | |
| @@ -51,15 +40,15 @@ | ||
| 51 | 40 | add_action( 'admin_init', function () { |
| 52 | 41 | $this->handle_external_redirects(); |
| 53 | 42 | } ); |
| 54 | 43 | |
| 55 | - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { | |
| 56 | - $this->register_editor_one_menu_items( $menu_data_provider ); | |
| 57 | - } ); | |
| 44 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 45 | + $this->register_menu_items( $admin_menu ); | |
| 46 | + }, static::ADMIN_MENU_PRIORITY ); | |
| 58 | 47 | |
| 59 | - if ( Utils::is_sale_time() ) { | |
| 60 | - add_filter( 'add_menu_classes', [ $this, 'override_one_menu_upgrade_label_during_sale' ] ); | |
| 61 | - } | |
| 48 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 49 | + $this->register_promotion_menu_item( $admin_menu ); | |
| 50 | + }, static::ADMIN_MENU_PROMOTIONS_PRIORITY ); | |
| 62 | 51 | |
| 63 | 52 | add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) { |
| 64 | 53 | foreach ( Api::get_promotion_widgets() as $widget_data ) { |
| 65 | 54 | $manager->register( new Widgets\Pro_Widget_Promotion( [], [ |
| @@ -68,22 +57,8 @@ | ||
| 68 | 57 | ] ) ); |
| 69 | 58 | } |
| 70 | 59 | } ); |
| 71 | 60 | |
| 72 | - if ( Birthday::should_display_notice() ) { | |
| 73 | - new Birthday(); | |
| 74 | - } | |
| 75 | - | |
| 76 | - if ( Black_Friday::should_display_notice() ) { | |
| 77 | - new Black_Friday(); | |
| 78 | - } | |
| 79 | - | |
| 80 | - if ( Conversion_Banner::should_display_banner() ) { | |
| 81 | - new Conversion_Banner(); | |
| 82 | - } | |
| 83 | - | |
| 84 | - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] ); | |
| 85 | - | |
| 86 | 61 | if ( Utils::has_pro() ) { |
| 87 | 62 | return; |
| 88 | 63 | } |
| 89 | 64 | |
| @@ -91,64 +66,31 @@ | ||
| 91 | 66 | $controls_manager->register( new Controls\Promotion_Control() ); |
| 92 | 67 | } ); |
| 93 | 68 | |
| 94 | 69 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] ); |
| 95 | - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] ); | |
| 96 | - | |
| 97 | - // Add Ally promo | |
| 98 | - Ally_Dashboard_Widget::init(); | |
| 99 | - | |
| 100 | - $this->register_atomic_promotions(); | |
| 101 | 70 | } |
| 102 | 71 | |
| 103 | - /** | |
| 104 | - * Get Ally Scanner URL | |
| 105 | - * | |
| 106 | - * @return string | |
| 107 | - */ | |
| 108 | - public static function get_ally_external_scanner_url(): string { | |
| 109 | - return apply_filters( 'elementor/ally_external_scanner_url', 'https://go.elementor.com/acc-checker-dashboard-plg' ); | |
| 110 | - } | |
| 111 | - | |
| 112 | 72 | private function handle_external_redirects() { |
| 113 | - $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); | |
| 114 | - if ( empty( $page ) ) { | |
| 73 | + if ( empty( $_GET['page'] ) ) { | |
| 115 | 74 | return; |
| 116 | 75 | } |
| 117 | 76 | |
| 118 | - if ( 'go_elementor_pro' === $page ) { | |
| 119 | - wp_redirect( Go_Pro_Promotion_Item::get_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect | |
| 77 | + if ( 'go_elementor_pro' === $_GET['page'] ) { | |
| 78 | + wp_redirect( Go_Pro_Promotion_Item::get_url() ); | |
| 120 | 79 | die; |
| 121 | 80 | } |
| 122 | 81 | } |
| 123 | 82 | |
| 124 | - public function override_one_menu_upgrade_label_during_sale( $menu ) { | |
| 125 | - global $submenu; | |
| 126 | - | |
| 127 | - $parent_slug = Menu_Config::ELEMENTOR_HOME_MENU_SLUG; | |
| 128 | - $upgrade_slug = 'elementor-one-upgrade'; | |
| 129 | - | |
| 130 | - if ( empty( $submenu[ $parent_slug ] ) ) { | |
| 131 | - return $menu; | |
| 132 | - } | |
| 133 | - | |
| 134 | - foreach ( $submenu[ $parent_slug ] as &$item ) { | |
| 135 | - if ( isset( $item[2] ) && $upgrade_slug === $item[2] ) { | |
| 136 | - $item[0] = esc_html__( 'Sale!', 'elementor' ) . '<br />' . esc_html__( 'Upgrade Now', 'elementor' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | |
| 137 | - break; | |
| 138 | - } | |
| 139 | - } | |
| 140 | - | |
| 141 | - return $menu; | |
| 83 | + private function register_menu_items( Admin_Menu_Manager $admin_menu ) { | |
| 84 | + $admin_menu->register( 'e-form-submissions', new Form_Submissions_Promotion_Item() ); | |
| 85 | + $admin_menu->register( 'elementor_custom_fonts', new Custom_Fonts_Promotion_Item() ); | |
| 86 | + $admin_menu->register( 'elementor_custom_icons', new Custom_Icons_Promotion_Item() ); | |
| 87 | + $admin_menu->register( 'elementor_custom_code', new Custom_Code_Promotion_Item() ); | |
| 88 | + $admin_menu->register( 'popup_templates', new Popups_Promotion_Item() ); | |
| 142 | 89 | } |
| 143 | 90 | |
| 144 | - private function register_editor_one_menu_items( Menu_Data_Provider $menu_data_provider ) { | |
| 145 | - $menu_data_provider->register_menu( new Editor_One_Custom_Elements_Menu() ); | |
| 146 | - $menu_data_provider->register_menu( new Editor_One_Submissions_Menu() ); | |
| 147 | - $menu_data_provider->register_menu( new Editor_One_Fonts_Menu() ); | |
| 148 | - $menu_data_provider->register_menu( new Editor_One_Icons_Menu() ); | |
| 149 | - $menu_data_provider->register_menu( new Editor_One_Custom_Code_Menu() ); | |
| 150 | - $menu_data_provider->register_menu( new Editor_One_Popups_Menu() ); | |
| 91 | + private function register_promotion_menu_item( Admin_Menu_Manager $admin_menu ) { | |
| 92 | + $admin_menu->register( 'go_elementor_pro', new Go_Pro_Promotion_Item() ); | |
| 151 | 93 | } |
| 152 | 94 | |
| 153 | 95 | public function enqueue_react_data(): void { |
| 154 | 96 | if ( ! current_user_can( 'manage_options' ) ) { |
| @@ -163,10 +105,8 @@ | ||
| 163 | 105 | [ |
| 164 | 106 | 'react', |
| 165 | 107 | 'react-dom', |
| 166 | 108 | 'backbone-marionette', |
| 167 | - 'elementor-editor-modules', | |
| 168 | - 'elementor-v2-ui', | |
| 169 | 109 | ], |
| 170 | 110 | ELEMENTOR_VERSION, |
| 171 | 111 | true |
| 172 | 112 | ); |
| @@ -179,29 +119,8 @@ | ||
| 179 | 119 | $this->get_app_js_config() |
| 180 | 120 | ); |
| 181 | 121 | } |
| 182 | 122 | |
| 183 | - public function enqueue_editor_v4_alphachip(): void { | |
| 184 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 185 | - return; | |
| 186 | - } | |
| 187 | - | |
| 188 | - $min_suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 189 | - | |
| 190 | - wp_enqueue_script( | |
| 191 | - 'editor-v4-opt-in-alphachip', | |
| 192 | - ELEMENTOR_ASSETS_URL . 'js/editor-v4-opt-in-alphachip' . $min_suffix . '.js', | |
| 193 | - [ | |
| 194 | - 'react', | |
| 195 | - 'react-dom', | |
| 196 | - 'elementor-common', | |
| 197 | - 'elementor-v2-ui', | |
| 198 | - ], | |
| 199 | - ELEMENTOR_VERSION, | |
| 200 | - true | |
| 201 | - ); | |
| 202 | - } | |
| 203 | - | |
| 204 | 123 | private function get_app_js_config(): array { |
| 205 | 124 | $editor_assets_api = new EditorAssetsAPI( $this->get_api_config() ); |
| 206 | 125 | $promotion_data = new PromotionData( $editor_assets_api ); |
| 207 | 126 | |
| @@ -213,118 +132,6 @@ | ||
| 213 | 132 | EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/free-to-pro-upsell/v1/free-to-pro-upsell.json', |
| 214 | 133 | EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_free_to_pro_upsell', |
| 215 | 134 | EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell', |
| 216 | 135 | ]; |
| 217 | - } | |
| 218 | - | |
| 219 | - public function add_v4_promotions_data( array $settings ): array { | |
| 220 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 221 | - return $settings; | |
| 222 | - } | |
| 223 | - | |
| 224 | - $editor_assets_api = new EditorAssetsAPI( $this->get_v4_promotions_api_config() ); | |
| 225 | - $promotion_data = new PromotionData( $editor_assets_api ); | |
| 226 | - | |
| 227 | - $settings['v4Promotions'] = $promotion_data->get_v4_promotions_data(); | |
| 228 | - | |
| 229 | - return $settings; | |
| 230 | - } | |
| 231 | - | |
| 232 | - private function get_v4_promotions_api_config(): array { | |
| 233 | - return [ | |
| 234 | - EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/packages/v1/promotions.json', | |
| 235 | - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_v4_promotions', | |
| 236 | - EditorAssetsAPI::ASSETS_DATA_KEY => 'promotions', | |
| 237 | - ]; | |
| 238 | - } | |
| 239 | - | |
| 240 | - private function is_atomic_widgets_active(): bool { | |
| 241 | - return Plugin::$instance->experiments->is_feature_active( 'e_atomic_elements' ); | |
| 242 | - } | |
| 243 | - | |
| 244 | - private function get_atomic_promotion_configs(): array { | |
| 245 | - return [ | |
| 246 | - [ | |
| 247 | - 'key' => 'attributes', | |
| 248 | - 'label' => __( 'Attributes', 'elementor' ), | |
| 249 | - 'section' => 'settings', | |
| 250 | - 'priority' => 40, | |
| 251 | - ], | |
| 252 | - [ | |
| 253 | - 'key' => 'display-conditions', | |
| 254 | - 'label' => __( 'Display Conditions', 'elementor' ), | |
| 255 | - 'section' => 'settings', | |
| 256 | - 'priority' => 50, | |
| 257 | - ], | |
| 258 | - ]; | |
| 259 | - } | |
| 260 | - | |
| 261 | - private function register_atomic_promotions(): void { | |
| 262 | - add_action( 'elementor/init', function() { | |
| 263 | - if ( ! $this->is_atomic_widgets_active() ) { | |
| 264 | - return; | |
| 265 | - } | |
| 266 | - | |
| 267 | - add_filter( | |
| 268 | - 'elementor/atomic-widgets/props-schema', | |
| 269 | - [ $this, 'inject_atomic_promotion_props' ] | |
| 270 | - ); | |
| 271 | - | |
| 272 | - foreach ( $this->get_atomic_promotion_configs() as $config ) { | |
| 273 | - add_filter( | |
| 274 | - 'elementor/atomic-widgets/controls', | |
| 275 | - fn( array $controls, $element ) => $this->inject_atomic_promotion_control( $controls, $element, $config ), | |
| 276 | - $config['priority'], | |
| 277 | - 2 | |
| 278 | - ); | |
| 279 | - } | |
| 280 | - | |
| 281 | - ( new Birthday_Easter_Egg_Promotion() )->register(); | |
| 282 | - } ); | |
| 283 | - | |
| 284 | - ( new Atomic_Form_Widget_Promotion() )->register(); | |
| 285 | - } | |
| 286 | - | |
| 287 | - public function inject_atomic_promotion_props( array $schema ): array { | |
| 288 | - foreach ( $this->get_atomic_promotion_configs() as $config ) { | |
| 289 | - $key = $config['key']; | |
| 290 | - | |
| 291 | - if ( isset( $schema[ $key ] ) ) { | |
| 292 | - continue; | |
| 293 | - } | |
| 294 | - | |
| 295 | - $schema[ $key ] = Promotion_Prop_Type::make( $key ); | |
| 296 | - } | |
| 297 | - | |
| 298 | - return $schema; | |
| 299 | - } | |
| 300 | - | |
| 301 | - protected function inject_atomic_promotion_control( array $element_controls, $atomic_element, array $config ): array { | |
| 302 | - $key = $config['key']; | |
| 303 | - $schema = $atomic_element::get_props_schema(); | |
| 304 | - | |
| 305 | - if ( ! array_key_exists( $key, $schema ) ) { | |
| 306 | - return $element_controls; | |
| 307 | - } | |
| 308 | - | |
| 309 | - foreach ( $element_controls as $item ) { | |
| 310 | - if ( ! ( $item instanceof \Elementor\Modules\AtomicWidgets\Controls\Section ) ) { | |
| 311 | - continue; | |
| 312 | - } | |
| 313 | - | |
| 314 | - if ( $item->get_id() !== $config['section'] ) { | |
| 315 | - continue; | |
| 316 | - } | |
| 317 | - | |
| 318 | - $control = Atomic_Promotion_Control::make( $key ) | |
| 319 | - ->set_label( $config['label'] ) | |
| 320 | - ->set_meta( [ | |
| 321 | - 'topDivider' => true, | |
| 322 | - ] ); | |
| 323 | - | |
| 324 | - $item->add_item( $control ); | |
| 325 | - break; | |
| 326 | - } | |
| 327 | - | |
| 328 | - return $element_controls; | |
| 329 | 136 | } |
| 330 | 137 | } |