example-client icon indicating copy to clipboard operation
example-client copied to clipboard

Requires `wp_parse_url`

Open tollmanz opened this issue 9 years ago • 2 comments

wp_parse_url is a new function available in WordPress 4.4. The oauth1 server plugin requires the function. If you are using this with example client with WP < 4.4, the server will fatal.

A temporary workaround is to add the following as an MU plugin to the server:

<?php
/**
 * wp_parse_url is only available in WP 4.4. This ensures the function is available regardles of the WP version.
 */
if ( ! function_exists( 'wp_parse_url' ) ) {
    function wp_parse_url( $url ) {
        $parts = @parse_url( $url );
        if ( ! $parts ) {
            // < PHP 5.4.7 compat, trouble with relative paths including a scheme break in the path
            if ( '/' == $url[0] && false !== strpos( $url, '://' ) ) {
                // Since we know it's a relative path, prefix with a scheme/host placeholder and try again
                if ( ! $parts = @parse_url( 'placeholder://placeholder' . $url ) ) {
                    return $parts;
                }
                // Remove the placeholder values
                unset( $parts['scheme'], $parts['host'] );
            } else {
                return $parts;
            }
        }

        // < PHP 5.4.7 compat, doesn't detect schemeless URL's host field
        if ( '//' == substr( $url, 0, 2 ) && ! isset( $parts['host'] ) ) {
            $path_parts = explode( '/', substr( $parts['path'], 2 ), 2 );
            $parts['host'] = $path_parts[0];
            if ( isset( $path_parts[1] ) ) {
                $parts['path'] = '/' . $path_parts[1];
            } else {
                unset( $parts['path'] );
            }
        }

        return $parts;
    }
}

Not sure that there is an action item here other than updating the docs.

tollmanz avatar Dec 07 '15 17:12 tollmanz

Seems like an issue with the server, rather than the client?

rmccue avatar Dec 08 '15 13:12 rmccue

Indeed. Hence, "Not sure that there is an action item here other than updating the docs". Just wanted to document it for the next wayward soul just looking for some tokens in this lonely world.

tollmanz avatar Dec 08 '15 13:12 tollmanz