Skip to content

Instantly share code, notes, and snippets.

@pragmatic-web
Last active June 7, 2023 10:08
Show Gist options
  • Save pragmatic-web/9352466 to your computer and use it in GitHub Desktop.
Save pragmatic-web/9352466 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' );
@LeighJeffery
Copy link

LeighJeffery commented Jul 29, 2018

Hi David,

Thank you for sharing:D I was wondering if anyone knows why the code is displaying like this?

https://www.screencast.com/t/6Ua2lvYaNMZO

I have the Twitter field filled in and the icon png file uploaded.

Any help would be appreciated. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment