Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #129 from alleyinteractive/revert-125-fix-irving-path
Browse files Browse the repository at this point in the history
Revert a bad commit and offer an alternative solution
  • Loading branch information
jameswburke authored Mar 25, 2020
2 parents 738e7b7 + d56020e commit 7d1d260
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions inc/endpoints/class-components-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class Components_Endpoint extends Endpoint {
*/
public $path = '';

/**
* Static version of the path for accessing globally.
*
* @var string
*/
public static $irving_path = '';

/**
* Context of request.
*
Expand Down Expand Up @@ -205,7 +212,8 @@ public function parse_path( string $raw_path = '' ) {
*
* @param string $raw_path Raw path value from request.
*/
$this->path = (string) apply_filters( 'wp_irving_components_path', $raw_path );
$this->path = (string) apply_filters( 'wp_irving_components_path', $raw_path );
self::$irving_path = $this->path;

/**
* Action fired on the sanitized path value.
Expand Down Expand Up @@ -302,33 +310,31 @@ public function build_query() {
}
}

// Fix an issue where `add_query_arg` doesn't work with already
// encoded strings missing the equal.
if ( ! empty( $query ) ) {

// Fix an issue where `add_query_arg` doesn't work with already
// encoded strings missing the equal.
if ( false === strpos( $query, '=' ) ) {
$query .= '=';
}
}

// Add irving-path to the query.
$query = add_query_arg(
[
'irving-path' => $this->path,
'irving-path-params' => $this->custom_params,
],
$query
);

// Add any extra included params.
foreach ( $this->custom_params as $key => $value ) {
$query = add_query_arg( $key, $value, $query );
}
// Add irving-path to the query.
$query = add_query_arg(
[
'irving-path' => $this->path,
'irving-path-params' => $this->custom_params,
],
$query
);

// Add_query_arg will encode the url, which we don't want.
$query = urldecode( $query );
// Add any extra included params.
foreach ( $this->custom_params as $key => $value ) {
$query = add_query_arg( $key, $value, $query );
}

// Remove any leading question marks as artifacts from add_query_arg.
$query = ltrim( $query, '?' );
// add_query_arg will encode the url, which we don't want.
$query = urldecode( $query );
}

/**
* Modify the query vars.
Expand Down

0 comments on commit 7d1d260

Please sign in to comment.