$value ) { // Get the setting type (checkbox, select, etc). $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false; if ( $type ) { /** * Field type specific filter. * * @since 1.2.0 * @param array $value Setting value. * @paaram array $key Setting key. */ $input[ $key ] = apply_filters( 'ata_settings_sanitize_' . $type, $value, $key ); } /** * Field type general filter. * * @since 1.2.0 * @paaram array $key Setting key. */ $input[ $key ] = apply_filters( 'ata_settings_sanitize', $input[ $key ], $key ); } // Loop through the whitelist and unset any that are empty for the tab being saved. if ( ! empty( $settings[ $tab ] ) ) { foreach ( $settings[ $tab ] as $key => $value ) { if ( empty( $input[ $key ] ) && ! empty( $ata_settings[ $key ] ) ) { unset( $ata_settings[ $key ] ); } } } // Merge our new settings with the existing. Force (array) in case it is empty. $ata_settings = array_merge( (array) $ata_settings, $input ); add_settings_error( 'ata-notices', '', __( 'Settings updated.', 'add-to-all' ), 'updated' ); return $ata_settings; } /** * Sanitize text fields * * @since 1.2.0 * * @param array $input The field value. * @return string $input Sanitizied value */ function ata_sanitize_text_field( $input ) { return sanitize_text_field( $input ); } add_filter( 'ata_settings_sanitize_text', 'ata_sanitize_text_field' ); /** * Sanitize CSV fields * * @since 1.2.0 * * @param array $input The field value. * @return string $input Sanitizied value */ function ata_sanitize_csv_field( $input ) { return implode( ',', array_map( 'trim', explode( ',', sanitize_text_field( wp_unslash( $input ) ) ) ) ); } add_filter( 'ata_settings_sanitize_csv', 'ata_sanitize_csv_field' ); /** * Sanitize textarea fields * * @since 1.2.0 * * @param array $input The field value. * @return string $input Sanitizied value */ function ata_sanitize_textarea_field( $input ) { global $allowedposttags; // We need more tags to allow for script and style. $moretags = array( 'script' => array( 'type' => true, 'src' => true, ), 'style' => array( 'type' => true, ), ); $allowedatatags = array_merge( $allowedposttags, $moretags ); return wp_kses( wp_unslash( $input ), $allowedatatags ); } add_filter( 'ata_settings_sanitize_textarea', 'ata_sanitize_textarea_field' );