Skip to content

Instantly share code, notes, and snippets.

@wal-f
Last active March 11, 2025 14:15
Show Gist options
  • Save wal-f/447409ccee66c545a06789c5203e548b to your computer and use it in GitHub Desktop.
Save wal-f/447409ccee66c545a06789c5203e548b to your computer and use it in GitHub Desktop.
A method to provide full management of form submissions to less-privileged WP roles.
<?php
/*
Plugin Name: Elementor form submission access
Description: Promotes the Elementor Pro form submissions page to top level, and bypasses the excessive and inflexible restrictions on access.
Version: 2.0.0
Author: Some netizen
Update URI: do-not-auto-update
*/
namespace Elementor\Core\Admin\Menu;
defined('ABSPATH') or die;
/**
* Shim the WordPress submenu function by creating a namespaced version that only exists when Elementor creates its
* menu items. That means it can intercept the form submissions link to promote it to the top level but other plugins
* and WordPress code do not see this shimmed version.
*/
function add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null) {
if ($menu_slug === 'e-form-submissions') {
return \add_menu_page($page_title, $menu_title, 'etor_submissions_read', $menu_slug, $callback, 'dashicons-forms', 3.5);
}
return \add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback, $position);
}
/**
* Wait till elementor has registered its REST endpoints, and replace the permissions check with capabilities you can
* assign to whoever you need, instead of Elementor's use of the generic 'manage_options' capability.
*/
add_filter(
'rest_endpoints',
function($endpoints) {
$permission_callback = function($request) {
if ($request->get_method() === 'GET') {
return current_user_can('etor_submissions_read');
}
return current_user_can('etor_submissions_full_management');
};
foreach ($endpoints as $route => $handlers) {
if (preg_match('#^/elementor/v1/form(?:-submission)?s(?:$|/)#', $route)) {
if (!isset($handlers['callback'])) {
foreach ($handlers as $i => $handler) {
if (isset($handler['permission_callback'])) {
$endpoints[$route][$i]['permission_callback'] = $permission_callback;
}
}
}
elseif (isset($handlers['permission_callback'])) {
$endpoints[$route]['permission_callback'] = $permission_callback;
}
}
}
return $endpoints;
},
444444444
);
@wal-f
Copy link
Author

wal-f commented May 16, 2023

To install this:

  1. Download the PHP file from the Raw link above.
  2. Upload this file directly to your wp-content/plugins directory or zip the file (by itself, no folders) and upload that zip on your Add New plugin admin page.
  3. Activate it from your Plugins page.
  4. Temporarily install a role manager plugin to create and assign the custom capabilities, e.g. with User Role Editor:
    1. Install and activate the role editor.
    2. Go to its admin page in the Users submenu.
    3. Click Add Capability and add etor_submissions_read:
      Screenshot of adding permission
    4. Repeat for etor_submissions_full_management.
    5. Select the roles that should have the capabilities, tick the box(es) and click Update. Managers will also need read.
  5. The Submissions page should now be available to the relevant roles.
  6. Deactivate the role manager plugin.

@manuel-will
Copy link

This works nicely. I have briefly added the members plugin to add the role, then deactivated members again. Thank you for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment