WP_Widget_Media::display_media_state() WordPress Method

The WP_Widget_Media::display_media_state() method is used to output the state of a widget for a specific media type. This is useful for displaying an error message if a user tries to upload an unsupported file type, for example.

WP_Widget_Media::display_media_state( array $states, WP_Post $post = null ) #

Filters the default media display states for items in the Media list table.


Parameters

$states

(array)(Required)An array of media states.

$post

(WP_Post)(Optional)The current attachment object.

Default value: null


Top ↑

Return

(array)


Top ↑

Source

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

	public function display_media_state( $states, $post = null ) {
		if ( ! $post ) {
			$post = get_post();
		}

		// Count how many times this attachment is used in widgets.
		$use_count = 0;
		foreach ( $this->get_settings() as $instance ) {
			if ( isset( $instance['attachment_id'] ) && $instance['attachment_id'] === $post->ID ) {
				$use_count++;
			}
		}

		if ( 1 === $use_count ) {
			$states[] = $this->l10n['media_library_state_single'];
		} elseif ( $use_count > 0 ) {
			$states[] = sprintf( translate_nooped_plural( $this->l10n['media_library_state_multi'], $use_count ), number_format_i18n( $use_count ) );
		}

		return $states;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.8.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.