Created
August 2, 2024 14:34
-
-
Save adczk/97bcd754a7ac3583d809dbd119db0c76 to your computer and use it in GitHub Desktop.
Forminator - hide and disallow bulk delete entry actions and delete/resend buttons for subscriber roles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Forminator - block entry delete action for subscribers | |
* Plugin URI: https://gist.github.com/adczk | |
* Description: Hides and disallows delte entry options for subscribers; hides other buttons in single entry footer too | |
* Author: adczk | |
* | |
* Author URI: https://gist.github.com/adczk | |
* License: GPLv2 or later | |
* | |
* Use as MU plugin; | |
* | |
* Tested with Forminator 1.34.0 | |
* | |
* you can replace "subscirber" role in code with any other role | |
* role has to be first given permission to access submissions via the Forminator permission settings | |
* | |
*/ | |
// hide bulk options and delete button | |
add_action( 'admin_footer', 'wpmu_block_forminator_delete_entry_css' ); | |
function wpmu_block_forminator_delete_entry_css() { | |
$user = wp_get_current_user(); | |
if ( in_array( 'subscriber', (array) $user->roles ) ) { | |
?> | |
<style> | |
.wpmudev-forminator-forminator-entries .sui-search-left *, | |
.wpmudev-forminator-forminator-entries .sui-box-footer { | |
display:none!important; | |
} | |
</style> | |
<?php | |
} | |
} | |
// issue error if delete attempt | |
add_action( 'forminator_before_delete_entries', 'wpmu_block_forminator_delete_entry', 10, 1 ); | |
add_action( 'forminator_before_delete_entry', 'wpmu_block_forminator_delete_entry', 10, 1 ); | |
function wpmu_block_forminator_delete_entry( $args ) { | |
$user = wp_get_current_user(); | |
if ( in_array( 'subscriber', (array) $user->roles ) ) { | |
wp_die( "You're not allowed to do this!" ); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment