Assign a listing owner by category
- Thread started
- Last updated
What you’ll achieve
Assign listings in a selected category to a designated user when they are created or edited through the site form.
My site
Assign listings in one category to a specific user when visitors create or edit them through the site form.
Choose the category and the new owner
Choose the target category and intended owner account. The examples use category 6 and owner 5; replace both with administrator-approved IDs.
The examples assign the designated owner when a listing is created or edited in that category. Editing an existing listing can therefore transfer ownership and change who can edit, preview, delete, publish, or manage its media. Let only administrators configure the category-to-owner mapping. Do not choose the owner from a user-submitted ID.
Keep the customization in your JReviews overrides. Start a new PHP file with <?php followed by defined('MVC_FRAMEWORK') or die;. In an existing file, add the callback without repeating the opening tag or guard. If a snippet includes those lines, keep each only once.
JReviews 6 Early Access
Enable Listing Form in Early Access.
Assign the category owner
Joomla. Use templates/jreviews_overrides/hooks.php.
WordPress. Use jreviews_overrides/hooks.php.
Add the callback marked with +. Replace category 6 and owner 5 with the approved IDs. This version applies only to saves through the site form; it leaves control-panel saves unchanged.
- If
hooks.phpalready exists, add the marked lines at the end of the file. The copy button copies only those lines. - If you are creating
hooks.php, type the two dimmed lines first, then add the marked lines below them.
<?php
defined('MVC_FRAMEWORK') or die;
fwd_add_filter('jreviews:listing.data_before_save', function (array $data, $listing): array {
if (! fwd_request()->inFrontend()) {
return $data;
}
if ((int) ($data['cat_id'] ?? $listing->cat_id) === 6) {
$data['owner_id'] = 5;
}
return $data;
}, 20, 2);
Keep existing owners
To assign the owner only when creating a listing, add if ($listing->exists) { return $data; } immediately before the if ((int) category check. Existing listings then keep their owners when edited.
JReviews 5 and v6 Legacy
Assign the category owner
Joomla. Use templates/jreviews_overrides/filters/filter_functions.php.
WordPress. Use jreviews_overrides/filters/filter_functions.php.
Replace category 6 and owner 5 with the approved IDs.
function assign_user($data, $params)
{
// Check category id
if ( $data['Listing']['catid'] == 6 ) {
$data['Listing']['created_by'] = 5; // assign listings created in catid 6 to user #5
}
return $data;
}
Clickfwd\Hook\Filter::add('listing_save_pre', 'assign_user', 10);
Keep existing owners
To assign the owner only when creating a listing, add if (!$params['is_new']) { return $data; } immediately before the // Check category id line. Existing listings then keep their owners when edited.
This hook runs on site-form saves. Current control-panel saves use a separate save process and do not call this hook.
Check ownership and access
Create a listing in the target category, edit it, and create a listing in another category. Check the resulting owner and access for both the submitter and designated recipient. Repeat a control-panel edit and confirm that the mapping leaves its owner unchanged. If you added a creation-only condition, confirm an edit preserves the existing owner.