Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter mdrees321

    (@mdrees321)

    I found a way, I have used PODS for creating an additional user field on the profile page. This field has multiple checkboxes which allow the user to select which notifications (“benachrichtigungen” is the custom post field in the users profile created by PODS) he want to recieve. It is quite dirty code so just a impression of how it could be handled. Maybe helpful.

    function changenotiuser($user)
    {
    # GET PODS FROM USER
    $user_id = $user->ID;
    $user = get_userdata( $user_id);
    $user_noti = get_user_meta($user_id,"benachrichtigungen");
    $args = array('post_type'=> 'bnfw_notification');              
    $the_query = new WP_Query( $args );
    if($the_query->have_posts() )
    	{ 
    	while ( $the_query->have_posts() )
    		{
    		$the_query->the_post();
    		$title = get_the_title();
    		$bnfw_users = get_post_meta( get_the_ID(), "bnfw_users" , true );
    # UPDATE BNFW NOTIFICATION USER
    		if(in_array($title,$user_noti))
    			{
    			# SCHREIBE / ENTFERNE USER AUS SETTINGS VON BNFW
    			if(in_array($user_id,$bnfw_users))
    				{
    				# User Steht schon drin und gehört auch rein tue nix
    				}
    			else
    				{
    				$bnfw_users[] = $user_id;
    				update_post_meta(get_the_ID(), "bnfw_users", $bnfw_users);
    				}
    			}
    		else
    			{
    			# User muss aus BNFW RAUS
    			$tmp = array();
    			foreach($bnfw_users as $uid)
    				{
    				if($uid == $user_id) continue;
    				$tmp[] = $uid;
    				}
    			update_post_meta(get_the_ID(), "bnfw_users", $tmp);
    			}
    		}
    	}
    }
     add_action('edit_user_profile', 'changenotiuser');
     add_action('show_user_profile', 'changenotiuser');
    
Viewing 1 replies (of 1 total)