Please or Register to create posts and topics.

Oops – how to globally unsubscribe all users

I found the magic code to subscribe all users to all topics and posts:

/* one-time function to subscribe all users to all topics and posts */
<?php
    $users = get_users();
    foreach ($users as $user) {
        update_user_meta($user->ID, 'asgarosforum_subscription_global_posts', 1);
        delete_user_meta($user->ID, 'asgarosforum_subscription_global_topics');
    }

I stupidly did it before I was finished testing everything else, and ended up sending emails out to everyone about a nonsense test.

As I don’t understand the heart of this function, can someone tell me how to reverse it?  Globally unsubscribe all users from all topics and posts?  Thank you.

After looking at the usermeta table in the database, I realized what I need to do is delete both of those meta keys from all users.  So I changed the code to delete_user_meta for both.  However, I found a more efficient function for globally deleting a metadata key:

delete_metadata(
    'user',                                   // the meta type
    0,                                        // object_id the metadata are for
    'asgarosforum_subscription_global_posts', // the meta key to be removed everywhere
    '',                                       // meta value; '' means any and all
    true                                      // ignore object_id, remove all
);

 

Asgaros has reacted to this post.
Asgaros