JReviews:Developers Filters

From JReviews Documentation
Revision as of 21:20, 15 February 2018 by Jreviews (Talk | contribs)

Jump to: navigation, search

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


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);

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);

Listing Detail

Listing Detail Action Buttons

Description

The "listing_detail_action_buttons" filter is used to filter the page next metatag.

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 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 create 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 the user permission to update listing media. 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" 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 "Report" 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 the user permission to update media. 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

Usage

  84:    return $this->filteredResponse($trust,'trusted_on_create_review_owner_reply');

Review Allows Report

Description

Usage

 104:    return $this->filteredResponse($permission,'review_allows_report',$review);

Review Allows Voting

Description

Usage

 124:    return $this->filteredResponse($permission,'review_allows_voting',$review);

Review Allows Replies

Description

Usage

 140:    return $this->filteredResponse($permission,'review_allows_replies',$review);

Review Allows Discussions

Description

Usage

 156:    return $this->filteredResponse($permission,'review_allows_discussions',$review);

Can Update Review

Description

Usage

 180:    return $this->filteredResponse($permission,'can_update_review',$review);

Can Reply To Review

Description

Usage

 204:    return $this->filteredResponse($permission,'can_reply_to_review',[$listing,$review]);

Can Delete Review Reply

Description

Usage

 220:    return $this->filteredResponse($permission,'can_delete_review_reply',$listing);

Can Report Review

Description

Usage

 236:    return $this->filteredResponse($permission,'can_report_review',$review);

Can Vote On Review

Description

Usage

 261:    return $this->filteredResponse($permission,'can_vote_on_review',$review);

Can Create Review Comment

Description

Usage

 279:    return $this->filteredResponse($permission,'can_create_review_post',$review);

Can Upload Review Media

Description

Usage

 319:    return $this->filteredResponse($permission,'can_upload_review_media',$review);

Can Upload Review Media From URL

Description

Usage

 337:    return $this->filteredResponse($permission,'can_upload_media_from_url_in_review',$review);

Can Upload Review Photo

Description

Usage

 353:    return $this->filteredResponse($permission,'can_upload_review_photo',$review);

Can Upload Review Video

Description

Usage

 369:    return $this->filteredResponse($permission,'can_upload_review_video',$review);

Can Upload Review Audio

Description

Usage

 385:    return $this->filteredResponse($permission,'can_upload_review_audio',$review);

Can Upload Review Attachment

Description

Usage

 401:    return $this->filteredResponse($permission,'can_upload_review_attachment',$review);

Review Discussion Permissions

Trusted on Create Review Discussion

Description

Usage

  26:    return $this->filteredResponse($trust,'trusted_on_create_review_discussion');

Review Discussion Allows Report

Description

Usage

  48:    return $this->filteredResponse($permission,'review_discussion_allows_report',$post);

Can Report Review Discussion

Description

Usage

  64:    return $this->filteredResponse($permission,'can_report_review_discussion',$post);

Can Update Review Discussion

Description

Usage

  86:    return $this->filteredResponse($permission,'can_update_review_discussion',[$post,$review]);

Can Delete Review Discussion

Description

Usage

 108:    return $this->filteredResponse($permission,'can_delete_review_discussion',[$post,$review]);

Field Permissions

Can View Field in Listing Detail Page

Description

Usage

  59:    return $this->filteredResponse($permission,'can_view_field_in_detail_page',$field);

Can View Field in Listing Detail Page

Description

Usage

  59:    return $this->filteredResponse($permission,'can_view_field_in_list_page',$field);

Can View Field in Listing Detail Page

Description

Usage

  59:    return $this->filteredResponse($permission,'can_view_field_in_comparison_page',$field);

Can Read Field

Description

Usage

  87:    return $this->filteredResponse($permission,'can_read_field',[$fname]);

Can Write Field

Description

Usage

 115:    return $this->filteredResponse($permission,'can_write_field',[$fname]);