Skip to content

Instantly share code, notes, and snippets.

@ultimatemember
ultimatemember / gist:66259b3282b232a5b447
Last active January 18, 2023 04:52
Private Messages API: Get number of unread messages for a user
global $um_messaging;
$user_id = 'xx'; // enter user id here
$count = $um_messaging->api->get_unread_count( $user_id );
echo $count;
@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:643cd90967e5e415378d
Last active June 20, 2020 21:32
Custom profile tab example: showing user pages
/* add a custom tab to show user pages */
add_filter('um_profile_tabs', 'pages_tab', 1000 );
function pages_tab( $tabs ) {
$tabs['pages'] = array(
'name' => 'Pages',
'icon' => 'um-faicon-pencil',
'custom' => true
);
return $tabs;
}
@ultimatemember
ultimatemember / gist:78aac8b268b2c75489f0
Last active September 13, 2022 11:58
Apply your own custom validation to a field
/*
In this code sample, you can learn how to apply custom
validations on any fields you want.
This can be done using these steps:
1. Edit the field in backend (field modal)
2. Where it asks for field validation choose "Custom"
3. Enter a unique validation action name e.g. my_8numbers
@ultimatemember
ultimatemember / gist:5f725bff6bcf79d2988e
Last active January 22, 2020 19:00
Using notifications API to add custom notifications
/*
This code sample shows you how to use the API to create
and add custom notifications (for real-time notifications)
plugin.
STEP 1: You need to extend the filter: um_notifications_core_log_types with your
new notification type as follows for example
*/
@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: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:44d89249baf9f73b89d6
Last active December 21, 2020 15:08
Using the new RESTful API to process remote queries
// API Request
$url = 'http://localhost/um-api/get.user/?id=1';
// Include your public key and token to the URL
$url = add_query_arg('key', '75d9a913782eee3d990e4464ce26213e', $url );
$url = add_query_arg('token', 'bae6ee38cf02a50a0ac8259eed34ceb9', $url );
// Process your request
$request = wp_remote_get( $url );
$response = json_decode( wp_remote_retrieve_body( $request ) , true );
@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: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;