Difference between revisions of "JReviews:Developers Filters"
(→Description) |
(→Listing Detail Action Buttons) |
||
Line 532: | Line 532: | ||
==== Description ==== | ==== Description ==== | ||
− | The "listing_detail_action_buttons" filter is used to filter the page | + | The "listing_detail_action_buttons" filter is used to filter the action buttons in the detail page. |
==== Usage ==== | ==== Usage ==== | ||
Line 563: | Line 563: | ||
</source> | </source> | ||
+ | === Listing Detail Action Button Extras === | ||
+ | |||
+ | ==== Description ==== | ||
+ | |||
+ | The "listing_detail_action_buttons extras" filter is used to filter the action buttons in the detail page. The extras button are processed before the rest of the buttons and are sometimes used to insert add-on buttons. | ||
+ | |||
+ | ==== Usage ==== | ||
+ | |||
+ | When the "listing_detail_action_buttons extras" filter is called, it is passed two arguments. The first argument is an associative array of button positions, allowing adding new buttons . The second argument is an associative array with context data. | ||
=== Post Get Listing Detailpage Query === | === Post Get Listing Detailpage Query === |
Revision as of 00:34, 17 May 2018
JReviews 3 comes with Filters that allow you to make certain types of customizations and extend the functionality of JReviews without having to modify core files.
Contents
- 1 What is a Filter?
- 2 Defining a new Filter Hook
- 3 Using Filter Functions
- 4 Available Filters
- 4.1 Notifications
- 4.2 Asset Manager
- 4.3 Metatags
- 4.4 Listings
- 4.5 Listings List
- 4.6 Listing Detail
- 4.7 Listing Permissions
- 4.7.1 Trusted On Listing Create
- 4.7.2 Listing Allows Claims
- 4.7.3 Listing Allows Inquiries
- 4.7.4 Listing Allows Favorites
- 4.7.5 Listing Allows User Reviews
- 4.7.6 Listing Allows Editor Reviews
- 4.7.7 Listing User Reviews Open
- 4.7.8 Listing Editor Reviews Open
- 4.7.9 Can Create Listing
- 4.7.10 Can Update Listing
- 4.7.11 Can Add Listing Metadata
- 4.7.12 Can User WYSIWYG Editor in Listing
- 4.7.13 Can Publish Listing
- 4.7.14 Can Delete Listing
- 4.7.15 Can Claim Listing
- 4.7.16 Can Send Listing Inquiry
- 4.7.17 Can Favorite Listing
- 4.7.18 Can Feature Listing
- 4.7.19 Can Create User Review For Listing
- 4.7.20 Can Create Editor Review For Listing
- 4.7.21 Can Add Review on Listing Create
- 4.7.22 Can Update Listing Media
- 4.7.23 Can Upload Listing Media
- 4.7.24 Can Upload Listing Media From URL
- 4.7.25 Can Upload Listing Photo
- 4.7.26 Can Upload Listing Video
- 4.7.27 Can Upload Listing Audio
- 4.7.28 Can Upload Listing Attachment
- 4.8 Media Permissions
- 4.8.1 Trusted On Create Photo
- 4.8.2 Trusted On Create Video
- 4.8.3 Trusted On Create Audio
- 4.8.4 Trusted On Create Attachment
- 4.8.5 Media Allows Voting
- 4.8.6 Media Allows Report
- 4.8.7 Can Update Media In Listing
- 4.8.8 Can Delete Media In Listing
- 4.8.9 Can Publish Media In Listing
- 4.8.10 Can Set Main Media
- 4.8.11 Can Vote on Media
- 4.8.12 Can Report Media
- 4.8.13 Can Download Attachment
- 4.9 Review Permissions
- 4.9.1 Trusted on Create User Review
- 4.9.2 Trusted on Update User Review
- 4.9.3 Trusted on Create Editor Review
- 4.9.4 Trusted on Update Editor Review
- 4.9.5 Trusted on Create Review Owner Reply
- 4.9.6 Review Allows Report
- 4.9.7 Review Allows Voting
- 4.9.8 Review Allows Replies
- 4.9.9 Review Allows Discussions
- 4.9.10 Can Update Review
- 4.9.11 Can Reply To Review
- 4.9.12 Can Delete Review Reply
- 4.9.13 Can Report Review
- 4.9.14 Can Vote On Review
- 4.9.15 Can Create Review Comment
- 4.9.16 Can Upload Review Media
- 4.9.17 Can Upload Review Media From URL
- 4.9.18 Can Upload Review Photo
- 4.9.19 Can Upload Review Video
- 4.9.20 Can Upload Review Audio
- 4.9.21 Can Upload Review Attachment
- 4.10 Review Discussion Permissions
- 4.11 Field Permissions
- 4.12 UserProfiles Add-on
What is a Filter?
JReviews has many filter hooks strategically placed in the code at points where you may want to change or override the value of a variable at runtime.
Filters can modify data by binding a callback function to a filter hook. When the filter is executed, each callback function is run in order of priority, and can modify the filtered data by returning a new value.
For example, you can use a filter to:
- Change the page title and metatags of different pages
- Override the permissions of specific users or user groups for different events (creating listings, reviews, etc.)
- Add or remove CSS and Scripts to and from the page.
Defining a new Filter Hook
JReviews 3 already comes with many filter hooks and we'll add more over time. However, if you need to create a new filter that is not yet available you would use the following syntax:
$data = \Clickfwd\Hook\Filter::filter('example_filter_name', $data, ['foo'=>$bar]);
Where:
- $data is the variable that can be modified by filter callback function
- $params are other arguments that can be passed to the filter callback function to provide context and their values cannot be modified by the filter.
Using Filter Functions
The following example shows how a callback function is bound to a filter hook:
function example_filter_callback_function($data, $params = []) { // Modify $data in some way and return it return $data; } Clickfwd\Hook\Filter::add('example_filter_name', 'example_filter_callback_function', $priority = 10);
The $data variable can be modified inside the callback function and must always be returned at the end of the function.
To create new filter functions that are not overwritten on upgrades, create a new file in overrides and place your filter functions there:
Joomla
/templates/jreviews_overrides/filters/filter_functions.php
WordPress
/jreviews_overrides/filters/filter_functions.php
Available Filters
Notifications
Listing Inquiry Email Payload
Description
The "modify_inquiry_sender_info" filter is used to filter the inquiry email payload before the email is sent.
Usage
When the "modify_inquiry_sender_info" filter is called, it is passed two arguments. The first argument is an associative array with the email payload ($to, $bcc, $fromEmail, $fromName, $subject, $body). The second argument is an associative array with context data for the $listing and $event that triggered the email. $event is an object that allows retrieving sender user ID and IP address information.
Examples
Modify sender name and email
By default when an inquiry email is sent, the sender name and e-mail address are populated with the information entered in the inquiry form. This allows the recipient of the inquiry to reply directly to the sender. However, in some cases, you may not want the recipient to reply directly to the sender and you can use this filter to modify the email values before it is sent.
function modify_inquiry_sender_info($payload) { $payload['fromEmail'] = '[email protected]'; $payload['fromName'] = 'John Smith'; return $payload; } Clickfwd\Hook\Filter::add('listing_inquiry_email_payload', 'modify_inquiry_sender_info', 10);
Asset Manager
Asset Manager Stylesheets
Description
The "asset_manager_stylesheets" filter is used to filter the stylesheets loaded by JReviews and Add-ons.
Usage
When the "asset_manager_stylesheets" filter is called, it is passed an associative array containing the paths of the stylesheets that will be loaded on the page. The array contains keys for different namespaces used to load stylesheets so it's possible to control the order in which these are loaded. The namespaces are: addon, core, bottom, and top.
Examples
Unload jQuery UI Stylesheet
It is possible to stop specific stylesheets from loading if you want to use your own stylesheets or have already overwritten them in your site's stylesheet.
function remove_stylesheets($stylesheets) { // Uncomment line below to dump filter arguments to the screen // dd($stylesheets); unset($stylesheets['core']['jquery_ui_theme/jquery-ui-1.9.2.custom.css']); return $stylesheets; } Clickfwd\Hook\Filter::add('asset_manager_stylesheets', 'remove_stylesheets', 10);
Asset Manager Scripts
Description
The "asset_manager_scripts" filter is used to filter the scripts loaded by JReviews and Add-ons.
Usage
When the "asset_manager_scripts" filter is called, it is passed an associative array containing the paths of the scripts that will be loaded on the page. The array contains keys for different namespaces used to load scripts so it's possible to control the order in which these are loaded. The namespaces are: addon, core, bottom, and top.
Examples
Unload bxSlider Script
function remove_scripts($scripts) { // Uncomment line below to dump filter arguments to the screen // dd($scripts); unset($jsArray['top']['bxslider-4/jquery.bxslider.min.js']); return $scripts; } Clickfwd\Hook\Filter::add('asset_manager_scripts', 'remove_scripts', 10);
Metatags
Page Title Tag
Description
The "page_title_metatag" filter is used to filter the page title tag.
Usage
When the "page_title_metatag" filter is called, it is passed two arguments. The first argument is the page title. The second argument is an associative array with context data.
function page_title_tag($title, $params) { // Uncomment line below to dump filter arguments to the screen // dd($title, $params); return $title; } Clickfwd\Hook\Filter::add('page_title_metatag', 'page_title_tag', 10);
Examples
Prepend Listing Count To Category Page Title Tag
This example will prepend the total number of listings in a category page to the page title tag. You can modify the example to limit the filter functionality to specific category IDs or menu IDs using the $catId and $menuId variables.
function add_count_category_title($title, $params) { // Uncomment line below to dump filter arguments to the screen // dd($title, $params); $categoryPage = S2Array::get($params,'route') == 'categories.category'; $catId = S2Array::get($params,'vars.cat_id'); $menuId = S2Array::get($params,'vars.params.Itemid'); $count = S2Array::get($params,'pagination.total'); if ( $categoryPage && $count ) { $title = $count .' '.$title; } return $title; } Clickfwd\Hook\Filter::add('page_title_metatag', 'add_count_category_title', 10);
Page Robots Metatag
Description
The "page_robots_metatag" filter is used to filter the page robots metatag so you can change the indexing rules for specific pages.
Usage
When the "page_robots_metatag" filter is called, it is passed two arguments. The first argument is the current value of the robots metatag. The second argument is an associative array with context data.
function change_robots_metatag($robots, $params) { // Uncomment line below to dump filter arguments to the screen // dd($robots, $params); return $robots; } Clickfwd\Hook\Filter::add('page_robots_metatag', 'change_robots_metatag', 10);
Page Keywords Metatag
Description
The "page_keywords_metatag" filter is used to filter the page keywords metatag.
Usage
When the "page_keywords_metatag" filter is called, it is passed two arguments. The first argument is the current value of the keywords metatag. The second argument is an associative array with context data.
function change_keywords_metatag($keywords, $params) { // Uncomment line below to dump filter arguments to the screen // dd($keywords, $params); return $keywords; } Clickfwd\Hook\Filter::add('page_keywords_metatag', 'change_keywords_metatag', 10);
Page Description Metatag
Description
The "page_description_metatag" filter is used to filter the page description metatag.
Usage
When the "page_description_metatag" filter is called, it is passed two arguments. The first argument is the current value of the description metatag. The second argument is an associative array with context data.
function change_description_metatag($description, $params) { // Uncomment line below to dump filter arguments to the screen // dd($description, $params); return $description; } Clickfwd\Hook\Filter::add('page_description_metatag', 'change_description_metatag', 10);
Page Canonical Metatag
Description
The "page_canonical_metatag" filter is used to filter the page canonical URL.
Usage
When the "page_canonical_metatag" filter is called, it is passed two arguments. The first argument is the current value of the canonical link URL. The second argument is an associative array with context data.
function change_canonical_metatag($url, $params) { // Uncomment line below to dump filter arguments to the screen // dd($url, $params); return $url; } Clickfwd\Hook\Filter::add('page_canonical_metatag', 'change_canonical_metatag', 10);
Page Prev Metatag
Description
The "page_canonical_metatag" filter is used to filter the page prev metatag.
Usage
When the "page_canonical_metatag" filter is called, it is passed two arguments. The first argument is the current value of the prev link URL. The second argument is an associative array with context data.
function change_prev_metatag($url, $params) { // Uncomment line below to dump filter arguments to the screen // dd($url, $params); return $url; } Clickfwd\Hook\Filter::add('page_prev_metatag', 'change_prev_metatag', 10);
Page Next Metatag
Description
The "page_next_metatag" filter is used to filter the page next metatag.
Usage
When the "page_next_metatag" filter is called, it is passed two arguments. The first argument is the current value of the next link URL. The second argument is an associative array with context data.
function change_next_metatag($url, $params) { // Uncomment line below to dump filter arguments to the screen // dd($url, $params); return $url; } Clickfwd\Hook\Filter::add('page_next_metatag', 'change_next_metatag', 10);
Listings
Listing Status Labels
Description
The "listing_status_labels" filter is used to filter the listing status labels (i.e. Hot, New, Featured).
Usage
When the "listing_status_labels" filter is called, it is passed two arguments. The first argument is an array of labels, allowing removing or adding new labels . The second argument is an associative array with context data.
Examples
Add Custom Field As Label
This example will output the selected/entered text for a text, single select or radio button custom field named jr_status as a label. If you want to have a different color for each select/radio option, the value of the selection is already included in the label CSS class output. So you would need to add new CSS classes to your template CSS or custom_styles.css file in JReviews overrides. For example, if the status option values are "open" and "closed", then you can add these CSS classes and adjust the background colors to your liking.
.jrStatusLabel.open { background-color: #468847; } .jrStatusLabel.closed { background-color: #b94a48; }
function status_field_label($labels, $params) { // Uncomment line below to dump filter arguments to the screen // dd($labels, $params); $listing = array_get($params,'listing'); // Only works for text, single select and radio button custom fields $statusText = array_get($listing,'Field.pairs.jr_status.text.0'); $statusValue = array_get($listing,'Field.pairs.jr_status.value.0'); if ( $statusText ) { $label = [ 'class'=>'jrStatusLabel '.$statusValue, 'text'=>$status ]; } // Add new label in the first position array_unshift($labels, $label); return $labels; } Clickfwd\Hook\Filter::add('listing_status_labels', 'status_field_label', 10);
Add Labels For Different Paid Plans
function paid_plan_labels($labels, $params) { // Uncomment line below to dump filter arguments to the screen // dd($labels, $params); $listing = array_get($params,'listing'); $planIds = array_get($listing,'Paid.plan_ids',[]); $basicPlanId = 1; $premiumPlanId = 2; if ( in_array($basicPlanId, $planIds) ) { $labels['basic'] = [ 'class'=>'jrStatusLabel jrPurple', // jrRed, jrOrange, jrBlue, jrGreen, jrBrown, jrPurple, jrBrown 'text'=>'Basic Plan' ]; } if ( in_array($premiumPlanId, $planIds) ) { $labels['premium'] = [ 'class'=>'jrStatusLabel jrGreen', // jrRed, jrOrange, jrBlue, jrGreen, jrBrown, jrPurple, jrBrown 'text'=>'Premium Plan' ]; } return $labels; } Clickfwd\Hook\Filter::add('listing_status_labels', 'paid_plan_labels', 10);
Add Label With Listing Type Title
function listing_type_label($labels, $params) { // Uncomment line below to dump filter arguments to the screen // dd($labels, $params); $listing = array_get($params,'listing'); $listingType = (S2App::make('listing_type'))->getById($listing['ListingType']['listing_type_id']); $label = [ 'class'=>'jrStatusLabel jrRed', // jrRed, jrOrange, jrBlue, jrGreen, jrBrown, jrPurple, jrBrown 'text'=>$listingType['ListingType']['title'] ]; // Add new label in the first position array_unshift($labels, $label); return $labels; } Clickfwd\Hook\Filter::add('listing_status_labels', 'listing_type_label', 10);
Listings List
Pre Get Listings Listpage Query
Description
The "pre_get_listings_listpage_query" filter is used to filter listings list database queries. Modifying the default database queries can lead to decreased performance because custom queries have not been optimized.
Usage
When the "pre_get_listings_listpage_query" filter is called, it is passed two arguments. The first argument is the listing model. The second argument is an associative array with context data.
Examples
Change Featured Listing Ordering With Most Recent Paid Orders First
This example can lead to decreased performance because it uses an ORDER BY statement with cross-table columns. This will become more noticeable in sites with large number of listings.
function featured_most_recent_transactions_ordering($listingModel, $params) { // Uncomment line below to dump filter arguments to the screen // dd($listingModel, $params); if ( isset($listingModel->order['featured']) ) { $listingModel->joins['PaidOrder'] = 'LEFT JOIN #__jreviews_paid_orders AS PaidOrder ON Listing.'.$listingModel::_LISTING_ID.' = PaidOrder.listing_id AND PaidOrder.order_amount > 0 AND order_active = 1'; $listingModel->order['featured'] = 'Field.featured DESC, PaidOrder.order_created DESC'; $listingModel->group[] = 'Field.contentid'; } return $listingModel; } Clickfwd\Hook\Filter::add('pre_get_listings_listpage_query', 'featured_most_recent_transactions_ordering', 10);
Pre Get Listings Listings Module Query
Description
The "pre_get_listings_listings_module_query" filter is used to filter listings list database queries. Modifying the default database queries can lead to decreased performance because custom queries have not been optimized.
Usage
When the "pre_get_listings_listings_module_query" filter is called, it is passed two arguments. The first argument is the listing model. The second argument is an associative array with context data.
Post Get Listings Listpage Query
Description
The "post_get_listings_listpage_query" filter is used to filter the listings array before it is made available to the theme file.
Usage
When the "post_get_listings_listpage_query" filter is called, it is passed two arguments. The first argument is the listings array. The second argument is an associative array with context data.
Post Get Listings Listings Module Query
Description
The "post_get_listings_listings_module_query" filter is used to filter the listings array before it is made available to the theme file.
Usage
When the "post_get_listings_listings_module_query" filter is called, it is passed two arguments. The first argument is the listings array. The second argument is an associative array with context data.
Listing Detail
Listing Detail Action Buttons
Description
The "listing_detail_action_buttons" filter is used to filter the action buttons in the detail page.
Usage
When the "listing_detail_action_buttons" filter is called, it is passed two arguments. The first argument is an associative array of button positions, allowing adding new buttons . The second argument is an associative array with context data.
You can insert buttons in positions 1 through 9.
Examples
Add EasySocial Message Button
function add_easysocial_message_button($positions, $params) { $listing = $params['listing']; $button = ' <button type="button" class="jrButton jrSmall" data-ck-chat="'.$listing['User']['user_id'].'"> <i class="fa fa-commenting" aria-hidden="true"></i> Contact This Member </button> '; $positions[7][] = $button; return $positions; }
Listing Detail Action Button Extras
Description
The "listing_detail_action_buttons extras" filter is used to filter the action buttons in the detail page. The extras button are processed before the rest of the buttons and are sometimes used to insert add-on buttons.
Usage
When the "listing_detail_action_buttons extras" filter is called, it is passed two arguments. The first argument is an associative array of button positions, allowing adding new buttons . The second argument is an associative array with context data.
Post Get Listing Detailpage Query
Description
The "post_get_listing_detailpage_query" filter is used to filter the listing array before it is made available to the theme file.
Usage
When the "post_get_listing_detailpage_query" filter is called, it is passed two arguments. The first argument is the listing array. The second argument is an associative array with context data.
Examples
Strip Links From Listing Text
This example will replace link tags in the listing summary and description fields, leaving only the anchor text.
function strip_links_detail($listing, $params) { // Uncomment line below to dump filter arguments to the screen // dd($listing, $params); $listing['Listing']['text'] = preg_replace('#<a.*?>(.*?)</a>#i', '\1', $listing['Listing']['text']); return $listing; } Clickfwd\Hook\Filter::add('post_get_listing_detailpage_query', 'strip_links_detail', 10);
Listing Permissions
Trusted On Listing Create
Description
The "trusted_on_create_listing" filter is used to filter the moderation setting when a new listing is created.
Usage
When the "trusted_on_create_listing" filter is called, it is passed two arguments. The first argument is the current value of the moderation setting. The value is true when the user is trusted to create listings without moderation and false otherwise. The second argument is an associative array with context data.
Examples
Trust All Listing Submissions From Users With Published Listings
function trust_published_authors($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); $auth = S2Object::make('auth'); if ( $auth->id > 0 ) { $Model = new S2Model(); $query = sprintf('SELECT count(*) FROM %s WHERE %s = %d AND state = 1', EverywhereComContentModel::_LISTING_TABLE, EverywhereComContentModel::_LISTING_USER_ID, $auth->id); $count = $Model->query($query,'loadResult'); if ( $count > 0 ) { return true; } } return $trust; } Clickfwd\Hook\Filter::add('trusted_on_create_listing', 'trust_published_authors', 10);
Listing Allows Claims
Description
The "listing_allows_claims" filter is used to filter the listing claims configuration setting.
Usage
When the "listing_allows_claims" filter is called, it is passed two arguments. The first argument is the current value for listing claims. The second argument is an associative array with context data. The "Claim" button only appears on the listing if the filter returns true and the listing is not alredy claimed.
Examples
Enable Claims Only For Listings with Premium Paid Plans (PaidListings)
function claims_for_premium_listings($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); $listing = $params['listing']; $premiumPlanIds = [1,2,3]; $allow = isset($listing['Paid']) && array_intersect($premiumPlanIds, $listing['Paid']['plan_ids']); return $allow; } Clickfwd\Hook\Filter::add('listing_allows_claims', 'claims_for_premium_listings', 10);
Listing Allows Inquiries
Description
The "listing_allows_inquiries" filter is used to filter the listing inquiry configuration setting.
Usage
When the "listing_allows_inquiries" filter is called, it is passed two arguments. The first argument is the current value for listing inquiries. The second argument is an associative array with context data. The "Send Inquiry" button only appears on the listing if the filter returns true.
Examples
Enable Inquiries Only For Listings with Premium Paid Plans (PaidListings)
function inquiries_for_premium_listings($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); $listing = $params['listing']; $premiumPlanIds = [1,2,3]; $allow = isset($listing['Paid']) && array_intersect($premiumPlanIds, $listing['Paid']['plan_ids']); return $allow; } Clickfwd\Hook\Filter::add('listing_allows_inquiries', 'inquiries_for_premium_listings', 10);
Listing Allows Favorites
Description
The "listing_allows_favorites" filter is used to filter the listing favorites configuration setting.
Usage
When the "listing_allows_favorites" filter is called, it is passed two arguments. The first argument is the current value for listing inquiries. The second argument is an associative array with context data. The "Favorite" button only appears on the listing if the filter returns true.
Examples
Enable Favorites Only For Listings with Premium Paid Plans (PaidListings)
function favorites_for_premium_listings($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); $listing = $params['listing']; $premiumPlanIds = [1,2,3]; $allow = isset($listing['Paid']) && array_intersect($premiumPlanIds, $listing['Paid']['plan_ids']); return $allow; } Clickfwd\Hook\Filter::add('listing_allows_favorites', 'favorites_for_premium_listings', 10);
Listing Allows User Reviews
Description
The "listing_allows_user_reviews" filter is used to filter filter the listing user reviews setting.
Usage
When the "listing_allows_user_reviews" filter is called, it is passed two arguments. The first argument is the current value for the allow user reviews setting. The second argument is an associative array with context data. User reviews are only enabled for a listing if the callback function returns true.
function allow_user_reviews($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); return $allow; } Clickfwd\Hook\Filter::add('listing_allows_user_reviews', 'allow_user_reviews', 10);
Listing Allows Editor Reviews
Description
The "listing_allows_editor_reviews" filter is used to filter filter the listing editor reviews setting.
Usage
When the "listing_allows_editor_reviews" filter is called, it is passed two arguments. The first argument is the current value for the allow editor reviews setting. The second argument is an associative array with context data. Editor reviews are only enabled for a listing if the callback function returns true.
function listing_allows_editor_reviews($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); return $allow; } Clickfwd\Hook\Filter::add('listing_allows_editor_reviews', 'allow_editor_reviews', 10);
Listing User Reviews Open
Description
The "listing_user_reviews_open" filter is used to filter the open/closed state for user reviews in a listing.
Usage
When the "listing_user_reviews_open" filter is called, it is passed two arguments. The first argument is the current value for the open/closed state. The second argument is an associative array with context data. When the filter returns true the reviews are open, otherwise listing no longer accepts reviews, but displays existing reviews and rating information.
Examples
Control user reviews open state using a listing custom field
This example lets you add the ability to close user reviews for a specific listing. It uses a listing custom field to let you set the open state for user reviews. You can set this field for admin access only or if you prefer you can also allow listing owners to have control of this feature when they edit the listings.
function user_reviews_open($open, $params) { // Uncomment line below to dump filter arguments to the screen // dd($state, $params); $listing = $params['listing']; // jr_userreviewstate is a radio field with yes/no option values. You could also use a checkbox custom field if you prefer // and modify the example accordingly. In this example, when a value is not found for the custom field the reviews will be open. $fieldName = 'jr_userreviewsstate'; if ( isset($listing['Field']['pairs'][$fieldName]) && $listing['Field']['pairs'][$fieldName]['value'][0] == 'no' ) { return false; } return $open; } Clickfwd\Hook\Filter::add('listing_user_reviews_open', 'user_reviews_open', 10);
Listing Editor Reviews Open
Description
The "listing_user_reviews_open" filter is used to filter the open/closed state for user reviews in a listing.
Usage
When the "listing_user_reviews_open" filter is called, it is passed two arguments. The first argument is the current value for the open/closed state. The second argument is an associative array with context data. When the filter returns true the reviews are open, otherwise listing no longer accepts reviews, but displays existing reviews and rating information.
function editor_reviews_open($open, $params) { // Uncomment line below to dump filter arguments to the screen // dd($open, $params); return $open; } Clickfwd\Hook\Filter::add('listing_editor_reviews_open', 'editor_reviews_open', 10);
Can Create Listing
Description
The "can_create_listing" filter is used to filter the user permission to create a new listing.
Usage
When the "can_create_listing" filter is called, it is passed two arguments. The first argument is the current value for the create permission. The second argument is an associative array with context data.
Examples
Limit listing submissions to one per user
This example limits the listing submissions to one per user and allows you to override the access denied message shown to the user.
function one_listing_limit_registered_user($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); $listingPermissions = (S2Object::make('perm'))->__('listing'); $auth = S2Object::make('auth'); if ( $auth->id > 0 ) { $Model = new S2Model(); $query = sprintf('SELECT count(*) FROM %s WHERE %s = %d AND state = 1', EverywhereComContentModel::_LISTING_TABLE, EverywhereComContentModel::_LISTING_USER_ID, $auth->id); $count = $Model->query($query,'loadResult'); if ( $count > 0 ) { $listingPermissions->setMessage('Sorry, you already created a listing and there\'s a limit of one listing per user'); return false; } } return $permission; } Clickfwd\Hook\Filter::add('can_create_listing', 'one_listing_limit_registered_user', 10);
Can Update Listing
Description
The "can_update_listing" filter is used to filter the user permission to update a listing.
Usage
When the "can_update_listing" filter is called, it is passed two arguments. The first argument is the current value for the update permission. The second argument is an associative array with context data.
function can_update_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_update_listing', 'can_update_listing', 10);
Can Add Listing Metadata
Description
The "can_add_listing_metadata" filter is used to filter the user permission to add meta description and keywords while creating or updating a listing.
Usage
When the "can_add_listing_metadata" filter is called, it is passed two arguments. The first argument is the current value for the metadata permission. The second argument is an associative array with context data.
function can_add_listing_metadata($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_add_listing_metadata', 'can_add_listing_metadata', 10);
Can User WYSIWYG Editor in Listing
Description
The "can_use_editor_in_listing" filter is used to filter the user permission to use the WYSIWYG editor for listing summary and description fields.
Usage
When the "can_use_editor_in_listing" filter is called, it is passed two arguments. The first argument is the current value for the WYSIWYG Editor permission. The second argument is an associative array with context data.
function can_use_editor_in_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_use_editor_in_listing', 'can_use_editor_in_listing', 10);
Can Publish Listing
Description
The "can_publish_listing" filter is used to filter the user permission to publish a listing.
Usage
When the "can_publish_listing" filter is called, it is passed two arguments. The first argument is the current value for the publish permission. The second argument is an associative array with context data.
function can_publish_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_publish_listing', 'can_publish_listing', 10);
Can Delete Listing
Description
The "can_delete_listing" filter is used to filter the user permission to delete a listing.
Usage
When the "can_delete_listing" filter is called, it is passed two arguments. The first argument is the current value for the delete permission. The second argument is an associative array with context data.
function can_delete_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_delete_listing', 'can_publish_listing', 10);
Can Claim Listing
Description
The "can_claim_listing" filter is used to filter the user permission to claim a listing.
Usage
When the "can_claim_listing" filter is called, it is passed two arguments. The first argument is the current value for the claim permission. The second argument is an associative array with context data.
function can_claim_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_claim_listing', 'can_claim_listing', 10);
Can Send Listing Inquiry
Description
The "can_send_listing_inquiry" filter is used to filter the user permission to send a listing inquiry.
Usage
When the "can_send_listing_inquiry" filter is called, it is passed two arguments. The first argument is the current value for the send inquiry permission. The second argument is an associative array with context data.
Examples
Prevent Guests from sending inquiries
function prevent_guest_inquiries($permission, $params = []) { $auth = S2Object::make('auth'); if ( $auth->id == 0 ) { return false; } return $permission; } Clickfwd\Hook\Filter::add('can_send_listing_inquiry', 'prevent_guest_inquiries', 10);
Can Favorite Listing
Description
The "can_favorite_listing" filter is used to filter the user permission use the favorites feature.
Usage
When the "can_favorite_listing" filter is called, it is passed two arguments. The first argument is the current value for the favorites permission. The second argument is an associative array with context data.
function can_favorite_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_favorite_listing', 'can_favorite_listing', 10);
Can Feature Listing
Description
The "can_feature_listing" filter is used to filter the user permission use feature a listing.
Usage
When the "can_feature_listing" filter is called, it is passed two arguments. The first argument is the current value for the feature permission. The second argument is an associative array with context data.
function can_feature_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_feature_listing', 'can_feature_listing', 10);
Can Create User Review For Listing
Description
The "can_create_user_review_for_listing" filter is used to filter the user permission to create a new user review. This is different from the "listing_allows_user_reviews" filter because while a listing may allow user reviews, you can stop specific users from submitting user reviews.
Usage
When the "can_create_user_review_for_listing" filter is called, it is passed two arguments. The first argument is the current value for the create user review permission. The second argument is an associative array with context data.
function can_create_user_review_for_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_create_user_review_for_listing', 'can_create_user_review_for_listing', 10);
Can Create Editor Review For Listing
Description
The "can_create_editor_review_for_listing" filter is used to filter the user permission to create a new editor review. This is different from the "listing_allows_editor_reviews" filter because while a listing may allow editor reviews, you can stop specific users from submitting editor reviews.
Usage
When the "can_create_editor_review_for_listing" filter is called, it is passed two arguments. The first argument is the current value for the create user review permission. The second argument is an associative array with context data.
function can_create_editor_review_for_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_create_editor_review_for_listing', 'can_create_editor_review_for_listing', 10);
Can Add Review on Listing Create
Description
The "can_add_review_on_listing_create" filter is used to filter the user permission to add a review while creating a new listing.
Usage
When the "can_add_review_on_listing_create" filter is called, it is passed two arguments. The first argument is the current value for the user permission to add a review in the listing form. The second argument is an associative array with context data.
function can_add_review_on_listing_create($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_add_review_on_listing_create', 'can_add_review_on_listing_create', 10);
Can Update Listing Media
Description
The "can_update_listing_media" filter is used to filter the user permission to update listing media. This refers to media edit page that is reached via the "Edit Media" link in the listing's manage dropdown (the gear icon).
Usage
When the "can_update_listing_media" filter is called, it is passed two arguments. The first argument is the current value for update permission. The second argument is an associative array with context data.
function can_update_listing_media($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_update_listing_media', 'can_update_listing_media', 10);
Can Upload Listing Media
Description
The "can_upload_listing_media" filter is used to filter the user permission to upload listing media.
Usage
When the "can_upload_listing_media" filter is called, it is passed two arguments. The first argument is the current value for the user permission to upload listing media. The second argument is an associative array with context data.
function can_upload_listing_media($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_listing_media', 'can_upload_listing_media', 10);
Can Upload Listing Media From URL
Description
The "can_upload_media_from_url_in_listing" filter is used to filter the user permission to upload listing media with the upload from URL feature.
Usage
When the "can_upload_media_from_url_in_listing" filter is called, it is passed two arguments. The first argument is the current value for the user permission to upload listing media using a URL. The second argument is an associative array with context data.
function can_upload_media_from_url_in_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_media_from_url_in_listing', 'can_upload_media_from_url_in_listing', 10);
Can Upload Listing Photo
Description
The "can_upload_listing_photo" filter is used to filter the user permission to upload listing photos.
Usage
When the "can_upload_listing_photo" filter is called, it is passed two arguments. The first argument is the current value for the user permission to upload listing photos. The second argument is an associative array with context data.
function can_upload_listing_photo($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_listing_photo', 'can_upload_listing_photo', 10);
Can Upload Listing Video
Description
The "can_upload_listing_video" filter is used to filter the user permission to upload listing videos.
Usage
When the "can_upload_listing_video" filter is called, it is passed two arguments. The first argument is the current value for the user permission to upload listing videos. The second argument is an associative array with context data.
function can_upload_listing_video($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_listing_video', 'can_upload_listing_video', 10);
Can Upload Listing Audio
Description
The "can_upload_listing_audio" filter is used to filter the user permission to upload listing audio.
Usage
When the "can_upload_listing_audio" filter is called, it is passed two arguments. The first argument is the current value for the user permission to upload listing audio. The second argument is an associative array with context data.
function can_upload_listing_audio($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_listing_audio', 'can_upload_listing_audio', 10);
Can Upload Listing Attachment
Description
The "can_upload_listing_attachment" filter is used to filter the user permission to upload listing attachments.
Usage
When the "can_upload_listing_attachment" filter is called, it is passed two arguments. The first argument is the current value for the user permission to upload listing attachments. The second argument is an associative array with context data.
function can_upload_listing_attachment($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_listing_attachment', 'can_upload_listing_attachment', 10);
Media Permissions
Trusted On Create Photo
Description
The "trusted_on_create_photo" filter is used to filter the moderation setting when a new photo is uploaded.
Usage
When the "trusted_on_create_photo" filter is called, it is passed two arguments. The first argument is the current value of the moderation setting. The value is true when the user is trusted to upload photos without moderation and false otherwise. The second argument is an associative array with context data.
Examples
Trust All Photo Uploads From Users With Published Media
If you want to use this approach for all types of media, then you can use the same callback function for all the filters.
function trust_published_media_users($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); $auth = S2Object::make('auth'); if ( $auth->id > 0 ) { $Model = new S2Model(); $query = sprintf('SELECT count(*) FROM #__jreviews_media WHERE user_id = %d AND published = 1 AND approved = 1', $auth->id); $count = $Model->query($query,'loadResult'); if ( $count > 0 ) { return true; } } return $trust; } Clickfwd\Hook\Filter::add('trusted_on_create_photo', 'trust_published_media_users', 10);
Trusted On Create Video
Description
The "trusted_on_create_photo" filter is used to filter the moderation setting when a new video is uploaded.
Usage
When the "trusted_on_create_photo" filter is called, it is passed two arguments. The first argument is the current value of the moderation setting. The value is true when the user is trusted to upload videos without moderation and false otherwise. The second argument is an associative array with context data.
Examples
Trust All Video Uploads From Users With Published Media
If you want to use this approach for all types of media, then you can use the same callback function for all the filters.
function trust_published_media_users($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); $auth = S2Object::make('auth'); if ( $auth->id > 0 ) { $Model = new S2Model(); $query = sprintf('SELECT count(*) FROM #__jreviews_media WHERE user_id = %d AND published = 1 AND approved = 1', $auth->id); $count = $Model->query($query,'loadResult'); if ( $count > 0 ) { return true; } } return $trust; } Clickfwd\Hook\Filter::add('trusted_on_create_video', 'trust_published_media_users', 10);
Trusted On Create Audio
Description
The "trusted_on_create_audio" filter is used to filter the moderation setting when a new audio is uploaded.
Usage
When the "trusted_on_create_audio" filter is called, it is passed two arguments. The first argument is the current value of the moderation setting. The value is true when the user is trusted to upload audio without moderation and false otherwise. The second argument is an associative array with context data.
Examples
Trust All Audio Uploads From Users With Published Media
If you want to use this approach for all types of media, then you can use the same callback function for all the filters.
function trust_published_media_users($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); $auth = S2Object::make('auth'); if ( $auth->id > 0 ) { $Model = new S2Model(); $query = sprintf('SELECT count(*) FROM #__jreviews_media WHERE user_id = %d AND published = 1 AND approved = 1', $auth->id); $count = $Model->query($query,'loadResult'); if ( $count > 0 ) { return true; } } return $trust; } Clickfwd\Hook\Filter::add('trusted_on_create_audio', 'trust_published_media_users', 10);
Trusted On Create Attachment
Description
The "trusted_on_create_attachment" filter is used to filter the moderation setting when a new attachment is uploaded.
Usage
When the "trusted_on_create_attachment" filter is called, it is passed two arguments. The first argument is the current value of the moderation setting. The value is true when the user is trusted to upload attachments without moderation and false otherwise. The second argument is an associative array with context data.
Examples
Trust All Attachment Uploads From Users With Published Media
If you want to use this approach for all types of media, then you can use the same callback function for all the filters.
function trust_published_media_users($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); $auth = S2Object::make('auth'); if ( $auth->id > 0 ) { $Model = new S2Model(); $query = sprintf('SELECT count(*) FROM #__jreviews_media WHERE user_id = %d AND published = 1 AND approved = 1', $auth->id); $count = $Model->query($query,'loadResult'); if ( $count > 0 ) { return true; } } return $trust; } Clickfwd\Hook\Filter::add('trusted_on_create_attachment', 'trust_published_media_users', 10);
Media Allows Voting
Description
The "media_allows_voting" filter is used to filter the media likes feature.
Usage
When the "media_allows_voting" filter is called, it is passed two arguments. The first argument is the current value for media likes feature. The second argument is an associative array with context data. The likes feature is enabled only if the filter returns true.
Examples
Disable media likes
function disable_media_likes($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); return false; } Clickfwd\Hook\Filter::add('media_allows_voting', 'disable_media_likes', 10);
Media Allows Report
Description
The "media_allows_report" filter is used to filter the media abuse reporting feature.
Usage
When the "media_allows_report" filter is called, it is passed two arguments. The first argument is the current value for media abuse reporting feature. The second argument is an associative array with context data. The reporting feature is enabled only if the filter returns true.
Examples
Disable media reporting for guest users
function disable_media_reporting_for_guests($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); $auth = S2Object::make('auth'); if ( !$auth->connected ) { return false; } return $allow; } Clickfwd\Hook\Filter::add('media_allows_report', 'disable_media_reporting_for_guests', 10);
Can Update Media In Listing
Description
The "can_update_media_in_listing" filter is used to filter the user permission to update uploaded media details like title and description by using the edit icon for media which brings up the update dialog.
Usage
When the "can_update_media_in_listing" filter is called, it is passed two arguments. The first argument is the current value for update permission. The second argument is an associative array with context data.
function can_update_media_in_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_update_media_in_listing', 'can_update_media_in_listing', 10);
Can Delete Media In Listing
Description
The "can_delete_media_in_listing" filter is used to filter the user permission to delete uploaded media.
Usage
When the "can_delete_media_in_listing" filter is called, it is passed two arguments. The first argument is the current value for the user permission to delete media. The second argument is an associative array with context data.
function can_delete_media_in_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_delete_media_in_listing', 'can_delete_media_in_listing', 10);
Can Publish Media In Listing
Description
The "can_publish_media_in_listing" filter is used to filter the user permission to publish uploaded media.
Usage
When the "can_publish_media_in_listing" filter is called, it is passed two arguments. The first argument is the current value for the user permission to publish media. The second argument is an associative array with context data.
function can_publish_media_in_listing($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_publish_media_in_listing', 'can_publish_media_in_listing', 10);
Can Set Main Media
Description
The "can_set_main_media" filter is used to filter the user permission to change the main media.
Usage
When the "can_set_main_media" filter is called, it is passed two arguments. The first argument is the current value for the user permission to change the main media. The second argument is an associative array with context data.
function can_set_main_media($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_set_main_media', 'can_set_main_media', 10);
Can Vote on Media
Description
The "can_vote_on_media" filter is used to filter the user permission to like media. This is different from the "media_allows_voting" filter because even if the media like feature is visible, with this filter you can stop specific users from liking media.
Usage
When the "can_vote_on_media" filter is called, it is passed two arguments. The first argument is the current value for the user permission to like media. The second argument is an associative array with context data.
function can_vote_on_media($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_vote_on_media', 'can_vote_on_media', 10);
Can Report Media
Description
The "can_report_media" filter is used to filter the user permission to report media. This is different from the "media_allows_report" filter because even if the media report feature is visible, with this filter you can stop specific users from reporting media.
Usage
When the "can_report_media" filter is called, it is passed two arguments. The first argument is the current value for the user permission to report media. The second argument is an associative array with context data.
function can_report_media($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_report_media', 'can_report_media', 10);
Can Download Attachment
Description
The "can_download_attachment" filter is used to filter the user permission to download attachments.
Usage
When the "can_download_attachment" filter is called, it is passed two arguments. The first argument is the current value for the user permission to download attachments. The second argument is an associative array with context data. If your site has a membership functionality, you could use this filter to only allow certain types of members to download media by including some code from the membership solution to check the logged in user's membership plan.
function can_download_attachment($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_download_attachment', 'can_download_attachment', 10);
Review Permissions
Trusted on Create User Review
Description
The "trusted_on_create_user_review" filter is used to filter the moderation setting when a new user review is created.
Usage
When the "trusted_on_create_user_review" filter is called, it is passed two arguments. The first argument is the current value of the moderation setting. The value is true when the user is trusted to create user reviews without moderation and false otherwise. The second argument is an associative array with context data.
Examples
Trust All Review Submissions From Users With Published Reviews
function trust_published_reviewers($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); $auth = S2Object::make('auth'); if ( $auth->id > 0 ) { $Model = new S2Model(); $query = sprintf('SELECT count(*) FROM #__jreviews_comments WHERE userid = %d AND published = 1', $auth->id); $count = $Model->query($query,'loadResult'); if ( $count > 0 ) { return true; } } return $trust; } Clickfwd\Hook\Filter::add('trusted_on_create_user_review', 'trust_published_reviewers', 10);
Trusted on Update User Review
Description
The "trusted_on_update_user_review" filter is used to filter the moderation setting when a user review is updated.
Usage
When the "trusted_on_update_user_review" filter is called, it is passed two arguments. The first argument is the current value of the update moderation setting. The value is true when the user is trusted to update reviews without moderation and false otherwise. The second argument is an associative array with context data.
function trusted_on_update_user_review($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); return $trust; } Clickfwd\Hook\Filter::add('trusted_on_update_user_review', 'trusted_on_update_user_review', 10);
Trusted on Create Editor Review
Description
The "trusted_on_create_editor_review" filter is used to filter the moderation setting when a new editor review is created.
Usage
When the "trusted_on_create_editor_review" filter is called, it is passed two arguments. The first argument is the current value of the moderation setting. The value is true when the user is trusted to create editor reviews without moderation and false otherwise. The second argument is an associative array with context data.
Examples
Trust All Review Submissions From Users With Published Reviews
function trust_published_reviewers($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); $auth = S2Object::make('auth'); if ( $auth->id > 0 ) { $Model = new S2Model(); $query = sprintf('SELECT count(*) FROM #__jreviews_comments WHERE userid = %d AND published = 1', $auth->id); $count = $Model->query($query,'loadResult'); if ( $count > 0 ) { return true; } } return $trust; } Clickfwd\Hook\Filter::add('trusted_on_create_editor_review', 'trust_published_reviewers', 10);
Trusted on Update Editor Review
Description
The "trusted_on_update_editor_review" filter is used to filter the moderation setting when a editor review is updated.
Usage
When the "trusted_on_update_editor_review" filter is called, it is passed two arguments. The first argument is the current value of the update moderation setting. The value is true when the user is trusted to update reviews without moderation and false otherwise. The second argument is an associative array with context data.
function trusted_on_update_editor_review($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); return $trust; } Clickfwd\Hook\Filter::add('trusted_on_update_editor_review', 'trusted_on_update_editor_review', 10);
Trusted on Create Review Owner Reply
Description
The "trusted_on_create_review_owner_reply" filter is used to filter the moderation setting when a listing owner replies to a review.
Usage
When the "trusted_on_create_review_owner_reply" filter is called, it is passed two arguments. The first argument is the current value of the owner reply moderation setting. The value is true when the user is trusted to reply to reviews without moderation and false otherwise. The second argument is an associative array with context data.
function trusted_on_create_review_owner_reply($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); return $trust; } Clickfwd\Hook\Filter::add('trusted_on_create_review_owner_reply', 'trusted_on_create_review_owner_reply', 10);
Review Allows Report
Description
The "review_allows_report" filter is used to filter the review abuse reporting feature.
Usage
When the "review_allows_report" filter is called, it is passed two arguments. The first argument is the current value for review abuse reporting feature. The second argument is an associative array with context data. The reporting feature is enabled only if the filter returns true.
Examples
Disable review reporting for guest users
function disable_review_reporting_for_guests($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); $auth = S2Object::make('auth'); if ( !$auth->connected ) { return false; } return $allow; } Clickfwd\Hook\Filter::add('review_allows_report', 'disable_review_reporting_for_guests', 10);
Review Allows Voting
Description
The "review_allows_voting" filter is used to filter the review helpfulness voting feature.
Usage
When the "review_allows_voting" filter is called, it is passed two arguments. The first argument is the current value for review helpfulness voting. The second argument is an associative array with context data. The helpfulness voting is enabled only if the filter returns true.
Examples
Disable review helpfulness voting
function disable_review_voting($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); return false; } Clickfwd\Hook\Filter::add('review_allows_voting', 'disable_review_voting', 10);
Review Allows Replies
Description
The "review_allows_replies" filter is used to filter the owner reply feature.
Usage
When the "review_allows_replies" filter is called, it is passed two arguments. The first argument is the current value for owner replies. The second argument is an associative array with context data. Owner replies are enabled only if the filter returns true.
function review_allows_replies($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); return false; } Clickfwd\Hook\Filter::add('review_allows_replies', 'review_allows_replies', 10);
Review Allows Discussions
Description
The "review_allows_discussions" filter is used to filter the revie discussion feature.
Usage
When the "review_allows_discussions" filter is called, it is passed two arguments. The first argument is the current value for owner replies. The second argument is an associative array with context data. Owner replies are enabled only if the filter returns true.
function review_allows_discussions($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); return false; } Clickfwd\Hook\Filter::add('review_allows_discussions', 'review_allows_replies', 10);
Can Update Review
Description
The "can_update_review" filter is used to filter the user permission to update a review.
Usage
When the "can_update_review" filter is called, it is passed two arguments. The first argument is the current value for the review update permission. The second argument is an associative array with context data.
function can_update_review($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_update_review', 'can_update_review', 10);
Can Reply To Review
Description
The "can_reply_to_review" filter is used to filter the user permission to reply to a review.
Usage
When the "can_reply_to_review" filter is called, it is passed two arguments. The first argument is the current value for the create review reply permission. The second argument is an associative array with context data.
function can_reply_to_review($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_reply_to_review', 'can_reply_to_review', 10);
Can Delete Review Reply
Description
The "can_delete_review_reply" filter is used to filter the user permission to delete a review reply.
Usage
When the "can_delete_review_reply" filter is called, it is passed two arguments. The first argument is the current value for the delete review reply permission. The second argument is an associative array with context data.
function can_delete_review_reply($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_delete_review_reply', 'can_delete_review_reply', 10);
Can Report Review
Description
The "can_report_review" filter is used to filter the user permission to report a review.
Usage
When the "can_report_review" filter is called, it is passed two arguments. The first argument is the current value for the report review permission. The second argument is an associative array with context data.
function can_report_review($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_report_review', 'can_report_review', 10);
Can Vote On Review
Description
The "can_vote_on_review" filter is used to filter the user permission to vote on a review's helpfulness.
Usage
When the "can_vote_on_review" filter is called, it is passed two arguments. The first argument is the current value for the review vote permission. The second argument is an associative array with context data.
function can_vote_on_review($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_vote_on_review', 'can_vote_on_review', 10);
Can Create Review Comment
Description
The "can_create_review_post" filter is used to filter the user permission to write a comment about a review.
Usage
When the "can_create_review_post" filter is called, it is passed two arguments. The first argument is the current value for the write comment permission. The second argument is an associative array with context data.
function can_create_review_post($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_create_review_post', 'can_create_review_post', 10);
Can Upload Review Media
Description
The "can_upload_review_media" filter is used to filter the user permission to upload media to a review.
Usage
When the "can_upload_review_media" filter is called, it is passed two arguments. The first argument is the current value for the upload review media permission. The second argument is an associative array with context data.
function can_upload_review_media($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_review_media', 'can_upload_review_media', 10);
Can Upload Review Media From URL
Description
The "can_upload_media_from_url_in_review" filter is used to filter the user permission to upload review media with the upload from URL feature.
Usage
When the "can_upload_media_from_url_in_review" filter is called, it is passed two arguments. The first argument is the current value for the user permission to upload review media using a URL. The second argument is an associative array with context data.
function can_upload_media_from_url_in_review($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_media_from_url_in_review', 'can_upload_media_from_url_in_review', 10);
Can Upload Review Photo
Description
The "can_upload_review_photo" filter is used to filter the user permission to upload photos to a review.
Usage
When the "can_upload_review_photo" filter is called, it is passed two arguments. The first argument is the current value for the upload review photo permission. The second argument is an associative array with context data.
function can_upload_review_photo($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_review_photo', 'can_upload_review_photo', 10);
Can Upload Review Video
Description
The "can_upload_review_video" filter is used to filter the user permission to upload videos to a review.
Usage
When the "can_upload_review_video" filter is called, it is passed two arguments. The first argument is the current value for the upload review video permission. The second argument is an associative array with context data.
function can_upload_review_video($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_review_video', 'can_upload_review_video', 10);
Can Upload Review Audio
Description
The "can_upload_review_audio" filter is used to filter the user permission to upload audio to a review.
Usage
When the "can_upload_review_audio" filter is called, it is passed two arguments. The first argument is the current value for the upload review audio permission. The second argument is an associative array with context data.
function can_upload_review_audio($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_review_audio', 'can_upload_review_audio', 10);
Can Upload Review Attachment
Description
The "can_upload_review_attachment" filter is used to filter the user permission to upload attachments to a review.
Usage
When the "can_upload_review_attachment" filter is called, it is passed two arguments. The first argument is the current value for the upload review attachment permission. The second argument is an associative array with context data.
function can_upload_review_attachment($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_upload_review_attachment', 'can_upload_review_attachment', 10);
Review Discussion Permissions
Trusted on Create Review Discussion
Description
The "trusted_on_create_review_discussion" filter is used to filter the moderation setting when a new review discussion comment is created.
Usage
When the "trusted_on_create_review_discussion" filter is called, it is passed two arguments. The first argument is the current value of the moderation setting. The value is true when the user is trusted to create user review discussions without moderation and false otherwise. The second argument is an associative array with context data.
Examples
Trust All Review Submissions From Users With Published Reviews
In this example any user with a published review will also be able to comment on other reviews without the need for moderation.
function trust_published_reviewers($trust, $params) { // Uncomment line below to dump filter arguments to the screen // dd($trust, $params); $auth = S2Object::make('auth'); if ( $auth->id > 0 ) { $Model = new S2Model(); $query = sprintf('SELECT count(*) FROM #__jreviews_comments WHERE userid = %d AND published = 1', $auth->id); $count = $Model->query($query,'loadResult'); if ( $count > 0 ) { return true; } } return $trust; } Clickfwd\Hook\Filter::add('trusted_on_create_review_discussion', 'trust_published_reviewers', 10);
Review Discussion Allows Report
Description
The "review_discussion_allows_report" filter is used to filter the review discussion abuse reporting feature.
Usage
When the "review_discussion_allows_report" filter is called, it is passed two arguments. The first argument is the current value for review discussion abuse reporting feature. The second argument is an associative array with context data. The reporting feature is enabled only if the filter returns true.
Examples
Disable review discussion reporting for guest users
function disable_review_discussion_reporting_for_guests($allow, $params) { // Uncomment line below to dump filter arguments to the screen // dd($allow, $params); $auth = S2Object::make('auth'); if ( !$auth->connected ) { return false; } return $allow; } Clickfwd\Hook\Filter::add('review_discussion_allows_report', 'disable_review_discussion_reporting_for_guests', 10);
Can Report Review Discussion
Description
The "can_report_review_discussion" filter is used to filter the user permission to report review discussions. This is different from the "review_discussion_allows_report" filter because even if the review discussion report feature is visible, with this filter you can stop specific users from reporting review discussions.
Usage
When the "can_report_review_discussion" filter is called, it is passed two arguments. The first argument is the current value for the user permission to report review discussions. The second argument is an associative array with context data.
function can_report_review_discussion($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_report_review_discussion', 'can_report_review_discussion', 10);
Can Update Review Discussion
Description
The "can_update_review_discussion" filter is used to filter the user permission to update a review discussion comment.
Usage
When the "can_update_review_discussion" filter is called, it is passed two arguments. The first argument is the current value for the review discussion update permission. The second argument is an associative array with context data.
function can_update_review_discussion($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_update_review_discussion', 'can_update_review_discussion', 10);
Can Delete Review Discussion
Description
The "can_delete_review_discussion" filter is used to filter the user permission to delete a review discussion comment.
Usage
When the "can_delete_review_discussion" filter is called, it is passed two arguments. The first argument is the current value for the delete permission. The second argument is an associative array with context data.
function can_delete_review_discussion($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_delete_review_discussion', 'can_delete_review_discussion', 10);
Field Permissions
Can View Field in Listing Detail Page
Description
The "can_view_field_in_detail_page" filter is used to filter the user permission to view custom fields in the listing detail page.
Usage
When the "can_view_field_in_detail_page" filter is called, it is passed two arguments. The first argument is the current value for the view field permission. The second argument is an associative array with context data.
function can_view_field_in_detail_page($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_view_field_in_detail_page', 'can_view_field_in_detail_page', 10);
Can View Field in Listing List Page
Description
The "can_view_field_in_list_page" filter is used to filter the user permission to view custom fields in the listing list pages.
Usage
When the "can_view_field_in_list_page" filter is called, it is passed two arguments. The first argument is the current value for the view field permission. The second argument is an associative array with context data.
function can_view_field_in_list_page($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_view_field_in_list_page', 'can_view_field_in_list_page', 10);
Can View Field in Listing Comparison Page
Description
The "can_view_field_in_comparison_page" filter is used to filter the user permission to view custom fields in the listing comparison page.
Usage
When the "can_view_field_in_comparison_page" filter is called, it is passed two arguments. The first argument is the current value for the view field permission. The second argument is an associative array with context data.
function can_view_field_in_comparison_page($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_view_field_in_comparison_page', 'can_view_field_in_comparison_page', 10);
Can Read Field
Description
The "can_read_field" filter is used to filter the user permission to view the output of custom fields. While the "can_view_field__..." filter is specific to certain pages, this filter works on all pages.
Usage
When the "can_read_field" filter is called, it is passed two arguments. The first argument is the current value for the read field permission. The second argument is an associative array with context data.
Examples
Hide a specific custom field
function hide_city_field($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); $field = $params['field']; if ( $field['name'] == 'jr_city' ) { return false; } return $permission; } Clickfwd\Hook\Filter::add('can_read_field', 'hide_city_field', 10);
Can Write Field
Description
The "can_write_field" filter is used to filter the user permission to access field inputs in forms.
Usage
When the "can_write_field" filter is called, it is passed two arguments. The first argument is the current value for the write field permission. The second argument is an associative array with context data.
function can_write_field($permission, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('can_write_field', 'can_write_field', 10);
UserProfiles Add-on
UserProfiles Account Sections
Description
The "userprofiles_account_sections" filter lets you modify the UserProfiles account page by allowing you to add or remove sections from it.
Usage
When the "userprofiles_account_sections" filter is called, it is passed two arguments. The first argument is an array with the account sections. The second argument is an associative array with context data.
function userprofiles_account_sections($sections, $params) { // Uncomment line below to dump filter arguments to the screen // dd($permission, $params); return $permission; } Clickfwd\Hook\Filter::add('userprofiles_account_sections', 'userprofiles_account_sections', 10);
Examples
Show 3rd party solution membership information
If you have a membership solution from another provider on your site, you could show information about the user's membership status or link to the membership management page.
function userprofiles_account_sections($sections, $params = []) { $userId = array_get($params,'user.User.id'); $sections['membership'] = [ 'title'=>'Your Membership Status', 'summary'=>'Below you can find the details of your current membership plan', 'body'=>'<p>Here you can add a link to the membership page or if you have the code to lookup membership info you can insert the rendered template with that information here</p>' ]; return $sections; } Clickfwd\Hook\Filter::add('userprofiles_account_sections', 'userprofiles_account_sections', 10);