Template Kit – Import - Version 1.0.12

Version Description

  • 2021-07-19 =
  • Update: Compatibility with Elementor 3.3.0
Download this release

Release Info

Developer dtbaker
Plugin Icon 128x128 Template Kit – Import
Version 1.0.12
Comparing to
See all releases

Code changes from version 1.0.11 to 1.0.12

languages/template-kit-import.pot CHANGED
@@ -42,7 +42,7 @@ msgstr ""
42
  msgid "Something went wrong."
43
  msgstr ""
44
 
45
- #: vendor/template-kit-import/inc/class-builder-elementor.php:167
46
  msgid "Import into Elementor Library"
47
  msgstr ""
48
 
42
  msgid "Something went wrong."
43
  msgstr ""
44
 
45
+ #: vendor/template-kit-import/inc/class-builder-elementor.php:174
46
  msgid "Import into Elementor Library"
47
  msgstr ""
48
 
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: envato
3
  Tags: elementor, template, templates
4
  Requires at least: 5.3
5
- Tested up to: 5.6
6
  Requires PHP: 5.6
7
- Stable tag: 1.0.11
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -36,6 +36,9 @@ Create your own "Template Kit" for others with the "[Template Kit Export](https:
36
 
37
  == Changelog ==
38
 
 
 
 
39
  = 1.0.11 - 2021-02-02 =
40
  * Feature: Support for Elementor Landing Page templates
41
  * Feature: Elementor compatibility check
2
  Contributors: envato
3
  Tags: elementor, template, templates
4
  Requires at least: 5.3
5
+ Tested up to: 5.8
6
  Requires PHP: 5.6
7
+ Stable tag: 1.0.12
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
36
 
37
  == Changelog ==
38
 
39
+ = 1.0.12 - 2021-07-19 =
40
+ * Update: Compatibility with Elementor 3.3.0
41
+
42
  = 1.0.11 - 2021-02-02 =
43
  * Feature: Support for Elementor Landing Page templates
44
  * Feature: Elementor compatibility check
template-kit-import.php CHANGED
@@ -4,11 +4,11 @@
4
  * Description: Import Template Kits to WordPress
5
  * Author: Envato
6
  * Author URI: https://envato.com
7
- * Version: 1.0.11
8
  * License: GPLv3 or later
9
  * License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
- * Elementor tested up to: 3.2.0
11
- * Elementor Pro tested up to: 3.1.0
12
  *
13
  * Text Domain: template-kit-import
14
  *
@@ -30,7 +30,7 @@ if ( ! defined( 'ABSPATH' ) ) {
30
  }
31
 
32
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_SLUG', 'template-kit-import' );
33
- define( 'ENVATO_TEMPLATE_KIT_IMPORT_VER', '1.0.11' );
34
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_FILE', __FILE__ );
35
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_DIR', plugin_dir_path( ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
36
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_URI', plugins_url( '/', ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
4
  * Description: Import Template Kits to WordPress
5
  * Author: Envato
6
  * Author URI: https://envato.com
7
+ * Version: 1.0.12
8
  * License: GPLv3 or later
9
  * License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
+ * Elementor tested up to: 3.3.0
11
+ * Elementor Pro tested up to: 3.3.0
12
  *
13
  * Text Domain: template-kit-import
14
  *
30
  }
31
 
