Answer the question
In order to leave comments, you need to log in
How to add or add a function?
Help me please, there is a code for adding an object to bookmarks:
if ( ! function_exists( 'cs_addto_usermeta_carosel' ) ) :
function cs_addto_usermeta_carosel() {
$user = cs_get_user_id();
if(isset($user) && $user <> ''){
if(isset($_POST['post_id']) && $_POST['post_id'] <> ''){
$cs_wishlist = cs_get_user_meta();
$cs_wishlist = (isset($cs_wishlist) and is_array($cs_wishlist)) ? $cs_wishlist : array();
if ( isset ( $cs_wishlist ) && in_array( $_POST['post_id'] , $cs_wishlist )) {
$post_id = array();
$post_id[] = $_POST['post_id'];
$cs_wishlist = array_diff( $post_id , $cs_wishlist );
cs_update_user_meta( $cs_wishlist );
echo '<i class="icon-star-o"></i>';
die();
}
$cs_wishlist = array();
$cs_wishlist = get_user_meta(cs_get_user_id(),'cs-directory-wishlist', true);
$cs_wishlist[] = $_POST['post_id'];
$cs_wishlist = array_unique($cs_wishlist);
update_user_meta(cs_get_user_id(),'cs-directory-wishlist',$cs_wishlist);
$user_watchlist = get_user_meta(cs_get_user_id(),'cs-directory-wishlist', true);
$cs_icon = '<i class="icon-star2"></i>';
$cs_pop_msg = '<div class="outerwrapp-layer">'.__('Added to Favourite','directory').'</div>';
$cs_html = array(
'icon' => $cs_icon,
'msg' => $cs_pop_msg,
);
$cs_json = json_encode($cs_html);
echo $cs_json;
}
} else {
_e('You have to login first.','directory');
}
die();
}
endif;
add_action("wp_ajax_cs_addto_usermeta_carosel", "cs_addto_usermeta_carosel");
add_action("wp_ajax_nopriv_cs_addto_usermeta_carosel", "cs_addto_usermeta_carosel");
Answer the question
In order to leave comments, you need to log in
function cs_addto_usermeta_carosel() {
$user_data = get_userdata( get_current_user_id() );
if( 'subscriber' === $user_data->roles[0] )
wp_die();
/** Остальной код **/
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question