postbox_classes() WordPress Function

The postbox_classes() function is used to add classes to postboxes on the WordPress admin pages. It is used to add classes to postboxes on the WordPress admin pages. By default, it adds the 'postbox' class to every postbox.

postbox_classes( string $box_id, string $screen_id ) #

Returns the list of classes to be used by a meta box.


Parameters

$box_id

(string)(Required)Meta box ID (used in the 'id' attribute for the meta box).

$screen_id

(string)(Required)The screen on which the meta box is shown.


Top ↑

Return

(string) Space-separated string of class names.


Top ↑

Source

File: wp-admin/includes/post.php

function postbox_classes( $box_id, $screen_id ) {
	if ( isset( $_GET['edit'] ) && $_GET['edit'] == $box_id ) {
		$classes = array( '' );
	} elseif ( get_user_option( 'closedpostboxes_' . $screen_id ) ) {
		$closed = get_user_option( 'closedpostboxes_' . $screen_id );
		if ( ! is_array( $closed ) ) {
			$classes = array( '' );
		} else {
			$classes = in_array( $box_id, $closed, true ) ? array( 'closed' ) : array( '' );
		}
	} else {
		$classes = array( '' );
	}

	/**
	 * Filters the postbox classes for a specific screen and box ID combo.
	 *
	 * The dynamic portions of the hook name, `$screen_id` and `$box_id`, refer to
	 * the screen ID and meta box ID, respectively.
	 *
	 * @since 3.2.0
	 *
	 * @param string[] $classes An array of postbox classes.
	 */
	$classes = apply_filters( "postbox_classes_{$screen_id}_{$box_id}", $classes );

	return implode( ' ', $classes );
}


Top ↑

Changelog

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

Show More