Skip to content

Requires wp_parse_url #3

Open
Open

Description

@tollmanz

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.

Activity

  1. rmccue commented on Dec 8, 2015

    @rmccue
    Member

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

  2. tollmanz commented on Dec 8, 2015

    @tollmanz
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions