private function php_search_replace( $data, $serialised, $recursion_level = 0, $visited_data = array() ) {
		// some unseriliased data cannot be re-serialised eg. SimpleXMLElements
		try {
			// If we've reached the maximum recursion level, short circuit
			if ( $this->max_recursion !== 0 && $recursion_level >= $this->max_recursion ) { // @codingStandardsIgnoreLine
				return $data;
			}
			if ( is_array( $data ) || is_object( $data ) ) {
				// If we've seen this exact object or array before, short circuit
				if ( in_array( $data, $visited_data, true ) ) {
					return $data; // Avoid infinite loops when there's a cycle
				}
				// Add this data to the list of
				$visited_data[] = $data;
			}

			if ( is_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) {
				$data = $this->php_search_replace( $unserialized, true, $recursion_level + 1 );
			} elseif ( is_array( $data ) ) {
				$keys = array_keys( $data );
				foreach ( $keys as $key ) {
					$data[ $key ] = $this->php_search_replace( $data[ $key ], false, $recursion_level + 1, $visited_data );
				}
			} elseif ( is_object( $data ) ) {
				foreach ( $data as $key => $value ) {
					$data->$key = $this->php_search_replace( $value, false, $recursion_level + 1, $visited_data );
				}
			} elseif ( is_string( $data ) ) {
				$data = str_replace( $this->old, $this->new, $data );
			}
			if ( $serialised ) {
				return serialize( $data );
			}
		} catch ( Exception $error ) {
			// Do nothing
		}

		return $data;
	}