diff --git src/wp-includes/media.php src/wp-includes/media.php
index 1981f3ad9a..68be78f25d 100644
|
|
function gallery_shortcode( $attr ) { |
1666 | 1666 | $atts = shortcode_atts( array( |
1667 | 1667 | 'order' => 'ASC', |
1668 | 1668 | 'orderby' => 'menu_order ID', |
1669 | | 'id' => $post ? $post->ID : 0, |
| 1669 | 'id' => null, |
1670 | 1670 | 'itemtag' => $html5 ? 'figure' : 'dl', |
1671 | 1671 | 'icontag' => $html5 ? 'div' : 'dt', |
1672 | 1672 | 'captiontag' => $html5 ? 'figcaption' : 'dd', |
… |
… |
function gallery_shortcode( $attr ) { |
1677 | 1677 | 'link' => '' |
1678 | 1678 | ), $attr, 'gallery' ); |
1679 | 1679 | |
1680 | | $id = intval( $atts['id'] ); |
| 1680 | if ( null !== $atts['id'] ) { |
| 1681 | $id = intval( $atts['id'] ); |
| 1682 | } else { |
| 1683 | $id = $post ? intval( $post->ID ) : null; |
| 1684 | } |
1681 | 1685 | |
1682 | 1686 | if ( ! empty( $atts['include'] ) ) { |
1683 | 1687 | $_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); |
… |
… |
function gallery_shortcode( $attr ) { |
1686 | 1690 | foreach ( $_attachments as $key => $val ) { |
1687 | 1691 | $attachments[$val->ID] = $_attachments[$key]; |
1688 | 1692 | } |
1689 | | } elseif ( ! empty( $atts['exclude'] ) ) { |
1690 | | $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); |
1691 | | } else { |
1692 | | $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); |
| 1693 | } elseif ( null !== $id ) { |
| 1694 | if ( ! empty( $atts['exclude'] ) ) { |
| 1695 | $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); |
| 1696 | } else { |
| 1697 | $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); |
| 1698 | } |
1693 | 1699 | } |
1694 | 1700 | |
1695 | 1701 | if ( empty( $attachments ) ) { |
diff --git src/wp-includes/widgets/class-wp-widget-custom-html.php src/wp-includes/widgets/class-wp-widget-custom-html.php
index 855c3c5895..758e08c3ba 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 | // Override global $post so filters (and shortcodes) apply in a consistent context. |
| 97 | $original_post = $post; |
| 98 | if ( is_singular() ) { |
| 99 | // Make sure post is always the queried object on singular queries (not from another sub-query that failed to clean up the global $post). |
| 100 | $post = get_queried_object(); |
| 101 | } else { |
| 102 | // Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context on archive queries. |
| 103 | $post = null; |
| 104 | } |
93 | 105 | |
94 | 106 | $instance = array_merge( $this->default_instance, $instance ); |
95 | 107 | |
… |
… |
class WP_Widget_Custom_HTML extends WP_Widget { |
118 | 130 | */ |
119 | 131 | $content = apply_filters( 'widget_custom_html_content', $content, $instance, $this ); |
120 | 132 | |
| 133 | // Restore post global. |
| 134 | $post = $original_post; |
| 135 | |
121 | 136 | // Inject the Text widget's container class name alongside this widget's class name for theme styling compatibility. |
122 | 137 | $args['before_widget'] = preg_replace( '/(?<=\sclass=["\'])/', 'widget_text ', $args['before_widget'] ); |
123 | 138 | |
diff --git src/wp-includes/widgets/class-wp-widget-text.php src/wp-includes/widgets/class-wp-widget-text.php
index ffcfe0cd09..a6a0b44c23 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. |
225 | | $suspended_post = null; |
226 | | if ( isset( $post ) ) { |
227 | | $suspended_post = $post; |
| 224 | // Override global $post so filters (and shortcodes) apply in a consistent context. |
| 225 | $original_post = $post; |
| 226 | if ( is_singular() ) { |
| 227 | // Make sure post is always the queried object on singular queries (not from another sub-query that failed to clean up the global $post). |
| 228 | $post = get_queried_object(); |
| 229 | } else { |
| 230 | // Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context on archive queries. |
228 | 231 | $post = null; |
229 | 232 | } |
230 | 233 | |
… |
… |
class WP_Widget_Text extends WP_Widget { |
278 | 281 | } |
279 | 282 | |
280 | 283 | // Restore post global. |
281 | | if ( isset( $suspended_post ) ) { |
282 | | $post = $suspended_post; |
283 | | } |
| 284 | $post = $original_post; |
284 | 285 | |
285 | 286 | // Undo suspension of legacy plugin-supplied shortcode handling. |
286 | 287 | if ( $should_suspend_legacy_shortcode_support ) { |