I am trying to develop a WordPress plugin that will send a variable to my server. So far if I use my code bellow as separate PHP file and not within my script works great.. it sends the variables and receive the results from remote PHP file.
If I put the same code in my custom WordPress plugin it doesn't receive anything.
my code:
<script>
jQuery(document).ready(function(){
jQuery(".adminpnlnshbutton").click(function(){
var usermail = jQuery('#uemail').val();
var userkey = jQuery('#ukey').val();
var dataString = 'usermail='+ usermail + '&userkey='+ userkey;
$.ajax({
type: "POST",
url: "http://www.myremotedomain.co.uk/check.php",
data: dataString,
crossDomain: true,
dataType: 'html',
success: function(data) {
alert (data);
}
});
});
});
</script>
And check PHP:
$m = $_POST['usermail'];
$k = $_POST['userkey'];
$s = " | ";
echo $m . $s . $k;
As WordPress plugin:
<?
add_action('admin_menu', 'test_plugin_setup_menu');
function test_plugin_setup_menu(){
add_menu_page( 'Test Plugin Page', 'Tes Plugin', 'manage_options', 'test-plugin', 'test_init' );
}
function test_init(){
if (is_user_logged_in()) {
?>
<input name="uemail" type="text" id="uemail" value="email" />
<input name="ukey" type="text" id="ukey" value="activation key" />
<div class="adminpnlnshbutton">SEND</div>
<script>
jQuery(document).ready(function(){
jQuery(".adminpnlnshbutton").click(function(){
var usermail = jQuery('#uemail').val();
var userkey = jQuery('#ukey').val();
var dataString = 'usermail='+ usermail + '&userkey='+ userkey;
$.ajax({
type: "POST",
url: "http://www.myremotedomain.co.uk/check.php",
data: dataString,
crossDomain: true,
dataType: 'html',
success: function(data) {
alert (data);
}
});
});
});
</script>
<?
}
}
?>
any idea why I can't receive the data inside my plugin?