WordPress.org

Make WordPress Core

Ticket #24011: 24011.5.diff

File 24011.5.diff, 4.0 KB (added by kovshenin, 5 years ago)
  • wp-admin/css/wp-admin.css

     
    39863986        margin-bottom: 20px;
    39873987}
    39883988
     3989.wp-format-aside #titlewrap,
     3990.wp-format-status #titlewrap,
    39893991.wp-format-aside .wp-media-buttons .insert-media,
    39903992.wp-format-status .wp-media-buttons .insert-media {
    39913993        display: none;
  • 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

     
    931931
    932932        echo str_replace( ']]>', ']]>', $content );
    933933}
     934
     935/**
     936 * Don't display post titles for asides and status posts on the front end.
     937 *
     938 * @since 3.6.0
     939 * @access private
     940 */
     941function _post_formats_title( $title, $post_id ) {
     942        if ( is_admin() || is_feed() || ! in_array( get_post_format( $post_id ), array( 'aside', 'status' ) ) )
     943                return $title;
     944
     945        // Return an empty string only if the title is auto-generated.
     946        $post = get_post( $post_id );
     947        if ( $title == _post_formats_generate_title( $post->post_content, get_post_format( $post_id ) ) )
     948                $title = '';
     949
     950        return $title;
     951}
     952
     953/**
     954 * Generate a title from the post content or format.
     955 *
     956 * @since 3.6.0
     957 * @access private
     958 */
     959function _post_formats_generate_title( $content, $post_format = '' ) {
     960        $title = wp_trim_words( strip_shortcodes( $content ), 8, '' );
     961
     962        if ( empty( $title ) )
     963                $title = get_post_format_string( $post_format );
     964
     965        return $title;
     966}
     967
     968/**
     969 * Runs during save_post, fixes empty titles for asides and statuses.
     970 *
     971 * @since 3.6.0
     972 * @access private
     973 */
     974function _post_formats_fix_empty_title( $data, $postarr ) {
     975        if ( 'auto-draft' == $data['post_status'] || ! post_type_supports( $data['post_type'], 'post-formats' ) )
     976                return $data;
     977
     978        $post_id = ( isset( $postarr['ID'] ) ) ? absint( $postarr['ID'] ) : 0;
     979
     980        if ( $post_id )
     981                $post_format = get_post_format( $post_id );
     982
     983        if ( isset( $postarr['post_format'] ) )
     984                $post_format = ( in_array( $postarr['post_format'], get_post_format_slugs() ) ) ? $postarr['post_format'] : '';
     985
     986        if ( ! in_array( $post_format, array( 'aside', 'status' ) ) )
     987                return $data;
     988
     989        if ( $data['post_title'] == _post_formats_generate_title( $data['post_content'], $post_format ) )
     990                return $data;
     991
     992        // If updating an existing post, check whether the title was auto-generated.
     993        if ( $post_id && $post = get_post( $post_id ) )
     994                if ( $post->post_title == $data['post_title'] && $post->post_title == _post_formats_generate_title( $post->post_content, get_post_format( $post->ID ) ) )
     995                        $data['post_title'] = '';
     996
     997        if ( empty( $data['post_title'] ) )
     998                $data['post_title'] = _post_formats_generate_title( $data['post_content'], $post_format );
     999
     1000        return $data;
     1001}
     1002 No newline at end of file