| @@ -3,27 +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\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; | |
| 14 | +use Elementor\Modules\Promotions\AdminMenuItems\Popups_Promotion_Item; | |
| 16 | 15 | use Elementor\Modules\Promotions\Pointers\Birthday; |
| 17 | -use Elementor\Modules\Promotions\Pointers\Black_Friday; | |
| 18 | -use Elementor\Modules\Promotions\PropTypes\Promotion_Prop_Type; | |
| 19 | -use Elementor\Modules\Promotions\Widgets\Ally_Dashboard_Widget; | |
| 20 | -use Elementor\Modules\Promotions\Widgets\Atomic_Form_Widget_Promotion; | |
| 21 | 16 | use Elementor\Widgets_Manager; |
| 22 | 17 | use Elementor\Utils; |
| 23 | 18 | use Elementor\Includes\EditorAssetsAPI; |
| 24 | -use Elementor\Plugin; | |
| 25 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 26 | 19 | |
| 27 | 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 28 | 21 | exit; // Exit if accessed directly. |
| 29 | 22 | } |
| @@ -48,12 +41,16 @@ | ||
| 48 | 41 | add_action( 'admin_init', function () { |
| 49 | 42 | $this->handle_external_redirects(); |
| 50 | 43 | } ); |
| 51 | 44 | |
| 52 | - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { | |
| 53 | - $this->register_editor_one_menu_items( $menu_data_provider ); | |
| 54 | - } ); | |
| 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 ); | |
| 55 | 48 | |
| 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 ); | |
| 52 | + | |
| 56 | 53 | add_action( 'elementor/widgets/register', function( Widgets_Manager $manager ) { |
| 57 | 54 | foreach ( Api::get_promotion_widgets() as $widget_data ) { |
| 58 | 55 | $manager->register( new Widgets\Pro_Widget_Promotion( [], [ |
| 59 | 56 | 'widget_name' => $widget_data['name'], |
| @@ -65,14 +62,8 @@ | ||
| 65 | 62 | if ( Birthday::should_display_notice() ) { |
| 66 | 63 | new Birthday(); |
| 67 | 64 | } |
| 68 | 65 | |
| 69 | - if ( Black_Friday::should_display_notice() ) { | |
| 70 | - new Black_Friday(); | |
| 71 | - } | |
| 72 | - | |
| 73 | - add_filter( 'elementor/editor/localize_settings', [ $this, 'add_v4_promotions_data' ] ); | |
| 74 | - | |
| 75 | 66 | if ( Utils::has_pro() ) { |
| 76 | 67 | return; |
| 77 | 68 | } |
| 78 | 69 | |
| @@ -81,45 +72,33 @@ | ||
| 81 | 72 | } ); |
| 82 | 73 | |
| 83 | 74 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_react_data' ] ); |
| 84 | 75 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_v4_alphachip' ] ); |
| 85 | - | |
| 86 | - // Add Ally promo | |
| 87 | - Ally_Dashboard_Widget::init(); | |
| 88 | - | |
| 89 | - $this->register_atomic_promotions(); | |
| 90 | 76 | } |
| 91 | 77 | |
| 92 | - /** | |
| 93 | - * Get Ally Scanner URL | |
| 94 | - * | |
| 95 | - * @return string | |
| 96 | - */ | |
| 97 | - public static function get_ally_external_scanner_url(): string { | |
| 98 | - return apply_filters( 'elementor/ally_external_scanner_url', 'https://go.elementor.com/acc-checker-dashboard-plg' ); | |
| 99 | - } | |
| 100 | - | |
| 101 | 78 | private function handle_external_redirects() { |
| 102 | - $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); | |
| 103 | - if ( empty( $page ) ) { | |
| 79 | + if ( empty( $_GET['page'] ) ) { | |
| 104 | 80 | return; |
| 105 | 81 | } |
| 106 | 82 | |
| 107 | - if ( 'go_elementor_pro' === $page ) { | |
| 108 | - 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() ); | |
| 109 | 85 | die; |
| 110 | 86 | } |
| 111 | 87 | } |
| 112 | 88 | |
| 113 | - private function register_editor_one_menu_items( Menu_Data_Provider $menu_data_provider ) { | |
| 114 | - $menu_data_provider->register_menu( new Editor_One_Custom_Elements_Menu() ); | |
| 115 | - $menu_data_provider->register_menu( new Editor_One_Submissions_Menu() ); | |
| 116 | - $menu_data_provider->register_menu( new Editor_One_Fonts_Menu() ); | |
| 117 | - $menu_data_provider->register_menu( new Editor_One_Icons_Menu() ); | |
| 118 | - $menu_data_provider->register_menu( new Editor_One_Custom_Code_Menu() ); | |
| 119 | - $menu_data_provider->register_menu( new Editor_One_Popups_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() ); | |
| 120 | 95 | } |
| 121 | 96 | |
| 97 | + private function register_promotion_menu_item( Admin_Menu_Manager $admin_menu ) { | |
| 98 | + $admin_menu->register( 'go_elementor_pro', new Go_Pro_Promotion_Item() ); | |
| 99 | + } | |
| 100 | + | |
| 122 | 101 | public function enqueue_react_data(): void { |
| 123 | 102 | if ( ! current_user_can( 'manage_options' ) ) { |
| 124 | 103 | return; |
| 125 | 104 | } |
| @@ -182,116 +161,6 @@ | ||
| 182 | 161 | EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/free-to-pro-upsell/v1/free-to-pro-upsell.json', |
| 183 | 162 | EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_free_to_pro_upsell', |
| 184 | 163 | EditorAssetsAPI::ASSETS_DATA_KEY => 'free-to-pro-upsell', |
| 185 | 164 | ]; |
| 186 | - } | |
| 187 | - | |
| 188 | - public function add_v4_promotions_data( array $settings ): array { | |
| 189 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 190 | - return $settings; | |
| 191 | - } | |
| 192 | - | |
| 193 | - $editor_assets_api = new EditorAssetsAPI( $this->get_v4_promotions_api_config() ); | |
| 194 | - $promotion_data = new PromotionData( $editor_assets_api ); | |
| 195 | - | |
| 196 | - $settings['v4Promotions'] = $promotion_data->get_v4_promotions_data(); | |
| 197 | - | |
| 198 | - return $settings; | |
| 199 | - } | |
| 200 | - | |
| 201 | - private function get_v4_promotions_api_config(): array { | |
| 202 | - return [ | |
| 203 | - EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/packages/v1/promotions.json', | |
| 204 | - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_v4_promotions', | |
| 205 | - EditorAssetsAPI::ASSETS_DATA_KEY => 'promotions', | |
| 206 | - ]; | |
| 207 | - } | |
| 208 | - | |
| 209 | - private function is_atomic_widgets_active(): bool { | |
| 210 | - return Plugin::$instance->experiments->is_feature_active( 'e_atomic_elements' ); | |
| 211 | - } | |
| 212 | - | |
| 213 | - private function get_atomic_promotion_configs(): array { | |
| 214 | - return [ | |
| 215 | - [ | |
| 216 | - 'key' => 'attributes', | |
| 217 | - 'label' => __( 'Attributes', 'elementor' ), | |
| 218 | - 'section' => 'settings', | |
| 219 | - 'priority' => 40, | |
| 220 | - ], | |
| 221 | - [ | |
| 222 | - 'key' => 'display-conditions', | |
| 223 | - 'label' => __( 'Display Conditions', 'elementor' ), | |
| 224 | - 'section' => 'settings', | |
| 225 | - 'priority' => 50, | |
| 226 | - ], | |
| 227 | - ]; | |
| 228 | - } | |
| 229 | - | |
| 230 | - private function register_atomic_promotions(): void { | |
| 231 | - add_action( 'elementor/init', function() { | |
| 232 | - if ( ! $this->is_atomic_widgets_active() ) { | |
| 233 | - return; | |
| 234 | - } | |
| 235 | - | |
| 236 | - add_filter( | |
| 237 | - 'elementor/atomic-widgets/props-schema', | |
| 238 | - [ $this, 'inject_atomic_promotion_props' ] | |
| 239 | - ); | |
| 240 | - | |
| 241 | - foreach ( $this->get_atomic_promotion_configs() as $config ) { | |
| 242 | - add_filter( | |
| 243 | - 'elementor/atomic-widgets/controls', | |
| 244 | - fn( array $controls, $element ) => $this->inject_atomic_promotion_control( $controls, $element, $config ), | |
| 245 | - $config['priority'], | |
| 246 | - 2 | |
| 247 | - ); | |
| 248 | - } | |
| 249 | - } ); | |
| 250 | - | |
| 251 | - ( new Atomic_Form_Widget_Promotion() )->register(); | |
| 252 | - } | |
| 253 | - | |
| 254 | - public function inject_atomic_promotion_props( array $schema ): array { | |
| 255 | - foreach ( $this->get_atomic_promotion_configs() as $config ) { | |
| 256 | - $key = $config['key']; | |
| 257 | - | |
| 258 | - if ( isset( $schema[ $key ] ) ) { | |
| 259 | - continue; | |
| 260 | - } | |
| 261 | - | |
| 262 | - $schema[ $key ] = Promotion_Prop_Type::make( $key ); | |
| 263 | - } | |
| 264 | - | |
| 265 | - return $schema; | |
| 266 | - } | |
| 267 | - | |
| 268 | - protected function inject_atomic_promotion_control( array $element_controls, $atomic_element, array $config ): array { | |
| 269 | - $key = $config['key']; | |
| 270 | - $schema = $atomic_element::get_props_schema(); | |
| 271 | - | |
| 272 | - if ( ! array_key_exists( $key, $schema ) ) { | |
| 273 | - return $element_controls; | |
| 274 | - } | |
| 275 | - | |
| 276 | - foreach ( $element_controls as $item ) { | |
| 277 | - if ( ! ( $item instanceof \Elementor\Modules\AtomicWidgets\Controls\Section ) ) { | |
| 278 | - continue; | |
| 279 | - } | |
| 280 | - | |
| 281 | - if ( $item->get_id() !== $config['section'] ) { | |
| 282 | - continue; | |
| 283 | - } | |
| 284 | - | |
| 285 | - $control = Atomic_Promotion_Control::make( $key ) | |
| 286 | - ->set_label( $config['label'] ) | |
| 287 | - ->set_meta( [ | |
| 288 | - 'topDivider' => true, | |
| 289 | - ] ); | |
| 290 | - | |
| 291 | - $item->add_item( $control ); | |
| 292 | - break; | |
| 293 | - } | |
| 294 | - | |
| 295 | - return $element_controls; | |
| 296 | 165 | } |
| 297 | 166 | } |