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

route() returns incorrect URLs when request is not handled by index.php #400

Open
stefanfisk opened this issue Sep 11, 2024 · 6 comments
Open
Labels
bug Something isn't working

Comments

@stefanfisk
Copy link
Contributor

Version

v4.3.0

What did you expect to happen?

I expected route() to return correct URLs whenever used.

What actually happens?

When used outside of the frontend or console route() prefixes the URLs with whatever .php file WordPress handled the request via.

So http://localhost/my-route becomes http://localhost/wp/wp-admin/admin-post.php/my-route etc.

The issue can be solved by calling Illuminate\Support\Facades\URL::forceRootUrl(home_url()) during boot but I am not sure about possible caveats.

Steps to reproduce

  1. Add Route::get('/test')->name('test'); to routes/web.php
  2. Add add_action('admin_post_nopriv_route_test', function() { echo route('test'); }); to functions.php
  3. Open /wp-admin/admin-post.php?action=route_test as appropriate for your local environment

System info

Pop!_OS 22.04 LTS

Log output

No response

Please confirm this isn't a support request.

Yes

@stefanfisk stefanfisk added the bug Something isn't working label Sep 11, 2024
@retlehs
Copy link
Member

retlehs commented Sep 11, 2024

Just to be clear, the bug is that Laravel routes don't work within the wp-admin?

@stefanfisk
Copy link
Contributor Author

stefanfisk commented Sep 11, 2024

Getting the URL of a Laravel route is broken in wp-admin and possibly other places that do not use index.php as the entrypoint.

@retlehs
Copy link
Member

retlehs commented Sep 11, 2024

Got any examples of what other places that could possibly be?

Acorn is typically booted via the after_setup_theme hook 🤔

@stefanfisk
Copy link
Contributor Author

wp-cron.php for example.

@stefanfisk
Copy link
Contributor Author

And wp-admin includes both admin-post.php and admin-ajax.php which are frequently used by the frontend. So thinking of it as only affecting wp-admin can be misleading.

@stefanfisk
Copy link
Contributor Author

If I understand it all correctly the root cause is that WordPress doesn't use a single file as its entry point, which confuses this function https://github.com/symfony/symfony/blob/44395abfcb2c859b26e0c6880c74dadd94da1038/src/Symfony/Component/HttpFoundation/Request.php#L1776.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants