/** * Test if the site was added as an oEmbed provider. */ function test_add_oembed_provider() { $oembed = _wp_oembed_get_object(); wp_oembed_remove_provider(home_url('/*')); $this->assertArrayNotHasKey(home_url('/*'), $oembed->providers); $this->plugin()->add_oembed_provider(); $this->assertArrayHasKey(home_url('/*'), $oembed->providers); $this->assertEquals(array(esc_url(rest_url('wp/v2/oembed')), false), $oembed->providers[home_url('/*')]); }
/** * Test if the site was added as an oEmbed provider. */ function test_add_oembed_provider() { $oembed = _wp_oembed_get_object(); wp_oembed_remove_provider(home_url('/*')); $this->assertArrayNotHasKey(home_url('/*'), $oembed->providers); wp_oembed_add_site_as_provider(); $this->assertArrayHasKey(home_url('/*'), $oembed->providers); $this->assertEquals(array(get_oembed_endpoint_url(), false), $oembed->providers[home_url('/*')]); }
} // Since we support Instagram via oEmbed, we simply leave a link on a line by itself. $replace_regex = sprintf('#\\s*%s\\s*#', preg_quote($match[0], '#')); $url = esc_url($url_matches[0]); $content = preg_replace($replace_regex, sprintf("\n\n%s\n\n", $url), $content); /** This action is documented in modules/shortcodes/youtube.php */ do_action('jetpack_embed_to_shortcode', 'instagram', $url); } } return $content; } add_filter('pre_kses', 'jetpack_instagram_embed_reversal'); /** * Instagram */ wp_oembed_remove_provider('#https?://(www\\.)?instagr(\\.am|am\\.com)/p/.*#i'); // remove core's oEmbed support so we can override wp_embed_register_handler('jetpack_instagram', '#http(s?)://(www\\.)?instagr(\\.am|am\\.com)/p/([^/]*)#i', 'jetpack_instagram_handler'); function jetpack_instagram_handler($matches, $atts, $url) { global $content_width; // keep a copy of the passed-in URL since it's modified below $passed_url = $url; $max_width = 698; $min_width = 320; if (is_feed()) { $media_url = sprintf('http://instagr.am/p/%s/media/?size=l', $matches[4]); return sprintf('<a href="%s" title="%s" target="_blank"><img src="%s" alt="Instagram Photo" /></a>', esc_url($url), esc_attr__('View on Instagram', 'jetpack'), esc_url($media_url)); } $atts = shortcode_atts(array('width' => isset($content_width) ? $content_width : $max_width, 'hidecaption' => false), $atts); $atts['width'] = absint($atts['width']);
function test_add_remove_oembed_provider() { wp_oembed_add_provider( 'http://foo.bar/*', 'http://foo.bar/oembed' ); $this->assertTrue( wp_oembed_remove_provider( 'http://foo.bar/*' ) ); $this->assertFalse( wp_oembed_remove_provider( 'http://foo.bar/*' ) ); }
continue; } // Since we support Instagram via oEmbed, we simply leave a link on a line by itself. $replace_regex = sprintf('#\\s*%s\\s*#', preg_quote($match[0], '#')); $url = esc_url($url_matches[0]); $content = preg_replace($replace_regex, sprintf("\n\n%s\n\n", $url), $content); do_action('jetpack_embed_to_shortcode', 'instagram', $url); } } return $content; } add_filter('pre_kses', 'jetpack_instagram_embed_reversal'); /** * Instagram */ wp_oembed_remove_provider('#http://instagr(\\.am|am\\.com)/p/.*#i'); // remove core's oEmbed support so we can override wp_embed_register_handler('jetpack_instagram', '#http(s?)://instagr(\\.am|am\\.com)/p/([^/]*)#i', 'jetpack_instagram_handler'); function jetpack_instagram_handler($matches, $atts, $url) { global $content_width; static $did_script; // keep a copy of the passed-in URL since it's modified below $passed_url = $url; $max_width = 698; $min_width = 320; if (is_feed()) { $media_url = sprintf('http://instagr.am/p/%s/media/?size=l', $matches[2]); return sprintf('<a href="%s" title="%s"><img src="%s" alt="Instagram Photo" /></a>', esc_url($url), esc_attr__('View on Instagram', 'jetpack'), esc_url($media_url)); } $atts = shortcode_atts(array('width' => isset($content_width) ? $content_width : $max_width, 'hidecaption' => false), $atts);
<?php // guarantee use of https wp_oembed_remove_provider('#https?://(www\\.)?slideshare\\.net/.*#i'); wp_oembed_add_provider('#https?://(www\\.)?slideshare\\.net/.*#i', 'https://www.slideshare.net/api/oembed/2', true); /* * Slideshare shortcode format: * Old style (still compatible): [slideshare id=5342235&doc=camprock-101002163655-phpapp01&w=300&h=200] * New style: [slideshare id=5342235&w=300&h=200&fb=0&mw=0&mh=0&sc=no] * * Legend: * id = Document ID provided by Slideshare * w = Width of iFrame (int) * h = Height of iFrame (int) * fb = iFrame frameborder (int) * mw = iFrame marginwidth (int) * mh = iFrame marginheight (int) * sc = iFrame Scrollbar (yes/no) **/ add_shortcode('slideshare', 'slideshare_shortcode'); function slideshare_shortcode($atts) { global $content_width; $params = shortcode_new_to_old_params($atts); parse_str($params, $arguments); if (empty($arguments)) { return '<!-- SlideShare error: no arguments -->'; } extract($arguments); // check that the Slideshare ID contains letters, numbers and query strings $pattern = '/[^-_a-zA-Z0-9?=&]/';
/** * Attach handlers for embedded Tweets * * @since 1.0.0 * * @return void */ public static function init() { // register our shortcode and its handler add_shortcode(self::SHORTCODE_TAG, array(__CLASS__, 'shortcodeHandler')); // Shortcode UI, if supported add_action('register_shortcode_ui', array(__CLASS__, 'shortcodeUI'), 5, 0); if (!is_admin()) { // unhook the WordPress Core oEmbed handler wp_oembed_remove_provider(static::OEMBED_CORE_REGEX); // pass a Tweet detail URL through the Tweet shortcode handler wp_embed_register_handler(self::SHORTCODE_TAG, static::TWEET_URL_REGEX, array(__CLASS__, 'linkHandler'), 1); } }
/** * Attach handlers for Vine * * @since 1.3.0 * * @return void */ public static function init() { $classname = get_called_class(); // register our shortcode and its handler add_shortcode(static::SHORTCODE_TAG, array($classname, 'shortcodeHandler')); // unhook the WordPress Core oEmbed handler wp_oembed_remove_provider(static::OEMBED_CORE_REGEX); // convert a URL into the shortcode equivalent wp_embed_register_handler(static::SHORTCODE_TAG, static::URL_REGEX, array($classname, 'linkHandler'), 1); // Shortcode UI, if supported add_action('register_shortcode_ui', array($classname, 'shortcodeUI'), 5, 0); }
/** * Remove the Wordpress default Oembed support for video providers that ARVE Supports. Array taken from wp-includes/class-oembed.php __construct * * @since 5.9.9 * */ public function oembed_remove_providers() { $wp_core_oembed_shits = array('#http://(www\\.)?youtube\\.com/watch.*#i' => array('http://www.youtube.com/oembed', true), '#https://(www\\.)?youtube\\.com/watch.*#i' => array('http://www.youtube.com/oembed?scheme=https', true), '#http://youtu\\.be/.*#i' => array('http://www.youtube.com/oembed', true), '#https://youtu\\.be/.*#i' => array('http://www.youtube.com/oembed?scheme=https', true), 'http://blip.tv/*' => array('http://blip.tv/oembed/', false), '#https?://(.+\\.)?vimeo\\.com/.*#i' => array('http://vimeo.com/api/oembed.{format}', true), '#https?://(www\\.)?dailymotion\\.com/.*#i' => array('http://www.dailymotion.com/services/oembed', true), 'http://dai.ly/*' => array('http://www.dailymotion.com/services/oembed', false), '#https?://(www\\.)?funnyordie\\.com/videos/.*#i' => array('http://www.funnyordie.com/oembed', true), '#https?://vine.co/v/.*#i' => array('https://vine.co/oembed.{format}', true), '#https?://(www\\.)?collegehumor\\.com/video/.*#i' => array('http://www.collegehumor.com/oembed.{format}', true), '#https?://(www\\.|embed\\.)?ted\\.com/talks/.*#i' => array('http://www.ted.com/talks/oembed.{format}', true)); foreach ($wp_core_oembed_shits as $shit => $f**k) { wp_oembed_remove_provider($shit); } // Jetpack shit remove_shortcode('dailymotion', 'dailymotion_shortcode'); remove_filter('pre_kses', 'jetpack_dailymotion_embed_reversal'); remove_filter('pre_kses', 'dailymotion_embed_to_shortcode'); remove_shortcode('vimeo', 'vimeo_shortcode'); remove_filter('pre_kses', 'vimeo_embed_to_shortcode'); wp_embed_unregister_handler('jetpack_vine'); remove_shortcode('vine', 'vine_shortcode'); remove_filter('pre_kses', 'youtube_embed_to_short_code'); remove_shortcode('youtube', 'youtube_shortcode'); remove_shortcode('ted', 'shortcode_ted'); wp_oembed_remove_provider('!https?://(www\\.)?ted.com/talks/view/id/.+!i'); wp_oembed_remove_provider('!https?://(www\\.)?ted.com/talks/[a-zA-Z\\-\\_]+\\.html!i'); remove_filter('pre_kses', 'blip_embed_to_shortcode'); remove_shortcode('blip.tv', 'blip_shortcode'); }
/** * register oembed for images, and remove imgur.com default embed so lightbox can use imgur.com images * * @since 1.0 */ function embeds() { wp_embed_register_handler('detect_lightbox', '#^http://.+\\.(jpe?g|gif|png)$#i', array($this, 'wp_embed_register_handler'), 10, 3); wp_oembed_remove_provider('#https?://(.+\\.)?imgur\\.com/.*#i'); }
/** * Remove oembed handlers that are incompatible with o2 */ public function remove_oembed_handlers() { wp_oembed_remove_provider('#https?://(.+\\.)?polldaddy\\.com/.*#i'); }