Skip to content

Commit 524eaf0

Browse files
committed
Merge branch 'trunk' into try/php85-tests
2 parents b06109b + 330deca commit 524eaf0

File tree

8 files changed

+154
-5
lines changed

8 files changed

+154
-5
lines changed

src/wp-includes/SimplePie/src/IRI.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function __get(string $name)
170170
$return = null;
171171
}
172172

173-
if ($return === null && isset($this->normalization[$this->scheme][$name])) {
173+
if ($return === null && isset($this->scheme, $this->normalization[$this->scheme][$name])) {
174174
return $this->normalization[$this->scheme][$name];
175175
}
176176

@@ -623,6 +623,10 @@ protected function remove_iunreserved_percent_encoded(array $match)
623623
*/
624624
protected function scheme_normalization()
625625
{
626+
if ($this->scheme === null) {
627+
return;
628+
}
629+
626630
if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) {
627631
$this->iuserinfo = null;
628632
}

src/wp-includes/block-bindings/post-data.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,29 @@ function _block_bindings_post_data_get_value( array $source_args, $block_instanc
2323
return null;
2424
}
2525

26-
if ( empty( $block_instance->context['postId'] ) ) {
26+
/*
27+
* BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks.
28+
* Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE.
29+
*/
30+
$block_name = $block_instance->name ?? '';
31+
$is_navigation_block = in_array(
32+
$block_name,
33+
array( 'core/navigation-link', 'core/navigation-submenu' ),
34+
true
35+
);
36+
37+
if ( $is_navigation_block ) {
38+
// Navigation blocks: read from block attributes.
39+
$post_id = $block_instance->attributes['id'] ?? null;
40+
} else {
41+
// All other blocks: use context.
42+
$post_id = $block_instance->context['postId'] ?? null;
43+
}
44+
45+
// If we don't have an entity ID, bail early.
46+
if ( empty( $post_id ) ) {
2747
return null;
2848
}
29-
$post_id = $block_instance->context['postId'];
3049

3150
// If a post isn't public, we need to prevent unauthorized users from accessing the post data.
3251
$post = get_post( $post_id );
@@ -46,6 +65,11 @@ function _block_bindings_post_data_get_value( array $source_args, $block_instanc
4665
return '';
4766
}
4867
}
68+
69+
if ( 'link' === $source_args['key'] ) {
70+
$permalink = get_permalink( $post_id );
71+
return false === $permalink ? null : esc_url( $permalink );
72+
}
4973
}
5074

5175
/**
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
/**
3+
* Term Data source for Block Bindings.
4+
*
5+
* @since 6.9.0
6+
* @package WordPress
7+
* @subpackage Block Bindings
8+
*/
9+
10+
/**
11+
* Gets value for Term Data source.
12+
*
13+
* @since 6.9.0
14+
* @access private
15+
*
16+
* @param array $source_args Array containing source arguments used to look up the override value.
17+
* Example: array( "key" => "name" ).
18+
* @param WP_Block $block_instance The block instance.
19+
* @return mixed The value computed for the source.
20+
*/
21+
function _block_bindings_term_data_get_value( array $source_args, $block_instance ) {
22+
if ( empty( $source_args['key'] ) ) {
23+
return null;
24+
}
25+
26+
/*
27+
* BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks.
28+
* Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE.
29+
*/
30+
$block_name = $block_instance->name ?? '';
31+
$is_navigation_block = in_array(
32+
$block_name,
33+
array( 'core/navigation-link', 'core/navigation-submenu' ),
34+
true
35+
);
36+
37+
if ( $is_navigation_block ) {
38+
// Navigation blocks: read from block attributes.
39+
$term_id = $block_instance->attributes['id'] ?? null;
40+
$type = $block_instance->attributes['type'] ?? '';
41+
// Map UI shorthand to taxonomy slug when using attributes.
42+
$taxonomy = ( 'tag' === $type ) ? 'post_tag' : $type;
43+
} else {
44+
// All other blocks: use context
45+
$term_id = $block_instance->context['termId'] ?? null;
46+
$taxonomy = $block_instance->context['taxonomy'] ?? '';
47+
}
48+
49+
// If we don't have required identifiers, bail early.
50+
if ( empty( $term_id ) || empty( $taxonomy ) ) {
51+
return null;
52+
}
53+
54+
// Get the term data.
55+
$term = get_term( $term_id, $taxonomy );
56+
if ( is_wp_error( $term ) || ! $term ) {
57+
return null;
58+
}
59+
60+
// Check if taxonomy exists and is publicly queryable.
61+
$taxonomy_object = get_taxonomy( $taxonomy );
62+
if ( ! $taxonomy_object || ! $taxonomy_object->publicly_queryable ) {
63+
if ( ! current_user_can( 'read' ) ) {
64+
return null;
65+
}
66+
}
67+
68+
switch ( $source_args['key'] ) {
69+
case 'id':
70+
return esc_html( (string) $term_id );
71+
72+
case 'name':
73+
return esc_html( $term->name );
74+
75+
case 'link':
76+
// Only taxonomy entities are supported by Term Data.
77+
$term_link = get_term_link( $term );
78+
return is_wp_error( $term_link ) ? null : esc_url( $term_link );
79+
80+
case 'slug':
81+
return esc_html( $term->slug );
82+
83+
case 'description':
84+
return wp_kses_post( $term->description );
85+
86+
case 'parent':
87+
return esc_html( (string) $term->parent );
88+
89+
case 'count':
90+
return esc_html( (string) $term->count );
91+
92+
default:
93+
return null;
94+
}
95+
}
96+
97+
/**
98+
* Registers Term Data source in the block bindings registry.
99+
*
100+
* @since 6.9.0
101+
* @access private
102+
*/
103+
function _register_block_bindings_term_data_source() {
104+
if ( get_block_bindings_source( 'core/term-data' ) ) {
105+
// The source is already registered.
106+
return;
107+
}
108+
109+
register_block_bindings_source(
110+
'core/term-data',
111+
array(
112+
'label' => _x( 'Term Data', 'block bindings source' ),
113+
'get_value_callback' => '_block_bindings_term_data_get_value',
114+
'uses_context' => array( 'termId', 'taxonomy' ),
115+
)
116+
);
117+
}
118+
119+
add_action( 'init', '_register_block_bindings_term_data_source' );

