Changeset 61111
- Timestamp:
- 11/01/2025 04:44:21 AM (5 days ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-includes/class-wp.php (modified) (1 diff)
-
src/wp-includes/default-filters.php (modified) (1 diff)
-
src/wp-includes/template.php (modified) (5 diffs)
-
tests/phpunit/tests/template.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp.php
r61088 r61111 589 589 * Fires once the requested HTTP headers for caching, content type, etc. have been sent. 590 590 * 591 * The {@see 'wp_ send_late_headers'} action may be used to send headers after rendering the template into an592 * output buffer.591 * The {@see 'wp_finalized_template_enhancement_output_buffer'} action may be used to send 592 * headers after rendering the template into an output buffer. 593 593 * 594 594 * @since 2.1.0 -
trunk/src/wp-includes/default-filters.php
r61089 r61111 424 424 add_action( 'do_robots', 'do_robots' ); 425 425 add_action( 'do_favicon', 'do_favicon' ); 426 add_action( 'wp_before_include_template', 'wp_start_template_enhancement_output_buffer', 1000 ); // Late priority to let `wp_template_enhancement_output_buffer` filters and `wp_ send_late_headers` actions be registered.426 add_action( 'wp_before_include_template', 'wp_start_template_enhancement_output_buffer', 1000 ); // Late priority to let `wp_template_enhancement_output_buffer` filters and `wp_finalized_template_enhancement_output_buffer` actions be registered. 427 427 add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 3 ); 428 428 add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' ); -
trunk/src/wp-includes/template.php
r61088 r61111 845 845 * 846 846 * By default, an output buffer is only started if a {@see 'wp_template_enhancement_output_buffer'} filter has been 847 * added or if a plugin has added a {@see 'wp_ send_late_headers'} action. For this default to apply, either of the848 * hooks must be added by the time the template is included at the {@see 'wp_before_include_template'} action. This849 * allows template responses to be streamed unless the there is code which depends on an output buffer being opened.850 * This filter allows a site to opt in to adding such template enhancement filters later during the rendering of the851 * template.847 * added or if a plugin has added a {@see 'wp_finalized_template_enhancement_output_buffer'} action. For this 848 * default to apply, either of the hooks must be added by the time the template is included at the 849 * {@see 'wp_before_include_template'} action. This allows template responses to be streamed unless the there is 850 * code which depends on an output buffer being opened. This filter allows a site to opt in to adding such template 851 * enhancement filters later during the rendering of the template. 852 852 * 853 853 * @since 6.9.0 … … 855 855 * @param bool $use_output_buffer Whether an output buffer is started. 856 856 */ 857 return (bool) apply_filters( 'wp_should_output_buffer_template_for_enhancement', has_filter( 'wp_template_enhancement_output_buffer' ) || has_action( 'wp_ send_late_headers' ) );857 return (bool) apply_filters( 'wp_should_output_buffer_template_for_enhancement', has_filter( 'wp_template_enhancement_output_buffer' ) || has_action( 'wp_finalized_template_enhancement_output_buffer' ) ); 858 858 } 859 859 … … 960 960 if ( ! $is_html_content_type ) { 961 961 /** This action is documented in wp-includes/template.php */ 962 do_action( 'wp_ send_late_headers', $output );962 do_action( 'wp_finalized_template_enhancement_output_buffer', $output ); 963 963 return $output; 964 964 } … … 976 976 * fully supports HTML5. 977 977 * 978 * Important: Because this filter is applied inside an output buffer callback (i.e. display handler), any callbacks 979 * added to the filter must not attempt to start their own output buffers. Otherwise, PHP will raise a fatal error: 980 * "Cannot use output buffering in output buffering display handlers." 981 * 978 982 * @since 6.9.0 979 983 * … … 984 988 985 989 /** 986 * Fires at the last moment HTTP headers may be sent. 987 * 988 * This happens immediately before the template enhancement output buffer is flushed. This is in contrast with 989 * the {@see 'send_headers'} action which fires after the initial headers have been sent before the template 990 * has begun rendering, and thus does not depend on output buffering. This action does not fire if the "template 991 * enhancement output buffer" was not started. This output buffer is automatically started if this action is added 992 * before {@see wp_start_template_enhancement_output_buffer()} runs at the {@see 'wp_before_include_template'} 993 * action with priority 1000. Before this point, the output buffer will also be started automatically if there was a 990 * Fires after the template enhancement output buffer has been finalized. 991 * 992 * This happens immediately before the template enhancement output buffer is flushed. No output may be printed at 993 * this action. However, HTTP headers may be sent, which makes this action complimentary to the 994 * {@see 'send_headers'} action, in which headers may be sent before the template has started rendering. In 995 * contrast, this `wp_finalized_template_enhancement_output_buffer` action is the possible point at which HTTP 996 * headers can be sent. This action does not fire if the "template enhancement output buffer" was not started. This 997 * output buffer is automatically started if this action is added before 998 * {@see wp_start_template_enhancement_output_buffer()} runs at the {@see 'wp_before_include_template'} action with 999 * priority 1000. Before this point, the output buffer will also be started automatically if there was a 994 1000 * {@see 'wp_template_enhancement_output_buffer'} filter added, or if the 995 1001 * {@see 'wp_should_output_buffer_template_for_enhancement'} filter is made to return `true`. 996 1002 * 1003 * Important: Because this action fires inside an output buffer callback (i.e. display handler), any callbacks added 1004 * to the action must not attempt to start their own output buffers. Otherwise, PHP will raise a fatal error: 1005 * "Cannot use output buffering in output buffering display handlers." 1006 * 997 1007 * @since 6.9.0 998 1008 * 999 * @param string $output Output buffer.1009 * @param string $output Finalized output buffer. 1000 1010 */ 1001 do_action( 'wp_ send_late_headers', $filtered_output );1011 do_action( 'wp_finalized_template_enhancement_output_buffer', $filtered_output ); 1002 1012 1003 1013 return $filtered_output; -
trunk/tests/phpunit/tests/template.php
r61088 r61111 647 647 $mock_action_callback = new MockAction(); 648 648 add_filter( 649 'wp_ send_late_headers',649 'wp_finalized_template_enhancement_output_buffer', 650 650 array( $mock_action_callback, 'action' ), 651 651 10, … … 734 734 $this->assertStringContainsString( '</html>', $processed_output, 'Expected processed output to contain string.' ); 735 735 736 $this->assertSame( 1, did_action( 'wp_ send_late_headers' ), 'Expected the wp_send_late_headersaction to have fired.' );737 $this->assertSame( 1, $mock_action_callback->get_call_count(), 'Expected wp_ send_late_headersaction callback to have been called once.' );736 $this->assertSame( 1, did_action( 'wp_finalized_template_enhancement_output_buffer' ), 'Expected the wp_finalized_template_enhancement_output_buffer action to have fired.' ); 737 $this->assertSame( 1, $mock_action_callback->get_call_count(), 'Expected wp_finalized_template_enhancement_output_buffer action callback to have been called once.' ); 738 738 $action_args = $mock_action_callback->get_args()[0]; 739 $this->assertCount( 1, $action_args, 'Expected the wp_ send_late_headersaction to have been passed only one argument.' );740 $this->assertSame( $processed_output, $action_args[0], 'Expected the arg passed to wp_ send_late_headersto be the same as the processed output buffer.' );739 $this->assertCount( 1, $action_args, 'Expected the wp_finalized_template_enhancement_output_buffer action to have been passed only one argument.' ); 740 $this->assertSame( $processed_output, $action_args[0], 'Expected the arg passed to wp_finalized_template_enhancement_output_buffer to be the same as the processed output buffer.' ); 741 741 } 742 742 … … 773 773 $mock_action_callback = new MockAction(); 774 774 add_filter( 775 'wp_ send_late_headers',775 'wp_finalized_template_enhancement_output_buffer', 776 776 array( $mock_action_callback, 'action' ), 777 777 10, … … 819 819 $this->assertStringContainsString( '<title>Output Buffer Not Processed</title>', $output, 'Expected output buffer to have string since the output buffer was ended with cleaning.' ); 820 820 821 $this->assertSame( 0, did_action( 'wp_ send_late_headers' ), 'Expected the wp_send_late_headersaction to not have fired.' );822 $this->assertSame( 0, $mock_action_callback->get_call_count(), 'Expected wp_ send_late_headersaction callback to have been called once.' );821 $this->assertSame( 0, did_action( 'wp_finalized_template_enhancement_output_buffer' ), 'Expected the wp_finalized_template_enhancement_output_buffer action to not have fired.' ); 822 $this->assertSame( 0, $mock_action_callback->get_call_count(), 'Expected wp_finalized_template_enhancement_output_buffer action callback to have been called once.' ); 823 823 } 824 824 … … 855 855 $mock_action_callback = new MockAction(); 856 856 add_filter( 857 'wp_ send_late_headers',857 'wp_finalized_template_enhancement_output_buffer', 858 858 array( $mock_action_callback, 'action' ), 859 859 10, … … 906 906 $this->assertStringContainsString( '<h1>Template Replaced</h1>', $output, 'Expected output buffer to have string due to replaced template.' ); 907 907 908 $this->assertSame( 1, did_action( 'wp_ send_late_headers' ), 'Expected the wp_send_late_headersaction to have fired.' );909 $this->assertSame( 1, $mock_action_callback->get_call_count(), 'Expected wp_ send_late_headersaction callback to have been called once.' );908 $this->assertSame( 1, did_action( 'wp_finalized_template_enhancement_output_buffer' ), 'Expected the wp_finalized_template_enhancement_output_buffer action to have fired.' ); 909 $this->assertSame( 1, $mock_action_callback->get_call_count(), 'Expected wp_finalized_template_enhancement_output_buffer action callback to have been called once.' ); 910 910 $action_args = $mock_action_callback->get_args()[0]; 911 $this->assertCount( 1, $action_args, 'Expected the wp_ send_late_headersaction to have been passed only one argument.' );912 $this->assertSame( $output, $action_args[0], 'Expected the arg passed to wp_ send_late_headersto be the same as the processed output buffer.' );911 $this->assertCount( 1, $action_args, 'Expected the wp_finalized_template_enhancement_output_buffer action to have been passed only one argument.' ); 912 $this->assertSame( $output, $action_args[0], 'Expected the arg passed to wp_finalized_template_enhancement_output_buffer to be the same as the processed output buffer.' ); 913 913 } 914 914 … … 931 931 $mock_action_callback = new MockAction(); 932 932 add_filter( 933 'wp_ send_late_headers',933 'wp_finalized_template_enhancement_output_buffer', 934 934 array( $mock_action_callback, 'action' ), 935 935 10, … … 971 971 $this->assertSame( $json, $output, 'Expected output to not be processed.' ); 972 972 973 $this->assertSame( 1, did_action( 'wp_ send_late_headers' ), 'Expected the wp_send_late_headersaction to have fired even though the wp_template_enhancement_output_buffer filter did not apply.' );974 $this->assertSame( 1, $mock_action_callback->get_call_count(), 'Expected wp_ send_late_headersaction callback to have been called once.' );973 $this->assertSame( 1, did_action( 'wp_finalized_template_enhancement_output_buffer' ), 'Expected the wp_finalized_template_enhancement_output_buffer action to have fired even though the wp_template_enhancement_output_buffer filter did not apply.' ); 974 $this->assertSame( 1, $mock_action_callback->get_call_count(), 'Expected wp_finalized_template_enhancement_output_buffer action callback to have been called once.' ); 975 975 $action_args = $mock_action_callback->get_args()[0]; 976 $this->assertCount( 1, $action_args, 'Expected the wp_ send_late_headersaction to have been passed only one argument.' );977 $this->assertSame( $output, $action_args[0], 'Expected the arg passed to wp_ send_late_headersto be the same as the processed output buffer.' );976 $this->assertCount( 1, $action_args, 'Expected the wp_finalized_template_enhancement_output_buffer action to have been passed only one argument.' ); 977 $this->assertSame( $output, $action_args[0], 'Expected the arg passed to wp_finalized_template_enhancement_output_buffer to be the same as the processed output buffer.' ); 978 978 } 979 979
Note: See TracChangeset
for help on using the changeset viewer.