image_align_input_fields

函数
image_align_input_fields ( $post, $checked = '' )
参数
  • (WP_Post) $post
    Required:
  • (string) $checked
    Required:
    Default: (empty)
返回值
  • (string)
定义位置
相关方法
image_link_input_fieldsimage_size_input_fieldsget_plugin_filescomment_id_fieldsget_post_field
引入
2.7.0
弃用
-

image_align_input_fields: 此函数用于为图像创建对齐输入字段。

检索图像对齐单选按钮的HTML,并选中指定的一个。

function image_align_input_fields( $post, $checked = '' ) {

	if ( empty( $checked ) ) {
		$checked = get_user_setting( 'align', 'none' );
	}

	$alignments = array(
		'none'   => __( 'None' ),
		'left'   => __( 'Left' ),
		'center' => __( 'Center' ),
		'right'  => __( 'Right' ),
	);

	if ( ! array_key_exists( (string) $checked, $alignments ) ) {
		$checked = 'none';
	}

	$output = array();

	foreach ( $alignments as $name => $label ) {
		$name     = esc_attr( $name );
		$output[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'" .
			( $checked == $name ? " checked='checked'" : '' ) .
			" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
	}

	return implode( "n", $output );
}

常见问题

FAQs
查看更多 >