Title: Sanitize Data Description: Sanitize many data types like textarea, attribute, url and more.
Never trust user input. Input that is not malicious could be malformed and break your site. The Sanitize
class can help protect your site from bad data.
Remove all blocked tags defined by WordPress like <script>
.
$filtered = \TypeRocket\Utility\Sanitize::textarea( $value );
Do not filter the value.
$filtered = \TypeRocket\Utility\Sanitize::raw( $value );
Escape the value for use in an HTML attribute.
$filtered = \TypeRocket\Utility\Sanitize::attribute( $value );
Escape the URL.
$filtered = \TypeRocket\Utility\Sanitize::url( $value );
Escape SQL for a query.
$filtered = \TypeRocket\Utility\Sanitize::sql( $value );
Remove all HTML tags.
$filtered = \TypeRocket\Utility\Sanitize::plaintext( $value );
Filter HTML tags based on user capabilities. For example, an administrator with the capability unfiltered_html
will be allowed to enter raw data. Other users will be restricted like when using the WordPress Editor.
$filtered = \TypeRocket\Utility\Sanitize::editor( $value , $force_filter, $auto_p);
Escape a hexadecimal value like #FFFFFF
.
$filtered = \TypeRocket\Utility\Sanitize::hex( $value );
Remove all special characters and replace spaces and dashes with underscores allowing only a single underscore after trimming whitespace form string and lower casing.
$value = 'First Name';
echo \TypeRocket\Utility\Sanitize::underscore( $value );
Will output,
first_name
Remove all special characters and replace spaces and underscores with dashes allowing only a single dash after trimming whitespace form string and lower casing.
$value = 'First Name';
echo \TypeRocket\Utility\Sanitize::dash( $value );
Will output,
first-name