Skip to content

Instantly share code, notes, and snippets.

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 itsjusteileen/81f9f97a7ef507dcb2e7b6c931e7d269 to your computer and use it in GitHub Desktop.
Save itsjusteileen/81f9f97a7ef507dcb2e7b6c931e7d269 to your computer and use it in GitHub Desktop.
<?php
// http://stackoverflow.com/questions/7952977/php-check-if-url-and-a-file-exists
function is_200($url) {
$options['http'] = array(
'method' => "HEAD",
'ignore_errors' => 1,
'max_redirects' => 0
);
$body = file_get_contents($url, NULL, stream_context_create($options));
sscanf($http_response_header[0], 'HTTP/%*d.%*d %d', $code);
return $code === 200;
}
// Social Media Icons based on the profile user info
function member_social_extend(){
$dmember_id = $bp->displayed_user->id;
$profiles = array(
'Website',
'Email',
'Twitter',
'Facebook profile',
'Facebook page',
'Google+',
'Vimeo',
'LinkedIn',
'Kickstarter',
'Behance',
'Custom web link'
);
$profiles_data = array();
foreach( $profiles as $profile ) {
$profile_content = '';
$profile_content = xprofile_get_field_data( $profile, $dmember_id );
if ( !empty( $profile_content ) ) {
$profiles_data[ $profile ] .= $profile_content;
}
}
echo '<div class="member-social">';
if( !( empty( $profiles_data ) ) ) {
echo '<h3>Find me online:</h3>';
echo '<ul class="social-icons">';
while ( list( $key, $value ) = each( $profiles_data ) ) {
$profile_icon_uri = get_stylesheet_directory_uri() . '/assets/images/' . sanitize_title( $key ) . '.png';
$profile_icon_uri_exists = is_200( $profile_icon_uri );
$default_profile_icon_uri = get_stylesheet_directory_uri() . '/assets/images/custom-web-link.png';
if( $profile_icon_uri_exists ) {
$profile_icon = $profile_icon_uri;
} else {
$profile_icon = $default_profile_icon_uri;
}
echo '<a href="' . $value . '" title="' . $key . '" target="_blank"><img src="' . $profile_icon . '" /></a>';
}
echo '<ul class="social-icons">';
echo '</div>';
}
}
add_filter( 'bp_before_member_header_meta', 'member_social_extend' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment