| @@ -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,22 +14,17 @@ | ||
| 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; |
| 16 | -use Elementor\Modules\Promotions\Controls\Atomic_Promotion_Control; | |
| 17 | -use Elementor\Modules\Promotions\Conversion_Banner; | |
| 20 | +use Elementor\Modules\Promotions\AdminMenuItems\Popups_Promotion_Item; | |
| 18 | 21 | use Elementor\Modules\Promotions\Pointers\Birthday; |
| 19 | 22 | use Elementor\Modules\Promotions\Pointers\Black_Friday; |
| 20 | -use Elementor\Modules\Promotions\PropTypes\Promotion_Prop_Type; | |
| 21 | -use Elementor\Modules\Promotions\Widgets\Ally_Dashboard_Widget; | |
| 22 | -use Elementor\Modules\Promotions\Widgets\Atomic_Form_Widget_Promotion; | |
| 23 | -use Elementor\Modules\Promotions\Widgets\Collection_Loop_Widget_Promotion; | |
| 24 | 23 | use Elementor\Widgets_Manager; |
| 25 | 24 | use Elementor\Utils; |
| 26 | 25 | use Elementor\Includes\EditorAssetsAPI; |
| 27 | 26 | use Elementor\Plugin; |
| 28 | -use Elementor\Modules\EditorOne\Classes\Menu_Config; | |
| 29 | 27 | use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; |
| 30 | 28 | |
| 31 | 29 | if ( ! defined( 'ABSPATH' ) ) { |
| 32 | 30 | exit; // Exit if accessed directly. |
| @@ -38,9 +36,9 @@ | ||
| 38 | 36 | |
| 39 | 37 | const ADMIN_MENU_PROMOTIONS_PRIORITY = 120; |
| 40 | 38 | |
| 41 | 39 | public static function is_active() { |
| 42 | - return ! Utils::has_pro() || ! Utils::is_license_active(); | |
| 40 | + return ! Utils::has_pro(); | |
| 43 | 41 | } |
| 44 | 42 | |
| 45 | 43 | public function get_name() { |
| 46 | 44 | return 'promotions'; |
| @@ -48,28 +46,23 @@ | ||
| 48 | 46 | |
| 49 | 47 | public function __construct() { |
| 50 | 48 | parent::__construct(); |
| 51 | 49 | |
| 52 | - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] ); | |
| 53 | - | |
| 54 | - if ( Utils::has_pro() ) { | |
| 55 | - add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] ); | |
| 56 | - $this->register_atomic_promotions(); | |
| 57 | - | |
| 58 | - return; | |
| 59 | - } | |
| 60 | - | |
| 61 | 50 | add_action( 'admin_init', function () { |
| 62 | 51 | $this->handle_external_redirects(); |
| 63 | 52 | } ); |
| 64 | 53 | |
| 54 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 55 | + $this->register_menu_items( $admin_menu ); | |
| 56 | + }, static::ADMIN_MENU_PRIORITY ); | |
| 57 | + | |
| 65 | 58 | add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { |
| 66 | 59 | $this->register_editor_one_menu_items( $menu_data_provider ); |
| 67 | 60 | } ); |
| 68 | 61 | |
| 69 | - if ( Utils::is_sale_time() ) { | |
| 70 | - add_filter( 'add_menu_classes', [ $this, 'override_one_menu_upgrade_label_during_sale' ] ); | |
| 71 | - } | |
| 62 | + add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) { | |
| 63 | + $this->register_promotion_menu_item( $admin_menu ); | |
| 64 | + }, static::ADMIN_MENU_PROMOTIONS_PRIORITY ); | |
| 72 | 65 | |
| 73 | 66 | add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) { |
| 74 | 67 | foreach ( Api::get_promotion_widgets() as $widget_data ) { |
| 75 | 68 | $manager->register( new Widgets\Pro_Widget_Promotion( [], [ |
| @@ -86,14 +79,12 @@ | ||
| 86 | 79 | if ( Black_Friday::should_display_notice() ) { |
| 87 | 80 | new Black_Friday(); |
| 88 | 81 | } |
| 89 | 82 | |
| 90 | - if ( Conversion_Banner::should_display_banner() ) { | |
| 91 | - new Conversion_Banner(); | |
| 83 | + if ( Utils::has_pro() ) { | |
| 84 | + return; | |
| 92 | 85 | } |
| 93 | 86 | |
| 94 | - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_editing_panel_sticky_promotion' ] ); | |
| 95 | - | |
| 96 | 87 | add_action( 'elementor/controls/register', function ( Controls_Manager $controls_manager ) { |
| 97 | 88 | $controls_manager->register( new Controls\Promotion_Control() ); |
| 98 | 89 | } ); |
| 99 | 90 | |
| @@ -98,24 +89,13 @@ | ||
| 98 | 89 | } ); |
| 99 | 90 | |
| 100 | 91 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] ); |
| 101 | 92 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] ); |
| 93 | + add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] ); | |
| 102 | 94 | |
| 103 | - // Add Ally promo | |
| 104 | - Ally_Dashboard_Widget::init(); | |
| 105 | - | |
| 106 | - $this->register_atomic_promotions(); | |
| 95 | + $this->register_display_conditions_promo_hooks(); | |
| 107 | 96 | } |
| 108 | 97 | |
| 109 | - /** | |
| 110 | - * Get Ally Scanner URL | |
| 111 | - * | |
| 112 | - * @return string | |
| 113 | - */ | |
| 114 | - public static function get_ally_external_scanner_url(): string { | |
| 115 | - return apply_filters( 'elementor/ally_external_scanner_url', 'https://go.elementor.com/acc-checker-dashboard-plg' ); | |
| 116 | - } | |
| 117 | - | |
| 118 | 98 | private function handle_external_redirects() { |
| 119 | 99 | $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
| 120 | 100 | if ( empty( $page ) ) { |
| 121 | 101 | return; |
| @@ -120,32 +100,22 @@ | ||
| 120 | 100 | if ( empty( $page ) ) { |
| 121 | 101 | return; |
| 122 | 102 | } |
| 123 | 103 | |
| 124 | - if ( in_array( $page, [ 'go_elementor_pro', 'elementor-one-upgrade' ], true ) ) { | |
| 104 | + if ( 'go_elementor_pro' === $page ) { | |
| 125 | 105 | wp_redirect( Go_Pro_Promotion_Item::get_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect |
| 126 | 106 | die; |
| 127 | 107 | } |
| 128 | 108 | } |
| 129 | 109 | |
| 130 | - public function override_one_menu_upgrade_label_during_sale( $menu ) { | |
| 131 | - global $submenu; | |
| 132 | - | |
| 133 | - $parent_slug = Menu_Config::ELEMENTOR_HOME_MENU_SLUG; | |
| 134 | - $upgrade_slug = 'elementor-one-upgrade'; | |
| 135 | - | |
| 136 | - if ( empty( $submenu[ $parent_slug ] ) ) { | |
| 137 | - return $menu; | |
| 110 | + private function register_menu_items( Admin_Menu_Manager $admin_menu ) { | |
| 111 | + if ( ! $this->is_editor_one_active() ) { | |
| 112 | + $admin_menu->register( 'e-form-submissions', new Form_Submissions_Promotion_Item() ); | |
| 113 | + $admin_menu->register( 'elementor_custom_fonts', new Custom_Fonts_Promotion_Item() ); | |
| 114 | + $admin_menu->register( 'elementor_custom_icons', new Custom_Icons_Promotion_Item() ); | |
| 115 | + $admin_menu->register( 'elementor_custom_code', new Custom_Code_Promotion_Item() ); | |
| 116 | + $admin_menu->register( 'popup_templates', new Popups_Promotion_Item() ); | |
| 138 | 117 | } |
| 139 | - | |
| 140 | - foreach ( $submenu[ $parent_slug ] as &$item ) { | |
| 141 | - if ( isset( $item[2] ) && $upgrade_slug === $item[2] ) { | |
| 142 | - $item[0] = esc_html__( 'Sale!', 'elementor' ) . '<br />' . esc_html__( 'Upgrade Now', 'elementor' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | |
| 143 | - break; | |
| 144 | - } | |
| 145 | - } | |
| 146 | - | |
| 147 | - return $menu; | |
| 148 | 118 | } |
| 149 | 119 | |
| 150 | 120 | private function register_editor_one_menu_items( Menu_Data_Provider $menu_data_provider ) { |
| 151 | 121 | $menu_data_provider->register_menu( new Editor_One_Custom_Elements_Menu() ); |
| @@ -155,8 +125,14 @@ | ||
| 155 | 125 | $menu_data_provider->register_menu( new Editor_One_Custom_Code_Menu() ); |
| 156 | 126 | $menu_data_provider->register_menu( new Editor_One_Popups_Menu() ); |
| 157 | 127 | } |
| 158 | 128 | |
| 129 | + private function register_promotion_menu_item( Admin_Menu_Manager $admin_menu ) { | |
| 130 | + if ( ! $this->is_editor_one_active() ) { | |
| 131 | + $admin_menu->register( 'go_elementor_pro', new Go_Pro_Promotion_Item() ); | |
| 132 | + } | |
| 133 | + } | |
| 134 | + | |
| 159 | 135 | public function enqueue_react_data(): void { |
| 160 | 136 | if ( ! current_user_can( 'manage_options' ) ) { |
| 161 | 137 | return; |
| 162 | 138 | } |
| @@ -171,9 +147,8 @@ | ||
| 171 | 147 | 'react-dom', |
| 172 | 148 | 'backbone-marionette', |
| 173 | 149 | 'elementor-editor-modules', |
| 174 | 150 | 'elementor-v2-ui', |
| 175 | - 'elementor-v2-icons', | |
| 176 | 151 | ], |
| 177 | 152 | ELEMENTOR_VERSION, |
| 178 | 153 | true |
| 179 | 154 | ); |
| @@ -222,18 +197,8 @@ | ||
| 222 | 197 | EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell', |
| 223 | 198 | ]; |
| 224 | 199 | } |
| 225 | 200 | |
| 226 | - public function add_editing_panel_sticky_promotion( array $settings ): array { | |
| 227 | - if ( ! Plugin::$instance->experiments->is_feature_active( 'e_panel_promotions' ) ) { | |
| 228 | - return $settings; | |
| 229 | - } | |
| 230 | - | |
| 231 | - $settings['editingPanelStickyPromotion'] = Filtered_Promotions_Manager::get_editor_panel_sticky_promotion(); | |
| 232 | - | |
| 233 | - return $settings; | |
| 234 | - } | |
| 235 | - | |
| 236 | 201 | public function add_v4_promotions_data( array $settings ): array { |
| 237 | 202 | if ( ! current_user_can( 'manage_options' ) ) { |
| 238 | 203 | return $settings; |
| 239 | 204 | } |
| @@ -253,73 +218,56 @@ | ||
| 253 | 218 | EditorAssetsAPI::ASSETS_DATA_KEY => 'promotions', |
| 254 | 219 | ]; |
| 255 | 220 | } |
| 256 | 221 | |
| 222 | + private function is_editor_one_active(): bool { | |
| 223 | + return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' ); | |
| 224 | + } | |
| 225 | + | |
| 257 | 226 | private function is_atomic_widgets_active(): bool { |
| 258 | 227 | return Plugin::$instance->experiments->is_feature_active( 'e_atomic_elements' ); |
| 259 | 228 | } |
| 260 | 229 | |
| 261 | - private function get_atomic_promotion_configs(): array { | |
| 262 | - return [ | |
| 263 | - [ | |
| 264 | - 'key' => 'attributes', | |
| 265 | - 'label' => __( 'Attributes', 'elementor' ), | |
| 266 | - 'section' => 'settings', | |
| 267 | - 'priority' => 40, | |
| 268 | - ], | |
| 269 | - [ | |
| 270 | - 'key' => 'display-conditions', | |
| 271 | - 'label' => __( 'Display Conditions', 'elementor' ), | |
| 272 | - 'section' => 'settings', | |
| 273 | - 'priority' => 50, | |
| 274 | - ], | |
| 275 | - ]; | |
| 276 | - } | |
| 277 | - | |
| 278 | - private function register_atomic_promotions(): void { | |
| 230 | + private function register_display_conditions_promo_hooks(): void { | |
| 279 | 231 | add_action( 'elementor/init', function() { |
| 280 | 232 | if ( ! $this->is_atomic_widgets_active() ) { |
| 281 | 233 | return; |
| 282 | 234 | } |
| 283 | 235 | |
| 236 | + require_once __DIR__ . '/prop-types/display-conditions-prop-type.php'; | |
| 237 | + require_once __DIR__ . '/controls/display-conditions-promotion-control.php'; | |
| 238 | + | |
| 284 | 239 | add_filter( |
| 285 | 240 | 'elementor/atomic-widgets/props-schema', |
| 286 | - [ $this, 'inject_atomic_promotion_props' ] | |
| 241 | + [ $this, 'inject_display_conditions_promo_prop' ] | |
| 287 | 242 | ); |
| 288 | 243 | |
| 289 | - foreach ( $this->get_atomic_promotion_configs() as $config ) { | |
| 290 | - add_filter( | |
| 291 | - 'elementor/atomic-widgets/controls', | |
| 292 | - fn( array $controls, $element ) => $this->inject_atomic_promotion_control( $controls, $element, $config ), | |
| 293 | - $config['priority'], | |
| 294 | - 2 | |
| 295 | - ); | |
| 296 | - } | |
| 244 | + add_filter( | |
| 245 | + 'elementor/atomic-widgets/controls', | |
| 246 | + [ $this, 'inject_display_conditions_promo_control' ], | |
| 247 | + 50, | |
| 248 | + 2 | |
| 249 | + ); | |
| 297 | 250 | } ); |
| 298 | - | |
| 299 | - ( new Atomic_Form_Widget_Promotion() )->register(); | |
| 300 | - ( new Collection_Loop_Widget_Promotion() )->register(); | |
| 301 | 251 | } |
| 302 | 252 | |
| 303 | - public function inject_atomic_promotion_props( array $schema ): array { | |
| 304 | - foreach ( $this->get_atomic_promotion_configs() as $config ) { | |
| 305 | - $key = $config['key']; | |
| 253 | + public function inject_display_conditions_promo_prop( array $schema ): array { | |
| 254 | + $prop_key = PropTypes\Display_Conditions_Prop_Type::get_key(); | |
| 306 | 255 | |
| 307 | - if ( isset( $schema[ $key ] ) ) { | |
| 308 | - continue; | |
| 309 | - } | |
| 256 | + if ( isset( $schema[ $prop_key ] ) ) { | |
| 257 | + return $schema; | |
| 258 | + } | |
| 310 | 259 | |
| 311 | - $schema[ $key ] = Promotion_Prop_Type::make( $key ); | |
| 312 | - } | |
| 260 | + $schema[ $prop_key ] = PropTypes\Display_Conditions_Prop_Type::make(); | |
| 313 | 261 | |
| 314 | 262 | return $schema; |
| 315 | 263 | } |
| 316 | 264 | |
| 317 | - protected function inject_atomic_promotion_control( array $element_controls, $atomic_element, array $config ): array { | |
| 318 | - $key = $config['key']; | |
| 265 | + public function inject_display_conditions_promo_control( array $element_controls, $atomic_element ): array { | |
| 266 | + $prop_key = PropTypes\Display_Conditions_Prop_Type::get_key(); | |
| 319 | 267 | $schema = $atomic_element::get_props_schema(); |
| 320 | 268 | |
| 321 | - if ( ! array_key_exists( $key, $schema ) ) { | |
| 269 | + if ( ! array_key_exists( $prop_key, $schema ) ) { | |
| 322 | 270 | return $element_controls; |
| 323 | 271 | } |
| 324 | 272 | |
| 325 | 273 | foreach ( $element_controls as $item ) { |
| @@ -326,14 +274,14 @@ | ||
| 326 | 274 | if ( ! ( $item instanceof \Elementor\Modules\AtomicWidgets\Controls\Section ) ) { |
| 327 | 275 | continue; |
| 328 | 276 | } |
| 329 | 277 | |
| 330 | - if ( $item->get_id() !== $config['section'] ) { | |
| 278 | + if ( $item->get_id() !== 'settings' ) { | |
| 331 | 279 | continue; |
| 332 | 280 | } |
| 333 | 281 | |
| 334 | - $control = Atomic_Promotion_Control::make( $key ) | |
| 335 | - ->set_label( $config['label'] ) | |
| 282 | + $control = Controls\Display_Conditions_Promotion_Control::bind_to( $prop_key ) | |
| 283 | + ->set_label( __( 'Display Conditions', 'elementor' ) ) | |
| 336 | 284 | ->set_meta( [ |
| 337 | 285 | 'topDivider' => true, |
| 338 | 286 | ] ); |
| 339 | 287 | |