Skip to content

Instantly share code, notes, and snippets.

View cryptexvinci's full-sized avatar
🏆
Focusing

Towhid cryptexvinci

🏆
Focusing
  • Ultimate Member Group Ltd
  • Bangladesh
View GitHub Profile
@cryptexvinci
cryptexvinci / um-group.php
Created January 6, 2024 16:56
Ultimate Member - Adds a user to a specified group
<?php
/*
* Adds a user to a specified group with specific details, such as the group ID, user ID,
* when a user registers on a website using the Ultimate Member plugin.
*/
add_action( 'um_registration_set_extra_data', 'my_registration_set_extra_data', 10, 2 );
function my_registration_set_extra_data( $user_id, $args ) {
@cryptexvinci
cryptexvinci / update-existing-pm.php
Created April 5, 2023 02:47
Update private messaging option for all existing users.
<?php
/**
* Update private messaging option for all existing users.
* @return void
*/
function um_update_existing_users_pm_option() {
// Get all existing users.
$users = get_users();
// Loop through each user and update their private messaging option to 'friends'.
@cryptexvinci
cryptexvinci / private-message-default.php
Created April 5, 2023 02:44
Set the default value for private messaging option on user register or add.
<?php
/**
* Set the default value for private messaging option on user register or add.
* @param int $user_id The ID of the newly registered user.
* @return void
*/
function um_change_who_can_pm_default( $user_id ) {
// Set the default value for private messaging option to 'friends' for the new user.
update_user_meta( $user_id, '_pm_who_can', 'friends' );
@cryptexvinci
cryptexvinci / gist:a159a8f394e797e0ee16961c4e9e83b2
Last active March 22, 2023 04:19
Get Ultimate member Search Term or keyword
<?php
/**
* Gets the search term from the member directory search query.
*
* @return void
*/
function um_member_directory_search_term() {
// Only execute on the members page.
if ( ! um_is_core_page( 'members' ) ) {
return;
@cryptexvinci
cryptexvinci / privacy.php
Created February 28, 2023 05:32
Set Profile Privacy = "who can see profile" to Friends only
<?php
/* Set default values for privacy in new accounts
*
* Set Profile Privacy = "who can see profile" to Friends only
*/
add_action("um_registration_complete","custom_um_user_registration_complete", 1);
function custom_um_user_registration_complete( $user_id ){
update_user_meta( $user_id, "profile_privacy", "Friends only");
}
@cryptexvinci
cryptexvinci / um-custom-checkbox-output.php
Created August 3, 2022 06:23
Ultimate Member - Display checkbox output in columns
<?php
add_filter( "um_view_field_value_checkbox", "my_um_view_field_value_checkbox", 10, 2 );
function my_um_view_field_value_checkbox( $html, $data ) {
if ( $data['metakey'] != 'your_checkbox_meta_key' ) {
return $html;
}
@cryptexvinci
cryptexvinci / um-registration-email.php
Created August 3, 2022 05:28
Ultimate Member Registration - List "disallowed" domain extensions such as .ru and .in
<?php
add_action( 'um_submit_form_errors_hook__registration', 'um_custom_validate_username', 99 );
function um_custom_validate_username( $args ) {
static $domain = '.in, .ru';
if ( isset( $args['user_email'] ) ) {
if ( str_ends_with( $args['user_email'], '.in' ) || str_ends_with( $args['user_email'], '.ru' )) {
$message = sprintf( __( 'Cant use email domain %1$s for registration', 'ultimate-member' ), $domain );
@cryptexvinci
cryptexvinci / um-after-post-profile.php
Created March 29, 2022 04:47
display the user profile like at the end of the blog post where I only have to change the user id.
<?php
/*
Code snippet of Plugin Ultimate Member
URL: https://wordpress.org/plugins/ultimate-member/
*/
// Display field data of Ultimate Member
// e.g. [um_field_data userid='24']
@cryptexvinci
cryptexvinci / um_user_column_backend.php
Created January 21, 2022 03:28
Add custom Ultimate member fields Column to Users list table on WordPress
<?php
// Display UM Country Column Label
function um_add_meta_user_table( $column ) {
$column['country'] = 'Country';
return $column;
}
add_filter( 'manage_users_columns', 'um_add_meta_user_table' );
@cryptexvinci
cryptexvinci / mail-role-change.php
Created August 31, 2021 10:27
Ultimate Member - Send Welcome Email after Role Change.
<?php
add_action( 'um_after_member_role_upgrade', 'my_um_after_member_role_upgrade', 10, 3 );
function my_um_after_member_role_upgrade( $hook_roles, $old_roles, $user_id ){
$user = get_userdata( $user_id );
UM()->mail()->send( $user->user_email, 'welcome_email' );
}