diff --git src/wp-includes/widgets/class-wp-widget-custom-html.php src/wp-includes/widgets/class-wp-widget-custom-html.php
index 855c3c5895..d5fefb90c4 100644
|
|
|
class WP_Widget_Custom_HTML extends WP_Widget { |
| 85 | 85 | * |
| 86 | 86 | * @since 4.8.1 |
| 87 | 87 | * |
| | 88 | * @global WP_Post $post |
| 88 | 89 | * @param array $args Display arguments including 'before_title', 'after_title', |
| 89 | 90 | * 'before_widget', and 'after_widget'. |
| 90 | 91 | * @param array $instance Settings for the current Custom HTML widget instance. |
| 91 | 92 | */ |
| 92 | 93 | public function widget( $args, $instance ) { |
| | 94 | global $post; |
| | 95 | |
| | 96 | // Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context on archive queries. |
| | 97 | $suspended_post = null; |
| | 98 | if ( isset( $post ) ) { |
| | 99 | $suspended_post = $post; |
| | 100 | $post = null; |
| | 101 | } |
| | 102 | |
| | 103 | // Make sure post is always the queried object on singular queries (not from another sub-query that failed to clean up the global $post). |
| | 104 | if ( is_singular() ) { |
| | 105 | $post = get_queried_object(); |
| | 106 | } |
| 93 | 107 | |
| 94 | 108 | $instance = array_merge( $this->default_instance, $instance ); |
| 95 | 109 | |
| … |
… |
class WP_Widget_Custom_HTML extends WP_Widget { |
| 118 | 132 | */ |
| 119 | 133 | $content = apply_filters( 'widget_custom_html_content', $content, $instance, $this ); |
| 120 | 134 | |
| | 135 | // Restore post global. |
| | 136 | if ( isset( $suspended_post ) ) { |
| | 137 | $post = $suspended_post; |
| | 138 | } |
| | 139 | |
| 121 | 140 | // Inject the Text widget's container class name alongside this widget's class name for theme styling compatibility. |
| 122 | 141 | $args['before_widget'] = preg_replace( '/(?<=\sclass=["\'])/', 'widget_text ', $args['before_widget'] ); |
| 123 | 142 | |
diff --git src/wp-includes/widgets/class-wp-widget-text.php src/wp-includes/widgets/class-wp-widget-text.php
index ffcfe0cd09..c9008c0674 100644
|
|
|
class WP_Widget_Text extends WP_Widget { |
| 221 | 221 | remove_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority ); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | | // Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context. |
| | 224 | // Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context on archive queries. |
| 225 | 225 | $suspended_post = null; |
| 226 | 226 | if ( isset( $post ) ) { |
| 227 | 227 | $suspended_post = $post; |
| 228 | 228 | $post = null; |
| 229 | 229 | } |
| 230 | 230 | |
| | 231 | // Make sure post is always the queried object on singular queries (not from another sub-query that failed to clean up the global $post). |
| | 232 | if ( is_singular() ) { |
| | 233 | $post = get_queried_object(); |
| | 234 | } |
| | 235 | |
| 231 | 236 | /** |
| 232 | 237 | * Filters the content of the Text widget. |
| 233 | 238 | * |