diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css index 4629c795ec..ceae0a9a98 100644 --- a/wp-admin/css/wp-admin.css +++ b/wp-admin/css/wp-admin.css @@ -3995,6 +3995,8 @@ body .ui-tooltip { margin-bottom: 20px; } +.wp-format-aside #titlewrap, +.wp-format-status #titlewrap, .wp-format-aside .wp-media-buttons .insert-media, .wp-format-status .wp-media-buttons .insert-media { display: none; diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 9d4d1412b8..601ca05a14 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -131,6 +131,7 @@ add_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3 add_filter( 'the_title', 'wptexturize' ); add_filter( 'the_title', 'convert_chars' ); add_filter( 'the_title', 'trim' ); +add_filter( 'the_title', '_post_formats_title', 10, 2 ); add_filter( 'the_content', 'post_formats_compat', 7 ); add_filter( 'the_content', 'wptexturize' ); @@ -250,6 +251,7 @@ add_action( 'init', 'smilies_init', add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 ); add_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); +add_action( 'wp_insert_post_data', '_post_formats_fix_empty_title', 10, 2 ); add_action( 'wp_insert_post', 'wp_save_post_revision', 10, 1 ); add_action( 'publish_post', '_publish_post_hook', 5, 1 ); add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); diff --git a/wp-includes/post-formats.php b/wp-includes/post-formats.php index 7039c3d209..9002881bfb 100644 --- a/wp-includes/post-formats.php +++ b/wp-includes/post-formats.php @@ -931,3 +931,71 @@ function the_remaining_content( $more_link_text = null, $strip_teaser = false ) echo str_replace( ']]>', ']]>', $content ); } + +/** + * Don't display post titles for asides and status posts on the front end. + * + * @since 3.6.0 + * @access private + */ +function _post_formats_title( $title, $post_id ) { + if ( is_admin() || is_feed() || ! in_array( get_post_format( $post_id ), array( 'aside', 'status' ) ) ) + return $title; + + // Return an empty string only if the title is auto-generated. + $post = get_post( $post_id ); + if ( $title == _post_formats_generate_title( $post->post_content, get_post_format( $post_id ) ) ) + $title = ''; + + return $title; +} + +/** + * Generate a title from the post content or format. + * + * @since 3.6.0 + * @access private + */ +function _post_formats_generate_title( $content, $post_format = '' ) { + $title = wp_trim_words( strip_shortcodes( $content ), 8, '' ); + + if ( empty( $title ) ) + $title = get_post_format_string( $post_format ); + + return $title; +} + +/** + * Runs during save_post, fixes empty titles for asides and statuses. + * + * @since 3.6.0 + * @access private + */ +function _post_formats_fix_empty_title( $data, $postarr ) { + if ( 'auto-draft' == $data['post_status'] || ! post_type_supports( $data['post_type'], 'post-formats' ) ) + return $data; + + $post_id = ( isset( $postarr['ID'] ) ) ? absint( $postarr['ID'] ) : 0; + + if ( $post_id ) + $post_format = get_post_format( $post_id ); + + if ( isset( $postarr['post_format'] ) ) + $post_format = ( in_array( $postarr['post_format'], get_post_format_slugs() ) ) ? $postarr['post_format'] : ''; + + if ( ! in_array( $post_format, array( 'aside', 'status' ) ) ) + return $data; + + if ( $data['post_title'] == _post_formats_generate_title( $data['post_content'], $post_format ) ) + return $data; + + // If updating an existing post, check whether the title was auto-generated. + if ( $post_id && $post = get_post( $post_id ) ) + if ( $post->post_title == $data['post_title'] && $post->post_title == _post_formats_generate_title( $post->post_content, get_post_format( $post->ID ) ) ) + $data['post_title'] = ''; + + if ( empty( $data['post_title'] ) ) + $data['post_title'] = _post_formats_generate_title( $data['post_content'], $post_format ); + + return $data; +} \ No newline at end of file