Opened 12 years ago
Last modified 10 months ago
#27888 assigned feature request
Feature request: `get_current_admin_url()` and `get_current_admin_hook()`
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 3.9 |
| Component: | Administration | Keywords: | good-first-bug has-patch needs-testing has-unit-tests |
| Focuses: | administration | Cc: |
Description
It would be sweet if to be able to get the current page's url using some kind of API. And its hook, for that matter. For instance:
public function get_current_admin_page_url()
{
if (!is_admin()) {
return false;
}
global $pagenow;
global $typenow;
global $taxnow;
global $plugin_page;
$url = $pagenow;
if (!empty($plugin_page)) {
$url .= '?page='.$plugin_page;
}
elseif (!empty($typenow)) {
$url .= '?post_type='.$typenow;
}
elseif (!empty($taxnow)) {
$url .= '?taxonomy='.$taxnow;
}
return $url;
}
And something similar for get_current_admin_hook().
Attachments (5)
Change History (24)
This ticket was mentioned in Slack in #core by tahteche. View the logs.
10 years ago
#5
@
10 years ago
I could be misunderstanding, but doesn't global $hook_suffix cover the page's hook?
#6
in reply to:
↑ 3
;
follow-up:
↓ 7
@
10 years ago
Replying to swissspidy:
I am up for it. Could you tell me where would it go? Inside pluggable.php ?
#7
in reply to:
↑ 6
;
follow-up:
↓ 8
@
10 years ago
Replying to mrahmadawais:
Replying to swissspidy:
I am up for it. Could you tell me where would it go? Inside
pluggable.php?
pluggable.php is only for "pluggable" functions (wrapped in if ( ! function_exists( ... ) ) blocks), which is considered a bad practice.
I'm not that familiar with the file structure inside wp-admin, but I'd put it inside wp-admin/includes/misc.php for now.
Note: Not wp-includes, because the suggested functions are only needed in the admin.
#8
in reply to:
↑ 7
@
10 years ago
Replying to swissspidy:
Replying to mrahmadawais:
Replying to swissspidy:
Got it, will contribute a patch at the weekend.
@
9 years ago
Patch to add a get_current_admin_page_url() function into wp-admin/includes/misc.php. This is my first patch, so be gentle with me when feeding back.
@
9 years ago
Patch to add a get_current_admin_hookl() function into wp-admin/includes/misc.php. This is only my second patch, so feedback appreciated.
#10
@
9 years ago
- Keywords has-patch needs-testing added; needs-patch removed
I should note that 27888.2.diff contains both patches, including the one from 27888.diff.
This ticket was mentioned in Slack in #core by mwtsn. View the logs.
9 years ago
#13
@
9 years ago
@jorbin, sample use case: I borrowed this function and use it in admin bar menu, allowing me to return to the page I was on when returning from the customizer, eg:
<?php function add_admin_bar_customizer_url( $wp_admin_bar ) { global $post; $return_url = ( is_admin() ) ? $this->_get_current_admin_page_url() : get_permalink( $post->ID ); $args = array( 'id' => 'plugin-customizer-link', 'title' => __( 'Plugin Customizer', 'plugin-customizer' ), 'href' => $this->_get_customizer_url( $return_url, 'plugin_settings_panel' ), ); $wp_admin_bar->add_node( $args ); }
#14
@
9 years ago
@mwtsn
Thanks for the patch.
I have enhanced your patch by adding phpdoc blocks to the functions.
Also I am wondering if we really need get_current_admin_hook, since right now it is just a wrapper to current_filter function.
#15
@
9 years ago
Hi there,
I've created a patch that adds tests to cover the two new functions, let me know if it helps. The patch only applies to the the tests/phpunit/tests/admin/includeMisc.php file.
#16
@
9 years ago
Adding a further patch that refactors the previously existing tests to use data providers, again this patch will only apply to the tests/phpunit/tests/admin/includeMisc.php file.
#17
@
8 years ago
- Owner set to lucatume
- Status changed from new to assigned
Assigning ownership to mark the good-first-bug as "claimed".
This ticket was mentioned in Slack in #core by sergey. View the logs.
6 years ago
This ticket was mentioned in PR #8266 on WordPress/wordpress-develop by @sukhendu2002.
10 months ago
#19
- Keywords has-unit-tests added; needs-unit-tests removed
Trac ticket: https://core.trac.wordpress.org/ticket/27888
Patch Refresh for: https://core.trac.wordpress.org/attachment/ticket/27888/27888.3.patch
Somewhat related: #27737