• Resolved mdrees321

    (@mdrees321)


    Hi community,

    thx for the awesome plugin.

    I would like to know where I can find the action which adds an user_id to the meta_key “bnfw_users” in the wp_postmeta table.

    I added a custom field on the profile page where the user can click a checkbox for recieving the selected notification. I use Pods and already have the custom field.

    With the hook “personal_options_update” I want to add the user_id to the “bnfw_users”.

    Any suggestions? Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author bnfw

    (@voltronik)

    Hi @mdrees321,
    Thanks for your message.

    There aren’t any actions or hooks that are readily available for developers outside of the ones in the Documentation at present. I do plan to add some but this is a way off yet. Additionally, an add-on is planned to add opt-in / opt-out support for notifications on a per-user basis via their profile.

    You may also be interested in the Custom Fields add-on.

    Hope this helps and remember, if you like the plugin and the support, please feel free to leave an honest review.

    Thanks,
    Jack

    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');
    
    Plugin Author bnfw

    (@voltronik)

    Hi @mdrees321,
    Thanks for sending this through.

    I’ll take a better look when I get around to the user opt-in/opt-out add-on.

    Thanks,
    Jack

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hook for adding user_id to notification’ is closed to new replies.