Skip to content

Instantly share code, notes, and snippets.

View jreviews's full-sized avatar

JReviews jreviews

View GitHub Profile
@jreviews
jreviews / listings-shortcode-word-match.md
Created October 28, 2021 20:45
Using match=words attribute in listings shortcode

All searches in JReviews use LIKE to retrieve results. To use an exact word match, it would be necessary to use REGEXP because there aren't any fulltext indexes.

The following filter allows adding the match=word attribute to the listings shortcode to perform a word match. Example usage:

[jreviews type="listings" custom_params="keywords=you" match="word" limit="3"]

The above will match "you", but not "yourself", "yours", etc.

@jreviews
jreviews / custom-parameter-active-events.md
Last active October 26, 2021 14:19
Using a custom parameter to filter results for active events

The filter hook below allows using a custom defined parameter events=active to automatically filter results shown in shortcodes and listings module to only show events that are currently active/open.

Add the code below to filter_functions.php in overrides, and then in your shortcode or listings module add events=open in the custom parameters attribute or setting respectively.

Clickfwd\Hook\Filter::add('pre_get_listings_listings_module_query', function($listingsRepository, $params) 
{
	$customParams = $params['params']['module']['custom_params'] ?? '';
	
	if (empty($customParams)) {
@jreviews
jreviews / peepso-about-author.md
Last active October 22, 2021 21:38
PeepSo About Author Snippet in JReviews

The PeepSo About Author output is not present in the JReviews listing detail pages by default. If you want to add it back you can use the following code snippet in the listing detail page or even in the php output format of a banner custom field.

echo PeepSoTemplate::exec_template('blogposts','author_box', 
	['author' => PeepSoUser::get_instance($listing['User']['user_id'])],
	true
);

You can also add the code after the listing description without template customizations using a JReviews action hook:

@jreviews
jreviews / filter_functions.md
Created October 20, 2021 12:19
Restrict page access to admins and listing owners

The code below should be placed in the filter_functions.php file in overrides per the JReviews Hooks documentation.

This is meant to be a starting point, not a full-proof solution as JReviews itself doesn't have functionality to limit visibility of user generated content.

// Listing list pages
// https://www.jreviews.com/docs/hooks/pre_get_listings_listpage_query
// https://www.jreviews.com/docs/hooks/pre_get_listings_listings_module_query

function limit_listing_list_visibility_to_owners_and_admins($ListingsRepository, $params)
@jreviews
jreviews / filter_functions.php
Created July 19, 2021 12:28
Add complete media info to widget & module queries
<?php
Clickfwd\Hook\Filter::add('post_get_listings_listings_module_query', function($listings, $params) {
$config = S2Object::make('config');
$Media = new MediaModel;
$listings = $Media->addMedia(
$listings,
'Listing',
'listing_id',
@jreviews
jreviews / filter_functions.php
Created July 10, 2021 11:02
Replace Featured label text with custom text
<?php
defined('_JEXEC') or die;
Clickfwd\Hook\Filter::add('listing_status_labels', 'jreviews_change_featured_label_to_urgent');
function jreviews_change_featured_label_to_urgent($labels, $params)
{
if (! isset($labels['featured'])) {
return $labels;
@jreviews
jreviews / filter_functions.php
Last active December 11, 2021 10:49
Add listing labels with custom CSS classes for multiple custom fields
<?php
defined('_JEXEC') or die;
Clickfwd\Hook\Filter::add('listing_status_labels', 'jreviews_custom_labels');
function jreviews_custom_labels($labels, $params)
{
$listing = $params['listing'];
@jreviews
jreviews / hello_elementor.php
Created July 8, 2021 17:14
Hello Elementor Theme Support for JReviews
<?php
namespace JReviews\ThemeSupport;
defined( 'ABSPATH' ) || exit;
class HelloElementor
{
public static function init()
{
add_action( 'jreviews_template:before_content', [ __CLASS__, 'output_content_wrapper_open' ] );
@jreviews
jreviews / filter_functions.php
Last active June 10, 2021 12:52
Apply WordPress shortcodes to JReviews listing detail page text (summary and description) output
<?php
Clickfwd\Hook\Filter::add('post_get_listing_detailpage_query', function($listing, $params)
{
$listing['Listing']['text'] = do_shortcode($listing['Listing']['text']);
return $listing;
});
@jreviews
jreviews / filter_functions.md
Last active June 13, 2021 00:42
Custom filters for open graph images and meta description in listing detail pages

Customize the open graph image in listing detail pages for individual categories

Clickfwd\Hook\Filter::add('open_graph_tags_before_parse', function($tags, $listing) 
{
	/**
	 * If you specify a category in this array, it will take precedence
	 */
	$imageToCategoriesArray = [
 "images/someimage_opengraph_big.jpg" =&gt; [1, 2, 3, 90],