Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Created August 28, 2023 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriinalivaiko/4b946c53942f208eb312fe9d1262410c to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/4b946c53942f208eb312fe9d1262410c to your computer and use it in GitHub Desktop.
This code adds a button for each member on the member directory and also on the user profile.
<?php
/**
* Change the $href variable to an URL that navigates to a page you need
* and change the $title variable to a button text you need
* then add this code to the functions.php file in the theme directory.
*/
// Add a custom button (link) on user profile.
function um_custom_button_in_profile( $args ) {
$href = home_url( '' );
$title = 'Custom form';
?>
<div class="um-profile-custom-btn">
<a href="<?php echo esc_attr( $href ); ?>" class="um-custom-btn um-button"><?php echo esc_html( $title ); ?></a>
</div>
<?php
}
add_action( 'um_profile_navbar', 'um_custom_button_in_profile', 4 );
// Add a custom button (link) for each member on member directory.
function um_custom_button_in_member_directory( $args ) {
$href = home_url( '' );
$title = 'Custom form';
?>
<div class="um-members-custom-btn">
<a href="<?php echo esc_attr( $href ); ?>" class="um-custom-btn um-button"><?php echo esc_html( $title ); ?></a>
</div>
<?php
}
add_action( 'um_members_just_after_name_tmpl', 'um_custom_button_in_member_directory', 110, 1 ); // for grid.
add_action( 'um_members_list_just_after_actions_tmpl', 'um_custom_button_in_member_directory', 110, 1 ); // for list.
// Style a custom button.
function um_custom_button_styles() {
?>
<style type="text/css">
.um-profile .um-profile-custom-btn {
float: right;
margin: 0px 0px 0px 5px;
}
.um-profile a.um-custom-btn {
padding: 10px 15px !important;
}
.um-members.um-members-grid a.um-custom-btn {
display: inline-block !important;
font-size: 13px;
margin: 0 auto !important;
min-width: 110px;
padding: 10px 15px !important;
text-align: center;
transition: none !important;
width: auto;
}
.um-members.um-members-list a.um-custom-btn {
font-size: 13px;
padding: 10px 15px !important;
}
</style>
<?php
}
add_action( 'wp_footer', 'um_custom_button_styles' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment