| Server IP : 39.106.62.82 / Your IP : 216.73.217.128 Web Server : nginx/1.14.1 System : Linux iz2ze1m0zmp2dk5c3j5ap5z 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /webdata/gohomesh.com/wp-content/plugins/members/addons/members-privacy-caps/ |
Upload File : |
<?php
namespace Members\AddOns\PrivacyCaps;
# Add actions and filters.
add_action( 'members_register_caps', __NAMESPACE__ . '\register_caps' );
add_filter( 'map_meta_cap', __NAMESPACE__ . '\map_meta_cap', 95, 2 );
# Register activation/deactivation hooks.
register_activation_hook( __FILE__, __NAMESPACE__ . '\activation' );
/**
* Adds the privacy capabilities to the administrator role whenever the plugin
* is activated.
*
* On Multisite, we're not adding any caps to a role because these caps are, by
* default, only allowed for people with the `manage_network` capability, which
* is a Super Admin cap. If network owners want sub-site administrators to be
* able to have thse caps, they should be added to the role via the edit role
* screen in Members.
*
* @since 1.0.0
* @access public
* @return void
*/
function activation() {
if ( is_multisite() ) {
return;
}
$role = get_role( 'administrator' );
if ( $role ) {
$role->add_cap( 'export_others_personal_data' );
$role->add_cap( 'erase_others_personal_data' );
$role->add_cap( 'manage_privacy_options' );
}
}
/**
* Registers capabilities with the Members plugin.
*
* @since 1.0.0
* @access public
* @return void
*/
function register_caps() {
members_register_cap( 'manage_privacy_options', [
'label' => __( 'Manage Privacy Options', 'members' ),
'group' => 'general'
] );
members_register_cap( 'erase_others_personal_data', [
'label' => __( "Erase Others' Personal Data", 'members' ),
'group' => 'user'
] );
members_register_cap( 'export_others_personal_data', [
'label' => __( "Export Others' Personal Data", 'members' ),
'group' => 'user'
] );
}
/**
* The privacy caps are mapped to `manage_options` (or `manage_network` in the
* case of multisite) by default, effectively making them meta caps. We're
* turning the caps into primitive caps.
*
* @since 1.0.0
* @access public
* @param array $caps
* @param string $cap
* @return array
*/
function map_meta_cap( $caps, $cap ) {
$privacy_caps = [
'export_others_personal_data',
'erase_others_personal_data',
'manage_privacy_options'
];
if ( in_array( $cap, $privacy_caps ) ) {
// The cap should map back to itself.
$caps = [ $cap ];
// Core WP requires the 'delete_users' cap when erasing a user's
// personal data. This becomes even more important on multisite
// where even a sub-site admin might not be able to delete users.
// So, we're adding this as a required cap too.
if ( 'erase_others_personal_data' === $cap ) {
$caps[] = 'delete_users';
}
}
return $caps;
}