Changeset 7763
- Timestamp:
- 10/01/2026 04:50:02 AM (8 days ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
CHANGELOG.md (modified) (1 diff)
-
src/includes/common/blocks.php (modified) (3 diffs)
-
tests/phpunit/testcases/common/block-visibility.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CHANGELOG.md
r7751 r7763 124 124 ### Fixed 125 125 126 - Avoided block editor choice queries when their target script is unavailable. 126 127 - Kept forum exclusions active in topic and reply queries using OR metadata conditions. 127 128 - Corrected topic edit-lock owner detection. -
trunk/src/includes/common/blocks.php
r7755 r7763 130 130 */ 131 131 public function enqueue_block_editor_assets() { 132 133 // Bail if the script receiving this data is unavailable. 134 if ( ! wp_script_is( 'bbp-admin-blocks', 'registered' ) ) { 135 return; 136 } 132 137 133 138 // Localize script data for the block editor (script is loaded via block.json). … … 382 387 $placeholders = implode( ', ', array_fill( 0, count( $statuses ), '%s' ) ); 383 388 $forum_placeholders = implode( ', ', array_fill( 0, count( $forum_ids ), '%d' ) ); 384 $values = array_merge( array( bbp_get_topic_tag_tax_id(), bbp_get_topic_post_type() ), $statuses, $forum_ids , $forum_ids, $forum_ids);389 $values = array_merge( array( bbp_get_topic_tag_tax_id(), bbp_get_topic_post_type() ), $statuses, $forum_ids ); 385 390 $query = "SELECT DISTINCT tt.term_id 386 391 FROM {$bbp_db->term_taxonomy} AS tt … … 390 395 WHERE tt.taxonomy = %s AND p.post_type = %s AND p.post_status IN ({$placeholders}) 391 396 AND p.post_parent IN ({$forum_placeholders}) 392 AND CAST( fm.meta_value AS UNSIGNED ) IN ({$forum_placeholders}) 393 AND NOT EXISTS ( 394 SELECT 1 FROM {$bbp_db->postmeta} AS excluded_fm 395 WHERE excluded_fm.post_id = p.ID AND excluded_fm.meta_key = '_bbp_forum_id' 396 AND CAST( excluded_fm.meta_value AS UNSIGNED ) NOT IN ({$forum_placeholders}) 397 )"; 397 AND CAST( fm.meta_value AS UNSIGNED ) = p.post_parent"; 398 398 $term_ids = $bbp_db->get_col( $bbp_db->prepare( $query, $values ) ); 399 399 -
trunk/tests/phpunit/testcases/common/block-visibility.php
r7708 r7763 9 9 */ 10 10 class BBP_Tests_Common_Block_Visibility extends BBP_UnitTestCase { 11 12 /** 13 * @covers ::BBP_Blocks::enqueue_block_editor_assets 14 */ 15 public function test_editor_choices_only_load_for_registered_admin_script() { 16 $forum_id = $this->factory->forum->create(); 17 $this->factory->topic->create( array( 'post_parent' => $forum_id, 'topic_meta' => array( 'forum_id' => $forum_id ) ) ); 18 $scripts = wp_scripts(); 19 $registered = isset( $scripts->registered['bbp-admin-blocks'] ) ? $scripts->registered['bbp-admin-blocks'] : null; 20 $query_count = 0; 21 $count_query = function( $query ) use ( &$query_count ) { 22 if ( false !== strpos( $query, 'SELECT DISTINCT tt.term_id' ) ) { 23 ++$query_count; 24 } 25 return $query; 26 }; 27 28 wp_deregister_script( 'bbp-admin-blocks' ); 29 add_filter( 'query', $count_query ); 30 31 try { 32 $this->assertNotFalse( has_action( 'enqueue_block_editor_assets', array( bbpress()->blocks, 'enqueue_block_editor_assets' ) ) ); 33 do_action( 'enqueue_block_editor_assets' ); 34 $this->assertSame( 0, $query_count ); 35 $this->assertFalse( $scripts->get_data( 'bbp-admin-blocks', 'data' ) ); 36 37 wp_register_script( 'bbp-admin-blocks', false ); 38 bbpress()->blocks->enqueue_block_editor_assets(); 39 $this->assertGreaterThan( 0, $query_count ); 40 $this->assertStringContainsString( 'bbpBlocksJS', $scripts->get_data( 'bbp-admin-blocks', 'data' ) ); 41 } finally { 42 remove_filter( 'query', $count_query ); 43 wp_deregister_script( 'bbp-admin-blocks' ); 44 if ( null !== $registered ) { 45 $scripts->registered['bbp-admin-blocks'] = $registered; 46 } 47 } 48 } 11 49 12 50 /** … … 121 159 $this->assertContains( 'public-block-tag', $labels ); 122 160 161 delete_post_meta( $public_topic, '_bbp_forum_id' ); 162 $labels = wp_list_pluck( BBP_Blocks::get_localize_script_data( 'topic_tags' ), 'label' ); 163 $this->assertNotContains( 'public-block-tag', $labels ); 164 165 update_post_meta( $public_topic, '_bbp_forum_id', 'not-a-forum' ); 166 $labels = wp_list_pluck( BBP_Blocks::get_localize_script_data( 'topic_tags' ), 'label' ); 167 $this->assertNotContains( 'public-block-tag', $labels ); 168 123 169 wp_update_post( array( 'ID' => $public_topic, 'post_parent' => $private_forum ) ); 124 170 update_post_meta( $public_topic, '_bbp_forum_id', $private_forum );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)