Created
November 28, 2012 22:20
-
-
Save boonebgorges/4165099 to your computer and use it in GitHub Desktop.
A function for reliably testing whether you're in the WordPress Dashboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Are we looking at the WordPress admin? | |
* | |
* Because AJAX requests are sent to wp-admin/admin-ajax.php, WordPress's | |
* is_admin() function returns true when DOING_AJAX. This function contains | |
* logic to test whether AJAX requests are coming from the front end or from | |
* the Dashboard. | |
* | |
* @return bool | |
*/ | |
function bbg_is_admin() { | |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { | |
// wp_get_referer() should contain the URL of the requesting | |
// page. Check to see whether it's an admin page | |
$is_admin = 0 === strpos( wp_get_referer(), admin_url() ); | |
} else { | |
$is_admin = is_admin(); | |
} | |
return $is_admin; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clever!
Could you exemplify a use case for this function?