Support » Plugin: Email Users » Contexture Page Security and user_meta

  • Resolved ConfusedTA

    (@confusedta)


    Hi,

    I use WordPress as a database for a membership site, using Contexture Page Security (https://en-gb.wordpress.org/plugins/contexture-page-security/) for membership access, but a difference with mine is that not all members/users have email addresses – for these members we have given them an email address on our own domain.

    I am looking for ways to easily send emails to members of that group which do not have an email address that matches our domain, or those who have not opted out of receiving mails from us.

    Your plugin looks like it might do the job quite nicely, as it provides the ability to enable/disable emails, both by the user, and by the administrators in bulk 🙂

    Anyway – I have three questions 🙂

    1) Integration with Contexture – if I were to knock up an integration file which generates the list of groups, and the list of members, as per the other integration files, could this be integrated into the main core easily?

    2) Does the update of user_meta do anything else special, or could I just duplicate those check-boxes and a basic update_user_meta call into my front-end for users to update their own preferences? (I am using WooCommerce’s dashboard for everything)

    3) Do all emails sent via wp_mail() get filtered by your plugin to retrieve the user’s email preferences?

    Thanks!

    Garry

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mike Walsh

    (@mpwalsh8)

    1. The best way to do an integration is to use the filters. The integration I did with several Groups plugins works but using the filters is better. If I had to do it all over again, I’d use the filters as opposed to plugin specific integrations. There is an example of creating custom groups of users based on information in the WordPress database on my web site.
    2. No. It simply updates the fields for each user. I can’t think of any reason why you couldn’t manage the same fields and values through a different interface.
    3. No. Only emails sent through the Email Users “Send to Users”. “Send to Groups”, and “Post/Page Notifications” honor the user’s email preferences. That said, since wp_mail() is pluggable, you coould write your own handler to check the same fields as part of wp_mail().

    Hi Mike,

    Thanks for your response 🙂

    I’ve managed to get a filter appearing in the list of groups, and a meta_key placed against users, which looks to be correct!

    For reference (in case anyone is searching for similar in the future), the code I used is below.

    Contexture Page Security has an optional expiration date for group membership, and when it has expired, the users still appear as a group member, so a little logic needs to be applied to determine whether they are current or expired.

    add_action( 'mailusers_group_custom_meta_filter', 'send_to_current_members', 5 );
    
    function send_to_current_members()
    {
        mailusers_register_group_custom_meta_filter('Current Members', 'currentmember', true);
        mailusers_register_group_custom_meta_filter('Expired Members', 'expiredmember', true);
    }
    
    add_action( 'mailusers_update_custom_meta_filters', 'update_currentmembers_meta_filter', 5 );
    
    function update_currentmembers_meta_filter()
    {
        // My Contexture Page Security Group ID is 4
        // Go to Users->Groups to see the ID for your group
        $ctxps_group_id = 4;
    
        // Define the meta_key used to denote current and expired members
        $cm_mk = 'currentmember';
        $em_mk = 'expiredmember';
    	
        //  Remove all instances of the Current Member and Expired Member meta keys
        $uq = new WP_User_Query(array('meta_key' => $cm_mk));
        foreach ($uq->get_results() as $u)
        {
            delete_user_meta($u->ID, $cm_mk);
        }
    	
        $uq = new WP_User_Query(array('meta_key' => $em_mk));
        foreach ($uq->get_results() as $u)
        {
            delete_user_meta($u->ID, $em_mk);
        }
    	
        // Get a list of all users who belong to the specified group
        $uq = CTXPS_Queries::get_group_members($aoc_ctxps_group_id);
    
        //  Loop through the users who are members of the group and check
        //  whether they are still current or expired
        foreach ($uq as $u)
        {
            if(!is_null($u->grel_expires))
            {
                // An expiry date has been set for this user
                $timestamp = strtotime($u->grel_expires);
                if ($timestamp < time()) {
                    // Expiry is earlier than Now, this user is Expired
                    update_user_meta($u->ID, $em_mk, true);
                } else {
                    // Expiry is later than No, this user is still a current member
                   update_user_meta($u->ID, $cm_mk, true);
                }            
            } else {
                // No expiration is set, this user is a member
                update_user_meta($u->ID, $cm_mk, true);
            }
        }
    }

    I will add check-boxes for the two options into the WooCommerce dashboard, and look at hooking into wp_mail() to check recipients against the meta values created by this plugin.

    Thanks!

    Garry

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.