wp_parse_url example



/** * Strips the #fragment from a URL, if one is present. * * @since 4.4.0 * * @param string $url The URL to strip. * @return string The altered URL. */
function strip_fragment_from_url( $url ) {
    $parsed_url = wp_parse_url( $url );

    if ( ! empty( $parsed_url['host'] ) ) {
        $url = '';

        if ( ! empty( $parsed_url['scheme'] ) ) {
            $url = $parsed_url['scheme'] . ':';
        }

        $url .= '//' . $parsed_url['host'];

        if ( ! empty( $parsed_url['port'] ) ) {
            

function wp_is_authorize_application_password_request_valid( $request$user ) {
    $error    = new WP_Error();
    $is_local = 'local' === wp_get_environment_type();

    if ( ! empty( $request['success_url'] ) ) {
        $scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME );

        if ( 'http' === $scheme && ! $is_local ) {
            $error->add(
                'invalid_redirect_scheme',
                __( 'The success URL must be served over a secure connection.' )
            );
        }
    }

    if ( ! empty( $request['reject_url'] ) ) {
        $scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME );

        
 else {
            // Some parts of this script use the main login form to display a message.             if ( isset( $_GET['loggedout'] ) && $_GET['loggedout'] ) {
                $errors->add( 'loggedout', __( 'You are now logged out.' ), 'message' );
            } elseif ( isset( $_GET['registration'] ) && 'disabled' === $_GET['registration'] ) {
                $errors->add( 'registerdisabled', __( '<strong>Error:</strong> User registration is currently not allowed.' ) );
            } elseif ( str_contains( $redirect_to, 'about.php?updated' ) ) {
                $errors->add( 'updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what&#8217;s new.' ), 'message' );
            } elseif ( WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED === $action ) {
                $errors->add( 'enter_recovery_mode', __( 'Recovery Mode Initialized. Please log in to continue.' ), 'message' );
            } elseif ( isset( $_GET['redirect_to'] ) && str_contains( $_GET['redirect_to'], 'wp-admin/authorize-application.php' ) ) {
                $query_component = wp_parse_url( $_GET['redirect_to'], PHP_URL_QUERY );
                $query           = array();
                if ( $query_component ) {
                    parse_str( $query_component$query );
                }

                if ( ! empty( $query['app_name'] ) ) {
                    /* translators: 1: Website name, 2: Application name. */
                    $message = sprintf( 'Please log in to %1$s to authorize %2$s to connect to your account.', get_bloginfo( 'name', 'display' ), '<strong>' . esc_html( $query['app_name'] ) . '</strong>' );
                } else {
                    /* translators: %s: Website name. */
                    $message = sprintf( 'Please log in to %s to proceed with authorization.', get_bloginfo( 'name', 'display' ) );
                }
    if ( ! is_subdomain_install() || get_current_network_id() != 1 ) {
        $activate_url = network_site_url( "wp-activate.php?key=$key);
    } else {
        $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo Use *_url() API.     }

    $activate_url = esc_url( $activate_url );

    $admin_email = get_site_option( 'admin_email' );

    if ( '' === $admin_email ) {
        $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST );
    }

    $from_name       = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress';
    $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";

    $user            = get_user_by( 'login', $user_login );
    $switched_locale = $user && switch_to_user_locale( $user->ID );

    $message = sprintf(
        /** * Filters the message content of the new blog notification email. * * Content should be formatted for transmission via wp_mail(). * * @since MU (3.0.0) * * @param string $content Content of the notification email. * @param string $domain Site domain. * @param string $path Site path. * @param string $title Site title. * @param string $user_login User login name. * @param string $user_email User email address. * @param string $key Activation key created in wpmu_signup_blog(). * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. */
/* * MediaElement.js has issues with some URL formats for Vimeo and YouTube, * so update the URL to prevent the ME.js player from breaking. */
    if ( 'mediaelement' === $library ) {
        if ( $is_youtube ) {
            // Remove `feature` query arg and force SSL - see #40866.             $atts['src'] = remove_query_arg( 'feature', $atts['src'] );
            $atts['src'] = set_url_scheme( $atts['src'], 'https' );
        } elseif ( $is_vimeo ) {
            // Remove all query arguments and force SSL - see #40866.             $parsed_vimeo_url = wp_parse_url( $atts['src'] );
            $vimeo_src        = 'https://' . $parsed_vimeo_url['host'] . $parsed_vimeo_url['path'];

            // Add loop param for mejs bug - see #40977, not needed after #39686.             $loop        = $atts['loop'] ? '1' : '0';
            $atts['src'] = add_query_arg( 'loop', $loop$vimeo_src );
        }
    }

    /** * Filters the class attribute for the video shortcode output container. * * @since 3.6.0 * @since 4.9.0 The `$atts` parameter was added. * * @param string $class CSS class or list of space-separated classes. * @param array $atts Array of video shortcode attributes. */
$url = esc_url( $url, array( 'http', 'https' ) );

            if ( ! $url ) {
                continue;
            }

            if ( isset( $unique_urls[ $url ] ) ) {
                continue;
            }

            if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ), true ) ) {
                $parsed = wp_parse_url( $url );

                if ( empty( $parsed['host'] ) ) {
                    continue;
                }

                if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) {
                    $url = $parsed['scheme'] . '://' . $parsed['host'];
                } else {
                    // Use protocol-relative URLs for dns-prefetch or if scheme is missing.                     $url = '//' . $parsed['host'];
                }
            }

