_wp_kses_allow_pdf_objects( string $url ): bool
- Since
- 5.9.0
- Source
wp-includes/kses.php:3135
Compatibility
- WordPress
- since 5.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$urlstring- The URL to check.
Return value
bool- True if the URL is safe, false otherwise.
Performance profile
How much work a call to _wp_kses_allow_pdf_objects() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 4–44
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 48.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below _wp_kses_allow_pdf_objects()
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _wp_kses_allow_pdf_objects() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$url | 4–6 | none |
!$url && !str_ends_with() | 11 | str_ends_with() |
!$url && str_ends_with() | 35–44 | str_ends_with(), wp_upload_dir(), wp_parse_url() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 48 | 4–44 | 7 | |
| 8.5 | 48 | 4–44 | 7 | |
| 8.4 | 48 | 4–44 | 7 | 12 fewer instructions than PHP 8.3 |
| 8.3 | 60 | 7–56 | 7 | |
| 8.2 | 60 | 7–56 | 7 | |
| 8.1 | 60 | 7–56 | 7 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 61 | 7–57 | 7 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 5
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- wp_upload_dir()Returns an array containing the current upload directory's path and URL.
- wp_parse_url()A wrapper for PHP's parse_url() function that handles consistency in the return values across PHP versions.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
Source code
function _wp_kses_allow_pdf_objects( $url ) { // We're not interested in URLs that contain query strings or fragments. if ( str_contains( $url, '?' ) || str_contains( $url, '#' ) ) { return false; } // If it doesn't have a PDF extension, it's not safe. if ( ! str_ends_with( $url, '.pdf' ) ) { return false; } // If the URL host matches the current site's media URL, it's safe. $upload_info = wp_upload_dir( null, false ); $parsed_url = wp_parse_url( $upload_info['url'] ); $upload_host = $parsed_url['host'] ?? ''; $upload_port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : ''; if ( str_starts_with( $url, "http://$upload_host$upload_port/" ) || str_starts_with( $url, "https://$upload_host$upload_port/" ) ) { return true; } return false;}Changelog
Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/kses.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.