WordPress.org

Make WordPress Core

Ticket #24011: 24011.4.diff

File 24011.4.diff, 3.5 KB (added by kovshenin, 5 years ago)
  • wp-includes/default-filters.php

     
    131131add_filter( 'the_title', 'wptexturize'   );
    132132add_filter( 'the_title', 'convert_chars' );
    133133add_filter( 'the_title', 'trim'          );
     134add_filter( 'the_title', '_post_formats_title', 10, 2 );
    134135
    135136add_filter( 'the_content', 'post_formats_compat', 7 );
    136137add_filter( 'the_content', 'wptexturize'            );
     
    250251add_action( 'plugins_loaded',             'wp_maybe_load_widgets',                    0    );
    251252add_action( 'plugins_loaded',             'wp_maybe_load_embeds',                     0    );
    252253add_action( 'shutdown',                   'wp_ob_end_flush_all',                      1    );
     254add_action( 'wp_insert_post_data',        '_post_formats_fix_empty_title',           10, 2 );
    253255add_action( 'wp_insert_post',             'wp_save_post_revision',                   10, 1 );
    254256add_action( 'publish_post',               '_publish_post_hook',                       5, 1 );
    255257add_action( 'transition_post_status',     '_transition_post_status',                  5, 3 );
  • wp-includes/post-formats.php

     
    812812
    813813        echo str_replace( ']]>', ']]>', $content );
    814814}
     815
     816/**
     817 * Don't display post titles for asides and status posts on the front end.
     818 *
     819 * @since 3.6.0
     820 * @access private
     821 */
     822function _post_formats_title( $title, $post_id ) {
     823        if ( is_admin() || ! in_array( get_post_format( $post_id ), array( 'aside', 'status' ) ) )
     824                return $title;
     825
     826        // Return an empty string only if the title is auto-generated.
     827        $post = get_post( $post_id );
     828        if ( $title == _post_formats_generate_title( $post->post_content, get_post_format( $post_id ) ) )
     829                $title = '';
     830
     831        return $title;
     832}
     833
     834/**
     835 * Generate a title from the post content or format.
     836 *
     837 * @since 3.6.0
     838 * @access private
     839 */
     840function _post_formats_generate_title( $content, $post_format = '' ) {
     841        $title = wp_trim_words( strip_shortcodes( $content ), 8, '' );
     842
     843        if ( empty( $title ) )
     844                $title = get_post_format_string( $post_format );
     845
     846        return $title;
     847}
     848
     849/**
     850 * Runs during save_post, fixes empty titles for asides and statuses.
     851 *
     852 * @since 3.6.0
     853 * @access private
     854 */
     855function _post_formats_fix_empty_title( $data, $postarr ) {
     856        if ( 'auto-draft' == $data['post_status'] || ! isset( $postarr['post_format'] ) || ! post_type_supports( $data['post_type'], 'post-formats' ) )
     857                return $data;
     858
     859        $post_id = ( isset( $postarr['ID'] ) ) ? absint( $postarr['ID'] ) : 0;
     860        $post_format = ( in_array( $postarr['post_format'], get_post_format_slugs() ) ) ? $postarr['post_format'] : '';
     861
     862        if ( ! in_array( $post_format, array( 'aside', 'status' ) ) )
     863                return $data;
     864
     865        if ( $data['post_title'] == _post_formats_generate_title( $data['post_content'], $post_format ) )
     866                return $data;
     867
     868        // If updating an existing post, check whether the title was auto-generated.
     869        if ( $post_id && $post = get_post( $post_id ) )
     870                if ( $post->post_title == $data['post_title'] && $post->post_title == _post_formats_generate_title( $post->post_content, get_post_format( $post->ID ) ) )
     871                        $data['post_title'] = '';
     872
     873        if ( empty( $data['post_title'] ) )
     874                $data['post_title'] = _post_formats_generate_title( $data['post_content'], $post_format );
     875
     876        return $data;
     877}
     878 No newline at end of file