VK Block Patterns - Version 1.25.3

Version Description

[ Specification Change ] Changed to cache pattern api data. [ Fix ] Add Snackbar when success save setting or not.

Download this release

Release Info

Developer vektor-inc
Plugin Icon wp plugin VK Block Patterns
Version 1.25.3
Comparing to
See all releases

Code changes from version 1.25.2 to 1.25.3

admin/admin.php CHANGED
@@ -57,6 +57,7 @@ function vbp_setting_page() {
57
  $lang = ( get_locale() === 'ja' ) ? 'ja' : 'en';
58
  if ( 'ja' === $lang ) {
59
  $get_menu_html .= '<li><a href="#pattern-library-setting">' . __( 'VK Pattern Library Setting', 'vk-block-patterns' ) . '</a></li>';
 
60
  }
61
 
62
  Vk_Admin::admin_page_frame( $get_page_title, 'vbp_setting', $get_logo_html, $get_menu_html );
@@ -153,6 +154,7 @@ function vbp_admin_enqueue_scripts( $hook_suffix ) {
153
  $vbp_options = vbp_get_options();
154
  $vbp_options['adminUrl'] = admin_url();
155
  $vbp_options['template'] = get_template();
 
156
  wp_localize_script( 'vk-patterns-admin-js', 'vkpOptions', $vbp_options );
157
  }
158
  add_action( 'admin_enqueue_scripts', 'vbp_admin_enqueue_scripts' );
@@ -216,8 +218,6 @@ function vbp_vws_alert_list() {
216
  return $alert;
217
  }
218
 
219
-
220
-
221
  /**
222
  * 警告を追加
223
  *
@@ -279,3 +279,15 @@ function vbp_admin_control() {
279
  update_option( 'vk_block_patterns_options', $options );
280
  }
281
  add_action( 'admin_init', 'vbp_admin_control' );
 
 
 
 
 
 
 
 
 
 
 
 
57
  $lang = ( get_locale() === 'ja' ) ? 'ja' : 'en';
58
  if ( 'ja' === $lang ) {
59
  $get_menu_html .= '<li><a href="#pattern-library-setting">' . __( 'VK Pattern Library Setting', 'vk-block-patterns' ) . '</a></li>';
60
+ $get_menu_html .= '<li><a href="#cache-setting">' . __( 'Patterns data cache setting', 'vk-block-patterns' ) . '</a></li>';
61
  }
62
 
63
  Vk_Admin::admin_page_frame( $get_page_title, 'vbp_setting', $get_logo_html, $get_menu_html );
154
  $vbp_options = vbp_get_options();
155
  $vbp_options['adminUrl'] = admin_url();
156
  $vbp_options['template'] = get_template();
157
+ $vbp_options['ajaxUrl'] = admin_url( 'admin-ajax.php' );
158
  wp_localize_script( 'vk-patterns-admin-js', 'vkpOptions', $vbp_options );
159
  }
160
  add_action( 'admin_enqueue_scripts', 'vbp_admin_enqueue_scripts' );
218
  return $alert;
219
  }
220
 
 
 
221
  /**
222
  * 警告を追加
223
  *
279
  update_option( 'vk_block_patterns_options', $options );
280
  }
281
  add_action( 'admin_init', 'vbp_admin_control' );
282
+
283
+ /**
284
+ * API連携で取得したパターンデータのキャッシュを削除
285
+ * Delete Cache Pattern Data from API
286
+ */
287
+ function vbp_clear_patterns_cache() {
288
+ delete_transient( 'vk_patterns_api_data' );
289
+ die();
290
+ }
291
+ // 'clear_patterns_cache' の部分は src/admin/js/index.js で定義している.
292
+ add_action( 'wp_ajax_clear_patterns_cache', 'vbp_clear_patterns_cache' );
293
+ add_action( 'wp_ajax_nopriv_clear_patterns_cache', 'vbp_clear_patterns_cache' );
build/admin/index.asset.php CHANGED
@@ -1 +1 @@
1
- <?php return array('dependencies' => array('wp-api', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'f9b7d6579890233b957f');
1
+ <?php return array('dependencies' => array('wp-api', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'eeda52860fc671c215ed');
build/admin/index.js CHANGED
@@ -1 +1 @@
1
- !function(){"use strict";var e,t={406:function(e,t,n){var r=window.wp.element,a=window.wp.i18n,l=window.wp.components,o=window.wp.api,i=n.n(o);(0,r.render)((0,r.createElement)((()=>{const e="1"===vkpOptions.showPatternsLink,t="1"===vkpOptions.disableCorePattern,n="1"===vkpOptions.disablePluginPattern,[o,s]=(0,r.useState)({role:vkpOptions.role,showPatternsLink:e,VWSMail:vkpOptions.VWSMail,disableCorePattern:t,disablePluginPattern:n}),c=e=>{s(e)},[p,u]=(0,r.useState)(!1),[k,b]=(0,r.useState)(""),v=(0,a.getLocaleData)()[""].lang,m=vkpOptions.adminUrl+"edit.php?post_type=vk-block-patterns",d=vkpOptions.template;return(0,r.createElement)(r.Fragment,null,(0,r.createElement)("div",null,(0,r.createElement)("section",null,(0,r.createElement)("h3",{id:"role-setting"},(0,a.__)("Role Setting","vk-block-patterns")),(0,r.createElement)("p",null,(0,a.__)("User permission to register patterns in VK Block Patterns","vk-block-patterns")," [ ",(0,r.createElement)("a",{href:m},"VK Block Patterns")," ]"),(0,r.createElement)(l.SelectControl,{value:o.role,onChange:e=>{c({...o,role:e})},options:[{label:(0,a.__)("Contributor or higher","vk-block-patterns"),value:"contributor"},{label:(0,a.__)("Author or higher","vk-block-patterns"),value:"author"},{label:(0,a.__)("Editor or higher","vk-block-patterns"),value:"editor"},{label:(0,a.__)("Administrator only","vk-block-patterns"),value:"administrator"}]})),(0,r.createElement)("section",null,(0,r.createElement)("h3",{id:"default-patterns-setting"},(0,a.__)("Default Pattern Setting","vk-block-patterns")),(0,r.createElement)(l.ToggleControl,{label:(0,a.__)("Disable WordPress Core Patterns","vk-block-patterns"),checked:o.disableCorePattern,onChange:e=>{c({...o,disableCorePattern:e})}}),(0,r.createElement)(l.ToggleControl,{label:(0,a.__)("Disable default patterns of this plugin","vk-block-patterns"),checked:o.disablePluginPattern,onChange:e=>{c({...o,disablePluginPattern:e})}}),"ja_JP"===v&&""!==o.VWSMail&&"x-t9"===d&&(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.ToggleControl,{label:(0,a.__)("Disable X-T9 patterns","vk-block-patterns"),checked:o.disableXT9Pattern,onChange:e=>{c({...o,disableXT9Pattern:e})}}))),"ja_JP"===v&&(0,r.createElement)(r.Fragment,null,(0,r.createElement)("h3",{id:"pattern-library-setting"},(0,a.__)("VK Pattern Library Setting","vk-block-patterns")),(0,r.createElement)("section",null,(0,r.createElement)("h4",null,"アカウント連携"),(0,r.createElement)("p",null,(0,r.createElement)("a",{href:"https://vws.vektor-inc.co.jp/product/lightning-g3-pro-pack?ref=vkbp-admin",target:"_blank"},"Lightning G3 Pro Pack")," のライセンスをお持ちのユーザーは ",(0,r.createElement)("a",{href:"https://patterns.vektor-inc.co.jp/",target:"_blank"},"VK Pattern Library")," でお気に入りに登録したパターンをエディター上で直接呼び出す事ができます。"),(0,r.createElement)("p",null,"お気に入り登録・連携を利用するには VK Pattern Library のユーザーアカウントを発行する必要があります。",(0,r.createElement)("br",null),"[ ",(0,r.createElement)("a",{href:"https://patterns.vektor-inc.co.jp/about/about-favorite/",target:"_blank"},(0,a.__)("Click here for more information on Favorites","vk-block-patterns"))," ]"),(0,r.createElement)(l.TextControl,{type:"email",className:"vws-mail-address",label:"VK Pattern Library のアカウントのメールアドレス",value:o.VWSMail,onChange:e=>{c({...o,VWSMail:e})}})),(0,r.createElement)("section",null,(0,r.createElement)("h4",null,(0,a.__)("Editor Setting","vk-block-patterns")),(0,r.createElement)(l.ToggleControl,{label:(0,a.__)("Show VK Pattern Library link in editor toolbar","vk-block-patterns"),checked:o.showPatternsLink,onChange:e=>{c({...o,showPatternsLink:e})}}))),(0,r.createElement)(l.Button,{isPrimary:!0,onClick:()=>{u(!0),i().loadPromise.then((()=>{const e=new(i().models.Settings)({vk_block_patterns_options:o}).save();e.success((()=>{setTimeout((()=>{u(!1),b(!0)}),600)})),e.error((()=>{setTimeout((()=>{u(!1),b(!1)}),600)}))}))},isBusy:p},(0,a.__)("Save setting","vk-block-patterns")),p&&(0,r.createElement)(l.Spinner,null),!1===k&&(0,a.__)("Failed to save.","vk-block-patterns")))}),null),document.getElementById("vk_block_patterns_admin"))}},n={};function r(e){var a=n[e];if(void 0!==a)return a.exports;var l=n[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.m=t,e=[],r.O=function(t,n,a,l){if(!n){var o=1/0;for(p=0;p<e.length;p++){n=e[p][0],a=e[p][1],l=e[p][2];for(var i=!0,s=0;s<n.length;s++)(!1&l||o>=l)&&Object.keys(r.O).every((function(e){return r.O[e](n[s])}))?n.splice(s--,1):(i=!1,l<o&&(o=l));if(i){e.splice(p--,1);var c=a();void 0!==c&&(t=c)}}return t}l=l||0;for(var p=e.length;p>0&&e[p-1][2]>l;p--)e[p]=e[p-1];e[p]=[n,a,l]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={846:0,966:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var a,l,o=n[0],i=n[1],s=n[2],c=0;if(o.some((function(t){return 0!==e[t]}))){for(a in i)r.o(i,a)&&(r.m[a]=i[a]);if(s)var p=s(r)}for(t&&t(n);c<o.length;c++)l=o[c],r.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return r.O(p)},n=self.webpackChunkvk_block_patterns=self.webpackChunkvk_block_patterns||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))}();var a=r.O(void 0,[966],(function(){return r(406)}));a=r.O(a)}();
1
+ !function(){"use strict";var e,t={406:function(e,t,n){var r=window.wp.element,a=window.wp.i18n,l=window.wp.components,o=window.wp.api,i=n.n(o);(0,r.render)((0,r.createElement)((()=>{const e="1"===vkpOptions.showPatternsLink,t="1"===vkpOptions.disableCorePattern,n="1"===vkpOptions.disablePluginPattern,[o,c]=(0,r.useState)({role:vkpOptions.role,showPatternsLink:e,VWSMail:vkpOptions.VWSMail,disableCorePattern:t,disablePluginPattern:n}),s=e=>{c(e)},[u,p]=(0,r.useState)(!1),[k,b]=(0,r.useState)(""),[v,m]=(0,r.useState)(!1),[d,_]=(0,r.useState)(""),[h,g]=(0,r.useState)(!1),f=(0,a.getLocaleData)()[""].lang,E=vkpOptions.adminUrl+"edit.php?post_type=vk-block-patterns",P=vkpOptions.template,S=vkpOptions.ajaxUrl;return(0,r.useEffect)((()=>{k&&setTimeout((()=>{b()}),3e3)}),[k]),(0,r.useEffect)((()=>{d&&setTimeout((()=>{_()}),3e3)}),[d]),(0,r.createElement)(r.Fragment,null,(0,r.createElement)("div",null,(0,r.createElement)("section",null,(0,r.createElement)("h3",{id:"role-setting"},(0,a.__)("Role Setting","vk-block-patterns")),(0,r.createElement)("p",null,(0,a.__)("User permission to register patterns in VK Block Patterns","vk-block-patterns")," ","[ ",(0,r.createElement)("a",{href:E},"VK Block Patterns")," ]"),(0,r.createElement)(l.SelectControl,{value:o.role,onChange:e=>{s({...o,role:e})},options:[{label:(0,a.__)("Contributor or higher","vk-block-patterns"),value:"contributor"},{label:(0,a.__)("Author or higher","vk-block-patterns"),value:"author"},{label:(0,a.__)("Editor or higher","vk-block-patterns"),value:"editor"},{label:(0,a.__)("Administrator only","vk-block-patterns"),value:"administrator"}]})),(0,r.createElement)("section",null,(0,r.createElement)("h3",{id:"default-patterns-setting"},(0,a.__)("Default Pattern Setting","vk-block-patterns")),(0,r.createElement)(l.ToggleControl,{label:(0,a.__)("Disable WordPress Core Patterns","vk-block-patterns"),checked:o.disableCorePattern,onChange:e=>{s({...o,disableCorePattern:e})}}),(0,r.createElement)(l.ToggleControl,{label:(0,a.__)("Disable default patterns of this plugin","vk-block-patterns"),checked:o.disablePluginPattern,onChange:e=>{s({...o,disablePluginPattern:e})}}),"ja_JP"===f&&""!==o.VWSMail&&"x-t9"===P&&(0,r.createElement)(r.Fragment,null,(0,r.createElement)(l.ToggleControl,{label:(0,a.__)("Disable X-T9 patterns","vk-block-patterns"),checked:o.disableXT9Pattern,onChange:e=>{s({...o,disableXT9Pattern:e})}}))),"ja_JP"===f&&(0,r.createElement)(r.Fragment,null,(0,r.createElement)("h3",{id:"pattern-library-setting"},(0,a.__)("VK Pattern Library Setting","vk-block-patterns")),(0,r.createElement)("section",null,(0,r.createElement)("h4",null,"アカウント連携"),(0,r.createElement)("p",null,(0,r.createElement)("a",{href:"https://vws.vektor-inc.co.jp/product/lightning-g3-pro-pack?ref=vkbp-admin",target:"_blank",rel:"noreferrer"},"Lightning G3 Pro Pack")," ","のライセンスをお持ちのユーザーは"," ",(0,r.createElement)("a",{href:"https://patterns.vektor-inc.co.jp/",target:"_blank",rel:"noreferrer"},"VK Pattern Library")," ","でお気に入りに登録したパターンをエディター上で直接呼び出す事ができます。"),(0,r.createElement)("p",null,"お気に入り登録・連携を利用するには VK Pattern Library のユーザーアカウントを発行する必要があります。",(0,r.createElement)("br",null),"["," ",(0,r.createElement)("a",{href:"https://patterns.vektor-inc.co.jp/about/about-favorite/",target:"_blank",rel:"noreferrer"},(0,a.__)("Click here for more information on Favorites","vk-block-patterns"))," ","]"),(0,r.createElement)(l.TextControl,{type:"email",className:"vws-mail-address",label:"VK Pattern Library のアカウントのメールアドレス",value:o.VWSMail,onChange:e=>{s({...o,VWSMail:e}),g(!0)}})),(0,r.createElement)("section",null,(0,r.createElement)("h4",null,(0,a.__)("Editor Setting","vk-block-patterns")),(0,r.createElement)(l.ToggleControl,{label:(0,a.__)("Show VK Pattern Library link in editor toolbar","vk-block-patterns"),checked:o.showPatternsLink,onChange:e=>{s({...o,showPatternsLink:e})}})),(0,r.createElement)("section",null,(0,r.createElement)("h3",{id:"cache-setting"},(0,a.__)("Patterns data cache setting","vk-block-patterns")),(0,r.createElement)("p",null,(0,a.__)("If the VK Pattern Library data is old, please try clearing the cache.","vk-block-patterns")),(0,r.createElement)(l.Button,{isSecondary:!0,onClick:()=>{m(!0);const e=new XMLHttpRequest;e.open("POST",S,!0),e.setRequestHeader("content-type","application/x-www-form-urlencoded;charset=UTF-8"),e.send("action=clear_patterns_cache"),m(!1),_(!0)},isBusy:v},(0,a.__)("Clear Cache","vk-block-patterns")),v&&(0,r.createElement)(l.Spinner,null),!0===d&&(0,r.createElement)("div",null,(0,r.createElement)(l.Snackbar,null,(0,a.__)("Cache cleared","vk-block-patterns")," ")))),(0,r.createElement)(l.Button,{isPrimary:!0,onClick:()=>{p(!0),i().loadPromise.then((()=>{const e=new(i().models.Settings)({vk_block_patterns_options:o}).save();e.success((()=>{setTimeout((()=>{p(!1),b(!0)}),600),!0===h&&location.reload()})),e.error((()=>{setTimeout((()=>{p(!1),b(!1)}),600)}))}))},isBusy:u},(0,a.__)("Save setting","vk-block-patterns")),u&&(0,r.createElement)(l.Spinner,null),!0===k&&(0,r.createElement)("div",null,(0,r.createElement)(l.Snackbar,null,(0,a.__)("Save Success","vk-block-patterns")," ")),!1===k&&(0,r.createElement)("div",null,(0,r.createElement)(l.Snackbar,null,(0,a.__)("Failed to save.","vk-block-patterns")," "))))}),null),document.getElementById("vk_block_patterns_admin"))}},n={};function r(e){var a=n[e];if(void 0!==a)return a.exports;var l=n[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.m=t,e=[],r.O=function(t,n,a,l){if(!n){var o=1/0;for(u=0;u<e.length;u++){n=e[u][0],a=e[u][1],l=e[u][2];for(var i=!0,c=0;c<n.length;c++)(!1&l||o>=l)&&Object.keys(r.O).every((function(e){return r.O[e](n[c])}))?n.splice(c--,1):(i=!1,l<o&&(o=l));if(i){e.splice(u--,1);var s=a();void 0!==s&&(t=s)}}return t}l=l||0;for(var u=e.length;u>0&&e[u-1][2]>l;u--)e[u]=e[u-1];e[u]=[n,a,l]},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e={846:0,966:0};r.O.j=function(t){return 0===e[t]};var t=function(t,n){var a,l,o=n[0],i=n[1],c=n[2],s=0;if(o.some((function(t){return 0!==e[t]}))){for(a in i)r.o(i,a)&&(r.m[a]=i[a]);if(c)var u=c(r)}for(t&&t(n);s<o.length;s++)l=o[s],r.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return r.O(u)},n=self.webpackChunkvk_block_patterns=self.webpackChunkvk_block_patterns||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))}();var a=r.O(void 0,[966],(function(){return r(406)}));a=r.O(a)}();
favorite-patterns/favorite-patterns.php CHANGED
@@ -7,6 +7,15 @@
7
 
8
  /**
9
  * API からデータを読み込み
 
 
 
 
 
 
 
 
 
10
  */
11
  function vbp_get_pattern_api_data() {
12
  $options = vbp_get_options();
@@ -14,17 +23,28 @@ function vbp_get_pattern_api_data() {
14
  $return = '';
15
 
16
  if ( ! empty( $user_email ) ) {
17
- $result = wp_remote_post(
18
- 'https://patterns.vektor-inc.co.jp/wp-json/vk-patterns/v1/status',
19
- array(
20
- 'timeout' => 10,
21
- 'body' => array(
22
- 'login_id' => $user_email,
23
- ),
24
- )
25
- );
26
- if ( ! empty( $result ) && ! is_wp_error( $result ) ) {
27
- $return = json_decode( $result['body'], true );
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
  }
30
  return $return;
@@ -32,43 +52,28 @@ function vbp_get_pattern_api_data() {
32
 
33
  /**
34
  * パターンを登録
 
 
 
 
 
 
 
 
35
  */
36
- function vbp_register_favorite_patterns() {
37
- $pattern_api_data = vbp_get_pattern_api_data();
38
- $current_template = get_template();
39
- $options = vbp_get_options();
40
- if ( ! empty( $pattern_api_data ) && is_array( $pattern_api_data ) ) {
41
- if ( ! empty( $pattern_api_data['patterns'] ) ) {
42
- $patterns_data = $pattern_api_data['patterns'];
43
-
44
- if ( function_exists( 'mb_convert_encoding' ) ) {
45
- $patterns_data = mb_convert_encoding( $patterns_data, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN' );
46
- }
47
-
48
- $patterns = json_decode( $patterns_data, true );
49
- register_block_pattern_category(
50
- 'vk-pattern-favorites',
51
- array(
52
- 'label' => __( 'Favorites of VK Pattern Library', 'vk-block-patterns' ),
53
- )
54
- );
55
- if ( ! empty( $patterns ) && is_array( $patterns ) ) {
56
- foreach ( $patterns as $pattern ) {
57
- register_block_pattern(
58
- $pattern['post_name'],
59
- array(
60
- 'title' => $pattern['title'],
61
- 'categories' => $pattern['categories'],
62
- 'content' => $pattern['content'],
63
- )
64
- );
65
- }
66
- }
67
- }
68
 
69
- if ( 'x-t9' === $current_template && false === $options['disableXT9Pattern'] ) {
70
- if ( ! empty( $pattern_api_data['x-t9'] ) ) {
71
- $patterns_data = $pattern_api_data['x-t9'];
72
 
73
  if ( function_exists( 'mb_convert_encoding' ) ) {
74
  $patterns_data = mb_convert_encoding( $patterns_data, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN' );
@@ -76,14 +81,14 @@ function vbp_register_favorite_patterns() {
76
 
77
  $patterns = json_decode( $patterns_data, true );
78
  register_block_pattern_category(
79
- 'x-t9',
80
  array(
81
- 'label' => __( 'X-T9', 'vk-block-patterns' ),
82
  )
83
  );
84
  if ( ! empty( $patterns ) && is_array( $patterns ) ) {
85
  foreach ( $patterns as $pattern ) {
86
- register_block_pattern(
87
  $pattern['post_name'],
88
  array(
89
  'title' => $pattern['title'],
@@ -94,7 +99,38 @@ function vbp_register_favorite_patterns() {
94
  }
95
  }
96
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
  }
 
99
  }
100
  add_action( 'init', 'vbp_register_favorite_patterns' );
7
 
8
  /**
9
  * API からデータを読み込み
10
+ *
11
+ * @return array{
12
+ * array {
13
+ * role: string,
14
+ * title: string,
15
+ * categories: array,
16
+ * content: string,
17
+ * }
18
+ * } $return
19
  */
20
  function vbp_get_pattern_api_data() {
21
  $options = vbp_get_options();
23
  $return = '';
24
 
25
  if ( ! empty( $user_email ) ) {
26
+ // パターン情報をキャッシュデータから読み込み読み込み.
27
+ $transients = get_transient( 'vk_patterns_api_data' );
28
+
29
+ // パターンのキャッシュがあればキャッシュを読み込み.
30
+ if ( ! empty( $transients ) ) {
31
+ $return = $transients;
32
+ } else {
33
+ // キャッシュがない場合 API を呼び出しキャッシュに登録.
34
+ $result = wp_remote_post(
35
+ 'https://patterns.vektor-inc.co.jp/wp-json/vk-patterns/v1/status',
36
+ array(
37
+ 'timeout' => 10,
38
+ 'body' => array(
39
+ 'login_id' => $user_email,
40
+ ),
41
+ )
42
+ );
43
+ if ( ! empty( $result ) && ! is_wp_error( $result ) ) {
44
+ $return = json_decode( $result['body'], true );
45
+ // APIで取得したパターンデータをキャッシュに登録. 1日 に設定.
46
+ set_transient( 'vk_patterns_api_data', $return, 60 * 60 * 24 );
47
+ }
48
  }
49
  }
50
  return $return;
52
 
53
  /**
54
  * パターンを登録
55
+ *
56
+ * @param array $api テスト用に用意した API を読み込む変数(通常は空).
57
+ * @param string $template テスト用に用意した現在のテーマが何かを読み込む変数(通常は空).
58
+ *
59
+ * @return array{
60
+ * 'favorite' => array(),
61
+ * 'x-t9' => array()
62
+ * } $returnx : 成功したらそれぞれの配列に true が入ってくる.
63
  */
64
+ function vbp_register_favorite_patterns( $api = null, $template = null ) {
65
+ $options = vbp_get_options();
66
+ $result = array(
67
+ 'favorite' => array(),
68
+ 'x-t9' => array(),
69
+ );
70
+ if ( ! empty( $options['VWSMail'] ) ) {
71
+ $pattern_api_data = ! empty( $api ) ? $api : vbp_get_pattern_api_data();
72
+ $current_template = ! empty( $template ) ? $template : get_template();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
+ if ( ! empty( $pattern_api_data ) && is_array( $pattern_api_data ) ) {
75
+ if ( ! empty( $pattern_api_data['patterns'] ) ) {
76
+ $patterns_data = $pattern_api_data['patterns'];
77
 
78
  if ( function_exists( 'mb_convert_encoding' ) ) {
79
  $patterns_data = mb_convert_encoding( $patterns_data, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN' );
81
 
82
  $patterns = json_decode( $patterns_data, true );
83
  register_block_pattern_category(
84
+ 'vk-pattern-favorites',
85
  array(
86
+ 'label' => __( 'Favorites of VK Pattern Library', 'vk-block-patterns' ),
87
  )
88
  );
89
  if ( ! empty( $patterns ) && is_array( $patterns ) ) {
90
  foreach ( $patterns as $pattern ) {
91
+ $result['favorite'][] = register_block_pattern(
92
  $pattern['post_name'],
93
  array(
94
  'title' => $pattern['title'],
99
  }
100
  }
101
  }
102
+
103
+ if ( 'x-t9' === $current_template && empty( $options['disableXT9Pattern'] ) ) {
104
+ if ( ! empty( $pattern_api_data['x-t9'] ) ) {
105
+ $patterns_data = $pattern_api_data['x-t9'];
106
+
107
+ if ( function_exists( 'mb_convert_encoding' ) ) {
108
+ $patterns_data = mb_convert_encoding( $patterns_data, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN' );
109
+ }
110
+
111
+ $patterns = json_decode( $patterns_data, true );
112
+ register_block_pattern_category(
113
+ 'x-t9',
114
+ array(
115
+ 'label' => __( 'X-T9', 'vk-block-patterns' ),
116
+ )
117
+ );
118
+ if ( ! empty( $patterns ) && is_array( $patterns ) ) {
119
+ foreach ( $patterns as $pattern ) {
120
+ $result['x-t9'][] = register_block_pattern(
121
+ $pattern['post_name'],
122
+ array(
123
+ 'title' => $pattern['title'],
124
+ 'categories' => $pattern['categories'],
125
+ 'content' => $pattern['content'],
126
+ )
127
+ );
128
+ }
129
+ }
130
+ }
131
+ }
132
  }
133
  }
134
+ return $result;
135
  }
136
  add_action( 'init', 'vbp_register_favorite_patterns' );
readme.txt CHANGED
@@ -16,6 +16,10 @@ When you activate this plugin that create new custom post type for custom block
16
 
17
  == Changelog ==
18
 
 
 
 
 
19
  = 1.25.2 =
20
  [ Bug fix ] Fix Setting Page Layout bug ( vk admin 2.6.0 )
21
 
16
 
17
  == Changelog ==
18
 
19
+ = 1.25.3 =
20
+ [ Specification Change ] Changed to cache pattern api data.
21
+ [ Fix ] Add Snackbar when success save setting or not.
22
+
23
  = 1.25.2 =
24
  [ Bug fix ] Fix Setting Page Layout bug ( vk admin 2.6.0 )
25
 
vk-block-patterns.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: VK Block Patterns
4
  * Plugin URI: https://github.com/vektor-inc/vk-block-patterns
5
  * Description: You can make and register your original custom block patterns.
6
- * Version: 1.25.2
7
  * Requires at least: 5.8
8
  * Author: Vektor,Inc.
9
  * Author URI: https://vektor-inc.co.jp
@@ -78,17 +78,11 @@ function vbp_plugin_loaded() {
78
  require_once VBP_PATH . 'inc/edit-post/vk-edit-post-config.php';
79
  // Load Admin Options.
80
  require_once VBP_PATH . 'admin/admin.php';
 
 
81
  }
82
  add_action( 'plugins_loaded', 'vbp_plugin_loaded' );
83
 
84
- // Add a link to this plugin's settings page
85
- function vbp_set_plugin_meta( $links ) {
86
- $settings_link = '<a href="options-general.php?page=vk_block_patterns_options">' . __( 'Setting', 'vk-block-patterns' ) . '</a>';
87
- array_unshift( $links, $settings_link );
88
- return $links;
89
- }
90
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'vbp_set_plugin_meta', 10, 1 );
91
-
92
  $options = vbp_get_options();
93
  if ( ! empty( $options['disableCorePattern'] ) ) {
94
  remove_theme_support( 'core-block-patterns' );
@@ -99,9 +93,13 @@ if ( ! empty( $options['disablePluginPattern'] ) ) {
99
  remove_action( 'init', array( 'wp_content\plugins\vk_block_patterns\patterns_data\Register_Patterns_From_Json', 'register_template' ) );
100
  }
101
 
102
- if ( ! empty( $options['VWSMail'] ) ) {
103
- require dirname( __FILE__ ) . '/favorite-patterns/favorite-patterns.php';
 
 
 
104
  }
 
105
 
106
  /**
107
  * Add pattern library link
3
  * Plugin Name: VK Block Patterns
4
  * Plugin URI: https://github.com/vektor-inc/vk-block-patterns
5
  * Description: You can make and register your original custom block patterns.
6
+ * Version: 1.25.3
7
  * Requires at least: 5.8
8
  * Author: Vektor,Inc.
9
  * Author URI: https://vektor-inc.co.jp
78
  require_once VBP_PATH . 'inc/edit-post/vk-edit-post-config.php';
79
  // Load Admin Options.
80
  require_once VBP_PATH . 'admin/admin.php';
81
+
82
+ require VBP_PATH . '/favorite-patterns/favorite-patterns.php';
83
  }
84
  add_action( 'plugins_loaded', 'vbp_plugin_loaded' );
85
 
 
 
 
 
 
 
 
 
86
  $options = vbp_get_options();
87
  if ( ! empty( $options['disableCorePattern'] ) ) {
88
  remove_theme_support( 'core-block-patterns' );
93
  remove_action( 'init', array( 'wp_content\plugins\vk_block_patterns\patterns_data\Register_Patterns_From_Json', 'register_template' ) );
94
  }
95
 
96
+ // Add a link to this plugin's settings page
97
+ function vbp_set_plugin_meta( $links ) {
98
+ $settings_link = '<a href="options-general.php?page=vk_block_patterns_options">' . __( 'Setting', 'vk-block-patterns' ) . '</a>';
99
+ array_unshift( $links, $settings_link );
100
+ return $links;
101
  }
102
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'vbp_set_plugin_meta', 10, 1 );
103
 
104
  /**
105
  * Add pattern library link