JReviews logo
Guides My site
← All guides Community guide

Add an EngageUsers follow button to list pages

Josh
Thread started by Josh. Contributors Josh.
Thread started
Last updated

What you’ll achieve

Let visitors follow listings from list pages using the EngageUsers subscription controls.

My site

Platform
JReviews version

Add a Follow button beside each listing on a list page so visitors can follow it without opening its detail page.

Configure EngageUsers and preferences

Install and activate EngageUsers and configure notification preferences before adding the Follow button to list pages. Verify that its normal Follow control works.

For JReviews 6 Early Access list pages, enable Listing List Pages in Early Access. EngageUsers Pages separately switches the activity stream, inbox, and preferences pages to Early Access. Enable it if you use the Early Access preferences page.

Open your EngageUsers preferences page and copy its path. Replace /preferences in the legacy callback if your page uses a different path.

JReviews 6 Early Access

Register the Follow action

Joomla. Add the code to templates/jreviews_overrides/hooks.php.

WordPress. Add the code to jreviews_overrides/hooks.php.

Add the callback marked with +. EngageUsers already provides a Follow button on listing detail pages. The callback adds that button to list pages through listings_list. Visitors can follow or unfollow a listing, and guests see the account prompt.

  • If hooks.php already exists, add the marked lines at the end of the file. The copy button copies only those lines.
  • If you are creating hooks.php, type the two dimmed lines first, then add the marked lines below them.
<?php
defined('MVC_FRAMEWORK') or die;

fwd_add_filter('jreviews:listing:actions.listings_list', function (array $result, $listing): array {
    if (! class_exists(\JReviews\Addons\EngageUsers\App\View\Components\Blocks\FollowListingBlock::class)) {
        return $result;
    }

    $result['blocks']['follow'] = [
        'callback' => fn () => \JReviews\Addons\EngageUsers\App\View\Components\Blocks\FollowListingBlock::make(listing: $listing)
            ->size($result['size'] ?? 'sm')
            ->render(),
        'position' => 26,
    ];

    $result['exclude'] = array_values(array_diff($result['exclude'] ?? [], ['follow']));

    if (($result['include'] ?? null) !== null) {
        $result['include'] = array_values(array_unique([...$result['include'], 'follow']));
    }

    return $result;
}, 20, 2);

If EngageUsers is unavailable, the class check leaves the existing buttons unchanged. Favorite is a separate button.

To show Follow only for one listing type, add this condition at the start of the callback, before the class check. Replace 1 with that listing type's ID:

if ((int) $listing->listing_type_id !== 1) {
	return $result;
}

To show Favorite alongside Follow, keep the built-in Favorite block enabled in the layout and enable favorites for the listing type.

JReviews 5 and v6 Legacy

Add the Follow callback

Joomla. Use templates/jreviews_overrides/filters/filter_functions.php.

WordPress. Use jreviews_overrides/filters/filter_functions.php.

Start a new file with <?php followed by defined('MVC_FRAMEWORK') or die;. The code adds a Follow button that opens the preferences dialog.

Add the following callback to filter_functions.php.

/* Add Subscribe button to list page */

function add_subscribe_button_list_page($buttons, $params)
{

   $listing = $params['listing'];
   $listing_id = (int) $listing['Listing']['listing_id'];

   if (S2Object::make('auth')->guest) {
       ob_start();
       ClassRegistry::getClass('ListingHelperHelper')->signupModal([
           'btn_class' => 'jrFollowButton jrButton jrSmall jrOrange',
           'btn_text' => 'Follow',
           'btn_icon_class' => 'jrIconBell',
       ]);
       $buttons['subscribe'] = ob_get_clean();
       return $buttons;
   }

   ob_start();?>
   <span data-jr-follow="">
    <a class="jrFollowButton jrButton jrSmall jrOrange" data-jr-action="dialog" data-jr-dialog-modal="true" data-jr-width="512" data-jr-title="Follow" rel="nofollow" href="/preferences?task=createFollow&app=jreviews&area=listing&rel_id=<?php echo $listing_id;?>">
        <span class="jrIconBell"></span>Follow
     </a>
    </span>
        <?php
        $subscribeButton = ob_get_clean();
        $buttons['subscribe'] = $subscribeButton;
   return $buttons;
}

Clickfwd\Hook\Filter::add('listing_list_action_buttons', 'add_subscribe_button_list_page', 10);

Keep the app, area, and rel_id parameters identifying the listing.

Add Favorite too, if needed

If you need the combined callback below, use it instead of the preceding Follow callback, not alongside it.

function add_favorite_button_list_page($buttons, $params)
{
   $listing = $params['listing'];

   $listingHelper = ClassRegistry::getClass('ListingHelperHelper');

   ob_start();

   $listingHelper->favorite($listing);

   $favoriteButton = ob_get_clean();

   $buttons['favorite'] = $favoriteButton;

   // Show subscribe button

   $listing_id = (int) $listing['Listing']['listing_id'];

   if (S2Object::make('auth')->guest) {
       ob_start();
       ClassRegistry::getClass('ListingHelperHelper')->signupModal([
           'btn_class' => 'jrFollowButton jrButton jrSmall jrOrange',
           'btn_text' => 'Follow',
           'btn_icon_class' => 'jrIconBell',
       ]);
       $buttons['subscribe'] = ob_get_clean();
       return $buttons;
   }
   ob_start();?>
   <span data-jr-follow="">
    <a class="jrFollowButton jrButton jrSmall jrOrange" data-jr-action="dialog" data-jr-dialog-modal="true" data-jr-width="512" data-jr-title="Follow" rel="nofollow" href="/preferences?task=createFollow&app=jreviews&area=listing&rel_id=<?php echo $listing_id;?>">
        <span class="jrIconBell"></span>Follow</a></span>
        <?php
        $subscribeButton = ob_get_clean();
        $buttons['subscribe'] = $subscribeButton;

   return $buttons;
}
Clickfwd\Hook\Filter::add('listing_list_action_buttons', 'add_favorite_button_list_page', 10);

Follow and unfollow a listing

Sign in as a member, follow a listing from the list page, and then unfollow it. Confirm that each action updates the follow state. Repeat as a guest and check the account prompt.

Confirm that the preferences link opens your preferences page.

If your layout limits the actions shown, check that it allows Follow. Configure and test notification delivery separately.

To show Follow only for one listing type, add if ((int) $params['listing']['ListingType']['listing_type_id'] !== 1) { return $buttons; } immediately after the callback's opening {. Replace 1 with the ID shown for that type in Listing Types Manager. For the combined Favorite and Follow example, this condition restricts both buttons.

See EngageUsers follows and Listing actions.

Learn more