hanlders]
* @return array [endpoints=>hanlders]
*/
static function filterRestEndpoints($endpoints)
{
if (self::isJustEditor())
{
error_reporting(0); // there are a couple of PHP notices which prevent the Ajax JSON data from loading
foreach($endpoints as $route=>$handlers) //for each endpoint
if (strpos($route, '/elementor/v1/form') === 0) //it is one of the elementor endpoints forms, form-submissions or form-submissions/export
foreach($handlers as $num=>$handler) //loop through the handlers
if (is_array ($handler) && isset ($handler['permission_callback'])) //if this handler has a permission_callback
$endpoints[$route][$num]['permission_callback'] = function($request){return true;}; //handler always returns true to grant permission
}
return $endpoints;
}
/**
* Add the submissions page to the admin menu on the left for editors only, as administrators
* can already see it.
*/
static function addOptionsPage()
{
if (!self::isJustEditor()) return;
add_menu_page('Inschrijvingen', 'Inschrijvingen', 'edit_posts', 'e-form-submissions', function(){echo '';},'dashicons-email', 2);
}
/**
* Hook up the filter and action. I can't check if they are an editor here as the wp_user_can function
* is not available yet.
*/
static function hookIntoWordpress()
{
add_filter ('rest_endpoints', array('ElementorFormSubmissionsAccess', 'filterRestEndpoints'), 1, 3);
add_action ('admin_menu', array('ElementorFormSubmissionsAccess', 'addOptionsPage'));
}
}
ElementorFormSubmissionsAccess::hookIntoWordpress();
} //a wrapper to see if the class already exists or not