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

Fix bugs for a multisite environment. #15

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

baxtian
Copy link

@baxtian baxtian commented Jun 6, 2019

Use get_home_url to creat the rest URI.
Use apache_request_header in case $_SERVER didn't retrieve it.

Use get_home_url to creat the rest URI.
Use apache_request_header in case $_SERVER didn't retrieve it.
@@ -80,7 +80,7 @@ public static function get_rest_uri() {
$prefix = rest_get_url_prefix();
}

return sprintf( '/%s/%s/%s', $prefix, self::_NAMESPACE_, self::_REST_BASE_ );
return sprintf( '%s/%s/%s/%s', get_home_url(), $prefix, self::_NAMESPACE_, self::_REST_BASE_ );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add the home url here? This will break the tests and would require some additional modifications.

@@ -762,6 +762,14 @@ public function get_auth_header() {
$header = sanitize_text_field( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] );
}

//Maybe apache?
Copy link
Collaborator

@valendesigns valendesigns Jul 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole block of code does not adhere to coding standards and is causing phpcs to fail the build. Please update it when you have a chance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would make more sense to check for the missing header at the same time as the check for the function.

// Fallback for Apache request headers.
if ( ! $header && function_exists( 'apache_request_headers' ) ) {
    $headers = apache_request_headers();
    if ( is_array( $headers ) && ! empty( $headers[ 'Authorization' ] ) ) {
        $header = sanitize_text_field( $headers[ 'Authorization' ] );
    }
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't have anything to do with Multisite though. Can you describe the problem you're having with Multisite so I can understand why you are changing the rest endpoint?

@baxtian
Copy link
Author

baxtian commented Jul 5, 2019 via email

@arctouch-carlosbarreto
Copy link

This PR will fix the issue #19 , it's directly related.

@Edely
Copy link

Edely commented Nov 19, 2019

@valendesigns hello
I tried to solve this more programmatically using this approach:

public static function get_rest_uri() {
	$blog_id = get_current_blog_id();
	$prefix  = 'index.php?rest_route=';

	if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) {
				
	    $multisite_domain = strstr($_SERVER['REQUEST_URI'], 'wp-admin', true);
	    $prefix = $multisite_domain['0'] == '/' ? substr($multisite_domain, 1) . rest_get_url_prefix() : $multisite_domain  . rest_get_url_prefix();
	}
	return sprintf( '/%s/%s/%s', $prefix, self::_NAMESPACE_, self::_REST_BASE_ );
}

Although it works, it would certainly break the tests because of the hardcoded uris in test_get_rest_uri

public function test_get_rest_uri() {
	$this->assertEquals( '/index.php?rest_route=/wp/v2/key-pair', WP_REST_Key_Pair::get_rest_uri() );
	$this->set_permalink_structure( '/%postname%/' );
	$this->assertEquals( '/wp-json/wp/v2/key-pair', WP_REST_Key_Pair::get_rest_uri() );
	$this->set_permalink_structure( '' );
}

I was wondering if would be a good idea to build dynamically the uris in the test function.

@flip111
Copy link

flip111 commented May 3, 2020

sorry guys for using this ticket for something totally unrelated ...

@baxtian the comment box at http://www.sebaxtian.com/acerca-de/schreikasten does not work any longer (Ha habido un error crítico en tu web. Aprende más sobre la depuración en WordPress.). I searched around on the internet but i couldn't find a way to contact you as i didn't see an e-mail address or a public repository you made where i can comment on.

Below the comment that i was going to post there


Hi sebaxtian, thank you for the plugin. Would you consider uploading the source code to github / gitlab for more collaboration? People can send in fixes for the code as pull requests and make bug reports in separate tickets. We only have the release SVN, which is not for development, at https://plugins.trac.wordpress.org/browser/schreikasten/

I would also be very interested in all the ideas that you have for improvements to a shoutbox (possibly as new implementation instead of new version). You write:

There are too many reasons why, but to give just 3 of them: to use a template language, to use jQuery, to use WordPress own custom post type generator.

If you can spare the time a full list of possible improvements would be very appreciated (perhaps in a github ticket / wiki).


You can contact me at flip101@gmail.com so we don't have to use this ticket for communication.

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

Successfully merging this pull request may close these issues.

5 participants