Skip to content

Commit

Permalink
Boost: Better handling for slashes for cornerstone pages (#40012)
Browse files Browse the repository at this point in the history
  • Loading branch information
dilirity authored Nov 4, 2024
1 parent 928eb03 commit 0e8842a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
10 changes: 7 additions & 3 deletions projects/plugins/boost/app/data-sync/Cornerstone_Pages_Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function set( $value ) {
return;
}

$value = array_map( 'untrailingslashit', $value );

$updated = update_option( $this->option_key, $value );
if ( $updated ) {
( new Environment_Change_Detector() )->handle_cornerstone_pages_list_update();
Expand All @@ -41,7 +43,7 @@ public function set( $value ) {

private function sanitize_value( $value ) {
if ( is_array( $value ) ) {
$value = array_values( array_unique( array_filter( array_map( array( $this, 'transform_to_relative' ), $value ) ) ) );
$value = array_values( array_unique( array_map( array( $this, 'transform_to_relative' ), $value ) ) );
} else {
$value = array();
}
Expand All @@ -58,8 +60,10 @@ private function transform_to_relative( $url ) {
}

// Ensure the URL starts with a slash.
$url = ltrim( $url, '/' );
$url = '/' . $url;
if ( $url !== '' ) {
$url = ltrim( $url, '/' );
$url = '/' . $url;
}

return $url;
}
Expand Down
15 changes: 12 additions & 3 deletions projects/plugins/boost/app/lib/Cornerstone_Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public function remove_ccss_front_page_provider( $providers ) {

private function default_pages() {
if ( $this->get_max_pages() === static::FREE_MAX_PAGES ) {
return array( '/' );
return array( '' );
}

$max_pages = $this->get_max_pages();
$yoast_cornerstone_pages = $this->get_yoast_cornerstone_pages();
$woocommerce_pages = $this->get_woocommerce_pages();

$homepage = array( '/' );
$homepage = array( '' );

$urls = array_unique( array_merge( $homepage, $woocommerce_pages, $yoast_cornerstone_pages ) );

Expand Down Expand Up @@ -104,7 +104,16 @@ private function make_relative_url( $url ) {
}

public function get_pages() {
return jetpack_boost_ds_get( 'cornerstone_pages_list' );
$pages = jetpack_boost_ds_get( 'cornerstone_pages_list' );

$permalink_structure = get_option( 'permalink_structure' );

// If permalink structure ends with slash, add trailing slashes
if ( $permalink_structure && substr( $permalink_structure, -1 ) === '/' ) {
$pages = array_map( 'trailingslashit', $pages );
}

return $pages;
}

public function get_properties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static function get_request_url() {
return home_url( $wp->request );
}

return add_query_arg( $wp->query_vars, home_url( '/' ) );
return add_query_arg( $wp->query_vars, home_url() );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Don't store trailing slashes for foundation pages.


0 comments on commit 0e8842a

Please sign in to comment.