Created
August 18, 2011 22:15
-
-
Save mjangda/1155395 to your computer and use it in GitHub Desktop.
Get a domain-mapping safe admin-ajax URL on WordPress.com
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 | |
/** | |
* Generates a domain-mapping safe URL on WordPress.com | |
* Core's ajaxurl uses admin_url() which returns *.wordpress.com which doesn't work for the front-end on domain-mapped sites. | |
* This works around that and generates the correct URL based on context. | |
*/ | |
function my_admin_ajax_url( $path = '' ) { | |
if ( is_admin() ) | |
$url = admin_url( 'admin-ajax.php' ); | |
else | |
$url = home_url( 'wp-admin/admin-ajax.php' ); | |
$url .= ltrim( $path, '/' ); | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment