diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
index a196f4ff19..1c7ae718f1 100644
|
|
add_filter( 'widget_text_content', 'capital_P_dangit', 11 ); |
169 | 169 | add_filter( 'widget_text_content', 'wptexturize' ); |
170 | 170 | add_filter( 'widget_text_content', 'convert_smilies', 20 ); |
171 | 171 | add_filter( 'widget_text_content', 'wpautop' ); |
| 172 | add_filter( 'widget_text_content', 'do_shortcode', 11 ); // Runs after wpautop() but note that $post global will be null when shortcodes run. |
172 | 173 | |
173 | 174 | add_filter( 'date_i18n', 'wp_maybe_decline_date' ); |
174 | 175 | |
diff --git src/wp-includes/widgets/class-wp-widget-text.php src/wp-includes/widgets/class-wp-widget-text.php
index a79e0daa6c..ed9d4e995c 100644
|
|
class WP_Widget_Text extends WP_Widget { |
183 | 183 | * |
184 | 184 | * @since 2.8.0 |
185 | 185 | * |
| 186 | * @global WP_Post $post |
| 187 | * |
186 | 188 | * @param array $args Display arguments including 'before_title', 'after_title', |
187 | 189 | * 'before_widget', and 'after_widget'. |
188 | 190 | * @param array $instance Settings for the current Text widget instance. |
189 | 191 | */ |
190 | 192 | public function widget( $args, $instance ) { |
| 193 | global $post; |
191 | 194 | |
192 | 195 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
193 | 196 | $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
… |
… |
class WP_Widget_Text extends WP_Widget { |
211 | 214 | * added by the shortcode. |
212 | 215 | */ |
213 | 216 | $widget_text_do_shortcode_priority = has_filter( 'widget_text', 'do_shortcode' ); |
| 217 | $has_widget_text_content_shortcode_filter = has_filter( 'widget_text_content', 'do_shortcode' ); |
214 | 218 | $should_upgrade_shortcode_handling = ( $is_visual_text_widget && false !== $widget_text_do_shortcode_priority ); |
215 | 219 | if ( $should_upgrade_shortcode_handling ) { |
216 | 220 | remove_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority ); |
217 | | add_filter( 'widget_text_content', 'do_shortcode', 11 ); |
| 221 | if ( ! $has_widget_text_content_shortcode_filter ) { |
| 222 | add_filter( 'widget_text_content', 'do_shortcode', 11 ); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context. |
| 227 | $suspended_post = null; |
| 228 | if ( isset( $post ) ) { |
| 229 | $suspended_post = $post; |
| 230 | $post = null; |
218 | 231 | } |
219 | 232 | |
220 | 233 | /** |
… |
… |
class WP_Widget_Text extends WP_Widget { |
249 | 262 | $text = wpautop( $text ); // Back-compat for instances prior to 4.8. |
250 | 263 | } |
251 | 264 | |
| 265 | if ( isset( $suspended_post ) ) { |
| 266 | $post = $suspended_post; |
| 267 | } |
| 268 | |
252 | 269 | // Undo temporary upgrade of the plugin-supplied shortcode handling. |
253 | 270 | if ( $should_upgrade_shortcode_handling ) { |
254 | 271 | remove_filter( 'widget_text_content', 'do_shortcode', 11 ); |
255 | | add_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority ); |
| 272 | |
| 273 | if ( ! $has_widget_text_content_shortcode_filter ) { |
| 274 | add_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority ); |
| 275 | } |
256 | 276 | } |
257 | 277 | |
258 | 278 | echo $args['before_widget']; |