wppaste
WordPress

wp_ajax_send_link_to_editor()

Since
3.5.0
Source
wp-admin/includes/ajax-actions.php:3427
Handles sending a link to the editor via AJAX.

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

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
66–93

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 97.

Plugin surface
1 hook

Third-party callbacks on '{$type}_send_to_editor_url' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
!$166–70check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success()
!$168–72check_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()
!$168–72check_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()
!$170–74check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), wp_basename(), get_post(), ->run_shortcode(), ->maybe_make_link(), apply_filters(), wp_send_json_success()
!$170–74check_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()
!$172–76check_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()
!$172–76check_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()
$173–79check_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 && !$173–76check_ajax_referer(), wp_unslash(), sanitize_url(), wp_unslash(), get_post(), ->run_shortcode(), ->maybe_make_link(), esc_url(), apply_filters(), wp_send_json_success()
!$174–78check_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()
$175–81check_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 && !$175–78check_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 93 instructions
$175–81check_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 && !$175–78check_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()
$177–83check_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 && !$177–80check_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()
$177–83check_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 && !$177–80check_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()
$179–85check_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 && !$179–82check_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()
$179–85check_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 && !$179–82check_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 && $180–85check_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()
$181–87check_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 && !$181–84check_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 && $182–87check_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 && $182–87check_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 && $184–89check_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 && $184–89check_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 && $186–91check_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 && $186–91check_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 && $188–93check_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

PHPCompiledExecutedBranchesNotes
8.6-dev9766–9310
8.59766–9310
8.49766–931010 fewer instructions than PHP 8.3
8.310776–10310
8.210776–10310
8.110776–10310
7.410776–10310

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:

  1. apply_filters( {$type}_send_to_editor_url )filterline 3479 (+52 into the body)

    Filters the URL sent to the editor for a specific media type.

Uses · 10

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( $_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';	$extension = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src );	if ( $extension ) {		$extension_type = wp_ext2type( $extension );		if ( 'audio' === $extension_type || 'video' === $extension_type ) {			$type = $extension_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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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-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.