Hooks

This applies only to Business Directory 5.0 and later.

Overview

Introduction

Business Directory Plugin offers plugin and theme developers the ability to hook into some of our processes and templates using WordPress actions.

Using general hooks custom processes can be included within Business Directory normal execution. Using template hooks extra HTML or output can be displayed on certain specific pages.

How to use the hooks?

Since our hooks are just regular WordPress actions, you need to familiarize yourself with the WordPress Plugin API and with the add_action() function in particular.

Once you’ve decided which hook to use (see list below) you have to edit your theme’s functions.php file or create a new plugin that takes advantage of said hook. See example below.

Example 1

The following PHP code would display “Thank you for your purchase!” after the checkout receipt is printed by BD.

<?php
function my_thankyou_function() {
    echo '<h4>Thank you for your purchase!</h4>';
}
add_action( 'wpbdp_after_render_receipt', 'my_thankyou_function' );
?>

Example 2

The following PHP code displays a message on top of every category page, with a special message (“Everybody likes pizza”) for just the category with slug “pizza”.

<?php

function pizza_places_message( $category ) {
    if ( 'pizza' == $category->slug ) {
        echo "<p>Everybody likes pizza.</p>";
    } else {
        echo "<p>This is category {$category->name}.</p>";
    }
}
add_action( 'wpbdp_before_category_page', 'pizza_places_message' );
?>

General Actions

Hook Name Description Arguments Module
wpbdp_save_listing Fired after a listing has been saved into the database. $listing_id
<pre> (int) - The listing ID.</pre>
$context
<pre> (bool) - Listing save context, true for new listings, false for edited listings.</pre>
BD Core Plugin 5.0
wpbdp_add_listing Fired after a listing has been created and saved into the database. $listing_id
<pre> (int) - The inserted listing ID.</pre>
BD Core Plugin 5.0
wpbdp_edit_listing Fired after a listing has been edited in the frontend and saved in the database. This action is not fired when a listing has been edited in WP Dashboard. $listing_id
<pre> (int) - The edited listing ID.</pre>
BD Core Plugin 5.0
wpbdm_listing_claimed Fired after claim listing process is finished. $listing_id
<pre> (int) - The claimed listing ID.</pre>
$claim_id
<pre> (int) - The claim ID.</pre>
Claim Listings 5.1.2
wpbdm_claim_approved Fired after admin approves a listing claim. $listing_id
<pre> (int) - The claimed listing ID.</pre>
$claim_id
<pre> (int) - The claim ID.</pre>
Claim Listings 5.1.2

Template Actions

Hook Name Description Arguments
wpbdp_checkout_form_top Fired at the top of the checkout form. Used by the Discount Codes module to display its discount field. $payment
<pre> (object) - The payment object.</pre>
wpbdp_checkout_form_bottom Fired at the bottom of the checkout form. $payment
<pre> (object) - The payment object.</pre>
wpbdp_before_render_receipt Fired before rendering the receipt during the checkout process. $payment
<pre> (object) - The payment object.</pre>
wpbdp_after_render_receipt Fired after rendering the receipt during the checkout process. $payment
<pre> (object) - The payment object.</pre>
wpbdp_before_search_results Fired before rendering the search results. Only when there are results.  
wpbdp_after_search_results Fired after rendering the search results. Only when there are results.  
wpbdp_before_category_page Fired before rendering the category page. $category
<pre> (object) - The current category. A WP_Term object.</pre>
wpbdp_after_category_page Fired after rendering the category page. $category
<pre> (object) - The current category. A WP_Term object.</pre>
wpbdp_before_submit_listing_page Fired before rendering the submit listing page. $listing
<pre> (object) - An object with information about the current listing being submitted or edited.</pre>
wpbdp_after_submit_listing_page Fired after rendering the submit listing page. $listing
<pre> (object) - An object with information about the current listing being submitted or edited.</pre>