GC_Customize_Nav_Menu_Setting::sanitize()
最后更新于:2021-11-27 06:23:18
GC_Customize_Nav_Menu_Setting::sanitize( array$value)Sanitize an input.
参数
- $value
-
(array) (Required) The value to sanitize.
响应
(array|false|null) Null if an input isn’t valid. False if it is marked for deletion. Otherwise the sanitized value.
源文件
文件: gc-includes/customize/class-gc-customize-nav-menu-setting.php
public function sanitize( $value ) {
// Menu is marked for deletion.
if ( false === $value ) {
return $value;
}
// Invalid.
if ( ! is_array( $value ) ) {
return null;
}
$default = array(
'name' => '',
'description' => '',
'parent' => 0,
'auto_add' => false,
);
$value = array_merge( $default, $value );
$value = gc_array_slice_assoc( $value, array_keys( $default ) );
$value['name'] = trim( esc_html( $value['name'] ) ); // This sanitization code is used in gc-admin/nav-menus.php.
$value['description'] = sanitize_text_field( $value['description'] );
$value['parent'] = max( 0, (int) $value['parent'] );
$value['auto_add'] = ! empty( $value['auto_add'] );
if ( '' === $value['name'] ) {
$value['name'] = _x( '(unnamed)', 'Missing menu name.' );
}
/** This filter is documented in gc-includes/class-gc-customize-setting.php */
return apply_filters( "customize_sanitize_{$this->id}", $value, $this );
}