Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories
Register::is_valid_path()
Indicates if the URL is within an approved directory. The approved directory must be enabled (it is possible for individual approved directories to be disabled).
For instance, for 'https://storage.king/12345/ebook.pdf' to be valid then 'https://storage.king/12345' would need to be within our register.
If the provided URL is a filepath it can be passed in without the 'file://' scheme.
Метод класса: Register{}
Хуков нет.
Возвращает
true|false
.
Использование
$Register = new Register(); $Register->is_valid_path( $download_url ): bool;
- $download_url(строка) (обязательный)
- The URL to check.
Код Register::is_valid_path() Register::is valid path WC 7.7.0
public function is_valid_path( string $download_url ): bool { global $wpdb; $parent_directories = array(); foreach ( ( new URL( $this->normalize_url( $download_url ) ) )->get_all_parent_urls() as $parent ) { $parent_directories[] = "'" . esc_sql( $parent ) . "'"; } if ( empty( $parent_directories ) ) { return false; } $parent_directories = join( ',', $parent_directories ); $table = $this->get_table(); // Look for a rule that matches the start of the download URL being tested. Since rules describe parent // directories, we also ensure it ends with a trailing slash. // // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared $matches = (int) $wpdb->get_var( " SELECT COUNT(*) FROM {$table} WHERE enabled = 1 AND url IN ( {$parent_directories} ) " ); // phpcs:enable return $matches > 0; }