| 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.6 |
| 12 |
Requires at least: 6.0 |
| 13 |
*/ |
| 14 |
/* Copyright 2019 LIQUID DESIGN Ltd. (email : info@lqd.jp) |
| 15 |
|
| 16 |
This program is free software; you can redistribute it and/or modify |
| 17 |
it under the terms of the GNU General Public License, version 2, as |
| 18 |
published by the Free Software Foundation. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with this program; if not, write to the Free Software |
| 27 |
*/ |
| 28 |
|
| 29 |
// ------------------------------------ |
| 30 |
// Plugin |
| 31 |
// ------------------------------------ |
| 32 |
$liquid_blocks_data = get_file_data( __FILE__, array( 'version' => 'Version')); |
| 33 |
|
| 34 |
// api |
| 35 |
if ( is_admin() ) { |
| 36 |
$liquid_blocks_api = require_once 'inc/api.php'; |
| 37 |
$liquid_blocks_json = $liquid_blocks_api('https://lqd.jp/wp/data/p/liquid-blocks.json', 'liquid_blocks_json'); |
| 38 |
} |
| 39 |
|
| 40 |
// LIQUID PRO ライセンス認証(� |
| 41 |
�有ファイル・他プラグインと多重同梱可) |
| 42 |
require_once plugin_dir_path( __FILE__ ) . 'inc/liquid-pro.php'; |
| 43 |
|
| 44 |
// notices |
| 45 |
function liquid_blocks_admin_notices() { |
| 46 |
global $liquid_blocks_json; |
| 47 |
if( !empty($liquid_blocks_json) ) { |
| 48 |
if ( isset( $_GET['liquid_admin_notices_dismissed'] ) && current_user_can( 'manage_options' ) ) { |
| 49 |
set_transient( 'liquid_admin_notices', 'dismissed', 60*60*24*180 ); |
| 50 |
} |
| 51 |
if ( isset( $_GET['liquid_admin_offer_dismissed'] ) && current_user_can( 'manage_options' ) ) { |
| 52 |
set_transient( 'liquid_admin_offer', 'dismissed', 60*60*24*180 ); |
| 53 |
} |
| 54 |
if( !empty($liquid_blocks_json['news']) && get_transient( 'liquid_admin_notices' ) != 'dismissed' ){ |
| 55 |
echo '<div class="notice notice-info" style="position: relative;"><p>'.wp_kses_post($liquid_blocks_json['news']).'</p><a href="?liquid_admin_notices_dismissed" style="position: absolute; right: 10px; top: 10px;">×</a></div>'; |
| 56 |
} |
| 57 |
if( !empty($liquid_blocks_json['offer']) && get_transient( 'liquid_admin_offer' ) != 'dismissed' ){ |
| 58 |
echo '<div class="notice notice-info" style="position: relative;"><p>'.wp_kses_post($liquid_blocks_json['offer']).'</p><a href="?liquid_admin_offer_dismissed" style="position: absolute; right: 10px; top: 10px;">×</a></div>'; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
add_action( 'admin_notices', 'liquid_blocks_admin_notices' ); |
| 63 |
|
| 64 |
// get_option |
| 65 |
$liquid_blocks_toggle = get_option( 'liquid_blocks_toggle' ); |
| 66 |
$liquid_blocks_no = get_option( 'liquid_blocks_no' ) ? get_option( 'liquid_blocks_no' ) : []; |
| 67 |
$liquid_blocks_type = get_option( 'liquid_blocks_type' ) ? get_option( 'liquid_blocks_type' ) : []; |
| 68 |
$liquid_blocks_name = get_option( 'liquid_blocks_name' ) ? get_option( 'liquid_blocks_name' ) : []; |
| 69 |
$liquid_blocks_clean = get_option( 'liquid_blocks_clean' ) ? get_option( 'liquid_blocks_clean' ) : []; |
| 70 |
if( empty( $liquid_blocks_toggle ) ){ |
| 71 |
add_action( 'init', 'liquid_blocks_init' ); |
| 72 |
add_action( 'enqueue_block_assets', 'liquid_blocks_assets' ); |
| 73 |
add_action( 'enqueue_block_editor_assets', 'liquid_blocks_enqueue_block_editor_assets' ); |
| 74 |
add_action( 'admin_footer', 'liquid_blocks_admin_footer' ); |
| 75 |
add_action( 'plugins_loaded', function () { |
| 76 |
load_plugin_textdomain( |
| 77 |
'liquid-blocks', |
| 78 |
false, |
| 79 |
dirname(plugin_basename(__FILE__)) . '/languages/' |
| 80 |
); |
| 81 |
} ); |
| 82 |
} |
| 83 |
|
| 84 |
// plugin_action_links |
| 85 |
function liquid_blocks_plugin_action_links( $links ) { |
| 86 |
$settings = '<a href="' . esc_url( admin_url('admin.php?page=liquid-blocks') ) . '">' |
| 87 |
. esc_html__( 'Settings', 'liquid-blocks' ) . '</a>'; |
| 88 |
if ( function_exists( 'is_liquid_pro' ) && is_liquid_pro() ) { |
| 89 |
array_unshift( $links, $settings ); |
| 90 |
} else { |
| 91 |
$pro = '<a href="' . esc_url( 'https://lqd.jp/wp/plugin/blocks_pro.html' ) . '" target="_blank" rel="noopener" style="font-weight:bold;">' |
| 92 |
. esc_html__( 'Get Pro', 'liquid-blocks' ) . '</a>'; |
| 93 |
array_unshift( $links, $pro, $settings ); |
| 94 |
} |
| 95 |
return $links; |
| 96 |
} |
| 97 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'liquid_blocks_plugin_action_links' ); |
| 98 |
|
| 99 |
function liquid_blocks_assets() { |
| 100 |
global $liquid_blocks_data; |
| 101 |
wp_enqueue_style( 'liquid-blocks', plugins_url( 'css/block.css' , __FILE__ ), array( 'swiper' ), $liquid_blocks_data['version'] ); |
| 102 |
// slider |
| 103 |
wp_enqueue_style( 'swiper', plugins_url( 'css/swiper-bundle.min.css' , __FILE__ ), array() ); |
| 104 |
wp_enqueue_script( 'swiper', plugins_url( 'lib/swiper-bundle.min.js' , __FILE__ ), array() ); |
| 105 |
wp_enqueue_script( 'liquid-blocks', plugins_url( 'lib/liquid-blocks.js' , __FILE__ ), array( 'swiper' ) ); |
| 106 |
} |
| 107 |
|
| 108 |
function liquid_blocks_enqueue_block_editor_assets(){ |
| 109 |
global $liquid_blocks_data, $liquid_blocks_no, $liquid_blocks_type, $liquid_blocks_name, $pagenow; |
| 110 |
// wp-edit-post 依存の block.js は新ウィジェットエディターでは読み込まない(wp-editor 競合の Notice 回避) |
| 111 |
$liquid_blocks_skip_block = ( $pagenow == 'widgets.php' || $pagenow == 'customize.php' ); |
| 112 |
// wp_enqueue_script |
| 113 |
wp_enqueue_script( 'clipboard' ); |
| 114 |
wp_enqueue_script( 'liquid-blocks-template', plugins_url( 'lib/template.js', __FILE__ ), array(), $liquid_blocks_data['version'] ); |
| 115 |
// ライセンス認証の結果を各ブロック JS に渡す(判定は PHP 側の is_liquid_pro()) |
| 116 |
wp_add_inline_script( 'liquid-blocks-template', 'window.LIQUID_PRO = { enabled: ' . ( is_liquid_pro() ? 'true' : 'false' ) . ' };', 'before' ); |
| 117 |
if ( ! $liquid_blocks_skip_block ) { |
| 118 |
wp_enqueue_script( 'liquid-blocks-block', 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'] ); |
| 119 |
} |
| 120 |
// 書式(Mark/Big/Small/Underline)は wp-edit-post 非依存のため� |
| 121 |
�画面でエンキュー |
| 122 |
wp_enqueue_script( 'liquid-blocks-format', plugins_url( 'lib/block-format.js', __FILE__ ), array( 'wp-rich-text', 'wp-block-editor', 'wp-element', 'wp-i18n' ), $liquid_blocks_data['version'] ); |
| 123 |
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' ) ); |
| 124 |
wp_enqueue_script( 'liquid-blocks-tabs', plugins_url( 'lib/block-tabs.js', __FILE__ ), array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor', 'wp-components' ) ); |
| 125 |
wp_enqueue_script( 'liquid-blocks-table', plugins_url( 'lib/block-table.js', __FILE__ ), array('wp-blocks', 'wp-i18n', 'wp-hooks', 'wp-element', 'wp-components', 'wp-compose', 'wp-block-editor') ); |
| 126 |
wp_enqueue_script( 'liquid-blocks-fixed', plugins_url( 'lib/block-fixed.js', __FILE__ ), array( 'wp-blocks', 'wp-i18n', 'wp-hooks', 'wp-element', 'wp-components', 'wp-compose', 'wp-block-editor', 'wp-data' ) ); |
| 127 |
|
| 128 |
// wp_set_script_translations |
| 129 |
wp_set_script_translations( 'liquid-blocks', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 130 |
if ( ! $liquid_blocks_skip_block ) { |
| 131 |
wp_set_script_translations( 'liquid-blocks-block', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 132 |
} |
| 133 |
wp_set_script_translations( 'liquid-blocks-format', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 134 |
wp_set_script_translations( 'liquid-blocks-cards', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 135 |
wp_set_script_translations( 'liquid-blocks-tabs', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 136 |
wp_set_script_translations( 'liquid-blocks-slider', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 137 |
wp_set_script_translations( 'liquid-blocks-custom-field', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 138 |
wp_set_script_translations( 'liquid-blocks-if-conditions', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 139 |
wp_set_script_translations( 'liquid-blocks-table', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 140 |
wp_set_script_translations( 'liquid-blocks-fixed', 'liquid-blocks', plugin_dir_path( __FILE__ ) . 'languages' ); |
| 141 |
|
| 142 |
// wp_localize_script |
| 143 |
wp_localize_script( 'liquid-blocks-template', 'liquid_blocks_imgurl', array( plugins_url( 'images/', __FILE__ ) ) ); |
| 144 |
if ( ! $liquid_blocks_skip_block ) { |
| 145 |
wp_localize_script( 'liquid-blocks-block', 'liquid_blocks_imgurl', array( plugins_url( 'images/', __FILE__ ) ) ); |
| 146 |
wp_localize_script( 'liquid-blocks-block', 'liquid_blocks_no', $liquid_blocks_no ); |
| 147 |
wp_localize_script( 'liquid-blocks-block', 'liquid_blocks_type', $liquid_blocks_type ); |
| 148 |
wp_localize_script( 'liquid-blocks-block', 'liquid_blocks_name', $liquid_blocks_name ); |
| 149 |
} |
| 150 |
|
| 151 |
// wp_enqueue_style |
| 152 |
wp_enqueue_style( 'liquid-blocks', plugins_url( 'css/block.css' , __FILE__ ), array(), $liquid_blocks_data['version'] ); |
| 153 |
wp_enqueue_style( 'liquid-blocks-editor', plugins_url( 'css/block-editor.css' , __FILE__ ), array(), $liquid_blocks_data['version'] ); |
| 154 |
|
| 155 |
// theme.json の layout.contentSize をブレークポイントとして使用 |
| 156 |
$content_size = ''; |
| 157 |
if (function_exists('wp_get_global_settings')) { |
| 158 |
// まず theme.json 由来を取りに行く(環境差に強い) |
| 159 |
$content_size = (string) wp_get_global_settings(['layout', 'contentSize'], ['origin' => 'base']); |
| 160 |
} |
| 161 |
$content_size = trim((string) $content_size); |
| 162 |
// フォールバック:theme.json に無い / 空なら $content_width を採用 |
| 163 |
if ($content_size === '' && isset($content_width) && is_numeric($content_width) && (int) $content_width > 0) { |
| 164 |
$content_size = (int) $content_width . 'px'; |
| 165 |
} |
| 166 |
// media query に使えない値(var(...))は無効扱い |
| 167 |
$usable_bp = ($content_size !== '' && stripos($content_size, 'var(') === false); |
| 168 |
$settings = array( |
| 169 |
'hasContentSize' => $usable_bp, |
| 170 |
'breakpoint' => $usable_bp ? $content_size : '', |
| 171 |
); |
| 172 |
wp_add_inline_script( |
| 173 |
'liquid-blocks-table', |
| 174 |
'window.LiquidBlocksBlockTableSettings=' . wp_json_encode($settings) . ';', |
| 175 |
'before' |
| 176 |
); |
| 177 |
} |
| 178 |
|
| 179 |
function liquid_blocks_admin_footer() { |
| 180 |
global $pagenow, $post; |
| 181 |
if( $pagenow == 'post.php' || $pagenow == 'post-new.php' ){ |
| 182 |
if ( apply_filters( 'replace_editor', false, $post ) !== true ) { |
| 183 |
if ( use_block_editor_for_post( $post ) ) { |
| 184 |
?> |
| 185 |
<!-- Gallery --> |
| 186 |
<div id="liquid_blocks_modal" class="liquid_blocks_modal" style="display:none;"> |
| 187 |
<div class="liquid_blocks_modal_gallery"> |
| 188 |
|
| 189 |
<?php |
| 190 |
/* ブロックCSS+グローバルスタイル+テーマCSSを読み込んだプレビュー === */ |
| 191 |
if ( ! function_exists( 'liquid_blocks_preview_src' ) ) { |
| 192 |
function liquid_blocks_preview_src( $raw_html ) { |
| 193 |
$rendered = function_exists('do_blocks') ? do_blocks($raw_html) : apply_filters('the_content', $raw_html); |
| 194 |
|
| 195 |
$links = ''; |
| 196 |
$styles = wp_styles(); |
| 197 |
if ( wp_style_is('wp-block-library','registered') && ! empty($styles->registered['wp-block-library']->src) ) { |
| 198 |
$href = $styles->registered['wp-block-library']->src; |
| 199 |
if ( 0 !== strpos($href,'http') ) $href = site_url($href); |
| 200 |
$links .= '<link rel="stylesheet" href="'.esc_url($href).'">'; |
| 201 |
} else { |
| 202 |
$links .= '<link rel="stylesheet" href="'.esc_url( includes_url('css/dist/block-library/style.min.css') ).'">'; |
| 203 |
} |
| 204 |
if ( function_exists('wp_get_global_stylesheet') ) { |
| 205 |
$links .= '<style>'.wp_get_global_stylesheet().'</style>'; |
| 206 |
} |
| 207 |
$links .= '<link rel="stylesheet" href="'.esc_url( get_stylesheet_uri() ).'">'; |
| 208 |
|
| 209 |
$doc = '<!doctype html><html><head><meta charset="'.esc_attr( get_bloginfo('charset') ).'">'.$links.'<style>img{max-width:100%;height:auto;display:block}</style></head><body>'.$rendered.'</body></html>'; |
| 210 |
|
| 211 |
return 'data:text/html;charset=UTF-8;base64,'.base64_encode($doc); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
/* === Site Editor のユーザーパターン(wp_block)を一覧表示 === */ |
| 216 |
$user_args = array( |
| 217 |
'post_type' => array( 'wp_block' ), // Site Editor で作るユーザーパターン |
| 218 |
'post_status' => array( 'publish' ), |
| 219 |
'posts_per_page' => -1, |
| 220 |
'orderby' => 'date', // 安定のため日付→ID |
| 221 |
'order' => 'ASC', |
| 222 |
); |
| 223 |
$uquery = new WP_Query( $user_args ); |
| 224 |
|
| 225 |
if ( $uquery->have_posts() ) { |
| 226 |
echo '<h3>' . esc_html__( 'Block Patterns', 'liquid-blocks' ) . ' <small>User</small></h3>'; |
| 227 |
echo '<script>if(!window.LiquidGallery){window.LiquidGallery={}}; if(!LiquidGallery["user"]){LiquidGallery["user"]=[]}</script>'; |
| 228 |
|
| 229 |
$i = 0; |
| 230 |
while ( $uquery->have_posts() ) { |
| 231 |
$uquery->the_post(); |
| 232 |
$post_id = get_the_ID(); |
| 233 |
$pattern_title = get_the_title(); |
| 234 |
if ( ! $pattern_title ) { |
| 235 |
$pattern_title = __( 'Untitled pattern', 'liquid-blocks' ); |
| 236 |
} |
| 237 |
|
| 238 |
// 生のブロックコンテンツ(クリック時にそのまま parse → insert) |
| 239 |
$raw = get_post_field( 'post_content', $post_id ); |
| 240 |
if ( ! $raw ) { |
| 241 |
continue; |
| 242 |
} |
| 243 |
|
| 244 |
// プレビューURL(コアCSS適用の実HTMLを返す) |
| 245 |
$preview_src = liquid_blocks_preview_src( $raw ); |
| 246 |
|
| 247 |
// JSに詰める(JSONエンコードで安� |
| 248 |
�に) |
| 249 |
$raw_no_newline = preg_replace( "/\r|\n/", '', $raw ); |
| 250 |
$raw_json = wp_json_encode( $raw_no_newline ); |
| 251 |
|
| 252 |
// 画像 + タイトル(既存と同フォーマット) |
| 253 |
echo '<script>LiquidGallery["user"][' . (int) $i . '] = ' . $raw_json . ';</script>'; |
| 254 |
echo '<a onclick="LiquidGalleryButton(LiquidGallery[\'user\'][' . (int) $i . '], this)" class="liquid_blocks_iframe">'; |
| 255 |
|
| 256 |
// iframe |
| 257 |
$frame_w = 420; // サムネイル枠の見た目� |
| 258 |
|
| 259 |
$frame_h = 280; // サムネイル枠の見た目高さ |
| 260 |
$desktop_vw = 1280; // PCレイアウトとして見せたい� |
| 261 |
(ブレークポイント用) |
| 262 |
$scale = $frame_w / $desktop_vw; |
| 263 |
$desktop_h = (int) round($frame_h / $scale); |
| 264 |
$preview_src = liquid_blocks_preview_src( $raw ); |
| 265 |
echo '<iframe src="'.esc_attr($preview_src).'" |
| 266 |
style="width:'.$desktop_vw.'px;height:'.$desktop_h.'px; |
| 267 |
transform:scale('.$scale.');transform-origin:0 0; |
| 268 |
border:0;pointer-events:none;display:block;background:#fff" |
| 269 |
loading="lazy" referrerpolicy="no-referrer"></iframe>'; |
| 270 |
|
| 271 |
echo '<span>' . ( (int) ($i + 1) ) . ': ' . esc_html( $pattern_title ) . '</span>'; |
| 272 |
echo '</a>'; |
| 273 |
|
| 274 |
$i++; |
| 275 |
} |
| 276 |
wp_reset_postdata(); |
| 277 |
} |
| 278 |
?> |
| 279 |
|
| 280 |
<?php |
| 281 |
/* === liquid_block === */ |
| 282 |
$args = array( |
| 283 |
'post_type' => array( 'liquid_block' ), |
| 284 |
'post_status' => array( 'publish' ), |
| 285 |
'posts_per_page' => -1, |
| 286 |
'order' => 'ASC', |
| 287 |
); |
| 288 |
$the_query = new WP_Query( $args ); |
| 289 |
if ( $the_query->have_posts() ) { |
| 290 |
$i = 0; |
| 291 |
echo '<h3>'.__( 'Block Patterns', 'liquid-blocks' ).' <small>Patterns</small></h3>'; |
| 292 |
echo '<script>LiquidGallery[\'Patterns\'] = []</script>'; |
| 293 |
while ( $the_query->have_posts() ) { |
| 294 |
$j = $i + 1; |
| 295 |
$the_query->the_post(); |
| 296 |
$pattern_title = get_the_title(); |
| 297 |
if( !$pattern_title ){ |
| 298 |
$pattern_title = __( 'Untitled block', 'liquid-blocks' ); |
| 299 |
} |
| 300 |
$pattern_content = get_the_content(); |
| 301 |
$pattern_categories = array(); |
| 302 |
$terms = get_the_terms( 0, 'liquid_patterns' ); |
| 303 |
if( !empty( $terms ) && !is_wp_error( $terms ) ){ |
| 304 |
foreach( $terms as $term ){ |
| 305 |
$pattern_categories[] = $term->slug; |
| 306 |
} |
| 307 |
} |
| 308 |
if( has_post_thumbnail() ) { |
| 309 |
$thumbnail_id = get_post_thumbnail_id(); |
| 310 |
$src_info = wp_get_attachment_image_src($thumbnail_id, $size = array(600,400)); |
| 311 |
$src = $src_info ? $src_info[0] : ''; |
| 312 |
$class = ''; |
| 313 |
} else { |
| 314 |
$src = plugins_url( 'images/noimage.png', __FILE__ ); |
| 315 |
$class = 'liquid_noimage'; |
| 316 |
} |
| 317 |
if( $pattern_content ){ |
| 318 |
$pattern_content = str_replace( array("\r", "\n"), '', $pattern_content ); |
| 319 |
echo '<script>LiquidGallery[\'Patterns\']['.$i.'] = '.wp_json_encode($pattern_content).';</script>'; |
| 320 |
echo '<a onclick="LiquidGalleryButton(LiquidGallery[\'Patterns\']['.$i.'], this)" class="liquid_blocks_img '.$class.'"><img src="'.$src.'" alt=""><span>'.$j.': '.$pattern_title.'</span></a>'; |
| 321 |
$i++; |
| 322 |
} |
| 323 |
} |
| 324 |
wp_reset_postdata(); |
| 325 |
} |
| 326 |
?> |
| 327 |
|
| 328 |
<h3><?php _e( 'Headlines', 'liquid-blocks' ); ?> <small>Headlines</small></h3> |
| 329 |
<script>LiquidGalleryList('Headlines');</script> |
| 330 |
<h3><?php _e( 'Layouts', 'liquid-blocks' ); ?> <small>Layouts</small></h3> |
| 331 |
<script>LiquidGalleryList('Layouts');</script> |
| 332 |
<h3><?php _e( 'Price list', 'liquid-blocks' ); ?> <small>Price</small></h3> |
| 333 |
<script>LiquidGalleryList('Price');</script> |
| 334 |
<h3><?php _e( 'CTA: Call To Action', 'liquid-blocks' ); ?> <small>CTA</small></h3> |
| 335 |
<script>LiquidGalleryList('CTA');</script> |
| 336 |
<h3><?php _e( 'Landing pages', 'liquid-blocks' ); ?> <small>Landing</small></h3> |
| 337 |
<script>LiquidGalleryList('Landing');</script> |
| 338 |
<h3><?php _e( 'Recommended Plugins', 'liquid-blocks' ); ?></h3> |
| 339 |
<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> |
| 340 |
</div> |
| 341 |
</div> |
| 342 |
<!-- Multiple --> |
| 343 |
<div id="liquid_blocks_buttons" class="liquid_blocks_buttons"> |
| 344 |
<a id="liquid_blocks_copy" class="liquid_blocks_copy liquid_blocks_btn none"><?php _e( 'Copy', 'liquid-blocks' ); ?></a><script>LiquidGalleryCopy();</script> |
| 345 |
<a id="liquid_blocks_insert" onclick="LiquidGalleryInsert()" class="liquid_blocks_btn none"><?php _e( 'Insert', 'liquid-blocks' ); ?><span id="liquid_blocks_count"></span></a> |
| 346 |
<a id="liquid_blocks_multiple" onclick="LiquidGalleryMultiple()" class="liquid_blocks_btn"><?php _e( 'Select', 'liquid-blocks' ); ?></a> |
| 347 |
<a id="liquid_blocks_cancel" onclick="LiquidGalleryCancel()" class="liquid_blocks_btn none"><?php _e( 'Cancel', 'liquid-blocks' ); ?></a> |
| 348 |
<a id="liquid_blocks_close" onclick="LiquidGalleryClose()" class="liquid_blocks_btn"><?php _e( 'Close', 'liquid-blocks' ); ?></a> |
| 349 |
</div> |
| 350 |
<?php |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
// ------------------------------------ |
| 357 |
// init |
| 358 |
// ------------------------------------ |
| 359 |
|
| 360 |
// block_categories |
| 361 |
function liquid_block_categories($categories, $post) { |
| 362 |
return array_merge( |
| 363 |
$categories, |
| 364 |
array( |
| 365 |
array( |
| 366 |
'slug' => 'liquid', |
| 367 |
'title' => 'LIQUID', |
| 368 |
), |
| 369 |
) |
| 370 |
); |
| 371 |
} |
| 372 |
add_filter('block_categories_all', 'liquid_block_categories', 10, 2); |
| 373 |
|
| 374 |
function liquid_blocks_init(){ |
| 375 |
global $liquid_blocks_clean; |
| 376 |
|
| 377 |
// pattern_category |
| 378 |
register_block_pattern_category( |
| 379 |
'liquid_headlines', |
| 380 |
array( 'label' => __( 'Headlines', 'liquid-blocks' ) ) |
| 381 |
); |
| 382 |
// img_path |
| 383 |
$path = plugins_url( 'images/', __FILE__ ); |
| 384 |
|
| 385 |
// slider |
| 386 |
register_block_type( 'liquid/slider', array( |
| 387 |
'editor_script' => 'liquid-blocks-slider', |
| 388 |
'editor_style' => 'liquid-blocks-editor', |
| 389 |
'attributes' => array( |
| 390 |
'fields' => array( |
| 391 |
'type' => 'array', |
| 392 |
), |
| 393 |
'delay' => array( |
| 394 |
'type' => 'number', |
| 395 |
), |
| 396 |
'speed' => array( |
| 397 |
'type' => 'number', |
| 398 |
), |
| 399 |
'slidesPerView' => array( |
| 400 |
'type' => 'number', |
| 401 |
), |
| 402 |
'animationType' => array( |
| 403 |
'type' => 'string', |
| 404 |
), |
| 405 |
), |
| 406 |
) ); |
| 407 |
wp_register_script( |
| 408 |
'liquid-blocks-slider', |
| 409 |
plugins_url( 'lib/block-slider.js', __FILE__ ), |
| 410 |
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor', 'wp-components' ) |
| 411 |
); |
| 412 |
|
| 413 |
// カスタムフィールド |
| 414 |
register_block_type('liquid/custom-field', array( |
| 415 |
'editor_script' => 'liquid-blocks-custom-field', |
| 416 |
'render_callback' => 'liquid_blocks_render_custom_field', |
| 417 |
)); |
| 418 |
wp_register_script( |
| 419 |
'liquid-blocks-custom-field', |
| 420 |
plugin_dir_url(__FILE__) . 'lib/block-custom-field.js', |
| 421 |
array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor', 'wp-components') |
| 422 |
); |
| 423 |
|
| 424 |
// isカスタム |
| 425 |
register_block_type( 'liquid/if-conditions', array( |
| 426 |
'editor_script' => 'liquid-blocks-if-conditions', |
| 427 |
'render_callback' => 'liquid_blocks_is_custom', |
| 428 |
) ); |
| 429 |
wp_register_script( |
| 430 |
'liquid-blocks-if-conditions', |
| 431 |
plugins_url( 'lib/block-if-conditions.js', __FILE__ ), |
| 432 |
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-block-editor', 'wp-components' ) |
| 433 |
); |
| 434 |
function liquid_blocks_is_custom( $attributes, $content ) { |
| 435 |
$visibility = isset( $attributes['visibility'] ) ? $attributes['visibility'] : ''; |
| 436 |
$role = isset( $attributes['role'] ) ? $attributes['role'] : ''; |
| 437 |
$parameters = isset( $attributes['parameters'] ) ? sanitize_text_field($attributes['parameters']) : ''; |
| 438 |
$conditionType = isset( $attributes['conditionType'] ) ? $attributes['conditionType'] : ''; |
| 439 |
|
| 440 |
// helper: Not Match 判定の� |
| 441 |
�通化 |
| 442 |
$invert = ( $conditionType === 'not_match' ); |
| 443 |
|
| 444 |
// is_user_logged_in |
| 445 |
if ( 'is_user_logged_in' === $visibility ) { |
| 446 |
if( ! $conditionType ){ |
| 447 |
if ( ! is_user_logged_in() ) { return ''; } |
| 448 |
// role |
| 449 |
if ( $role ) { |
| 450 |
$current_user = wp_get_current_user(); |
| 451 |
if ( ! in_array( $role, (array) $current_user->roles, true ) ) { return ''; } |
| 452 |
} |
| 453 |
} else { |
| 454 |
if ( is_user_logged_in() ) { return ''; } |
| 455 |
} |
| 456 |
} |
| 457 |
// is_front_page |
| 458 |
if ( 'is_front_page' === $visibility ) { |
| 459 |
if( ! $conditionType ){ |
| 460 |
if ( ! is_front_page() ) { return ''; } |
| 461 |
} else { |
| 462 |
if ( is_front_page() ) { return ''; } |
| 463 |
} |
| 464 |
} |
| 465 |
// is_front_page |
| 466 |
if ( 'is_front_page' === $visibility ) { |
| 467 |
if( ! $conditionType ){ |
| 468 |
if ( ! is_front_page() ) { return ''; } |
| 469 |
} else { |
| 470 |
if ( is_front_page() ) { return ''; } |
| 471 |
} |
| 472 |
} |
| 473 |
// is_home |
| 474 |
if ( 'is_home' === $visibility ) { |
| 475 |
if( ! $conditionType ){ |
| 476 |
if ( ! is_home() ) { return ''; } |
| 477 |
} else { |
| 478 |
if ( is_home() ) { return ''; } |
| 479 |
} |
| 480 |
} |
| 481 |
// is_page |
| 482 |
if ( 'is_page' === $visibility ) { |
| 483 |
if( ! $conditionType ){ |
| 484 |
if ( ! is_page($parameters) ) { return ''; } |
| 485 |
} else { |
| 486 |
if ( is_page($parameters) ) { return ''; } |
| 487 |
} |
| 488 |
} |
| 489 |
// is_single |
| 490 |
if ( 'is_single' === $visibility ) { |
| 491 |
if( ! $conditionType ){ |
| 492 |
if ( ! is_single($parameters) ) { return ''; } |
| 493 |
} else { |
| 494 |
if ( is_single($parameters) ) { return ''; } |
| 495 |
} |
| 496 |
} |
| 497 |
// is_singular |
| 498 |
if ( 'is_singular' === $visibility ) { |
| 499 |
if( ! $conditionType ){ |
| 500 |
if ( ! is_singular($parameters) ) { return ''; } |
| 501 |
} else { |
| 502 |
if ( is_singular($parameters) ) { return ''; } |
| 503 |
} |
| 504 |
} |
| 505 |
// is_archive |
| 506 |
if ( 'is_archive' === $visibility ) { |
| 507 |
if( ! $conditionType ){ |
| 508 |
if ( ! is_archive() ) { return ''; } |
| 509 |
} else { |
| 510 |
if ( is_archive() ) { return ''; } |
| 511 |
} |
| 512 |
} |
| 513 |
// is_category |
| 514 |
if ( 'is_category' === $visibility ) { |
| 515 |
if( ! $conditionType ){ |
| 516 |
if ( ! is_category($parameters) ) { return ''; } |
| 517 |
} else { |
| 518 |
if ( is_category($parameters) ) { return ''; } |
| 519 |
} |
| 520 |
} |
| 521 |
// is_tag |
| 522 |
if ( 'is_tag' === $visibility ) { |
| 523 |
if( ! $conditionType ){ |
| 524 |
if ( ! is_tag($parameters) ) { return ''; } |
| 525 |
} else { |
| 526 |
if ( is_tag($parameters) ) { return ''; } |
| 527 |
} |
| 528 |
} |
| 529 |
// is_author |
| 530 |
if ( 'is_author' === $visibility ) { |
| 531 |
if( ! $conditionType ){ |
| 532 |
if ( ! is_author($parameters) ) { return ''; } |
| 533 |
} else { |
| 534 |
if ( is_author($parameters) ) { return ''; } |
| 535 |
} |
| 536 |
} |
| 537 |
// is_tax |
| 538 |
if ( 'is_tax' === $visibility ) { |
| 539 |
if( ! $conditionType ){ |
| 540 |
if ( ! is_tax($parameters) ) { return ''; } |
| 541 |
} else { |
| 542 |
if ( is_tax($parameters) ) { return ''; } |
| 543 |
} |
| 544 |
} |
| 545 |
// has_post_format |
| 546 |
if ( 'has_post_format' === $visibility ) { |
| 547 |
if( ! $conditionType ){ |
| 548 |
if ( ! has_post_format($parameters) ) { return ''; } |
| 549 |
} else { |
| 550 |
if ( has_post_format($parameters) ) { return ''; } |
| 551 |
} |
| 552 |
} |
| 553 |
// wp_is_mobile |
| 554 |
if ( 'wp_is_mobile' === $visibility ) { |
| 555 |
if( ! $conditionType ){ |
| 556 |
if ( ! wp_is_mobile() ) { return ''; } |
| 557 |
} else { |
| 558 |
if ( wp_is_mobile() ) { return ''; } |
| 559 |
} |
| 560 |
} |
| 561 |
// get_locale |
| 562 |
if ( 'get_locale' === $visibility ) { |
| 563 |
$locale = function_exists('get_locale') ? (string) get_locale() : ''; |
| 564 |
$list = array_filter( array_map( 'trim', preg_split( '/[,\s]+/', $parameters ) ) ); |
| 565 |
$matched = false; |
| 566 |
foreach ( $list as $p ) { |
| 567 |
if ( $p !== '' && strpos( $locale, $p ) === 0 ) { // prefix match |
| 568 |
$matched = true; |
| 569 |
break; |
| 570 |
} |
| 571 |
} |
| 572 |
if ( ! $invert ) { |
| 573 |
if ( ! $matched ) { return ''; } |
| 574 |
} else { |
| 575 |
if ( $matched ) { return ''; } |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
// content |
| 580 |
return '<div class="liquid-if-conditions">' . $content . '</div>'; |
| 581 |
} |
| 582 |
|
| 583 |
// fixed |
| 584 |
register_block_type('liquid/fixed', array( |
| 585 |
'editor_script' => 'liquid-blocks-fixed', |
| 586 |
'style' => 'liquid-blocks-fixed', |
| 587 |
'render_callback' => 'liquid_blocks_render_fixed', |
| 588 |
'attributes' => array( |
| 589 |
'positionX' => array('type' => 'string', 'default' => 'right'), // left/right |
| 590 |
'positionY' => array('type' => 'string', 'default' => 'bottom'), // top/bottom |
| 591 |
'offsetTop' => array('type' => 'string', 'default' => '0px'), |
| 592 |
'offsetBottom' => array('type' => 'string', 'default' => '0px'), |
| 593 |
'offsetLeft' => array('type' => 'string', 'default' => '0px'), |
| 594 |
'offsetRight' => array('type' => 'string', 'default' => '0px'), |
| 595 |
|
| 596 |
'showOnScroll' => array('type' => 'boolean', 'default' => false), |
| 597 |
'scrollThreshold' => array('type' => 'number', 'default' => 200), |
| 598 |
'scrollMode' => array('type' => 'string', 'default' => 'after'), // after/up/down |
| 599 |
|
| 600 |
'closeable' => array('type' => 'boolean', 'default' => false), |
| 601 |
'closePersist' => array('type' => 'boolean', 'default' => true), |
| 602 |
'persistKey' => array('type' => 'string', 'default' => ''), // 自動生成 |
| 603 |
), |
| 604 |
)); |
| 605 |
|
| 606 |
// ------------------------------------ |
| 607 |
// unregister_block_pattern |
| 608 |
// ------------------------------------ |
| 609 |
if( !empty($liquid_blocks_clean) ){ |
| 610 |
add_action( 'after_setup_theme', function() { |
| 611 |
remove_theme_support( 'core-block-patterns' ); |
| 612 |
} ); |
| 613 |
add_filter( 'should_load_remote_block_patterns', '__return_false' ); |
| 614 |
} |
| 615 |
|
| 616 |
// register_post_type |
| 617 |
register_post_type( |
| 618 |
'liquid_block', |
| 619 |
array( |
| 620 |
'public' => true, |
| 621 |
'description' => __( 'Block Pattern Manager', 'liquid-blocks' ), |
| 622 |
'hierarchical' => false, |
| 623 |
'has_archive' => false, |
| 624 |
'labels' => array( |
| 625 |
'name' => __( 'Block Pattern', 'liquid-blocks' ), |
| 626 |
'menu_name' => __( 'Block Pattern', 'liquid-blocks' ), |
| 627 |
'singular_name' => __( 'Block Pattern', 'liquid-blocks' ), |
| 628 |
'all_items' => __( 'Block Pattern List', 'liquid-blocks' ), |
| 629 |
'add_new' => __( 'Add New', 'liquid-blocks' ), |
| 630 |
'add_new_item' => __( 'Add New', 'liquid-blocks' ), |
| 631 |
'edit_item' => __( 'Edit', 'liquid-blocks' ), |
| 632 |
), |
| 633 |
'publicly_queryable' => false, |
| 634 |
'show_ui' => true, |
| 635 |
'show_in_menu' => false, |
| 636 |
'show_in_nav_menus' => false, |
| 637 |
'show_in_admin_bar' => true, |
| 638 |
'capability_type' => 'post', |
| 639 |
'menu_position' => 9, |
| 640 |
'query_var' => false, |
| 641 |
'exclude_from_search' => true, |
| 642 |
'publicly_queryable' => false, |
| 643 |
'supports' => array( |
| 644 |
'title', |
| 645 |
'editor', |
| 646 |
'author', |
| 647 |
'thumbnail', |
| 648 |
), |
| 649 |
'taxonomies' => array('liquid_block'), |
| 650 |
'show_in_rest' => true, |
| 651 |
) |
| 652 |
); |
| 653 |
register_taxonomy( |
| 654 |
'liquid_patterns', |
| 655 |
'liquid_block', |
| 656 |
array( |
| 657 |
'label' => __( 'Block Pattern Category', 'liquid-blocks' ), |
| 658 |
'hierarchical' => false, |
| 659 |
'public' => false, |
| 660 |
'show_ui' => true, |
| 661 |
'show_in_rest' => true, |
| 662 |
'show_tagcloud' => false, |
| 663 |
'labels' => array( |
| 664 |
'singular_name' => __( 'Block Pattern Category', 'liquid-blocks' ), |
| 665 |
'add_new_item' => __( 'Add New', 'liquid-blocks' ), |
| 666 |
'separate_items_with_commas' => __( 'Press the Enter key.', 'liquid-blocks' ), |
| 667 |
), |
| 668 |
) |
| 669 |
); |
| 670 |
|
| 671 |
$terms = get_terms( array( 'taxonomy' => 'liquid_patterns', 'get'=>'all' ) ); |
| 672 |
if( !empty( $terms ) && !is_wp_error( $terms ) ){ |
| 673 |
foreach( $terms as $term ){ |
| 674 |
register_block_pattern_category( |
| 675 |
$term->slug, |
| 676 |
array( 'label' => $term->name ) |
| 677 |
); |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
// register_block_pattern self-made |
| 682 |
$args = array( |
| 683 |
'post_type' => array( 'liquid_block' ), |
| 684 |
'post_status' => array( 'publish' ), |
| 685 |
'posts_per_page' => -1, |
| 686 |
'order' => 'ASC', |
| 687 |
); |
| 688 |
$the_query = new WP_Query( $args ); |
| 689 |
if ( $the_query->have_posts() ) { |
| 690 |
$i = 0; |
| 691 |
while ( $the_query->have_posts() ) { |
| 692 |
$the_query->the_post(); |
| 693 |
$pattern_title = get_the_title(); |
| 694 |
if( !$pattern_title ){ |
| 695 |
$pattern_title = __( 'Untitled block', 'liquid-blocks' ); |
| 696 |
} |
| 697 |
$pattern_content = get_the_content(); |
| 698 |
$pattern_categories = array(); |
| 699 |
$terms = get_the_terms( 0, 'liquid_patterns' ); |
| 700 |
if( !empty( $terms ) && !is_wp_error( $terms ) ){ |
| 701 |
foreach( $terms as $term ){ |
| 702 |
$pattern_categories[] = $term->slug; |
| 703 |
} |
| 704 |
} |
| 705 |
if( $pattern_content ){ |
| 706 |
register_block_pattern( |
| 707 |
'liquid/liquid_pattern_' . $i, |
| 708 |
array( |
| 709 |
'title' => $pattern_title, |
| 710 |
'content' => $pattern_content, |
| 711 |
'categories' => $pattern_categories, |
| 712 |
) |
| 713 |
); |
| 714 |
$i++; |
| 715 |
} |
| 716 |
} |
| 717 |
wp_reset_postdata(); |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
// カスタムフィールドブロックのレンダリング |
| 722 |
function liquid_blocks_render_custom_field($attributes) { |
| 723 |
// カスタムフィールドキーと投稿IDの取得 |
| 724 |
$fieldKey = isset($attributes['fieldKey']) ? $attributes['fieldKey'] : ''; |
| 725 |
$postId = isset($attributes['postId']) && !empty($attributes['postId']) ? intval($attributes['postId']) : get_the_ID(); |
| 726 |
|
| 727 |
// フィールドタイプを取得(テキストか画像か) |
| 728 |
$fieldType = isset($attributes['fieldType']) ? $attributes['fieldType'] : 'text'; |
| 729 |
|
| 730 |
// デフォルトの alignment を設定 |
| 731 |
$alignment = isset($attributes['alignment']) ? $attributes['alignment'] : 'left'; |
| 732 |
|
| 733 |
// 追加CSSクラスを取得 |
| 734 |
$customClass = isset($attributes['className']) ? $attributes['className'] : ''; |
| 735 |
|
| 736 |
// スタイル属性を構築 |
| 737 |
$style = 'text-align:' . esc_attr($alignment) . ';'; |
| 738 |
|
| 739 |
// カスタムフィールドデータの取得 |
| 740 |
if (!empty($fieldKey)) { |
| 741 |
$fieldValue = get_post_meta($postId, $fieldKey, true); |
| 742 |
|
| 743 |
// フィールドタイプに基づいて処理を分ける |
| 744 |
if ($fieldType === 'image') { |
| 745 |
// 画像の場合 |
| 746 |
if (is_array($fieldValue)) { |
| 747 |
// 繰り返し画像フィールドの場合の処理 |
| 748 |
$output = '<div class="liquid_custom_field_repeatable">'; |
| 749 |
foreach ($fieldValue as $mediaId) { |
| 750 |
$image_url = wp_get_attachment_url($mediaId); |
| 751 |
if ($image_url) { |
| 752 |
$output .= '<div class="liquid_custom_field_item"><img src="' . esc_url($image_url) . '" alt="" /></div>'; |
| 753 |
} |
| 754 |
} |
| 755 |
$output .= '</div>'; |
| 756 |
} else { |
| 757 |
// 単一画像フィールドの場合 |
| 758 |
$image_url = wp_get_attachment_url($fieldValue); |
| 759 |
if ($image_url) { |
| 760 |
$output = '<div class="liquid_custom_field_item"><img src="' . esc_url($image_url) . '" alt="" /></div>'; |
| 761 |
} |
| 762 |
} |
| 763 |
} else { |
| 764 |
// テキストの場合 |
| 765 |
if (is_array($fieldValue)) { |
| 766 |
// 繰り返しテキストフィールドの場合の処理 |
| 767 |
$output = '<div class="liquid_custom_field_repeatable">'; |
| 768 |
foreach ($fieldValue as $value) { |
| 769 |
$output .= '<div class="liquid_custom_field_item">' . esc_html($value) . '</div>'; |
| 770 |
} |
| 771 |
$output .= '</div>'; |
| 772 |
} else { |
| 773 |
// 単一テキストフィールドの場合の処理 |
| 774 |
$output = '<div class="liquid_custom_field_item">' . esc_html($fieldValue) . '</div>'; |
| 775 |
} |
| 776 |
} |
| 777 |
|
| 778 |
// 追加CSSクラスを適用してカスタムフィールドの� |
| 779 |
容をスタイル付きのdivでラップ |
| 780 |
return '<div class="liquid_custom_field ' . esc_attr($customClass) . '" style="' . esc_attr($style) . '">' . $output . '</div>'; |
| 781 |
} else { |
| 782 |
return '<div class="liquid_custom_field ' . esc_attr($customClass) . '">' . __('No custom field selected.', 'liquid-blocks') . '</div>'; |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
// Fixedブロックのレンダリング |
| 787 |
function liquid_blocks_render_fixed($attributes, $content, $block) { |
| 788 |
$x = $attributes['positionX'] ?? 'right'; |
| 789 |
$y = $attributes['positionY'] ?? 'top'; |
| 790 |
|
| 791 |
$style = array( |
| 792 |
'position:fixed', |
| 793 |
'z-index:9999', |
| 794 |
); |
| 795 |
|
| 796 |
if ($y === 'top') { |
| 797 |
$style[] = 'top:' . ($attributes['offsetTop'] ?? '0'); |
| 798 |
} else { |
| 799 |
$style[] = 'bottom:' . ($attributes['offsetBottom'] ?? '0'); |
| 800 |
} |
| 801 |
|
| 802 |
if ($x === 'left') { |
| 803 |
$style[] = 'left:' . ($attributes['offsetLeft'] ?? '0'); |
| 804 |
} else { |
| 805 |
$style[] = 'right:' . ($attributes['offsetRight'] ?? '0'); |
| 806 |
} |
| 807 |
|
| 808 |
$persist_key = trim((string)($attributes['persistKey'] ?? '')); |
| 809 |
$close_persist = !empty($attributes['closePersist']) && $persist_key !== ''; |
| 810 |
|
| 811 |
$wrapper_attrs = get_block_wrapper_attributes(array( |
| 812 |
'class' => 'liquid-fixed', |
| 813 |
'style' => implode(';', $style) . ';', |
| 814 |
'data-liquid-fixed' => '1', |
| 815 |
'data-liquid-scroll' => !empty($attributes['showOnScroll']) ? '1' : '0', |
| 816 |
'data-liquid-scroll-threshold'=> (string)($attributes['scrollThreshold'] ?? 0), |
| 817 |
'data-liquid-scroll-mode' => (string)($attributes['scrollMode'] ?? 'after'), |
| 818 |
'data-liquid-close' => !empty($attributes['closeable']) ? '1' : '0', |
| 819 |
'data-liquid-close-key' => $persist_key, |
| 820 |
'data-liquid-close-persist' => $close_persist ? '1' : '0', |
| 821 |
)); |
| 822 |
|
| 823 |
return '<div ' . $wrapper_attrs . '>' . $content . '</div>'; |
| 824 |
} |
| 825 |
|
| 826 |
// ------------------------------------ |
| 827 |
// Admin |
| 828 |
// ------------------------------------ |
| 829 |
function liquid_blocks_admin() { |
| 830 |
add_menu_page( |
| 831 |
'LIQUID BLOCKS', |
| 832 |
'LIQUID BLOCKS', |
| 833 |
'administrator', |
| 834 |
'liquid-blocks', |
| 835 |
'liquid_blocks_admin_page', |
| 836 |
'dashicons-screenoptions' |
| 837 |
); |
| 838 |
add_theme_page( |
| 839 |
__( 'Patterns', 'liquid-blocks' ), |
| 840 |
__( 'Patterns', 'liquid-blocks' ), |
| 841 |
'administrator', |
| 842 |
'edit.php?post_type=liquid_block' |
| 843 |
); |
| 844 |
// 親メニューと同名の� |
| 845 |
�頭子メニュー(自動生成)を削除 |
| 846 |
remove_submenu_page( 'liquid-blocks', 'liquid-blocks' ); |
| 847 |
|
| 848 |
// License ページ(liquid-pro.php � |
| 849 |
�通。option � |
| 850 |
�有のため他プラグインと重複表示されてもよい) |
| 851 |
if ( function_exists( 'liquid_pro_render_page' ) ) { |
| 852 |
add_submenu_page( |
| 853 |
'liquid-blocks', |
| 854 |
'License', |
| 855 |
'License', |
| 856 |
'manage_options', |
| 857 |
'liquid-blocks-license', |
| 858 |
'liquid_pro_render_page' |
| 859 |
); |
| 860 |
} |
| 861 |
register_setting( |
| 862 |
'liquid_blocks_group', |
| 863 |
'liquid_blocks_toggle', |
| 864 |
'liquid_blocks_toggle_validation' |
| 865 |
); |
| 866 |
register_setting( |
| 867 |
'liquid_blocks_group', |
| 868 |
'liquid_blocks_no', array( |
| 869 |
'sanitize_callback' => function( $input ) { |
| 870 |
if ( ! is_array( $input ) ) { |
| 871 |
return array(); |
| 872 |
} |
| 873 |
return array_map( 'absint', $input ); |
| 874 |
}, |
| 875 |
) |
| 876 |
); |
| 877 |
register_setting( |
| 878 |
'liquid_blocks_group', |
| 879 |
'liquid_blocks_type', array( |
| 880 |
'sanitize_callback' => function( $input ) { |
| 881 |
if ( ! is_array( $input ) ) { |
| 882 |
return array(); |
| 883 |
} |
| 884 |
return array_map( 'sanitize_text_field', $input ); |
| 885 |
}, |
| 886 |
) |
| 887 |
); |
| 888 |
register_setting( |
| 889 |
'liquid_blocks_group', |
| 890 |
'liquid_blocks_name', array( |
| 891 |
'sanitize_callback' => function( $input ) { |
| 892 |
if ( ! is_array( $input ) ) { |
| 893 |
return array(); |
| 894 |
} |
| 895 |
return array_map( 'sanitize_text_field', $input ); |
| 896 |
}, |
| 897 |
) |
| 898 |
); |
| 899 |
register_setting( |
| 900 |
'liquid_blocks_group', |
| 901 |
'liquid_blocks_clean', array( |
| 902 |
'sanitize_callback' => 'absint', |
| 903 |
) |
| 904 |
); |
| 905 |
} |
| 906 |
add_action( 'admin_menu', 'liquid_blocks_admin' ); |
| 907 |
|
| 908 |
add_action( 'admin_enqueue_scripts', function( $hook ) { |
| 909 |
// Recommend の開閉 UI(Pro 版のみ)。判定は PHP 側の is_liquid_pro() |
| 910 |
if ( $hook !== 'toplevel_page_liquid-blocks' || ! is_liquid_pro() ) { |
| 911 |
return; |
| 912 |
} |
| 913 |
wp_enqueue_script( |
| 914 |
'liquid-blocks-settings', |
| 915 |
plugins_url( 'lib/liquid-blocks-settings.js', __FILE__ ), |
| 916 |
array( 'jquery' ), |
| 917 |
'1.0.0', |
| 918 |
true |
| 919 |
); |
| 920 |
} ); |
| 921 |
|
| 922 |
function liquid_blocks_toggle_validation( $input ) { |
| 923 |
$input = (int) $input; |
| 924 |
if ( $input === 0 || $input === 1 ) { |
| 925 |
return $input; |
| 926 |
} else { |
| 927 |
add_settings_error( |
| 928 |
'liquid_blocks_toggle', |
| 929 |
'liquid_blocks_toggle_validation_error', |
| 930 |
__( 'illegal data', 'liquid-blocks' ), |
| 931 |
'error' |
| 932 |
); |
| 933 |
} |
| 934 |
} |
| 935 |
|
| 936 |
function liquid_blocks_admin_page() { |
| 937 |
global $liquid_blocks_json, $liquid_blocks_toggle, $liquid_blocks_no, $liquid_blocks_type, $liquid_blocks_name, $liquid_blocks_clean; |
| 938 |
if( empty( $liquid_blocks_toggle ) ){ |
| 939 |
$toggle_on = 'checked="checked"'; |
| 940 |
$toggle_off = ''; |
| 941 |
} else { |
| 942 |
$toggle_on = ''; |
| 943 |
$toggle_off = 'checked="checked"'; |
| 944 |
} |
| 945 |
if( empty( $liquid_blocks_clean ) ){ |
| 946 |
$clean_on = 'checked="checked"'; |
| 947 |
$clean_off = ''; |
| 948 |
} else { |
| 949 |
$clean_on = ''; |
| 950 |
$clean_off = 'checked="checked"'; |
| 951 |
} |
| 952 |
?> |
| 953 |
<div class="wrap"> |
| 954 |
<h1>LIQUID BLOCKS<?php if ( is_liquid_pro() ) { ?><span style="display:inline-block;vertical-align:middle;background:#2271b1;color:#fff;font-size:12px;font-weight:600;line-height:1;padding:4px 8px;border-radius:3px;margin-left:8px;letter-spacing:0.05em;">PRO</span><?php } ?></h1> |
| 955 |
|
| 956 |
<div id="poststuff"> |
| 957 |
|
| 958 |
<!-- Recommend --> |
| 959 |
<?php if( !empty($liquid_blocks_json) && !empty($liquid_blocks_json['recommend']) ){ ?> |
| 960 |
<div class="postbox" id="liquid-blocks-recommend"> |
| 961 |
<h2 style="border-bottom: 1px solid #eee; cursor:pointer;"><?php _e( 'Recommend', 'liquid-blocks' ); ?></h2> |
| 962 |
<div class="inside"><?php echo wp_kses_post($liquid_blocks_json['recommend']); ?></div> |
| 963 |
</div> |
| 964 |
<?php } ?> |
| 965 |
|
| 966 |
<!-- Settings --> |
| 967 |
<div class="postbox"> |
| 968 |
<h2 style="border-bottom: 1px solid #eee;"><?php _e( 'Settings', 'liquid-blocks' ); ?></h2> |
| 969 |
<div class="inside"> |
| 970 |
<form method="post" action="options.php"> |
| 971 |
<?php |
| 972 |
settings_fields( 'liquid_blocks_group' ); |
| 973 |
do_settings_sections( 'default' ); |
| 974 |
?> |
| 975 |
<?php if ( function_exists('register_block_pattern') ) { ?> |
| 976 |
<?php if ( ! is_liquid_pro() ) { ?> |
| 977 |
<h3 class="liquid-blocks-pro-ttl"><?php _e( 'LIQUID BLOCKS Pro', 'liquid-blocks' ); ?></h3> |
| 978 |
<div class="liquid-blocks-pro-box"> |
| 979 |
<p><?php _e('Unlock all features with the Pro version.', 'liquid-blocks'); ?></p> |
| 980 |
<ul style="list-style:disc;padding-left:1.5em;margin-bottom:1.5em;"> |
| 981 |
<li><?php _e('Unlimited Slider and Tabs (free version: up to 10 each)', 'liquid-blocks'); ?></li> |
| 982 |
<li><?php _e('Fixed blocks and If conditional blocks: Advanced options', 'liquid-blocks'); ?></li> |
| 983 |
</ul> |
| 984 |
<a href="https://lqd.jp/wp/plugin/blocks_pro.html" target="_blank" rel="noopener" class="button button-primary" style="font-size:14px;height:auto;padding:8px 20px;"><?php _e( 'Get Pro', 'liquid-blocks' ); ?></a> |
| 985 |
</div> |
| 986 |
<?php } ?> |
| 987 |
<h3><?php _e( 'Block Pattern Manager', 'liquid-blocks' ); ?></h3> |
| 988 |
<a href="site-editor.php?p=%2Fpattern" class="button button-primary"><?php _e( 'Block Pattern Manager', 'liquid-blocks' ); ?></a> |
| 989 |
<h3><?php _e( 'Enable default block pattern', 'liquid-blocks' ); ?></h3> |
| 990 |
<p> |
| 991 |
<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> |
| 992 |
<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> |
| 993 |
</p> |
| 994 |
<?php } ?> |
| 995 |
<h3><?php _e( 'Shortcuts', 'liquid-blocks' ); ?></h3> |
| 996 |
<p><?php _e( 'Sidebar shortcut button settings.', 'liquid-blocks' ); ?><br><?php _e( 'Enter any name, gallery category name, and number.', 'liquid-blocks' ); ?></p> |
| 997 |
<?php |
| 998 |
for ($i=0; $i<10; $i++) { |
| 999 |
$j = $i + 1; |
| 1000 |
$no = !empty($liquid_blocks_no[$i]) ? $liquid_blocks_no[$i] : ""; |
| 1001 |
$type = !empty($liquid_blocks_type[$i]) ? $liquid_blocks_type[$i] : ""; |
| 1002 |
$name = !empty($liquid_blocks_name[$i]) ? $liquid_blocks_name[$i] : ""; |
| 1003 |
echo '<p>'.$j.' Name:<input type="text" name="liquid_blocks_name['.$i.']" value="'.esc_html($name).'" placeholder="intro"> '; |
| 1004 |
echo 'Type:<input type="text" name="liquid_blocks_type['.$i.']" value="'.esc_html($type).'" placeholder="Headlines"> '; |
| 1005 |
echo 'No:<input type="number" name="liquid_blocks_no['.$i.']" value="'.esc_html($no).'"></p>'; |
| 1006 |
} |
| 1007 |
?> |
| 1008 |
<h3><?php _e( 'Enable', 'liquid-blocks' ); ?> LIQUID BLOCKS</h3> |
| 1009 |
<p> |
| 1010 |
<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> |
| 1011 |
<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> |
| 1012 |
</p> |
| 1013 |
<?php submit_button(); ?> |
| 1014 |
</form> |
| 1015 |
</div> |
| 1016 |
</div> |
| 1017 |
|
| 1018 |
</div><!-- /poststuff --> |
| 1019 |
<hr><a href="https://lqd.jp/wp/" target="_blank">LIQUID PRESS</a> |
| 1020 |
</div><!-- /wrap --> |
| 1021 |
<?php } ?> |