postbox_classes

函数
postbox_classes ( $box_id, $screen_id )
参数
  • (string) $box_id Meta box ID (used in the 'id' attribute for the meta box).
    Required:
  • (string) $screen_id The screen on which the meta box is shown.
    Required:
返回值
  • (string) Space-separated string of class names.
定义位置
相关方法
post_classget_post_classbody_classget_body_classsticky_class
引入
2.5.0
弃用
-

postbox_classes函数是WordPress的一个函数,用来生成文章编辑界面上的文章框的CSS类。它接受一个单一的参数,也就是邮筒的名称: 该函数返回一个CSS类的数组,这些类可以用来为邮筒设置样式。

返回元组框所使用的类别列表。

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

常见问题

FAQs
查看更多 >