wpcf7_is_file_path_in_content_dir()CF7 1.0

Verifies that a given file path is under the directories that WordPress manages for user contents.

Returns false if the file at the given path does not exist yet.

Хуков нет.

Возвращает

true|false. True if the path is under the content directories, false otherwise.

Использование

wpcf7_is_file_path_in_content_dir( $path );
$path(строка) (обязательный)
A file path.

Код wpcf7_is_file_path_in_content_dir() CF7 5.9.3

function wpcf7_is_file_path_in_content_dir( $path ) {
	if ( ! is_string( $path ) or '' === $path ) {
		return false;
	}

	$callback = static function ( $path, $dir ) {
		if ( $real_path = realpath( $path ) ) {
			$path = $real_path;
		} else {
			return false;
		}

		if ( $real_dir = realpath( $dir ) ) {
			$dir = trailingslashit( $real_dir );
		} else {
			return false;
		}

		return str_starts_with(
			wp_normalize_path( $path ),
			wp_normalize_path( $dir )
		);
	};

	if (
		call_user_func( $callback, $path, WP_CONTENT_DIR )
	) {
		return true;
	}

	if (
		defined( 'UPLOADS' ) and
		call_user_func( $callback, $path, ABSPATH . UPLOADS )
	) {
		return true;
	}

	if (
		defined( 'WP_TEMP_DIR' ) and
		call_user_func( $callback, $path, WP_TEMP_DIR )
	) {
		return true;
	}

	return false;
}