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

Admin page links: use admin_url() for internal admin links #59536

Open
ramonjd opened this issue Mar 4, 2024 · 0 comments
Open

Admin page links: use admin_url() for internal admin links #59536

ramonjd opened this issue Mar 4, 2024 · 0 comments
Labels
[Feature] Blocks Overall functionality of blocks [Type] Enhancement A suggestion for improvement.

Comments

@ramonjd
Copy link
Member

ramonjd commented Mar 4, 2024

What problem does this address?

Gutenberg hardcodes paths to wp-admin pages, e.g,

const siteIconSettingsUrl = shouldUseNewUrl

The proposal is to run these links through, or generate them using, admin_url for use in the editor.

Why?

The admin URL can be filtered:

https://github.com/WordPress/wordpress-develop/blob/6.4/src/wp-includes/link-template.php#L3556-L3576

So can the site URL:

https://github.com/WordPress/wordpress-develop/blob/6.4/src/wp-includes/link-template.php#L3527

If folks are using these filters, Gutenberg should reflect the intended values.

Site running in a subdirectory might have different admin URLs as well, see:

Furthermore, as the site editor becomes more integrated with WP-ADMIN functionality, it would be good to have a way to generate admin URLs.

What is your proposed solution?

I can't find a canonical index of all admin pages. global $menu, $admin_page_hooks contain some., but not all, possible values.

One way might be to add a set of common admin URLs to the editor settings, for example, using the block_editor_settings_all PHP filter. admin_url would be run in this filter.

await wp.data.resolveSelect( 'core/block-editor' ).getSettings();

/*
   {
        ...,
        admin_urls: {
             'options-general': ...,
             'customizer': ...,
             'users': ...,
             ...
        }
    }
*/

There is a backwards compatibility risk involved in this as settings are intended to stick around.

Another option could be to create such a canonical index — perhaps a directory list of https://github.com/WordPress/wordpress-develop/tree/trunk/src/wp-admin — and a restricted (admin logged-in) API route to fetch it 🤷🏻

Related discussion:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants