Manually subscribing members to Forum
Quote from notechup on December 1, 2018, 6:40 pmHi,
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 ); } ?>
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 ); } ?>
Quote from Asgaros on December 1, 2018, 7:01 pmHello @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.
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.
Quote from notechup on December 2, 2018, 5:31 pmHey,
Thanks for the input and clarification. I have it working correctly now 🙂
Hey,
Thanks for the input and clarification. I have it working correctly now 🙂