Ich entwickle gerade ein Intranet und verwende das Mitglieder-Plugin von Justin Tadlock, um Rollen und Funktionen zu steuern.
Ich habe eine HR
-Rolle erstellt, mit der Personalmitarbeiter Benutzerkonten erstellen und bearbeiten können. Allen Mitarbeitern, die in WP erstellt wurden, wird die Rolle contributor
zugewiesen, und einigen ausgewählten Mitarbeitern werden die Rollen editor
und administrator
zugewiesen.
Ich möchte, dass sich Mitarbeiter nicht mehr anmelden und ihre eigenen Profilinformationen ändern. Nur Mitarbeiter der Rolle HR
dürfen Profilinformationen bearbeiten können.
Hat es mit ein bisschen Zeit geklappt. Hier ist der Code, den ich benutze:
<?php
/*
Plugin Name: Restrict User Editing Own Profile
Plugin URI: http://www.philosophydesign.com
Description: Restricts users from editing their own profile information.
Author: Scott Cariss
Version: 0.1
Author URI: http://www.philosophydesign.com/scott-cariss.html
*/
add_action( 'admin_menu', 'stop_access_profile' );
function stop_access_profile() {
remove_menu_page( 'profile.php' );
remove_submenu_page( 'users.php', 'profile.php' );
if(IS_PROFILE_PAGE === true) {
wp_die( 'You are not permitted to change your own profile information. Please contact a member of HR to have your profile information changed.' );
}
}
?>
Der obige Code hindert jeden daran, seine eigenen Profilinformationen zu bearbeiten, unabhängig davon, wer er ist. Benutzer, die Verwendungen erstellen und bearbeiten können, können dies weiterhin tun, aber ihre eigenen nicht ändern.
tolle Antwort, um noch einen Schritt weiter zu gehen und für alle, die dies auf alle Benutzer ohne Administratorrechte anwenden möchten (z. B. Mitwirkende, Redakteure usw.).
// ===== remove edit profile link from admin bar and side menu and kill profile page if not an admin
if( !current_user_can('activate_plugins') ) {
function mytheme_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('edit-profile', 'user-actions');
}
add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
function stop_access_profile() {
if(IS_PROFILE_PAGE === true) {
wp_die( 'Please contact your administrator to have your profile information changed.' );
}
remove_menu_page( 'profile.php' );
remove_submenu_page( 'users.php', 'profile.php' );
}
add_action( 'admin_init', 'stop_access_profile' );
}
Ich überprüfte alle bereitgestellten Lösungen und dachte, ich könnte ein nettes MU-Plugin daraus machen. Die einzige wirkliche Änderung ist, dass es vermeidet
<?php
! defined( 'ABSPATH' ) AND exit;
/**
* Plugin Name: Disable profile page link
* Description: Remove edit profile link from admin bar and side menu and kill profile page if user isn't an administrator.
*/
# Version: 2012-09-15.2245
function oxo_stop_access_profile()
{
// Remove AdminBar Link
if (
'wp_before_admin_bar_render' === current_filter()
AND ! current_user_can( 'manage_options' )
)
return $GLOBALS['wp_admin_bar']->remove_menu( 'edit-profile', 'user-actions' );
// Remove (sub)menu items
remove_menu_page( 'profile.php' );
remove_submenu_page( 'users.php', 'profile.php' );
// Deny access to the profile page and redirect upon try
if (
defined( 'IS_PROFILE_PAGE' )
AND IS_PROFILE_PAGE
AND ! current_user_can( 'manage_options' )
)
{
wp_redirect( admin_url() );
exit;
}
}
add_action( 'wp_before_admin_bar_render', 'oxo_stop_access_profile' );
add_action( 'admin_menu', 'oxo_stop_access_profile' );
Alle obigen Lösungen verwenden die Konstante: IS_PROFILE_PAGE
if( IS_PROFILE_PAGE === true ) {
Wenn jedoch wordpress debug auf true gesetzt ist, wird der Fehler "undefined constant" ausgegeben. Etwas reparieren :
if( defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE === true ){
........................
}
add_action( 'admin_menu', 'prefix_disable_profile_access' );
function prefix_disable_profile_access() {
if( ! current_user_can('editor') || ! current_user_can('administrator') ) { // You can add the user roles who can edit their profiles here.
remove_menu_page( 'profile.php' );
remove_submenu_page( 'users.php', 'profile.php' );
if ( true === IS_PROFILE_PAGE ) {
wp_die( 'You are not permitted to change your own profile information. Please contact a member of HR to have your profile information changed.' );
}
}
}
Hoffe das hilft jemandem.