Ticket #23347: 23347.4.diff

File 23347.4.diff, 6.9 KB (added by beaulebens, 3 months ago)

Removed the chat fallback entirely, until we can decide what to do with it. Also bailed earlier in the function for aside/status formats.

Line 
1Index: wp-includes/default-filters.php
2===================================================================
3--- wp-includes/default-filters.php     (revision 23447)
4+++ wp-includes/default-filters.php     (working copy)
5@@ -132,12 +132,13 @@
6 add_filter( 'the_title', 'convert_chars' );
7 add_filter( 'the_title', 'trim'          );
8 
9-add_filter( 'the_content', 'wptexturize'        );
10-add_filter( 'the_content', 'convert_smilies'    );
11-add_filter( 'the_content', 'convert_chars'      );
12-add_filter( 'the_content', 'wpautop'            );
13-add_filter( 'the_content', 'shortcode_unautop'  );
14-add_filter( 'the_content', 'prepend_attachment' );
15+add_filter( 'the_content', 'post_formats_compat', 7 );
16+add_filter( 'the_content', 'wptexturize'            );
17+add_filter( 'the_content', 'convert_smilies'        );
18+add_filter( 'the_content', 'convert_chars'          );
19+add_filter( 'the_content', 'wpautop'                );
20+add_filter( 'the_content', 'shortcode_unautop'      );
21+add_filter( 'the_content', 'prepend_attachment'     );
22 
23 add_filter( 'the_excerpt',     'wptexturize'      );
24 add_filter( 'the_excerpt',     'convert_smilies'  );
25Index: wp-includes/formatting.php
26===================================================================
27--- wp-includes/formatting.php  (revision 23447)
28+++ wp-includes/formatting.php  (working copy)
29@@ -1799,6 +1799,191 @@
30 }
31 
32 /**
33+ * Return the class for a post format content wrapper
34+ *
35+ * @since 3.6.0
36+ *
37+ * @param string $format
38+ */
39+function get_post_format_content_class( $format ) {
40+       return apply_filters( 'post_format_content_class', $format . '-post-format-content', $format );
41+}
42+
43+/**
44+ * Ouput the class for a post format content wrapper
45+ *
46+ * @since 3.6.0
47+ *
48+ * @param string $format
49+ */
50+function post_format_content_class( $format ) {
51+       echo get_post_format_content_class( $format );
52+}
53+
54+/**
55+ * Provide fallback behavior for Posts that have associated post format
56+ *
57+ * @since 3.6.0
58+ *
59+ * @param string $content
60+ */
61+function post_formats_compat( $content, $id = 0 ) {
62+       $post = empty( $id ) ? get_post() : get_post( $id );
63+       if ( empty( $post ) )
64+               return $content;
65+
66+       $format = get_post_format( $post );
67+       if ( empty( $format ) || in_array( $format, array( 'status', 'aside', 'chat' ) ) )
68+               return $content;
69+
70+       if ( current_theme_supports( 'post-formats', $format ) )
71+               return $content;
72+
73+       $defaults = array(
74+               'position' => 'after',
75+               'tag' => 'div',
76+               'class' => get_post_format_content_class( $format ),
77+               'chat_tag' => 'span',
78+               'chat_tag_class' => 'chat-line',
79+               'chat_delimiter' => PHP_EOL,
80+               'link_class' => '',
81+               'image_class' => '',
82+               'gallery' => '[gallery]',
83+               'audio' => '[audio]',
84+               'video' => '[video]'
85+       );
86+
87+       $args = apply_filters( 'post_format_compat', array() );
88+       $compat = wp_parse_args( $args, $defaults );
89+
90+       $show_content = true;
91+       $format_output = '';
92+       $meta = get_post_format_meta( $post->ID );
93+
94+       switch ( $format ) {
95+       case 'link':
96+               $compat['tag'] = '';
97+
98+               if ( ! empty( $meta['url'] ) ) {
99+                       $esc_url = preg_quote( $meta['url'], '#' );
100+                       // Make sure the same URL isn't in the post (modified/extended versions allowed)
101+                       if ( ! preg_match( '#' . $esc_url . '[^/&\?]#', $content ) ) {
102+                               $format_output .= sprintf(
103+                                       '<a %shref="%s">%s</a>',
104+                                       empty( $compat['link_class'] ) ? '' : sprintf( 'class="%s" ', $compat['link_class'] ),
105+                                       esc_url( $meta['url'] ),
106+                                       empty( $post->post_title ) ? esc_url( $meta['url'] ) : apply_filters( 'the_title', $post->post_title )
107+                               );
108+                       }
109+               }
110+               break;
111+
112+       case 'quote':
113+               if ( ! empty( $meta['quote'] ) && ! stristr( $content, $meta['quote'] ) ) {
114+                       $format_output .= sprintf( '<blockquote>%s</blockquote>', $meta['quote'] );
115+                       if ( ! empty( $meta['quote_source'] ) ) {
116+                               $format_output .= sprintf(
117+                                       '<cite>%s</cite>',
118+                                       ! empty( $meta['url'] ) ?
119+                                               sprintf( '<a href="%s">%s</a>', esc_url( $meta['url'] ), $meta['quote_source'] ) :
120+                                               $meta['quote_source']
121+                               );
122+                       }
123+               }
124+               break;
125+
126+       case 'image':
127+               if ( ! empty( $meta['image'] ) ) {
128+                       $image = is_numeric( $meta['image'] ) ? wp_get_attachment_url( $meta['image'] ) : $meta['image'];
129+
130+                       if ( ! empty( $image ) && ! stristr( $content, $image ) ) {
131+                               $image_html = sprintf(
132+                                       '<img %ssrc="%s" alt="" />',
133+                                       empty( $compat['image_class'] ) ? '' : sprintf( 'class="%s" ', $compat['image_class'] ),
134+                                       $image
135+                               );
136+                               if ( empty( $meta['url'] ) ) {
137+                                       $format_output .= $image_html;
138+                               } else {
139+                                       $format_output .= sprintf(
140+                                               '<a href="%s">%s</a>',
141+                                               esc_url( $meta['url'] ),
142+                                               $image_html
143+                                       );
144+                               }
145+                       }
146+               }
147+               break;
148+
149+       case 'gallery':
150+               preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches );
151+               if ( ! empty( $matches ) && isset( $matches[2] ) ) {
152+                       foreach ( (array) $matches[2] as $match ) {
153+                               if ( 'gallery' === $match )
154+                                       break 2; // foreach + case
155+                       }
156+               }
157+
158+               if ( empty( $meta['gallery'] ) && ! empty( $compat['gallery'] ) ) {
159+                       $format_output .= $compat['gallery'];
160+               } elseif ( ! empty( $meta['gallery'] ) ) {
161+                       $format_output .= $meta['gallery'];
162+               }
163+               break;
164+
165+       case 'video':
166+       case 'audio':
167+               $shortcode_regex = '/' . get_shortcode_regex() . '/s';
168+               $matches = preg_match( $shortcode_regex, $content );
169+               if ( ! $matches || $format !== $matches[2] ) {
170+                       if ( empty( $meta['media'] ) && ! empty( $compat[$format] ) ) {
171+                               $format_output .= $compat[$format];
172+                       } elseif ( ! empty( $meta['media'] ) ) {
173+                               // the metadata is a shortcode or an embed code
174+                               if ( preg_match( $shortcode_regex, $meta['media'] ) || preg_match( '#<[^>]+>#', $meta['media'] ) ) {
175+                                       $format_output .= $meta['media'];
176+                               } elseif ( ! stristr( $content, $meta['media'] ) ) {
177+                                       $mime_type = wp_check_filetype( $meta['media'] );
178+                                       // URL that can be shortcode'd
179+                                       if ( ! empty( $mime_type['type'] )
180+                                               && ( ( 'video' === $format && 'video/mp4' === $mime_type['type'] )
181+                                                       || ( 'audio' === $format && 'audio/mpeg' === $mime_type['type'] ) ) ) {
182+                                               $format_output .= sprintf( '[%s src="%s"]', $format, esc_url( $meta['media'] ) );
183+                                       // URL that isn't embeddable outputs string
184+                                       } else {
185+                                               $format_output .= sprintf( '[embed]%s[/embed]', $meta['media'] );
186+                                       }
187+                               }
188+                       }
189+               }
190+               break;
191+       default:
192+               return $content;
193+               break;
194+       }
195+
196+       if ( empty( $format_output ) )
197+               return $content;
198+
199+       $output = '';
200+       if ( ! empty( $compat['tag'] ) )
201+               $output .= sprintf( '<%s class="%s">', $compat['tag'], $compat['class'] );
202+
203+       if ( ! empty( $content ) && $show_content && 'before' !== $compat['position'] )
204+               $output .= $content . PHP_EOL . PHP_EOL;
205+
206+       $output .= $format_output;
207+
208+       if ( ! empty( $content ) && $show_content && 'before' === $compat['position'] )
209+               $output .= PHP_EOL . PHP_EOL . $content;
210+
211+       if ( ! empty( $compat['tag'] ) )
212+               $output .= sprintf( '</%s>', $compat['tag'] );;
213+
214+       return $output;
215+}
216+
217+/**
218  * Verifies that an email is valid.
219  *
220  * Does not grok i18n domains. Not RFC compliant.