PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / trunk
Gutenify – Visual Site Builder Blocks & Starter Templates vtrunk
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / core / dist / blocks / term-thumbnail / index.php

index.php in Gutenify – Visual Site Builder Blocks & Starter Templates trunk, at core/dist/blocks/term-thumbnail/index.php

64 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Term Thumbnail Block
4 *
5 * @package gutenify
6 */
7
8 namespace gutenify\Blocks\Term_Thumbnail;
9
10 defined( 'ABSPATH' ) || exit;
11
12 class Term_Thumbnail {
13
14 /**
15 * Init function.
16 */
17 public static function init() {
18 add_action( 'init', array( __CLASS__, 'register_block' ) );
19 add_action( 'init', array( __CLASS__, 'register_term_meta' ) );
20 }
21
22 /**
23 * Exposes the `thumbnail_id` term meta convention this block already
24 * reads (see render.php) over the REST API, for any taxonomy.
25 *
26 * Without this, `GET /wp/v2/<taxonomy>/<id>` returns an empty `meta`
27 * object regardless of whether term meta exists — WordPress never
28 * exposes a meta key over REST unless it's explicitly registered with
29 * `show_in_rest`, confirmed live against this site's own
30 * `product_cat` terms. That silently blocked the block editor's own
31 * Focal Point picker (edit.js) from ever finding a real image to show
32 * a preview against, since it has no other way to resolve "this
33 * term's thumbnail" client-side.
34 */
35 public static function register_term_meta() {
36 register_term_meta(
37 '',
38 'thumbnail_id',
39 array(
40 'type' => 'integer',
41 'single' => true,
42 'show_in_rest' => true,
43 )
44 );
45 }
46
47 /**
48 * Register the block.
49 *
50 * block.json's `render` field wires render.php as the render callback
51 * automatically. Unlike category-list/single-product-gallery, this
52 * block is registered unconditionally (not gated behind WooCommerce or
53 * WP_DEBUG) — it works for any taxonomy that happens to store a
54 * thumbnail under the `thumbnail_id` term meta key, and render.php
55 * itself only reaches into WooCommerce for its own placeholder-image
56 * fallback when the taxonomy is `product_cat`.
57 */
58 public static function register_block() {
59 register_block_type( __DIR__ );
60 }
61 }
62
63 Term_Thumbnail::init();
64