src/wp-includes/template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ function load_template( $_template_file, $load_once = true, $args = array() ) {
828828
* Checks whether the template should be output buffered for enhancement.
829829
*
830830
* By default, an output buffer is only started if a {@see 'wp_template_enhancement_output_buffer'} filter has been
831-
* added be the time a template is included at the {@see 'wp_before_include_template'} action. This allows template
831+
* added by the time a template is included at the {@see 'wp_before_include_template'} action. This allows template
832832
* responses to be streamed as much as possible when no template enhancements are registered to apply.
833833
*
834834
* @since 6.9.0

src/wp-settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@
369369
require ABSPATH . WPINC . '/block-bindings/pattern-overrides.php';
370370
require ABSPATH . WPINC . '/block-bindings/post-data.php';
371371
require ABSPATH . WPINC . '/block-bindings/post-meta.php';
372+
require ABSPATH . WPINC . '/block-bindings/term-data.php';
372373
require ABSPATH . WPINC . '/blocks.php';
373374
require ABSPATH . WPINC . '/blocks/index.php';
374375
require ABSPATH . WPINC . '/block-editor.php';

tests/phpunit/includes/functions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ function _unhook_block_registration() {
350350
remove_action( 'init', '_register_block_bindings_pattern_overrides_source' );
351351
remove_action( 'init', '_register_block_bindings_post_data_source' );
352352
remove_action( 'init', '_register_block_bindings_post_meta_source' );
353+
remove_action( 'init', '_register_block_bindings_term_data_source' );
353354
}
354355
tests_add_filter( 'init', '_unhook_block_registration', 1000 );
355356

tests/phpunit/tests/block-bindings/register.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function test_get_all_registered() {
7575
'core/post-data' => get_block_bindings_source( 'core/post-data' ),
7676
'core/post-meta' => get_block_bindings_source( 'core/post-meta' ),
7777
'core/pattern-overrides' => get_block_bindings_source( 'core/pattern-overrides' ),
78+
'core/term-data' => get_block_bindings_source( 'core/term-data' ),
7879
);
7980

8081
$registered = get_all_registered_block_bindings_sources();

tests/phpunit/tests/template.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ static function ( string $buffer ) use ( &$filter_args ): string {
577577

578578
$p = WP_HTML_Processor::create_full_parser( $buffer );
579579
while ( $p->next_tag() ) {
580-
echo $p->get_tag() . PHP_EOL;
581580
switch ( $p->get_tag() ) {
582581
case 'HTML':
583582
$p->set_attribute( 'lang', 'es' );

0 commit comments

Comments
 (0)