Provides a replacement for WP's native stripslashes_deep
function, which, frustratingly, doesn't trim

@param $value
@return array|object|string
348184
public static function trim_stripslashes_deep($value){
        if ( is_array($value) ) {
            $value = array_map(array(get_called_class(), 'trim_stripslashes_deep'), $value);
        } elseif ( is_object($value) ) {
            $vars = get_object_vars( $value );
            foreach ($vars as $key=>$data) {
                $value->{$key} = self::trim_stripslashes_deep( $data );
            }
        } elseif ( is_string( $value ) ) {
            $value = trim(stripslashes($value));
        }
        return $value;
    }
300724
public static function stripSlashes( $value )
    {
        if ( is_string($value) ){
            return stripslashes($value);
        }
        elseif ( is_array($value) ){
            $array = $value;
            foreach( $array as $key => $value ){
                $array[$key] = self::stripSlashes( $value );
            }
            return $array;
        }
        elseif ( is_object($value) ){
            $object = $value;
            $vars = get_object_vars($object);
            foreach( $vars as $key => $value ){
                $object->$key = self::stripSlashes( $value );
            }
            return $object;
        }
        return $value;
    }
1099327
protected static function _stripSlashes($value)
    {
        if (! is_object($value)) {
            $value = is_array($value) ? array_map(array( 'AnRequest', '_stripSlashes' ), $value) : stripslashes($value);
        }

        return $value;
    }
1177991
private static function getListFromString($value)
    {
        if (is_string($value_array = $value)) {
            $value = str_replace([',', ' '], ';', $value);
            $value_array = explode(';', $value);
        }

        if (is_array($value_array)) {
            return array_filter(array_map('trim', $value_array));
        }

        return [];
    }
558915
public function sanitize($value)
    {
        $value = (string) $value;

        // Filter var for XSS and other 'bad' code etc.
        if (!empty ($value)) {
            $value = $this->_remove($this->_decode($value));
        }

        return $value;
    }
1016607
public static function clean_vars($value){
        if(is_array($value)){
            foreach($value as $key => $val) {
                $value[$key] = self::clean_vars($val);
            }
        }
        else{
            $value= self::filter_simple_xss($value);
        }
        return $value;
    }
1138864
public static function escape( $value )
    {
        if ( is_string($value) ){
            $res = htmlspecialchars($value, ENT_QUOTES, mb_internal_encoding());
//log_debug( "debug", "escape:" . print_r($res,true) );
            return $res;
        }
        elseif ( is_array($value) ){
            $ret = array();
            foreach( $value as $key => $item ){
                $ret[$key] = self::escape( $item );
            }
            return $ret;
        }
        elseif ( is_object($value) ){
            $object = $value;
            $vars = get_object_vars($object);
            foreach( $vars as $key => $value ){
                $object->$key = self::escape( $value );
            }
            return $object;
        }
        return $value;
    }
87917
private static function stringify($value)
    {
        if (is_string($value)) {
            return sprintf('"%s"', preg_replace('/\n/', '\n', $value));
        }

        if (is_bool($value)) {
            return $value ? 'true' : 'false';
        }

        if (is_null($value)) {
            return 'null';
        }

        if (is_array($value)) {
            return sprintf('[%s]', implode(', ', array_map(
                function ($value) {
                    return self::stringify($value);
                },
                $value
            )));
        }

        return (string) $value;
    }
518085
public function asCode($value)
    {
        if ($value instanceof JS) {
            $value = (string) $value;
        } elseif (is_bool($value)) {
            $value = $value ? 'true' : 'false';
        } elseif (is_string($value)) {
            $value = '\''.$value.'\'';
        } elseif (is_array($value)) {
            $tmp = array();
            $useKey = !$this->isKeysNumeric($value);
            foreach ($value as $k => $v) {
                // skip null value
                if (null === $v) {
                    continue;
                }
                $v = $this->asCode($v);
                $tmp[] = $useKey ? sprintf('%s: %s', $k, $v) : $v;
            }
            $multiline = $this->getOption('multiline');
            $value = ($multiline ? "\n" : '').implode($multiline ? ",\n" : ', ', $tmp).($multiline ? "\n" : '');
            if ($useKey) {
                $value = sprintf('{%s}', $value);
            } else {
                $value = sprintf('[%s]', $value);
            }
            if ($multiline) {
                $value = $this->wrapLines($value, 1);
            }
        }

        return $value;
    }
