W3cubDocs

/WordPress

WP_Widget_Media_Gallery::has_content( array $instance ): bool

Whether the widget has content to show.

Parameters

$instancearrayrequired
Widget instance props.

Return

bool Whether widget has content.

Source

protected function has_content( $instance ) {
	if ( ! empty( $instance['ids'] ) ) {
		$attachments = wp_parse_id_list( $instance['ids'] );
		// Prime attachment post caches.
		_prime_post_caches( $attachments, false, false );
		foreach ( $attachments as $attachment ) {
			if ( 'attachment' !== get_post_type( $attachment ) ) {
				return false;
			}
		}
		return true;
	}
	return false;
}

Changelog

Version Description
4.9.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_widget_media_gallery/has_content