Skip to content

Instantly share code, notes, and snippets.

View wp-user-manager's full-sized avatar

wp-user-manager

View GitHub Profile
@wp-user-manager
wp-user-manager / wpum_conditional_account_tabs.php
Created March 20, 2020 12:54
WP User Manager - Conditionally show/hide account tabs based on role
<?php
function wpum_account_tab_changes( $tabs ) {
$tabs['settings']['name'] = esc_html( 'User Details' );
$user = wp_get_current_user();
if ( in_array( 'subscriber', (array) $user->roles ) ) {
unset( $tabs['institution-detail'] );
$tabs['individual-detail']['name'] = esc_html( 'Additional Information' );
}
@wp-user-manager
wp-user-manager / wpum_customize_new_user_registration_email.php
Last active April 10, 2020 07:47
WP User Manager - Customize the new user registration admin email
<?php
// Add this file to the wp-content/mu-plugins directory. The mu-plugins directory might need to be created.
/**
* Send the new user registered email to other email addresses
*/
add_filter( 'wpum_admin_registration_confirmation_email_recipient', function ( $to_email ) {
return $to_email . ',someotheremail@gmail.com';
} );
@wp-user-manager
wp-user-manager / wpum_customize_admin_email_new_user.php
Created January 9, 2020 11:13
WP User Manager - Add all custom field data the user enters on registration to the email sent to the administrator
<?php
add_filter( 'wpum_admin_registration_confirmation_email_headers', function() {
return array('Content-Type: text/html; charset=UTF-8');
});
add_filter('wpum_admin_registration_confirmation_email_message', function( $message, $user ) {
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
$message = sprintf( esc_html__( 'You have a new member application for the %s:', 'wp-user-manager' ), $blogname ) . "<br><br>";
@wp-user-manager
wp-user-manager / wpum_add_paragraphs_to_profile_description.php
Created May 6, 2020 09:05
WP User Manager - Add paragraphs to new lines in the description field when outputted on the profile page
<?php
add_filter( 'wpum_field_ouput_callback_function', 'my_wpum_field_ouput_callback_function', 10, 3 );
function my_wpum_field_ouput_callback_function( $func_name, $field, $value ) {
if ( $field->primary_id !== 'user_description' ) {
return $func_name;
}
return 'wpum_format_field_description_output';
}
@wp-user-manager
wp-user-manager / wpum_stop_registration_emails.php
Created May 9, 2020 07:45
WP User Manager - Stop default registration emails being sent if wpum_send_registration_confirmation_email() is triggered elsewhere
<?php
add_action( 'wpum_before_registration_end', function () {
global $wpum_stop_reg_email;
$wpum_stop_reg_email = true;
} );
add_action( 'wpum_email_send_before', function () {
global $wpum_stop_reg_email;
if ( empty( $wpum_stop_reg_email ) ) {
@wp-user-manager
wp-user-manager / wpum_redirect_specific_users_after_login.php
Last active May 11, 2020 21:45
WP User Manager - Redirect different users to specific pages after login
<?php
add_filter( 'wpum_redirect_after_login', 'my_wpum_redirect_after_login', 10, 2 );
function my_wpum_redirect_after_login( $redirect, $user ) {
if ( $user->ID === 1 ) {
$redirect = home_url( '/some-url/' );
} elseif ( $user->ID === 2 ) {
$redirect = home_url( '/another-url/' );
}
@wp-user-manager
wp-user-manager / wpum_register_template_location.php
Last active June 5, 2020 12:35
WP User Manager - Register a directory for templates in plugins or other code
<?php
/**
* @param array $file_paths
*
* @return array
*/
function my_wpum_register_template_location( $file_paths ) {
$path = trailingslashit( dirname( __FILE__ ) . 'templates' );
@wp-user-manager
wp-user-manager / wpum_send_password_reset_link_in_new_user_email.php
Last active July 3, 2020 08:55
WP User Manager - Send password reset link instead of plain text password in the email sent to a new user on registration
<?php
ob_start();
// Add your restricted template content here
?>
<p>some content</p>
<?php
get_template_part( 'sometemplate' );
$output = ob_get_clean();
echo wpum_restrict_logged_in( array(), $output );
<?php
add_filter( 'wpum_admin_registration_confirmation_email_attachments', function ( $attachments, $user ) {
$field_keys = array(
'wpum_field_file_13', // TODO change to the custom field key(s)
);
foreach ( $field_keys as $field_key ) {
$file = get_user_meta( $user->ID, $field_key, true );
if ( $file ) {