Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Display user country flag

@davehakkens

Participant

OK, we got it to work in a different way. Special thanks to @coffeywebdev for the help.
For those interested:

This snippet is used in the functions.php to get the locations from the profile fields and show the flag image.

function dh_get_flag_by_location($country){
  if($country <> '' && !empty($country)){
  $country_filename = get_stylesheet_directory_uri() . '/img/flags/' . sanitize_file_name($country) . '.png';
  $country_path = get_stylesheet_directory() . '/img/flags/' . sanitize_file_name($country). '.png';    
     if(file_exists($country_path)){
       $html = '<img src="' . $country_filename . '"/>';
     } else {
       $html = $country;
       echo '<!--' . get_stylesheet_directory_uri() . '/img/flags/' . sanitize_file_name($country) . '-->';
    }
  echo $html;
  }
}

Then we needed to change 2 templates to show this flag image in
the Bbpress forum replies and on the buddypress members page. So we added the code necessary to show the flag
bbpress/loop-single-reply.php
<div id="country" style="float:left;margin-right:.5em;"> <?php $user = get_userdata( bbp_get_reply_author_id() ); $country = xprofile_get_field_data( 42, $user->ID ); dh_get_flag_by_location($country); ?></div>

buddypress/members/members-loop.php
<div class="member-location"> <?php $country = bp_get_member_profile_data('field=Location'); dh_get_flag_by_location($country); ?></div>

Skip to toolbar