Skip to content

Instantly share code, notes, and snippets.

Avatar

Alejandro Schmeichler jreviews

View GitHub Profile
@jreviews
jreviews / peepso-search-member-profiles.md
Last active Sep 14, 2022
PeepSo: Allow searching member profiles with multi-select fields
View peepso-search-member-profiles.md

Within PeepSo fields it's only possible to enable single select lists as searchable. The following code uses PeepSo filters to allow you to include multi-select fields in the members search area by converting them to single select and including the selected value in the database query.

Create a peepso-search-member-profiles.php file in /wp-content/mu-plugins with the following code:

<?php

/**
 * Find the field IDs under PeepSo Manage Fields
 * Add the field IDs of multiple select fields you want to show for member search
@jreviews
jreviews / htmx-loading-states-extension.md
Last active Jun 29, 2022
htmx loading states extension
View htmx-loading-states-extension.md

htmx loading states extension

The loading-states extension allows you to easily manage loading states while a request is in flight, including disabling elements, and adding and removing CSS classes.

Using the extension

Add the hx-ext="loading-states" attribute to the body tag or to any parent element containing your htmx attributes.

Add the following class to your stylesheet to make sure elements are hidden by default:

@jreviews
jreviews / listings-shortcode-word-match.md
Created Oct 28, 2021
Using match=words attribute in listings shortcode
View listings-shortcode-word-match.md

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 Oct 26, 2021
Using a custom parameter to filter results for active events
View custom-parameter-active-events.md

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 Oct 22, 2021
PeepSo About Author Snippet in JReviews
View peepso-about-author.md

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 Oct 20, 2021
Restrict page access to admins and listing owners
View filter_functions.md

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 Jul 19, 2021
Add complete media info to widget & module queries
View filter_functions.php
<?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 Jul 10, 2021
Replace Featured label text with custom text
View filter_functions.php
<?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 Dec 11, 2021
Add listing labels with custom CSS classes for multiple custom fields
View filter_functions.php
<?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 Jul 8, 2021
Hello Elementor Theme Support for JReviews
View hello_elementor.php
<?php
namespace JReviews\ThemeSupport;
defined( 'ABSPATH' ) || exit;
class HelloElementor
{
public static function init()
{
add_action( 'jreviews_template:before_content', [ __CLASS__, 'output_content_wrapper_open' ] );