返回介绍

wp_ajax_send_link_to_editor()

发布于 2017-09-11 11:32:04 字数 3086 浏览 1074 评论 0 收藏 0

wp_ajax_send_link_to_editor()

Ajax handler for sending a link to the editor.


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

源代码

File: wp-admin/includes/ajax-actions.php

function wp_ajax_send_link_to_editor() {
	global $post, $wp_embed;

	check_ajax_referer( 'media-send-to-editor', 'nonce' );

	if ( ! $src = wp_unslash( $_POST['src'] ) )
		wp_send_json_error();

	if ( ! strpos( $src, '://' ) )
		$src = 'http://' . $src;

	if ( ! $src = esc_url_raw( $src ) )
		wp_send_json_error();

	if ( ! $link_text = trim( wp_unslash( $_POST['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';
	if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
		&& ( '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 );
}

更新日志

Versiondescription
3.5.0Introduced.

相关函数

Uses

  • wp-admin/includes/media.php: {$type}_send_to_editor_url
  • wp-includes/formatting.php: wp_unslash()
  • wp-includes/formatting.php: wp_basename()
  • wp-includes/formatting.php: esc_url_raw()
  • wp-includes/formatting.php: esc_url()
  • wp-includes/pluggable.php: check_ajax_referer()
  • wp-includes/functions.php: wp_send_json_error()
  • wp-includes/functions.php: wp_send_json_success()
  • wp-includes/functions.php: wp_ext2type()
  • wp-includes/class-wp-embed.php: WP_Embed::maybe_make_link()
  • wp-includes/class-wp-embed.php: WP_Embed::run_shortcode()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: get_post()
  • Show 8 more uses Hide more uses

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文