self_admin_url( string $path = '', string $scheme = 'admin' ): string
- Since
- 3.1.0
- Source
wp-includes/link-template.php:3898
Builds an admin URL that automatically switches between the network admin, user admin, or regular admin screen based on the current request context. Use it for links that must stay correct whether they render on wp-admin, wp-admin/network, or wp-admin/user pages. On a single site install it behaves exactly like admin_url() since neither is_network_admin() nor is_user_admin() will be true.
Compatibility
- WordPress
- since 3.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$pathstringoptional- Path relative to the admin URL. Default empty.Default:
'' $schemestringoptional- The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.Default:
'admin'
Return value
string- Admin URL link with optional path appended.
Code examples
Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.
Build a redirect URL after saving a plugin setting
A settings page handler wants a link back into wp-admin that stays correct no matter which admin context the code runs in.
$redirect_url = self_admin_url( 'options-general.php?page=my-plugin&updated=1' );
echo esc_html( $redirect_url );On this single-site sandbox this resolves the same way admin_url() would, the difference only shows up on multisite network or user admin screens.
Force an admin link to use https regardless of site settings
An upgrader-style notice wants to guarantee its link uses https even if force_ssl_admin() is off.
$secure_link = self_admin_url( 'plugins.php?activated=true', 'https' );
printf( 'Return to plugins: %s', esc_html( $secure_link ) );Common problems and fixes · 4
- Why does self_admin_url just give me the same thing as admin_url?
- How do I change the URL self_admin_url produces before it's used?
- Do I need to escape the value before printing it in HTML?
- Will this pick the wrong admin URL if I call it from an AJAX handler?
Why does self_admin_url just give me the same thing as admin_url?
How do I change the URL self_admin_url produces before it's used?
Do I need to escape the value before printing it in HTML?
Will this pick the wrong admin URL if I call it from an AJAX handler?
Alternatives and related functions
admin_url- When you know the link should always point at the current site's regular wp-admin, regardless of network or user admin context.
network_admin_url- When you specifically need a link into the network admin screens on a multisite install.
user_admin_url- When you specifically need a link into the user admin screens (used for personal settings on multisite).
home_url- When the link should point at the public front end of the site rather than any admin screen.
Performance profile
How much work a call to self_admin_url() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 18–21
- Plugin surface
- 1 hook
- Called by
- 40
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 32.
Third-party callbacks on 'self_admin_url' run inside this call, and their cost is not bounded by anything here.
40 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost self_admin_url() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_network_admin() | 18 | is_network_admin(), network_admin_url(), apply_filters() |
!is_network_admin() && !is_user_admin() | 20 | is_network_admin(), is_user_admin(), admin_url(), apply_filters() |
!is_network_admin() && is_user_admin() | 21 | is_network_admin(), is_user_admin(), user_admin_url(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 32 instructions, 18–21 executed per call, 2 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while self_admin_url() runs, in this order:
- apply_filters( self_admin_url )filterline 3916 (+18 into the body)
Filters the admin URL for the current site or network depending on context.
Uses · 6
- is_network_admin()Determines whether the current request is for the network administrative interface.
- network_admin_url()Retrieves the URL to the admin area for the network.
- is_user_admin()Determines whether the current request is for a user admin screen.
- user_admin_url()Retrieves the URL to the admin area for the current user.
- admin_url()Retrieves the URL to the admin area for the current site.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 40
- Bulk_Plugin_Upgrader_Skin::bulk_footer()Displays the footer following the bulk update process.
- Bulk_Theme_Upgrader_Skin::bulk_footer()Displays the footer following the bulk update process.
- File_Upload_Upgrader::__construct()Construct the upgrader for a form.
- Language_Pack_Upgrader_Skin::bulk_footer()Displays the footer following the bulk update process.
- Plugin_Installer_Skin::after()Performs an action following a plugin install.
- Plugin_Upgrader_Skin::after()Performs an action following a single plugin update.
- Theme_Installer_Skin::after()Performs an action following a single theme install.
- Theme_Upgrader_Skin::after()Performs an action following a single theme update.
- WP_Customize_Manager::customize_pane_settings()Prints JavaScript settings for parent window.
- WP_Customize_Theme_Control::content_template()Render a JS template for theme display.
- WP_Plugin_Install_List_Table::display_rows()Generates the list table rows.
- WP_Plugin_Install_List_Table::get_views()
Show all 40
- WP_Plugins_List_Table::single_row()
- WP_REST_Plugins_Controller::is_filesystem_available()Determine if the endpoints are available.
- WP_Theme_Install_List_Table::get_views()
- WP_Theme_Install_List_Table::install_theme_info()Prints the info for a theme (to be used in the theme installer modal).
- WP_Theme_Install_List_Table::single_row()Prints a theme from the WordPress.org API.
- core_auto_updates_settings()Display WordPress auto-updates settings.
- core_upgrade_preamble()Display upgrade WordPress for downloading latest or upgrading automatically form.
- customize_themes_print_templates()Prints JS templates for the theme-browsing UI in the Customizer.
- do_block_editor_incompatible_meta_box()Renders a "fake" meta box with an information message, shown on the block editor, when an incompatible meta box is found.
- do_core_upgrade()Upgrades WordPress core display.
- get_edit_user_link()Retrieves the edit user link.
- install_dashboard()Displays the Featured tab of Add Plugins screen.
- install_plugin_information()Displays plugin information in dialog box form.
- install_plugin_install_status()Determines the status we can perform on a plugin.
- install_plugins_upload()Displays a form to upload plugins from zip files.
- install_themes_upload()Displays a form to upload themes from zip files.
- list_plugin_updates()Display the upgrade plugins form.
- list_theme_updates()Display the upgrade themes form.
- send_confirmation_on_profile_email()Sends a confirmation request email when a change of user email address is attempted.
- update_option_new_admin_email()Sends a confirmation request email when a change of site admin email address is attempted.
- wp_admin_bar_wp_menu()Adds the WordPress logo menu.
- wp_link_manager_disabled_message()Outputs the 'disabled' message for the WordPress Link Manager.
- wp_load_press_this()
- wp_plugin_update_row()Displays update information for a plugin.
- wp_print_plugin_file_tree()Outputs the formatted file list for the plugin file editor.
- wp_print_request_filesystem_credentials_modal()Prints the filesystem credentials modal when needed.
- wp_print_theme_file_tree()Outputs the formatted file list for the theme file editor.
- wp_theme_update_row()Displays update information for a theme.
Source code
function self_admin_url( $path = '', $scheme = 'admin' ) { if ( is_network_admin() ) { $url = network_admin_url( $path, $scheme ); } elseif ( is_user_admin() ) { $url = user_admin_url( $path, $scheme ); } else { $url = admin_url( $path, $scheme ); } /** * Filters the admin URL for the current site or network depending on context. * * @since 4.9.0 * * @param string $url The complete URL including scheme and path. * @param string $path Path relative to the URL. Blank string if no path is specified. * @param string $scheme The scheme to use. */ return apply_filters( 'self_admin_url', $url, $path, $scheme );}Changelog
Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.