image_media_send_to_editor

函式
image_media_send_to_editor ( $html, $attachment_id, $attachment )
引數
  • (string) $html
    Required:
  • (int) $attachment_id
    Required:
  • (array) $attachment
    Required:
返回值
  • (string)
定義位置
相關方法
media_send_to_editorget_image_send_to_editorimage_constrain_size_for_editorget_real_file_to_editwp_ajax_send_link_to_editor
引入
2.5.0
棄用
-

image_media_send_to_editor: 這個函式用來傳送一個影象到文章編輯器。

檢索媒體元素的HTML,傳送給編輯器。

function image_media_send_to_editor( $html, $attachment_id, $attachment ) {
	$post = get_post( $attachment_id );

	if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
		$url   = $attachment['url'];
		$align = ! empty( $attachment['align'] ) ? $attachment['align'] : 'none';
		$size  = ! empty( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
		$alt   = ! empty( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
		$rel   = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $attachment_id ) === $url );

		return get_image_send_to_editor( $attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt );
	}

	return $html;
}

常見問題

FAQs
檢視更多 >