post_type) { wp_send_json_error(); } $rel = $url = ''; $html = $title = $attachment['post_title'] ?? ''; if (!empty($attachment['url'])) { $url = $attachment['url']; if (strpos($url, 'attachment_id') || get_attachment_link($id) == $url) { $rel = ' rel="attachment wp-att-' . $id . '"'; } $html = '' . $html . ''; } if ('image' === substr($post->post_mime_type, 0, 5)) { $align = $attachment['align'] ?? 'none'; $size = $attachment['image-size'] ?? 'medium'; $alt = $attachment['image_alt'] ?? ''; $caption = $attachment['post_excerpt'] ?? ''; $title = ''; // We no longer insert title tags into tags, as they are redundant. $html = get_image_send_to_editor($id, $caption, $title, $align, $url, (bool)$rel, $size, $alt); } elseif ('video' === substr($post->post_mime_type, 0, 5) || 'audio' === substr($post->post_mime_type, 0, 5)) { global $wp_embed; $meta = get_post_meta($id, '_wp_attachment_metadata', true); $html = $wp_embed->shortcode($meta, $url); } /** * * This filter is documented in wp-admin/includes/media.php */ $html = apply_filters('media_send_to_editor', $html, $id, $attachment); // replace wp-image-, wp-att- and attachment_ $html = preg_replace( array( '#(caption id="attachment_)(\d+")#', // mind the quotes! '#(wp-image-|wp-att-)(\d+)#' ), array( sprintf('${1}nsm_%s_${2}', esc_attr($nsm_blog_id)), sprintf('${1}nsm-%s-${2}', esc_attr($nsm_blog_id)), ), $html ); if (isset($post_chromeless) && $post_chromeless) { // WP3.5+ media browser is identified by the 'chromeless' parameter exit(esc_html($html)); } else { return media_send_to_editor($html); } }