32
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_SLUG', 'template-kit-import' );
33
+ define( 'ENVATO_TEMPLATE_KIT_IMPORT_VER', '1.0.12' );
34
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_FILE', __FILE__ );
35
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_DIR', plugin_dir_path( ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
36
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_URI', plugins_url( '/', ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
vendor/template-kit-import/inc/class-builder-elementor.php CHANGED
@@ -62,18 +62,21 @@ class Builder_Elementor extends Builder {
62
  *
63
  * @param $template_index
64
  *
65
- * @return bool|array
66
  */
67
  public function get_template_data( $template_index ) {
68
  $template_data = parent::get_template_data( $template_index );
69
  if ( $template_data && ! empty( $template_data['source'] ) ) {
70
  $template_kit_folder_name = $this->get_template_kit_temporary_folder();
71
  $template_json_file = $template_kit_folder_name . $template_data['source'];
72
- $template_data['template_json'] = json_decode( file_get_contents( $template_json_file ), true );
73
- return $template_data;
 
 
 
74
  }
75
 
76
- return false;
77
  }
78
 
79
  /**
@@ -102,20 +105,24 @@ class Builder_Elementor extends Builder {
102
  // This overwrites the 'template type' so our Elementor Free users can at least import some of the Pro templates.
103
  // As Elementor only accepts the path to a JSON file for importing we temporarily modify the JSON data and
104
  // send in that template file name to Elementor for processing. We delete the temporary JSON file after processing below.
105
- $temp_wp_json_file = false;
106
  if ( ! empty( $local_json_data['metadata']['elementor_pro_required'] ) && ! class_exists( '\ElementorPro\Plugin' ) ) {
107
  $local_json_data['type'] = 'page';
108
- require_once ABSPATH . '/wp-admin/includes/file.php';
109
- $temp_wp_json_file = wp_tempnam();
110
- file_put_contents( $temp_wp_json_file, json_encode( $local_json_data ) );
111
- $template_json_file = $temp_wp_json_file;
112
  }
113
- $result = $source->import_template( basename( $template_json_file ), $template_json_file );
114
 
115
- // Cleanup above free template type file if it was created.
116
- if ( $temp_wp_json_file ) {
 
 
 
 
 
 
 
 
 
117
  unlink( $temp_wp_json_file );
118
  }
 
119
  if ( is_wp_error( $result ) ) {
120
  return new \WP_Error( 'import_error', 'Failed to import template: ' . esc_html( $result->get_error_message() ) );
121
  }
62
  *
63
  * @param $template_index
64
  *
65
+ * @return \WP_Error|array
66
  */
67
  public function get_template_data( $template_index ) {
68
  $template_data = parent::get_template_data( $template_index );
69
  if ( $template_data && ! empty( $template_data['source'] ) ) {
70
  $template_kit_folder_name = $this->get_template_kit_temporary_folder();
71
  $template_json_file = $template_kit_folder_name . $template_data['source'];
72
+ if(file_exists($template_json_file)) {
73
+ $template_data['template_json'] = json_decode( file_get_contents( $template_json_file ), true );
74
+
75
+ return $template_data;
76
+ }
77
  }
78
 
79
+ return new \WP_Error( 'template_error', 'Template Data Error. Please delete the Template Kit and import it again.' );
80
  }
81
 
82
  /**
105
  // This overwrites the 'template type' so our Elementor Free users can at least import some of the Pro templates.
106
  // As Elementor only accepts the path to a JSON file for importing we temporarily modify the JSON data and
107
  // send in that template file name to Elementor for processing. We delete the temporary JSON file after processing below.
 
108
  if ( ! empty( $local_json_data['metadata']['elementor_pro_required'] ) && ! class_exists( '\ElementorPro\Plugin' ) ) {
109
  $local_json_data['type'] = 'page';
 
 
 
 
110
  }
 
111
 
112
+ // Elementor deletes JSON files after importing them, so we have to duplicate the JSON file before sending it over.
113
+ require_once ABSPATH . '/wp-admin/includes/file.php';
114
+ $temp_wp_json_file = wp_tempnam('elements-tk-import-');
115
+ file_put_contents( $temp_wp_json_file, json_encode( $local_json_data ) );
116
+
117
+ // Pass our temporary JSON file to Elementor for import:
118
+ // FYI, newer versions of Elementor delete a JSON file after successful import
119
+ $result = $source->import_template( basename( $temp_wp_json_file ), $temp_wp_json_file );
120
+
121
+ // Cleanup above temporary file
122
+ if ( file_exists( $temp_wp_json_file ) ) {
123
  unlink( $temp_wp_json_file );
124
  }
125
+
126
  if ( is_wp_error( $result ) ) {
127
  return new \WP_Error( 'import_error', 'Failed to import template: ' . esc_html( $result->get_error_message() ) );
128
  }