Skip to content

Instantly share code, notes, and snippets.

@ultimatemember
ultimatemember / gist:cebf7407ea1c93dea904
Last active August 29, 2015 14:15
Control the output of a textfield using UM filter hooks
/*
This is a sample filter that assumes your textfield meta key is "buttoncode"
The filter below allow you to change the output dynamically
to show a shortcode instead of the value entered for that field
Use in theme functions.php and do not have to rely on UM core
*/
@ultimatemember
ultimatemember / gist:6c8d18b2b0869662d203
Last active August 29, 2015 14:15
Check when user updates e-mail via account page
add_action('um_account_pre_update_profile', 'did_user_change_email', 10, 2 );
function did_user_change_email( $changes, $user_id ) {
$data = get_userdata($user_id);
if ( isset( $changes['user_email'] ) && $data->user_email != $changes['user_email'] ) {
// user e-mail changed! Do something
}
}
@ultimatemember
ultimatemember / gist:21e10196a0b4aa493fbb
Last active August 29, 2015 14:17
Updated: Ultimate Member & bbPress Custom CSS
#bbpress-forums .bbp-forums-list li {
font-size: 12px !important;
margin: 0px 12px 0 0 !important;
}
#bbpress-forums .bbp-forums-list li a {
padding: 1px 4px;
font-size: 12px;
background: #eee;
color: #666;
display: inline-block;
@ultimatemember
ultimatemember / gist:873ae0013a15228abb70
Last active August 29, 2015 14:25
Run a specific action whenever community role is updated
add_action('um_after_user_role_is_updated', 'mycustom_role_change_action', 10, 2 );
function mycustom_role_change_action( $user_id, $new_role ) {
if ( $new_role == 'admin' ) {
die('You can not be a community admin');
}
}
@ultimatemember
ultimatemember / gist:afb94c5b66c63a34d3c1
Last active November 5, 2015 19:07
UM/EDD Open Metrics: Show recent payments
// recent payments
function sc_edd_recent_payments( $atts ) {
$p_query = new EDD_Payments_Query( array(
'number' => 12,
'status' => 'publish'
) );
$payments = $p_query->get_payments();
@ultimatemember
ultimatemember / gist:8743ef32801f7bf08c82
Created March 19, 2015 18:24
All members to automatically be WP contributors when they sign up via UM
add_action('um_after_user_is_approved', 'wp_role_contributor_after_um', 99 );
function wp_role_contributor_after_um( $user_id ) {
$wp_user_object = new WP_User( $user_id );
$wp_user_object->set_role( 'contributor' );
}
@ultimatemember
ultimatemember / gist:d1cdd1ffb04b74743c6b
Last active August 14, 2017 23:39
Sync UM role during Gravity user registration
/* This code will update the user registered with gravity
form and allow you to give him a specific UM community role */
add_action("gform_user_registered", "um_gravity_user_role_sync", 88, 4);
function um_gravity_user_role_sync($user_id, $config, $entry, $user_pass) {
update_user_meta($user_id, 'role', 'member'); // member can be your UM role slug
}
@ultimatemember
ultimatemember / gist:48bf0a269af5d182ad9b
Created May 4, 2015 19:15
UM/EDD Open Metrics: Show various sale stats
// Avg downloads per customer
function sc_edd_avg_downloads_per_customer( $atts ) {
$amount = 0;
$query = new WP_Query( array( 'post_type' => 'download' ) );
foreach( $query->posts as $post ) {
$amount = $amount + edd_get_download_sales_stats( $post->ID );
}
$amount = $amount / edd_count_total_customers();
return number_format( $amount, 2 );
}
@ultimatemember
ultimatemember / gist:02311172f7b42adeb3ed
Last active January 17, 2018 07:12
Delete display_name usermeta from all users
$users = get_users( array('fields' => 'ID') );
foreach( $users as $user_id ) {
delete_user_meta( $user_id, 'display_name' );
}
@ultimatemember
ultimatemember / gist:962dcd6eaa6db560f6c7
Last active January 26, 2018 01:18
Sync UM / WP User Role During User Approval
/* This example syncs both UM / WP role during user approval */
add_action('um_after_user_is_approved', 'sync_um_and_wp_role', 99 );
function sync_um_and_wp_role( $user_id ) {
// Get UM role
$role = get_user_meta( $user_id, 'role', true );
// Set WordPress role for same user
$wp_user_object = new WP_User( $user_id );