Skip to content

Instantly share code, notes, and snippets.

View yuriinalivaiko's full-sized avatar

Yurii Nalivaiko yuriinalivaiko

View GitHub Profile
@yuriinalivaiko
yuriinalivaiko / um_custom_validate_birth_date.php
Last active October 6, 2022 19:34
This code snippet restricts registration for under 18 years old using the custom validation applied to the Birth Date field. You can add this code to the functions.php file in the active theme directory.
<?php
/**
* Restrict registration for under 18 years old.
*
* @param array $args Form Arguments.
*/
function um_custom_validate_birth_date( $args ) {
if ( ! empty( $args['birth_date'] ) ) {
// Birth date as a Unix timestamp.
@yuriinalivaiko
yuriinalivaiko / um_add_vcard_file_types.php
Last active October 28, 2022 13:48
This code snippet extends the "File upload" field type to allow the vCard (also known as VCF) file types.
<?php
/**
* Allow to upload vCard files via the "File Upload" field type.
* Add this code to the file functions.php in the active theme directory.
*/
function um_add_vcard_file_types( $allowed_types ) {
if( is_array( $allowed_types ) ) {
$vcard_types = array(
@yuriinalivaiko
yuriinalivaiko / hide_unapproved_members.php
Last active November 1, 2022 10:34
This code snippet hides unapproved members in the members directory.
<?php
/**
* Hide unapproved members in the members directory for everybody.
*/
add_action( 'um_member_directory_before_query', function() {
add_filter( 'um_user_permissions_filter', 'custom_disable_permission_can_edit_everyone' );
} );
function custom_disable_permission_can_edit_everyone( $permissions ) {
$permissions['can_edit_everyone'] = false;
@yuriinalivaiko
yuriinalivaiko / customize_email_error_message.php
Last active November 1, 2022 11:21
This code snippet changes the validation error messages in the registration form if user exists.
<?php
/**
* Customize registration error message.
*/
add_action( 'um_submit_form_errors_hook', function( $args ) {
if ( isset( $args['mode'] ) && 'register' === $args['mode'] ) {
if ( isset( $args['user_email'] ) && email_exists( $args['user_email'] ) ) {
UM()->form()->add_error( 'user_email', __( 'There is already an account with that email', 'ultimate-member' ) );
}
@yuriinalivaiko
yuriinalivaiko / login hooks.php
Created November 3, 2022 11:00
Login hooks examples
<?php
/**
* Hook: um_login_form_button_one
*
* Type: filter
*
* Description: Change the Login Form primary button text.
*
* @example https://github.com/ultimatemember/ultimatemember/blob/master/includes/core/um-actions-login.php#L358
@yuriinalivaiko
yuriinalivaiko / um_core_form_meta_all.php
Created November 4, 2022 11:49
Hook um_core_form_meta_all
<?php
/**
* Hook: um_core_form_meta_all
*
* Type: filter
*
* Description: Extend UM forms meta keys.
*
* @example https://github.com/ultimatemember/ultimatemember/blob/master/includes/class-config.php#L230
@yuriinalivaiko
yuriinalivaiko / um_admin_custom_login_metaboxes.php
Created November 4, 2022 11:50
Hook um_admin_custom_login_metaboxes
<?php
/**
* Hook: um_admin_custom_login_metaboxes
*
* Type: action
*
* Description: Add custom metaboxes for the Login Form type.
*
* @example https://github.com/ultimatemember/ultimatemember/blob/master/includes/admin/core/class-admin-metabox.php#L1040
@yuriinalivaiko
yuriinalivaiko / um_render_field_type.php
Created November 4, 2022 11:52
Hook um_render_field_type_{$type}
<?php
/**
* Hook: um_render_field_type_{$type}
*
* Type: filter
*
* Description: Change admin form field layout by $type.
*
* @example https://github.com/ultimatemember/ultimatemember/blob/master/includes/admin/core/class-admin-forms.php#L312
@yuriinalivaiko
yuriinalivaiko / um_admin_pre_save_field_to_form.php
Created November 4, 2022 11:54
Hook um_admin_pre_save_field_to_form
<?php
/**
* Hook: um_admin_pre_save_field_to_form
*
* Type: filter
*
* Description: Change field data before save to form.
*
* @example https://github.com/ultimatemember/ultimatemember/blob/master/includes/admin/core/class-admin-builder.php#L725
@yuriinalivaiko
yuriinalivaiko / um_before_mode_form_is_loaded.php
Created November 4, 2022 11:59
Hook um_before_{$mode}_form_is_loaded
<?php
/**
* Hook: um_before_{$mode}_form_is_loaded
*
* Type: action
*
* Description: Fires before the form shortcode is loaded.
*
* @example https://github.com/ultimatemember/ultimatemember/blob/master/includes/core/class-shortcodes.php#L792