本文整理汇总了PHP中wp_parse_url函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_parse_url函数的具体用法?PHP wp_parse_url怎么用?PHP wp_parse_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_parse_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_from_vulnerabilities_array
/**
* Set the messages array from a vulnerabilities array.
*
* @param array $vulnerabilities Array of vulnerability objects.
*/
public function set_from_vulnerabilities_array(array $vulnerabilities)
{
$this->messages = [];
if (empty($vulnerabilities)) {
return;
}
foreach ($vulnerabilities as $vulnerability) {
$message = ['title' => $vulnerability->title, 'meta' => [], 'links' => []];
if (!is_null($vulnerability->published_date)) {
$message['meta'][] = sprintf('Published %s', $vulnerability->published_date->format('d M Y'));
}
if (isset($vulnerability->references->url)) {
foreach ($vulnerability->references->url as $url) {
$parsed = wp_parse_url($url);
$host = isset($parsed['host']) ? $parsed['host'] : $url;
$message['links'][$url] = $host;
}
}
$message['links'][sprintf('https://wpvulndb.com/vulnerabilities/%s', $vulnerability->id)] = 'wpvulndb.com';
if (is_null($vulnerability->fixed_in)) {
$message['meta'][] = 'Not fixed yet';
} else {
$message['meta'][] = sprintf('Fixed in v%s', $vulnerability->fixed_in);
}
$this->messages[] = $message;
}
}
示例2: is_same_origin
protected function is_same_origin($src)
{
$script_url = wp_parse_url($src);
$home_url = wp_parse_url(home_url());
// Bad URL.
if (!isset($script_url['host']) || !isset($home_url['host'])) {
return true;
}
return $script_url['host'] === $home_url['host'];
}
示例3: twitter_url_to_user
/**
* @param $twitter_profile
*
* @return mixed
* @since 2.3.5
* @since 2.3.5.1 Bail if < WordPress 4.4 for now.
*/
public static function twitter_url_to_user($twitter_profile)
{
// If they're below 4.4 (no wp_parse_url) bail. We can improve this for <4.4 later or just hold out until we drop 4.4 support.
if (!function_exists('wp_parse_url')) {
return $twitter_profile;
}
//extract the twitter username from the url
$parsed_twitter_profile = wp_parse_url($twitter_profile);
$path = $parsed_twitter_profile['path'];
$path_parts = explode('/', $path);
$twitter_profile = $path_parts[1];
return $twitter_profile;
}
示例4: get_video_embed_url
/**
* Convert a "watch" url into an "embed"
* Eg https://www.youtube.com/watch?v=OQZKh8Bjdv0 to https://www.youtube.com/embed/OQZKh8Bjdv0
* Or https://vimeo.com/155086124 to https://player.vimeo.com/video/155086124
*
* @param string $url The video url.
* @return string
*/
public static function get_video_embed_url($url)
{
if (strpos($url, 'youtube') !== false && strpos($url, 'watch') !== false) {
$parts = wp_parse_url($url);
if (is_array($parts) && isset($parts['query'])) {
parse_str($parts['query']);
if (isset($v)) {
return 'https://www.youtube.com/embed/' . $v;
}
}
}
if (strpos($url, 'vimeo') !== false && strpos($url, 'player') === false) {
$parts = wp_parse_url($url);
if (is_array($parts) && isset($parts['path'])) {
return 'https://player.vimeo.com/video' . $parts['path'];
}
}
return $url;
}
示例5: __construct
/**
* Class constructor.
*
* @param array $args Configuration array.
*
* @throws \RuntimeException If home_url() cannot be parsed properly.
*/
public function __construct(array $args = [])
{
// Revisit - at a minimum this won't hold up against ccSLDs.
$host = wp_parse_url(home_url());
if (!isset($host['host'])) {
// @todo
throw new \RuntimeException();
}
$host = $host['host'];
$host_parts = explode('.', $host);
$tld = array_pop($host_parts);
$domain = array_pop($host_parts);
$defaults = ['aggressive' => apply_filters('metis.cdn.aggressive.default', true), 'domain' => apply_filters('metis.cdn.domain.default', sprintf('static.%s.%s', $domain, $tld)), 'extensions' => apply_filters('metis.cdn.extensions.default', ['css', 'gif', 'ico', 'jpe?g', 'js', 'png', 'svg'])];
$this->args = wp_parse_args($args, $defaults);
$this->assert_string($this->args['domain']);
$this->assert_array_of_strings($this->args['extensions']);
$this->elements = ['img' => ['src', 'srcset'], 'link' => ['href'], 'meta' => ['content'], 'script' => ['src']];
$this->replace = sprintf('\\1%s\\2\\3', $this->args['domain']);
$this->search = sprintf('/(https?\\:(?:\\\\)?\\/(?:\\\\)?\\/)%s((?:\\\\)?\\/[^\'"]*?)(\\.(?:%s))/', preg_quote($host), implode('|', $this->args['extensions']));
}
示例6: get_related_events
public function get_related_events($request)
{
$context = !empty($request['context']) ? $request['context'] : 'view';
$url = wp_parse_url($_SERVER['REQUEST_URI']);
$events_index = preg_match('/events$/', $url['path']);
if ($context === 'embed' && $events_index) {
return [];
// when hitting the events index, we don't need the related events data
}
$event_id = $request['event_id'];
$genre = get_post_meta($event_id, 'event_genre', true);
$events_in_genre_args = array('post_type' => 'event', 'post_status' => array('publish'), 'posts_per_page' => -1, 'post__not_in' => array($event_id), 'meta_query' => array('relation' => 'AND', 'genre_clause' => array('key' => 'event_genre', 'value' => $genre, 'compare' => '='), 'last_event_instance_clause' => array('key' => 'last_event_instance', 'value' => date('Y-m-d H:i:s'), 'type' => 'DATETIME', 'compare' => '>=')), 'orderby' => 'last_event_instance_clause', 'order' => 'ASC');
$related_events = get_posts($events_in_genre_args);
$related_event_ids = array_map(function ($event) {
return $event->ID;
}, $related_events);
if (count($related_event_ids)) {
$request->set_param('filter', array('orderby' => 'post__in', 'post__in' => array_values($related_event_ids), 'post_type' => 'event', 'post__not_in' => array($event_id)));
$request->set_param('per_page', 3);
return $this->get_items($request);
} else {
return [];
}
}
示例7: wp_resource_hints_scripts_styles
/**
* Adds dns-prefetch for all scripts and styles enqueued from external hosts.
*
* @since 4.6.0
*/
function wp_resource_hints_scripts_styles()
{
global $wp_scripts, $wp_styles;
$unique_hosts = array();
if (is_object($wp_scripts) && !empty($wp_scripts->registered)) {
foreach ($wp_scripts->registered as $registered_script) {
$parsed = wp_parse_url($registered_script->src);
if (!empty($parsed['host']) && !in_array($parsed['host'], $unique_hosts) && $parsed['host'] !== $_SERVER['SERVER_NAME']) {
$unique_hosts[] = $parsed['host'];
}
}
}
if (is_object($wp_styles) && !empty($wp_styles->registered)) {
foreach ($wp_styles->registered as $registered_style) {
$parsed = wp_parse_url($registered_style->src);
if (!empty($parsed['host']) && !in_array($parsed['host'], $unique_hosts) && $parsed['host'] !== $_SERVER['SERVER_NAME']) {
$unique_hosts[] = $parsed['host'];
}
}
}
return $unique_hosts;
}
示例8: remove_all_non_snapshot_admin_bar_links
/**
* Remove all admin bar nodes that have links and which aren't for snapshots.
*
* @param \WP_Admin_Bar $wp_admin_bar Admin bar.
*/
public function remove_all_non_snapshot_admin_bar_links($wp_admin_bar)
{
if (empty($this->snapshot)) {
return;
}
$snapshot_admin_bar_node_ids = array('customize', 'exit-customize-snapshot', 'inspect-customize-snapshot');
foreach ($wp_admin_bar->get_nodes() as $node) {
if (in_array($node->id, $snapshot_admin_bar_node_ids, true) || '#' === substr($node->href, 0, 1)) {
continue;
}
$parsed_link_url = wp_parse_url($node->href);
$parsed_home_url = wp_parse_url(home_url('/'));
$is_external_link = isset($parsed_link_url['host']) && $parsed_link_url['host'] !== $parsed_home_url['host'] || isset($parsed_link_url['path']) && 0 !== strpos($parsed_link_url['path'], $parsed_home_url['path']) || (!isset($parsed_link_url['query']) || !preg_match('#(^|&)customize_snapshot_uuid=#', $parsed_link_url['query']));
if ($is_external_link) {
$wp_admin_bar->remove_node($node->id);
}
}
}
示例9: give_send_back_to_checkout
/**
* Send back to donation form..
*
* Used to redirect a user back to the donation form if there are errors present.
*
* @param array $args
*
* @access public
* @since 1.0
* @return Void
*/
function give_send_back_to_checkout($args = array())
{
$url = isset($_POST['give-current-url']) ? sanitize_text_field($_POST['give-current-url']) : '';
//Set the form_id.
if (isset($_POST['give-form-id'])) {
$form_id = sanitize_text_field($_POST['give-form-id']);
} else {
$form_id = 0;
}
//Need a URL to continue. If none, redirect back to single form.
if (empty($url)) {
wp_safe_redirect(get_permalink($form_id));
give_die();
}
$defaults = array('form-id' => (int) $form_id);
// Check for backward compatibility.
if (is_string($args)) {
$args = str_replace('?', '', $args);
}
$args = wp_parse_args($args, $defaults);
// Merge URL query with $args to maintain third-party URL parameters after redirect.
$url_data = wp_parse_url($url);
//Check if an array to prevent notices before parsing.
if (isset($url_data['query']) && !empty($url_data['query'])) {
parse_str($url_data['query'], $query);
//Precaution: don't allow any CC info.
unset($query['card_number']);
unset($query['card_cvc']);
} else {
//No $url_data so pass empty array.
$query = array();
}
$new_query = array_merge($args, $query);
$new_query_string = http_build_query($new_query);
// Assemble URL parts.
$redirect = home_url('/' . $url_data['path'] . '?' . $new_query_string . '#give-form-' . $form_id . '-wrap');
//Redirect them.
wp_safe_redirect(apply_filters('give_send_back_to_checkout', $redirect, $args));
give_die();
}
示例10: test_customize_link
/**
* @ticket 30937
* @covers wp_admin_bar_customize_menu()
*/
public function test_customize_link()
{
global $wp_customize;
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
$uuid = wp_generate_uuid4();
$this->go_to(home_url("/?customize_changeset_uuid={$uuid}"));
wp_set_current_user(self::$admin_id);
$this->factory()->post->create(array('post_type' => 'customize_changeset', 'post_status' => 'auto-draft', 'post_name' => $uuid));
$wp_customize = new WP_Customize_Manager(array('changeset_uuid' => $uuid));
$wp_customize->start_previewing_theme();
set_current_screen('front');
$wp_admin_bar = $this->get_standard_admin_bar();
$node = $wp_admin_bar->get_node('customize');
$this->assertNotEmpty($node);
$parsed_url = wp_parse_url($node->href);
$query_params = array();
wp_parse_str($parsed_url['query'], $query_params);
$this->assertEquals($uuid, $query_params['changeset_uuid']);
$this->assertNotContains('changeset_uuid', $query_params['url']);
}
示例11: test_replace_customize_link
/**
* Test replace_customize_link.
*
* @covers CustomizeSnapshots\Customize_Snapshot_Manager::replace_customize_link()
*/
public function test_replace_customize_link()
{
global $wp_admin_bar;
set_current_screen('front');
require_once ABSPATH . WPINC . '/class-wp-admin-bar.php';
remove_all_actions('admin_bar_menu');
$this->go_to(home_url('?customize_snapshot_uuid=' . self::UUID));
$_REQUEST['customize_snapshot_uuid'] = self::UUID;
$manager = new Customize_Snapshot_Manager($this->plugin);
$manager->init();
// Ensure customize link remains unknown if user lacks cap.
wp_set_current_user(0);
$wp_admin_bar = new \WP_Admin_Bar();
// WPCS: Override OK.
$wp_admin_bar->initialize();
$wp_admin_bar->add_menus();
do_action_ref_array('admin_bar_menu', array(&$wp_admin_bar));
$this->assertEmpty($wp_admin_bar->get_node('customize'));
// Ensure customize link modified.
wp_set_current_user($this->user_id);
$wp_admin_bar = new \WP_Admin_Bar();
// WPCS: Override OK.
$wp_admin_bar->initialize();
$wp_admin_bar->add_menus();
do_action_ref_array('admin_bar_menu', array(&$wp_admin_bar));
$node = $wp_admin_bar->get_node('customize');
$this->assertTrue(is_object($node));
$parsed_url = wp_parse_url($node->href);
$query_params = array();
parse_str($parsed_url['query'], $query_params);
$this->assertArrayHasKey('customize_snapshot_uuid', $query_params);
$this->assertEquals(self::UUID, $query_params['customize_snapshot_uuid']);
$this->assertArrayHasKey('url', $query_params);
$parsed_preview_url = wp_parse_url($query_params['url']);
$this->assertArrayNotHasKey('query', $parsed_preview_url);
}
示例12: fetchAndSaveUniqueImage
/**
* Fetch an image with wp_remote_get(), save it to $fullpath with a unique name.
* Will return an empty string if something went wrong.
*
* @param $url string
* @param $fullpath string
*
* @return string filename
*/
protected function fetchAndSaveUniqueImage($url, $fullpath)
{
if (isset($this->fetchedImageCache[$url])) {
return $this->fetchedImageCache[$url];
}
$response = wp_remote_get($url, array('timeout' => $this->timeout));
// WordPress error?
if (is_wp_error($response)) {
try {
// protocol relative urls handed to wp_remote_get will fail
// try adding a protocol
$protocol_relative = wp_parse_url($url);
if (!isset($protocol_relative['scheme'])) {
if (true === is_ssl()) {
$url = 'https:' . $url;
} else {
$url = 'http:' . $url;
}
}
$response = wp_remote_get($url, array('timeout' => $this->timeout));
if (is_wp_error($response)) {
throw new \Exception('Bad URL: ' . $url);
}
} catch (\Exception $exc) {
$this->fetchedImageCache[$url] = '';
error_log('\\PressBooks\\Export\\Epub201\\fetchAndSaveUniqueImage wp_error on wp_remote_get() - ' . $response->get_error_message() . ' - ' . $exc->getMessage());
return '';
}
}
// Basename without query string
$filename = explode('?', basename($url));
// isolate latex image service from WP, add file extension
if ('s.wordpress.com' == parse_url($url, PHP_URL_HOST) && 'latex.php' == $filename[0]) {
$filename = md5(array_pop($filename));
// content-type = 'image/png'
$type = explode('/', $response['headers']['content-type']);
$type = array_pop($type);
$filename = $filename . '.' . $type;
} else {
$filename = array_shift($filename);
$filename = sanitize_file_name(urldecode($filename));
$filename = Sanitize\force_ascii($filename);
}
$tmp_file = \Pressbooks\Utility\create_tmp_file();
file_put_contents($tmp_file, wp_remote_retrieve_body($response));
if (!\Pressbooks\Image\is_valid_image($tmp_file, $filename)) {
$this->fetchedImageCache[$url] = '';
error_log('\\PressBooks\\Export\\Epub201\\fetchAndSaveUniqueImage is_valid_image, not a valid image ');
return '';
// Not an image
}
if ($this->compressImages) {
$format = explode('.', $filename);
$format = strtolower(end($format));
// Extension
\Pressbooks\Image\resize_down($format, $tmp_file);
}
// Check for duplicates, save accordingly
if (!file_exists("{$fullpath}/{$filename}")) {
copy($tmp_file, "{$fullpath}/{$filename}");
} elseif (md5(file_get_contents($tmp_file)) != md5(file_get_contents("{$fullpath}/{$filename}"))) {
$filename = wp_unique_filename($fullpath, $filename);
copy($tmp_file, "{$fullpath}/{$filename}");
}
$this->fetchedImageCache[$url] = $filename;
return $filename;
}
示例13: is_cross_domain
/**
* Determines whether the admin and the frontend are on different domains.
*
* @since 4.7.0
* @access public
*
* @return bool Whether cross-domain.
*/
public function is_cross_domain()
{
$admin_origin = wp_parse_url(admin_url());
$home_origin = wp_parse_url(home_url());
$cross_domain = strtolower($admin_origin['host']) !== strtolower($home_origin['host']);
return $cross_domain;
}
示例14: robots_txt
/**
* Edits the robots.txt output
*
* Requires not to have a robots.txt file in the root directory
*
* @uses robots_txt filter located at WP core
*
* @since 2.2.9
*
* @global int $blog_id;
*
* @todo maybe combine with noindex/noarchive/(nofollow) -> only when object caching?
*/
public function robots_txt($robots_txt = '', $public = '')
{
global $blog_id;
/**
* Don't do anything if the blog isn't public
*/
if ('0' === $public) {
return $robots_txt;
}
$revision = '1';
$cache_key = 'robots_txt_output_' . $revision . $blog_id;
$output = $this->object_cache_get($cache_key);
if (false === $output) {
$output = '';
/**
* Apply filters the_seo_framework_robots_txt_pre & the_seo_framework_robots_txt_pro
* : Add custom cacheable lines.
* : Don't forget to add line breaks ( "\r\n" | PHP_EOL )
*
* @since 2.5.0
*/
$pre = (string) apply_filters('the_seo_framework_robots_txt_pre', '');
$pro = (string) apply_filters('the_seo_framework_robots_txt_pro', '');
$site_url = wp_parse_url(site_url());
$path = !empty($site_url['path']) ? $site_url['path'] : '';
$output .= $pre;
//* Output defaults
$output .= "User-agent: *\r\n";
$output .= "Disallow: {$path}/wp-admin/\r\n";
$output .= "Allow: {$path}/wp-admin/admin-ajax.php\r\n";
/**
* Prevents query indexing
* @since 2.2.9
*
* Applies filters the_seo_framework_robots_disallow_queries : Whether to allow queries for robots.
* @since 2.5.0
*/
if (apply_filters('the_seo_framework_robots_disallow_queries', false)) {
$home_url = wp_parse_url(rtrim($this->the_home_url_from_cache(), ' /\\'));
$home_path = !empty($home_url['path']) ? $home_url['path'] : '';
$output .= "Disallow: {$home_path}/*?*\r\n";
}
$output .= $pro;
if ($this->get_option('sitemaps_robots') && $this->can_do_sitemap_robots()) {
//* Add whitespace before sitemap.
$output .= "\r\n";
//* Add sitemap full url
$output .= 'Sitemap: ' . $this->the_home_url_from_cache(true) . "sitemap.xml\r\n";
}
$this->object_cache_set($cache_key, $output, 86400);
}
/**
* Completely override robots with output.
* @since 2.5.0
*/
$robots_txt = $output;
return $robots_txt;
}
示例15: true_purge_all
function true_purge_all()
{
global $rt_wp_nginx_helper;
$prefix = trim($rt_wp_nginx_helper->options['redis_prefix']);
$this->log('* * * * *');
// If Purge Cache link click from network admin then purge all
if (is_network_admin()) {
delete_keys_by_wildcard($prefix . '*');
$this->log('* Purged Everything! * ');
} else {
// Else purge only site specific cache
$parse = wp_parse_url(get_site_url());
$parse['path'] = empty($parse['path']) ? '/' : $parse['path'];
delete_keys_by_wildcard($prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'] . '*');
$this->log('* ' . get_site_url() . ' Purged! * ');
}
$this->log('* * * * *');
}