1060039
protected function _addSlashesDeep( $value ) {
		if ( is_array( $value ) ) {
			$value = array_map( array( $this, '_addSlashesDeep' ), $value );
		} elseif ( is_object( $value ) ) {
			$vars = get_object_vars( $value );
			foreach ( $vars as $key => $data ) {
				$value->{$key} = $this->_addSlashesDeep( $data );
			}
		} elseif ( is_string( $value ) ) {
			$value = addslashes( $value );
		}

		return $value;
	}
215077
protected function wrapValue($value)
    {
        if ($value === '*') {
            return $value;
        }

        // If the given value is a JSON selector we will wrap it differently than a
        // traditional value. We will need to split this path and wrap each part
        // wrapped, etc. Otherwise, we will simply wrap the value as a string.
        if ($this->isJsonSelector($value)) {
            return $this->wrapJsonSelector($value);
        }

        return '`' . str_replace('`', '``', $value) . '`';
    }
881602
public function encodeValue($value)
    {
        if ($this->urlEncode == self::RFC_3986) {
            return rawurlencode($value);
        } elseif ($this->urlEncode == self::FORM_URLENCODED) {
            return urlencode($value);
        } else {
            return (string) $value;
        }
    }
1209546
public static function getStringForTable($value)
    {
        if (true === is_string($value)) {
            return wordwrap($value, self::MAX_STRING_LENGTH, PHP_EOL);
        }

        if (true === is_bool($value)) {
            if (true === $value) {
                return 'TRUE';
            }

            return 'FALSE';
        }

        if ($value instanceof \DateTime) {
            return $value->format('Y-m-d H:i:s');
        }

        if (null === $value) {
            return 'NULL';
        }

        if (true === is_array($value)) {
            $result = [];
            foreach ($value as $arrayIndex => $arrayValue) {
                if (true === is_numeric($arrayIndex)) {
                    $result[] = self::getStringForTable($arrayValue);

                    continue;
                }

                $result[] = sprintf('%s : %s', $arrayIndex, self::getStringForTable($arrayValue));
            }

            return implode(PHP_EOL, $result);
        }

        return json_encode($value);
    }
479456
protected function _compileEscapedEchos($value)
    {
        $pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->_escapedTags[0], $this->_escapedTags[1]);

        $callback = function ($matches) {
            if ($matches[1]) {
                return substr($matches[0], 1);
            }

            if (preg_match('#^[\w\.\[\]"\']+$#', $matches[2]) || preg_match('#^\\$[\w]+\(#', $matches[2])) {
                return $matches[0];
            } elseif ($this->_isSafeEchos($matches[2])) {
                return "<?= $matches[2] ?>" . (empty($matches[3]) ? '' : $matches[3]);
            } else {
                return '<?= e(' . $this->_compileEchoDefaults($matches[2]) . '); ?>' . (empty($matches[3]) ? '' : $matches[3]);
            }
        };

        return preg_replace_callback($pattern, $callback, $value);
    }
339158
public static function cleanValue($value)
    {
        if (is_array($value)) {
            $new_value = [];

            foreach ($value as $k => $v) {
                $new_value[$k] = self::cleanValue($v);
            }

            return $new_value;
        }

        return stripslashes($value);
    }
357070
public function sanitize( $value ) {
		if ( is_array( $value ) ) {
			foreach ( $value as $key => $subvalue ) {
				if ( '' !== $subvalue || isset( $this->choices[''] ) ) {
					$key           = sanitize_key( $key );
					$value[ $key ] = sanitize_text_field( $subvalue );
				}
			}
			return $value;
		}
		return sanitize_text_field( $value );
	}
265743
public static function getStringValueAsCode($value): string
    {
        if ($value instanceof \DateTime) {
            return "new \DateTime('".$value->format(self::DEFAULT_DATETIME_FORMAT)."')";
        } elseif (is_bool($value)) {
            return $value ? 'true' : 'false';
        } elseif (is_array($value)) {
            return '['.implode(', ', array_map('self::getStringValueAsCode', array_filter($value))).']';
        } elseif (is_null($value)) {
            return 'null';
        } elseif (is_int($value) || is_float($value)) {
            return (string) $value;
        }

        return "'".(string) $value."'";
    }