Changeset 22768 for trunk/wp-admin/includes/ajax-actions.php
- Timestamp:
- 11/21/2012 04:02:20 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/ajax-actions.php
r22723 r22768 1908 1908 wp_send_json_success( $attachment ); 1909 1909 } 1910 1911 /** 1912 * Generates the HTML to send an attachment to the editor. 1913 * Backwards compatible with the media_send_to_editor filter and the chain 1914 * of filters that follow. 1915 * 1916 * @since 3.5.0 1917 */ 1918 function wp_ajax_send_attachment_to_editor() { 1919 check_ajax_referer( 'media-send-to-editor', 'nonce' ); 1920 1921 $attachment = stripslashes_deep( $_POST['attachment'] ); 1922 1923 $id = intval( $attachment['id'] ); 1924 1925 if ( ! $post = get_post( $id ) ) 1926 wp_send_json_error(); 1927 1928 if ( ! current_user_can( 'edit_post', $id ) ) 1929 wp_send_json_error(); 1930 1931 if ( 'attachment' != $post->post_type ) 1932 wp_send_json_error(); 1933 1934 $html = isset( $attachment['title'] ) ? $attachment['title'] : ''; 1935 if ( ! empty( $attachment['url'] ) ) { 1936 $rel = ''; 1937 if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link( $id ) == $attachment['url'] ) 1938 $rel = ' rel="attachment wp-att-' . $id . '"'; 1939 $html = '<a href="' . esc_url( $attachment['url'] ) . '"' . $rel . '>' . $html . '</a>'; 1940 } 1941 1942 remove_filter( 'media_send_to_editor', 'image_media_send_to_editor', 10, 3 ); 1943 1944 if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) { 1945 $url = $attachment['url']; 1946 $align = isset( $attachment['image-align'] ) ? $attachment['image-align'] : 'none'; 1947 $size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium'; 1948 $alt = isset( $attachment['image-alt'] ) ? $attachment['image-alt'] : ''; 1949 $caption = isset( $attachment['caption'] ) ? $attachment['caption'] : ''; 1950 $title = ''; // We no longer insert title tags into <img> tags, as they are redundant. 1951 $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt ); 1952 } 1953 1954 $html = apply_filters( 'media_send_to_editor', $html, $id, $attachment ); 1955 1956 wp_send_json_success( $html ); 1957 } 1958 1959 /** 1960 * Generates the HTML to send a non-image embed link to the editor. 1961 * 1962 * Backwards compatible with the following filters: 1963 * - file_send_to_editor_url 1964 * - audio_send_to_editor_url 1965 * - video_send_to_editor_url 1966 * 1967 * @since 3.5.0 1968 */ 1969 function wp_ajax_send_link_to_editor() { 1970 check_ajax_referer( 'media-send-to-editor', 'nonce' ); 1971 1972 if ( ! $src = stripslashes( $_POST['src'] ) ) 1973 wp_send_json_error(); 1974 1975 if ( ! strpos( $src, '://' ) ) 1976 $src = 'http://' . $src; 1977 1978 if ( ! $src = esc_url_raw( $src ) ) 1979 wp_send_json_error(); 1980 1981 if ( ! $title = trim( stripslashes( $_POST['title'] ) ) ) 1982 $title = wp_basename( $src ); 1983 1984 $html = ''; 1985 if ( $title ) 1986 $html = '<a href="' . esc_url( $src ) . '">' . $title . '</a>'; 1987 1988 // Figure out what filter to run: 1989 $type = 'file'; 1990 if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) 1991 && ( 'audio' == $ext_type || 'video' == $ext_type ) ) 1992 $type = $ext_type; 1993 1994 $html = apply_filters( $type . '_send_to_editor_url', $html, $src, $title ); 1995 1996 wp_send_json_success( $html ); 1997 }
Note: See TracChangeset
for help on using the changeset viewer.