Envato Elements – Template Kits (Beta) - Version 2.0.9

Version Description

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

Release Info

Developer dtbaker
Plugin Icon 128x128 Envato Elements – Template Kits (Beta)
Version 2.0.9
Comparing to
See all releases

Code changes from version 2.0.8 to 2.0.9

envato-elements.php CHANGED
@@ -4,11 +4,11 @@
4
  * Description: Access beautifully designed Template Kits + Photos from Envato Elements.
5
  * Author: Envato
6
  * Author URI: https://elements.envato.com/extensions/wordpress/?utm_source=extensions&utm_medium=referral&utm_campaign=elements_extensions_wpplugins
7
- * Version: 2.0.8
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: envato-elements
14
  *
@@ -30,7 +30,7 @@ if ( ! defined( 'ABSPATH' ) ) {
30
  }
31
 
32
  define( 'ENVATO_ELEMENTS_SLUG', 'envato-elements' );
33
- define( 'ENVATO_ELEMENTS_VER', '2.0.8' );
34
  define( 'ENVATO_ELEMENTS_FILE', __FILE__ );
35
  define( 'ENVATO_ELEMENTS_DIR', plugin_dir_path( ENVATO_ELEMENTS_FILE ) );
36
  define( 'ENVATO_ELEMENTS_URI', plugins_url( '/', ENVATO_ELEMENTS_FILE ) );
4
  * Description: Access beautifully designed Template Kits + Photos from Envato Elements.
5
  * Author: Envato
6
  * Author URI: https://elements.envato.com/extensions/wordpress/?utm_source=extensions&utm_medium=referral&utm_campaign=elements_extensions_wpplugins
7
+ * Version: 2.0.9
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: envato-elements
14
  *
30
  }
31
 
32
  define( 'ENVATO_ELEMENTS_SLUG', 'envato-elements' );
33
+ define( 'ENVATO_ELEMENTS_VER', '2.0.9' );
34
  define( 'ENVATO_ELEMENTS_FILE', __FILE__ );
35
  define( 'ENVATO_ELEMENTS_DIR', plugin_dir_path( ENVATO_ELEMENTS_FILE ) );
36
  define( 'ENVATO_ELEMENTS_URI', plugins_url( '/', ENVATO_ELEMENTS_FILE ) );
inc/api/class-template-kit-import.php CHANGED
@@ -255,10 +255,15 @@ class Template_Kit_Import extends API {
255
  );
256
  }
257
 
 
 
258
  $source = \Elementor\Plugin::$instance->templates_manager->get_source( 'local' );
 
259
  $result = $source->import_template( basename( $temporary_json_file_path ), $temporary_json_file_path );
260
- $block_data = json_decode( file_get_contents( $temporary_json_file_path ), true );
261
- unlink( $temporary_json_file_path );
 
 
262
 
263
  if ( is_wp_error( $result ) ) {
264
  return $this->format_error(
255
  );
256
  }
257
 
258
+ $block_data = json_decode( file_get_contents( $temporary_json_file_path ), true );
259
+
260
  $source = \Elementor\Plugin::$instance->templates_manager->get_source( 'local' );
261
+ // FYI, newer versions of Elementor delete a JSON file after successful import
262
  $result = $source->import_template( basename( $temporary_json_file_path ), $temporary_json_file_path );
263
+
264
+ if ( file_exists( $temporary_json_file_path ) ) {
265
+ unlink( $temporary_json_file_path );
266
+ }
267
 
268
  if ( is_wp_error( $result ) ) {
269
  return $this->format_error(
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: envato
3
  Tags: elementor, elements, templates, template kit
4
  Requires at least: 4.6
5
- Tested up to: 5.6
6
  Requires PHP: 5.6
7
- Stable tag: 2.0.8
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -79,6 +79,9 @@ If you have any questions or feedback for the team, please send an email to exte
79
 
80
  == Changelog ==
81
 
 
 
 
82
  = 2.0.8 - 2021-02-02 =
83
  * Feature: Support for Elementor Landing Page templates
84
  * Feature: Elementor compatibility check
2
  Contributors: envato
3
  Tags: elementor, elements, templates, template kit
4
  Requires at least: 4.6
5
+ Tested up to: 5.8
6
  Requires PHP: 5.6
7
+ Stable tag: 2.0.9
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
79
 
80
  == Changelog ==
81
 
82
+ = 2.0.9 - 2021-07-19 =
83
+ * Fix: Compatibility with Elementor 3.3.0
84
+
85
  = 2.0.8 - 2021-02-02 =
86
  * Feature: Support for Elementor Landing Page templates
87
  * Feature: Elementor compatibility check
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
  }