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