How to set user status in user table admin side wordpress

Posted: June 18, 2015 in Uncategorized

add php file in function.php

add_filter(‘user_row_actions’, ‘vd_add_action_links’, 10, 2);
function vd_add_action_links($actions, $user_object) {
$get_user_id= $user_object->ID;
$get_status = get_user_meta($get_user_id,’user_status’,true);
//$actions[‘vd_user_status’] = “ID”) . “‘>” . $get_status . ““;
$actions[‘vd_user_status’] = “” . $get_status . ““;
return $actions;
}
function load_vd_admin_jscss() {
wp_register_style( ‘vd_user_status_css_nm’, get_template_directory_uri() . ‘/vd_lib/css/vd_user_status.css’ );
wp_enqueue_style( ‘vd_user_status_css_nm’ );
wp_register_script(‘vd_user_status_js_nm’, get_template_directory_uri() . ‘/vd_lib/js/vd_user_status.js’, array( ‘jquery’ ) , true);
//wp_enqueue_script( ‘vd_user_status_js_nm’, get_template_directory_uri() . ‘/vd_lib/js/vd_user_status.js’, array(‘jQuery’) );
wp_enqueue_script(‘vd_user_status_js_nm’);
wp_localize_script( ‘vd_user_status_js_nm’, ‘vd_user_status_object’, array(
‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ),
‘loadingmessage’ => __(‘Sending user info, please wait…’)
));
}
add_action( ‘admin_enqueue_scripts’, ‘load_vd_admin_jscss’ );

//AJAX HANDLE

add_action( ‘wp_ajax_set_status’, ‘vd_user_status_ajax_handle’ );
add_action( ‘wp_ajax_nopriv_set_status’, ‘vd_user_status_ajax_handle’ );

function vd_user_status_ajax_handle() {
$get_uid = $_REQUEST[‘uid’];
$get_current_status = get_user_meta($get_uid,’user_status’,true);
if($get_current_status==’Approved’){
update_user_meta($get_uid,’user_status’,’Unapproved’);
echo ‘unapprove’;
}else{
update_user_meta($get_uid,’user_status’,’Approved’);
echo ‘approve’;
}
exit;
}

ADD Js

//For Add Event
jQuery(document).ready(function(e){
jQuery(‘.set_status’).click(function(e){
var get_admin_ajax_url = vd_user_status_object.ajaxurl;
var clicked = jQuery(this);
var uid=jQuery(this).attr(‘data-id’);
jQuery.ajax({
url: ajaxurl,
data: {
‘action’:’set_status’,
‘uid’ : uid
},
success:function(data) {
// This outputs the result of the ajax request
if(data==’approve’){
clicked.text(‘Approved’);
}else{
clicked.text(‘Unapproved’);
}
},
error: function(errorThrown){
alert(errorThrown);
}
});

});
});
//For Add Function
( function($) {

} )( jQuery );

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s