wp/wp-includes/blocks/query-no-results.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
     7 
     7 
     8 /**
     8 /**
     9  * Renders the `core/query-no-results` block on the server.
     9  * Renders the `core/query-no-results` block on the server.
       
    10  *
       
    11  * @since 6.0.0
       
    12  *
       
    13  * @global WP_Query $wp_query WordPress Query object.
    10  *
    14  *
    11  * @param array    $attributes Block attributes.
    15  * @param array    $attributes Block attributes.
    12  * @param string   $content    Block default content.
    16  * @param string   $content    Block default content.
    13  * @param WP_Block $block      Block instance.
    17  * @param WP_Block $block      Block instance.
    14  *
    18  *
    30 	} else {
    34 	} else {
    31 		$query_args = build_query_vars_from_query_block( $block, $page );
    35 		$query_args = build_query_vars_from_query_block( $block, $page );
    32 		$query      = new WP_Query( $query_args );
    36 		$query      = new WP_Query( $query_args );
    33 	}
    37 	}
    34 
    38 
    35 	if ( $query->have_posts() ) {
    39 	if ( $query->post_count > 0 ) {
    36 		return '';
    40 		return '';
    37 	}
    41 	}
    38 
    42 
    39 	if ( ! $use_global_query ) {
    43 	$classes            = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : '';
    40 		wp_reset_postdata();
    44 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
    41 	}
       
    42 
       
    43 	return sprintf(
    45 	return sprintf(
    44 		'<div %1$s>%2$s</div>',
    46 		'<div %1$s>%2$s</div>',
    45 		get_block_wrapper_attributes(),
    47 		$wrapper_attributes,
    46 		$content
    48 		$content
    47 	);
    49 	);
    48 }
    50 }
    49 
    51 
    50 /**
    52 /**
    51  * Registers the `core/query-no-results` block on the server.
    53  * Registers the `core/query-no-results` block on the server.
       
    54  *
       
    55  * @since 6.0.0
    52  */
    56  */
    53 function register_block_core_query_no_results() {
    57 function register_block_core_query_no_results() {
    54 	register_block_type_from_metadata(
    58 	register_block_type_from_metadata(
    55 		__DIR__ . '/query-no-results',
    59 		__DIR__ . '/query-no-results',
    56 		array(
    60 		array(