~canonical-sysadmins/wordpress/4.7.2

« back to all changes in this revision

Viewing changes to wp-includes/class-wp-embed.php

  • Committer: Barry Price
  • Date: 2016-08-17 04:50:12 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: barry.price@canonical.com-20160817045012-qfui81zhqnqv2ba9
Merge WP4.6 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
        /**
18
18
         * When a URL cannot be embedded, return false instead of returning a link
19
 
         * or the URL. Bypasses the 'embed_maybe_make_link' filter.
 
19
         * or the URL.
 
20
         *
 
21
         * Bypasses the {@see 'embed_maybe_make_link'} filter.
 
22
         *
 
23
         * @access public
 
24
         * @var bool
20
25
         */
21
26
        public $return_false_on_fail = false;
22
27
 
33
38
                // Attempts to embed all URLs in a post
34
39
                add_filter( 'the_content', array( $this, 'autoembed' ), 8 );
35
40
 
36
 
                // After a post is saved, cache oEmbed items via AJAX
 
41
                // After a post is saved, cache oEmbed items via Ajax
37
42
                add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) );
38
43
                add_action( 'edit_page_form', array( $this, 'maybe_run_ajax_cache' ) );
39
44
        }
43
48
         *
44
49
         * Since the [embed] shortcode needs to be run earlier than other shortcodes,
45
50
         * this function removes all existing shortcodes, registers the [embed] shortcode,
46
 
         * calls {@link do_shortcode()}, and then re-registers the old shortcodes.
 
51
         * calls do_shortcode(), and then re-registers the old shortcodes.
47
52
         *
48
53
         * @global array $shortcode_tags
49
54
         *
70
75
 
71
76
        /**
72
77
         * If a post/page was saved, then output JavaScript to make
73
 
         * an AJAX request that will call WP_Embed::cache_oembed().
 
78
         * an Ajax request that will call WP_Embed::cache_oembed().
74
79
         */
75
80
        public function maybe_run_ajax_cache() {
76
81
                $post = get_post();
88
93
        }
89
94
 
90
95
        /**
91
 
         * Register an embed handler. Do not use this function directly, use {@link wp_embed_register_handler()} instead.
 
96
         * Registers an embed handler.
 
97
         *
 
98
         * Do not use this function directly, use wp_embed_register_handler() instead.
 
99
         *
92
100
         * This function should probably also only be used for sites that do not support oEmbed.
93
101
         *
94
102
         * @param string $id An internal ID/name for the handler. Needs to be unique.
104
112
        }
105
113
 
106
114
        /**
107
 
         * Unregister a previously registered embed handler. Do not use this function directly, use {@link wp_embed_unregister_handler()} instead.
 
115
         * Unregisters a previously-registered embed handler.
 
116
         *
 
117
         * Do not use this function directly, use wp_embed_unregister_handler() instead.
108
118
         *
109
119
         * @param string $id The handler ID that should be removed.
110
120
         * @param int $priority Optional. The priority of the handler to be removed (default: 10).
114
124
        }
115
125
 
116
126
        /**
117
 
         * The {@link do_shortcode()} callback function.
 
127
         * The do_shortcode() callback function.
118
128
         *
119
 
         * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers.
120
 
         * If none of the regex matches and it's enabled, then the URL will be given to the {@link WP_oEmbed} class.
 
129
         * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of
 
130
         * the registered embed handlers. If none of the regex matches and it's enabled, then the URL
 
131
         * will be given to the WP_oEmbed class.
121
132
         *
122
133
         * @param array $attr {
123
134
         *     Shortcode attributes. Optional.
159
170
                                if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
160
171
                                        if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
161
172
                                                /**
162
 
                                                 * Filter the returned embed handler.
 
173
                                                 * Filters the returned embed handler.
163
174
                                                 *
164
175
                                                 * @since 2.9.0
165
176
                                                 *
187
198
                        $cachekey_time = '_oembed_time_' . $key_suffix;
188
199
 
189
200
                        /**
190
 
                         * Filter the oEmbed TTL value (time to live).
 
201
                         * Filters the oEmbed TTL value (time to live).
191
202
                         *
192
203
                         * @since 4.0.0
193
204
                         *
214
225
 
215
226
                                if ( ! empty( $cache ) ) {
216
227
                                        /**
217
 
                                         * Filter the cached oEmbed HTML.
 
228
                                         * Filters the cached oEmbed HTML.
218
229
                                         *
219
230
                                         * @since 2.9.0
220
231
                                         *
230
241
                        }
231
242
 
232
243
                        /**
233
 
                         * Filter whether to inspect the given URL for discoverable link tags.
 
244
                         * Filters whether to inspect the given URL for discoverable link tags.
234
245
                         *
235
246
                         * @since 2.9.0
236
247
                         * @since 4.4.0 The default value changed to true.
289
300
 
290
301
                $post_types = get_post_types( array( 'show_ui' => true ) );
291
302
                /**
292
 
                 * Filter the array of post types to cache oEmbed results for.
 
303
                 * Filters the array of post types to cache oEmbed results for.
293
304
                 *
294
305
                 * @since 2.9.0
295
306
                 *
312
323
        }
313
324
 
314
325
        /**
315
 
         * Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} for potential embedding.
 
326
         * Passes any unlinked URLs that are on their own line to WP_Embed::shortcode() for potential embedding.
316
327
         *
317
 
         * @uses WP_Embed::autoembed_callback()
 
328
         * @see WP_Embed::autoembed_callback()
318
329
         *
319
330
         * @param string $content The content to be searched.
320
331
         * @return string Potentially modified $content.
323
334
                // Replace line breaks from all HTML elements with placeholders.
324
335
                $content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) );
325
336
 
326
 
                // Find URLs that are on their own line.
327
 
                $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
 
337
                if ( preg_match( '#(^|\s|>)https?://#i', $content ) ) {
 
338
                        // Find URLs on their own line.
 
339
                        $content = preg_replace_callback( '|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
 
340
                        // Find URLs in their own paragraph.
 
341
                        $content = preg_replace_callback( '|(<p(?: [^>]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', array( $this, 'autoembed_callback' ), $content );
 
342
                }
328
343
 
329
344
                // Put the line breaks back.
330
345
                return str_replace( '<!-- wp-line-break -->', "\n", $content );
331
346
        }
332
347
 
333
348
        /**
334
 
         * Callback function for {@link WP_Embed::autoembed()}.
 
349
         * Callback function for WP_Embed::autoembed().
335
350
         *
336
351
         * @param array $match A regex match array.
337
352
         * @return string The embed HTML on success, otherwise the original URL.
359
374
                $output = ( $this->linkifunknown ) ? '<a href="' . esc_url($url) . '">' . esc_html($url) . '</a>' : $url;
360
375
 
361
376
                /**
362
 
                 * Filter the returned, maybe-linked embed URL.
 
377
                 * Filters the returned, maybe-linked embed URL.
363
378
                 *
364
379
                 * @since 2.9.0
365
380
                 *