Skip to content

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

@stefanfisk

Description

@stefanfisk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions