Italian (Italy)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Dashboard  >  Recupera i Widget supportati

apply_filters( 'vikrestaurants_fetch_supported_statistics_widgets', mixed $widgets )

Fires while loading the supported widgets to display within the dashboard and statistics pages.


Description

This filter can be used to support additional types of widgets without having to edit any core files.

Here you should simply return the list of widgets that can be loaded within the script. Only the base name of the files have to be returned. The base name of the files to load can specify only letters, numbers and underscores.

Note: at the first execution of the hook the $widgets argument isn't an array.


Parameters

$widgets

(array|null)  The array holding the name of the external widgets to load.


Example

The example below adds support for all the widgets contained in a specific folder of a third-party plugin. Such as:

/wp-content/plugins/vikwp/widgets/

All the PHP files contained within the widgets folder of the VikWP plugin will be loaded.

/**
 * Trigger filter can be used to register external widgets to
 * extend the statistics dashboard without editing any core files.
 *
 * @param  array|null  $widgets  The array holding the widgets to load.
 */
add_filter('vikrestaurants_fetch_supported_statistics_widgets', function($widgets)
{
    if (!$widgets)
    {
        // first cycle of the filter, init the list of widgets
        $widgets = array();
    }

    // create base path to "widgets" folder contained within the plugin
    $base = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'widgets' . DIRECTORY_SEPARATOR;

    // load all PHP files from "widgets" folder
    $files = glob($base . '*.php');

    // IMPORTANT: map the widgets to return only the base name
    $files = array_map(function($widget)
    {
        return basename($widget);
    }, $files);

    // merge existing widgets with this ones
    return array_merge($widgets, $files);
});

Changelog

Version Description
1.0 Introduced.
Ultimo aggiornamento: 2021-03-03
Utile?
Potrebbe interessarti:

Questo sito web utilizza i cookie

Questo sito web utilizza cookie e tecnologie simili. Alcune di queste tecnologie sono necessarie per il corretto funzionamento del sito web (essenziali). Altre tecnologie sono utilizzate per valutare il comportamento degli utenti (analisi), per integrare media esterni o per scopi pubblicitari. Se l'utente accetta, queste tecnologie vengono attivate. I dettagli sono riportati nella Privacy Policy. Da questa stessa pagina è inoltre possibile aggiornare/revocare il consenso. Se non si fornisce il consenso, verranno attivati solo i cookie con funzioni essenziali.

Sul nostro sito web utilizziamo tecnologie provenienti dagli Stati Uniti. Pertanto, se acconsentite, acconsentite anche al trasferimento dei vostri dati negli Stati Uniti. Desideriamo sottolineare che gli Stati Uniti non hanno un livello di protezione dei dati paragonabile a quello dell'Unione Europea e che qualsiasi azienda statunitense può essere obbligata dalle autorità statali a consegnare i vostri dati senza che voi abbiate alcuno strumento efficace di protezione legale contro questo.