On this page
WP_Widget_Media_Gallery::has_content( array $instance ): bool
Whether the widget has content to show.
Parameters
$instancearray Required-
Widget instance props.
Return
bool Whether widget has content.
Source
File: wp-includes/widgets/class-wp-widget-media-gallery.php. View all references
protected function has_content( $instance ) {
if ( ! empty( $instance['ids'] ) ) {
$attachments = wp_parse_id_list( $instance['ids'] );
foreach ( $attachments as $attachment ) {
if ( 'attachment' !== get_post_type( $attachment ) ) {
return false;
}
}
return true;
}
return false;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_parse_id_list() wp-includes/functions.php | Cleans up an array, comma- or space-separated list of IDs. |
| get_post_type() wp-includes/post.php | Retrieves the post type of the current post or of a given post. |
Changelog
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_widget_media_gallery/has_content