Make WordPress Core

Ticket #23347: 23347.diff

File 23347.diff, 6.9 KB (added by wonderboymusic, 11 years ago)
  • wp-includes/default-filters.php

    diff --git wp-includes/default-filters.php wp-includes/default-filters.php
    index 7d47e45..7c56bdb 100644
    add_filter( 'the_title', 'wptexturize' ); 
    132132add_filter( 'the_title', 'convert_chars' );
    133133add_filter( 'the_title', 'trim'          );
    134134
    135 add_filter( 'the_content', 'wptexturize'        );
    136 add_filter( 'the_content', 'convert_smilies'    );
    137 add_filter( 'the_content', 'convert_chars'      );
    138 add_filter( 'the_content', 'wpautop'            );
    139 add_filter( 'the_content', 'shortcode_unautop'  );
    140 add_filter( 'the_content', 'prepend_attachment' );
     135add_filter( 'the_content', 'wptexturize'         );
     136add_filter( 'the_content', 'convert_smilies'     );
     137add_filter( 'the_content', 'convert_chars'       );
     138add_filter( 'the_content', 'post_formats_compat' );
     139add_filter( 'the_content', 'wpautop'             );
     140add_filter( 'the_content', 'shortcode_unautop'   );
     141add_filter( 'the_content', 'prepend_attachment'  );
    141142
    142143add_filter( 'the_excerpt',     'wptexturize'      );
    143144add_filter( 'the_excerpt',     'convert_smilies'  );
  • wp-includes/formatting.php

    diff --git wp-includes/formatting.php wp-includes/formatting.php
    index 83f5269..6f8f705 100644
    function convert_smilies($text) { 
    18021802}
    18031803
    18041804/**
     1805 * Return the class for a post format content wrapper
     1806 *
     1807 * @since 3.6
     1808 *
     1809 * @param string $format
     1810 */
     1811function get_post_format_content_class( $format ) {
     1812        return apply_filters( 'post_format_content_class', $format . '-post-format-content', $format );
     1813}
     1814
     1815/**
     1816 * Ouput the class for a post format content wrapper
     1817 *
     1818 * @since 3.6
     1819 *
     1820 * @param string $format
     1821 */
     1822function post_format_content_class( $format ) {
     1823        echo get_post_format_content_class( $format );
     1824}
     1825
     1826/**
     1827 * Provide fallback behavior for Posts that have associated post format
     1828 *
     1829 * @since 3.6
     1830 *
     1831 * @param string $content
     1832 */
     1833function post_formats_compat( $content, $id = 0 ) {
     1834        $post = empty( $id ) ? get_post() : get_post( $id );
     1835        if ( empty( $post ) )
     1836                return $content;
     1837
     1838        $formats = get_the_terms( $post, 'post_format' );
     1839        if ( empty( $formats ) )
     1840                return $content;
     1841
     1842        $format = str_replace( 'post-format-', '', reset( $formats )->slug );
     1843
     1844        if ( current_theme_supports( 'post-formats', $format ) )
     1845                return $content;
     1846
     1847        $defaults = array(
     1848                'position' => 'after',
     1849                'tag' => 'div',
     1850                'class' => get_post_format_content_class( $format ),
     1851                'chat_tag' => 'span',
     1852                'chat_tag_class' => 'chat-line',
     1853                'chat_delimiter' => PHP_EOL,
     1854                'link_class' => '',
     1855                'image_class' => '',
     1856                'gallery' => '[gallery]',
     1857                'audio' => '[audio]',
     1858                'video' => '[video]'
     1859        );
     1860
     1861        $args = apply_filters( 'post_format_compat', array() );
     1862        $compat = wp_parse_args( $args, $defaults );
     1863
     1864        $show_content = true;
     1865        $format_output = '';
     1866
     1867        switch ( $format ) {
     1868        case 'chat':
     1869                $show_content = false;
     1870                $lines = explode( $compat['chat_delimiter'], $content );
     1871                foreach ( $lines as $line )
     1872                        $format_output .= sprintf( '<%1$s class="%2$s">%3$s</%1$s>', $compat['chat_tag'], $compat['chat_tag_class'], $line );
     1873                break;
     1874
     1875        case 'link':
     1876                $compat['tag'] = '';
     1877
     1878                $url = get_post_meta( $post->ID, '_wp_format_url', true );
     1879                if ( ! empty( $url ) ) {
     1880                        $format_output .= sprintf(
     1881                                '<a %shref="%s">%s</a>',
     1882                                empty( $compat['link_class'] ) ? '' : sprintf( 'class="%s" ', $compat['link_class'] ),
     1883                                esc_url( $url ),
     1884                                empty( $post->post_title ) ? esc_url( $url ) : apply_filters( 'the_title', $post->post_title )
     1885                        );
     1886                }
     1887                break;
     1888
     1889        case 'quote':
     1890                $quote = get_post_meta( $post->ID, '_wp_format_quote', true );
     1891                $source = get_post_meta( $post->ID, '_wp_format_quote_source', true );
     1892                $url = get_post_meta( $post->ID, '_wp_format_url', true );
     1893
     1894                if ( ! empty( $quote ) ) {
     1895                        $format_output .= sprintf( '<blockquote>%s</blockquote>', $quote );
     1896                        if ( ! empty( $source ) ) {
     1897                                $format_output .= sprintf(
     1898                                        '<cite>%s</cite>',
     1899                                        ! empty( $url ) ? sprintf( '<a href="%1$s">%1$s</a>', esc_url( $url ) ) : $source
     1900                                );
     1901                        }
     1902                }
     1903                break;
     1904
     1905        case 'image':
     1906                $image = get_post_meta( $post->ID, '_wp_format_image', true );
     1907                $url = get_post_meta( $post->ID, '_wp_format_url', true );
     1908
     1909                if ( is_numeric( $image ) )
     1910                        $image = wp_get_attachment_url( $image );
     1911
     1912                $esc_image_url = preg_quote( $image, '#' );
     1913                if ( ! empty( $image ) && ! preg_match( "#src=['\"]{$esc_image_url}#", $content ) ) {
     1914                        $image_html = sprintf(
     1915                                '<img %ssrc="%s" alt="" />',
     1916                                empty( $compat['image_class'] ) ? '' : sprintf( 'class="%s" ', $compat['image_class'] ),
     1917                                $image
     1918                        );
     1919                        if ( empty( $url ) ) {
     1920                                $format_output .= $image_html;
     1921                        } else {
     1922                                $format_output .= sprintf(
     1923                                        '<a href="%s">%s</a>',
     1924                                        esc_url( $url ),
     1925                                        $image_html
     1926                                );
     1927                        }
     1928                }
     1929                break;
     1930
     1931        case 'gallery':
     1932                $matches = preg_match( '/' . get_shortcode_regex() . '/s', $content );
     1933                if ( ! $matches || 'gallery' !== $matches[2] ) {
     1934                        $gallery = get_post_meta( $post->ID, '_wp_format_gallery', true );
     1935                        if ( empty( $gallery ) && ! empty( $compat['gallery'] ) ) {
     1936                                $format_output .= $compat['gallery'];
     1937                        } elseif ( ! empty( $gallery ) ) {
     1938                                $format_output .= $gallery;
     1939                        }
     1940                }
     1941                break;
     1942
     1943        case 'video':
     1944        case 'audio':
     1945                $shortcode_regex = '/' . get_shortcode_regex() . '/s';
     1946                $matches = preg_match( $shortcode_regex, $content );
     1947                if ( ! $matches || $format !== $matches[2] ) {
     1948                        $media = get_post_meta( $post->ID, '_wp_format_media', true );
     1949                        if ( empty( $media ) && ! empty( $compat[$format] ) ) {
     1950                                $format_output .= $compat[$format];
     1951                        } elseif ( ! empty( $media ) ) {
     1952                                // the metadata is a shortcode or an embed code
     1953                                if ( preg_match( $shortcode_regex, $media ) || preg_match( '#<[^>]+>#', $media ) ) {
     1954                                        $format_output .= $media;
     1955                                } else {
     1956                                        $mime_type = wp_check_filetype( $media );
     1957                                        // URL that can be shortcode'd
     1958                                        if ( ! empty( $mime_type['type'] )
     1959                                                && ( ( 'video' === $format && 'video/mp4' === $mime_type['type'] )
     1960                                                        || ( 'audio' === $format && 'audio/mpeg' === $mime_type['type'] ) ) ) {
     1961                                                $format_output .= sprintf( '[%s src="%s"]', $format, esc_url( $media ) );
     1962                                        // URL that isn't embeddable outputs string
     1963                                        } else {
     1964                                                $format_output .= $media;
     1965                                        }
     1966                                }
     1967                        }
     1968                }
     1969                break;
     1970        case 'standard':
     1971        case 'status':
     1972        case 'aside':
     1973        default:
     1974                return $content;
     1975                break;
     1976        }
     1977
     1978        $output = '';
     1979        if ( ! empty( $compat['tag'] ) )
     1980                $output .= sprintf( '<%s class="%s">', $compat['tag'], $compat['class'] );
     1981
     1982        if ( $show_content && 'before' !== $compat['position'] )
     1983                $output .= $content . PHP_EOL . PHP_EOL;
     1984
     1985        $output .= $format_output;
     1986
     1987        if ( $show_content && 'before' === $compat['position'] )
     1988                $output .= PHP_EOL . PHP_EOL . $content;
     1989
     1990        if ( ! empty( $compat['tag'] ) )
     1991                $output .= sprintf( '</%s>', $compat['tag'] );
     1992
     1993        return $output;
     1994}
     1995
     1996/**
    18051997 * Verifies that an email is valid.
    18061998 *
    18071999 * Does not grok i18n domains. Not RFC compliant.