Hi @tychow 👋
Thank you again for your patience — and sorry for the delay in replying. We really appreciate you waiting for us.
About your question — you can check whether a group exists using the Permissions API. And if the group doesn’t exist, you can create it and assign permissions immediately with the configuration you described:
Add Specific Permissions → Post type: Post → Operation: View → Adjustment: Enable → Qualification → Categories → All Statuses → select a specific category
Below is a complete working example. This version will check the group by name, create it if it doesn’t exist, and then assign the permissions:
<?php
try {
// Try to get the group by name
$group = pp_get_group_by_name("Sample Group", 'pp_group');
// If no group found, create one
if (!$group) {
$group_id = pp_create_group([
'group_name' => 'Sample Group',
'group_description' => 'Automatically created group'
]);
if (!$group_id) {
exit("❌ ERROR: Failed to create group\n");
}
echo "✅ SUCCESS: Group created with ID {$group_id}\n";
$group = get_post($group_id); // Load group object
}
// Get the target category (example: slug = sample-category)
$term = get_term_by('slug', 'sample-category', 'category');
// Assign permission rules
$args = [
'operation' => 'read',
'mod_type' => 'additional',
'for_item_source' => 'post',
'for_item_type' => 'post',
'via_item_source' => 'term',
'via_item_type' => 'category',
'item_id' => $term->term_taxonomy_id,
];
$agents = [];
$agents['item'][$group->ID] = true;
ppc_assign_exceptions($agents, 'pp_group', $args);
echo "✅ SUCCESS: Permissions assigned successfully to group\n";
} catch (Exception $e) {
exit('❌ ERROR: ' . $e->getMessage());
}
Short explanation
- Post type: Post -> ‘for_item_type’ => ‘post’,
- Operation: View -> ‘operation’ => ‘read’,
- Adjustment: Enable -> ‘mod_type’ => ‘additional’,
- Categories -> ‘via_item_type’ => ‘category’,
- select a specific category -> ‘item_id’ => $term->term_taxonomy_id,
Just let us know — we’re always glad to help! 🙌
Wishing you a wonderful day ahead!