本文整理汇总了PHP中_wp_oembed_get_object函数的典型用法代码示例。如果您正苦于以下问题:PHP _wp_oembed_get_object函数的具体用法?PHP _wp_oembed_get_object怎么用?PHP _wp_oembed_get_object使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_wp_oembed_get_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
require_once ABSPATH . WPINC . '/class-oembed.php';
$this->oembed = _wp_oembed_get_object();
$this->pre_oembed_result_filtered = false;
}
示例2: callback
function callback($path = '', $blog_id = 0)
{
$blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
if (is_wp_error($blog_id)) {
return $blog_id;
}
// permissions check
if (!current_user_can('edit_posts')) {
return new WP_Error('unauthorized', 'Your token must have permission to post on this blog.', 403);
}
// list em
$output = array('embeds' => array());
if (!function_exists('_wp_oembed_get_object')) {
require_once ABSPATH . WPINC . '/class-oembed.php';
}
global $wp_embed;
$oembed = _wp_oembed_get_object();
foreach ($wp_embed->handlers as $priority => $handlers) {
foreach ($handlers as $handler) {
if (!empty($handler['regex'])) {
$output['embeds'][] = $handler['regex'];
}
}
}
foreach ($oembed->providers as $regex => $oembed_info) {
if (!empty($regex)) {
$output['embeds'][] = $regex;
}
}
return $output;
}
示例3: __construct
public function __construct()
{
// Does not extend oEmbed in order to not initialize it a second time.
require_once ABSPATH . '/' . WPINC . '/class-oembed.php';
$this->oembed = _wp_oembed_get_object();
add_filter('oembed_fetch_url', array($this, 'additional_arguments'), 10, 3);
}
示例4: __construct
public function __construct($url = false)
{
if (!function_exists('_wp_oembed_get_object')) {
require_once ABSPATH . WPINC . '/class-oembed.php';
}
$this->_wp_oembed = _wp_oembed_get_object();
$this->set_url($url);
}
示例5: test_add_oembed_provider
/**
* 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('/*')]);
}
示例6: test_add_oembed_provider
/**
* 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('/*')]);
}
示例7: paragraph_not_contains_element
public function paragraph_not_contains_element($paragraph)
{
require_once ABSPATH . WPINC . '/class-oembed.php';
$wp_oembed = _wp_oembed_get_object();
preg_match_all('|^\\s*(https?://[^\\s"]+)\\s*$|im', $paragraph, $matches);
foreach ($matches[1] as $match) {
if ($wp_oembed->get_provider($match, array('discover' => false))) {
return false;
}
}
return true;
}
示例8: render_field
/**
* Render only field html
*
* @return string
*/
public function render_field()
{
if ($this->get_value()) {
require_once ABSPATH . WPINC . '/class-oembed.php';
/* @var \WP_oEmbed $oembed */
$oembed = _wp_oembed_get_object();
$provider = $oembed->get_provider($this->get_value());
$data = $oembed->fetch($provider, $this->get_value());
$this->_video = $data;
}
return sprintf('<input type="text" name="%s" id="%s" class="video_field %s" value="%s" placeholder="%s" %s />
%s<div class="video_info">%s</div>', $this->get_name(), $this->get_id(), $this->_get_classes(), $this->get_value(), $this->get_placeholder(), $this->_get_attributes(), $this->_get_description(), $this->_get_video_info());
}
示例9: jetpack_houzz_shortcode
function jetpack_houzz_shortcode($atts, $content = null)
{
$url = substr($atts[0], 1);
$args = array();
if (isset($atts['w']) && is_numeric($atts['w'])) {
$args['width'] = $atts['w'];
}
if (isset($atts['h']) && is_numeric($atts['h'])) {
$args['height'] = $atts['h'];
}
$oembed = _wp_oembed_get_object();
return $oembed->get_html($url, $args);
}
示例10: mk_theme_oembed_audios
function mk_theme_oembed_audios()
{
global $post;
if ($post && $post->post_content) {
global $shortcode_tags;
// Make a copy of global shortcode tags - we'll temporarily overwrite it.
$theme_shortcode_tags = $shortcode_tags;
// The shortcodes we're interested in.
$shortcode_tags = array('audio' => $theme_shortcode_tags['audio'], 'embed' => $theme_shortcode_tags['embed']);
// Get the absurd shortcode regexp.
$audio_regex = '#' . get_shortcode_regex() . '#i';
// Restore global shortcode tags.
$shortcode_tags = $theme_shortcode_tags;
$pattern_array = array($audio_regex);
// Get the patterns from the embed object.
if (!function_exists('_wp_oembed_get_object')) {
include ABSPATH . WPINC . '/class-oembed.php';
}
$oembed = _wp_oembed_get_object();
$pattern_array = array_merge($pattern_array, array_keys($oembed->providers));
// Or all the patterns together.
$pattern = '#(' . array_reduce($pattern_array, function ($carry, $item) {
if (strpos($item, '#') === 0) {
// Assuming '#...#i' regexps.
$item = substr($item, 1, -2);
} else {
// Assuming glob patterns.
$item = str_replace('*', '(.+)', $item);
}
return $carry ? $carry . ')|(' . $item : $item;
}) . ')#is';
// Simplistic parse of content line by line.
$lines = explode("\n", $post->post_content);
foreach ($lines as $line) {
$line = trim($line);
if (preg_match($pattern, $line, $matches)) {
if (strpos($matches[0], '[') === 0) {
$ret = do_shortcode($matches[0]);
} else {
$ret = wp_oembed_get($matches[0]);
}
return $ret;
}
}
}
}
示例11: extract_from_content
//.........这里部分代码省略.........
// ----------------------------------- LINKS ------------------------------
if (self::LINKS & $what_to_extract) {
// To hold the extracted stuff we find
$links = array();
// @todo Get the text inside the links?
// Grab any links, whether in <a href="..." or not, but subtract those from shortcodes and images
// (we treat embed links as just another link)
if (preg_match_all('#(?:^|\\s|"|\')(https?://([^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|/))))#', $content, $matches)) {
foreach ($matches[1] as $link_raw) {
$url = parse_url($link_raw);
// Build a simple form of the URL so we can compare it to ones we found in IMAGES or SHORTCODES and exclude those
$simple_url = $url['scheme'] . '://' . $url['host'] . (!empty($url['path']) ? $url['path'] : '');
if (isset($extracted['image']['url'])) {
if (in_array($simple_url, (array) $extracted['image']['url'])) {
continue;
}
}
list($proto, $link_all_but_proto) = explode('://', $link_raw);
// Build a reversed hostname
$host_parts = array_reverse(explode('.', $url['host']));
$host_reversed = '';
foreach ($host_parts as $part) {
$host_reversed .= (!empty($host_reversed) ? '.' : '') . $part;
}
$link_analyzed = '';
if (!empty($url['path'])) {
// The whole path (no query args or fragments)
$path = substr($url['path'], 1);
// strip the leading '/'
$link_analyzed .= (!empty($link_analyzed) ? ' ' : '') . $path;
// The path split by /
$path_split = explode('/', $path);
if (count($path_split) > 1) {
$link_analyzed .= ' ' . implode(' ', $path_split);
}
// The fragment
if (!empty($url['fragment'])) {
$link_analyzed .= (!empty($link_analyzed) ? ' ' : '') . $url['fragment'];
}
}
// @todo Check unique before adding
$links[] = array('url' => $link_all_but_proto, 'host_reversed' => $host_reversed, 'host' => $url['host']);
}
}
$link_count = count($links);
$extracted['link'] = $links;
if ($link_count) {
if (!isset($extracted['has'])) {
$extracted['has'] = array();
}
$extracted['has']['link'] = $link_count;
}
}
// ----------------------------------- EMBEDS ------------------------------
//Embeds are just individual links on their own line
if (self::EMBEDS & $what_to_extract) {
if (!function_exists('_wp_oembed_get_object')) {
include ABSPATH . WPINC . '/class-oembed.php';
}
// get an oembed object
$oembed = _wp_oembed_get_object();
// Grab any links on their own lines that may be embeds
if (preg_match_all('|^\\s*(https?://[^\\s"]+)\\s*$|im', $content, $matches)) {
// To hold the extracted stuff we find
$embeds = array();
foreach ($matches[1] as $link_raw) {
$url = parse_url($link_raw);
list($proto, $link_all_but_proto) = explode('://', $link_raw);
// Check whether this "link" is really an embed.
foreach ($oembed->providers as $matchmask => $data) {
list($providerurl, $regex) = $data;
// Turn the asterisk-type provider URLs into regex
if (!$regex) {
$matchmask = '#' . str_replace('___wildcard___', '(.+)', preg_quote(str_replace('*', '___wildcard___', $matchmask), '#')) . '#i';
$matchmask = preg_replace('|^#http\\\\://|', '#https?\\://', $matchmask);
}
if (preg_match($matchmask, $link_raw)) {
$provider = str_replace('{format}', 'json', $providerurl);
// JSON is easier to deal with than XML
$embeds[] = $link_all_but_proto;
// @todo Check unique before adding
// @todo Try to get ID's for the ones we care about (shortcode_keepers)
break;
}
}
}
if (!empty($embeds)) {
if (!isset($extracted['has'])) {
$extracted['has'] = array();
}
$extracted['has']['embed'] = count($embeds);
$extracted['embed'] = array('url' => array());
foreach ($embeds as $e) {
$extracted['embed']['url'][] = $e;
}
}
}
}
return $extracted;
}
示例12: wpSetUpBeforeClass
public static function wpSetUpBeforeClass()
{
self::$oembed = _wp_oembed_get_object();
}
示例13: shortcode
/**
* The {@link do_shortcode()} callback function.
*
* Attempts to convert a URL into embed HTML. Starts by checking the
* URL against the regex of the registered embed handlers. Next, checks
* the URL against the regex of registered {@link WP_oEmbed} providers
* if oEmbed discovery is false. If none of the regex matches and it's
* enabled, then the URL will be passed to {@link BP_Embed::parse_oembed()}
* for oEmbed parsing.
*
* @uses wp_parse_args()
* @uses wp_embed_defaults()
* @uses current_user_can()
* @uses _wp_oembed_get_object()
* @uses WP_Embed::maybe_make_link()
*
* @param array $attr Shortcode attributes.
* @param string $url The URL attempting to be embeded.
* @return string The embed HTML on success, otherwise the original URL.
*/
public function shortcode($attr, $url = '')
{
if (empty($url)) {
return '';
}
$rawattr = $attr;
$attr = wp_parse_args($attr, wp_embed_defaults());
// Use kses to convert & into & and we need to undo this
// See https://core.trac.wordpress.org/ticket/11311.
$url = str_replace('&', '&', $url);
// Look for known internal handlers.
ksort($this->handlers);
foreach ($this->handlers as $priority => $handlers) {
foreach ($handlers as $hid => $handler) {
if (preg_match($handler['regex'], $url, $matches) && is_callable($handler['callback'])) {
if (false !== ($return = call_user_func($handler['callback'], $matches, $attr, $url, $rawattr))) {
/**
* Filters the oEmbed handler result for the provided URL.
*
* @since 1.5.0
*
* @param string $return Handler callback for the oEmbed.
* @param string $url URL attempting to be embedded.
* @param array $attr Shortcode attributes.
*/
return apply_filters('embed_handler_html', $return, $url, $attr);
}
}
}
}
/**
* Filters the embed object ID.
*
* @since 1.5.0
*
* @param int $value Value of zero.
*/
$id = apply_filters('embed_post_id', 0);
$unfiltered_html = current_user_can('unfiltered_html');
$default_discovery = false;
// Since 4.4, WordPress is now an oEmbed provider.
if (function_exists('wp_oembed_register_route')) {
$unfiltered_html = true;
$default_discovery = true;
}
/**
* Filters whether or not oEmbed discovery is on.
*
* @since 1.5.0
* @since 2.5.0 Default status of oEmbed discovery has been switched
* to true to apply changes introduced in WordPress 4.4
*
* @param bool $default_discovery Current status of oEmbed discovery.
*/
$attr['discover'] = apply_filters('bp_embed_oembed_discover', $default_discovery) && $unfiltered_html;
// Set up a new WP oEmbed object to check URL with registered oEmbed providers.
require_once ABSPATH . WPINC . '/class-oembed.php';
$oembed_obj = _wp_oembed_get_object();
// If oEmbed discovery is true, skip oEmbed provider check.
$is_oembed_link = false;
if (!$attr['discover']) {
foreach ((array) $oembed_obj->providers as $provider_matchmask => $provider) {
$regex = ($is_regex = $provider[1]) ? $provider_matchmask : '#' . str_replace('___wildcard___', '(.+)', preg_quote(str_replace('*', '___wildcard___', $provider_matchmask), '#')) . '#i';
if (preg_match($regex, $url)) {
$is_oembed_link = true;
}
}
// If url doesn't match a WP oEmbed provider, stop parsing.
if (!$is_oembed_link) {
return $this->maybe_make_link($url);
}
}
return $this->parse_oembed($id, $url, $attr, $rawattr);
}
示例14: _limit_embed
/**
* Limit embed source URLs to specific providers.
*
* Not all core oEmbed providers are supported. Supported providers include YouTube, Vimeo,
* Vine, Daily Motion, SoundCloud, and Twitter.
*
* @ignore
* @since 4.2.0
*
* @param string $src Embed source URL.
* @return string If not from a supported provider, an empty string. Otherwise, a reformattd embed URL.
*/
private function _limit_embed($src)
{
$src = $this->_limit_url($src);
if (empty($src)) {
return '';
}
if (preg_match('!//(m|www)\\.youtube\\.com/(embed|v)/([^?]+)\\?.+$!i', $src, $src_matches)) {
// Embedded Youtube videos (www or mobile)
$src = 'https://www.youtube.com/watch?v=' . $src_matches[3];
} else {
if (preg_match('!//player\\.vimeo\\.com/video/([\\d]+)([?/].*)?$!i', $src, $src_matches)) {
// Embedded Vimeo iframe videos
$src = 'https://vimeo.com/' . (int) $src_matches[1];
} else {
if (preg_match('!//vimeo\\.com/moogaloop\\.swf\\?clip_id=([\\d]+)$!i', $src, $src_matches)) {
// Embedded Vimeo Flash videos
$src = 'https://vimeo.com/' . (int) $src_matches[1];
} else {
if (preg_match('!//vine\\.co/v/([^/]+)/embed!i', $src, $src_matches)) {
// Embedded Vine videos
$src = 'https://vine.co/v/' . $src_matches[1];
} else {
if (preg_match('!//(www\\.)?dailymotion\\.com/embed/video/([^/?]+)([/?].+)?!i', $src, $src_matches)) {
// Embedded Daily Motion videos
$src = 'https://www.dailymotion.com/video/' . $src_matches[2];
} else {
$oembed = _wp_oembed_get_object();
if (!$oembed->get_provider($src, array('discover' => false))) {
$src = '';
}
}
}
}
}
}
return $src;
}
示例15: filter_content
/**
* Save via AJAX the height of the preview wrap.
*
* @since 2.0.1
*/
public function filter_content($content)
{
global $post;
$typenow = get_post_type();
$editor = get_post_meta($post->ID, 'pixBuilderDisable', true);
if ($typenow == 'page') {
$display = true;
} else {
$display = false;
}
$row_open = apply_filters('pixgridder_row_open', "<div class=\"row\" data-cols=\"\$1\">");
$row_close = apply_filters('pixgridder_row_close', "</div><!--.row[data-cols=\"\$1\"]-->");
$column_open = apply_filters('pixgridder_column_open', "<div class=\"column\" data-col=\"\$1\">");
$column_close = apply_filters('pixgridder_column_close', "</div><!--.column[data-col=\"\$1\"]-->");
if ($display == true) {
require_once ABSPATH . WPINC . '/class-oembed.php';
$oembed = _wp_oembed_get_object();
$providers = $oembed->providers;
if (!function_exists('pixgridder_match_oembed')) {
function pixgridder_match_oembed($matches)
{
$var = preg_replace('/<p>/', '', $matches[0]);
$var = preg_replace('/<\\/p>/', '', $var);
global $wp_embed;
return $wp_embed->autoembed($var);
}
}
foreach ($providers as $key => $value) {
if (substr($key, 0, 1) == '#') {
$content = preg_replace_callback("{$key}", 'pixgridder_match_oembed', $content);
}
}
$content = preg_replace('/data-id\\[(.+?)\\]/', 'id="$1"', $content);
$content = preg_replace('/data-class\\[(.+?)\\]/', 'class="$1"', $content);
$content = preg_replace('/<!--pixgridder:column\\[(.?[^\\]\\s]+)\\]--><!--\\/pixgridder:column(.+?)-->/', '', $content);
$content = preg_replace('/<!--pixgridder:row\\[(.?[^\\]\\s]+)\\]--><!--\\/pixgridder:row(.+?)-->/', '', $content);
$content = preg_replace('/<p><!--pixgridder:(.+?)-->(?!<!--)/', '<!--pixgridder:$1--><p>', $content);
$content = preg_replace('/<p><!--\\/pixgridder:(.+?)-->(?!<!--)/', '<!--/pixgridder:$1--><p>', $content);
$content = preg_replace('/<p><!--pixgridder:(.+?)--><\\/p>/', '<!--pixgridder:$1-->', $content);
$content = preg_replace('/<p><!--\\/pixgridder:(.+?)--><\\/p>/', '<!--/pixgridder:$1-->', $content);
$content = preg_replace('/<!--\\/pixgridder:(.+?)--><p><\\/p>/', '<!--/pixgridder:$1-->', $content);
if (strpos($column_open, ' class=') !== false) {
preg_match('/ class=[\'"](.+?)[\'"]/', $column_open, $class);
$column_open = preg_replace('/ class=[\'"](.+?)[\'"]/', ' class="$1 dollar2"', $column_open);
$column_open = str_replace("dollar2", "\$2", $column_open);
$content = preg_replace('/<!--pixgridder:column(.+?) class="(.+?)"-->/', $column_open, $content);
$column_open = str_replace(" \$2", "", $column_open);
$content = preg_replace('/<!--pixgridder:column(.+?)-->/', $column_open, $content);
$content = preg_replace('/data-col="\\[col=(.?[^\\]\\s]+)\\] id="(.+?)""/', 'data-col="$1" id="$2"', $content);
$content = preg_replace('/data-col="\\[col=(.+?)\\]"/', 'data-col="$1"', $content);
} else {
$content = preg_replace('/<!--pixgridder:column\\[col=(.+?)\\]-->/', $column_open, $content);
$column_open = preg_replace('/<(.+?)>/', '<$1 dollar2>', $column_open);
$column_open = str_replace("dollar2", "\$2", $column_open);
$content = preg_replace('/<!--pixgridder:column\\[col=(.?[^\\]\\s]+)\\](.+?)-->/', $column_open, $content);
}
$content = preg_replace('/ class=/', ' class=', $content);
if (strpos($row_open, ' class=') !== false) {
preg_match('/ class=[\'"](.+?)[\'"]/', $row_open, $class);
$row_open = preg_replace('/ class=[\'"](.+?)[\'"]/', ' class="$1 dollar2"', $row_open);
$row_open = str_replace("dollar2", "\$2", $row_open);
$content = preg_replace('/<!--pixgridder:row(.+?) class="(.+?)"-->/', $row_open, $content);
$row_open = str_replace(" \$2", "", $row_open);
$content = preg_replace('/<!--pixgridder:row(.+?)-->/', $row_open, $content);
$content = preg_replace('/data-cols="\\[cols=(.?[^\\]\\s]+)\\] id="(.+?)""/', 'data-cols="$1" id="$2"', $content);
$content = preg_replace('/data-cols="\\[cols=(.+?)\\]"/', 'data-cols="$1"', $content);
} else {
$content = preg_replace('/<!--pixgridder:row\\[cols=(.+?)\\]-->/', $row_open, $content);
$row_open = preg_replace('/<(.+?)>/', '<$1 dollar2>', $row_open);
$row_open = str_replace("dollar2", "\$2", $row_open);
$content = preg_replace('/<!--pixgridder:row\\[cols=(.?[^\\]\\s]+)\\](.+?)-->/', $row_open, $content);
}
$content = preg_replace('/<!--\\/pixgridder:row\\[cols=(.+?)\\]-->/', $row_close, $content);
$content = preg_replace('/<!--\\/pixgridder:column\\[col=(.+?)\\]-->/', $column_close, $content);
$content = preg_replace('/ class=/', ' class=', $content);
$content = preg_replace('/<p><\\/p>/', '', $content);
} else {
$content = preg_replace('/<!--pixgridder(.+?)-->/', '', $content);
$content = preg_replace('/<!--\\/pixgridder(.+?)-->/', '', $content);
}
return $content;
}