PluginProbe
LIQUID BLOCKS – Slider, Carousel, Accordion / 1.3.1
LIQUID BLOCKS – Slider, Carousel, Accordion v1.3.1
1.3.7 1.3.6 trunk 1.0 1.0.2 1.0.3 1.0.4 1.0.5 1.0.8 1.0.9 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5
liquid-blocks / liquid-blocks.php

liquid-blocks.php in LIQUID BLOCKS – Slider, Carousel, Accordion 1.3.1, at liquid-blocks.php

600 lines 25.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: LIQUID BLOCKS
4 Plugin URI: https://lqd.jp/wp/plugin.html
5 Description: A magic tool to master WordPress blocks.
6 Author: LIQUID DESIGN Ltd.
7 Author URI: https://lqd.jp/wp/
8 License: GPLv2
9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 Text Domain: liquid-blocks
11 Version: 1.3.1
12 */
13 /* Copyright 2019 LIQUID DESIGN Ltd. (email : info@lqd.jp)
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License, version 2, as
17 published by the Free Software Foundation.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 */
27
28 // ------------------------------------
29 // Plugin
30 // ------------------------------------
31 $liquid_blocks_data = get_file_data( __FILE__, array( 'version' => 'Version'));
32
33 // json
34 if ( is_admin() ) {
35 $json_liquid_blocks_error = "";
36 $json_liquid_blocks_url = "https://lqd.jp/wp/data/p/liquid-blocks.json";
37 $json_liquid_blocks = wp_remote_get($json_liquid_blocks_url);
38 if ( is_wp_error( $json_liquid_blocks ) ) {
39 $json_liquid_blocks_error = $json_liquid_blocks->get_error_message().$json_liquid_blocks_url;
40 }else{
41 $json_liquid_blocks = json_decode($json_liquid_blocks['body'], true);
42 }
43 }
44
45 // notices
46 function liquid_blocks_admin_notices() {
47 global $json_liquid_blocks, $json_liquid_blocks_error;
48 if( empty($json_liquid_blocks_error) ) {
49 if ( isset( $_GET['liquid_admin_notices_dismissed'] ) ) {
50 set_transient( 'liquid_admin_notices', 'dismissed', 60*60*24*30 );
51 }
52 if ( isset( $_GET['liquid_admin_offer_dismissed'] ) ) {
53 set_transient( 'liquid_admin_offer', 'dismissed', 60*60*24*30 );
54 }
55 if( !empty($json_liquid_blocks['news']) && get_transient( 'liquid_admin_notices' ) != 'dismissed' ){
56 echo '<div class="notice notice-info" style="position: relative;"><p>'.$json_liquid_blocks['news'].'</p><a href="?liquid_admin_notices_dismissed" style="position: absolute; right: 10px; top: 10px;">&times;</a></div>';
57 }
58 if( !empty($json_liquid_blocks['offer']) && get_transient( 'liquid_admin_offer' ) != 'dismissed' ){
59 echo '<div class="notice notice-info" style="position: relative;"><p>'.$json_liquid_blocks['offer'].'</p><a href="?liquid_admin_offer_dismissed" style="position: absolute; right: 10px; top: 10px;">&times;</a></div>';
60 }
61 }
62 }
63 add_action( 'admin_notices', 'liquid_blocks_admin_notices' );
64
65 // get_option
66 $liquid_blocks_toggle = get_option( 'liquid_blocks_toggle' );
67 $liquid_blocks_no = get_option( 'liquid_blocks_no' ) ? get_option( 'liquid_blocks_no' ) : [];
68 $liquid_blocks_type = get_option( 'liquid_blocks_type' ) ? get_option( 'liquid_blocks_type' ) : [];
69 $liquid_blocks_name = get_option( 'liquid_blocks_name' ) ? get_option( 'liquid_blocks_name' ) : [];
70 $liquid_blocks_clean = get_option( 'liquid_blocks_clean' ) ? get_option( 'liquid_blocks_clean' ) : [];
71 if( empty( $liquid_blocks_toggle ) ){
72 add_action( 'init', 'liquid_blocks_init' );
73 add_action( 'enqueue_block_assets', 'liquid_blocks_assets' );
74 add_action( 'enqueue_block_editor_assets', 'liquid_blocks_enqueue_block_editor_assets' );
75 add_action( 'admin_footer', 'liquid_blocks_admin_footer' );
76 }
77
78 // plugin_action_links
79 function liquid_blocks_plugin_action_links( $links ) {
80 $mylinks = '<a href="'.admin_url( 'options-general.php?page=liquid-blocks' ).'">'.__( 'Settings', 'liquid-blocks' ).'</a>';
81 array_unshift( $links, $mylinks);
82 return $links;
83 }
84 add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'liquid_blocks_plugin_action_links' );
85
86 function liquid_blocks_assets() {
87 global $liquid_blocks_data;
88 wp_enqueue_style( 'liquid-blocks', plugins_url( 'css/block.css' , __FILE__ ), array( 'swiper' ), $liquid_blocks_data['version'] );
89 // slider
90 wp_enqueue_style( 'swiper', plugins_url( 'css/swiper-bundle.min.css' , __FILE__ ), array() );
91 wp_enqueue_script( 'swiper', plugins_url( 'lib/swiper-bundle.min.js' , __FILE__ ), array() );
92 wp_enqueue_script( 'liquid-blocks', plugins_url( 'lib/liquid-blocks.js' , __FILE__ ), array( 'swiper' ) );
93 }
94
95 function liquid_blocks_enqueue_block_editor_assets(){
96 global $liquid_blocks_data, $liquid_blocks_no, $liquid_blocks_type, $liquid_blocks_name;
97 wp_enqueue_script( 'clipboard' );
98 wp_enqueue_script( 'liquid-blocks-template', plugins_url( 'lib/template.js', __FILE__ ), array(), $liquid_blocks_data['version'] );
99 wp_enqueue_script( 'liquid-blocks', plugins_url( 'lib/block.js', __FILE__ ), array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor', 'wp-plugins', 'wp-edit-post', 'wp-components', 'liquid-blocks-template', 'clipboard' ), $liquid_blocks_data['version'] );
100 wp_enqueue_script( 'liquid-blocks-cards', plugins_url( 'lib/block-cards.js', __FILE__ ), array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor', 'wp-components' ) );
101 wp_set_script_translations( 'liquid-blocks', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' );
102 wp_set_script_translations( 'liquid-blocks-cards', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' );
103 wp_localize_script( 'liquid-blocks-template', 'liquid_blocks_imgurl', array( plugins_url( 'images/', __FILE__ ) ) );
104 wp_localize_script( 'liquid-blocks', 'liquid_blocks_imgurl', array( plugins_url( 'images/', __FILE__ ) ) );
105 wp_localize_script( 'liquid-blocks', 'liquid_blocks_no', $liquid_blocks_no );
106 wp_localize_script( 'liquid-blocks', 'liquid_blocks_type', $liquid_blocks_type );
107 wp_localize_script( 'liquid-blocks', 'liquid_blocks_name', $liquid_blocks_name );
108 wp_enqueue_style( 'liquid-blocks', plugins_url( 'css/block.css' , __FILE__ ), array(), $liquid_blocks_data['version'] );
109 wp_enqueue_style( 'liquid-blocks-editor', plugins_url( 'css/block-editor.css' , __FILE__ ), array(), $liquid_blocks_data['version'] );
110 }
111
112 function liquid_blocks_admin_footer() {
113 global $pagenow, $post;
114 if( $pagenow == 'post.php' || $pagenow == 'post-new.php' ){
115 if ( apply_filters( 'replace_editor', false, $post ) !== true ) {
116 if ( use_block_editor_for_post( $post ) ) {
117 ?>
118 <!-- Gallery -->
119 <div id="liquid_blocks_modal" class="liquid_blocks_modal" style="display:none;">
120 <div class="liquid_blocks_modal_gallery">
121
122 <?php
123 $args = array(
124 'post_type' => array( 'liquid_block' ),
125 'post_status' => array( 'publish' ),
126 'posts_per_page' => -1,
127 'order' => 'ASC',
128 );
129 $the_query = new WP_Query( $args );
130 if ( $the_query->have_posts() ) {
131 $i = 0;
132 echo '<h3>'.__( 'Block Patterns', 'liquid-blocks' ).' <small>Patterns</small></h3>';
133 echo '<script>LiquidGallery[\'Patterns\'] = []</script>';
134 while ( $the_query->have_posts() ) {
135 $j = $i + 1;
136 $the_query->the_post();
137 $pattern_title = get_the_title();
138 if( !$pattern_title ){
139 $pattern_title = __( 'Untitled block', 'liquid-blocks' );
140 }
141 $pattern_content = get_the_content();
142 $pattern_categories = array();
143 $terms = get_the_terms( 0, 'liquid_patterns' );
144 if( !empty( $terms ) && !is_wp_error( $terms ) ){
145 foreach( $terms as $term ){
146 $pattern_categories[] = $term->slug;
147 }
148 }
149 if( has_post_thumbnail() ) {
150 $thumbnail_id = get_post_thumbnail_id();
151 $src_info = wp_get_attachment_image_src($thumbnail_id, $size = array(600,400));
152 $src = $src_info[0];
153 $class = '';
154 } else {
155 $src = plugins_url( 'images/noimage.png', __FILE__ );
156 $class = 'liquid_noimage';
157 }
158 if( $pattern_content ){
159 $pattern_content = str_replace( array("\r", "\n"), '', $pattern_content );
160 echo '<script>LiquidGallery[\'Patterns\']['.$i.'] = \''.addslashes($pattern_content).'\';</script>';
161 echo '<a onclick="LiquidGalleryButton(LiquidGallery[\'Patterns\']['.$i.'], this)" class="liquid_blocks_img '.$class.'"><img src="'.$src.'" alt=""><span>'.$j.': '.$pattern_title.'</span></a>';
162 $i++;
163 }
164 }
165 wp_reset_postdata();
166 }
167 ?>
168
169 <h3><?php _e( 'Headlines', 'liquid-blocks' ); ?> <small>Headlines</small></h3>
170 <script>LiquidGalleryList('Headlines');</script>
171 <h3><?php _e( 'Layouts', 'liquid-blocks' ); ?> <small>Layouts</small></h3>
172 <script>LiquidGalleryList('Layouts');</script>
173 <h3><?php _e( 'Price list', 'liquid-blocks' ); ?> <small>Price</small></h3>
174 <script>LiquidGalleryList('Price');</script>
175 <h3><?php _e( 'CTA: Call To Action', 'liquid-blocks' ); ?> <small>CTA</small></h3>
176 <script>LiquidGalleryList('CTA');</script>
177 <h3><?php _e( 'Landing pages', 'liquid-blocks' ); ?> <small>Landing</small></h3>
178 <script>LiquidGalleryList('Landing');</script>
179 <h3><?php _e( 'Recommended Plugins', 'liquid-blocks' ); ?></h3>
180 <a href="https://wordpress.org/plugins/liquid-speech-balloon/" target="_blank"><img src="<?php echo plugins_url( 'images/Recommend/liquid-speech-balloon.png', __FILE__ ); ?>" alt=""></a>
181 </div>
182 </div>
183 <!-- Multiple -->
184 <div id="liquid_blocks_buttons" class="liquid_blocks_buttons">
185 <a id="liquid_blocks_copy" class="liquid_blocks_copy liquid_blocks_btn none"><?php _e( 'Copy', 'liquid-blocks' ); ?></a><script>LiquidGalleryCopy();</script>
186 <a id="liquid_blocks_insert" onclick="LiquidGalleryInsert()" class="liquid_blocks_btn none"><?php _e( 'Insert', 'liquid-blocks' ); ?><span id="liquid_blocks_count"></span></a>
187 <a id="liquid_blocks_multiple" onclick="LiquidGalleryMultiple()" class="liquid_blocks_btn"><?php _e( 'Select', 'liquid-blocks' ); ?></a>
188 <a id="liquid_blocks_cancel" onclick="LiquidGalleryCancel()" class="liquid_blocks_btn none"><?php _e( 'Cancel', 'liquid-blocks' ); ?></a>
189 <a id="liquid_blocks_close" onclick="LiquidGalleryClose()" class="liquid_blocks_btn"><?php _e( 'Close', 'liquid-blocks' ); ?></a>
190 </div>
191 <?php
192 }
193 }
194 }
195 }
196
197 // ------------------------------------
198 // init
199 // ------------------------------------
200
201 // block_categories
202 function liquid_block_categories($categories, $post) {
203 return array_merge(
204 $categories,
205 array(
206 array(
207 'slug' => 'liquid',
208 'title' => 'LIQUID',
209 ),
210 )
211 );
212 }
213 add_filter('block_categories_all', 'liquid_block_categories', 10, 2);
214
215 function liquid_blocks_init(){
216 global $liquid_blocks_clean;
217
218 // pattern_category
219 register_block_pattern_category(
220 'liquid_headlines',
221 array( 'label' => __( 'Headlines', 'liquid-blocks' ) )
222 );
223 // img_path
224 $path = plugins_url( 'images/', __FILE__ );
225
226 // TODO: register_block_pattern
227 // $pattern_name = 'liquid/pattern1';
228 // $pattern_properties = array(
229 // 'title' => 'Simple image',
230 // 'content' => '<!-- wp:image --><figure class="wp-block-image"><img src="'.$path.'bear.png" alt=""/></figure><!-- /wp:image --><!-- wp:heading {"align":"center"} --><h2 style="text-align:center">Lorem ipsum dolor sit amet</h2><!-- /wp:heading -->',
231 // 'categories' => array( 'liquid_headlines' ),
232 // 'keywords' => array( 'images' ),
233 // 'description'=> 'A simple text and image pattern.',
234 // );
235 // register_block_pattern( $pattern_name, $pattern_properties );
236
237 // translations
238 load_plugin_textdomain( 'liquid-blocks', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
239
240 // slider
241 register_block_type( 'liquid/slider', array(
242 'editor_script' => 'liquid-blocks-slider',
243 'editor_style' => 'liquid-blocks-editor',
244 'attributes' => array(
245 'fields' => array(
246 'type' => 'array',
247 ),
248 'delay' => array(
249 'type' => 'number',
250 ),
251 'slidesPerView' => array(
252 'type' => 'number',
253 ),
254 'animationType' => array(
255 'type' => 'string',
256 ),
257 ),
258 ) );
259 wp_register_script(
260 'liquid-blocks-slider',
261 plugins_url( 'lib/block-slider.js', __FILE__ ),
262 array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor', 'wp-components' )
263 );
264 wp_set_script_translations(
265 'liquid-blocks-slider',
266 'liquid-blocks',
267 plugin_dir_path( __FILE__ ) . 'languages'
268 );
269
270 // カスタムフィールド
271 register_block_type('liquid/custom-field', array(
272 'editor_script' => 'liquid-blocks-custom-field',
273 'render_callback' => 'liquid_blocks_render_custom_field',
274 ));
275 wp_register_script(
276 'liquid-blocks-custom-field',
277 plugin_dir_url(__FILE__) . 'lib/block-custom-field.js',
278 array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor', 'wp-components')
279 );
280 wp_set_script_translations(
281 'liquid-blocks-custom-field',
282 'liquid-blocks',
283 plugin_dir_path( __FILE__ ) . 'languages'
284 );
285
286 // unregister_block_pattern
287 if( !empty($liquid_blocks_clean) ){
288 unregister_block_pattern( 'core/heading-paragraph' );
289 unregister_block_pattern( 'core/large-header' );
290 unregister_block_pattern( 'core/large-header-button' );
291 unregister_block_pattern( 'core/quote' );
292 unregister_block_pattern( 'core/text-two-columns' );
293 unregister_block_pattern( 'core/text-two-columns-with-images' );
294 unregister_block_pattern( 'core/text-three-columns-buttons' );
295 unregister_block_pattern( 'core/three-buttons' );
296 unregister_block_pattern( 'core/two-buttons' );
297 unregister_block_pattern( 'core/two-images' );
298 }
299
300 // register_post_type
301 register_post_type(
302 'liquid_block',
303 array(
304 'public' => true,
305 'description' => __( 'Block Pattern Manager', 'liquid-blocks' ),
306 'hierarchical' => false,
307 'has_archive' => false,
308 'labels' => array(
309 'name' => __( 'Block Pattern', 'liquid-blocks' ),
310 'menu_name' => __( 'Block Pattern', 'liquid-blocks' ),
311 'singular_name' => __( 'Block Pattern', 'liquid-blocks' ),
312 'all_items' => __( 'Block Pattern List', 'liquid-blocks' ),
313 'add_new' => __( 'Add New', 'liquid-blocks' ),
314 'add_new_item' => __( 'Add New', 'liquid-blocks' ),
315 'edit_item' => __( 'Edit', 'liquid-blocks' ),
316 ),
317 'publicly_queryable' => false,
318 'show_ui' => true,
319 'show_in_menu' => false,
320 'show_in_nav_menus' => false,
321 'show_in_admin_bar' => true,
322 'capability_type' => 'post',
323 'menu_position' => 9,
324 'query_var' => false,
325 'exclude_from_search' => true,
326 'publicly_queryable' => false,
327 'supports' => array(
328 'title',
329 'editor',
330 'author',
331 'thumbnail',
332 ),
333 'taxonomies' => array('liquid_block'),
334 'show_in_rest' => true,
335 )
336 );
337 register_taxonomy(
338 'liquid_patterns',
339 'liquid_block',
340 array(
341 'label' => __( 'Block Pattern Category', 'liquid-blocks' ),
342 'hierarchical' => false,
343 'public' => false,
344 'show_ui' => true,
345 'show_in_rest' => true,
346 'show_tagcloud' => false,
347 'labels' => array(
348 'singular_name' => __( 'Block Pattern Category', 'liquid-blocks' ),
349 'add_new_item' => __( 'Add New', 'liquid-blocks' ),
350 'separate_items_with_commas' => __( 'Press the Enter key.', 'liquid-blocks' ),
351 ),
352 )
353 );
354
355 $terms = get_terms( array( 'taxonomy' => 'liquid_patterns', 'get'=>'all' ) );
356 if( !empty( $terms ) && !is_wp_error( $terms ) ){
357 foreach( $terms as $term ){
358 register_block_pattern_category(
359 $term->slug,
360 array( 'label' => $term->name )
361 );
362 }
363 }
364
365 // register_block_pattern self-made
366 $args = array(
367 'post_type' => array( 'liquid_block' ),
368 'post_status' => array( 'publish' ),
369 'posts_per_page' => -1,
370 'order' => 'ASC',
371 );
372 $the_query = new WP_Query( $args );
373 if ( $the_query->have_posts() ) {
374 $i = 0;
375 while ( $the_query->have_posts() ) {
376 $the_query->the_post();
377 $pattern_title = get_the_title();
378 if( !$pattern_title ){
379 $pattern_title = __( 'Untitled block', 'liquid-blocks' );
380 }
381 $pattern_content = get_the_content();
382 $pattern_categories = array();
383 $terms = get_the_terms( 0, 'liquid_patterns' );
384 if( !empty( $terms ) && !is_wp_error( $terms ) ){
385 foreach( $terms as $term ){
386 $pattern_categories[] = $term->slug;
387 }
388 }
389 if( $pattern_content ){
390 register_block_pattern(
391 'liquid/liquid_pattern_' . $i,
392 array(
393 'title' => $pattern_title,
394 'content' => $pattern_content,
395 'categories' => $pattern_categories,
396 )
397 );
398 $i++;
399 }
400 }
401 wp_reset_postdata();
402 }
403 }
404
405 // カスタムフィールドブロックのレンダリング
406 function liquid_blocks_render_custom_field($attributes) {
407 // カスタムフィールドキーと投稿IDの取得
408 $fieldKey = isset($attributes['fieldKey']) ? $attributes['fieldKey'] : '';
409 $postId = isset($attributes['postId']) && !empty($attributes['postId']) ? intval($attributes['postId']) : get_the_ID();
410
411 // フィールドタイプを取得(テキストか画像か)
412 $fieldType = isset($attributes['fieldType']) ? $attributes['fieldType'] : 'text';
413
414 // デフォルトの alignment を設定
415 $alignment = isset($attributes['alignment']) ? $attributes['alignment'] : 'left';
416
417 // 追加CSSクラスを取得
418 $customClass = isset($attributes['className']) ? $attributes['className'] : '';
419
420 // スタイル属性を構築
421 $style = 'text-align:' . esc_attr($alignment) . ';';
422
423 // カスタムフィールドデータの取得
424 if (!empty($fieldKey)) {
425 $fieldValue = get_post_meta($postId, $fieldKey, true);
426
427 // フィールドタイプに基づいて処理を分ける
428 if ($fieldType === 'image') {
429 // 画像の場合
430 if (is_array($fieldValue)) {
431 // 繰り返し画像フィールドの場合の処理
432 $output = '<div class="liquid_custom_field_repeatable">';
433 foreach ($fieldValue as $mediaId) {
434 $image_url = wp_get_attachment_url($mediaId);
435 if ($image_url) {
436 $output .= '<div class="liquid_custom_field_item"><img src="' . esc_url($image_url) . '" alt="" /></div>';
437 }
438 }
439 $output .= '</div>';
440 } else {
441 // 単一画像フィールドの場合
442 $image_url = wp_get_attachment_url($fieldValue);
443 if ($image_url) {
444 $output = '<div class="liquid_custom_field_item"><img src="' . esc_url($image_url) . '" alt="" /></div>';
445 }
446 }
447 } else {
448 // テキストの場合
449 if (is_array($fieldValue)) {
450 // 繰り返しテキストフィールドの場合の処理
451 $output = '<div class="liquid_custom_field_repeatable">';
452 foreach ($fieldValue as $value) {
453 $output .= '<div class="liquid_custom_field_item">' . esc_html($value) . '</div>';
454 }
455 $output .= '</div>';
456 } else {
457 // 単一テキストフィールドの場合の処理
458 $output = '<div class="liquid_custom_field_item">' . esc_html($fieldValue) . '</div>';
459 }
460 }
461
462 // 追加CSSクラスを適用してカスタムフィールドの�
463 容をスタイル付きのdivでラップ
464 return '<div class="liquid_custom_field ' . esc_attr($customClass) . '" style="' . esc_attr($style) . '">' . $output . '</div>';
465 } else {
466 return '<div class="liquid_custom_field ' . esc_attr($customClass) . '">' . __('No custom field selected.', 'liquid-blocks') . '</div>';
467 }
468 }
469
470 // ------------------------------------
471 // Admin
472 // ------------------------------------
473 function liquid_blocks_admin() {
474 add_options_page(
475 'LIQUID BLOCKS',
476 'LIQUID BLOCKS',
477 'administrator',
478 'liquid-blocks',
479 'liquid_blocks_admin_page'
480 );
481 add_theme_page(
482 __( 'Patterns', 'liquid-blocks' ),
483 __( 'Patterns', 'liquid-blocks' ),
484 'administrator',
485 'edit.php?post_type=liquid_block'
486 );
487 register_setting(
488 'liquid_blocks_group',
489 'liquid_blocks_toggle',
490 'liquid_blocks_toggle_validation'
491 );
492 register_setting(
493 'liquid_blocks_group',
494 'liquid_blocks_no'
495 );
496 register_setting(
497 'liquid_blocks_group',
498 'liquid_blocks_type'
499 );
500 register_setting(
501 'liquid_blocks_group',
502 'liquid_blocks_name'
503 );
504 register_setting(
505 'liquid_blocks_group',
506 'liquid_blocks_clean'
507 );
508 }
509 add_action( 'admin_menu', 'liquid_blocks_admin' );
510
511 function liquid_blocks_toggle_validation( $input ) {
512 $input = (int) $input;
513 if ( $input === 0 || $input === 1 ) {
514 return $input;
515 } else {
516 add_settings_error(
517 'liquid_blocks_toggle',
518 'liquid_blocks_toggle_validation_error',
519 __( 'illegal data', 'liquid-blocks' ),
520 'error'
521 );
522 }
523 }
524
525 function liquid_blocks_admin_page() {
526 global $json_liquid_blocks, $liquid_blocks_toggle, $liquid_blocks_no, $liquid_blocks_type, $liquid_blocks_name, $liquid_blocks_clean;
527 if( empty( $liquid_blocks_toggle ) ){
528 $toggle_on = 'checked="checked"';
529 $toggle_off = '';
530 } else {
531 $toggle_on = '';
532 $toggle_off = 'checked="checked"';
533 }
534 if( empty( $liquid_blocks_clean ) ){
535 $clean_on = 'checked="checked"';
536 $clean_off = '';
537 } else {
538 $clean_on = '';
539 $clean_off = 'checked="checked"';
540 }
541 ?>
542 <div class="wrap">
543 <h1>LIQUID BLOCKS</h1>
544
545 <div id="poststuff">
546
547 <!-- Recommend -->
548 <?php if( !empty($json_liquid_blocks['recommend']) ){ ?>
549 <div class="postbox">
550 <h2 style="border-bottom: 1px solid #eee;"><?php _e( 'Recommend', 'liquid-blocks' ); ?></h2>
551 <div class="inside"><?php echo $json_liquid_blocks['recommend']; ?></div>
552 </div>
553 <?php } ?>
554
555 <!-- Settings -->
556 <div class="postbox">
557 <h2 style="border-bottom: 1px solid #eee;"><?php _e( 'Settings', 'liquid-blocks' ); ?></h2>
558 <div class="inside">
559 <form method="post" action="options.php">
560 <?php
561 settings_fields( 'liquid_blocks_group' );
562 do_settings_sections( 'default' );
563 ?>
564 <?php if ( function_exists('register_block_pattern') ) { ?>
565 <h3><?php _e( 'Block Pattern Manager', 'liquid-blocks' ); ?></h3>
566 <a href="edit.php?post_type=liquid_block" class="button button-primary"><?php _e( 'Block Pattern Manager', 'liquid-blocks' ); ?></a>
567 <p><?php _e( 'Featured Image', 'liquid-blocks' ); ?>: w600 x h400px</p>
568 <h3><?php _e( 'Enable default block pattern', 'liquid-blocks' ); ?></h3>
569 <p>
570 <label for="liquid_blocks_clean_on"><input type="radio" id="liquid_blocks_clean_on" name="liquid_blocks_clean" value="0" <?php echo $clean_on; ?>>On</label>
571 <label for="liquid_blocks_clean_off"><input type="radio" id="liquid_blocks_clean_off" name="liquid_blocks_clean" value="1" <?php echo $clean_off; ?>>Off</label>
572 </p>
573 <?php } ?>
574 <h3><?php _e( 'Shortcuts', 'liquid-blocks' ); ?></h3>
575 <p><?php _e( 'Sidebar shortcut button settings.', 'liquid-blocks' ); ?><br><?php _e( 'Enter any name, gallery category name, and number.', 'liquid-blocks' ); ?></p>
576 <?php
577 for ($i=0; $i<10; $i++) {
578 $j = $i + 1;
579 $no = !empty($liquid_blocks_no[$i]) ? $liquid_blocks_no[$i] : "";
580 $type = !empty($liquid_blocks_type[$i]) ? $liquid_blocks_type[$i] : "";
581 $name = !empty($liquid_blocks_name[$i]) ? $liquid_blocks_name[$i] : "";
582 echo '<p>'.$j.' Name:<input type="text" name="liquid_blocks_name['.$i.']" value="'.esc_html($name).'" placeholder="intro"> ';
583 echo 'Type:<input type="text" name="liquid_blocks_type['.$i.']" value="'.esc_html($type).'" placeholder="Headlines"> ';
584 echo 'No:<input type="number" name="liquid_blocks_no['.$i.']" value="'.esc_html($no).'"></p>';
585 }
586 ?>
587 <h3><?php _e( 'Enable', 'liquid-blocks' ); ?> LIQUID BLOCKS</h3>
588 <p>
589 <label for="liquid_blocks_toggle_on"><input type="radio" id="liquid_blocks_toggle_on" name="liquid_blocks_toggle" value="0" <?php echo $toggle_on; ?>>On</label>
590 <label for="liquid_blocks_toggle_off"><input type="radio" id="liquid_blocks_toggle_off" name="liquid_blocks_toggle" value="1" <?php echo $toggle_off; ?>>Off</label>
591 </p>
592 <?php submit_button(); ?>
593 </form>
594 </div>
595 </div>
596
597 </div><!-- /poststuff -->
598 <hr><a href="https://lqd.jp/wp/" target="_blank">LIQUID PRESS</a>
599 </div><!-- /wrap -->
600 <?php } ?>