PluginProbe
Gutenberg / 14.5.2
Gutenberg v14.5.2
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | build/block-library/blocks/post-terms.php +50 -2 12.6.0 → 14.5.2 View file →
@@ -35,14 +35,24 @@
35 35 $separator = empty( $attributes['separator'] ) ? ' ' : $attributes['separator'];
36 36
37 37 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
38 38
39 + $prefix = "<div $wrapper_attributes>";
40 + if ( isset( $attributes['prefix'] ) && $attributes['prefix'] ) {
41 + $prefix .= '<span class="wp-block-post-terms__prefix">' . $attributes['prefix'] . '</span>';
42 + }
43 +
44 + $suffix = '</div>';
45 + if ( isset( $attributes['suffix'] ) && $attributes['suffix'] ) {
46 + $suffix = '<span class="wp-block-post-terms__suffix">' . $attributes['suffix'] . '</span>' . $suffix;
47 + }
48 +
39 49 return get_the_term_list(
40 50 $block->context['postId'],
41 51 $attributes['term'],
42 - "<div $wrapper_attributes>",
52 + wp_kses_post( $prefix ),
43 53 '<span class="wp-block-post-terms__separator">' . esc_html( $separator ) . '</span>',
44 - '</div>'
54 + wp_kses_post( $suffix )
45 55 );
46 56 }
47 57
48 58 /**
@@ -48,12 +58,50 @@
48 58 /**
49 59 * Registers the `core/post-terms` block on the server.
50 60 */
51 61 function gutenberg_register_block_core_post_terms() {
62 + $taxonomies = get_taxonomies(
63 + array(
64 + 'public' => true,
65 + 'show_in_rest' => true,
66 + ),
67 + 'objects'
68 + );
69 +
70 + // Split the available taxonomies to `built_in` and custom ones,
71 + // in order to prioritize the `built_in` taxonomies at the
72 + // search results.
73 + $built_ins = array();
74 + $custom_variations = array();
75 +
76 + // Create and register the eligible taxonomies variations.
77 + foreach ( $taxonomies as $taxonomy ) {
78 + $variation = array(
79 + 'name' => $taxonomy->name,
80 + 'title' => $taxonomy->label,
81 + /* translators: %s: taxonomy's label */
82 + 'description' => sprintf( __( 'Display the assigned taxonomy: %s' ), $taxonomy->label ),
83 + 'attributes' => array(
84 + 'term' => $taxonomy->name,
85 + ),
86 + 'isActive' => array( 'term' ),
87 + );
88 + // Set the category variation as the default one.
89 + if ( 'category' === $taxonomy->name ) {
90 + $variation['isDefault'] = true;
91 + }
92 + if ( $taxonomy->_builtin ) {
93 + $built_ins[] = $variation;
94 + } else {
95 + $custom_variations[] = $variation;
96 + }
97 + }
98 +
52 99 register_block_type_from_metadata(
53 100 __DIR__ . '/post-terms',
54 101 array(
55 102 'render_callback' => 'gutenberg_render_block_core_post_terms',
103 + 'variations' => array_merge( $built_ins, $custom_variations ),
56 104 )
57 105 );
58 106 }
59 107 add_action( 'init', 'gutenberg_register_block_core_post_terms', 20 );