WP_Widget_Media_Gallery::has_content() WordPress Method

The WP_Widget_Media_Gallery::has_content() method is used to check if a media gallery widget has any content. This is useful for determining if a gallery widget should be displayed on a page.

WP_Widget_Media_Gallery::has_content( array $instance ) #

Whether the widget has content to show.


Parameters

$instance

(array)(Required)Widget instance props.


Top ↑

Return

(bool) Whether widget has content.


Top ↑

Source

File: wp-includes/widgets/class-wp-widget-media-gallery.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.