Created
May 22, 2024 14:18
-
-
Save ipokkel/3056aa586328064de279217e75da748b to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Modify user field attributes example code. | |
* For Example: Change profile attribute based on location and user role. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_modify_user_field_attributes_example( $field, $where ) { | |
$user = wp_get_current_user(); | |
if ( is_admin() && 'admin_only' === $field->profile && ( current_user_can( 'edit_users' ) || in_array( 'editor', (array) $user->roles ) || in_array( 'author', (array) $user->roles ) ) ) { | |
$field->profile = 'only'; | |
} | |
return $field; | |
} | |
add_action( 'pmpro_add_user_field', 'my_pmpro_modify_user_field_attributes_example', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment