English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Core  >  Before Dispatch

do_action( 'vikrestaurants_before_dispatch' )

Fires before dispatching the plugin request.


Description

Every time the plugin tries to dispatch a request, this hook is triggered first.

It is useful to require some external libraries, check user global permissions, intercept the dispatched action, inject post variables and so on.


Example

The example below explains how to support a new type of page for the back-end of the plugin. The page will display every time you try to visit the link below.

/wp-admin/admin.php?page=vikrestaurants&view=mypage
/**
 * Fires before the controller of VikRestaurants is dispatched.
 * Useful to require libraries and to check user global permissions.
 */
add_action('vikrestaurants_before_dispatch', function()
{
    // get current view
    $view = isset($_REQUEST['view']) ? $_REQUEST['view'] : null;

    // check whether the view is supported
    if (is_admin() && $view == 'mypage')
    {
        // display main menu
        RestaurantsHelper::printMenu();

        /**
         * @todo display page contents here
         */
    }
});

Changelog

Version Description
1.0 Introduced.
Last Update: 2021-01-26
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information