Make WordPress Core

Ticket #23347: 23347.3.diff

File 23347.3.diff, 7.1 KB (added by beaulebens, 11 years ago)
  • wp-includes/default-filters.php

     
    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', 'post_formats_compat', 7 );
     136add_filter( 'the_content', 'wptexturize'            );
     137add_filter( 'the_content', 'convert_smilies'        );
     138add_filter( 'the_content', 'convert_chars'          );
     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

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