VK Block Patterns - Version 1.0.2

Version Description

[ Bug fix ] fix is_plugin_active() php error

Download this release

Release Info

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

Code changes from version 1.0.1 to 1.0.2

patterns-data/class-register-patterns-from-json.php CHANGED
@@ -1,162 +1,164 @@
1
  <?php
2
- namespace wp_content\plugins\vk_block_patterns\patterns_data;
3
-
4
- class VK_RegisterPatternsFromJson {
5
-
6
- public function __construct(){
7
- add_action( 'init', array( __CLASS__, 'register_template' ) );
8
- add_action( 'wp_enqueue_scripts', array( __CLASS__, 'print_pattern_css' ) );
9
- add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'print_pattern_editor_css' ) );
10
- }
11
-
12
- public static function load_inline_css( $filename = 'style.css' ){
13
- $style_path = dirname( __FILE__ ) . '/' . $filename;
14
- $style_url = str_replace( ABSPATH, site_url() . '/', dirname( __FILE__ ) ) . '/' . $filename;
15
- $dynamic_css = '';
16
- if ( file_exists( $style_path ) ){
17
-
18
- $dynamic_css = file_get_contents( $style_path );
19
- // delete before after space
20
- $dynamic_css = trim( $dynamic_css );
21
- // convert tab and br to space
22
- $dynamic_css = preg_replace( '/[\n\r\t]/', '', $dynamic_css );
23
- // Change multiple spaces to single space
24
- $dynamic_css = preg_replace( '/\s(?=\s)/', '', $dynamic_css );
25
- }
26
- return $dynamic_css;
27
- }
28
-
29
- public static function print_pattern_css(){
30
- $css = self::load_inline_css();
31
- if ( $css ){
32
- wp_add_inline_style( 'wp-block-library', $css );
33
- }
34
- }
35
-
36
- public static function print_pattern_editor_css(){
37
- $css = self::load_inline_css();
38
- $css .= self::load_inline_css( 'style-editor.css' );
39
- if ( $css ){
40
- wp_add_inline_style( 'wp-edit-blocks', $css );
41
- }
42
- }
43
-
44
- public static function register_template(){
45
-
46
- // これは読み込み側では存在しないクラスなので要対応
47
- $json_dir_path = dirname( __FILE__ ) . '/';
48
-
49
- if ( function_exists( 'register_block_pattern_category' ) && function_exists( 'register_block_pattern' ) ) {
50
-
51
- // import category
52
- /* ------------------------------*/
53
- $category_json = $json_dir_path . 'category.json';
54
-
55
- if ( file_exists( $category_json ) ) {
56
- $json = file_get_contents( $category_json );
57
- $json = mb_convert_encoding( $json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
58
- $obj = json_decode( $json, true );
59
- foreach( $obj as $key => $val) {
60
- // Block Category.
61
- register_block_pattern_category(
62
- $val['slug'],
63
- array( 'label' => esc_html( $val['name'] ) )
64
- );
65
- }
66
- }
67
-
68
- // import Language
69
- /* ------------------------------*/
70
- $language_json = $json_dir_path . 'term-language.json';
71
-
72
- if ( file_exists( $language_json ) ) {
73
- $json = file_get_contents( $language_json );
74
- $json = mb_convert_encoding( $json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
75
- $obj = json_decode( $json, true );
76
- $languages = array();
77
- foreach( $obj as $key => $val) {
78
- $languages[] = $val['slug'];
79
- }
80
- }
81
-
82
- // タームのスラッグが小文字に変換されてしまうため小文字
83
- $site_lang = mb_strtolower( get_locale() );
84
-
85
- // 表示中のサイトの言語が言語カテゴリーに含まれている場合
86
- if ( in_array( $site_lang, $languages ) ){
87
- // 表示中の言語に合致したパターンのみ登録するモード
88
- $judge_lang_mode = true;
89
- } else {
90
- // 英語のパターンのみ登録するモード
91
- $judge_lang_mode = false;
92
- }
93
-
94
- /* import posts
95
- /* ------------------------------*/
96
- if ( is_plugin_active( 'vk-blocks/vk-blocks.php' ) ) {
97
- $filename = 'template-for-vk-free.json';
98
- } else if ( is_plugin_active( 'vk-blocks-pro/vk-blocks.php' ) ) {
99
- $filename = 'template-for-vk-pro.json';
100
- } else {
101
- $filename = 'template-exclude-vk.json';
102
- }
103
-
104
- $jsonUrl = $json_dir_path . $filename;
105
-
106
- if ( file_exists( $jsonUrl ) ) {
107
- $json = file_get_contents( $jsonUrl );
108
- $json = mb_convert_encoding( $json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
109
- $obj = json_decode( $json, true );
110
-
111
- $image_dir_path = $json_dir_path . 'images/';
112
- $image_dir_uri = str_replace( ABSPATH, site_url() . '/', $image_dir_path );
113
-
114
- foreach( $obj as $key => $val) {
115
-
116
- // 本文欄の /// エスケープを戻す
117
- $val = wp_unslash( $val );
118
-
119
- $val['content'] = str_replace( '[pattern_directory]', $image_dir_uri , $val['content'] );
120
-
121
- $langs = $val[ 'languages' ];
122
-
123
- // 表示中の言語に合致したパターンのみ登録するモード
124
- if ( $judge_lang_mode ){
125
- if ( in_array( $site_lang, $val[ 'languages' ] ) ){
126
- // 本来 $val['post_status'] は必ず必ず入ってくる。リリース前のデータ対応なので2021年3月以降削除可
127
- if ( ! isset( $val['post_status'] ) || $val['post_status'] === 'publish' ){
128
- register_block_pattern(
129
- $val['post_name'],
130
- array(
131
- 'title' => $val['title'],
132
- 'categories' => $val['categories'],
133
- 'content' => $val['content'],
134
- )
135
- );
136
- }
137
- }
138
-
139
- // 英語のパターンのみ登録するモード
140
- } else {
141
- if ( in_array( mb_strtolower( 'en_US' ), $val[ 'languages' ] ) ){
142
- if ( ! isset( $val['post_status'] ) || $val['post_status'] === 'publish' ){
143
- register_block_pattern(
144
- $val['post_name'],
145
- array(
146
- 'title' => $val['title'],
147
- 'categories' => $val['categories'],
148
- 'content' => $val['content'],
149
- )
150
- );
151
- }
152
- }
153
- }
154
- }
155
- } else {
156
- echo "データがありません";
157
- }
158
- }
159
- }
160
- }
161
-
162
- new VK_RegisterPatternsFromJson;
 
 
1
  <?php
2
+ namespace wp_content\plugins\_vk_block_patterns\patterns_data;
3
+
4
+ class VK_RegisterPatternsFromJson {
5
+
6
+ public function __construct() {
7
+ add_action( 'init', array( __CLASS__, 'register_template' ) );
8
+ add_action( 'wp_enqueue_scripts', array( __CLASS__, 'print_pattern_css' ) );
9
+ add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'print_pattern_editor_css' ) );
10
+ }
11
+
12
+ public static function load_inline_css( $filename = 'style.css' ) {
13
+ $style_path = wp_normalize_path( dirname( __FILE__ ) . '/' . $filename );
14
+ $style_url = str_replace( wp_normalize_path( ABSPATH ), site_url() . '/', $style_path );
15
+ $dynamic_css = '';
16
+ if ( file_exists( $style_path ) ) {
17
+
18
+ $dynamic_css = file_get_contents( $style_path );
19
+ // delete before after space
20
+ $dynamic_css = trim( $dynamic_css );
21
+ // convert tab and br to space
22
+ $dynamic_css = preg_replace( '/[\n\r\t]/', '', $dynamic_css );
23
+ // Change multiple spaces to single space
24
+ $dynamic_css = preg_replace( '/\s(?=\s)/', '', $dynamic_css );
25
+ }
26
+ return $dynamic_css;
27
+ }
28
+
29
+ public static function print_pattern_css() {
30
+ $css = self::load_inline_css();
31
+ if ( $css ) {
32
+ wp_add_inline_style( 'wp-block-library', $css );
33
+ }
34
+ }
35
+
36
+ public static function print_pattern_editor_css() {
37
+ $css = self::load_inline_css();
38
+ $css .= self::load_inline_css( 'style-editor.css' );
39
+ if ( $css ) {
40
+ wp_add_inline_style( 'wp-edit-blocks', $css );
41
+ }
42
+ }
43
+
44
+ public static function register_template() {
45
+
46
+ // これは読み込み側では存在しないクラスなので要対応
47
+ $json_dir_path = wp_normalize_path( dirname( __FILE__ ) . '/' );
48
+
49
+ if ( function_exists( 'register_block_pattern_category' ) && function_exists( 'register_block_pattern' ) ) {
50
+
51
+ // import category
52
+ /* ------------------------------*/
53
+ $category_json = $json_dir_path . 'category.json';
54
+
55
+ if ( file_exists( $category_json ) ) {
56
+ $json = file_get_contents( $category_json );
57
+ $json = mb_convert_encoding( $json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN' );
58
+ $obj = json_decode( $json, true );
59
+ foreach ( $obj as $key => $val ) {
60
+ // Block Category.
61
+ register_block_pattern_category(
62
+ $val['slug'],
63
+ array( 'label' => esc_html( $val['name'] ) )
64
+ );
65
+ }
66
+ }
67
+
68
+ // import Language
69
+ /* ------------------------------*/
70
+ $language_json = $json_dir_path . 'term-language.json';
71
+
72
+ if ( file_exists( $language_json ) ) {
73
+ $json = file_get_contents( $language_json );
74
+ $json = mb_convert_encoding( $json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN' );
75
+ $obj = json_decode( $json, true );
76
+ $languages = array();
77
+ foreach ( $obj as $key => $val ) {
78
+ $languages[] = $val['slug'];
79
+ }
80
+ }
81
+
82
+ // タームのスラッグが小文字に変換されてしまうため小文字
83
+ $site_lang = mb_strtolower( get_locale() );
84
+
85
+ // 表示中のサイトの言語が言語カテゴリーに含まれている場合
86
+ if ( in_array( $site_lang, $languages ) ) {
87
+ // 表示中の言語に合致したパターンのみ登録するモード
88
+ $judge_lang_mode = true;
89
+ } else {
90
+ // 英語のパターンのみ登録するモード
91
+ $judge_lang_mode = false;
92
+ }
93
+
94
+ /*
95
+ import posts
96
+ /* ------------------------------*/
97
+ $active_plugins = get_option( 'active_plugins', array() );
98
+ if ( in_array( 'vk-blocks/vk-blocks.php', $active_plugins ) ) {
99
+ $filename = 'template-for-vk-free.json';
100
+ } elseif ( in_array( 'vk-blocks-pro/vk-blocks.php', $active_plugins ) ) {
101
+ $filename = 'template-for-vk-pro.json';
102
+ } else {
103
+ $filename = 'template-exclude-vk.json';
104
+ }
105
+
106
+ $jsonUrl = $json_dir_path . $filename;
107
+
108
+ if ( file_exists( $jsonUrl ) ) {
109
+ $json = file_get_contents( $jsonUrl );
110
+ $json = mb_convert_encoding( $json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN' );
111
+ $obj = json_decode( $json, true );
112
+
113
+ $image_dir_path = $json_dir_path . 'images/';
114
+ $image_dir_uri = str_replace( wp_normalize_path( ABSPATH ), site_url() . '/', $image_dir_path );
115
+
116
+ foreach ( $obj as $key => $val ) {
117
+
118
+ // 本文欄の /// エスケープを戻す
119
+ $val = wp_unslash( $val );
120
+
121
+ $val['content'] = str_replace( '[pattern_directory]', $image_dir_uri, $val['content'] );
122
+
123
+ $langs = $val['languages'];
124
+
125
+ // 表示中の言語に合致したパターンのみ登録するモード
126
+ if ( $judge_lang_mode ) {
127
+ if ( in_array( $site_lang, $val['languages'] ) ) {
128
+ // 本来 $val['post_status'] は必ず必ず入ってくる。リリース前のデータ対応なので2021年3月以降削除可
129
+ if ( ! isset( $val['post_status'] ) || $val['post_status'] === 'publish' ) {
130
+ register_block_pattern(
131
+ $val['post_name'],
132
+ array(
133
+ 'title' => $val['title'],
134
+ 'categories' => $val['categories'],
135
+ 'content' => $val['content'],
136
+ )
137
+ );
138
+ }
139
+ }
140
+
141
+ // 英語のパターンのみ登録するモード
142
+ } else {
143
+ if ( in_array( mb_strtolower( 'en_US' ), $val['languages'] ) ) {
144
+ if ( ! isset( $val['post_status'] ) || $val['post_status'] === 'publish' ) {
145
+ register_block_pattern(
146
+ $val['post_name'],
147
+ array(
148
+ 'title' => $val['title'],
149
+ 'categories' => $val['categories'],
150
+ 'content' => $val['content'],
151
+ )
152
+ );
153
+ }
154
+ }
155
+ }
156
+ }
157
+ } else {
158
+ echo 'データがありません';
159
+ }
160
+ }
161
+ }
162
+ }
163
+
164
+ new VK_RegisterPatternsFromJson();
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: Guternberg, Block Pattern
5
  Requires at least: 5.6
6
  Tested up to: 5.6
7
- Stable tag: 1.0.1
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -16,6 +16,9 @@ When you activate this plugin that create new custom post type for custom block
16
 
17
  == Changelog ==
18
 
 
 
 
19
  = 1.0.1 =
20
  [ Other ] Delete vain file
21
 
4
  Tags: Guternberg, Block Pattern
5
  Requires at least: 5.6
6
  Tested up to: 5.6
7
+ Stable tag: 1.0.2
8
  Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
16
 
17
  == Changelog ==
18
 
19
+ = 1.0.2 =
20
+ [ Bug fix ] fix is_plugin_active() php error
21
+
22
  = 1.0.1 =
23
  [ Other ] Delete vain file
24
 
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.0.1
7
  * Author: Vektor,Inc.
8
  * Author URI: https://vektor-inc.co.jp
9
  * Text Domain: vk-block-patterns
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.0.2
7
  * Author: Vektor,Inc.
8
  * Author URI: https://vektor-inc.co.jp
9
  * Text Domain: vk-block-patterns