Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requires `wp_parse_url` #3

Open
tollmanz opened this issue Dec 7, 2015 · 2 comments
Open

Requires `wp_parse_url` #3

tollmanz opened this issue Dec 7, 2015 · 2 comments

Comments

@tollmanz
Copy link

@tollmanz tollmanz commented Dec 7, 2015

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.

@rmccue
Copy link
Member

@rmccue rmccue commented Dec 8, 2015

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

@tollmanz
Copy link
Author

@tollmanz tollmanz commented Dec 8, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.