Last active
January 24, 2020 14:34
-
-
Save nikitasinelnikov/44d957966691f43a5d8cf8037838eb46 to your computer and use it in GitHub Desktop.
Member Directory different templates based on members.php file's copies with different headers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* For this snippet | |
members2.php - custom Member Directory template filename in "wp-content/themes/your-theme/ultimate-member/templates/" path. | |
members-grid2.php - custom Grid template, customized only for members2.php template, its path is "wp-content/themes/your-theme/ultimate-member/members-grid2.php" | |
*/ | |
add_filter( 'um_get_template', 'my_member_directory_templates', 10, 4 ); | |
function my_member_directory_templates( $located, $template_name, $path, $t_args ) { | |
if ( $template_name == 'members-grid.php' ) { | |
if ( ! empty( $t_args['template'] ) && $t_args['template'] == 'members2' ) { | |
if ( ! empty( $t_args ) && is_array( $t_args ) ) { | |
extract( $t_args ); | |
} | |
$path = ''; | |
$basename = UM()->member_directory()->get_type_basename( 'grid' ); | |
if ( $basename ) { | |
// use '/' instead of "DIRECTORY_SEPARATOR", because wp_normalize_path makes the correct replace | |
$array = explode( '/', wp_normalize_path( trim( $basename ) ) ); | |
$path = $array[0]; | |
} | |
$template_name = 'members-grid2.php'; | |
$located_custom = UM()->locate_template( $template_name, $path ); | |
if ( ! file_exists( $located_custom ) ) { | |
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); | |
return $located; | |
} | |
$located = $located_custom; | |
} | |
} | |
return $located; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment