| @@ -27,31 +27,31 @@ | ||
| 27 | 27 | |
| 28 | 28 | public function __construct() { |
| 29 | 29 | parent::__construct(); |
| 30 | 30 | |
| 31 | - $this->register_app(); | |
| 31 | + $this->register_experiment(); | |
| 32 | 32 | |
| 33 | - add_action( 'elementor/init', function () { | |
| 34 | - $this->set_cloud_library_settings(); | |
| 35 | - }, 12 /** After the initiation of the connect cloud library */ ); | |
| 33 | + if ( Plugin::$instance->experiments->is_feature_active( $this->get_name() ) ) { | |
| 34 | + $this->register_app(); | |
| 36 | 35 | |
| 37 | - add_filter( 'elementor/editor/localize_settings', function ( $settings ) { | |
| 38 | - return $this->localize_settings( $settings ); | |
| 39 | - }, 11 /** After Elementor Core */ ); | |
| 36 | + add_action( 'elementor/init', function () { | |
| 37 | + $this->set_cloud_library_settings(); | |
| 38 | + }, 12 /** After the initiation of the connect cloud library */ ); | |
| 40 | 39 | |
| 41 | - add_filter( 'elementor/render_mode/module', function( $module_name ) { | |
| 42 | - $render_mode_manager = \Elementor\Plugin::$instance->frontend->render_mode_manager; | |
| 40 | + add_filter( 'elementor/editor/localize_settings', function ( $settings ) { | |
| 41 | + return $this->localize_settings( $settings ); | |
| 42 | + }, 11 /** After Elementor Core */ ); | |
| 43 | 43 | |
| 44 | - if ( $render_mode_manager ) { | |
| 45 | - $current_render_mode = $render_mode_manager->get_current(); | |
| 44 | + add_filter( 'elementor/render_mode/module', function( $module_name ) { | |
| 45 | + $render_mode_manager = \Elementor\Plugin::$instance->frontend->render_mode_manager; | |
| 46 | 46 | |
| 47 | - if ( $current_render_mode instanceof \Elementor\Modules\CloudLibrary\Render_Mode_Preview ) { | |
| 47 | + if ( $render_mode_manager && $render_mode_manager->get_current() instanceof \Elementor\Modules\CloudLibrary\Render_Mode_Preview ) { | |
| 48 | 48 | return 'cloud-library'; |
| 49 | 49 | } |
| 50 | - } | |
| 51 | 50 | |
| 52 | - return $module_name; | |
| 53 | - }, 12); | |
| 51 | + return $module_name; | |
| 52 | + }, 12); | |
| 53 | + } | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public function localize_settings( $settings ) { |
| 57 | 57 | if ( isset( $settings['i18n'] ) ) { |
| @@ -62,8 +62,18 @@ | ||
| 62 | 62 | |
| 63 | 63 | return $settings; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | + private function register_experiment() { | |
| 67 | + Plugin::$instance->experiments->add_feature( [ | |
| 68 | + 'name' => $this->get_name(), | |
| 69 | + 'title' => esc_html__( 'Cloud Templates', 'elementor' ), | |
| 70 | + 'description' => esc_html__( 'Cloud Templates empowers you to save and manage design elements across all your projects. This feature is associated and connected to your Elementor Pro account and can be accessed from any website associated with your account.', 'elementor' ), | |
| 71 | + 'release_status' => ExperimentsManager::RELEASE_STATUS_BETA, | |
| 72 | + 'default' => ExperimentsManager::STATE_ACTIVE, | |
| 73 | + ] ); | |
| 74 | + } | |
| 75 | + | |
| 66 | 76 | private function register_app() { |
| 67 | 77 | add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) { |
| 68 | 78 | $connect_module->register_app( 'cloud-library', Cloud_Library::get_class_name() ); |
| 69 | 79 | } ); |
| @@ -80,9 +90,9 @@ | ||
| 80 | 90 | |
| 81 | 91 | /** |
| 82 | 92 | * @param Render_Mode_Manager $manager |
| 83 | 93 | * |
| 84 | - * @throws \Exception If render mode registration fails. | |
| 94 | + * @throws \Exception | |
| 85 | 95 | */ |
| 86 | 96 | public function register_render_mode( Render_Mode_Manager $manager ) { |
| 87 | 97 | $manager->register_render_mode( Render_Mode_Preview::class ); |
| 88 | 98 | } |
| @@ -109,11 +119,11 @@ | ||
| 109 | 119 | 'utm_campaign' => 'library-connect', |
| 110 | 120 | 'utm_content' => 'cloud-library', |
| 111 | 121 | 'source' => 'cloud-library', |
| 112 | 122 | ] ) ), |
| 113 | - 'library_connect_title_copy' => esc_html__( 'Connect to your Elementor account', 'elementor' ), | |
| 114 | - 'library_connect_sub_title_copy' => esc_html__( 'Then you can find all your templates in one convenient library.', 'elementor' ), | |
| 115 | - 'library_connect_button_copy' => esc_html__( 'Connect', 'elementor' ), | |
| 123 | + 'library_connect_title' => esc_html__( 'Connect to your Elementor account', 'elementor' ), | |
| 124 | + 'library_connect_sub_title' => esc_html__( 'Then you can find all your templates in one convenient library.', 'elementor' ), | |
| 125 | + 'library_connect_button_text' => esc_html__( 'Connect', 'elementor' ), | |
| 116 | 126 | ] ); |
| 117 | 127 | } |
| 118 | 128 | |
| 119 | 129 | private function get_document_types() { |
| @@ -140,23 +150,10 @@ | ||
| 140 | 150 | |
| 141 | 151 | private function print_thumbnail_preview_callback() { |
| 142 | 152 | $doc = Plugin::$instance->documents->get_current(); |
| 143 | 153 | |
| 144 | - if ( ! $doc ) { | |
| 145 | - $render_mode = Plugin::$instance->frontend->render_mode_manager->get_current(); | |
| 146 | - if ( $render_mode instanceof Render_Mode_Preview ) { | |
| 147 | - $doc = $render_mode->get_document(); | |
| 148 | - } | |
| 149 | - } | |
| 154 | + // PHPCS - should not be escaped. | |
| 155 | + echo Plugin::$instance->frontend->get_builder_content_for_display( $doc->get_main_id(), true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 150 | 156 | |
| 151 | - if ( ! $doc ) { | |
| 152 | - echo '<div class="elementor-alert elementor-alert-danger">' . esc_html__( 'Document not found for preview.', 'elementor' ) . '</div>'; | |
| 153 | - return; | |
| 154 | - } | |
| 155 | - | |
| 156 | - Plugin::$instance->documents->switch_to_document( $doc ); | |
| 157 | - | |
| 158 | - $content = $doc->get_content( true ); | |
| 159 | - | |
| 160 | - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 157 | + wp_delete_post( $doc->get_main_id(), true ); | |
| 161 | 158 | } |
| 162 | 159 | } |