Created
June 13, 2014 00:11
-
-
Save georgestephanis/c8bdd3079b0cfba85067 to your computer and use it in GitHub Desktop.
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
$.getJSON( 'http://target-domain.com/wp-admin/admin-ajax.php?action=get_my_user_data', function(data) { | |
console.log( data ); | |
} ); |
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 | |
add_action( 'wp_ajax_get_my_user_data', 'demo_wp_ajax_get_my_user_data' ); | |
function demo_wp_ajax_get_my_user_data() { | |
if ( is_user_logged_in() ) { | |
wp_send_json_success( get_currentuserinfo() ); | |
} else { | |
wp_send_json_error( new WP_Error( __( 'User is not logged in.' ) ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getJSON would have to be setup to specifically use JSONP, and the JSON responses would need to produce callbacks. Origins would also be needed to be overridden via filters to support requests from other domains. Currently, only http/https versions of admin_url() / home_url() are allowed: