Skip to content

Instantly share code, notes, and snippets.

@ultimatemember
ultimatemember / gist:08c7f3369f49021cb749
Last active April 4, 2018 14:20
How to stop registration using Ultimate Member action hooks
/*
You need to hook into um_submit_form_errors_hook with a
priority over 10.
You can stop registration here if the customer_code field does not
match the value you want "ALLOWED_VALUE" in this example
*/
@ultimatemember
ultimatemember / gist:296161825d8127fa28fc
Last active February 28, 2018 15:59
Stop registration if customer_code field does not equal ABCDE
add_action('um_submit_form_errors_hook', 'check_customer_code', 100 );
function check_customer_code( $args ){
if ( isset( $args['customer_code'] ) && $args['customer_code'] != 'ABCDE' )
exit( wp_redirect( add_query_arg('err', 'invalid_customer_code') ) );
}
@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 );
@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: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: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: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: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: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: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;