English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Core  >  After Display Page

do_action( 'vikappointments_after_display_{$page}', JView $view )

Fires after displaying a page of the plugin.


Description

This hook is triggered every time the plugin completes the rendering of a page.

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

DO NOT echo any HTML in this hook to avoid sending the headers in advance.


Parameters

$page

(JView)  The page instance.


Example

The example below explains how to extend the toolbar with a custom button within the appointments list.

/**
 * Fires after the controller displayed the page.
 *
 * @param  JView  $page  The page instance.
 */
add_action('vikappointments_after_display_reservations', function($page)
{
    // adds a button to archive the appointments
    JToolbarHelper::archiveList('reservation.archive');
});

Every time the archive button is clicked, the plugin will submit the request to the following end-point.

/wp-admin/admin.php?page=vikappointments&task=reservation.archive

It is now possible to rely on the vikappointments_before_dispatch hook to intercept the request and archive the selected appointments.

add_action('vikappointments_before_dispatch', function()
{
    // get requested action
    $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';

    if (is_admin() && $task == 'reservation.archive')
    {
        // get selected records
        $ids = isset($_REQUEST['cid']) ? (array) $_REQUEST['cid'] : array();

        if (count($ids))
        {
            /**
             * @todo archive selected appointments
             */
        }

        // then go back to the appointments list
        wp_redirect('admin.php?page=vikappointments&view=reservations');
    }
});

Changelog

Version Description
1.0 Introduced.
Last Update: 2022-05-16
Helpful?