wp/wp-includes/class-wp-embed.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * API for easily embedding rich media such as videos and images into content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Embed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
class WP_Embed {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
	public $handlers = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
	public $post_ID;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
	public $usecache = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
	public $linkifunknown = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
	 * When an URL cannot be embedded, return false instead of returning a link
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
	 * or the URL. Bypasses the 'embed_maybe_make_link' filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
	public $return_false_on_fail = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	 * Constructor
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	public function __construct() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		// Hack to get the [embed] shortcode to run before wpautop()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		add_filter( 'the_content', array( $this, 'run_shortcode' ), 8 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		// Shortcode placeholder for strip_shortcodes()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		add_shortcode( 'embed', '__return_false' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		// Attempts to embed all URLs in a post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		add_filter( 'the_content', array( $this, 'autoembed' ), 8 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		// After a post is saved, cache oEmbed items via AJAX
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	 * Process the [embed] shortcode.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	 * Since the [embed] shortcode needs to be run earlier than other shortcodes,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	 * this function removes all existing shortcodes, registers the [embed] shortcode,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	 * calls {@link do_shortcode()}, and then re-registers the old shortcodes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	 * @uses $shortcode_tags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	 * @param string $content Content to parse
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	 * @return string Content with shortcode parsed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
	public function run_shortcode( $content ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
		global $shortcode_tags;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		// Back up current registered shortcodes and clear them all out
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
		$orig_shortcode_tags = $shortcode_tags;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		remove_all_shortcodes();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		add_shortcode( 'embed', array( $this, 'shortcode' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		// Do the shortcode (only the [embed] one is registered)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		$content = do_shortcode( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
		// Put the original shortcodes back
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		$shortcode_tags = $orig_shortcode_tags;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
		return $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	 * If a post/page was saved, then output JavaScript to make
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	 * an AJAX request that will call WP_Embed::cache_oembed().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
	public function maybe_run_ajax_cache() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
		$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
		if ( ! $post || empty( $_GET['message'] ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	jQuery(document).ready(function($){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		$.get("<?php echo admin_url( 'admin-ajax.php?action=oembed-cache&post=' . $post->ID, 'relative' ); ?>");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	 * Register an embed handler. Do not use this function directly, use {@link wp_embed_register_handler()} instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	 * This function should probably also only be used for sites that do not support oEmbed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	 * @param string $id An internal ID/name for the handler. Needs to be unique.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	 * @param string $regex The regex that will be used to see if this handler should be used for a URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	 * @param callback $callback The callback function that will be called if the regex is matched.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	 * @param int $priority Optional. Used to specify the order in which the registered handlers will be tested (default: 10). Lower numbers correspond with earlier testing, and handlers with the same priority are tested in the order in which they were added to the action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
	public function register_handler( $id, $regex, $callback, $priority = 10 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
		$this->handlers[$priority][$id] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
			'regex'    => $regex,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
			'callback' => $callback,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
	 * Unregister a previously registered embed handler. Do not use this function directly, use {@link wp_embed_unregister_handler()} instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	 * @param string $id The handler ID that should be removed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	 * @param int $priority Optional. The priority of the handler to be removed (default: 10).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
	public function unregister_handler( $id, $priority = 10 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
		if ( isset($this->handlers[$priority][$id]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
			unset($this->handlers[$priority][$id]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	 * The {@link do_shortcode()} callback function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
	 * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	 * If none of the regex matches and it's enabled, then the URL will be given to the {@link WP_oEmbed} class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
	 * @param array $attr {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
	 *     Shortcode attributes. Optional.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
	 *     @type int $width  Width of the embed in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
	 *     @type int $height Height of the embed in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
	 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	 * @param string $url The URL attempting to be embedded.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	 * @return string|false The embed HTML on success, otherwise the original URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
	 *                      `->maybe_make_link()` can return false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
	public function shortcode( $attr, $url = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
		if ( empty( $url ) && ! empty( $attr['src'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
			$url = $attr['src'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
		if ( empty( $url ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
			return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
		$rawattr = $attr;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
		$attr = wp_parse_args( $attr, wp_embed_defaults( $url ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
		// kses converts & into &amp; and we need to undo this
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
		// See https://core.trac.wordpress.org/ticket/11311
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
		$url = str_replace( '&amp;', '&', $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
		// Look for known internal handlers
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
		ksort( $this->handlers );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
		foreach ( $this->handlers as $priority => $handlers ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
			foreach ( $handlers as $id => $handler ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
				if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
					if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
						/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
						 * Filter the returned embed handler.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
						 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
						 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
						 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
						 * @see WP_Embed::shortcode()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
						 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
						 * @param mixed  $return The shortcode callback function to call.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
						 * @param string $url    The attempted embed URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
						 * @param array  $attr   An array of shortcode attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
						 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
						return apply_filters( 'embed_handler_html', $return, $url, $attr );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
		$post_ID = ( ! empty( $post->ID ) ) ? $post->ID : null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		if ( ! empty( $this->post_ID ) ) // Potentially set by WP_Embed::cache_oembed()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
			$post_ID = $this->post_ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
		// Unknown URL format. Let oEmbed have a go.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
		if ( $post_ID ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
			// Check for a cached result (stored in the post meta)
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
			$key_suffix = md5( $url . serialize( $attr ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
			$cachekey = '_oembed_' . $key_suffix;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
			$cachekey_time = '_oembed_time_' . $key_suffix;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
			 * Filter the oEmbed TTL value (time to live).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
			 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
			 * @param int    $time    Time to live (in seconds).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
			 * @param string $url     The attempted embed URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
			 * @param array  $attr    An array of shortcode attributes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
			 * @param int    $post_ID Post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
			$ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, $attr, $post_ID );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
			$cache = get_post_meta( $post_ID, $cachekey, true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
			$cache_time = get_post_meta( $post_ID, $cachekey_time, true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
			if ( ! $cache_time ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
				$cache_time = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
			$cached_recently = ( time() - $cache_time ) < $ttl;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
			if ( $this->usecache || $cached_recently ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
				// Failures are cached. Serve one if we're using the cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
				if ( '{{unknown}}' === $cache )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
					return $this->maybe_make_link( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
				if ( ! empty( $cache ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
					/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
					 * Filter the cached oEmbed HTML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
					 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
					 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
					 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   214
					 * @see WP_Embed::shortcode()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
					 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
					 * @param mixed  $cache   The cached HTML result, stored in post meta.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
					 * @param string $url     The attempted embed URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
					 * @param array  $attr    An array of shortcode attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
					 * @param int    $post_ID Post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
					 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
					return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
			/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
			 * Filter whether to inspect the given URL for discoverable link tags.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
			 * @since 2.9.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
			 * @see WP_oEmbed::discover()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
			 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
			 * @param bool $enable Whether to enable `<link>` tag discovery. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
			$attr['discover'] = ( apply_filters( 'embed_oembed_discover', false ) && author_can( $post_ID, 'unfiltered_html' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
			// Use oEmbed to get the HTML
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
			$html = wp_oembed_get( $url, $attr );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
			// Maybe cache the result
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
			if ( $html ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
				update_post_meta( $post_ID, $cachekey, $html );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
				update_post_meta( $post_ID, $cachekey_time, time() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
			} elseif ( ! $cache ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
				update_post_meta( $post_ID, $cachekey, '{{unknown}}' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			// If there was a result, return it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
			if ( $html ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
				/** This filter is documented in wp-includes/class-wp-embed.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
				return apply_filters( 'embed_oembed_html', $html, $url, $attr, $post_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
		// Still unknown
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		return $this->maybe_make_link( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
	 * Delete all oEmbed caches. Unused by core as of 4.0.0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
	 * @param int $post_ID Post ID to delete the caches for.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
	public function delete_oembed_caches( $post_ID ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
		$post_metas = get_post_custom_keys( $post_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
		if ( empty($post_metas) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		foreach( $post_metas as $post_meta_key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
			if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
				delete_post_meta( $post_ID, $post_meta_key );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	 * Triggers a caching of all oEmbed results.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
	 * @param int $post_ID Post ID to do the caching for.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
	public function cache_oembed( $post_ID ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
		$post = get_post( $post_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
		$post_types = get_post_types( array( 'show_ui' => true ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
		 * Filter the array of post types to cache oEmbed results for.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
		 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
		 * @param array $post_types Array of post types to cache oEmbed results for. Defaults to post types with `show_ui` set to true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
		if ( empty( $post->ID ) || ! in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', $post_types ) ) ){
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
		// Trigger a caching
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
		if ( ! empty( $post->post_content ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
			$this->post_ID = $post->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
			$this->usecache = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
			$content = $this->run_shortcode( $post->post_content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
			$this->autoembed( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
			$this->usecache = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	 * Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} for potential embedding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	 * @uses WP_Embed::autoembed_callback()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
	 * @param string $content The content to be searched.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
	 * @return string Potentially modified $content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
	public function autoembed( $content ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
		return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
	 * Callback function for {@link WP_Embed::autoembed()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
	 * @param array $match A regex match array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
	 * @return string The embed HTML on success, otherwise the original URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
	public function autoembed_callback( $match ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
		$oldval = $this->linkifunknown;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		$this->linkifunknown = false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
		$return = $this->shortcode( array(), $match[2] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
		$this->linkifunknown = $oldval;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
		return $match[1] . $return . $match[3];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	 * Conditionally makes a hyperlink based on an internal class variable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	 * @param string $url URL to potentially be linked.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
	 * @return false|string Linked URL or the original URL. False if 'return_false_on_fail' is true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
	public function maybe_make_link( $url ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
		if ( $this->return_false_on_fail ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
			return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
		$output = ( $this->linkifunknown ) ? '<a href="' . esc_url($url) . '">' . esc_html($url) . '</a>' : $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
		 * Filter the returned, maybe-linked embed URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
		 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		 * @param string $output The linked or original URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		 * @param string $url    The original URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
		return apply_filters( 'embed_maybe_make_link', $output, $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
$GLOBALS['wp_embed'] = new WP_Embed();