Forum

Thread tagged as: Question, Forms, Members

At the moment I am just running it within a page on the site to see if it will work, but the idea would be for it to be an app on the dashboard that runs when the client logs into perch, checks all the members to see if any of the verifications are out of date, and then tags members as unverified if they are.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, you need to appreciate that those are two different environments that won't behave in the same way. Testing code in one doesn't mean it'll work in the other and vice versa.

If it's control panel app code, run it in the app environment.

Ah ok gotcha. Will give that a go.

Ok So I've been running this as an app eventually. I can't find any docs about the members API. How would you test for a specific tag for all members? As above I've tried:

$API = new PerchAPI(1.0, 'perch_members');
            $Members = new PerchMembers_Members($API);
            $members = $Members->all();
            foreach($members as $Member) {
                if($Member->has_tag('verified')) {
                    $Member->add_tag('unverified', true, '2016-01-01');
                };
            };

But it doesn't work and Debug says missing property has_tag.

Any suggestions as to how to achieve this and then output a list of all members with a certain tag?

Drew McLellan

Drew McLellan 2638 points
Perch Support

There's no has_tag() method on a Member. Rather than using $Members->all() you could use

$members = $Members->get_by_tag_for_admin_listing('verified');

Brill thanks for that! That got me working. Is there anyway to then output a list of those members? And is it possible to remove the widget from the sidebar in the Perch UI? In the docs it says set it to false in admin.php but this doesnt seem to work.

For anyone else trying to do the same thing here is my final code:

    $API = new PerchAPI(1.0, 'perch_members');

    $Members = new PerchMembers_Members($API);
    $allMembers = $Members->all(); //Get a list of all members
    $verifiedMembers = $Members->get_by_tag_for_admin_listing('verified'); //Get list of verified members

    foreach($allMembers as $Member) {
        $Member->add_tag('unverified'); //Add unverified tag to everyone
    };

    foreach($verifiedMembers as $Member) {
        $Member->add_tag('unverified', true, '2016-01-01'); //Remove unverified tags from anyone with verified tag
    };