Skip to content

Instantly share code, notes, and snippets.

View yuriinalivaiko's full-sized avatar

Yurii Nalivaiko yuriinalivaiko

View GitHub Profile
@yuriinalivaiko
yuriinalivaiko / investigate_redirect.php
Last active August 22, 2023 21:17
Investigate WordPress redirect.
<?php
/**
* Add the code below to the functions.php file, reproduce the redirect you want to investigate then remove this code.
* Look at the debug.log file. You will see detailed information about the redirect.
*
* Note: Enable debug logging first. See https://docs.ultimatemember.com/article/1751-enable-debug-logging
*/
add_filter( 'wp_redirect', function( $location, $status ) {
@yuriinalivaiko
yuriinalivaiko / um_wpseo_sitemaps_users.php
Last active June 16, 2023 18:59
This code snippet adds all approved users whose Ultimate Member profiles are public to the sitemap generated by Yoast SEO plugin.
<?php
/**
* Add all approved users whose Ultimate Member profiles are public to the sitemap.
*/
add_filter( 'wpseo_sitemap_entry', 'um_wpseo_sitemap_entry', 10, 3 );
add_filter( 'wpseo_sitemap_exclude_author', 'um_wpseo_sitemaps_users' );
/**
@yuriinalivaiko
yuriinalivaiko / um_user_locations_map_args_customize_05.php
Last active October 26, 2023 11:31
This code snippet uses the Map ID to customize the map styles in the User Locations extension.
<?php
/**
* Use Map ID to customize the user location map.
*/
add_action( 'wp_footer', function () {
?><script type="text/javascript">
function um_user_locations_customize_mapId( args, hash, directory ) {
args.mapId = 'YOUR_MAP_ID';
@yuriinalivaiko
yuriinalivaiko / um_user_locations_marker_data.php
Last active October 26, 2023 11:32
This code snippet changes the map marker in the User Locations extension.
<?php
/**
* Change the map marker title and image.
*/
add_action( 'wp_footer', function () {
?><script type="text/javascript">
wp.hooks.addFilter('um_user_locations_marker_data', 'um_user_locations', function (marker_data, hash, userdata) {
// Change the map marker title.
@yuriinalivaiko
yuriinalivaiko / um_member_directory_disable_clustering.php
Last active October 26, 2023 11:30
This code snippet disables the map marker clustering in the User Locations extension.
<?php
/**
* Disable Clustering
*/
add_action( 'wp_footer', function () {
?><script type="text/javascript">
wp.hooks.addFilter( 'um_member_directory_disable_clustering', 'um_user_locations', function ( disableClustering, directory ) {
disableClustering = true;
return disableClustering;
@yuriinalivaiko
yuriinalivaiko / um_woocommerce_subscription_status_changed_remove_old_roles.php
Last active May 1, 2023 17:58
This code removes all old user roles if a new user role is assigned when subscription status is changed.
<?php
// Remove all old roles on subscription status change.
function um_woocommerce_subscription_status_changed_remove_old_roles( $subscription_id, $old_status, $new_status ) {
global $wpdb;
if ( ! UM()->WooCommerce_API()->api()->is_wc_subscription_plugin_active() ) {
return;
}
@yuriinalivaiko
yuriinalivaiko / um_account_custom_tabs.php
Last active June 4, 2023 17:43
This code adds the 'custom_tab_01' tab with fields 'um_pet', 'um_colors', 'um_multi_select' to the account menu in Ultimate Member. You can add your own tabs and fields.
<?php
/**
* Add custom tabs.
*
* @param array $tabs Account tabs.
* @return array
*/
function um_account_custom_tabs( $tabs ) {
$tabs[ 150 ][ 'custom_tab_01' ] = array(
@yuriinalivaiko
yuriinalivaiko / um_profile_header_shortcode.php
Last active December 6, 2023 12:54
This code adds a shortcode that displays the header section of the Ultimate Member profile.
<?php
/**
* Shortcode that displays the profile header.
* Example: [um_profile_header form_id="7" user_id="1"]
*
* @global \wpdb $wpdb
*
* @param array $atts Shortcode attributes:
* - (int) form_id - profile form ID. The first profile form if blank.
@yuriinalivaiko
yuriinalivaiko / um_email_notification_unverify_user.php
Last active June 4, 2023 21:49
This code adds custom email template "Verified Users - Account is not verified E-mail" to be used in the "Ultimate Member - Verified Users" extension.
<?php
if ( ! function_exists( 'um_email_locate_template' ) ) {
/**
* Locate a template and return the path for inclusion.
*/
function um_email_locate_template( $template_name ) {
$blog_id = is_multisite() ? '/' . get_current_blog_id() : '';
$template = locate_template(
@yuriinalivaiko
yuriinalivaiko / custom_field_validation_user_email.php
Created January 15, 2023 19:36
This code changes an error message for the E-mail Address field in the registration form
<?php
/**
* Custom validation and error message for the E-mail Address field.
*/
add_action( 'um_custom_field_validation_user_email_details', 'um_custom_validate_user_email_details', 999, 3 );
function um_custom_validate_user_email_details( $key, $array, $args ) {
if ( $key == 'user_email' && isset( $args['user_email'] ) ) {
if ( isset( UM()->form()->errors['user_email'] ) ) {
unset( UM()->form()->errors['user_email'] );