Skip to content

Instantly share code, notes, and snippets.

View jreviews's full-sized avatar

JReviews jreviews

View GitHub Profile
@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],
@jreviews
jreviews / filter_functions.php
Created April 19, 2021 11:01
JReviews filter to hide `write review` in action buttons area for listing owners
<?php
Clickfwd\Hook\Filter::add('listing_list_action_buttons', 'jreviews_hide_write_review_for_owners');
Clickfwd\Hook\Filter::add('listing_detail_action_buttons', 'jreviews_hide_write_review_for_owners');
function jreviews_hide_write_review_for_owners($buttons, $params)
{
if (S2Object::make('auth')->id == $params['listing']['User']['user_id']) {
unset($buttons['write_review']);
}
@jreviews
jreviews / modal-behavior._hs
Last active January 23, 2024 09:27
Hyperscript modal behavior
behavior Modal
init
set my focusRing to (<a, button, input:not([type=hidden]), textarea, select, details/> in me) as Array
end
on open
remove .hide
add { overflow: 'hidden' } to the <body/>
transition <[data-backdrop], [data-content]/> in me opacity from 0 to 1 over 0.3s
focus() the first <input/> in me
@jreviews
jreviews / unpublished-listings-filters.md
Created February 22, 2021 16:17
Use filters to show unpublished in dropdown and filter the results
// Filter to include new 'unpublished' option in ordering select list
Clickfwd\Hook\Filter::add('listing_list_ordering_select', function($orderingParams, $params) 
{    
    if (S2Object::make('auth')->guest) {
        return $orderingParams;
    }

    $orderingParams['options']['unpublished'] = 'Unpublished';