| @@ -3,10 +3,13 @@ | ||
| 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\Core\Utils\Promotions\Filtered_Promotions_Manager; | |
| 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; | |
| 9 | 12 | use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Code_Menu; |
| 10 | 13 | use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Elements_Menu; |
| 11 | 14 | use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Fonts_Menu; |
| 12 | 15 | use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Icons_Menu; |
| @@ -11,21 +14,20 @@ | ||
| 11 | 14 | use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Fonts_Menu; |
| 12 | 15 | use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Icons_Menu; |
| 13 | 16 | use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Popups_Menu; |
| 14 | 17 | use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Submissions_Menu; |
| 18 | +use Elementor\Modules\Promotions\AdminMenuItems\Form_Submissions_Promotion_Item; | |
| 15 | 19 | use Elementor\Modules\Promotions\AdminMenuItems\Go_Pro_Promotion_Item; |
| 20 | +use Elementor\Modules\Promotions\AdminMenuItems\Popups_Promotion_Item; | |
| 16 | 21 | use Elementor\Modules\Promotions\Controls\Atomic_Promotion_Control; |
| 17 | -use Elementor\Modules\Promotions\Conversion_Banner; | |
| 18 | 22 | use Elementor\Modules\Promotions\Pointers\Birthday; |
| 19 | 23 | use Elementor\Modules\Promotions\Pointers\Black_Friday; |
| 20 | 24 | use Elementor\Modules\Promotions\PropTypes\Promotion_Prop_Type; |
| 21 | -use Elementor\Modules\Promotions\Widgets\Atomic_Form_Widget_Promotion; | |
| 22 | -use Elementor\Modules\Promotions\Widgets\Collection_Loop_Widget_Promotion; | |
| 25 | +use Elementor\Modules\Promotions\Widgets\Ally_Dashboard_Widget; | |
| 23 | 26 | use Elementor\Widgets_Manager; |
| 24 | 27 | use Elementor\Utils; |
| 25 | 28 | use Elementor\Includes\EditorAssetsAPI; |
| 26 | 29 | use Elementor\Plugin; |
| 27 | -use Elementor\Modules\EditorOne\Classes\Menu_Config; | |
| 28 | 30 | use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; |
| 29 | 31 | |
| 30 | 32 | if ( ! defined( 'ABSPATH' ) ) { |
| 31 | 33 | exit; // Exit if accessed directly. |
| @@ -37,9 +39,9 @@ | ||
| 37 | 39 | |
| 38 | 40 | const ADMIN_MENU_PROMOTIONS_PRIORITY = 120; |
| 39 | 41 | |
| 40 | 42 | public static function is_active() { |
| 41 | - return ! Utils::has_pro() || ! Utils::is_license_active(); | |
| 43 | + return ! Utils::has_pro(); | |
| 42 | 44 | } |
| 43 | 45 | |
| 44 | 46 | public function get_name() { |
| 45 | 47 | return 'promotions'; |
| @@ -47,28 +49,23 @@ | ||
| 47 | 49 | |
| 48 | 50 | public function __construct() { |
| 49 | 51 | parent::__construct(); |
| 50 | 52 | |
| 51 | - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] ); | |
| 52 | - | |
| 53 | - if ( Utils::has_pro() ) { | |
| 54 | - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] ); | |
| 55 | - $this->register_atomic_promotions(); | |
| 56 | - | |
| 57 | - return; | |
| 58 | - } | |
| 59 | - | |
| 60 | 53 | add_action( 'admin_init', function () { |
| 61 | 54 | $this->handle_external_redirects(); |
| 62 | 55 | } ); |
| 63 | 56 | |
| 57 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 58 | + $this->register_menu_items( $admin_menu ); | |
| 59 | + }, static::ADMIN_MENU_PRIORITY ); | |
| 60 | + | |
| 64 | 61 | add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { |
| 65 | 62 | $this->register_editor_one_menu_items( $menu_data_provider ); |
| 66 | 63 | } ); |
| 67 | 64 | |
| 68 | - if ( Utils::is_sale_time() ) { | |
| 69 | - add_filter( 'add_menu_classes', [ $this, 'override_one_menu_upgrade_label_during_sale' ] ); | |
| 70 | - } | |
| 65 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 66 | + $this->register_promotion_menu_item( $admin_menu ); | |
| 67 | + }, static::ADMIN_MENU_PROMOTIONS_PRIORITY ); | |
| 71 | 68 | |
| 72 | 69 | add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) { |
| 73 | 70 | foreach ( Api::get_promotion_widgets() as $widget_data ) { |
| 74 | 71 | $manager->register( new Widgets\Pro_Widget_Promotion( [], [ |
| @@ -85,14 +82,12 @@ | ||
| 85 | 82 | if ( Black_Friday::should_display_notice() ) { |
| 86 | 83 | new Black_Friday(); |
| 87 | 84 | } |
| 88 | 85 | |
| 89 | - if ( Conversion_Banner::should_display_banner() ) { | |
| 90 | - new Conversion_Banner(); | |
| 86 | + if ( Utils::has_pro() ) { | |
| 87 | + return; | |
| 91 | 88 | } |
| 92 | 89 | |
| 93 | - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_editing_panel_sticky_promotion' ] ); | |
| 94 | - | |
| 95 | 90 | add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) { |
| 96 | 91 | $controls_manager->register( new Controls\Promotion_Control() ); |
| 97 | 92 | } ); |
| 98 | 93 | |
| @@ -97,12 +92,25 @@ | ||
| 97 | 92 | } ); |
| 98 | 93 | |
| 99 | 94 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] ); |
| 100 | 95 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] ); |
| 96 | + add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] ); | |
| 101 | 97 | |
| 98 | + // Add Ally promo | |
| 99 | + Ally_Dashboard_Widget::init(); | |
| 100 | + | |
| 102 | 101 | $this->register_atomic_promotions(); |
| 103 | 102 | } |
| 104 | 103 | |
| 104 | + /** | |
| 105 | + * Get Ally Scanner URL | |
| 106 | + * | |
| 107 | + * @return string | |
| 108 | + */ | |
| 109 | + public static function get_ally_external_scanner_url(): string { | |
| 110 | + return apply_filters( 'elementor/ally_external_scanner_url', 'https://elementor.com/tools/ally-accessibility-checker/scanner' ); | |
| 111 | + } | |
| 112 | + | |
| 105 | 113 | private function handle_external_redirects() { |
| 106 | 114 | $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
| 107 | 115 | if ( empty( $page ) ) { |
| 108 | 116 | return; |
| @@ -107,32 +115,22 @@ | ||
| 107 | 115 | if ( empty( $page ) ) { |
| 108 | 116 | return; |
| 109 | 117 | } |
| 110 | 118 | |
| 111 | - if ( in_array( $page, [ 'go_elementor_pro', 'elementor-one-upgrade' ], true ) ) { | |
| 119 | + if ( 'go_elementor_pro' === $page ) { | |
| 112 | 120 | wp_redirect( Go_Pro_Promotion_Item::get_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect |
| 113 | 121 | die; |
| 114 | 122 | } |
| 115 | 123 | } |
| 116 | 124 | |
| 117 | - public function override_one_menu_upgrade_label_during_sale( $menu ) { | |
| 118 | - global $submenu; | |
| 119 | - | |
| 120 | - $parent_slug = Menu_Config::ELEMENTOR_HOME_MENU_SLUG; | |
| 121 | - $upgrade_slug = 'elementor-one-upgrade'; | |
| 122 | - | |
| 123 | - if ( empty( $submenu[ $parent_slug ] ) ) { | |
| 124 | - return $menu; | |
| 125 | + private function register_menu_items( Admin_Menu_Manager $admin_menu ) { | |
| 126 | + if ( ! $this->is_editor_one_active() ) { | |
| 127 | + $admin_menu->register( 'e-form-submissions', new Form_Submissions_Promotion_Item() ); | |
| 128 | + $admin_menu->register( 'elementor_custom_fonts', new Custom_Fonts_Promotion_Item() ); | |
| 129 | + $admin_menu->register( 'elementor_custom_icons', new Custom_Icons_Promotion_Item() ); | |
| 130 | + $admin_menu->register( 'elementor_custom_code', new Custom_Code_Promotion_Item() ); | |
| 131 | + $admin_menu->register( 'popup_templates', new Popups_Promotion_Item() ); | |
| 125 | 132 | } |
| 126 | - | |
| 127 | - foreach ( $submenu[ $parent_slug ] as &$item ) { | |
| 128 | - if ( isset( $item[2] ) && $upgrade_slug === $item[2] ) { | |
| 129 | - $item[0] = esc_html__( 'Sale!', 'elementor' ) . '<br />' . esc_html__( 'Upgrade Now', 'elementor' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | |
| 130 | - break; | |
| 131 | - } | |
| 132 | - } | |
| 133 | - | |
| 134 | - return $menu; | |
| 135 | 133 | } |
| 136 | 134 | |
| 137 | 135 | private function register_editor_one_menu_items( Menu_Data_Provider $menu_data_provider ) { |
| 138 | 136 | $menu_data_provider->register_menu( new Editor_One_Custom_Elements_Menu() ); |
| @@ -142,8 +140,14 @@ | ||
| 142 | 140 | $menu_data_provider->register_menu( new Editor_One_Custom_Code_Menu() ); |
| 143 | 141 | $menu_data_provider->register_menu( new Editor_One_Popups_Menu() ); |
| 144 | 142 | } |
| 145 | 143 | |
| 144 | + private function register_promotion_menu_item( Admin_Menu_Manager $admin_menu ) { | |
| 145 | + if ( ! $this->is_editor_one_active() ) { | |
| 146 | + $admin_menu->register( 'go_elementor_pro', new Go_Pro_Promotion_Item() ); | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 146 | 150 | public function enqueue_react_data(): void { |
| 147 | 151 | if ( ! current_user_can( 'manage_options' ) ) { |
| 148 | 152 | return; |
| 149 | 153 | } |
| @@ -158,9 +162,8 @@ | ||
| 158 | 162 | 'react-dom', |
| 159 | 163 | 'backbone-marionette', |
| 160 | 164 | 'elementor-editor-modules', |
| 161 | 165 | 'elementor-v2-ui', |
| 162 | - 'elementor-v2-icons', | |
| 163 | 166 | ], |
| 164 | 167 | ELEMENTOR_VERSION, |
| 165 | 168 | true |
| 166 | 169 | ); |
| @@ -209,18 +212,8 @@ | ||
| 209 | 212 | EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell', |
| 210 | 213 | ]; |
| 211 | 214 | } |
| 212 | 215 | |
| 213 | - public function add_editing_panel_sticky_promotion( array $settings ): array { | |
| 214 | - if ( ! Plugin::$instance->experiments->is_feature_active( 'e_panel_promotions' ) ) { | |
| 215 | - return $settings; | |
| 216 | - } | |
| 217 | - | |
| 218 | - $settings['editingPanelStickyPromotion'] = Filtered_Promotions_Manager::get_editor_panel_sticky_promotion(); | |
| 219 | - | |
| 220 | - return $settings; | |
| 221 | - } | |
| 222 | - | |
| 223 | 216 | public function add_v4_promotions_data( array $settings ): array { |
| 224 | 217 | if ( ! current_user_can( 'manage_options' ) ) { |
| 225 | 218 | return $settings; |
| 226 | 219 | } |
| @@ -240,8 +233,12 @@ | ||
| 240 | 233 | EditorAssetsAPI::ASSETS_DATA_KEY => 'promotions', |
| 241 | 234 | ]; |
| 242 | 235 | } |
| 243 | 236 | |
| 237 | + private function is_editor_one_active(): bool { | |
| 238 | + return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' ); | |
| 239 | + } | |
| 240 | + | |
| 244 | 241 | private function is_atomic_widgets_active(): bool { |
| 245 | 242 | return Plugin::$instance->experiments->is_feature_active( 'e_atomic_elements' ); |
| 246 | 243 | } |
| 247 | 244 | |
| @@ -281,11 +278,8 @@ | ||
| 281 | 278 | 2 |
| 282 | 279 | ); |
| 283 | 280 | } |
| 284 | 281 | } ); |
| 285 | - | |
| 286 | - ( new Atomic_Form_Widget_Promotion() )->register(); | |
| 287 | - ( new Collection_Loop_Widget_Promotion() )->register(); | |
| 288 | 282 | } |
| 289 | 283 | |
| 290 | 284 | public function inject_atomic_promotion_props( array $schema ): array { |
| 291 | 285 | foreach ( $this->get_atomic_promotion_configs() as $config ) { |