Custom Worpdress Plugin Ajax Call return 0. Main File as Bellow.
<?php
/*
Plugin Name: XYZ
*/
class GMS_SMS_Notifier {
public function __construct(){
if (is_admin()){
//JS
add_action( 'admin_enqueue_scripts',array($this,'load_custom_js_scripts'));
}
function load_custom_js_scripts() {
wp_register_script( 'gms_custom', plugins_url('/assets/js/gms_custom.js', __FILE__ ),false,'1.0',true);
wp_localize_script('gms_custom','plugin_ajax',array('ajaxurl'=>admin_url('admin-ajax.php')));
wp_enqueue_script('gms_custom');
}
function mail_send_to(){
global $wpdb;
echo $_POST['recordID'].'Hello';
die();
add_action('wp_ajax_mail_send_to','mail_send_to');
add_action('wp_ajax_nopriv_mail_send_to','mail_send_to');
} // End Class GMS_SMS_Notifier
new GMS_SMS_Notifier();
Custom Function do not want to add function in theme function.php
JS file gms_custom.js as bellow
$(".send_mail_btn").click(function(){
var recordids = $(this).attr("id");
$.ajax({
url: plugin_ajax.ajaxurl,
type: 'POST',
data: ({
action: 'mail_send_to',
recordID: recordids,
}),
success: function(data) {
console.log(data);
}
});
});
Problem: Custom Function put on theme function.php working fine.but when put on plugin file that not working. I wan't same file
Given me your suggestion.
Thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire