block-types.php
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | if(!class_exists('acfe_dynamic_block_types')): |
| 7 | |
| 8 | class acfe_dynamic_block_types extends acfe_dynamic_module{ |
| 9 | |
| 10 | /* |
| 11 | * Initialize |
| 12 | */ |
| 13 | function initialize(){ |
| 14 | |
| 15 | $this->active = acf_get_setting('acfe/modules/block_types'); |
| 16 | $this->settings = 'modules.block_types'; |
| 17 | $this->post_type = 'acfe-dbt'; |
| 18 | $this->label = 'Block Type Title'; |
| 19 | $this->textdomain = 'ACF Extended: Block Types'; |
| 20 | |
| 21 | $this->tool = 'acfe_dynamic_block_types_export'; |
| 22 | $this->tools = array('php', 'json'); |
| 23 | $this->columns = array( |
| 24 | 'name' => __('Name', 'acf'), |
| 25 | 'category' => __('Category', 'acf'), |
| 26 | 'post_types' => __('Post Types', 'acf'), |
| 27 | 'render' => __('Render', 'acf'), |
| 28 | ); |
| 29 | |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | * Actions |
| 34 | */ |
| 35 | function actions(){ |
| 36 | |
| 37 | add_filter('acf/validate_value/key=field_acfe_dbt_name', array($this, 'validate_name'), 10, 4); |
| 38 | add_filter('acf/update_value/key=field_acfe_dbt_name', array($this, 'update_name'), 10, 3); |
| 39 | |
| 40 | // Save |
| 41 | add_filter('acfe/block_type/register', array($this, 'register'), 10, 2); |
| 42 | add_filter('acfe/block_type/save_args', array($this, 'save_args'), 10, 3); |
| 43 | add_action('acfe/block_type/save', array($this, 'save'), 10, 3); |
| 44 | |
| 45 | // Import |
| 46 | add_action('acfe/block_type/import_fields', array($this, 'import_fields'), 10, 3); |
| 47 | add_action('acfe/block_type/import', array($this, 'after_import'), 10, 2); |
| 48 | |
| 49 | $this->register_user_block_types(); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Get Name |
| 55 | */ |
| 56 | function get_name($post_id){ |
| 57 | |
| 58 | return get_field('name', $post_id); |
| 59 | |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Init |
| 64 | */ |
| 65 | function init(){ |
| 66 | |
| 67 | $this->register_post_type(); |
| 68 | |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * Register Post Type |
| 73 | */ |
| 74 | function register_post_type(){ |
| 75 | |
| 76 | $capability = acf_get_setting('capability'); |
| 77 | |
| 78 | if(!acf_get_setting('show_admin')) |
| 79 | $capability = false; |
| 80 | |
| 81 | register_post_type($this->post_type, array( |
| 82 | 'label' => 'Block Type', |
| 83 | 'description' => 'Block Type', |
| 84 | 'labels' => array( |
| 85 | 'name' => 'Block Types', |
| 86 | 'singular_name' => 'Block Type', |
| 87 | 'menu_name' => 'Block Types', |
| 88 | 'edit_item' => 'Edit Block Type', |
| 89 | 'add_new_item' => 'New Block Type', |
| 90 | ), |
| 91 | 'supports' => array('title'), |
| 92 | 'hierarchical' => false, |
| 93 | 'public' => false, |
| 94 | 'show_ui' => true, |
| 95 | 'show_in_menu' => 'edit.php?post_type=acf-field-group', |
| 96 | 'menu_icon' => 'dashicons-layout', |
| 97 | 'show_in_admin_bar' => false, |
| 98 | 'show_in_nav_menus' => false, |
| 99 | 'can_export' => false, |
| 100 | 'has_archive' => false, |
| 101 | 'rewrite' => false, |
| 102 | 'exclude_from_search' => true, |
| 103 | 'publicly_queryable' => false, |
| 104 | 'capabilities' => array( |
| 105 | 'publish_posts' => $capability, |
| 106 | 'edit_posts' => $capability, |
| 107 | 'edit_others_posts' => $capability, |
| 108 | 'delete_posts' => $capability, |
| 109 | 'delete_others_posts' => $capability, |
| 110 | 'read_private_posts' => $capability, |
| 111 | 'edit_post' => $capability, |
| 112 | 'delete_post' => $capability, |
| 113 | 'read_post' => $capability, |
| 114 | ), |
| 115 | 'acfe_admin_orderby' => 'title', |
| 116 | 'acfe_admin_order' => 'ASC', |
| 117 | 'acfe_admin_ppp' => 999, |
| 118 | )); |
| 119 | |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Register User Block Types |
| 124 | */ |
| 125 | function register_user_block_types(){ |
| 126 | |
| 127 | $settings = apply_filters('acfe/block_type/prepare_register', acfe_get_settings($this->settings)); |
| 128 | |
| 129 | if(empty($settings)) |
| 130 | return; |
| 131 | |
| 132 | foreach($settings as $name => $args){ |
| 133 | |
| 134 | // Bail early |
| 135 | if(empty($name) || acf_has_block_type('acf/' . $name)) |
| 136 | continue; |
| 137 | |
| 138 | // Filters |
| 139 | $args = apply_filters("acfe/block_type/register", $args, $name); |
| 140 | $args = apply_filters("acfe/block_type/register/name={$name}", $args, $name); |
| 141 | |
| 142 | if($args === false) |
| 143 | continue; |
| 144 | |
| 145 | // Register |
| 146 | acf_register_block_type($args); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * Post Head |
| 154 | */ |
| 155 | function post_head(){ |
| 156 | |
| 157 | global $post; |
| 158 | |
| 159 | $post_id = $post->ID; |
| 160 | $name = $this->get_name($post->ID); |
| 161 | |
| 162 | $field_groups = acf_get_field_groups(array( |
| 163 | 'block' => "acf/{$name}" |
| 164 | )); |
| 165 | |
| 166 | if($field_groups){ |
| 167 | |
| 168 | add_meta_box('acfe-dbt-field-groups', __('Field Groups', 'acf'), array($this, 'metabox_render'), $this->post_type, 'normal', 'default', $field_groups); |
| 169 | |
| 170 | } |
| 171 | |
| 172 | $prepend = acfe_get_setting('theme_folder') ? trailingslashit(acfe_get_setting('theme_folder')) : ''; |
| 173 | |
| 174 | add_filter('acf/prepare_field/name=render_template', function($field) use($name, $prepend){ |
| 175 | |
| 176 | $prepend = apply_filters("acfe/block_type/prepend/template", $prepend, $name); |
| 177 | $prepend = apply_filters("acfe/block_type/prepend/template/name={$name}", $prepend, $name); |
| 178 | $field['prepend'] = $prepend; |
| 179 | return $field; |
| 180 | |
| 181 | }); |
| 182 | |
| 183 | add_filter('acf/prepare_field/name=enqueue_style', function($field) use($name, $prepend){ |
| 184 | |
| 185 | $prepend = apply_filters("acfe/block_type/prepend/style", $prepend, $name); |
| 186 | $prepend = apply_filters("acfe/block_type/prepend/style/name={$name}", $prepend, $name); |
| 187 | $field['prepend'] = $prepend; |
| 188 | return $field; |
| 189 | |
| 190 | }); |
| 191 | |
| 192 | add_filter('acf/prepare_field/name=enqueue_script', function($field) use($name, $prepend){ |
| 193 | |
| 194 | $prepend = apply_filters("acfe/block_type/prepend/script", $prepend, $name); |
| 195 | $prepend = apply_filters("acfe/block_type/prepend/script/name={$name}", $prepend, $name); |
| 196 | $field['prepend'] = $prepend; |
| 197 | return $field; |
| 198 | |
| 199 | }); |
| 200 | |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * Metabox Render |
| 205 | */ |
| 206 | function metabox_render($array, $data){ |
| 207 | |
| 208 | $data = $data['args']; |
| 209 | |
| 210 | foreach($data as $field_group){ ?> |
| 211 | |
| 212 | <div class="acf-field"> |
| 213 | |
| 214 | <div class="acf-label"> |
| 215 | <label for="acf-_post_title"><a href="<?php echo admin_url('post.php?post=' . $field_group['ID'] . '&action=edit'); ?>"><?php echo $field_group['title']; ?></a></label> |
| 216 | <p class="description"><?php echo $field_group['key']; ?></p> |
| 217 | </div> |
| 218 | |
| 219 | <div class="acf-input"> |
| 220 | <?php $fields = acf_get_fields($field_group); ?> |
| 221 | |
| 222 | <?php if(!empty($fields)){ ?> |
| 223 | |
| 224 | <table class="acf-table"> |
| 225 | <thead> |
| 226 | <th class="acf-th" width="25%"><strong>Label</strong></th> |
| 227 | <th class="acf-th" width="25%"><strong>Name</strong></th> |
| 228 | <th class="acf-th" width="25%"><strong>Key</strong></th> |
| 229 | <th class="acf-th" width="25%"><strong>Type</strong></th> |
| 230 | </thead> |
| 231 | |
| 232 | <tbody> |
| 233 | <?php |
| 234 | |
| 235 | $array = array(); |
| 236 | foreach($fields as $field){ |
| 237 | |
| 238 | $this->get_fields_labels_recursive($array, $field); |
| 239 | |
| 240 | } |
| 241 | |
| 242 | foreach($array as $field_key => $field_label){ |
| 243 | |
| 244 | $field = acf_get_field($field_key); |
| 245 | $type = acf_get_field_type($field['type']); |
| 246 | $type_label = '-'; |
| 247 | if(isset($type->label)) |
| 248 | $type_label = $type->label; |
| 249 | ?> |
| 250 | |
| 251 | <tr class="acf-row"> |
| 252 | <td width="25%"><?php echo $field_label; ?></td> |
| 253 | <td width="25%"><?php echo $field['name']; ?></td> |
| 254 | <td width="25%"><code><?php echo $field_key; ?></code></td> |
| 255 | <td width="25%"><?php echo $type_label; ?></td> |
| 256 | </tr> |
| 257 | |
| 258 | <?php } ?> |
| 259 | </tbody> |
| 260 | </table> |
| 261 | |
| 262 | <?php } ?> |
| 263 | </div> |
| 264 | |
| 265 | </div> |
| 266 | |
| 267 | <?php } ?> |
| 268 | |
| 269 | <script type="text/javascript"> |
| 270 | (function($){ |
| 271 | |
| 272 | if(typeof acf === 'undefined') |
| 273 | return; |
| 274 | |
| 275 | acf.newPostbox(<?php echo wp_json_encode(array( |
| 276 | 'id' => 'acfe-dbt-field-groups', |
| 277 | 'key' => '', |
| 278 | 'style' => 'default', |
| 279 | 'label' => 'left', |
| 280 | 'edit' => false |
| 281 | )); ?>); |
| 282 | |
| 283 | })(jQuery); |
| 284 | </script> |
| 285 | <?php |
| 286 | |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * Edit Columns HTML |
| 291 | */ |
| 292 | function edit_columns_html($column, $post_id){ |
| 293 | |
| 294 | switch($column){ |
| 295 | |
| 296 | // Name |
| 297 | case 'name': |
| 298 | |
| 299 | echo '<code style="font-size: 12px;">' . $this->get_name($post_id) . '</code>'; |
| 300 | break; |
| 301 | |
| 302 | // Category |
| 303 | case 'category': |
| 304 | |
| 305 | $cat = '—'; |
| 306 | $category = get_field('category', $post_id); |
| 307 | |
| 308 | if(!empty($category)) |
| 309 | $cat = ucfirst($category); |
| 310 | |
| 311 | echo $cat; |
| 312 | break; |
| 313 | |
| 314 | // Post Types |
| 315 | case 'post_types': |
| 316 | |
| 317 | $pt = '—'; |
| 318 | |
| 319 | $get_post_types = acf_get_array(get_field('post_types', $post_id)); |
| 320 | |
| 321 | if(!empty($get_post_types)){ |
| 322 | |
| 323 | $post_types = array(); |
| 324 | |
| 325 | foreach($get_post_types as $post_type){ |
| 326 | |
| 327 | if(!post_type_exists($post_type)) |
| 328 | continue; |
| 329 | |
| 330 | $post_types[] = $post_type; |
| 331 | |
| 332 | } |
| 333 | |
| 334 | if(!empty($post_types)){ |
| 335 | |
| 336 | $post_types_labels = acf_get_pretty_post_types($post_types); |
| 337 | |
| 338 | if(!empty($post_types_labels)){ |
| 339 | $pt = implode(', ', $post_types_labels); |
| 340 | } |
| 341 | |
| 342 | } |
| 343 | |
| 344 | } |
| 345 | |
| 346 | echo $pt; |
| 347 | break; |
| 348 | |
| 349 | // Render |
| 350 | case 'render': |
| 351 | |
| 352 | // vars |
| 353 | $render = '—'; |
| 354 | $render_template = get_field('render_template', $post_id); |
| 355 | $render_callback = get_field('render_callback', $post_id); |
| 356 | |
| 357 | if(!empty($render_template)){ |
| 358 | |
| 359 | $render = '<code style="font-size: 12px;">' . $render_template . '</code>'; |
| 360 | |
| 361 | }elseif(!empty($render_callback)){ |
| 362 | |
| 363 | $render = '<code style="font-size: 12px;">' . $render_callback . '</code>'; |
| 364 | |
| 365 | } |
| 366 | |
| 367 | echo $render; |
| 368 | |
| 369 | break; |
| 370 | |
| 371 | } |
| 372 | |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | * ACF Save post |
| 377 | */ |
| 378 | function save_post($post_id){ |
| 379 | |
| 380 | // vars |
| 381 | $args = array(); |
| 382 | $name = $this->get_name($post_id); |
| 383 | |
| 384 | // Filters |
| 385 | $args = apply_filters("acfe/block_type/save_args", $args, $name, $post_id); |
| 386 | $args = apply_filters("acfe/block_type/save_args/name={$name}", $args, $name, $post_id); |
| 387 | $args = apply_filters("acfe/block_type/save_args/id={$post_id}", $args, $name, $post_id); |
| 388 | |
| 389 | if($args === false) |
| 390 | return; |
| 391 | |
| 392 | // Actions |
| 393 | do_action("acfe/block_type/save", $name, $args, $post_id); |
| 394 | do_action("acfe/block_type/save/name={$name}", $name, $args, $post_id); |
| 395 | do_action("acfe/block_type/save/id={$post_id}", $name, $args, $post_id); |
| 396 | |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * Save Args |
| 401 | */ |
| 402 | function save_args($args, $name, $post_id){ |
| 403 | |
| 404 | $label = get_post_field('post_title', $post_id); |
| 405 | $name = get_field('name', $post_id); |
| 406 | $description = get_field('description', $post_id); |
| 407 | $category = get_field('category', $post_id); |
| 408 | $keywords = acf_decode_choices(get_field('keywords', $post_id), true); |
| 409 | $post_types = acf_get_array(get_field('post_types', $post_id)); |
| 410 | $mode = get_field('mode', $post_id); |
| 411 | $align = get_field('align', $post_id); |
| 412 | $align_content = get_field('align_content', $post_id); |
| 413 | $render_template = get_field('render_template', $post_id); |
| 414 | $render_callback = get_field('render_callback', $post_id); |
| 415 | $enqueue_style = get_field('enqueue_style', $post_id); |
| 416 | $enqueue_script = get_field('enqueue_script', $post_id); |
| 417 | $enqueue_assets = get_field('enqueue_assets', $post_id); |
| 418 | |
| 419 | // Register: Args |
| 420 | $args = array( |
| 421 | 'name' => $name, |
| 422 | 'title' => $label, |
| 423 | 'description' => $description, |
| 424 | 'category' => $category, |
| 425 | 'keywords' => $keywords, |
| 426 | 'post_types' => $post_types, |
| 427 | 'mode' => $mode, |
| 428 | 'align' => $align, |
| 429 | 'align_content' => $align_content, |
| 430 | 'render_template' => $render_template, |
| 431 | 'render_callback' => $render_callback, |
| 432 | 'enqueue_style' => $enqueue_style, |
| 433 | 'enqueue_script' => $enqueue_script, |
| 434 | 'enqueue_assets' => $enqueue_assets, |
| 435 | ); |
| 436 | |
| 437 | // Align |
| 438 | if($align === 'none') |
| 439 | $args['align'] = ''; |
| 440 | |
| 441 | // Icon |
| 442 | $icon_type = get_field('icon_type', $post_id); |
| 443 | |
| 444 | // Icon: Simple |
| 445 | if($icon_type === 'simple'){ |
| 446 | |
| 447 | $icon_text = get_field('icon_text', $post_id); |
| 448 | $args['icon'] = $icon_text; |
| 449 | |
| 450 | } |
| 451 | |
| 452 | // Icon: Colors |
| 453 | elseif($icon_type == 'colors'){ |
| 454 | |
| 455 | $icon_background = get_field('icon_background', $post_id); |
| 456 | $icon_foreground = get_field('icon_foreground', $post_id); |
| 457 | $icon_src = get_field('icon_src', $post_id); |
| 458 | |
| 459 | $args['icon'] = array( |
| 460 | 'background' => $icon_background, |
| 461 | 'foreground' => $icon_foreground, |
| 462 | 'src' => $icon_src, |
| 463 | ); |
| 464 | |
| 465 | } |
| 466 | |
| 467 | // Supports: Align |
| 468 | $supports_align = get_field('supports_align', $post_id); |
| 469 | $supports_align_args = acf_decode_choices(get_field('supports_align_args', $post_id), true); |
| 470 | |
| 471 | $args['supports']['align'] = false; |
| 472 | if(!empty($supports_align)){ |
| 473 | |
| 474 | $args['supports']['align'] = true; |
| 475 | |
| 476 | if(!empty($supports_align_args)) |
| 477 | $args['supports']['align'] = $supports_align_args; |
| 478 | |
| 479 | } |
| 480 | |
| 481 | // Supports: Mode |
| 482 | $supports_mode = get_field('supports_mode', $post_id); |
| 483 | |
| 484 | $args['supports']['mode'] = false; |
| 485 | if(!empty($supports_mode)) |
| 486 | $args['supports']['mode'] = true; |
| 487 | |
| 488 | // Supports: Multiple |
| 489 | $supports_multiple = get_field('supports_multiple', $post_id); |
| 490 | |
| 491 | $args['supports']['multiple'] = false; |
| 492 | if(!empty($supports_multiple)) |
| 493 | $args['supports']['multiple'] = true; |
| 494 | |
| 495 | // Supports: Experimental JSX |
| 496 | $experimental_jsx = get_field('supports_experimental_jsx', $post_id); |
| 497 | |
| 498 | $args['supports']['jsx'] = false; |
| 499 | if(!empty($experimental_jsx)) |
| 500 | $args['supports']['jsx'] = true; |
| 501 | |
| 502 | // Supports: Align Content |
| 503 | $supports_align_content = get_field('supports_align_content', $post_id); |
| 504 | |
| 505 | $args['supports']['align_content'] = false; |
| 506 | if(!empty($supports_align_content)) |
| 507 | $args['supports']['align_content'] = true; |
| 508 | |
| 509 | // Supports: Anchor |
| 510 | $supports_anchor = get_field('supports_anchor', $post_id); |
| 511 | |
| 512 | $args['supports']['anchor'] = false; |
| 513 | if(!empty($supports_anchor)) |
| 514 | $args['supports']['anchor'] = true; |
| 515 | |
| 516 | return $args; |
| 517 | |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * Save |
| 522 | */ |
| 523 | function save($name, $args, $post_id){ |
| 524 | |
| 525 | // Get ACFE option |
| 526 | $settings = acfe_get_settings($this->settings); |
| 527 | |
| 528 | // Create ACFE option |
| 529 | $settings[$name] = $args; |
| 530 | |
| 531 | // Sort keys ASC |
| 532 | ksort($settings); |
| 533 | |
| 534 | // Update ACFE option |
| 535 | acfe_update_settings($this->settings, $settings); |
| 536 | |
| 537 | // Update post |
| 538 | wp_update_post(array( |
| 539 | 'ID' => $post_id, |
| 540 | 'post_name' => $name, |
| 541 | )); |
| 542 | |
| 543 | } |
| 544 | |
| 545 | /* |
| 546 | * Trashed Post Type |
| 547 | */ |
| 548 | function trashed_post($post_id){ |
| 549 | |
| 550 | $name = $this->get_name($post_id); |
| 551 | |
| 552 | // Get ACFE option |
| 553 | $settings = acfe_get_settings($this->settings); |
| 554 | |
| 555 | // Unset ACFE option |
| 556 | acfe_unset($settings, $name); |
| 557 | |
| 558 | // Update ACFE option |
| 559 | acfe_update_settings($this->settings, $settings); |
| 560 | |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | * Validate Name |
| 565 | */ |
| 566 | function validate_name($valid, $value, $field, $input){ |
| 567 | |
| 568 | if(!$valid) |
| 569 | return $valid; |
| 570 | |
| 571 | // Editing Current Block Type |
| 572 | $current_post_id = acf_maybe_get_POST('post_ID'); |
| 573 | |
| 574 | if(!empty($current_post_id)){ |
| 575 | |
| 576 | $current_name = get_field($field['name'], $current_post_id); |
| 577 | |
| 578 | if($value === $current_name) |
| 579 | return $valid; |
| 580 | |
| 581 | } |
| 582 | |
| 583 | // Check existing ACF Block Types |
| 584 | if(acf_has_block_type('acf/' . $value)){ |
| 585 | |
| 586 | $valid = 'This block type name already exists'; |
| 587 | |
| 588 | } |
| 589 | |
| 590 | return $valid; |
| 591 | |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * Update Name |
| 596 | */ |
| 597 | function update_name($value, $post_id, $field){ |
| 598 | |
| 599 | // Previous value |
| 600 | $_value = get_field($field['name'], $post_id); |
| 601 | |
| 602 | // Value Changed. Delete option |
| 603 | if($_value !== $value){ |
| 604 | acfe_delete_settings("{$this->settings}.{$_value}"); |
| 605 | } |
| 606 | |
| 607 | return $value; |
| 608 | |
| 609 | } |
| 610 | |
| 611 | /* |
| 612 | * Register |
| 613 | */ |
| 614 | function register($args, $name){ |
| 615 | |
| 616 | // Translate: Title |
| 617 | if(isset($args['title'])){ |
| 618 | acfe__($args['title'], 'Title', $this->textdomain); |
| 619 | } |
| 620 | |
| 621 | // Translate: Description |
| 622 | if(isset($args['description'])){ |
| 623 | acfe__($args['description'], 'Description', $this->textdomain); |
| 624 | } |
| 625 | |
| 626 | // Template |
| 627 | if(acf_maybe_get($args, 'render_template')){ |
| 628 | $template = acfe_locate_file_path($args['render_template']); |
| 629 | |
| 630 | if(!empty($template)){ |
| 631 | $args['render_template'] = $template; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | // Style |
| 636 | if(acf_maybe_get($args, 'enqueue_style')){ |
| 637 | $style = acfe_locate_file_url($args['enqueue_style']); |
| 638 | |
| 639 | if(!empty($style)){ |
| 640 | $args['enqueue_style'] = $style; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | // Script |
| 645 | if(acf_maybe_get($args, 'enqueue_script')){ |
| 646 | $script = acfe_locate_file_url($args['enqueue_script']); |
| 647 | |
| 648 | if(!empty($script)){ |
| 649 | $args['enqueue_script'] = $script; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | return $args; |
| 654 | |
| 655 | } |
| 656 | |
| 657 | /* |
| 658 | * Import: Data |
| 659 | */ |
| 660 | function import($name, $args){ |
| 661 | |
| 662 | // Vars |
| 663 | $settings = acfe_get_settings($this->settings); |
| 664 | $title = $args['title']; |
| 665 | |
| 666 | // Already exists |
| 667 | if(isset($settings[$name])){ |
| 668 | return new WP_Error('acfe_dbt_import_already_exists', __("Block type \"{$title}\" already exists. Import aborted.")); |
| 669 | } |
| 670 | |
| 671 | // Import Post |
| 672 | $post_id = false; |
| 673 | |
| 674 | $post = array( |
| 675 | 'post_title' => $title, |
| 676 | 'post_name' => $name, |
| 677 | 'post_type' => $this->post_type, |
| 678 | 'post_status' => 'publish' |
| 679 | ); |
| 680 | |
| 681 | $post = apply_filters("acfe/block_type/import_post", $post, $name); |
| 682 | $post = apply_filters("acfe/block_type/import_post/name={$name}", $post, $name); |
| 683 | |
| 684 | if($post !== false){ |
| 685 | $post_id = wp_insert_post($post); |
| 686 | } |
| 687 | |
| 688 | if(!$post_id || is_wp_error($post_id)){ |
| 689 | return new WP_Error('acfe_dbt_import_error', __("Something went wrong with the block type \"{$title}\". Import aborted.")); |
| 690 | } |
| 691 | |
| 692 | // Import Args |
| 693 | $args = apply_filters("acfe/block_type/import_args", $args, $name, $post_id); |
| 694 | $args = apply_filters("acfe/block_type/import_args/name={$name}", $args, $name, $post_id); |
| 695 | $args = apply_filters("acfe/block_type/import_args/name={$post_id}", $args, $name, $post_id); |
| 696 | |
| 697 | if($args === false) |
| 698 | return $post_id; |
| 699 | |
| 700 | // Import Fields |
| 701 | acf_enable_filter('local'); |
| 702 | |
| 703 | do_action("acfe/block_type/import_fields", $name, $args, $post_id); |
| 704 | do_action("acfe/block_type/import_fields/name={$name}", $name, $args, $post_id); |
| 705 | do_action("acfe/block_type/import_fields/id={$post_id}", $name, $args, $post_id); |
| 706 | |
| 707 | acf_disable_filter('local'); |
| 708 | |
| 709 | // Save |
| 710 | $this->save_post($post_id); |
| 711 | |
| 712 | return $post_id; |
| 713 | |
| 714 | } |
| 715 | |
| 716 | /* |
| 717 | * Import: Fields |
| 718 | */ |
| 719 | function import_fields($name, $args, $post_id){ |
| 720 | |
| 721 | update_field('name', $name, $post_id); |
| 722 | update_field('description', $args['description'], $post_id); |
| 723 | update_field('category', $args['category'], $post_id); |
| 724 | update_field('keywords', acf_encode_choices($args['keywords'], false), $post_id); |
| 725 | update_field('post_types', $args['post_types'], $post_id); |
| 726 | update_field('mode', $args['mode'], $post_id); |
| 727 | update_field('align', $args['align'], $post_id); |
| 728 | update_field('render_callback', $args['render_callback'], $post_id); |
| 729 | update_field('enqueue_assets', $args['enqueue_assets'], $post_id); |
| 730 | update_field('render_template', $args['render_template'], $post_id); |
| 731 | update_field('enqueue_style', $args['enqueue_style'], $post_id); |
| 732 | update_field('enqueue_script', $args['enqueue_script'], $post_id); |
| 733 | |
| 734 | // Align |
| 735 | if(empty($args['align'])) |
| 736 | update_field('align', 'none', $post_id); |
| 737 | |
| 738 | // Icon |
| 739 | if(!empty($args['icon'])){ |
| 740 | |
| 741 | // Simple |
| 742 | if(is_string($args['icon'])){ |
| 743 | |
| 744 | update_field('icon_type', 'simple', $post_id); |
| 745 | update_field('icon_text', $args['icon'], $post_id); |
| 746 | |
| 747 | } |
| 748 | |
| 749 | // Colors |
| 750 | elseif(is_array($args['icon'])){ |
| 751 | |
| 752 | update_field('icon_type', 'colors', $post_id); |
| 753 | |
| 754 | update_field('icon_background', $args['icon']['background'], $post_id); |
| 755 | update_field('icon_foreground', $args['icon']['foreground'], $post_id); |
| 756 | update_field('icon_src', $args['icon']['src'], $post_id); |
| 757 | |
| 758 | } |
| 759 | |
| 760 | } |
| 761 | |
| 762 | // Supports: Align |
| 763 | update_field('supports_align', $args['supports']['align'], $post_id); |
| 764 | |
| 765 | if(is_array($args['supports']['align'])){ |
| 766 | |
| 767 | update_field('supports_align_args', acf_encode_choices($args['supports']['align'], false), $post_id); |
| 768 | |
| 769 | } |
| 770 | |
| 771 | // Supports: Mode |
| 772 | update_field('supports_mode', $args['supports']['mode'], $post_id); |
| 773 | |
| 774 | // Supports: Multiple |
| 775 | update_field('supports_multiple', $args['supports']['multiple'], $post_id); |
| 776 | |
| 777 | } |
| 778 | |
| 779 | /* |
| 780 | * Export: Choices |
| 781 | */ |
| 782 | function export_choices(){ |
| 783 | |
| 784 | $choices = array(); |
| 785 | $settings = acfe_get_settings($this->settings); |
| 786 | |
| 787 | if(!$settings) |
| 788 | return $choices; |
| 789 | |
| 790 | foreach($settings as $name => $args){ |
| 791 | |
| 792 | $choices[$name] = esc_html($args['title']); |
| 793 | |
| 794 | } |
| 795 | |
| 796 | return $choices; |
| 797 | |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * Export: Data |
| 802 | */ |
| 803 | function export_data($name){ |
| 804 | |
| 805 | // Settings |
| 806 | $settings = acfe_get_settings($this->settings); |
| 807 | |
| 808 | // Doesn't exist |
| 809 | if(!isset($settings[$name])) |
| 810 | return false; |
| 811 | |
| 812 | $args = $settings[$name]; |
| 813 | |
| 814 | // Filters |
| 815 | $args = apply_filters("acfe/block_type/export_args", $args, $name); |
| 816 | $args = apply_filters("acfe/block_type/export_args/name={$name}", $args, $name); |
| 817 | |
| 818 | // Return |
| 819 | return $args; |
| 820 | |
| 821 | } |
| 822 | |
| 823 | /* |
| 824 | * Export: PHP |
| 825 | */ |
| 826 | function export_php($data){ |
| 827 | |
| 828 | // prevent default translation and fake __() within string |
| 829 | acf_update_setting('l10n_var_export', true); |
| 830 | |
| 831 | $str_replace = array( |
| 832 | " " => "\t", |
| 833 | "'!!__(!!\'" => "__('", |
| 834 | "!!\', !!\'" => "', '", |
| 835 | "!!\')!!'" => "')", |
| 836 | "array (" => "array(" |
| 837 | ); |
| 838 | |
| 839 | $preg_replace = array( |
| 840 | '/([\t\r\n]+?)array/' => 'array', |
| 841 | '/[0-9]+ => array/' => 'array' |
| 842 | ); |
| 843 | |
| 844 | // Get settings. |
| 845 | $l10n = acf_get_setting('l10n'); |
| 846 | $l10n_textdomain = acf_get_setting('l10n_textdomain'); |
| 847 | |
| 848 | echo "if( function_exists('acf_register_block_type') ):" . "\r\n" . "\r\n"; |
| 849 | |
| 850 | foreach($data as $args){ |
| 851 | |
| 852 | // Translate settings if textdomain is set. |
| 853 | if($l10n && $l10n_textdomain){ |
| 854 | |
| 855 | $args['title'] = acf_translate($args['title']); |
| 856 | $args['description'] = acf_translate($args['description']); |
| 857 | |
| 858 | } |
| 859 | |
| 860 | // code |
| 861 | $code = var_export($args, true); |
| 862 | |
| 863 | // change double spaces to tabs |
| 864 | $code = str_replace(array_keys($str_replace), array_values($str_replace), $code); |
| 865 | |
| 866 | // correctly formats "=> array(" |
| 867 | $code = preg_replace(array_keys($preg_replace), array_values($preg_replace), $code); |
| 868 | |
| 869 | // esc_textarea |
| 870 | $code = esc_textarea($code); |
| 871 | |
| 872 | // echo |
| 873 | echo "acf_register_block_type({$code});" . "\r\n" . "\r\n"; |
| 874 | |
| 875 | } |
| 876 | |
| 877 | echo "endif;"; |
| 878 | |
| 879 | } |
| 880 | |
| 881 | /* |
| 882 | * Reset |
| 883 | */ |
| 884 | function reset(){ |
| 885 | |
| 886 | $args = apply_filters("acfe/block_type/reset_args", array( |
| 887 | 'post_type' => $this->post_type, |
| 888 | 'posts_per_page' => -1, |
| 889 | 'fields' => 'ids', |
| 890 | 'post_status' => array('publish', 'acf-disabled'), |
| 891 | )); |
| 892 | |
| 893 | $posts = get_posts($args); |
| 894 | |
| 895 | if(empty($posts)) |
| 896 | return false; |
| 897 | |
| 898 | foreach($posts as $post_id){ |
| 899 | $this->save_post($post_id); |
| 900 | } |
| 901 | |
| 902 | // Log |
| 903 | acf_log('[ACF Extended] Reset: Block Types'); |
| 904 | |
| 905 | return true; |
| 906 | |
| 907 | } |
| 908 | |
| 909 | /* |
| 910 | * Add Local Field Group |
| 911 | */ |
| 912 | function add_local_field_group(){ |
| 913 | |
| 914 | //$__experimental_jsx = array(); |
| 915 | $experimental_jsx = array(); |
| 916 | $align_content = array(); |
| 917 | $supports_align_content = array(); |
| 918 | |
| 919 | if(acf_version_compare(acf_get_setting('version'), '>=', '5.9')){ |
| 920 | |
| 921 | $experimental_jsx = array( |
| 922 | 'key' => 'field_acfe_dbt_supports_experimental_jsx', |
| 923 | 'label' => 'Inner Block', |
| 924 | 'name' => 'supports_experimental_jsx', |
| 925 | 'type' => 'true_false', |
| 926 | 'instructions' => 'Enable inner block feature. Defaults to false.', |
| 927 | 'required' => 0, |
| 928 | 'conditional_logic' => 0, |
| 929 | 'wrapper' => array( |
| 930 | 'width' => '', |
| 931 | 'class' => '', |
| 932 | 'id' => '', |
| 933 | ), |
| 934 | 'acfe_validate' => '', |
| 935 | 'acfe_update' => '', |
| 936 | 'acfe_permissions' => '', |
| 937 | 'message' => '', |
| 938 | 'default_value' => 0, |
| 939 | 'ui' => 1, |
| 940 | 'ui_on_text' => 'True', |
| 941 | 'ui_off_text' => 'False', |
| 942 | ); |
| 943 | |
| 944 | $supports_align_content = array( |
| 945 | 'key' => 'field_acfe_dbt_supports_align_content', |
| 946 | 'label' => 'Align Content', |
| 947 | 'name' => 'supports_align_content', |
| 948 | 'type' => 'true_false', |
| 949 | 'instructions' => 'Set the "xy" position of content using a 3×3 matrix grid. Defaults to false.', |
| 950 | 'required' => 0, |
| 951 | 'conditional_logic' => 0, |
| 952 | 'wrapper' => array( |
| 953 | 'width' => '', |
| 954 | 'class' => '', |
| 955 | 'id' => '', |
| 956 | ), |
| 957 | 'acfe_validate' => '', |
| 958 | 'acfe_update' => '', |
| 959 | 'acfe_permissions' => '', |
| 960 | 'message' => '', |
| 961 | 'default_value' => 0, |
| 962 | 'ui' => 1, |
| 963 | 'ui_on_text' => 'True', |
| 964 | 'ui_off_text' => 'False', |
| 965 | ); |
| 966 | |
| 967 | $align_content = array( |
| 968 | 'key' => 'field_acfe_dbt_align_content', |
| 969 | 'label' => 'Align content', |
| 970 | 'name' => 'align_content', |
| 971 | 'type' => 'text', |
| 972 | 'instructions' => 'Specifies the default attribute value.', |
| 973 | 'required' => 0, |
| 974 | 'conditional_logic' => array( |
| 975 | array( |
| 976 | array( |
| 977 | 'field' => 'field_acfe_dbt_supports_align_content', |
| 978 | 'operator' => '==', |
| 979 | 'value' => '1', |
| 980 | ), |
| 981 | ), |
| 982 | ), |
| 983 | 'wrapper' => array( |
| 984 | 'width' => '', |
| 985 | 'class' => '', |
| 986 | 'id' => '', |
| 987 | ), |
| 988 | 'acfe_validate' => '', |
| 989 | 'acfe_update' => '', |
| 990 | 'acfe_permissions' => '', |
| 991 | 'default_value' => '', |
| 992 | 'placeholder' => '', |
| 993 | 'prepend' => '', |
| 994 | 'append' => '', |
| 995 | 'maxlength' => '', |
| 996 | ); |
| 997 | |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * Add Local Field Group |
| 1002 | */ |
| 1003 | acf_add_local_field_group(array( |
| 1004 | 'key' => 'group_acfe_dynamic_block_type', |
| 1005 | 'title' => __('Dynamic Block Type', 'acfe'), |
| 1006 | |
| 1007 | 'location' => array( |
| 1008 | array( |
| 1009 | array( |
| 1010 | 'param' => 'post_type', |
| 1011 | 'operator' => '==', |
| 1012 | 'value' => $this->post_type, |
| 1013 | ), |
| 1014 | ), |
| 1015 | ), |
| 1016 | |
| 1017 | 'menu_order' => 0, |
| 1018 | 'position' => 'normal', |
| 1019 | 'style' => 'default', |
| 1020 | 'label_placement' => 'left', |
| 1021 | 'instruction_placement' => 'label', |
| 1022 | 'hide_on_screen' => '', |
| 1023 | 'active' => 1, |
| 1024 | 'description' => '', |
| 1025 | |
| 1026 | 'fields' => array( |
| 1027 | array( |
| 1028 | 'key' => 'field_acfe_dbt_tab_general', |
| 1029 | 'label' => 'General', |
| 1030 | 'name' => '', |
| 1031 | 'type' => 'tab', |
| 1032 | 'instructions' => '', |
| 1033 | 'required' => 0, |
| 1034 | 'conditional_logic' => 0, |
| 1035 | 'wrapper' => array( |
| 1036 | 'width' => '', |
| 1037 | 'class' => '', |
| 1038 | 'id' => '', |
| 1039 | ), |
| 1040 | 'acfe_validate' => '', |
| 1041 | 'acfe_update' => '', |
| 1042 | 'acfe_permissions' => '', |
| 1043 | 'placement' => 'top', |
| 1044 | 'endpoint' => 0, |
| 1045 | ), |
| 1046 | array( |
| 1047 | 'key' => 'field_acfe_dbt_name', |
| 1048 | 'label' => 'Name', |
| 1049 | 'name' => 'name', |
| 1050 | 'type' => 'acfe_slug', |
| 1051 | 'instructions' => '(String) A unique name that identifies the block (without namespace).<br /> |
| 1052 | Note: A block name can only contain lowercase alphanumeric characters and dashes, and must begin with a letter.', |
| 1053 | 'required' => 1, |
| 1054 | 'conditional_logic' => 0, |
| 1055 | 'wrapper' => array( |
| 1056 | 'width' => '', |
| 1057 | 'class' => '', |
| 1058 | 'id' => '', |
| 1059 | ), |
| 1060 | 'acfe_validate' => '', |
| 1061 | 'acfe_update' => array( |
| 1062 | '5cd2ca4caa18b' => array( |
| 1063 | 'acfe_update_function' => 'sanitize_title', |
| 1064 | ), |
| 1065 | ), |
| 1066 | 'acfe_permissions' => '', |
| 1067 | 'default_value' => '', |
| 1068 | 'placeholder' => '', |
| 1069 | 'prepend' => '', |
| 1070 | 'append' => '', |
| 1071 | 'maxlength' => '', |
| 1072 | ), |
| 1073 | array( |
| 1074 | 'key' => 'field_acfe_dbt_description', |
| 1075 | 'label' => 'Description', |
| 1076 | 'name' => 'description', |
| 1077 | 'type' => 'textarea', |
| 1078 | 'instructions' => '(String) (Optional) This is a short description for your block.', |
| 1079 | 'required' => 0, |
| 1080 | 'conditional_logic' => 0, |
| 1081 | 'wrapper' => array( |
| 1082 | 'width' => '', |
| 1083 | 'class' => '', |
| 1084 | 'id' => '', |
| 1085 | ), |
| 1086 | 'acfe_validate' => '', |
| 1087 | 'acfe_update' => '', |
| 1088 | 'acfe_permissions' => '', |
| 1089 | 'default_value' => '', |
| 1090 | 'placeholder' => '', |
| 1091 | 'maxlength' => '', |
| 1092 | 'rows' => 3, |
| 1093 | 'new_lines' => '', |
| 1094 | ), |
| 1095 | array( |
| 1096 | 'key' => 'field_acfe_dbt_category', |
| 1097 | 'label' => 'Category', |
| 1098 | 'name' => 'category', |
| 1099 | 'type' => 'text', |
| 1100 | 'instructions' => '(String) Blocks are grouped into categories to help users browse and discover them. The core provided categories are [ common | formatting | layout | widgets | embed ]. Plugins and Themes can also register custom block categories.', |
| 1101 | 'required' => 0, |
| 1102 | 'conditional_logic' => 0, |
| 1103 | 'wrapper' => array( |
| 1104 | 'width' => '', |
| 1105 | 'class' => '', |
| 1106 | 'id' => '', |
| 1107 | ), |
| 1108 | 'acfe_validate' => '', |
| 1109 | 'acfe_update' => '', |
| 1110 | 'acfe_permissions' => '', |
| 1111 | 'default_value' => 'common', |
| 1112 | 'placeholder' => '', |
| 1113 | 'prepend' => '', |
| 1114 | 'append' => '', |
| 1115 | 'maxlength' => '', |
| 1116 | ), |
| 1117 | array( |
| 1118 | 'key' => 'field_acfe_dbt_keywords', |
| 1119 | 'label' => 'Keywords', |
| 1120 | 'name' => 'keywords', |
| 1121 | 'type' => 'textarea', |
| 1122 | 'instructions' => '(Array) (Optional) An array of search terms to help user discover the block while searching.<br /> |
| 1123 | One line for each keyword. ie:<br /><br /> |
| 1124 | quote<br /> |
| 1125 | mention<br /> |
| 1126 | cite', |
| 1127 | 'required' => 0, |
| 1128 | 'conditional_logic' => 0, |
| 1129 | 'wrapper' => array( |
| 1130 | 'width' => '', |
| 1131 | 'class' => '', |
| 1132 | 'id' => '', |
| 1133 | ), |
| 1134 | 'acfe_validate' => '', |
| 1135 | 'acfe_update' => '', |
| 1136 | 'acfe_permissions' => '', |
| 1137 | 'default_value' => '', |
| 1138 | 'placeholder' => '', |
| 1139 | 'maxlength' => '', |
| 1140 | 'rows' => '', |
| 1141 | 'new_lines' => '', |
| 1142 | ), |
| 1143 | array( |
| 1144 | 'key' => 'field_acfe_dbt_post_types', |
| 1145 | 'label' => 'Post types', |
| 1146 | 'name' => 'post_types', |
| 1147 | 'type' => 'acfe_post_types', |
| 1148 | 'instructions' => '(Array) (Optional) An array of post types to restrict this block type to.', |
| 1149 | 'required' => 0, |
| 1150 | 'conditional_logic' => 0, |
| 1151 | 'wrapper' => array( |
| 1152 | 'width' => '', |
| 1153 | 'class' => '', |
| 1154 | 'id' => '', |
| 1155 | ), |
| 1156 | 'acfe_validate' => '', |
| 1157 | 'acfe_update' => '', |
| 1158 | 'acfe_permissions' => '', |
| 1159 | 'field_type' => 'checkbox', |
| 1160 | 'return_format' => 'name', |
| 1161 | ), |
| 1162 | array( |
| 1163 | 'key' => 'field_acfe_dbt_mode', |
| 1164 | 'label' => 'Mode', |
| 1165 | 'name' => 'mode', |
| 1166 | 'type' => 'select', |
| 1167 | 'instructions' => '(String) (Optional) The display mode for your block. Available settings are “auto”, “preview” and “edit”. Defaults to “auto”.<br /><br /> |
| 1168 | auto: Preview is shown by default but changes to edit form when block is selected.<br /> |
| 1169 | preview: Preview is always shown. Edit form appears in sidebar when block is selected.<br /> |
| 1170 | edit: Edit form is always shown.<br /><br /> |
| 1171 | |
| 1172 | Note. When in “preview” or “edit” modes, an icon will appear in the block toolbar to toggle between modes.', |
| 1173 | 'required' => 0, |
| 1174 | 'conditional_logic' => 0, |
| 1175 | 'wrapper' => array( |
| 1176 | 'width' => '', |
| 1177 | 'class' => '', |
| 1178 | 'id' => '', |
| 1179 | ), |
| 1180 | 'acfe_validate' => '', |
| 1181 | 'acfe_update' => '', |
| 1182 | 'acfe_permissions' => '', |
| 1183 | 'choices' => array( |
| 1184 | 'auto' => 'Auto', |
| 1185 | 'preview' => 'Preview', |
| 1186 | 'edit' => 'Edit', |
| 1187 | ), |
| 1188 | 'default_value' => array( |
| 1189 | 0 => 'auto', |
| 1190 | ), |
| 1191 | 'allow_null' => 0, |
| 1192 | 'multiple' => 0, |
| 1193 | 'ui' => 0, |
| 1194 | 'return_format' => 'value', |
| 1195 | 'ajax' => 0, |
| 1196 | 'placeholder' => '', |
| 1197 | ), |
| 1198 | array( |
| 1199 | 'key' => 'field_acfe_dbt_align', |
| 1200 | 'label' => 'Align', |
| 1201 | 'name' => 'align', |
| 1202 | 'type' => 'select', |
| 1203 | 'instructions' => '(String) (Optional) The default block alignment. Available settings are “left”, “center”, “right”, “wide” and “full”. Defaults to an empty string.', |
| 1204 | 'required' => 0, |
| 1205 | 'conditional_logic' => 0, |
| 1206 | 'wrapper' => array( |
| 1207 | 'width' => '', |
| 1208 | 'class' => '', |
| 1209 | 'id' => '', |
| 1210 | ), |
| 1211 | 'acfe_validate' => '', |
| 1212 | 'acfe_update' => '', |
| 1213 | 'acfe_permissions' => '', |
| 1214 | 'choices' => array( |
| 1215 | 'none' => 'None', |
| 1216 | 'left' => 'Left', |
| 1217 | 'center' => 'Center', |
| 1218 | 'right' => 'Right', |
| 1219 | 'wide' => 'Wide', |
| 1220 | 'full' => 'Full', |
| 1221 | ), |
| 1222 | 'default_value' => array( |
| 1223 | ), |
| 1224 | 'allow_null' => 0, |
| 1225 | 'multiple' => 0, |
| 1226 | 'ui' => 0, |
| 1227 | 'return_format' => 'value', |
| 1228 | 'ajax' => 0, |
| 1229 | 'placeholder' => '', |
| 1230 | ), |
| 1231 | array( |
| 1232 | 'key' => 'field_acfe_dbt_tab_icon', |
| 1233 | 'label' => 'Icon', |
| 1234 | 'name' => '', |
| 1235 | 'type' => 'tab', |
| 1236 | 'instructions' => '', |
| 1237 | 'required' => 0, |
| 1238 | 'conditional_logic' => 0, |
| 1239 | 'wrapper' => array( |
| 1240 | 'width' => '', |
| 1241 | 'class' => '', |
| 1242 | 'id' => '', |
| 1243 | ), |
| 1244 | 'acfe_validate' => '', |
| 1245 | 'acfe_update' => '', |
| 1246 | 'acfe_permissions' => '', |
| 1247 | 'placement' => 'top', |
| 1248 | 'endpoint' => 0, |
| 1249 | ), |
| 1250 | array( |
| 1251 | 'key' => 'field_acfe_dbt_icon_type', |
| 1252 | 'label' => 'Icon Type', |
| 1253 | 'name' => 'icon_type', |
| 1254 | 'type' => 'select', |
| 1255 | 'instructions' => 'Simple: Specify a Dashicons class or SVG path<br /> |
| 1256 | Colors: Specify colors & Dashicons class', |
| 1257 | 'required' => 0, |
| 1258 | 'conditional_logic' => 0, |
| 1259 | 'wrapper' => array( |
| 1260 | 'width' => '', |
| 1261 | 'class' => '', |
| 1262 | 'id' => '', |
| 1263 | ), |
| 1264 | 'acfe_validate' => '', |
| 1265 | 'acfe_update' => '', |
| 1266 | 'acfe_permissions' => '', |
| 1267 | 'choices' => array( |
| 1268 | 'simple' => 'Simple', |
| 1269 | 'colors' => 'Colors', |
| 1270 | ), |
| 1271 | 'default_value' => array( |
| 1272 | ), |
| 1273 | 'allow_null' => 0, |
| 1274 | 'multiple' => 0, |
| 1275 | 'ui' => 0, |
| 1276 | 'return_format' => 'value', |
| 1277 | 'ajax' => 0, |
| 1278 | 'placeholder' => '', |
| 1279 | ), |
| 1280 | array( |
| 1281 | 'key' => 'field_acfe_dbt_icon_text', |
| 1282 | 'label' => 'Icon', |
| 1283 | 'name' => 'icon_text', |
| 1284 | 'type' => 'text', |
| 1285 | 'instructions' => '(String) (Optional) An icon property can be specified to make it easier to identify a block. These can be any of WordPress’ Dashicons, or a custom svg element.', |
| 1286 | 'required' => 0, |
| 1287 | 'conditional_logic' => array( |
| 1288 | array( |
| 1289 | array( |
| 1290 | 'field' => 'field_acfe_dbt_icon_type', |
| 1291 | 'operator' => '==', |
| 1292 | 'value' => 'simple', |
| 1293 | ), |
| 1294 | ), |
| 1295 | ), |
| 1296 | 'wrapper' => array( |
| 1297 | 'width' => '', |
| 1298 | 'class' => '', |
| 1299 | 'id' => '', |
| 1300 | ), |
| 1301 | 'acfe_validate' => '', |
| 1302 | 'acfe_update' => '', |
| 1303 | 'acfe_permissions' => '', |
| 1304 | 'default_value' => '', |
| 1305 | 'placeholder' => '', |
| 1306 | 'prepend' => '', |
| 1307 | 'append' => '', |
| 1308 | 'maxlength' => '', |
| 1309 | ), |
| 1310 | array( |
| 1311 | 'key' => 'field_acfe_dbt_icon_background', |
| 1312 | 'label' => 'Icon background', |
| 1313 | 'name' => 'icon_background', |
| 1314 | 'type' => 'color_picker', |
| 1315 | 'instructions' => 'Specifying a background color to appear with the icon e.g.: in the inserter.', |
| 1316 | 'required' => 0, |
| 1317 | 'conditional_logic' => array( |
| 1318 | array( |
| 1319 | array( |
| 1320 | 'field' => 'field_acfe_dbt_icon_type', |
| 1321 | 'operator' => '==', |
| 1322 | 'value' => 'colors', |
| 1323 | ), |
| 1324 | ), |
| 1325 | ), |
| 1326 | 'wrapper' => array( |
| 1327 | 'width' => '', |
| 1328 | 'class' => '', |
| 1329 | 'id' => '', |
| 1330 | ), |
| 1331 | 'acfe_validate' => '', |
| 1332 | 'acfe_update' => '', |
| 1333 | 'acfe_permissions' => '', |
| 1334 | 'default_value' => '', |
| 1335 | ), |
| 1336 | array( |
| 1337 | 'key' => 'field_acfe_dbt_icon_foreground', |
| 1338 | 'label' => 'Icon foreground', |
| 1339 | 'name' => 'icon_foreground', |
| 1340 | 'type' => 'color_picker', |
| 1341 | 'instructions' => 'Specifying a color for the icon (optional: if not set, a readable color will be automatically defined)', |
| 1342 | 'required' => 0, |
| 1343 | 'conditional_logic' => array( |
| 1344 | array( |
| 1345 | array( |
| 1346 | 'field' => 'field_acfe_dbt_icon_type', |
| 1347 | 'operator' => '==', |
| 1348 | 'value' => 'colors', |
| 1349 | ), |
| 1350 | ), |
| 1351 | ), |
| 1352 | 'wrapper' => array( |
| 1353 | 'width' => '', |
| 1354 | 'class' => '', |
| 1355 | 'id' => '', |
| 1356 | ), |
| 1357 | 'acfe_validate' => '', |
| 1358 | 'acfe_update' => '', |
| 1359 | 'acfe_permissions' => '', |
| 1360 | 'default_value' => '', |
| 1361 | ), |
| 1362 | array( |
| 1363 | 'key' => 'field_acfe_dbt_icon_src', |
| 1364 | 'label' => 'Icon src', |
| 1365 | 'name' => 'icon_src', |
| 1366 | 'type' => 'text', |
| 1367 | 'instructions' => 'Specifying a dashicon for the block', |
| 1368 | 'required' => 0, |
| 1369 | 'conditional_logic' => array( |
| 1370 | array( |
| 1371 | array( |
| 1372 | 'field' => 'field_acfe_dbt_icon_type', |
| 1373 | 'operator' => '==', |
| 1374 | 'value' => 'colors', |
| 1375 | ), |
| 1376 | ), |
| 1377 | ), |
| 1378 | 'wrapper' => array( |
| 1379 | 'width' => '', |
| 1380 | 'class' => '', |
| 1381 | 'id' => '', |
| 1382 | ), |
| 1383 | 'acfe_validate' => '', |
| 1384 | 'acfe_update' => '', |
| 1385 | 'acfe_permissions' => '', |
| 1386 | 'default_value' => '', |
| 1387 | 'placeholder' => '', |
| 1388 | 'prepend' => '', |
| 1389 | 'append' => '', |
| 1390 | 'maxlength' => '', |
| 1391 | ), |
| 1392 | array( |
| 1393 | 'key' => 'field_acfe_dbt_tab_render', |
| 1394 | 'label' => 'Render', |
| 1395 | 'name' => '', |
| 1396 | 'type' => 'tab', |
| 1397 | 'instructions' => '', |
| 1398 | 'required' => 0, |
| 1399 | 'conditional_logic' => 0, |
| 1400 | 'wrapper' => array( |
| 1401 | 'width' => '', |
| 1402 | 'class' => '', |
| 1403 | 'id' => '', |
| 1404 | ), |
| 1405 | 'acfe_validate' => '', |
| 1406 | 'acfe_update' => '', |
| 1407 | 'acfe_permissions' => '', |
| 1408 | 'placement' => 'top', |
| 1409 | 'endpoint' => 0, |
| 1410 | ), |
| 1411 | array( |
| 1412 | 'key' => 'field_acfe_dbt_render_template', |
| 1413 | 'label' => 'Render template', |
| 1414 | 'name' => 'render_template', |
| 1415 | 'type' => 'text', |
| 1416 | 'instructions' => '(String) The path to a template file used to render the block HTML. This can either be a relative path to a file within the active theme or a full path to any file.', |
| 1417 | 'required' => 0, |
| 1418 | 'conditional_logic' => 0, |
| 1419 | 'wrapper' => array( |
| 1420 | 'width' => '', |
| 1421 | 'class' => '', |
| 1422 | 'id' => '', |
| 1423 | ), |
| 1424 | 'acfe_validate' => '', |
| 1425 | 'acfe_update' => '', |
| 1426 | 'acfe_permissions' => '', |
| 1427 | 'default_value' => '', |
| 1428 | 'placeholder' => '', |
| 1429 | 'prepend' => '', |
| 1430 | 'append' => '', |
| 1431 | 'maxlength' => '', |
| 1432 | ), |
| 1433 | array( |
| 1434 | 'key' => 'field_acfe_dbt_render_callback', |
| 1435 | 'label' => 'Render callback', |
| 1436 | 'name' => 'render_callback', |
| 1437 | 'type' => 'text', |
| 1438 | 'instructions' => '(Callable) (Optional) Instead of providing a render_template, a callback function name may be specified to output the block’s HTML.', |
| 1439 | 'required' => 0, |
| 1440 | 'conditional_logic' => 0, |
| 1441 | 'wrapper' => array( |
| 1442 | 'width' => '', |
| 1443 | 'class' => '', |
| 1444 | 'id' => '', |
| 1445 | ), |
| 1446 | 'acfe_validate' => '', |
| 1447 | 'acfe_update' => '', |
| 1448 | 'acfe_permissions' => '', |
| 1449 | 'default_value' => '', |
| 1450 | 'placeholder' => '', |
| 1451 | 'prepend' => '', |
| 1452 | 'append' => '', |
| 1453 | 'maxlength' => '', |
| 1454 | ), |
| 1455 | array( |
| 1456 | 'key' => 'field_acfe_dbt_tab_enqueue', |
| 1457 | 'label' => 'Enqueue', |
| 1458 | 'name' => '', |
| 1459 | 'type' => 'tab', |
| 1460 | 'instructions' => '', |
| 1461 | 'required' => 0, |
| 1462 | 'conditional_logic' => 0, |
| 1463 | 'wrapper' => array( |
| 1464 | 'width' => '', |
| 1465 | 'class' => '', |
| 1466 | 'id' => '', |
| 1467 | ), |
| 1468 | 'acfe_validate' => '', |
| 1469 | 'acfe_update' => '', |
| 1470 | 'acfe_permissions' => '', |
| 1471 | 'placement' => 'top', |
| 1472 | 'endpoint' => 0, |
| 1473 | ), |
| 1474 | array( |
| 1475 | 'key' => 'field_acfe_dbt_enqueue_style', |
| 1476 | 'label' => 'Enqueue style', |
| 1477 | 'name' => 'enqueue_style', |
| 1478 | 'type' => 'text', |
| 1479 | 'instructions' => '(String) (Optional) The url to a .css file to be enqueued whenever your block is displayed (front-end and back-end).', |
| 1480 | 'required' => 0, |
| 1481 | 'conditional_logic' => 0, |
| 1482 | 'wrapper' => array( |
| 1483 | 'width' => '', |
| 1484 | 'class' => '', |
| 1485 | 'id' => '', |
| 1486 | ), |
| 1487 | 'acfe_validate' => '', |
| 1488 | 'acfe_update' => '', |
| 1489 | 'acfe_permissions' => '', |
| 1490 | 'default_value' => '', |
| 1491 | 'placeholder' => '', |
| 1492 | 'prepend' => '', |
| 1493 | 'append' => '', |
| 1494 | 'maxlength' => '', |
| 1495 | ), |
| 1496 | array( |
| 1497 | 'key' => 'field_acfe_dbt_enqueue_script', |
| 1498 | 'label' => 'Enqueue script', |
| 1499 | 'name' => 'enqueue_script', |
| 1500 | 'type' => 'text', |
| 1501 | 'instructions' => '(String) (Optional) The url to a .js file to be enqueued whenever your block is displayed (front-end and back-end).', |
| 1502 | 'required' => 0, |
| 1503 | 'conditional_logic' => 0, |
| 1504 | 'wrapper' => array( |
| 1505 | 'width' => '', |
| 1506 | 'class' => '', |
| 1507 | 'id' => '', |
| 1508 | ), |
| 1509 | 'acfe_validate' => '', |
| 1510 | 'acfe_update' => '', |
| 1511 | 'acfe_permissions' => '', |
| 1512 | 'default_value' => '', |
| 1513 | 'placeholder' => '', |
| 1514 | 'prepend' => '', |
| 1515 | 'append' => '', |
| 1516 | 'maxlength' => '', |
| 1517 | ), |
| 1518 | array( |
| 1519 | 'key' => 'field_acfe_dbt_enqueue_assets', |
| 1520 | 'label' => 'Enqueue assets', |
| 1521 | 'name' => 'enqueue_assets', |
| 1522 | 'type' => 'text', |
| 1523 | 'instructions' => '(Callable) (Optional) A callback function that runs whenever your block is displayed (front-end and back-end) and enqueues scripts and/or styles.', |
| 1524 | 'required' => 0, |
| 1525 | 'conditional_logic' => 0, |
| 1526 | 'wrapper' => array( |
| 1527 | 'width' => '', |
| 1528 | 'class' => '', |
| 1529 | 'id' => '', |
| 1530 | ), |
| 1531 | 'acfe_validate' => '', |
| 1532 | 'acfe_update' => '', |
| 1533 | 'acfe_permissions' => '', |
| 1534 | 'default_value' => '', |
| 1535 | 'placeholder' => '', |
| 1536 | 'prepend' => '', |
| 1537 | 'append' => '', |
| 1538 | 'maxlength' => '', |
| 1539 | ), |
| 1540 | array( |
| 1541 | 'key' => 'field_acfe_dbt_tab_supports', |
| 1542 | 'label' => 'Supports', |
| 1543 | 'name' => '', |
| 1544 | 'type' => 'tab', |
| 1545 | 'instructions' => '', |
| 1546 | 'required' => 0, |
| 1547 | 'conditional_logic' => 0, |
| 1548 | 'wrapper' => array( |
| 1549 | 'width' => '', |
| 1550 | 'class' => '', |
| 1551 | 'id' => '', |
| 1552 | ), |
| 1553 | 'acfe_validate' => '', |
| 1554 | 'acfe_update' => '', |
| 1555 | 'acfe_permissions' => '', |
| 1556 | 'placement' => 'top', |
| 1557 | 'endpoint' => 0, |
| 1558 | ), |
| 1559 | array( |
| 1560 | 'key' => 'field_acfe_dbt_supports_align', |
| 1561 | 'label' => 'Align', |
| 1562 | 'name' => 'supports_align', |
| 1563 | 'type' => 'true_false', |
| 1564 | 'instructions' => 'This property adds block controls which allow the user to change the block’s alignment. Defaults to true. Set to false to hide the alignment toolbar. Set to an array of specific alignment names to customize the toolbar.', |
| 1565 | 'required' => 0, |
| 1566 | 'conditional_logic' => 0, |
| 1567 | 'wrapper' => array( |
| 1568 | 'width' => '', |
| 1569 | 'class' => '', |
| 1570 | 'id' => '', |
| 1571 | ), |
| 1572 | 'acfe_validate' => '', |
| 1573 | 'acfe_update' => '', |
| 1574 | 'acfe_permissions' => '', |
| 1575 | 'message' => '', |
| 1576 | 'default_value' => 1, |
| 1577 | 'ui' => 1, |
| 1578 | 'ui_on_text' => 'True', |
| 1579 | 'ui_off_text' => 'False', |
| 1580 | ), |
| 1581 | array( |
| 1582 | 'key' => 'field_acfe_dbt_supports_align_args', |
| 1583 | 'label' => 'Align arguments', |
| 1584 | 'name' => 'supports_align_args', |
| 1585 | 'type' => 'textarea', |
| 1586 | 'instructions' => 'Set to an array of specific alignment names to customize the toolbar.<br /> |
| 1587 | One line for each name. ie:<br /><br /> |
| 1588 | left<br /> |
| 1589 | right<br /> |
| 1590 | full', |
| 1591 | 'required' => 0, |
| 1592 | 'conditional_logic' => array( |
| 1593 | array( |
| 1594 | array( |
| 1595 | 'field' => 'field_acfe_dbt_supports_align', |
| 1596 | 'operator' => '==', |
| 1597 | 'value' => '1', |
| 1598 | ), |
| 1599 | ), |
| 1600 | ), |
| 1601 | 'wrapper' => array( |
| 1602 | 'width' => '', |
| 1603 | 'class' => '', |
| 1604 | 'id' => '', |
| 1605 | ), |
| 1606 | 'acfe_validate' => '', |
| 1607 | 'acfe_update' => '', |
| 1608 | 'acfe_permissions' => '', |
| 1609 | 'default_value' => '', |
| 1610 | 'placeholder' => '', |
| 1611 | 'maxlength' => '', |
| 1612 | 'rows' => '', |
| 1613 | 'new_lines' => '', |
| 1614 | ), |
| 1615 | |
| 1616 | array( |
| 1617 | 'key' => 'field_acfe_dbt_supports_anchor', |
| 1618 | 'label' => 'Anchor', |
| 1619 | 'name' => 'supports_anchor', |
| 1620 | 'type' => 'true_false', |
| 1621 | 'instructions' => '', |
| 1622 | 'required' => 0, |
| 1623 | 'conditional_logic' => 0, |
| 1624 | 'wrapper' => array( |
| 1625 | 'width' => '', |
| 1626 | 'class' => '', |
| 1627 | 'id' => '', |
| 1628 | ), |
| 1629 | 'acfe_validate' => '', |
| 1630 | 'acfe_update' => '', |
| 1631 | 'acfe_permissions' => '', |
| 1632 | 'message' => '', |
| 1633 | 'default_value' => 0, |
| 1634 | 'ui' => 1, |
| 1635 | 'ui_on_text' => 'True', |
| 1636 | 'ui_off_text' => 'False', |
| 1637 | ), |
| 1638 | |
| 1639 | $experimental_jsx, |
| 1640 | |
| 1641 | $supports_align_content, |
| 1642 | |
| 1643 | $align_content, |
| 1644 | |
| 1645 | array( |
| 1646 | 'key' => 'field_acfe_dbt_supports_mode', |
| 1647 | 'label' => 'Mode', |
| 1648 | 'name' => 'supports_mode', |
| 1649 | 'type' => 'true_false', |
| 1650 | 'instructions' => 'This property allows the user to toggle between edit and preview modes via a button. Defaults to true.', |
| 1651 | 'required' => 0, |
| 1652 | 'conditional_logic' => 0, |
| 1653 | 'wrapper' => array( |
| 1654 | 'width' => '', |
| 1655 | 'class' => '', |
| 1656 | 'id' => '', |
| 1657 | ), |
| 1658 | 'acfe_validate' => '', |
| 1659 | 'acfe_update' => '', |
| 1660 | 'acfe_permissions' => '', |
| 1661 | 'message' => '', |
| 1662 | 'default_value' => 1, |
| 1663 | 'ui' => 1, |
| 1664 | 'ui_on_text' => 'True', |
| 1665 | 'ui_off_text' => 'False', |
| 1666 | ), |
| 1667 | array( |
| 1668 | 'key' => 'field_acfe_dbt_supports_multiple', |
| 1669 | 'label' => 'Multiple', |
| 1670 | 'name' => 'supports_multiple', |
| 1671 | 'type' => 'true_false', |
| 1672 | 'instructions' => 'This property allows the block to be added multiple times. Defaults to true.', |
| 1673 | 'required' => 0, |
| 1674 | 'conditional_logic' => 0, |
| 1675 | 'wrapper' => array( |
| 1676 | 'width' => '', |
| 1677 | 'class' => '', |
| 1678 | 'id' => '', |
| 1679 | ), |
| 1680 | 'acfe_validate' => '', |
| 1681 | 'acfe_update' => '', |
| 1682 | 'acfe_permissions' => '', |
| 1683 | 'message' => '', |
| 1684 | 'default_value' => 1, |
| 1685 | 'ui' => 1, |
| 1686 | 'ui_on_text' => 'True', |
| 1687 | 'ui_off_text' => 'False', |
| 1688 | ), |
| 1689 | ), |
| 1690 | )); |
| 1691 | |
| 1692 | } |
| 1693 | |
| 1694 | } |
| 1695 | |
| 1696 | acf_new_instance('acfe_dynamic_block_types'); |
| 1697 | |
| 1698 | endif; |