| @@ -15,9 +15,8 @@ | ||
| 15 | 15 | use Elementor\Plugin; |
| 16 | 16 | use Elementor\Core\Kits\Documents\Kit; |
| 17 | 17 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 18 | 18 | use Templately\Core\Importer\Elementor as ElementorImporter; |
| 19 | -use Templately\Core\Importer\Utils\Utils; | |
| 20 | 19 | use Elementor\TemplateLibrary\Source_Local as ElementorLocal; |
| 21 | 20 | |
| 22 | 21 | class Elementor extends Platform { |
| 23 | 22 | private $id = 'elementor'; |
| @@ -38,9 +37,9 @@ | ||
| 38 | 37 | public function hooks() { |
| 39 | 38 | if ( class_exists( '\Elementor\Plugin' ) ) { |
| 40 | 39 | add_action( 'elementor/preview/enqueue_styles', [ $this, 'styles' ] ); |
| 41 | 40 | add_action( 'elementor/editor/before_enqueue_styles', [ $this, 'styles' ] ); |
| 42 | - add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'scripts' ] ); | |
| 41 | + add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'scripts' ] ); | |
| 43 | 42 | } |
| 44 | 43 | } |
| 45 | 44 | |
| 46 | 45 | /** |
| @@ -48,9 +47,8 @@ | ||
| 48 | 47 | * @return void |
| 49 | 48 | */ |
| 50 | 49 | public function styles() { |
| 51 | 50 | templately()->assets->enqueue( 'templately-elementor-preview', 'css/elementor.css' ); |
| 52 | - templately()->assets->enqueue( 'templately-tailwind', 'css/tailwind.css', ['templately-elementor-preview'] ); | |
| 53 | 51 | } |
| 54 | 52 | |
| 55 | 53 | /** |
| 56 | 54 | * Assets Enqueueing |
| @@ -57,10 +55,9 @@ | ||
| 57 | 55 | * @return void |
| 58 | 56 | */ |
| 59 | 57 | public function scripts() { |
| 60 | 58 | templately()->assets->enqueue( 'templately-elementor', 'css/elementor.css' ); |
| 61 | - templately()->assets->enqueue( 'templately-tailwind', 'css/tailwind.css', ['templately-elementor'] ); | |
| 62 | - templately()->assets->enqueue( 'templately-elementor', 'js/elementor.js', [ 'jquery' ], true ); | |
| 59 | + templately()->assets->enqueue( 'templately-elementor', 'js/elementor.js', [ 'jquery' ] ); | |
| 63 | 60 | templately()->admin->scripts( 'elementor' ); |
| 64 | 61 | } |
| 65 | 62 | |
| 66 | 63 | /** |
| @@ -77,21 +74,16 @@ | ||
| 77 | 74 | * Checking the template eligibility for import. |
| 78 | 75 | * |
| 79 | 76 | * @return WP_Error|void |
| 80 | 77 | */ |
| 81 | - protected function is_eligible( $template, $types = [ 'page', 'section', 'block' ] ) { | |
| 78 | + protected function is_eligible( $template, $types = [ 'page', 'section' ] ) { | |
| 82 | 79 | if ( ! Helper::is_plugin_active( 'elementor-pro/elementor-pro.php' ) && |
| 83 | 80 | isset( $template['type'] ) && |
| 84 | - ! in_array( $template['type'], $types, true ) | |
| 85 | - ) { | |
| 81 | + ! in_array( $template['type'], $types, true ) ) { | |
| 86 | 82 | $message = sprintf( |
| 87 | - __( 'You have to install/activate %s to import %s Template.', 'templately' ), | |
| 88 | - sprintf( | |
| 89 | - '<a target="_blank" href="%s">%s</a>', | |
| 90 | - 'https://wpdeveloper.com/go/elementor', | |
| 91 | - 'Elementor PRO' | |
| 92 | - ), | |
| 93 | - $template['type'] | |
| 83 | + __( /** @lang text */ 'You have to install/activate <a target="_blank" href="%s">Elementor PRO</a> to import %s Template.', 'templately' ), | |
| 84 | + 'https://wpdeveloper.com/go/elementor', | |
| 85 | + ucwords( $template['type'] ) | |
| 94 | 86 | ); |
| 95 | 87 | |
| 96 | 88 | return Helper::error( 'required_elementor_pro', $message, 'import/page', 404 ); |
| 97 | 89 | } |
| @@ -97,12 +89,8 @@ | ||
| 97 | 89 | } |
| 98 | 90 | } |
| 99 | 91 | |
| 100 | 92 | public function get_saved_templates( $params = [] ) { |
| 101 | - if ( ! function_exists( 'is_plugin_active' ) ){ | |
| 102 | - require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); | |
| 103 | - } | |
| 104 | - | |
| 105 | 93 | $_page_number = isset( $params['page'] ) ? intval( $params['page'] ) : 1; |
| 106 | 94 | |
| 107 | 95 | $args = [ |
| 108 | 96 | 'post_type' => 'elementor_library', |
| @@ -135,13 +123,11 @@ | ||
| 135 | 123 | wp_reset_postdata(); |
| 136 | 124 | wp_reset_query(); |
| 137 | 125 | |
| 138 | 126 | return array( |
| 139 | - 'current_page' => $templates->query_vars['paged'], | |
| 140 | - 'total_page' => $templates->max_num_pages, | |
| 141 | - 'items' => $templateList, | |
| 142 | - 'has_elementor' => rest_sanitize_boolean( \is_plugin_active( 'elementor/elementor.php' ) ), | |
| 143 | - 'has_elementor_pro' => rest_sanitize_boolean( \is_plugin_active( 'elementor-pro/elementor-pro.php' ) ), | |
| 127 | + 'current_page' => $templates->query_vars['paged'], | |
| 128 | + 'total_page' => $templates->max_num_pages, | |
| 129 | + 'items' => $templateList, | |
| 144 | 130 | ); |
| 145 | 131 | } |
| 146 | 132 | |
| 147 | 133 | private function get_export_link( $template_id ) { |
| @@ -243,9 +229,9 @@ | ||
| 243 | 229 | * @since 2.0.0 |
| 244 | 230 | * |
| 245 | 231 | * @return array|WP_Error array on success, WP_Error on failure. |
| 246 | 232 | */ |
| 247 | - public function create_page( $id, $title, $importer = null, $settings = [] ) { | |
| 233 | + public function create_page( $id, $title, $importer = null ) { | |
| 248 | 234 | $template_data = $importer->get_content( $id ); |
| 249 | 235 | |
| 250 | 236 | if ( is_wp_error( $template_data ) ) { |
| 251 | 237 | return $template_data; |
| @@ -250,12 +236,8 @@ | ||
| 250 | 236 | if ( is_wp_error( $template_data ) ) { |
| 251 | 237 | return $template_data; |
| 252 | 238 | } |
| 253 | 239 | |
| 254 | - if ( ! empty( $settings ) && ! empty( $template_data['content'] ) && is_array( $template_data['content'] ) ) { | |
| 255 | - $template_data['content'] = \Templately\Core\Importer\Utils\ElementorSettingsMerger::merge( $template_data['content'], $settings ); | |
| 256 | - } | |
| 257 | - | |
| 258 | 240 | $importer = new ElementorImporter; |
| 259 | 241 | $template_data = $importer->get_data( $template_data ); |
| 260 | 242 | |
| 261 | 243 | if ( ! empty( $title ) ) { |
| @@ -263,13 +245,9 @@ | ||
| 263 | 245 | } |
| 264 | 246 | /** |
| 265 | 247 | * Checking the template eligibility for import. |
| 266 | 248 | */ |
| 267 | - $eligible = $this->is_eligible( $template_data ); | |
| 268 | - if( is_wp_error( $eligible ) ) { | |
| 269 | - return $eligible; | |
| 270 | - } | |
| 271 | - | |
| 249 | + $this->is_eligible( $template_data ); | |
| 272 | 250 | $inserted_ID = $importer->create_page( $template_data ); |
| 273 | 251 | |
| 274 | 252 | if ( is_wp_error( $inserted_ID ) ) { |
| 275 | 253 | return Helper::error( |
| @@ -288,9 +266,9 @@ | ||
| 288 | 266 | 'visit' => get_permalink( $inserted_ID ) |
| 289 | 267 | ]; |
| 290 | 268 | } |
| 291 | 269 | |
| 292 | - public function import_in_library( $id, $importer = null, $settings = [], $template_type = '', $type = '' ) { | |
| 270 | + public function import_in_library( $id, $importer = null ) { | |
| 293 | 271 | $template_data = $importer->get_content( $id, 'elementor', 'remote' ); |
| 294 | 272 | |
| 295 | 273 | if ( is_wp_error( $template_data ) ) { |
| 296 | 274 | return $template_data; |
| @@ -295,49 +273,15 @@ | ||
| 295 | 273 | if ( is_wp_error( $template_data ) ) { |
| 296 | 274 | return $template_data; |
| 297 | 275 | } |
| 298 | 276 | |
| 299 | - if ( ! empty( $settings ) && ! empty( $template_data['content'] ) && is_array( $template_data['content'] ) ) { | |
| 300 | - $template_data['content'] = \Templately\Core\Importer\Utils\ElementorSettingsMerger::merge( $template_data['content'], $settings ); | |
| 301 | - } | |
| 302 | - | |
| 303 | - // Frontend-provided template_type (from item details API) takes precedence over | |
| 304 | - // whatever the fetched content JSON reports. | |
| 305 | - if ( ! empty( $template_type ) ) { | |
| 306 | - $template_data['template_type'] = $template_type; | |
| 307 | - } | |
| 308 | - | |
| 309 | - // Resolve the correct Builder Type using template_type before passing to the importer. | |
| 310 | - try { | |
| 311 | - $template_data['type'] = static::resolve_library_type( $template_data ); | |
| 312 | - } catch ( \InvalidArgumentException $e ) { | |
| 313 | - return Helper::error( 'unsupported_template_type', $e->getMessage(), 'import', 400 ); | |
| 314 | - } | |
| 315 | - | |
| 316 | 277 | $importer = new ElementorImporter; |
| 317 | 278 | $imported_template = $importer->import_in_library( $template_data ); |
| 318 | 279 | |
| 319 | - if( is_wp_error( $imported_template ) ) { | |
| 320 | - return $imported_template; | |
| 321 | - } | |
| 322 | - | |
| 323 | - $post_id = $imported_template['template_id']; | |
| 324 | - | |
| 325 | - // Companion content for archive/fluent types — same side effects (Shop page, | |
| 326 | - // page_for_posts, LearnDash courses slug, fluent single-page template) the FSI | |
| 327 | - // Templates runner performs when importing these template types. | |
| 328 | - Utils::create_companion_content( $template_data['type'], $template_data['title'] ?? '', 'elementor' ); | |
| 329 | - | |
| 330 | - // Mark user as having imported a template | |
| 331 | - \Templately\Utils\Options::get_instance()->set( 'has_imported_template', true ); | |
| 332 | - | |
| 333 | - $document = Plugin::$instance->documents->get( $post_id ); | |
| 334 | - $elementor_edit_link = $document ? $document->get_edit_url() : admin_url( 'post.php?post=' . $post_id . '&action=elementor' ); | |
| 335 | - | |
| 336 | 280 | return [ |
| 337 | - 'post_id' => $post_id, | |
| 338 | - 'edit_link' => get_edit_post_link( $post_id, 'internal' ), | |
| 339 | - 'elementor_edit_link' => $elementor_edit_link, | |
| 281 | + 'post_id' => $imported_template['template_id'], | |
| 282 | + 'edit_link' => get_edit_post_link( $imported_template['template_id'], 'internal' ), | |
| 283 | + 'elementor_edit_link' => Plugin::$instance->documents->get( $imported_template['template_id'] )->get_edit_url(), | |
| 340 | 284 | 'visit' => $imported_template['url'] |
| 341 | 285 | ]; |
| 342 | 286 | } |
| 343 | 287 | |
| @@ -365,34 +309,6 @@ | ||
| 365 | 309 | public function insert( $data ) { |
| 366 | 310 | $importer = new ElementorImporter(); |
| 367 | 311 | |
| 368 | 312 | return $importer->get_data( $data ); |
| 369 | - } | |
| 370 | - | |
| 371 | - /** | |
| 372 | - * Filter Child Type | |
| 373 | - * | |
| 374 | - * @param $child_type | |
| 375 | - * @param $element_data | |
| 376 | - * @param $element | |
| 377 | - * | |
| 378 | - * @return mixed | |
| 379 | - */ | |
| 380 | - public static function filter_child_type( $child_type, $element_data, $element ) { | |
| 381 | - // Fix for Elementor Pro Promotion Widget | |
| 382 | - if ( is_a( $element, 'Elementor\Modules\Promotions\Widgets\Pro_Widget_Promotion' ) || ( is_object( $element ) && 'pro-promotion' === $element->get_name() ) ) { | |
| 383 | - $el_types = array_keys( Plugin::$instance->elements_manager->get_element_types() ); | |
| 384 | - | |
| 385 | - if ( isset( $element_data['elType'] ) && in_array( $element_data['elType'], $el_types, true ) ) { | |
| 386 | - return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] ); | |
| 387 | - } | |
| 388 | - | |
| 389 | - if ( ! isset( $element_data['widgetType'] ) ) { | |
| 390 | - return null; | |
| 391 | - } | |
| 392 | - | |
| 393 | - return Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] ); | |
| 394 | - } | |
| 395 | - | |
| 396 | - return $child_type; | |
| 397 | 313 | } |
| 398 | 314 | } |