listing_detail_action_buttons
Allows adding and removing buttons.
You need to have a working knowledge of Hooks before you get started.
Parameters
Name | Type | Description |
---|---|---|
$buttons |
parameter |
(array) action buttons |
$params |
parameter |
(array) associative array with contextual data |
Boilerplate Code
Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.
Clickfwd\Hook\Filter::add('listing_detail_action_buttons', function($buttons, $params)
{
// Uncomment line below to view available data passed into hook
// fwd_dd($buttons, $params);
return $buttons;
});
Examples
- Add EasySocial message button
- Add BuddyPress & BuddyBoss message button
- Hide send inquiry button for non-featured listings
Add EasySocial message button
Integrate the EasySocial message button directly inside the listing detail page, allowing members to contact the listing owner.
function add_easysocial_message_button($buttons, $params)
{
if ( !defined('ES_MESSAGE_FILTER') ) {
require_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/foundry.php');
ES::initialize();
ES::language()->loadSite();
define('ES_MESSAGE_FILTER', 1);
}
// If user not logged in, show sign-up dialog
if (fwd_auth()->user()->isGuest()) {
$url = fwd_request()->createFromGlobals()->fullUrl();
$formData = json_encode(['current_url' => base64_encode($url)]);
$messageButton = '<a href="/jreviews/users/signupModal"
class="jrButton jrSmall jrButton"
rel="nofollow noopener"
data-jr-action="dialog"
data-jr-dialog-modal="1"
data-jr-width="800"
data-jr-title="Requires an Account"
data-form-data=\''.$formData.'\'
>
<span class="jrIconMessage"></span> Send Message
</a>';
$buttons[] = $messageButton;
return $buttons;
}
$listing = $params['listing'];
$easysocial = '
<button type="button" class="jrButton jrSmall"
data-es-conversations-compose
data-es-conversations-id="'.$listing['User']['user_id'].'"
data-es-provide="tooltip"
data-original-title="Contact This Member"
>
<span class="jrIconMessage"></span> Contact This Member
</button>
';
$buttons[] = $easysocial;
return $buttons;
}
Clickfwd\Hook\Filter::add('listing_detail_action_buttons', 'add_easysocial_message_button', 10);
Add BuddyPress & BuddyBoss message button
Integrate the BuddyBoss and BuddyPress message button directly inside the listing detail page, allowing members to contact the listing owner.
function add_bb_message_button($buttons, $params)
{
if (! function_exists('bp_loggedin_user_domain')) {
return $buttons;
}
// If user not logged in, show sign-up dialog
if (fwd_auth()->user()->isGuest()) {
$url = fwd_request()->createFromGlobals()->fullUrl();
$formData = json_encode(['current_url' => base64_encode($url)]);
$messageButton = '<a href="/jreviews/users/signupModal"
class="jrButton jrSmall jrButton"
rel="nofollow noopener"
data-jr-action="dialog"
data-jr-dialog-modal="1"
data-jr-width="800"
data-jr-title="Requires an Account"
data-form-data=\''.$formData.'\'
>
<span class="jrIconMessage"></span> Send Message
</a>';
$buttons[] = $messageButton;
return $buttons;
}
$listing = $params['listing'];
$userId = $listing['User']['user_id'];
$url = wp_nonce_url( bp_loggedin_user_domain().bp_get_messages_slug().'/compose/?r='.bp_core_get_username($userId));
$messageButton = '
<a href="'.$url.'" class="jrButton jrSmall">
<span class="jrIconMessage"></span> Send Message
</a>
';
$buttons[] = $messageButton;
return $buttons;
}
Clickfwd\Hook\Filter::add('listing_detail_action_buttons', 'add_bb_message_button', 10);
Hide send inquiry button for non-featured listings
If you want to show the send inquiry button only for featured listings, you can change the default behavior to hide it when a listing is not featured.
Clickfwd\Hook\Filter::add('listing_detail_action_buttons', function($buttons, $params)
{
if (! $params['listing']['Listing']['featured']) {
unset($buttons['inquiry']);
}
return $buttons;
});
Source Files
/views/helpers/listing_helper.php