Please or Register to create posts and topics.

Manually subscribing members to Forum

Hi,

I know this one has been touched upon a bit before, and I know of the legal implications, but we need to implement it on the site as a one time off event and for all new members. Later they can choose to subscribe from the Forum in question.

We need members to become subscribed to a few forums, and receive notifications about new topics.

From my understanding, a row in the db is generated when subscribing, so we tested out adding that row to members in the DB, however, notifications are not sent out, so I’m guessing this is not the correct way 🙂

Do you see any obvious mistake we have done?  Thanks for all the support so far 🙂

Code:

/*Add Usermeta*/

 if( ! get_option('number_loop_execution') ) {
 add_option('number_loop_execution', '1');
 }

 if( get_option('number_loop_execution') === '1' ) {
$users = get_users( array( 'fields' => array( 'ID' ) ) );

foreach( $users as $user ) {

add_user_meta( $user->ID, 'asgarosforum_subscription_forum', '11', false );
 add_user_meta( $user->ID, 'asgarosforum_subscription_forum', '12', false );
 add_user_meta( $user->ID, 'asgarosforum_subscription_forum', '13', false ); 
 }

 update_option('number_loop_execution', '2');
}

add_action( 'user_register', 'custom_add_user_meta', 10, 1 );
function custom_add_user_meta( $user_id ) {

add_user_meta( $user_id, 'asgarosforum_subscription_forum', '11', false );
add_user_meta( $user_id, 'asgarosforum_subscription_forum', '12', false );
add_user_meta( $user_id, 'asgarosforum_subscription_forum', '13', false );
}
?>

 

Hello @notechup

First ensure, that the notifications-functionality itself is enabled.

The code looks fine, but you can try to use the following instead:

add_user_meta($user->ID, 'asgarosforum_subscription_forum', 11);

The only difference to your code is:

  • use numeric value instead of a string
  • removed the fourth false-argument

Please verify with a test-user, if the forums appear in the list inside the subscription-overview. If not you may also have to remove the number_loop_execution logic because the value could already be set to 2.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Hey,

Thanks for the input and clarification. I have it working correctly now 🙂

Asgaros has reacted to this post.
Asgaros