| 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 | */ |
| 822 | function _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 | */ |
| 840 | function _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 | */ |
| 855 | function _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'], array_keys( 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 |