| @@ -3,30 +3,20 @@ | ||
| 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\Editor_One_Custom_Code_Menu; | |
| 10 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Custom_Elements_Menu; | |
| 11 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Fonts_Menu; | |
| 12 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Icons_Menu; | |
| 13 | -use Elementor\Modules\Promotions\AdminMenuItems\Editor_One_Popups_Menu; | |
| 14 | -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; | |
| 15 | 13 | use Elementor\Modules\Promotions\AdminMenuItems\Go_Pro_Promotion_Item; |
| 16 | -use Elementor\Modules\Promotions\Controls\Atomic_Promotion_Control; | |
| 17 | -use Elementor\Modules\Promotions\Conversion_Banner; | |
| 14 | +use Elementor\Modules\Promotions\AdminMenuItems\Popups_Promotion_Item; | |
| 18 | 15 | use Elementor\Modules\Promotions\Pointers\Birthday; |
| 19 | -use Elementor\Modules\Promotions\Pointers\Black_Friday; | |
| 20 | -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; | |
| 23 | 16 | use Elementor\Widgets_Manager; |
| 24 | 17 | use Elementor\Utils; |
| 25 | 18 | 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 | 19 | |
| 30 | 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 31 | 21 | exit; // Exit if accessed directly. |
| 32 | 22 | } |
| @@ -37,9 +27,9 @@ | ||
| 37 | 27 | |
| 38 | 28 | const ADMIN_MENU_PROMOTIONS_PRIORITY = 120; |
| 39 | 29 | |
| 40 | 30 | public static function is_active() { |
| 41 | - return ! Utils::has_pro() || ! Utils::is_license_active(); | |
| 31 | + return ! Utils::has_pro(); | |
| 42 | 32 | } |
| 43 | 33 | |
| 44 | 34 | public function get_name() { |
| 45 | 35 | return 'promotions'; |
| @@ -47,28 +37,19 @@ | ||
| 47 | 37 | |
| 48 | 38 | public function __construct() { |
| 49 | 39 | parent::__construct(); |
| 50 | 40 | |
| 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 | 41 | add_action( 'admin_init', function () { |
| 61 | 42 | $this->handle_external_redirects(); |
| 62 | 43 | } ); |
| 63 | 44 | |
| 64 | - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { | |
| 65 | - $this->register_editor_one_menu_items( $menu_data_provider ); | |
| 66 | - } ); | |
| 45 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 46 | + $this->register_menu_items( $admin_menu ); | |
| 47 | + }, static::ADMIN_MENU_PRIORITY ); | |
| 67 | 48 | |
| 68 | - if ( Utils::is_sale_time() ) { | |
| 69 | - add_filter( 'add_menu_classes', [ $this, 'override_one_menu_upgrade_label_during_sale' ] ); | |
| 70 | - } | |
| 49 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 50 | + $this->register_promotion_menu_item( $admin_menu ); | |
| 51 | + }, static::ADMIN_MENU_PROMOTIONS_PRIORITY ); | |
| 71 | 52 | |
| 72 | 53 | add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) { |
| 73 | 54 | foreach ( Api::get_promotion_widgets() as $widget_data ) { |
| 74 | 55 | $manager->register( new Widgets\Pro_Widget_Promotion( [], [ |
| @@ -81,18 +62,12 @@ | ||
| 81 | 62 | if ( Birthday::should_display_notice() ) { |
| 82 | 63 | new Birthday(); |
| 83 | 64 | } |
| 84 | 65 | |
| 85 | - if ( Black_Friday::should_display_notice() ) { | |
| 86 | - new Black_Friday(); | |
| 66 | + if ( Utils::has_pro() ) { | |
| 67 | + return; | |
| 87 | 68 | } |
| 88 | 69 | |
| 89 | - if ( Conversion_Banner::should_display_banner() ) { | |
| 90 | - new Conversion_Banner(); | |
| 91 | - } | |
| 92 | - | |
| 93 | - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_editing_panel_sticky_promotion' ] ); | |
| 94 | - | |
| 95 | 70 | add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) { |
| 96 | 71 | $controls_manager->register( new Controls\Promotion_Control() ); |
| 97 | 72 | } ); |
| 98 | 73 | |
| @@ -97,51 +72,31 @@ | ||
| 97 | 72 | } ); |
| 98 | 73 | |
| 99 | 74 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] ); |
| 100 | 75 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] ); |
| 101 | - | |
| 102 | - $this->register_atomic_promotions(); | |
| 103 | 76 | } |
| 104 | 77 | |
| 105 | 78 | private function handle_external_redirects() { |
| 106 | - $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); | |
| 107 | - if ( empty( $page ) ) { | |
| 79 | + if ( empty( $_GET['page'] ) ) { | |
| 108 | 80 | return; |
| 109 | 81 | } |
| 110 | 82 | |
| 111 | - if ( in_array( $page, [ 'go_elementor_pro', 'elementor-one-upgrade' ], true ) ) { | |
| 112 | - wp_redirect( Go_Pro_Promotion_Item::get_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect | |
| 83 | + if ( 'go_elementor_pro' === $_GET['page'] ) { | |
| 84 | + wp_redirect( Go_Pro_Promotion_Item::get_url() ); | |
| 113 | 85 | die; |
| 114 | 86 | } |
| 115 | 87 | } |
| 116 | 88 | |
| 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 | - } | |
| 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; | |
| 89 | + private function register_menu_items( Admin_Menu_Manager $admin_menu ) { | |
| 90 | + $admin_menu->register( 'e-form-submissions', new Form_Submissions_Promotion_Item() ); | |
| 91 | + $admin_menu->register( 'elementor_custom_fonts', new Custom_Fonts_Promotion_Item() ); | |
| 92 | + $admin_menu->register( 'elementor_custom_icons', new Custom_Icons_Promotion_Item() ); | |
| 93 | + $admin_menu->register( 'elementor_custom_code', new Custom_Code_Promotion_Item() ); | |
| 94 | + $admin_menu->register( 'popup_templates', new Popups_Promotion_Item() ); | |
| 135 | 95 | } |
| 136 | 96 | |
| 137 | - private function register_editor_one_menu_items( Menu_Data_Provider $menu_data_provider ) { | |
| 138 | - $menu_data_provider->register_menu( new Editor_One_Custom_Elements_Menu() ); | |
| 139 | - $menu_data_provider->register_menu( new Editor_One_Submissions_Menu() ); | |
| 140 | - $menu_data_provider->register_menu( new Editor_One_Fonts_Menu() ); | |
| 141 | - $menu_data_provider->register_menu( new Editor_One_Icons_Menu() ); | |
| 142 | - $menu_data_provider->register_menu( new Editor_One_Custom_Code_Menu() ); | |
| 143 | - $menu_data_provider->register_menu( new Editor_One_Popups_Menu() ); | |
| 97 | + private function register_promotion_menu_item( Admin_Menu_Manager $admin_menu ) { | |
| 98 | + $admin_menu->register( 'go_elementor_pro', new Go_Pro_Promotion_Item() ); | |
| 144 | 99 | } |
| 145 | 100 | |
| 146 | 101 | public function enqueue_react_data(): void { |
| 147 | 102 | if ( ! current_user_can( 'manage_options' ) ) { |
| @@ -158,9 +113,8 @@ | ||
| 158 | 113 | 'react-dom', |
| 159 | 114 | 'backbone-marionette', |
| 160 | 115 | 'elementor-editor-modules', |
| 161 | 116 | 'elementor-v2-ui', |
| 162 | - 'elementor-v2-icons', | |
| 163 | 117 | ], |
| 164 | 118 | ELEMENTOR_VERSION, |
| 165 | 119 | true |
| 166 | 120 | ); |
| @@ -207,127 +161,6 @@ | ||
| 207 | 161 | EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/free-to-pro-upsell/v1/free-to-pro-upsell.json', |
| 208 | 162 | EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_free_to_pro_upsell', |
| 209 | 163 | EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell', |
| 210 | 164 | ]; |
| 211 | - } | |
| 212 | - | |
| 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 | - public function add_v4_promotions_data( array $settings ): array { | |
| 224 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 225 | - return $settings; | |
| 226 | - } | |
| 227 | - | |
| 228 | - $editor_assets_api = new EditorAssetsAPI( $this->get_v4_promotions_api_config() ); | |
| 229 | - $promotion_data = new PromotionData( $editor_assets_api ); | |
| 230 | - | |
| 231 | - $settings['v4Promotions'] = $promotion_data->get_v4_promotions_data(); | |
| 232 | - | |
| 233 | - return $settings; | |
| 234 | - } | |
| 235 | - | |
| 236 | - private function get_v4_promotions_api_config(): array { | |
| 237 | - return [ | |
| 238 | - EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/packages/v1/promotions.json', | |
| 239 | - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_v4_promotions', | |
| 240 | - EditorAssetsAPI::ASSETS_DATA_KEY => 'promotions', | |
| 241 | - ]; | |
| 242 | - } | |
| 243 | - | |
| 244 | - private function is_atomic_widgets_active(): bool { | |
| 245 | - return Plugin::$instance->experiments->is_feature_active( 'e_atomic_elements' ); | |
| 246 | - } | |
| 247 | - | |
| 248 | - private function get_atomic_promotion_configs(): array { | |
| 249 | - return [ | |
| 250 | - [ | |
| 251 | - 'key' => 'attributes', | |
| 252 | - 'label' => __( 'Attributes', 'elementor' ), | |
| 253 | - 'section' => 'settings', | |
| 254 | - 'priority' => 40, | |
| 255 | - ], | |
| 256 | - [ | |
| 257 | - 'key' => 'display-conditions', | |
| 258 | - 'label' => __( 'Display Conditions', 'elementor' ), | |
| 259 | - 'section' => 'settings', | |
| 260 | - 'priority' => 50, | |
| 261 | - ], | |
| 262 | - ]; | |
| 263 | - } | |
| 264 | - | |
| 265 | - private function register_atomic_promotions(): void { | |
| 266 | - add_action( 'elementor/init', function() { | |
| 267 | - if ( ! $this->is_atomic_widgets_active() ) { | |
| 268 | - return; | |
| 269 | - } | |
| 270 | - | |
| 271 | - add_filter( | |
| 272 | - 'elementor/atomic-widgets/props-schema', | |
| 273 | - [ $this, 'inject_atomic_promotion_props' ] | |
| 274 | - ); | |
| 275 | - | |
| 276 | - foreach ( $this->get_atomic_promotion_configs() as $config ) { | |
| 277 | - add_filter( | |
| 278 | - 'elementor/atomic-widgets/controls', | |
| 279 | - fn( array $controls, $element ) => $this->inject_atomic_promotion_control( $controls, $element, $config ), | |
| 280 | - $config['priority'], | |
| 281 | - 2 | |
| 282 | - ); | |
| 283 | - } | |
| 284 | - } ); | |
| 285 | - | |
| 286 | - ( new Atomic_Form_Widget_Promotion() )->register(); | |
| 287 | - ( new Collection_Loop_Widget_Promotion() )->register(); | |
| 288 | - } | |
| 289 | - | |
| 290 | - public function inject_atomic_promotion_props( array $schema ): array { | |
| 291 | - foreach ( $this->get_atomic_promotion_configs() as $config ) { | |
| 292 | - $key = $config['key']; | |
| 293 | - | |
| 294 | - if ( isset( $schema[ $key ] ) ) { | |
| 295 | - continue; | |
| 296 | - } | |
| 297 | - | |
| 298 | - $schema[ $key ] = Promotion_Prop_Type::make( $key ); | |
| 299 | - } | |
| 300 | - | |
| 301 | - return $schema; | |
| 302 | - } | |
| 303 | - | |
| 304 | - protected function inject_atomic_promotion_control( array $element_controls, $atomic_element, array $config ): array { | |
| 305 | - $key = $config['key']; | |
| 306 | - $schema = $atomic_element::get_props_schema(); | |
| 307 | - | |
| 308 | - if ( ! array_key_exists( $key, $schema ) ) { | |
| 309 | - return $element_controls; | |
| 310 | - } | |
| 311 | - | |
| 312 | - foreach ( $element_controls as $item ) { | |
| 313 | - if ( ! ( $item instanceof \Elementor\Modules\AtomicWidgets\Controls\Section ) ) { | |
| 314 | - continue; | |
| 315 | - } | |
| 316 | - | |
| 317 | - if ( $item->get_id() !== $config['section'] ) { | |
| 318 | - continue; | |
| 319 | - } | |
| 320 | - | |
| 321 | - $control = Atomic_Promotion_Control::make( $key ) | |
| 322 | - ->set_label( $config['label'] ) | |
| 323 | - ->set_meta( [ | |
| 324 | - 'topDivider' => true, | |
| 325 | - ] ); | |
| 326 | - | |
| 327 | - $item->add_item( $control ); | |
| 328 | - break; | |
| 329 | - } | |
| 330 | - | |
| 331 | - return $element_controls; | |
| 332 | 165 | } |
| 333 | 166 | } |