for metabox.
*
* @param array $field_args Array of field arguments.
* @param CMB2_Field $field The field object.
*
* @return CMB2_Field
*/
public static function render_meta_tab_container_open( $field_args, $field ) {
echo '';
return $field;
}
/**
* Render tab content opening
and closing
.
*
* @param array $field_args Array of field arguments.
* @param CMB2_Field $field The field object.
*
* @return CMB2_Field
*/
public static function render_tab( $field_args, $field ) {
printf(
true === $field->prop( 'open' ) ? '
' : '
',
esc_attr( $field->prop( 'id' ) )
);
return $field;
}
/**
* Handles sanitization for HTML entities.
*
* @param mixed $value The unsanitized value from the form.
*
* @return mixed Sanitized value to be stored.
*/
public static function sanitize_htmlentities( $value ) {
return htmlentities( $value, ENT_COMPAT, get_option( 'blog_charset' ) );
}
/**
* Handles sanitization for Separator Character option.
*
* @param mixed $value The unsanitized value from the form.
*
* @return mixed Sanitized value to be stored.
*/
public static function sanitize_separator( $value ) {
return htmlentities( wp_strip_all_tags( $value, true ) );
}
/**
* Handles sanitization for text fields.
*
* @param string $value The unsanitized value from the form.
*
* @return string Sanitized value to be stored.
*/
public static function sanitize_textfield( $value ) {
if ( is_object( $value ) || is_array( $value ) ) {
return '';
}
$value = (string) $value;
$filtered = wp_check_invalid_utf8( $value );
if ( strpos( $filtered, '<' ) !== false ) {
$filtered = wp_pre_kses_less_than( $filtered );
// Strip extra whitespace.
$filtered = wp_strip_all_tags( $filtered, false );
// Use html entities in a special case to make sure no later
// newline stripping stage could lead to a functional tag!
$filtered = str_replace( "<\n", "<\n", $filtered );
}
$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
$filtered = trim( $filtered );
$found = false;
while ( preg_match( '/%[0-9]{2}/i', $filtered, $match ) ) {
$filtered = str_replace( $match[0], '', $filtered );
$found = true;
}
if ( $found ) {
// Strip out the whitespace that may now exist after removing the octets.
$filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
}
return apply_filters( 'sanitize_text_field', $filtered, $value );
}
/**
* Handles sanitization of rank_math_permalink.
*
* @param string $value The unsanitized value from the form.
*
* @return string Sanitized value to be stored.
*/
public static function sanitize_permalink( $value ) {
if ( empty( $value ) ) {
return '';
}
return sanitize_title( $value );
}
/**
* Handles escaping of rank_math_permalink.
*
* @param string $value The value from the DB.
*
* @return string Escaped value.
*/
public static function escape_permalink( $value ) {
if ( empty( $value ) ) {
return '';
}
return esc_attr( urldecode( $value ) );
}
/**
* Handles sanitization of floating point values.
*
* @param string $value The unsanitized value from the form.
*
* @return string Sanitized value to be stored.
*/
public static function sanitize_float( $value ) {
if ( empty( $value ) ) {
return 0;
}
return filter_var( $value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
}
/**
* Handles sanitization for webmaster tag and remove
tag.
*
* @param mixed $value The unsanitized value from the form.
*
* @return mixed Sanitized value to be stored.
*/
public static function sanitize_webmaster_tags( $value ) {
$value = trim( $value );
if ( ! empty( $value ) && Str::starts_with( '
tags are allowed.
*
* @param mixed $value The unsanitized value from the form.
*/
public static function sanitize_custom_webmaster_tags( $value ) {
$sanitized = wp_kses(
$value,
[
'meta' => [
'name' => [],
'content' => [],
],
]
);
return $sanitized;
}
/**
* Handles sanitization of advanced robots data.
*
* @param array $robots The unsanitized value from the form.
*
* @return array Sanitized value to be stored.
*/
public static function sanitize_advanced_robots( $robots ) {
if ( empty( $robots ) ) {
return [];
}
$advanced_robots = [];
foreach ( $robots as $key => $robot ) {
$advanced_robots[ $key ] = ! empty( $robot['enable'] ) ? $robot['length'] : false;
}
return $advanced_robots;
}
/**
* Handles sanitization of Focus Keywords.
*
* @param mixed $value The unsanitized focus keywords.
*
* @return string Sanitized focus keywords to be stored.
*/
public static function sanitize_focus_keywords( $value ) {
$values = json_decode( stripslashes( $value ), true );
if ( empty( $values ) ) {
return '';
}
return implode(
',',
array_map(
function ( $entry ) {
return sanitize_text_field( $entry['value'] );
},
$values
)
);
}
/**
* Handles sanitization of Robots text.
*
* @since 1.0.45
*
* @param mixed $value The unsanitized Robots text.
*
* @return string Sanitized Robots text to be stored.
*/
public static function sanitize_robots_text( $value ) {
if ( empty( $value ) ) {
return '';
}
return wp_strip_all_tags( $value );
}
}