English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  System  >  Visualization  >  Display Table Head

apply_filters( 'vikrestaurants_display_{$page}_table_th', mixed $head, JView $viewarray $config )

Fires while displaying the table head of a specific entity.


Description

This hook is triggered within the list pages of certain sections of the plugin. It is possible to use this hook to include additional columns with list tables.

DO NOT include a th tag because it is automatically added by the system. Lean on data-id attribute for individual styling.

The dynamic portion of the hook name, $page, refers to the name of the page calling the hook. This means that, for example, the restaurant reservations page will trigger an hook called vikrestaurants_display_reservations_table_th.

IMPORTANT NOTE: not all the pages trigger this hook. Before to start coding a plugin, you should make sure that the page supports that hook, by checking whether the onDisplayTableColumns() method is used. This can be done by accessing the page at the path:

/wp-content/plugins/vikrestaurants/admin/views/{$page}/tmpl/default.php
(back-end pages)

Parameters

$head

(array|null)  An associative array containing the new columns to include. The key of the array should be a unique identifier to correctly pair the head with the body. The value of the array should be the legend to display.

At the first hook execution, the argument may be a null value.

$page

(JView)  The page instance holding the record details.

$config

(array)  An associative array of options.


Example

The example below displays the stay time of the reservations under the related list.

/**
 * Trigger hook to allow the plugins to include custom <TH> within the table. 
 * The hook must return an associative array where the key is the identifier
 * of the column and the value is the HTML to use.
 *
 * @param  mixed  $head    An associative array of columns.
 * @param  mixed  $view    The current page instance.
 * @param  array  $config  A configuration array.
 */
add_filter('vikrestaurants_display_reservations_table_th', function($head, $view, $config) {
    if (!$head) {
        $head = [];
    }

    // include "Stay Time" column within the table head
    $head['staytime'] = __('Stay Time', 'vikrestaurants');

    return $head;
}, 10, 3);

Changelog

Version Description
1.3 Introduced.
Last Update: 2024-01-04
Helpful?

This website uses cookies

This website uses cookies and similar technologies. Some of these technologies are necessary for the proper functioning of the website (Essential). Other technologies are used to evaluate user behavior (Analysis), to integrate external media or for advertising purposes. If you agree, these technologies are activated. For details, please refer to the privacy policy. From this same page you can also update/revoke your consent. If you do not give your consent, only cookies with essential functions will be activated.

We use technologies from the USA on our website. If you give your consent, you therefore consent at the same time to your data being transferred to the USA. We would like to point out that the USA does not have a level of data protection comparable to that of the EU and that any US company can be obliged by state authorities to hand over your data without you having any effective legal protection against this.