User capabilities
-
Hello,
Is there a way to allow Editors to view submissions?
I only found this old post but didn’t manage to make it work with the plugin submitted there by @edemir206. When activating this plugin, Forminator disappears!
Are there any new findings since this post?
Thanks.
-
Hi @dsl225
I hope you are doing well.
Another option is allowing full access:
https://gist.github.com/wpmudev-sls/d5b24413ca4211930aecd2bb07a4b562, and removing some pages using the remove_submenu_page() for editors.On upcoming update it will be included on the plugin:
https://premium.wpmudev.org/docs/wpmu-dev-plugins/forminator/#user-rolesOur team is already working to add this option on the plugin interface, which should include the “view” only.
Let us know if you need any further help on this.
Best Regards
Patrick FreitasMany thanks Patrick @wpmudevsupport12,
That’s excellent, will work that way for the time being and I’m looking forward to exploring the next version which really sounds very promising!
Good day!
I enabled the first part and that gives access to Editors without problem.
But I cannot manage the remove_submenu_page() for Editors to work correctly with this plugin.When I use “editor” in this part:
public function my_cap_forms() { //Aqui é a nova permiss?o mínima de acesso ao forminator, esse usuário poderá ver as submiss?es, porém apenas //usuários com permiss?o de "manage_options" poder?o criar forms, polls e quizes. return 'editor'; }
and I remove some sub-menu items it works fine for Editors but it completely hides Forminator menu for Admins!
I’m not sure I well understand how to use that section and the comments in there about ‘manage_options’ are quite confusing…
Any clues?
Hi @dsl225,
You only have to use the “remove_submenu_page” function, could you please try the following tweaked code and see whether it helps:
<?php /** * Plugin Name: [Forminator] Grants Full Access For Editor Role. * Plugin URI: https://premium.wpmudev.org/ * Description: This plugin allows users with the editor role to have full access (view and save) to the Forminator administrative pages. * Author: Glauber Silva @ WPMUDEV * Author URI: https://premium.wpmudev.org/ * Task: 0/11289012348292/1169742392170370 * License: GPLv2 or later * * @package Forminator_Grants_Full_Acesses_For_Editor_Role */ defined( 'ABSPATH' ) || exit; if ( ! class_exists( 'WPMUDEV_Forminator_Editor_Access' ) ) { /** * Main class of the plugin. */ class WPMUDEV_Forminator_Editor_Access { /** * Stores the main instance of the class. * * @var Property */ private static $instance = null; /** * Returns the main instance of the class. * * @return WPMUDEV_Forminator_Editor_Access */ public static function get_instance() { if ( is_null( self::$instance ) ) { self::$instance = new WPMUDEV_Forminator_Editor_Access(); } return self::$instance; } /** * Constructor of the class. */ private function __construct() { $this->init(); } /** * Loads the functions of the class in the apropriete hooks. */ public function init() { add_filter( 'forminator_admin_cap', array( $this, 'wpmudev_allows_editors_access_forminator_admin_pages' ) ); add_filter( 'user_has_cap', array( $this, 'wpmudev_allows_editors_save_forminator_admin_pages' ), 10, 4 ); add_action( 'admin_menu', array($this,'wpmudev_forminator_remove_menu_permissions'), 999 ); } /** * Changes the minimum capabilitie necessary to see the admin pages to one that editors has. * * @param string $cap The current cap necessary to access admin pages of forminator. * * @return string $cap The modify cap necessary to access admin pages of forminator. */ public function wpmudev_allows_editors_access_forminator_admin_pages( $cap ) { if ( ! current_user_can( $cap ) ) { return 'edit_others_posts'; } return $cap; } /** * Dynamically filter a user's capabilities. * * @since 2.0.0 * @since 3.7.0 Added the <code>$user</code> parameter. * * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name and boolean values * represent whether the user has that capability. * @param string[] $caps Required primitive capabilities for the requested capability. * @param array $args { * Arguments that accompany the requested capability check. * * @type string $0 Requested capability. * @type int $1 Concerned user ID. * @type mixed ...$2 Optional second and further parameters, typically object ID. * } * @param WP_User $user The user object. */ public function wpmudev_allows_editors_save_forminator_admin_pages( $allcaps, $caps, $args, $user ) { if ( ! isset( $_POST['forminator_export'] ) ) { // phpcs:ignore $is_export_action = false; } else { $is_export_action = true; } if ( ! isset( $_REQUEST['action'] ) || isset( $_REQUEST['action'] ) && strpos( $_REQUEST['action'], 'forminator' ) === false ) { // phpcs:ignore $is_allowed_ajax_actions = false; } else { $is_allowed_ajax_actions = true; } if ( ( $is_export_action || $is_allowed_ajax_actions ) && array_key_exists( 'edit_others_posts', $allcaps ) && ! array_key_exists( 'manage_options', $allcaps ) ) { $allcaps = array_merge( $allcaps, array( 'manage_options' => true ) ); } return $allcaps; } public function wpmudev_forminator_remove_menu_permissions() { if ( ! current_user_can( 'manage_options' ) ) { remove_submenu_page( 'forminator','forminator' ); remove_submenu_page( 'forminator','forminator-cform' ); remove_submenu_page( 'forminator','forminator-quiz' ); remove_submenu_page( 'forminator','forminator-poll' ); remove_submenu_page( 'forminator','forminator-settings' ); remove_submenu_page( 'forminator','forminator-integrations' ); remove_submenu_page( 'forminator','forminator-cform-wizard' ); remove_submenu_page( 'forminator','forminator-poll-wizard' ); remove_submenu_page( 'forminator','forminator-nowrong-wizard' ); remove_submenu_page( 'forminator','forminator-knowledge-wizard' ); remove_submenu_page( 'forminator', 'forminator-settings' ); } } } add_action( 'plugins_loaded', function() { return WPMUDEV_Forminator_Editor_Access::get_instance(); } ); }
Regards,
NithinMany thanks Nithin @wpmudevsupport11,
That works great indeed!
I only had to remove the previous one submitted by Patrick to make this work and, if I well understand, this one seems to be a mix of the 2 codes:
– The Editor role gets full access and then menus are removed for this role, or is it a bit different?
Just for my personal education…
Many thanks for your time and assistance!
Hello @dsl225 ,
– The Editor role gets full access and then menus are removed for this role, or is it a bit different?
That is correct. Editor gets full access to Forminator options, so then if we want to limit those then remove_submenu_page is used, to not show those submenus.
kind regards,
KasiaMany thanks, that’s awesome!
- The topic ‘User capabilities’ is closed to new replies.