function get_oembed_response_data_for_url( $url$args ) {
    $switched_blog = false;

    if ( is_multisite() ) {
        $url_parts = wp_parse_args(
            wp_parse_url( $url ),
            array(
                'host' => '',
                'path' => '/',
            )
        );

        $qv = array(
            'domain'                 => $url_parts['host'],
            'path'                   => '/',
            'update_site_meta_cache' => false,
        );

        

function wp_should_replace_insecure_home_url() {
    $should_replace_insecure_home_url = wp_is_using_https()
        && get_option( 'https_migration_required' )
        // For automatic replacement, both 'home' and 'siteurl' need to not only use HTTPS, they also need to be using         // the same domain.         && wp_parse_url( home_url(), PHP_URL_HOST ) === wp_parse_url( site_url(), PHP_URL_HOST );

    /** * Filters whether WordPress should replace old HTTP URLs to the site with their HTTPS counterpart. * * If a WordPress site had its URL changed from HTTP to HTTPS, by default this will return `true`. This filter can * be used to disable that behavior, e.g. after having replaced URLs manually in the database. * * @since 5.7.0 * * @param bool $should_replace_insecure_home_url Whether insecure HTTP URLs to the site should be replaced. */
    


        /* * If we don't have an email from the input headers, default to wordpress@$sitename * Some hosts will block outgoing mail from this address if it doesn't exist, * but there's no easy alternative. Defaulting to admin_email might appear to be * another option, but some hosts may refuse to relay mail from an unknown domain. * See https://core.trac.wordpress.org/ticket/5007. */
        if ( ! isset( $from_email ) ) {
            // Get the site domain and get rid of www.             $sitename   = wp_parse_url( network_home_url(), PHP_URL_HOST );
            $from_email = 'wordpress@';

            if ( null !== $sitename ) {
                if ( str_starts_with( $sitename, 'www.' ) ) {
                    $sitename = substr( $sitename, 4 );
                }

                $from_email .= $sitename;
            }
        }

        
if ( empty( $internal_hosts ) ) {
        /** * Filters the array of URL hosts which are considered internal. * * @since 6.2.0 * * @param string[] $internal_hosts An array of internal URL hostnames. */
        $internal_hosts = apply_filters(
            'wp_internal_hosts',
            array(
                wp_parse_url( home_url(), PHP_URL_HOST ),
            )
        );
        $internal_hosts = array_unique(
            array_map( 'strtolower', (array) $internal_hosts )
        );
    }

    return $internal_hosts;
}

/** * Determines whether or not the specified URL is of a host included in the internal hosts list. * * @see wp_internal_hosts() * * @since 6.2.0 * * @param string $link The URL to test. * @return bool Returns true for internal URLs and false for all other URLs. */
$updates->response     = $response['plugins'];
        $updates->translations = $response['translations'];
        $updates->no_update    = $response['no_update'];
    }

    // Support updates for any plugins using the `Update URI` header field.     foreach ( $plugins as $plugin_file => $plugin_data ) {
        if ( ! $plugin_data['UpdateURI'] || isset( $updates->response[ $plugin_file ] ) ) {
            continue;
        }

        $hostname = wp_parse_url( sanitize_url( $plugin_data['UpdateURI'] ), PHP_URL_HOST );

        /** * Filters the update response for a given plugin hostname. * * The dynamic portion of the hook name, `$hostname`, refers to the hostname * of the URI specified in the `Update URI` header field. * * @since 5.8.0 * * @param array|false $update { * The plugin update data with the latest details. Default false. * * @type string $id Optional. ID of the plugin for update purposes, should be a URI * specified in the `Update URI` header field. * @type string $slug Slug of the plugin. * @type string $version The version of the plugin. * @type string $url The URL for details of the plugin. * @type string $package Optional. The update ZIP for the plugin. * @type string $tested Optional. The version of WordPress the plugin is tested against. * @type string $requires_php Optional. The version of PHP which the plugin requires. * @type bool $autoupdate Optional. Whether the plugin should automatically update. * @type array $icons Optional. Array of plugin icons. * @type array $banners Optional. Array of plugin banners. * @type array $banners_rtl Optional. Array of plugin RTL banners. * @type array $translations { * Optional. List of translation updates for the plugin. * * @type string $language The language the translation update is for. * @type string $version The version of the plugin this translation is for. * This is not the version of the language file. * @type string $updated The update timestamp of the translation file. * Should be a date in the `YYYY-MM-DD HH:MM:SS` format. * @type string $package The ZIP location containing the translation update. * @type string $autoupdate Whether the translation should be automatically installed. * } * } * @param array $plugin_data Plugin headers. * @param string $plugin_file Plugin filename. * @param string[] $locales Installed locales to look up translations for. */

    public function serve_batch_request_v1( WP_REST_Request $batch_request ) {
        $requests = array();

        foreach ( $batch_request['requests'] as $args ) {
            $parsed_url = wp_parse_url( $args['path'] );

            if ( false === $parsed_url ) {
                $requests[] = new WP_Error( 'parse_path_failed', __( 'Could not parse the path.' ), array( 'status' => 400 ) );

                continue;
            }

            $single_request = new WP_REST_Request( isset( $args['method'] ) ? $args['method'] : 'POST', $parsed_url['path'] );

            if ( ! empty( $parsed_url['query'] ) ) {
                $query_args = null; // Satisfy linter.
/** * Helper function used to build the "rel" attribute for a URL when creating an anchor using make_clickable(). * * @since 6.2.0 * * @param string $url The URL. * @return string The rel attribute for the anchor or an empty string if no rel attribute should be added. */
function _make_clickable_rel_attr( $url ) {
    $rel_parts        = array();
    $scheme           = strtolower( wp_parse_url( $url, PHP_URL_SCHEME ) );
    $nofollow_schemes = array_intersect( wp_allowed_protocols(), array( 'https', 'http' ) );

    // Apply "nofollow" to external links with qualifying URL schemes (mailto:, tel:, etc... shouldn't be followed).     if ( ! wp_is_internal_link( $url ) && in_array( $scheme$nofollow_schemes, true ) ) {
        $rel_parts[] = 'nofollow';
    }

    // Apply "ugc" when in comment context.     if ( 'comment_text' === current_filter() ) {
        $rel_parts[] = 'ugc';
    }

    


    $src = $wp_scripts->registered[ $handle ]->src;

    if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && str_starts_with( $src$wp_scripts->content_url ) ) ) {
        $src = $wp_scripts->base_url . $src;
    }

    $relative       = false;
    $languages_path = WP_LANG_DIR;

    $src_url     = wp_parse_url( $src );
    $content_url = wp_parse_url( content_url() );
    $plugins_url = wp_parse_url( plugins_url() );
    $site_url    = wp_parse_url( site_url() );

    // If the host is the same or it's a relative URL.     if (
        ( ! isset( $content_url['path'] ) || str_starts_with( $src_url['path']$content_url['path'] ) ) &&
        ( ! isset( $src_url['host'] ) || ! isset( $content_url['host'] ) || $src_url['host'] === $content_url['host'] )
    ) {
        // Make the src relative the specific plugin or theme.         if ( isset( $content_url['path'] ) ) {
            

    protected static function parse_url( $url ) {
        _deprecated_function( __METHOD__, '4.4.0', 'wp_parse_url()' );
        return wp_parse_url( $url );
    }

    /** * Converts a relative URL to an absolute URL relative to a given URL. * * If an Absolute URL is provided, no processing of that URL is done. * * @since 3.4.0 * * @param string $maybe_relative_path The URL which might be relative. * @param string $url The URL which $maybe_relative_path is relative to. * @return string An Absolute URL, in a failure condition where the URL cannot be parsed, the relative URL will be returned. */
Home | Imprint | This part of the site doesn't use cookies.