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 empty path notice on initial setup #457

Merged
merged 1 commit into from
May 24, 2018
Merged

Conversation

joshcanhelp
Copy link
Contributor

No description provided.

@@ -86,10 +86,14 @@ public function convert_client_secret_to_key( $secret, $is_encoded, $is_RS256, $
*/
public function get_web_origins() {
$home_url_parsed = parse_url( home_url() );
$home_url_origin = str_replace( $home_url_parsed[ 'path' ], '', home_url() );
$home_url_origin = ! empty( $home_url_parsed[ 'path' ] )
? str_replace( $home_url_parsed[ 'path' ], '', home_url() )
Copy link
Contributor

@lbalmaceda lbalmaceda May 23, 2018

Choose a reason for hiding this comment

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

str_replace with '' as the index, would it work as an append? and if so, why not use . instead? also if true, if path is empty appending something without any characters in the middle would mean having that later string as the final output.
e.g.:

  • path=''
  • separator=''
  • home_url='something'
if !empty(path) -> home_url_origin=str_replace('', '', 'something') -> home_url_origin='something'

or, using php append ( . )

home_url_origin='' . 'something' -> home_url_origin='something'

Note the line above uses $home_url_parsed[ 'path' ] directly without checking if it's empty first, just as the previous code was doing. Am I right, is that the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if I understand ... I'm not appending anything here, I'm removing the path from the base URL of the site. So if the base URL is:

http://bananafarmer.com/peels

... I want:

http://bananafarmer.com

Using str_replace(), the first param is the needle, second is the replacement, third is the haystack.

That said, I probably want to do this instead:

$home_url_parsed = parse_url( home_url() );
$home_url_origin = $home_url_parsed['scheme'] . '://' . $home_url_parsed['host'] . 
	( ! empty( $home_url_parsed['port'] ) ? ':' . $home_url_parsed['port'] : '' );

Then I can put that in a function and not repeat it.

@joshcanhelp joshcanhelp merged commit e62f1bc into dev May 24, 2018
@joshcanhelp joshcanhelp deleted the fix-get-web-origins-error branch May 24, 2018 19:17
@joshcanhelp joshcanhelp mentioned this pull request Jun 5, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants