Template Kit – Import - Version 1.0.0

Version Description

  • 2020-01-16 =
  • Official release for public use.
Download this release

Release Info

Developer envato
Plugin Icon 128x128 Template Kit – Import
Version 1.0.0
Comparing to
See all releases

Code changes from version 1.0.0-RC2 to 1.0.0

assets/css/main.min.css CHANGED
@@ -10,10 +10,15 @@
10
  .envato-template-kit-import__tab:focus,.envato-template-kit-import__tab:active{outline:0;-webkit-box-shadow:none;box-shadow:none}
11
  .envato-template-kit-import__tab--current{border-bottom:2px solid #837e7e}
12
  .envato-template-kit-import__tab-panel{background:#f1f1f1;border-top:1px solid #e0e5e9;color:#000;padding:20px 30px;overflow:hidden}
13
- .envato-template-kit-import__template-kit{-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;margin-bottom:40px}
 
 
 
14
  .envato-template-kit-import__title{font-weight:bold;text-transform:capitalize}
15
  .envato-template-kit-import__screenshot{margin-right:25px;max-width:300px;height:200px;overflow:hidden}
16
  .envato-template-kit-import__screenshot img{width:100%;height:auto}
 
 
17
  .envato-template-kit-import__next{margin-left:auto}
18
  .envato-template-kit-import__upload{background-color:#fff;border:1px solid #e0e5e9;margin-right:auto;margin-left:auto;padding:50px 25px;max-width:900px}
19
  .envato-template-kit-import__upload-form{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between}
@@ -31,12 +36,23 @@
31
  .envato-template-kit-import__upload-btn-next-link:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba;box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba}
32
  .envato-template-kit-import__upload-btn-next-link:active{background:#0073a1;border-color:#0073a1;color:#fff}
33
  .envato-template-kit-import__upload-hidden{display:none}
 
34
  .envato-template-kit-import__templates{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;width:100%;margin:40px auto 40px}
35
  .envato-template-kit-import__template{-webkit-box-flex:0;-webkit-flex:0 0 30%;-ms-flex:0 0 30%;flex:0 0 30%;margin-right:3%;margin-bottom:3%;background:#fff;border:1px solid #ccd6df}
 
36
  .envato-template-kit-import__template-screenshot-wrapper{height:300px;overflow:hidden}
37
  .envato-template-kit-import__template-screenshot{max-width:100%;height:auto}
38
  .envato-template-kit-import__template-title{text-align:center;padding:20px 0 0;font-size:16px}
39
  .envato-template-kit-import__template-import-options{text-align:center;padding:20px 0}
 
 
 
 
 
 
 
 
 
40
  .envato-template-kit-import__button-import{background:#0085ba;border-color:#0085ba;color:#fff;border-radius:3px;font-size:13px;padding:16px 20px;border:0;cursor:pointer;text-decoration:none;-webkit-box-shadow:inset 0 -2px 0 #0073a1;box-shadow:inset 0 -2px 0 #0073a1}
41
  .envato-template-kit-import__button-import:hover,.envato-template-kit-import__button-import:focus{background:#0090c9;border-color:#007aab;color:#fff}
42
  .envato-template-kit-import__button-import:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba;box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba}
@@ -49,6 +65,14 @@
49
  .envato-template-kit-import__button-import-again:hover,.envato-template-kit-import__button-import-again:focus{background:#899298;border-color:#79828a;color:#fff}
50
  .envato-template-kit-import__button-import-again:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #818a91;box-shadow:0 0 0 1px #fff,0 0 0 3px #818a91}
51
  .envato-template-kit-import__button-import-again:active{background:#747d85;border-color:#747d85;color:#fff}
 
 
 
 
 
 
 
 
52
  .envato-template-kit-import__plugins{background:#fff;border:1px solid #ccd6df;margin:40px auto 40px;padding:20px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap}
53
  .envato-template-kit-import__plugin-list-wrapper{-webkit-box-flex:0;-webkit-flex:0 0 690px;-ms-flex:0 0 690px;flex:0 0 690px}
54
  .envato-template-kit-import__plugin-list{padding-top:10px;padding-left:10px}
@@ -86,4 +110,7 @@
86
  .envato-template-kit-import__plugin-list-next-button{background:#0085ba;border-color:#0085ba;color:#fff;border-radius:3px;font-size:13px;padding:16px 20px;border:0;cursor:pointer;text-decoration:none;-webkit-box-shadow:inset 0 -2px 0 #0073a1;box-shadow:inset 0 -2px 0 #0073a1}
87
  .envato-template-kit-import__plugin-list-next-button:hover,.envato-template-kit-import__plugin-list-next-button:focus{background:#0090c9;border-color:#007aab;color:#fff}
88
  .envato-template-kit-import__plugin-list-next-button:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba;box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba}
89
- .envato-template-kit-import__plugin-list-next-button:active{background:#0073a1;border-color:#0073a1;color:#fff}
 
 
 
10
  .envato-template-kit-import__tab:focus,.envato-template-kit-import__tab:active{outline:0;-webkit-box-shadow:none;box-shadow:none}
11
  .envato-template-kit-import__tab--current{border-bottom:2px solid #837e7e}
12
  .envato-template-kit-import__tab-panel{background:#f1f1f1;border-top:1px solid #e0e5e9;color:#000;padding:20px 30px;overflow:hidden}
13
+ .envato-template-kit-import__template-kit{background-color:#fff;border:1px solid #e0e5e9;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;margin-bottom:40px;padding:20px}
14
+ .envato-template-kit-import__template-kit:hover .envato-template-kit-import__btn-delete{left:0}
15
+ .envato-template-kit-import__template-kit--imported .envato-template-kit-import__template-meta:before{content:"\f147";font-family:dashicons;display:block;line-height:1;font-weight:400;font-style:normal;speak:none;text-decoration:inherit;position:absolute;font-size:60px;color:#82b541}
16
+ .envato-template-kit-import__template-kit--imported .envato-template-kit-import__title,.envato-template-kit-import__template-kit--imported .envato-template-kit-import__message{margin:0 0 10px 70px}
17
  .envato-template-kit-import__title{font-weight:bold;text-transform:capitalize}
18
  .envato-template-kit-import__screenshot{margin-right:25px;max-width:300px;height:200px;overflow:hidden}
19
  .envato-template-kit-import__screenshot img{width:100%;height:auto}
20
+ .envato-template-kit-import__btn-delete{background:transparent;border:0;color:#a00;font-size:13px;position:relative;left:-9999em}
21
+ .envato-template-kit-import__btn-delete:hover{color:#dc3232}
22
  .envato-template-kit-import__next{margin-left:auto}
23
  .envato-template-kit-import__upload{background-color:#fff;border:1px solid #e0e5e9;margin-right:auto;margin-left:auto;padding:50px 25px;max-width:900px}
24
  .envato-template-kit-import__upload-form{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between}
36
  .envato-template-kit-import__upload-btn-next-link:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba;box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba}
37
  .envato-template-kit-import__upload-btn-next-link:active{background:#0073a1;border-color:#0073a1;color:#fff}
38
  .envato-template-kit-import__upload-hidden{display:none}
39
+ .envato-template-kit-import__plugin-warning{background-color:#f2dede;border:1px solid #ebcccc;color:#a94442;padding:.75rem 1.25rem;margin-top:20px;border-radius:.25rem}
40
  .envato-template-kit-import__templates{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;width:100%;margin:40px auto 40px}
41
  .envato-template-kit-import__template{-webkit-box-flex:0;-webkit-flex:0 0 30%;-ms-flex:0 0 30%;flex:0 0 30%;margin-right:3%;margin-bottom:3%;background:#fff;border:1px solid #ccd6df}
42
+ .envato-template-kit-import__imported-flag{display:none}
43
  .envato-template-kit-import__template-screenshot-wrapper{height:300px;overflow:hidden}
44
  .envato-template-kit-import__template-screenshot{max-width:100%;height:auto}
45
  .envato-template-kit-import__template-title{text-align:center;padding:20px 0 0;font-size:16px}
46
  .envato-template-kit-import__template-import-options{text-align:center;padding:20px 0}
47
+ .envato-template-kit-import__template-import-option--imported,.envato-template-kit-import__template-import-option--unmet-requirements{display:none}
48
+ .envato-template-kit-import__template--imported{position:relative;overflow:hidden}
49
+ .envato-template-kit-import__template--imported .envato-template-kit-import__template-import-option--fresh{display:none}
50
+ .envato-template-kit-import__template--imported .envato-template-kit-import__template-import-option--imported{display:block}
51
+ .envato-template-kit-import__template--imported .envato-template-kit-import__imported-flag{width:200px;display:block;background:#0085ba;position:absolute;top:21px;text-align:center;line-height:30px;letter-spacing:1px;color:#fff;-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);right:-65px}
52
+ .envato-template-kit-import__template--importing .envato-template-kit-import__button-import-again,.envato-template-kit-import__template--importing .envato-template-kit-import__button-import{padding-right:40px;position:relative}
53
+ .envato-template-kit-import__template--importing .envato-template-kit-import__button-import-again:after,.envato-template-kit-import__template--importing .envato-template-kit-import__button-import:after{content:"\f463";font-family:dashicons;display:block;line-height:1;font-weight:400;font-style:normal;speak:none;text-decoration:inherit;position:absolute;font-size:27px;right:6px;top:10px;color:#fff;-webkit-animation:templateImportSpin 4s linear infinite;animation:templateImportSpin 4s linear infinite}
54
+ .envato-template-kit-import__template--unmet-requirements .envato-template-kit-import__template-import-option--fresh,.envato-template-kit-import__template--unmet-requirements .envato-template-kit-import__template-import-option--imported{display:none}
55
+ .envato-template-kit-import__template--unmet-requirements .envato-template-kit-import__template-import-option--unmet-requirements{display:block}
56
  .envato-template-kit-import__button-import{background:#0085ba;border-color:#0085ba;color:#fff;border-radius:3px;font-size:13px;padding:16px 20px;border:0;cursor:pointer;text-decoration:none;-webkit-box-shadow:inset 0 -2px 0 #0073a1;box-shadow:inset 0 -2px 0 #0073a1}
57
  .envato-template-kit-import__button-import:hover,.envato-template-kit-import__button-import:focus{background:#0090c9;border-color:#007aab;color:#fff}
58
  .envato-template-kit-import__button-import:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba;box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba}
65
  .envato-template-kit-import__button-import-again:hover,.envato-template-kit-import__button-import-again:focus{background:#899298;border-color:#79828a;color:#fff}
66
  .envato-template-kit-import__button-import-again:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #818a91;box-shadow:0 0 0 1px #fff,0 0 0 3px #818a91}
67
  .envato-template-kit-import__button-import-again:active{background:#747d85;border-color:#747d85;color:#fff}
68
+ .envato-template-kit-import__button-upload-new{background:#818a91;border-color:#818a91;color:#fff;border-radius:3px;font-size:13px;padding:16px 20px;border:0;cursor:pointer;text-decoration:none;-webkit-box-shadow:inset 0 -2px 0 #747d85;box-shadow:inset 0 -2px 0 #747d85}
69
+ .envato-template-kit-import__button-upload-new:hover,.envato-template-kit-import__button-upload-new:focus{background:#899298;border-color:#79828a;color:#fff}
70
+ .envato-template-kit-import__button-upload-new:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #818a91;box-shadow:0 0 0 1px #fff,0 0 0 3px #818a91}
71
+ .envato-template-kit-import__button-upload-new:active{background:#747d85;border-color:#747d85;color:#fff}
72
+ .envato-template-kit-import__button-ignore-requirements{background:#d9534f;border-color:#d9534f;color:#fff;border-radius:3px;font-size:13px;padding:5px 15px;border:0;cursor:pointer;text-decoration:none;-webkit-box-shadow:inset 0 -2px 0 #d43f3a;box-shadow:inset 0 -2px 0 #d43f3a}
73
+ .envato-template-kit-import__button-ignore-requirements:hover,.envato-template-kit-import__button-ignore-requirements:focus{background:#dc5f5c;border-color:#d64742;color:#fff}
74
+ .envato-template-kit-import__button-ignore-requirements:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #d9534f;box-shadow:0 0 0 1px #fff,0 0 0 3px #d9534f}
75
+ .envato-template-kit-import__button-ignore-requirements:active{background:#d43f3a;border-color:#d43f3a;color:#fff}
76
  .envato-template-kit-import__plugins{background:#fff;border:1px solid #ccd6df;margin:40px auto 40px;padding:20px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap}
77
  .envato-template-kit-import__plugin-list-wrapper{-webkit-box-flex:0;-webkit-flex:0 0 690px;-ms-flex:0 0 690px;flex:0 0 690px}
78
  .envato-template-kit-import__plugin-list{padding-top:10px;padding-left:10px}
110
  .envato-template-kit-import__plugin-list-next-button{background:#0085ba;border-color:#0085ba;color:#fff;border-radius:3px;font-size:13px;padding:16px 20px;border:0;cursor:pointer;text-decoration:none;-webkit-box-shadow:inset 0 -2px 0 #0073a1;box-shadow:inset 0 -2px 0 #0073a1}
111
  .envato-template-kit-import__plugin-list-next-button:hover,.envato-template-kit-import__plugin-list-next-button:focus{background:#0090c9;border-color:#007aab;color:#fff}
112
  .envato-template-kit-import__plugin-list-next-button:focus{-webkit-box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba;box-shadow:0 0 0 1px #fff,0 0 0 3px #0085ba}
113
+ .envato-template-kit-import__plugin-list-next-button:active{background:#0073a1;border-color:#0073a1;color:#fff}
114
+ @-webkit-keyframes templateImportSpin{100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}
115
+ }@keyframes templateImportSpin{100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}
116
+ }
assets/js/importer.min.js CHANGED
@@ -1 +1 @@
1
- !function(a){window.TemplateKitImport=function(){function t(t){t.preventDefault();var e=a(this).data();return e&&e.templateKitId&&e.nonce&&a.ajax({url:ajaxurl,method:"post",dataType:"json",data:{action:"envato_template_kit_import_process",template_kit_id:parseInt(e.templateKitId,10),template_index:parseInt(e.templateIndex,10),nonce:e.nonce},success:function(t){alert("success")},error:function(){alert("failed to import")}}),!1}function e(t){t.preventDefault();var e=a(this).data();switch(e.pluginStatus){case"deactivated":case"update":case"install":window.location.href=e.pluginUrl;break;case"activated":break;case"error":alert("Unknown error");break;default:alert("Unknown plugin action")}return!1}return{initPluginPage:function(){a(".js-template-kit-plugin").click(e)},initTemplatePage:function(){a(".js-template-kit-import").click(t)}}}}(jQuery);
1
+ !function(r){window.TemplateKitImport=function(){function t(t){t.preventDefault();var e=r(this).data();if(e&&e.templateKitId&&e.nonce){var a=parseInt(e.templateIndex,10),i=r('.js-single-template[data-template-index="'+a+'"]');i.addClass("envato-template-kit-import__template--importing"),r.ajax({url:ajaxurl,method:"post",dataType:"json",data:{action:"envato_template_kit_import_process",template_kit_id:parseInt(e.templateKitId,10),template_index:a,nonce:e.nonce},success:function(t){i.addClass("envato-template-kit-import__template--imported"),i.find(".js-edit-template").attr("href",t.data.edit_url)},error:function(){alert("failed to import")},complete:function(){i.removeClass("envato-template-kit-import__template--importing")}})}return!1}function e(t){if(t.preventDefault(),confirm("Are you sure?")){var e=r(this).data();return e&&e.templateKitId&&e.nonce&&r.ajax({url:ajaxurl,type:"post",dataType:"json",data:{action:"envato_template_kit_delete_process",template_kit_id:parseInt(e.templateKitId,10),_ajax_nonce:e.nonce},success:function(t){r(".js-template-kit-id-"+e.templateKitId).remove(),r(".envato-template-kit-import__wrapper").not(".envato-template-kit-import__template-kit")&&location.reload(!0)},error:function(t){alert("Failed to remove template kit!")}}),!1}}function a(t){t.preventDefault();var e=r(this).data();switch(e.pluginStatus){case"deactivated":case"update":case"install":window.location.href=e.pluginUrl;break;case"activated":break;case"error":alert("Unknown error");break;default:alert("Unknown plugin action")}return!1}function i(t){t.preventDefault();var e=r(this).data("templateIndex");return r('.js-single-template[data-template-index="'+e+'"]').removeClass("envato-template-kit-import__template--unmet-requirements"),!1}function n(t){return!((r(".envato-template-kit-import__plugin-status--install")[0]||r(".envato-template-kit-import__plugin-status--deactivated")[0])&&!confirm("Some required plugins are not installed or actived. Proceed anyway?"))||(t.preventDefault(),!1)}return{initPluginPage:function(){r(".js-template-kit-plugin").click(a),r(".js-template-kit-plugin-next").click(n)},initImportPage:function(){r(".js-template-kit-delete").click(e)},initTemplatePage:function(){r(".js-template-kit-import").click(t),r(".js-template-kit-ignore-requirements").click(i)}}}}(jQuery);
inc/bootstrap.php CHANGED
@@ -38,4 +38,6 @@ require_once __DIR__ . '/helper.php';
38
 
39
  Plugin::get_instance();
40
  Importer::get_instance();
 
41
  CPT_Kits::get_instance();
 
38
 
39
  Plugin::get_instance();
40
  Importer::get_instance();
41
+ Delete::get_instance();
42
  CPT_Kits::get_instance();
43
+ Builder_Elementor::get_instance();
inc/class-builder-elementor.php CHANGED
@@ -29,6 +29,10 @@ class Builder_Elementor extends Builder {
29
  */
30
  public $builder = 'elementor';
31
 
 
 
 
 
32
 
33
  /**
34
  * Imports a template to the Elementor page builder.
@@ -83,10 +87,71 @@ class Builder_Elementor extends Builder {
83
  /**
84
  * Get the URL to the list of imported templates.
85
  *
 
 
86
  * @return string
87
  */
88
- public function get_imported_template_edit_url() {
 
 
 
 
 
 
 
89
  return admin_url( 'edit.php?post_type=elementor_library&tabs_group=library' );
90
  }
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  }
29
  */
30
  public $builder = 'elementor';
31
 
32
+ public function __construct() {
33
+ parent::__construct();
34
+ add_action( 'before_delete_post', array( $this, 'check_if_imported_template_is_getting_deleted' ) );
35
+ }
36
 
37
  /**
38
  * Imports a template to the Elementor page builder.
87
  /**
88
  * Get the URL to the list of imported templates.
89
  *
90
+ * @param $imported_template_id int - Optional imported template ID.
91
+ *
92
  * @return string
93
  */
94
+ public function get_imported_template_edit_url( $imported_template_id = 0 ) {
95
+ if ( $imported_template_id && class_exists( '\Elementor\Plugin' ) ) {
96
+ $imported_template = \Elementor\Plugin::$instance->documents->get( $imported_template_id );
97
+ if ( $imported_template ) {
98
+ return $imported_template->get_edit_url();
99
+ }
100
+ }
101
+
102
  return admin_url( 'edit.php?post_type=elementor_library&tabs_group=library' );
103
  }
104
 
105
+ /**
106
+ * Hook that runs when a user deletes a template from the Elementor library.
107
+ * This checks if the template getting deleted was imported from us.
108
+ * If it was from us, we clean up our manifest metadata and flag this template as not "imported" any more
109
+ * so that the UI can show the correct buttons/status.
110
+ *
111
+ * @param $post_to_be_deleted
112
+ */
113
+ public function check_if_imported_template_is_getting_deleted( $post_to_be_deleted ) {
114
+ if ( class_exists( '\Elementor\Plugin' ) ) {
115
+ $post = get_post( $post_to_be_deleted );
116
+ if ( $post && 'elementor_library' === $post->post_type ) {
117
+ $source_kit_id = get_post_meta( $post->ID, 'envato_tk_source_kit', true );
118
+ if ( $source_kit_id ) {
119
+ $source_kit_index = get_post_meta( $post->ID, 'envato_tk_source_index', true );
120
+ try {
121
+ $this->load_kit( $source_kit_id );
122
+ $manifest = $this->get_manifest_data();
123
+ if ( $manifest && ! empty( $manifest['templates'] ) ) {
124
+ if ( isset( $manifest['templates'][ $source_kit_index ] ) && isset( $manifest['templates'][ $source_kit_index ]['imports'] ) ) {
125
+ foreach ( $manifest['templates'][ $source_kit_index ]['imports'] as $import_id => $imported_data ) {
126
+ if ( (int) $post_to_be_deleted === (int) $imported_data['imported_template_id'] ) {
127
+ // we've found the record in the 'imports' manifest array that matches the imported template.
128
+ // lets remove it!
129
+ unset( $manifest['templates'][ $source_kit_index ]['imports'][ $import_id ] );
130
+ }
131
+ }
132
+ }
133
+ }
134
+ update_post_meta( $this->kit_id, 'envato_tk_manifest', $manifest );
135
+ } catch ( \Exception $e ) {
136
+ // noop
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Get any unmet requirements for importing this template to WordPress
145
+ *
146
+ * @param $template array
147
+ *
148
+ * @return array
149
+ */
150
+ public function get_list_of_unmet_requirements( $template ) {
151
+ $unmet_requirements = array();
152
+ if ( ! empty( $template['elementor_pro_required'] ) && ! class_exists( '\ElementorPro\Plugin' ) ) {
153
+ $unmet_requirements[] = __( 'Elementor Pro is required for this Template.', 'template-kit-export' );
154
+ }
155
+ return $unmet_requirements;
156
+ }
157
  }
inc/class-builder.php CHANGED
@@ -202,9 +202,11 @@ abstract class Builder extends Base {
202
  /**
203
  * Get the URL to the list of imported templates.
204
  *
 
 
205
  * @return string
206
  */
207
- public function get_imported_template_edit_url() {
208
  return admin_url( 'edit.php?post_type=page' );
209
  }
210
 
@@ -219,5 +221,15 @@ abstract class Builder extends Base {
219
  return $post->post_title;
220
  }
221
 
 
 
 
 
 
 
 
 
 
 
222
 
223
  }
202
  /**
203
  * Get the URL to the list of imported templates.
204
  *
205
+ * @param $imported_template_id int - Optional imported template ID.
206
+ *
207
  * @return string
208
  */
209
+ public function get_imported_template_edit_url( $imported_template_id = 0 ) {
210
  return admin_url( 'edit.php?post_type=page' );
211
  }
212
 
221
  return $post->post_title;
222
  }
223
 
224
+ /**
225
+ * Get any unmet requirements for importing this template to WordPress
226
+ *
227
+ * @param $template array
228
+ *
229
+ * @return array
230
+ */
231
+ public function get_list_of_unmet_requirements( $template ) {
232
+ return array();
233
+ }
234
 
235
  }
inc/class-delete.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Template Kit Delete:
4
+ *
5
+ * Deletes the template kit from wp_posts and cleans up the uploaded
6
+ * folders and files.
7
+ *
8
+ * @package Envato/Envato_Template_Kit_Delete
9
+ * @since 1.0.1
10
+ */
11
+
12
+ namespace Envato_Template_Kit_Import;
13
+
14
+ if ( ! defined( 'ABSPATH' ) ) {
15
+ exit; // Exit if accessed directly.
16
+ }
17
+
18
+ /**
19
+ * Delete templage kit and cleanup.
20
+ *
21
+ * @since 1.0.1
22
+ */
23
+ class Delete extends Base {
24
+
25
+ public function __construct() {
26
+ parent::__construct();
27
+ add_action( 'before_delete_post', array( $this, 'cleanup_template_delete' ) );
28
+ add_action( 'wp_ajax_envato_template_kit_delete_process', array( $this, 'handle_template_delete' ) );
29
+ }
30
+
31
+ /**
32
+ * Deletes a template kit when called via ajax
33
+ *
34
+ * @since 1.0.1
35
+ */
36
+ public function handle_template_delete() {
37
+ $template_kit_id = isset( $_POST['template_kit_id'] ) ? (int) $_POST['template_kit_id'] : -1;
38
+ check_ajax_referer( 'delete_template_kit_' . $template_kit_id, 'nonce' );
39
+ wp_delete_post( $template_kit_id, true );
40
+ wp_send_json_success();
41
+ }
42
+
43
+ /**
44
+ * Clean up from template delete
45
+ *
46
+ * @since 1.0.1
47
+ * @param int $post_id The post id to let the things happen.
48
+ */
49
+ public function cleanup_template_delete( $post_id ) {
50
+ $post = get_post( $post_id );
51
+
52
+ if ( CPT_Kits::get_instance()->cpt_slug === $post->post_type ) {
53
+ require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
54
+ require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
55
+ $file_system_direct = new \WP_Filesystem_Direct( false );
56
+
57
+ $get_upload_dir = wp_upload_dir();
58
+ $template_kit_path = $get_upload_dir ['basedir'] . '/template-kits/';
59
+ $template_kit_id_path = get_post_meta( $post_id, 'envato_tk_folder_name', true );
60
+
61
+ if ( ! $template_kit_id_path ) {
62
+ return;
63
+ }
64
+
65
+ $full_template_kit_id_path = $template_kit_path . $template_kit_id_path;
66
+ $file_system_direct->rmdir( $full_template_kit_id_path, true );
67
+ }
68
+ }
69
+ }
inc/class-importer.php CHANGED
@@ -57,6 +57,7 @@ class Importer extends Base {
57
  wp_send_json_success(
58
  array(
59
  'template_id' => $imported_template_id,
 
60
  )
61
  );
62
 
@@ -105,36 +106,15 @@ class Importer extends Base {
105
  $manifest_data = json_decode( file_get_contents( $template_kit_extract_directory . '/manifest.json' ), true );
106
  // todo: validate manifest data structure.
107
 
108
- // Check if the user has uploaded this template kit zip file before.
109
- // We're assuming the unique naming rule will be enough for now, until we get true uuid's implemented.
110
- $template_kit_hash = md5( $manifest_data['title'] . $manifest_data['page_builder'] );
111
-
112
- // Check if we've got an existing post for this hash
113
- $existing_posts = get_posts(
114
- array(
115
- 'post_type' => CPT_Kits::get_instance()->cpt_slug,
116
- 'meta_key' => 'envato_tk_hash',
117
- 'meta_value' => $template_kit_hash,
118
- )
119
  );
120
- if ( $existing_posts ) {
121
- $existing_posts = current( $existing_posts );
122
- $post_id = $existing_posts->ID;
123
- // Todo: remove the old upload directory from `envato_tk_folder_name` metadata
124
- $old_zip_path = get_post_meta( $post_id, 'envato_tk_folder_name', true );
125
- } else {
126
- // Importing fresh:
127
- $post_data = array(
128
- 'post_title' => $manifest_data['title'],
129
- 'post_type' => CPT_Kits::get_instance()->cpt_slug,
130
- 'post_status' => 'publish',
131
- );
132
- $post_id = wp_insert_post( $post_data, true );
133
- }
134
 
135
  if ( $post_id && ! is_wp_error( $post_id ) ) {
136
  // successfully stored this post. Add some metadata
137
- update_post_meta( $post_id, 'envato_tk_hash', $template_kit_hash );
138
  update_post_meta( $post_id, 'envato_tk_manifest', $manifest_data );
139
  update_post_meta( $post_id, 'envato_tk_folder_name', $template_kit_random_folder );
140
  update_post_meta( $post_id, 'envato_tk_builder', $manifest_data['page_builder'] );
57
  wp_send_json_success(
58
  array(
59
  'template_id' => $imported_template_id,
60
+ 'edit_url' => $template_kit->get_imported_template_edit_url( $imported_template_id ),
61
  )
62
  );
63
 
106
  $manifest_data = json_decode( file_get_contents( $template_kit_extract_directory . '/manifest.json' ), true );
107
  // todo: validate manifest data structure.
108
 
109
+ $post_data = array(
110
+ 'post_title' => $manifest_data['title'],
111
+ 'post_type' => CPT_Kits::get_instance()->cpt_slug,
112
+ 'post_status' => 'publish',
 
 
 
 
 
 
 
113
  );
114
+ $post_id = wp_insert_post( $post_data, true );
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  if ( $post_id && ! is_wp_error( $post_id ) ) {
117
  // successfully stored this post. Add some metadata
 
118
  update_post_meta( $post_id, 'envato_tk_manifest', $manifest_data );
119
  update_post_meta( $post_id, 'envato_tk_folder_name', $template_kit_random_folder );
120
  update_post_meta( $post_id, 'envato_tk_builder', $manifest_data['page_builder'] );
inc/helper.php CHANGED
@@ -1,6 +1,5 @@
1
  <?php
2
 
3
-
4
  namespace Envato_Template_Kit_Import;
5
 
6
  if ( ! defined( 'ABSPATH' ) ) {
1
  <?php
2
 
 
3
  namespace Envato_Template_Kit_Import;
4
 
5
  if ( ! defined( 'ABSPATH' ) ) {
languages/template-kit-import.pot CHANGED
@@ -34,7 +34,7 @@ msgstr ""
34
  msgid "Something went wrong."
35
  msgstr ""
36
 
37
- #: inc/class-builder-elementor.php:80
38
  msgid "Import into Elementor Library"
39
  msgstr ""
40
 
@@ -42,11 +42,11 @@ msgstr ""
42
  msgid "Import Template"
43
  msgstr ""
44
 
45
- #: inc/class-importer.php:181
46
  msgid "Template Kit"
47
  msgstr ""
48
 
49
- #: inc/class-importer.php:181
50
  msgid "Import Template Kit for Page/Site Builders."
51
  msgstr ""
52
 
@@ -66,10 +66,36 @@ msgstr ""
66
  msgid "3. Select Templates"
67
  msgstr ""
68
 
69
- #: views/importer/step1-upload.php:16
 
 
 
 
70
  msgid "Next"
71
  msgstr ""
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  #. translators: %s Template kit name
74
  #: views/importer/step2.php:23
75
  msgid "The %s requires the following plugins to work best, select the plugins you would like to install:"
@@ -95,10 +121,23 @@ msgstr ""
95
  msgid "Plugin Error"
96
  msgstr ""
97
 
98
- #: views/importer/step3.php:30
 
 
 
 
 
 
 
 
 
99
  msgid "Edit"
100
  msgstr ""
101
 
102
- #: views/importer/step3.php:31
103
  msgid "Import Again"
104
  msgstr ""
 
 
 
 
34
  msgid "Something went wrong."
35
  msgstr ""
36
 
37
+ #: inc/class-builder-elementor.php:84
38
  msgid "Import into Elementor Library"
39
  msgstr ""
40
 
42
  msgid "Import Template"
43
  msgstr ""
44
 
45
+ #: inc/class-importer.php:161
46
  msgid "Template Kit"
47
  msgstr ""
48
 
49
+ #: inc/class-importer.php:161
50
  msgid "Import Template Kit for Page/Site Builders."
51
  msgstr ""
52
 
66
  msgid "3. Select Templates"
67
  msgstr ""
68
 
69
+ #: views/importer/step1-upload.php:14
70
+ msgid "Upload Template Kit Zip File"
71
+ msgstr ""
72
+
73
+ #: views/importer/step1-upload.php:16, views/importer/step1.php:56, views/importer/step2.php:60
74
  msgid "Next"
75
  msgstr ""
76
 
77
+ #. translators: %s: Template Kit Name
78
+ #: views/importer/step1.php:39
79
+ msgid "%s - Template Kit"
80
+ msgstr ""
81
+
82
+ #: views/importer/step1.php:45
83
+ msgid "Uploaded Successfully"
84
+ msgstr ""
85
+
86
+ #. translators: %s: Template Kit Upload Date
87
+ #: views/importer/step1.php:48
88
+ msgid "Uploaded on %s"
89
+ msgstr ""
90
+
91
+ #: views/importer/step1.php:52
92
+ msgid "Delete Template Kit"
93
+ msgstr ""
94
+
95
+ #: views/importer/step1.php:63
96
+ msgid "Upload Another Template Kit"
97
+ msgstr ""
98
+
99
  #. translators: %s Template kit name
100
  #: views/importer/step2.php:23
101
  msgid "The %s requires the following plugins to work best, select the plugins you would like to install:"
121
  msgid "Plugin Error"
122
  msgstr ""
123
 
124
+ #. translators: %1$s: <strong> opening html tag, %2$s: </strong> closing html tag, %3$s: <a> opening html tag, %4$s: </a> closing html tag
125
+ #: views/importer/step3.php:28
126
+ msgid "%1$sWarning!%2$s There are plugins that need installing or activating for this Template Kit to work correctly. Go back to %3$sInstall Plugins%4$s."
127
+ msgstr ""
128
+
129
+ #: views/importer/step3.php:56
130
+ msgid "Imported"
131
+ msgstr ""
132
+
133
+ #: views/importer/step3.php:66
134
  msgid "Edit"
135
  msgstr ""
136
 
137
+ #: views/importer/step3.php:67
138
  msgid "Import Again"
139
  msgstr ""
140
+
141
+ #: views/importer/step3.php:78
142
+ msgid "Ignore Requirements"
143
+ msgstr ""
readme.txt CHANGED
@@ -26,13 +26,18 @@ We will update this page with links to where to find Template Kits shortly.
26
 
27
  **How do I make a Template Kit?**
28
 
29
- Create your own "Template Kit" for others with the "Template Kit Export" plugin.
30
 
31
  == Screenshots ==
32
 
33
- 1. **Screenshot.**
 
 
34
 
35
  == Changelog ==
36
 
 
 
 
37
  = 1.0.0-RC2 - 2020-01-09 =
38
  * Initial public release candidate.
26
 
27
  **How do I make a Template Kit?**
28
 
29
+ Create your own "Template Kit" for others with the "[Template Kit Export](https://wordpress.org/plugins/template-kit-export/)" plugin.
30
 
31
  == Screenshots ==
32
 
33
+ 1. **Upload template kit.**
34
+ 2. **Install plugins.**
35
+ 3. **Select templates.**
36
 
37
  == Changelog ==
38
 
39
+ = 1.0.0 - 2020-01-16 =
40
+ * Official release for public use.
41
+
42
  = 1.0.0-RC2 - 2020-01-09 =
43
  * Initial public release candidate.
src/scss/admin/_templates.scss CHANGED
@@ -1,4 +1,15 @@
 
 
1
  .envato-template-kit-import{
 
 
 
 
 
 
 
 
 
2
  &__templates {
3
  display: flex;
4
  flex-wrap: wrap;
@@ -14,6 +25,10 @@
14
  border: 1px solid $gray-mouse;
15
  }
16
 
 
 
 
 
17
  &__template-screenshot-wrapper {
18
  height: 300px;
19
  overflow: hidden;
@@ -35,6 +50,67 @@
35
  padding: 20px 0;
36
  }
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  &__button-import {
39
  @include button($wp-primary);
40
  }
@@ -44,4 +120,10 @@
44
  &__button-import-again {
45
  @include button($gray);
46
  }
 
 
 
 
 
 
47
  }
1
+ @keyframes templateImportSpin { 100% { transform:rotate(360deg); } }
2
+
3
  .envato-template-kit-import{
4
+ &__plugin-warning {
5
+ background-color: #f2dede;
6
+ border: 1px solid #ebcccc;
7
+ color: #a94442;
8
+
9
+ padding: .75rem 1.25rem;
10
+ margin-top: 20px;
11
+ border-radius: .25rem;
12
+ }
13
  &__templates {
14
  display: flex;
15
  flex-wrap: wrap;
25
  border: 1px solid $gray-mouse;
26
  }
27
 
28
+ &__imported-flag {
29
+ display: none;
30
+ }
31
+
32
  &__template-screenshot-wrapper {
33
  height: 300px;
34
  overflow: hidden;
50
  padding: 20px 0;
51
  }
52
 
53
+ &__template-import-option--imported,
54
+ &__template-import-option--unmet-requirements {
55
+ display: none;
56
+ }
57
+ &__template--imported {
58
+ position: relative;
59
+ overflow: hidden;
60
+ .envato-template-kit-import__template-import-option--fresh {
61
+ display: none;
62
+ }
63
+ .envato-template-kit-import__template-import-option--imported {
64
+ display: block;
65
+ }
66
+ .envato-template-kit-import__imported-flag {
67
+ width: 200px;
68
+ display: block;
69
+ background: $wp-primary;
70
+ position: absolute;
71
+ top: 21px;
72
+ text-align: center;
73
+ line-height: 30px;
74
+ letter-spacing: 1px;
75
+ color: #fff;
76
+ transform: rotate(45deg);
77
+ right: -65px;
78
+ }
79
+ }
80
+ &__template--importing {
81
+ .envato-template-kit-import__button-import-again,
82
+ .envato-template-kit-import__button-import {
83
+ padding-right: 40px;
84
+ position: relative;
85
+
86
+ &:after {
87
+ content: "\f463";
88
+ font-family: dashicons;
89
+ display: block;
90
+ line-height: 1;
91
+ font-weight: 400;
92
+ font-style: normal;
93
+ speak: none;
94
+ text-decoration: inherit;
95
+ position: absolute;
96
+ font-size: 27px;
97
+ right: 6px;
98
+ top: 10px;
99
+ color: #fff;
100
+ animation: templateImportSpin 4s linear infinite;
101
+ }
102
+ }
103
+ }
104
+ &__template--unmet-requirements {
105
+ .envato-template-kit-import__template-import-option--fresh,
106
+ .envato-template-kit-import__template-import-option--imported {
107
+ display: none;
108
+ }
109
+ .envato-template-kit-import__template-import-option--unmet-requirements {
110
+ display: block;
111
+ }
112
+ }
113
+
114
  &__button-import {
115
  @include button($wp-primary);
116
  }
120
  &__button-import-again {
121
  @include button($gray);
122
  }
123
+ &__button-upload-new {
124
+ @include button($gray);
125
+ }
126
+ &__button-ignore-requirements {
127
+ @include button($danger, #fff, $buttonSmall);
128
+ }
129
  }
src/scss/admin/_upload.scss CHANGED
@@ -1,10 +1,42 @@
1
  .envato-template-kit-import {
2
- // Step 1 - Upload
3
  &__template-kit {
 
 
4
  align-items: center;
5
  display: flex;
6
  flex-direction: row;
7
  margin-bottom: 40px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  }
9
 
10
  &__title {
@@ -24,6 +56,19 @@
24
  }
25
  }
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  &__next {
28
  margin-left: auto;
29
  }
@@ -68,4 +113,4 @@
68
  }
69
 
70
  }
71
- }
1
  .envato-template-kit-import {
2
+ // Step 1 - List of Template Kits
3
  &__template-kit {
4
+ background-color: #fff;
5
+ border: 1px solid #e0e5e9;
6
  align-items: center;
7
  display: flex;
8
  flex-direction: row;
9
  margin-bottom: 40px;
10
+ padding: 20px;
11
+
12
+ &:hover {
13
+ .envato-template-kit-import__btn-delete {
14
+ left: 0;
15
+ }
16
+ }
17
+ }
18
+
19
+ &__template-kit--imported {
20
+ .envato-template-kit-import__template-meta {
21
+ &:before {
22
+ content: "\f147";
23
+ font-family: dashicons;
24
+ display: block;
25
+ line-height: 1;
26
+ font-weight: 400;
27
+ font-style: normal;
28
+ speak: none;
29
+ text-decoration: inherit;
30
+ position: absolute;
31
+ font-size: 60px;
32
+ color: #82b541;
33
+ }
34
+ }
35
+
36
+ .envato-template-kit-import__title,
37
+ .envato-template-kit-import__message {
38
+ margin: 0 0 10px 70px;
39
+ }
40
  }
41
 
42
  &__title {
56
  }
57
  }
58
 
59
+ &__btn-delete {
60
+ background: transparent;
61
+ border: none;
62
+ color: #a00;
63
+ font-size: 13px;
64
+ position: relative;
65
+ left: -9999em;
66
+
67
+ &:hover {
68
+ color: #dc3232;
69
+ }
70
+ }
71
+
72
  &__next {
73
  margin-left: auto;
74
  }
113
  }
114
 
115
  }
116
+ }
template-kit-import.php CHANGED
@@ -4,7 +4,7 @@
4
  * Description: Import Template Kits to WordPress
5
  * Author: Envato
6
  * Author URI: https://envato.com
7
- * Version: 1.0.0-RC2
8
  * License: GPLv3 or later
9
  * License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
  *
@@ -28,7 +28,7 @@ if ( ! defined( 'ABSPATH' ) ) {
28
  }
29
 
30
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_SLUG', 'template-kit-import' );
31
- define( 'ENVATO_TEMPLATE_KIT_IMPORT_VER', '1.0.0-RC2' );
32
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_FILE', __FILE__ );
33
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_DIR', plugin_dir_path( ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
34
  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.0
8
  * License: GPLv3 or later
9
  * License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
  *
28
  }
29
 
30
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_SLUG', 'template-kit-import' );
31
+ define( 'ENVATO_TEMPLATE_KIT_IMPORT_VER', '1.0.0' );
32
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_FILE', __FILE__ );
33
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_DIR', plugin_dir_path( ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
34
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_URI', plugins_url( '/', ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
views/importer/step1-upload.php CHANGED
@@ -11,7 +11,7 @@ if ( ! defined( 'ABSPATH' ) ) {
11
  <div class="envato-template-kit-import__upload">
12
  <form class="envato-template-kit-import__upload-form" action="<?php echo esc_url( admin_url( 'admin.php?action=envato_template_kit_import_upload' ) ); ?>" method="POST" enctype="multipart/form-data">
13
  <?php wp_nonce_field( 'envato_template_kit_import' ); ?>
14
- <label for="file" class="envato-template-kit-import__upload-btn"><span class="dashicons dashicons-upload"></span> Upload Template Kit Zip file</label>
15
  <input id="file" class="envato-template-kit-import__upload-hidden" type="file" name="template_kit" />
16
  <input type="submit" name="sign_up" id="sign_up" class="envato-template-kit-import__upload-btn-next-input" data-cy="submit_button" value="<?php esc_attr_e( 'Next', 'template-kit-import' ); ?>"/>
17
  </form>
11
  <div class="envato-template-kit-import__upload">
12
  <form class="envato-template-kit-import__upload-form" action="<?php echo esc_url( admin_url( 'admin.php?action=envato_template_kit_import_upload' ) ); ?>" method="POST" enctype="multipart/form-data">
13
  <?php wp_nonce_field( 'envato_template_kit_import' ); ?>
14
+ <label for="file" class="envato-template-kit-import__upload-btn"><span class="dashicons dashicons-upload"></span> <?php esc_attr_e( 'Upload Template Kit Zip File', 'template-kit-import' ); ?></label>
15
  <input id="file" class="envato-template-kit-import__upload-hidden" type="file" name="template_kit" />
16
  <input type="submit" name="sign_up" id="sign_up" class="envato-template-kit-import__upload-btn-next-input" data-cy="submit_button" value="<?php esc_attr_e( 'Next', 'template-kit-import' ); ?>"/>
17
  </form>
views/importer/step1.php CHANGED
@@ -8,39 +8,65 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  $existing_kits = CPT_Kits::get_instance()->get_all_uploaded_kits();
10
 
11
- ?>
12
- <div class="envato-template-kit-import__upload">
13
-
14
- <?php
15
  if ( ! $existing_kits || isset( $_GET['upload'] ) ) {
16
  require __DIR__ . '/step1-upload.php';
17
  } else {
 
 
 
 
 
18
  foreach ( $existing_kits as $template_kit ) {
 
 
19
  // Attempt to load this template kit to confirm it's a valid builder type, and get access to helper methods:
20
- $template_kit_manager = envato_template_kit_import_get_builder( $template_kit->ID );
21
  if ( $template_kit_manager ) {
22
  // Grab a list of templates from this kit, so we can use the first one as a screenshot url:
23
  $template_kit_templates = $template_kit_manager->get_available_templates();
 
24
  ?>
25
- <div class="envato-template-kit-import__template-kit">
26
  <div class="envato-template-kit-import__screenshot">
27
- <img src="<?php echo esc_url( $template_kit_templates[0]['screenshot_url'] ); ?>" alt="<?php echo esc_attr( $template_kit->post_title ); ?>" />
 
 
28
  </div>
29
  <div class="envato-template-kit-import__template-meta">
30
- <p class="envato-template-kit-import__title"><?php echo esc_html( $template_kit->post_title ); ?></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  </div>
32
  <div class="envato-template-kit-import__next">
33
  <a class="envato-template-kit-import__upload-btn-next-link"
34
- href="<?php echo esc_url( Importer::get_instance()->get_url() ); ?>&step=2&template_kit_id=<?php echo (int) $template_kit->ID; ?>">Next</a>
35
  </div>
36
  </div>
37
  <?php
38
  }
39
  }
40
  ?>
41
- <a class="envato-template-kit-import__button-import" href="<?php echo esc_url( Importer::get_instance()->get_url() ); ?>&upload">Upload New Template Kit</a>
42
  <?php
43
  }
44
  ?>
45
- </div>
 
 
 
 
46
  <?php
8
 
9
  $existing_kits = CPT_Kits::get_instance()->get_all_uploaded_kits();
10
 
 
 
 
 
11
  if ( ! $existing_kits || isset( $_GET['upload'] ) ) {
12
  require __DIR__ . '/step1-upload.php';
13
  } else {
14
+
15
+ // If the user just imports a template kit then we have access to it's ID as a query string.
16
+ // Only show the 'successfully uploaded' message for these kits.
17
+ $imported_template_kit_id = isset( $_GET['imported_template_kit_id'] ) ? (int) $_GET['imported_template_kit_id'] : -1;
18
+
19
  foreach ( $existing_kits as $template_kit ) {
20
+ // Get template kit id
21
+ $template_kit_id = $template_kit->ID;
22
  // Attempt to load this template kit to confirm it's a valid builder type, and get access to helper methods:
23
+ $template_kit_manager = envato_template_kit_import_get_builder( $template_kit_id );
24
  if ( $template_kit_manager ) {
25
  // Grab a list of templates from this kit, so we can use the first one as a screenshot url:
26
  $template_kit_templates = $template_kit_manager->get_available_templates();
27
+ $freshly_imported = $imported_template_kit_id && $imported_template_kit_id === $template_kit_id;
28
  ?>
29
+ <div class="envato-template-kit-import__template-kit<?php echo $freshly_imported ? ' envato-template-kit-import__template-kit--imported' : ''; ?> js-template-kit-id-<?php echo esc_attr( $template_kit_id ); ?>">
30
  <div class="envato-template-kit-import__screenshot">
31
+ <a href="<?php echo esc_url( Importer::get_instance()->get_url() ); ?>&step=2&template_kit_id=<?php echo (int) $template_kit_id; ?>">
32
+ <img src="<?php echo esc_url( $template_kit_templates[0]['screenshot_url'] ); ?>" alt="<?php echo esc_attr( $template_kit->post_title ); ?>" />
33
+ </a>
34
  </div>
35
  <div class="envato-template-kit-import__template-meta">
36
+ <p class="envato-template-kit-import__title">
37
+ <?php
38
+ /* translators: %s: Template Kit Name */
39
+ printf( esc_html__( '%s - Template Kit', 'template-kit-import' ), esc_html( $template_kit->post_title ) );
40
+ ?>
41
+ </p>
42
+ <p class="envato-template-kit-import__message">
43
+ <?php
44
+ if ( $freshly_imported ) {
45
+ esc_html_e( 'Uploaded Successfully', 'template-kit-import' );
46
+ } else {
47
+ /* translators: %s: Template Kit Upload Date */
48
+ printf( esc_html__( 'Uploaded on %s', 'template-kit-import' ), date_i18n( 'F j, Y g:i:a', strtotime( $template_kit->post_date ) ) );
49
+ }
50
+ ?>
51
+ </p>
52
+ <p><button class="envato-template-kit-import__btn-delete js-template-kit-delete" data-nonce="<?php echo wp_create_nonce( 'delete_template_kit_' . $template_kit_id ); ?>" data-template-kit-id="<?php echo (int) $template_kit_id; ?>"><?php echo esc_html_e( 'Delete Template Kit', 'template-kit-import' ); ?></button></p>
53
  </div>
54
  <div class="envato-template-kit-import__next">
55
  <a class="envato-template-kit-import__upload-btn-next-link"
56
+ href="<?php echo esc_url( Importer::get_instance()->get_url() ); ?>&step=2&template_kit_id=<?php echo (int) $template_kit_id; ?>"><?php esc_html_e( 'Next', 'template-kit-import' ); ?></a>
57
  </div>
58
  </div>
59
  <?php
60
  }
61
  }
62
  ?>
63
+ <a class="envato-template-kit-import__button-upload-new" href="<?php echo esc_url( Importer::get_instance()->get_url() ); ?>&upload"><?php esc_html_e( 'Upload Another Template Kit', 'template-kit-import' ); ?></a>
64
  <?php
65
  }
66
  ?>
67
+ <script>
68
+ jQuery( function () {
69
+ window.TemplateKitImport && window.TemplateKitImport().initImportPage();
70
+ } );
71
+ </script>
72
  <?php
views/importer/step2.php CHANGED
@@ -57,7 +57,7 @@ $required_plugins = $template_kit->get_required_plugins();
57
  </div>
58
  </div>
59
  <div class="envato-template-kit-import__plugin-list-next">
60
- <a class="envato-template-kit-import__plugin-list-next-button" href="<?php echo esc_url( Importer::get_instance()->get_url() ); ?>&step=3&template_kit_id=<?php echo (int) $template_kit_id; ?>">Next</a>
61
  </div>
62
  </div>
63
 
57
  </div>
58
  </div>
59
  <div class="envato-template-kit-import__plugin-list-next">
60
+ <a class="envato-template-kit-import__plugin-list-next-button js-template-kit-plugin-next" href="<?php echo esc_url( Importer::get_instance()->get_url() ); ?>&step=3&template_kit_id=<?php echo (int) $template_kit_id; ?>"><?php esc_html_e( 'Next', 'template-kit-import' ); ?></a>
61
  </div>
62
  </div>
63
 
views/importer/step3.php CHANGED
@@ -12,13 +12,49 @@ if ( ! $template_kit ) {
12
  wp_die( 'Invalid Template Kit ID' );
13
  }
14
 
15
- $templates = $template_kit->get_available_templates();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
 
17
  ?>
18
-
19
  <div class="envato-template-kit-import__templates">
20
- <?php foreach ( $templates as $template_index => $template ) { ?>
21
- <div class="envato-template-kit-import__template">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  <div class="envato-template-kit-import__template-screenshot-wrapper">
23
  <img src="<?php echo esc_url( $template['screenshot_url'] ); ?>" alt="<?php echo esc_attr( $template['name'] ); ?>" class="envato-template-kit-import__template-screenshot" />
24
  </div>
@@ -26,12 +62,21 @@ $templates = $template_kit->get_available_templates();
26
  <?php echo esc_html( $template['name'] ); ?>
27
  </div>
28
  <div class="envato-template-kit-import__template-import-options">
29
- <?php if ( $template['imports'] ) { ?>
30
- <a href="<?php echo esc_url( $template_kit->get_imported_template_edit_url() ); ?>" target="_blank" class="envato-template-kit-import__button-edit"><?php esc_html_e( 'Edit', 'template-kit-import' ); ?></a>
31
  <button class="envato-template-kit-import__button-import-again js-template-kit-import" data-nonce="<?php echo esc_attr( wp_create_nonce( 'import_template_kit_' . $template_kit_id ) ); ?>" data-template-kit-id="<?php echo (int) $template_kit_id; ?>" data-template-index="<?php echo (int) $template_index; ?>"><?php echo esc_html_e( 'Import Again', 'template-kit-import' ); ?></button>
32
- <?php } else { ?>
 
33
  <button class="envato-template-kit-import__button-import js-template-kit-import" data-nonce="<?php echo esc_attr( wp_create_nonce( 'import_template_kit_' . $template_kit_id ) ); ?>" data-template-kit-id="<?php echo (int) $template_kit_id; ?>" data-template-index="<?php echo (int) $template_index; ?>"><?php echo esc_html( $template_kit->get_import_button_text() ); ?></button>
34
- <?php } ?>
 
 
 
 
 
 
 
 
35
  </div>
36
  </div>
37
  <?php } ?>
12
  wp_die( 'Invalid Template Kit ID' );
13
  }
14
 
15
+ // We flag if the user has missed some plugin requirements from the previous step.
16
+ $has_pending_plugin_requirements = false;
17
+ $required_plugins = $template_kit->get_required_plugins();
18
+ foreach ( $required_plugins as $required_plugin ) {
19
+ if ( 'activated' !== $required_plugin['status'] && 'update' !== $required_plugin['status'] ) {
20
+ $has_pending_plugin_requirements = true;
21
+ }
22
+ }
23
+ if ( $has_pending_plugin_requirements ) {
24
+ ?>
25
+ <div class="envato-template-kit-import__plugin-warning">
26
+ <?php
27
+ /* translators: %1$s: <strong> opening html tag, %2$s: </strong> closing html tag, %3$s: <a> opening html tag, %4$s: </a> closing html tag */
28
+ printf( esc_html__( '%1$sWarning!%2$s There are plugins that need installing or activating for this Template Kit to work correctly. Go back to %3$sInstall Plugins%4$s.', 'template-kit-import' ), '<strong>', '</strong>', '<a href="' . esc_url( $step2_url ) . '">', '</a>' );
29
+ ?>
30
+ </div>
31
+ <?php
32
+ }
33
 
34
+ $templates = $template_kit->get_available_templates();
35
  ?>
 
36
  <div class="envato-template-kit-import__templates">
37
+ <?php
38
+ foreach ( $templates as $template_index => $template ) {
39
+ $classes = array(
40
+ 'js-single-template',
41
+ 'envato-template-kit-import__template',
42
+ );
43
+ if ( $template['imports'] ) {
44
+ // This template has been imported before, flag it so:
45
+ $classes[] = 'envato-template-kit-import__template--imported';
46
+ } else {
47
+ $unmet_requirements = $template_kit->get_list_of_unmet_requirements( $template );
48
+ if ( $unmet_requirements ) {
49
+ // This template needs Elementor Pro, but the user doesn't have it active.
50
+ $classes[] = 'envato-template-kit-import__template--unmet-requirements';
51
+ }
52
+ }
53
+ ?>
54
+ <div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>" data-template-index="<?php echo (int) $template_index; ?>">
55
+ <div class="envato-template-kit-import__imported-flag">
56
+ <?php esc_html_e( 'Imported', 'template-kit-import' ); ?>
57
+ </div>
58
  <div class="envato-template-kit-import__template-screenshot-wrapper">
59
  <img src="<?php echo esc_url( $template['screenshot_url'] ); ?>" alt="<?php echo esc_attr( $template['name'] ); ?>" class="envato-template-kit-import__template-screenshot" />
60
  </div>
62
  <?php echo esc_html( $template['name'] ); ?>
63
  </div>
64
  <div class="envato-template-kit-import__template-import-options">
65
+ <div class="envato-template-kit-import__template-import-option--imported">
66
+ <a href="<?php echo esc_url( $template_kit->get_imported_template_edit_url( $template['imports'] ? $template['imports'][0]['imported_template_id'] : 0 ) ); ?>" target="_blank" class="envato-template-kit-import__button-edit js-edit-template"><?php esc_html_e( 'Edit', 'template-kit-import' ); ?></a>
67
  <button class="envato-template-kit-import__button-import-again js-template-kit-import" data-nonce="<?php echo esc_attr( wp_create_nonce( 'import_template_kit_' . $template_kit_id ) ); ?>" data-template-kit-id="<?php echo (int) $template_kit_id; ?>" data-template-index="<?php echo (int) $template_index; ?>"><?php echo esc_html_e( 'Import Again', 'template-kit-import' ); ?></button>
68
+ </div>
69
+ <div class="envato-template-kit-import__template-import-option--fresh">
70
  <button class="envato-template-kit-import__button-import js-template-kit-import" data-nonce="<?php echo esc_attr( wp_create_nonce( 'import_template_kit_' . $template_kit_id ) ); ?>" data-template-kit-id="<?php echo (int) $template_kit_id; ?>" data-template-index="<?php echo (int) $template_index; ?>"><?php echo esc_html( $template_kit->get_import_button_text() ); ?></button>
71
+ </div>
72
+ <div class="envato-template-kit-import__template-import-option--unmet-requirements">
73
+ <ul>
74
+ <?php foreach ( $unmet_requirements as $unmet_requirement ) { ?>
75
+ <li><?php echo esc_html( $unmet_requirement ); ?></li>
76
+ <?php } ?>
77
+ </ul>
78
+ <button class="envato-template-kit-import__button-ignore-requirements js-template-kit-ignore-requirements" data-template-index="<?php echo (int) $template_index; ?>"><?php echo esc_html_e( 'Ignore Requirements', 'template-kit-import' ); ?></button>
79
+ </div>
80
  </div>
81
  </div>
82
  <?php } ?>