WP_Customize_Manager::_sanitize_background_setting( string $value, WP_Customize_Setting $setting ): string|WP_Error

In this article

Callback for validating a background setting value.

Parameters

$valuestringrequired
Repeat value.
$settingWP_Customize_Settingrequired
Setting.

Return

string|WP_Error Background value or validation error.

Source

public function _sanitize_background_setting( $value, $setting ) {
	if ( 'background_repeat' === $setting->id ) {
		if ( ! in_array( $value, array( 'repeat-x', 'repeat-y', 'repeat', 'no-repeat' ), true ) ) {
			return new WP_Error( 'invalid_value', __( 'Invalid value for background repeat.' ) );
		}
	} elseif ( 'background_attachment' === $setting->id ) {
		if ( ! in_array( $value, array( 'fixed', 'scroll' ), true ) ) {
			return new WP_Error( 'invalid_value', __( 'Invalid value for background attachment.' ) );
		}
	} elseif ( 'background_position_x' === $setting->id ) {
		if ( ! in_array( $value, array( 'left', 'center', 'right' ), true ) ) {
			return new WP_Error( 'invalid_value', __( 'Invalid value for background position X.' ) );
		}
	} elseif ( 'background_position_y' === $setting->id ) {
		if ( ! in_array( $value, array( 'top', 'center', 'bottom' ), true ) ) {
			return new WP_Error( 'invalid_value', __( 'Invalid value for background position Y.' ) );
		}
	} elseif ( 'background_size' === $setting->id ) {
		if ( ! in_array( $value, array( 'auto', 'contain', 'cover' ), true ) ) {
			return new WP_Error( 'invalid_value', __( 'Invalid value for background size.' ) );
		}
	} elseif ( 'background_preset' === $setting->id ) {
		if ( ! in_array( $value, array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) {
			return new WP_Error( 'invalid_value', __( 'Invalid value for background size.' ) );
		}
	} elseif ( 'background_image' === $setting->id || 'background_image_thumb' === $setting->id ) {
		$value = empty( $value ) ? '' : sanitize_url( $value );
	} else {
		return new WP_Error( 'unrecognized_setting', __( 'Unrecognized background setting.' ) );
	}
	return $value;
}

Changelog

VersionDescription
4.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.