Skip to content

Instantly share code, notes, and snippets.

View nikitasinelnikov's full-sized avatar

Mykyta Synelnikov nikitasinelnikov

  • ultimatemember.com
  • Kharkiv, Ukraine
View GitHub Profile
@nikitasinelnikov
nikitasinelnikov / Extending Ultimate Member Profile Menu using Hooks
Created November 28, 2017 08:49
This functions will create "My custom tab" at user's profile menu
/* First we need to extend main profile tabs */
add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {
$tabs['mycustomtab'] = array(
'name' => 'My custom tab',
'icon' => 'um-faicon-comments',
'custom' => true,
);
@nikitasinelnikov
nikitasinelnikov / hide current user from all member directories
Created December 1, 2017 10:48
Ultimate Member Hide current user profile from Member Directory using Hooks
add_filter( 'um_prepare_user_query_args', 'um_remove_current_user_from_list', 100, 2 );
function um_remove_current_user_from_list( $query_args, $args ) {
if ( is_user_logged_in() ) {
if ( ! empty( $query_args['exclude'] ) )
$query_args['exclude'] = array_merge( $query_args['exclude'], array( get_current_user_id() ) );
else
$query_args['exclude'] = array( get_current_user_id() );
}
return $query_args;
@nikitasinelnikov
nikitasinelnikov / gist:c8590b873ca34f492ceac0c0be9f325e
Created April 23, 2018 11:32
Restrict Login Page for logged in user
add_action( 'template_redirect', 'um_restrict_login_page_logged_in' );
function um_restrict_login_page_logged_in() {
if ( um_is_core_page('login') && is_user_logged_in() ) {
wp_redirect( um_get_core_page( 'user' ) );
exit;
}
}
@nikitasinelnikov
nikitasinelnikov / gist:46302171ecf43e7130581dfa5a76850d
Created April 25, 2018 12:13
Display All users not only Authors
add_filter( 'wp_dropdown_users_args', 'um_show_all_users', 10, 2 );
function um_show_all_users( $query_args, $r ) {
if ( isset( $query_args['who'] ) && 'authors' == $query_args['who'] ) {
$query_args['who'] = '';
}
return $query_args;
}
@nikitasinelnikov
nikitasinelnikov / Redirect from WP native login form
Created June 7, 2018 06:53
Create redirect from WP native login form to UM login form
/**
* Replace login page URL to UM login page
* @param string $login_url
* @param string $redirect
* @return string
*/
function um_login_url( $login_url, $redirect ){
$page_id = UM()->options()->get( 'core_login' );
if ( get_post( $page_id ) ) {
$login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), get_permalink( $page_id ) );
function um_custom_disable_redirect( $post_ID, $post_after, $post_before ) {
$post_obj = get_post( $post_ID );
if ( isset( $post_obj->post_type ) && 'um_activity' == $post_obj->post_type ) {
add_filter( 'wpseo_premium_post_redirect_slug_change', function( $bool ) {
return true;
}, 10, 1 );
}
}
add_action( 'post_updated', 'um_custom_disable_redirect', 10, 3 );
@nikitasinelnikov
nikitasinelnikov / UM Email Templates
Created June 20, 2018 15:34
Custom Body Attributes
add_filter( 'um_email_template_body_attrs', 'my_body_template', 10, 2 );
function my_body_template( $slug, $args ) {
return 'style="-webkit-text-size-adjust: none;-ms-text-size-adjust: none; margin: 0; padding: 0; width: 100%;"';
}
@nikitasinelnikov
nikitasinelnikov / UM Custom Email Templates
Created June 20, 2018 15:39
um_email_template_html_formatting
add_filter( 'um_email_template_html_formatting', 'my_email_template_html', 10, 2 );
function my_email_template_html( $slug, $args ) {
ob_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--[if gte mso 15]>
<xml>
<o:OfficeDocumentSettings>
@nikitasinelnikov
nikitasinelnikov / Woo:Subscriptions change role
Created June 21, 2018 21:11
Disable role changing by Woo:Subscriptions
add_filter( 'woocommerce_subscriptions_update_users_role', 'my_custom_disable_wcs_role_change', 10, 3 );
function my_custom_disable_wcs_role_change( $enable, $user, $role_new ) {
return false;
}
$posts = get_posts( array(
'numberposts' => -1,
'post_type' => 'any',
'post_status' => 'publish'
) );
foreach ( $posts as $post ) {
$content = preg_replace_callback( "/(\[um_show_content roles=\')(.*?)(\'\])/im", "um_custom_change_show_content_roles", $post->post_content );
$post->post_content = $content;