Skip to content

Commit

Permalink
[SITE-1140] fix subdirectory paths (#143)
Browse files Browse the repository at this point in the history
* port changes from #142

* remove no-longer-necessary id

Co-authored-by: Phil Tyler <[email protected]>

* execute and test in one step (instead of two)

Co-authored-by: Phil Tyler <[email protected]>

* remove the DIFF variable

don't need it

Co-authored-by: Phil Tyler <[email protected]>

---------

Co-authored-by: Phil Tyler <[email protected]>
  • Loading branch information
jazzsequence and pwtyler committed Jul 31, 2024
1 parent 9873c99 commit 36d2576
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/phpcbf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: PHP Code Beautifier
on: [pull_request]
permissions:
contents: write
pull-requests: write
jobs:
phpcbf:
name: PHPCBF & Commit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Install Composer dependencies and run PHPCBF
run: |
CBF=false
composer install
if ! composer lint:phpcbf; then
echo "cbf=true" >> $GITHUB_ENV
else
echo "cbf=false" >> $GITHUB_ENV
fi
- name: Commit changes to PR
if: env.cbf == 'true'
run: |
git config --global user.email "[email protected]"
git config --global user.name "Pantheon Robot"
if ! git diff-index --quiet HEAD; then
CHANGES_DETECTED=true
git add *.php
git commit -m "PHPCBF: Fix coding standards" --no-verify
git push origin ${{ github.event.pull_request.head.ref }} || CHANGES_DETECTED=false
echo "changes_detected=$CHANGES_DETECTED" >> $GITHUB_ENV
else
echo "changes_detected=false" >> $GITHUB_ENV
fi
- name: Add PR Comment
if: env.changes_detected == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
CURRENT_COMMIT=$(git rev-parse --short HEAD)
gh pr comment ${{ github.event.pull_request.number }} -b "Hi from your friendly robot! :robot: I fixed PHPCS issues with \`phpcbf\` on $CURRENT_COMMIT. Please review the changes."
32 changes: 2 additions & 30 deletions web/app/mu-plugins/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,14 @@ function fix_core_resource_urls( string $url ) : string {
}

$path = $parsed_url['path'];
$core_paths = [ 'wp-includes/', 'wp-admin/', 'wp-content/' ];
$core_paths = [ '/wp-includes/', '/wp-content/' ];
$path_modified = false;

foreach ( $core_paths as $core_path ) {
if ( strpos( $path, $current_site_path . $core_path ) !== false ) {
$path = str_replace( $current_site_path . $core_path, $core_path, $path );
$path_modified = true;
}

if ( str_contains( $path, 'wp' ) ) {
$path = str_replace( '/wp/', '/', $path );
$path_modified = true;
}

if ( $path_modified ) {
break;
break;
}
}

Expand Down Expand Up @@ -165,26 +157,6 @@ function adjust_main_site_urls( string $url ) : string {
add_filter( 'home_url', __NAMESPACE__ . '\\adjust_main_site_urls', 9 );
add_filter( 'site_url', __NAMESPACE__ . '\\adjust_main_site_urls', 9 );

/**
* Add /wp prefix to all admin and login URLs.
* Since /wp is where the core files are installed, this normalizes all non-front-facing urls to use the correct url structure.
*
* @since 1.1.0
* @param string $url The URL to check.
* @return string The corrected admin or login URL (or the base url if not an admin or login url).
*/
function add_wp_prefix_to_login_and_admin_urls( string $url ) : string {
if ( ! __is_login_url( $url ) ) {
return $url;
}
if ( strpos( $url, '/wp/' ) !== false ) {
return $url;
}
return __normalize_wp_url( preg_replace( '/(\/wp-(login|admin))/', '/wp/$1', $url ) );
}
add_filter( 'login_url', __NAMESPACE__ . '\\add_wp_prefix_to_login_and_admin_urls', 9 );
add_filter( 'admin_url', __NAMESPACE__ . '\\add_wp_prefix_to_login_and_admin_urls', 9 );

/**
* Check the URL to see if it's either an admin or wp-login URL.
*
Expand Down

0 comments on commit 36d2576

Please sign in to comment.