Skip to content

Instantly share code, notes, and snippets.

@leoloso
Created May 5, 2022 02:56
Show Gist options
  • Save leoloso/2b26da2881e95d8e08a498dea7f4f7bd to your computer and use it in GitHub Desktop.
Save leoloso/2b26da2881e95d8e08a498dea7f4f7bd to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Helper Plugin - Disable user edit profile for WP PoP API
Version: 0.1
Description: It removes the edit profile page for all users other than admins
Plugin URI: https://gist.github.com/leoloso/4e367eb8d8014a7aa7580567608bd5b4
Author: Leonardo Losoviz
*/
/**
* @see: https://wordpress.stackexchange.com/a/45892
*/
// ===== remove edit profile link from admin bar and side menu and kill profile page if not an admin
function mytheme_admin_bar_render() {
if( current_user_can('activate_plugins') ) {
return;
}
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( current_user_can('activate_plugins') ) {
return;
}
if(defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE === true) {
wp_die( 'Please contact your administrator to have your profile information changed.' );
}
wp_die( 'Please contact your administrator to access this page.' );
}
add_action( 'admin_init', 'stop_access_profile' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment