Validate::sanitize_description( null|string $value = null )

Description #

Sanitize description field.

Remove more, encode contents of code and pre tag. Replace square brackets so that shortcode don’t get rendered.

Parameters #

  • $value
    null | string (Optional) String to sanitize. Default value: null

Changelog #

VersionDescription
4.1.8Introduced.

Source #

File: lib/class-validate.php

	public static function sanitize_description( $value = null ) {
		if ( ! empty( $value ) ) {
			/**
			 * Filter called before applying sanitization to a description fields.
			 *
			 * @param string $value Value.
			 * @since 4.1.9
			 */
			$new_value = apply_filters( 'ap_pre_sanitize_description', $value );

			$new_value = str_replace( '<!--more-->', '', $new_value );
			$patt      = get_shortcode_regex();
			$new_value = preg_replace_callback( "/$patt/", array( __CLASS__, 'whitelist_shortcodes' ), $new_value );

			$new_value = preg_replace_callback( '/<pre(.*?)>(.*?)<\/pre>/imsu', array( __CLASS__, 'pre_content' ), $new_value );
			$new_value = preg_replace_callback( '/<code.*?>(.*?)<\/code>/imsu', array( __CLASS__, 'code_content' ), $new_value );

			// Remove multiple new lines.
			$new_value = str_replace( "\r\n", "\n", $new_value );
			$new_value = preg_replace( '/\n\s*\n/', "\n\n", $new_value );

			// Remove single white single space in line.
			$new_value = preg_replace( '/&nbsp;/', "\n", $new_value );

			return $new_value;
		}
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment