Jetpack::normalize_url_protocol_agnostic PHP Method

normalize_url_protocol_agnostic() public static method

Normalizes a url by doing three things: - Strips protocol - Strips www - Adds a trailing slash
Since: 4.4.0
public static normalize_url_protocol_agnostic ( string $url ) : WP_Error | string
$url string
return WP_Error | string
    public static function normalize_url_protocol_agnostic($url)
    {
        $parsed_url = wp_parse_url(trailingslashit(esc_url_raw($url)));
        if (!$parsed_url) {
            return new WP_Error('cannot_parse_url', sprintf(esc_html__('Cannot parse URL %s', 'jetpack'), $url));
        }
        // Strip www and protocols
        $url = preg_replace('/^www\\./i', '', $parsed_url['host'] . $parsed_url['path']);
        return $url;
    }

Usage Example

Example #1
0
    function get_start_fresh_action_explanation()
    {
        $html = wp_kses(sprintf(__('No. <a href="%1$s">%2$s</a> is a new and different website that\'s separate from 
					<a href="%3$s">%4$s</a>. It requires  a new connection to WordPress.com for new stats and subscribers.', 'jetpack'), esc_url(get_home_url()), self::prepare_url_for_display(get_home_url()), esc_url(self::$wpcom_home_url), untrailingslashit(Jetpack::normalize_url_protocol_agnostic(esc_url_raw(self::$wpcom_home_url)))), array('a' => array('href' => array())));
        /**
         * Allows overriding of the default text for explaining the start fresh action.
         *
         * @since 4.4.0
         *
         * @param string $html The HTML to be displayed
         */
        return apply_filters('jetpack_idc_start_fresh_explanation', $html);
    }
All Usage Examples Of Jetpack::normalize_url_protocol_agnostic
Jetpack