wp_ajax_send_link_to_editor()
- Since
- 3.5.0
- Source
wp-admin/includes/ajax-actions.php:3393
Description
Generates the HTML to send a non-image embed link to the editor.
Backward compatible with the following filters:
- file_send_to_editor_url
- audio_send_to_editor_url
- video_send_to_editor_url
Compatibility
- WordPress
- since 3.5.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.
Performance profile
How much work a call to wp_ajax_send_link_to_editor() 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
- Heavy
- Scaling
- Constant
- Instructions
- 67–95
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_post().
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 100.
Third-party callbacks on '{$type}_send_to_editor_url' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize 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 · 32 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_ajax_send_link_to_editor() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$1 | 67–72 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success() |
!$1 | 69–74 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_send_json_error(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success() |
!$1 | 69–74 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success() |
!$1 | 71–76 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success() |
!$1 | 71–76 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_send_json_error(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success() |
!$1 | 73–78 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_send_json_error(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success() |
!$1 | 73–78 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success() |
$1 | 74–81 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && !$1 | 74–78 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), apply_filters(), wp_send_json_success() |
!$1 | 75–80 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_send_json_error(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success() |
$1 | 76–83 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_send_json_error(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && !$1 | 76–80 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_send_json_error(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), apply_filters(), wp_send_json_success() |
20 further outcomes, up to 95 instructions
$1 | 76–83 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && !$1 | 76–80 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), apply_filters(), wp_send_json_success() |
$1 | 78–85 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && !$1 | 78–82 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), apply_filters(), wp_send_json_success() |
$1 | 78–85 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_send_json_error(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && !$1 | 78–82 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_send_json_error(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), apply_filters(), wp_send_json_success() |
$1 | 80–87 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_send_json_error(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && !$1 | 80–84 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_send_json_error(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), apply_filters(), wp_send_json_success() |
$1 | 80–87 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && !$1 | 80–84 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), apply_filters(), wp_send_json_success() |
$check_embed === false && $1 | 81–87 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$1 | 82–89 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_send_json_error(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && !$1 | 82–86 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_send_json_error(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), apply_filters(), wp_send_json_success() |
$check_embed === false && $1 | 83–89 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_send_json_error(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && $1 | 83–89 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && $1 | 85–91 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && $1 | 85–91 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_send_json_error(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && $1 | 87–93 | check_ajax_referer(), wp_unslash(), sanitize_url(), wp_send_json_error(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && $1 | 87–93 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), wp_ext2type(), apply_filters(), wp_send_json_success() |
$check_embed === false && $1 | 89–95 | check_ajax_referer(), wp_unslash(), wp_send_json_error(), sanitize_url(), wp_send_json_error(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), wp_ext2type(), apply_filters(), wp_send_json_success() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 100 | 67–95 | 10 | |
| 8.5 | 100 | 67–95 | 10 | |
| 8.4 | 100 | 67–95 | 10 | 10 fewer instructions than PHP 8.3 |
| 8.3 | 110 | 77–105 | 10 | |
| 8.2 | 110 | 77–105 | 10 | |
| 8.1 | 110 | 77–105 | 10 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 111 | 77–106 | 10 |
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.
Hooks and filters fired · 1
One hook fires while wp_ajax_send_link_to_editor() runs, in this order:
- apply_filters( {$type}_send_to_editor_url )filterline 3445 (+52 into the body)
Filters the URL sent to the editor for a specific media type.
Uses · 10
- check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- wp_send_json_error()Sends a JSON response back to an Ajax request, indicating failure.
- sanitize_url()Sanitizes a URL for database or redirect usage.
- wp_basename()i18n-friendly version of basename().
- get_post()Retrieves post data given a post ID or post object.
- esc_url()Checks and cleans a URL.
- wp_ext2type()Retrieves the file type based on the extension name.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_send_json_success()Sends a JSON response back to an Ajax request, indicating success.
Source code
function wp_ajax_send_link_to_editor() { global $post, $wp_embed; check_ajax_referer( 'media-send-to-editor', 'nonce' ); $src = wp_unslash( $_POST['src'] ); if ( ! $src ) { wp_send_json_error(); } if ( ! strpos( $src, '://' ) ) { $src = 'http://' . $src; } $src = sanitize_url( $src ); if ( ! $src ) { wp_send_json_error(); } $link_text = trim( wp_unslash( $_POST['link_text'] ) ); if ( ! $link_text ) { $link_text = wp_basename( $src ); } $post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 ); // Ping WordPress for an embed. $check_embed = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' ); // Fallback that WordPress creates when no oEmbed was found. $fallback = $wp_embed->maybe_make_link( $src ); if ( $check_embed !== $fallback ) { // TinyMCE view for [embed] will parse this. $html = '[embed]' . $src . '[/embed]'; } elseif ( $link_text ) { $html = '<a href="' . esc_url( $src ) . '">' . $link_text . '</a>'; } else { $html = ''; } // Figure out what filter to run: $type = 'file'; $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ); if ( $ext ) { $ext_type = wp_ext2type( $ext ); if ( 'audio' === $ext_type || 'video' === $ext_type ) { $type = $ext_type; } } /** This filter is documented in wp-admin/includes/media.php */ $html = apply_filters( "{$type}_send_to_editor_url", $html, $src, $link_text ); wp_send_json_success( $html );}Changelog
Introduced in 3.5.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 6.9.7 tag, from
src/wp-admin/includes/ajax-actions.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.