| @@ -3,11 +3,8 @@ | ||
| 3 | 3 | namespace Elementor\Modules\WidgetCreation; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Core\Base\Module as BaseModule; |
| 6 | 6 | use Elementor\Core\Experiments\Manager as ExperimentsManager; |
| 7 | -use Elementor\Core\Utils\Hints; | |
| 8 | -use Elementor\Elements_Manager; | |
| 9 | -use Elementor\Plugin; | |
| 10 | 7 | |
| 11 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | 9 | exit; |
| 13 | 10 | } |
| @@ -19,10 +16,8 @@ | ||
| 19 | 16 | const PACKAGES = [ |
| 20 | 17 | 'editor-widget-creation', |
| 21 | 18 | ]; |
| 22 | 19 | |
| 23 | - const ANGIE_CONSENT_OPTION = 'angie_external_scripts_consent'; | |
| 24 | - | |
| 25 | 20 | public function get_name() { |
| 26 | 21 | return self::MODULE_NAME; |
| 27 | 22 | } |
| 28 | 23 | |
| @@ -38,100 +33,10 @@ | ||
| 38 | 33 | } |
| 39 | 34 | |
| 40 | 35 | public function __construct() { |
| 41 | 36 | parent::__construct(); |
| 42 | - AngiePromotion::init(); | |
| 43 | 37 | |
| 44 | 38 | add_filter( 'elementor/editor/v2/packages', fn( $packages ) => $this->add_packages( $packages ) ); |
| 45 | - add_action( 'elementor/elements/categories_registered', [ $this, 'maybe_register_custom_widgets_category_fallback' ], 100 ); | |
| 46 | - add_action( 'rest_api_init', fn() => $this->register_consent_route() ); | |
| 47 | - } | |
| 48 | - | |
| 49 | - private function register_consent_route(): void { | |
| 50 | - register_rest_route( 'elementor/v1', '/angie/consent', [ | |
| 51 | - 'methods' => 'POST', | |
| 52 | - 'callback' => fn() => $this->handle_save_consent(), | |
| 53 | - 'permission_callback' => fn() => current_user_can( 'manage_options' ), | |
| 54 | - ] ); | |
| 55 | - } | |
| 56 | - | |
| 57 | - private function handle_save_consent(): \WP_REST_Response { | |
| 58 | - update_option( self::ANGIE_CONSENT_OPTION, 'yes' ); | |
| 59 | - | |
| 60 | - return new \WP_REST_Response( [ 'success' => true ], 200 ); | |
| 61 | - } | |
| 62 | - | |
| 63 | - public function maybe_register_custom_widgets_category_fallback( Elements_Manager $elements_manager ): void { | |
| 64 | - if ( ! Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ) ) { | |
| 65 | - return; | |
| 66 | - } | |
| 67 | - | |
| 68 | - if ( Hints::is_plugin_active( 'angie' ) ) { | |
| 69 | - return; | |
| 70 | - } | |
| 71 | - | |
| 72 | - $categories = $elements_manager->get_categories(); | |
| 73 | - | |
| 74 | - if ( isset( $categories[ Elements_Manager::CATEGORY_CUSTOM_WIDGETS ] ) ) { | |
| 75 | - return; | |
| 76 | - } | |
| 77 | - | |
| 78 | - $elements_manager->add_category( | |
| 79 | - Elements_Manager::CATEGORY_CUSTOM_WIDGETS, | |
| 80 | - [ | |
| 81 | - 'title' => esc_html__( 'Custom Widget', 'elementor' ), | |
| 82 | - 'icon' => 'eicon-ai', | |
| 83 | - 'hideIfEmpty' => false, | |
| 84 | - 'active' => true, | |
| 85 | - ] | |
| 86 | - ); | |
| 87 | - | |
| 88 | - add_action( 'elementor/editor/templates/panel/category', [ $this, 'render_custom_widgets_category_heading_cta' ] ); | |
| 89 | - add_action( 'elementor/editor/templates/panel/category/content', [ $this, 'render_custom_widgets_category_empty_state' ] ); | |
| 90 | - } | |
| 91 | - | |
| 92 | - public function render_custom_widgets_category_heading_cta(): void { | |
| 93 | - if ( ! Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ) ) { | |
| 94 | - return; | |
| 95 | - } | |
| 96 | - | |
| 97 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 98 | - return; | |
| 99 | - } | |
| 100 | - | |
| 101 | - ?> | |
| 102 | - <# if ( 'custom-widgets' === name ) { #> | |
| 103 | - <button type="button" class="elementor-panel-custom-widgets__cta elementor-panel-custom-widgets__cta--heading"><?php echo esc_html__( 'Try for free', 'elementor' ); ?></button> | |
| 104 | - <# } #> | |
| 105 | - <?php | |
| 106 | - } | |
| 107 | - | |
| 108 | - public function render_custom_widgets_category_empty_state(): void { | |
| 109 | - if ( ! Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ) ) { | |
| 110 | - return; | |
| 111 | - } | |
| 112 | - | |
| 113 | - if ( $this->custom_widgets_category_has_widgets() ) { | |
| 114 | - return; | |
| 115 | - } | |
| 116 | - | |
| 117 | - ?> | |
| 118 | - <# if ( 'custom-widgets' === name ) { #> | |
| 119 | - <div class="elementor-panel-category-custom-widgets-empty"> | |
| 120 | - <p class="elementor-panel-category-custom-widgets-empty__message"><?php echo esc_html__( 'Create custom widgets by describing what you need.', 'elementor' ); ?></p> | |
| 121 | - </div> | |
| 122 | - <# } #> | |
| 123 | - <?php | |
| 124 | - } | |
| 125 | - | |
| 126 | - private function custom_widgets_category_has_widgets(): bool { | |
| 127 | - foreach ( Plugin::$instance->widgets_manager->get_widget_types() as $widget ) { | |
| 128 | - if ( in_array( Elements_Manager::CATEGORY_CUSTOM_WIDGETS, $widget->get_categories(), true ) ) { | |
| 129 | - return true; | |
| 130 | - } | |
| 131 | - } | |
| 132 | - | |
| 133 | - return false; | |
| 134 | 39 | } |
| 135 | 40 | |
| 136 | 41 | private function add_packages( array $packages ): array { |
| 137 | 42 | return array_merge( $packages, self::PACKAGES ); |