array(
'default' => __('Like', 'buddypress-like'),
'custom' => __('Like', 'buddypress-like')
),
'unlike' => array(
'default' => __('Unlike', 'buddypress-like'),
'custom' => __('Unlike', 'buddypress-like')
),
'like_this_item' => array(
'default' => __('Like this item', 'buddypress-like'),
'custom' => __('Like this item', 'buddypress-like')
),
'unlike_this_item' => array(
'default' => __('Unlike this item', 'buddypress-like'),
'custom' => __('Unlike this item', 'buddypress-like')
),
'view_likes' => array(
'default' => __('View likes', 'buddypress-like'),
'custom' => __('View likes', 'buddypress-like')
),
'hide_likes' => array(
'default' => __('Hide likes', 'buddypress-like'),
'custom' => __('Hide likes', 'buddypress-like')
),
'show_activity_likes' => array(
'default' => __('Show Activity Likes', 'buddypress-like'),
'custom' => __('Show Activity Likes', 'buddypress-like')
),
'show_blogpost_likes' => array(
'default' => __('Show Blog Post Likes', 'buddypress-like'),
'custom' => __('Show Blog Post Likes', 'buddypress-like')
),
'must_be_logged_in' => array(
'default' => __('Sorry, you must be logged in to like that.', 'buddypress-like'),
'custom' => __('Sorry, you must be logged in to like that.', 'buddypress-like')),
'record_activity_likes_own' => array(
'default' => __('%user% likes their own activity', 'buddypress-like'),
'custom' => __('%user% likes their own activity', 'buddypress-like')
),
'record_activity_likes_an' => array(
'default' => __('%user% likes an activity', 'buddypress-like'),
'custom' => __('%user% likes an activity', 'buddypress-like')
),
'record_activity_likes_users' => array(
'default' => __('%user% likes %author%\'s activity', 'buddypress-like'),
'custom' => __('%user% likes %author%\'s activity', 'buddypress-like')
),
'record_activity_likes_own_blogpost' => array(
'default' => __('%user% likes their own blog post, %title%', 'buddypress-like'),
'custom' => __('%user% likes their own blog post, %title%', 'buddypress-like')
),
'record_activity_likes_a_blogpost' => array(
'default' => __('%user% likes a blog post, %title%', 'buddypress-like'),
'custom' => __('%user% likes an blog post, %title%', 'buddypress-like')
),
'record_activity_likes_users_blogpost' => array(
'default' => __('%user% likes %author%\'s blog post, %title%', 'buddypress-like'),
'custom' => __('%user% likes %author%\'s blog post, %title%', 'buddypress-like')
),
'get_likes_no_likes' => array(
'default' => __('Nobody likes this yet.', 'buddypress-like'),
'custom' => __('Nobody likes this yet.', 'buddypress-like')
),
'get_likes_only_liker' => array(
'default' => __('You are the only person who likes this so far.', 'buddypress-like'),
'custom' => __('You are the only person who likes this so far.', 'buddypress-like')
),
'get_likes_you_and_singular' => array(
'default' => __('You and %count% other person like this.', 'buddypress-like'),
'custom' => __('You and %count% other person like this.', 'buddypress-like')
),
'get_likes_you_and_plural' => array(
'default' => __('You and %count% other people like this', 'buddypress-like'),
'custom' => __('You and %count% other people like this', 'buddypress-like')
),
'get_likes_count_people_singular' => array(
'default' => __('%count% person likes this.', 'buddypress-like'),
'custom' => __('%count% person likes this.', 'buddypress-like')
),
'get_likes_count_people_plural' => array(
'default' => __('%count% people like this.', 'buddypress-like'),
'custom' => __('%count% people like this.', 'buddypress-like')
),
'get_likes_and_people_singular' => array(
'default' => __('and %count% other person like this.', 'buddypress-like'),
'custom' => __('and %count% other person like this.', 'buddypress-like')
),
'get_likes_and_people_plural' => array(
'default' => __('and %count% other people like this.', 'buddypress-like'),
'custom' => __('and %count% other people like this.', 'buddypress-like')
),
'get_likes_likes_this' => array(
'default' => __('likes this.', 'buddypress-like'),
'custom' => __('likes this.', 'buddypress-like')
),
'get_likes_like_this' => array(
'default' => __('like this.', 'buddypress-like'),
'custom' => __('like this.', 'buddypress-like')
),
'get_likes_no_friends_you_and_singular' => array(
'default' => __('None of your friends like this yet, but you and %count% other person does.', 'buddypress-like'),
'custom' => __('None of your friends like this yet, but you and %count% other person does.', 'buddypress-like')
),
'get_likes_no_friends_you_and_plural' => array(
'default' => __('None of your friends like this yet, but you and %count% other people do.', 'buddypress-like'),
'custom' => __('None of your friends like this yet, but you and %count% other people do.', 'buddypress-like')
),
'get_likes_no_friends_singular' => array(
'default' => __('None of your friends like this yet, but %count% other person does.', 'buddypress-like'),
'custom' => __('None of your friends like this yet, but %count% other person does.', 'buddypress-like')
),
'get_likes_no_friends_plural' => array(
'default' => __('None of your friends like this yet, but %count% other people do.', 'buddypress-like'),
'custom' => __('None of your friends like this yet, but %count% other people do.', 'buddypress-like')
)
);
$current_settings = get_site_option('bp_like_settings');
if ( $current_settings['post_to_activity_stream'] )
$post_to_activity_stream = $current_settings['post_to_activity_stream'];
else
$post_to_activity_stream = 1;
if ( $current_settings['show_excerpt'] )
$show_excerpt = $current_settings['show_excerpt'];
else
$show_excerpt = 0;
if ( $current_settings['excerpt_length'] )
$excerpt_length = $current_settings['excerpt_length'];
else
$excerpt_length = 140;
if ( $current_settings['likers_visibility'] )
$likers_visibility = $current_settings['likers_visibility'];
else
$likers_visibility = 'show_all';
if ( $current_settings['name_or_avatar'] )
$name_or_avatar = $current_settings['name_or_avatar'];
else
$name_or_avatar = 'name';
if ( $current_settings['text_strings'] ) :
$current_text_strings = $current_settings['text_strings'];
/* Go through each string and update the default to the current default, keep the custom settings */
foreach( $default_text_strings as $string_name => $string_contents ) :
$default = $default_text_strings[$string_name]['default'];
$custom = $current_settings['text_strings'][$string_name]['custom'];
if ( empty( $custom ) )
$custom = $default;
$text_strings[$string_name] = array('default' => $default, 'custom' => $custom);
endforeach;
else :
$text_strings = $default_text_strings;
endif;
$settings = array(
'likers_visibility' => $likers_visibility,
'post_to_activity_stream' => $post_to_activity_stream,
'show_excerpt' => $show_excerpt,
'excerpt_length' => $excerpt_length,
'text_strings' => $text_strings,
'name_or_avatar' => $name_or_avatar
);
update_site_option( 'bp_like_db_version', BP_LIKE_DB_VERSION );
update_site_option( 'bp_like_settings', $settings );
add_action( 'admin_notices', 'bp_like_updated_notice' );
}
/* The notice we show when the plugin is installed. */
function bp_like_install_buddypress_notice() {
echo '
';
}
/* The notice we show if the plugin is updated. */
function bp_like_updated_notice() {
if ( !is_site_admin() )
return false;
echo '
';
printf(__('BuddyPress Like has been successfully updated to version %s.', 'buddypress-like'), BP_LIKE_VERSION);
echo '
';
}
/**
* bp_like_check_installed()
*
* Checks to see if the DB tables exist or if you are running an old version
* of the component. If it matches, it will run the installation function.
* This means we don't have to deactivate and then reactivate.
*
*/
function bp_like_check_installed() {
global $wpdb;
if ( !is_site_admin() )
return false;
if ( !get_site_option( 'bp_like_settings' ) || get_site_option( 'bp-like-db-version' ) )
bp_like_install();
if ( get_site_option( 'bp_like_db_version' ) < BP_LIKE_DB_VERSION )
bp_like_install();
}
add_action( 'admin_menu', 'bp_like_check_installed' );
// Hack: make the admin work in wp 3.1 and bp 1.2.8
add_action( 'network_admin_menu', 'bp_like_check_installed' );
//add_action( 'admin_menu', 'bp_like_check_installed' );
/**
* Hack: bp_like_setup_globals()
*
*
* Sets up a Buddypress component to add notifications
*
*/
function bp_like_setup_globals() {
global $bp, $wpdb;
/* For internal identification */
$bp->bp_like->id = 'bp-like';
$bp->bp_like->format_notification_function = 'bp_like_format_notifications';
$bp->bp_like->slug = 'bp-like';
/* Register this in the active components array */
$bp->active_components[$bp->bp_like->slug] = $bp->bp_like->id;
}
add_action( 'bp_setup_globals', 'bp_like_setup_globals' );
/**
* Hack: bp_like_format_notifications()
*
*
* Sets up notifications format
*
*/
function bp_like_format_notifications( $action, $item_id, $secondary_item_id, $total_items) {
global $bp;
switch ( $action ) {
case 'new_bp_like':
/***
* We don't want a whole list of similar notifications in a users list, so we group them.
* If the user has more than one action from the same component, they are counted and the
* notification is rendered differently.
*/
if ( (int)$total_items > 1 ) {
$user_fullname = bp_core_get_user_displayname( $item_id, false );
$user_url = bp_core_get_userlink( $item_id, false, true );
return apply_filters( 'bp_like_notification', '' . sprintf( __( 'multiple people liked something of yours', 'bp-like' ), $user_fullname ) . '', $user_fullname );
return apply_filters( 'bp_like_notification_multiple', 'Many people liked this!' );
} else {
$user_fullname = bp_core_get_user_displayname( $item_id, false );
$user_url = bp_core_get_userlink( $item_id, false, true );
return apply_filters( 'bp_like_notification', '' . sprintf( __( '%s liked something of yours', 'bp-like' ), $user_fullname ) . '', $user_fullname );
return apply_filters( 'bp_like_notification_single', 'Someone liked this!' );
}
break;
}
do_action( 'bp_like_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
return false;
}
/**
* bp_like_get_settings()
*
* Returns settings from the database
*
*/
function bp_like_get_settings( $option = false ) {
$settings = get_site_option( 'bp_like_settings' );
if (!$option)
return $settings;
else
return $settings[$option];
}
/**
* bp_like_get_text()
*
* Returns a custom text string from the database
*
*/
function bp_like_get_text( $text = false, $type = 'custom' ) {
$settings = get_site_option( 'bp_like_settings' );
$text_strings = $settings['text_strings'];
$string = $text_strings[$text];
return $string[$type];
}
/**
* bp_like_process_ajax()
*
* Runs the relevant function depending on what Ajax call has been made.
*
*/
function bp_like_process_ajax() {
global $bp;
$id = preg_replace( "/\D/", "", $_POST['id'] );
if ( $_POST['type'] == 'like' )
bp_like_add_user_like( $id, 'activity' );
if ( $_POST['type'] == 'unlike' )
bp_like_remove_user_like( $id, 'activity' );
if ( $_POST['type'] == 'view-likes' )
bp_like_get_likes( $id, 'blogpost' );
if ( $_POST['type'] == 'like_blogpost' )
bp_like_add_user_like( $id, 'blogpost' );
if ( $_POST['type'] == 'unlike_blogpost' )
bp_like_remove_user_like( $id, 'blogpost' );
die();
}
add_action( 'wp_ajax_activity_like', 'bp_like_process_ajax' );
/**
* bp_like_is_liked()
*
* Checks to see whether the user has liked a given item.
*
*/
function bp_like_is_liked( $item_id = '', $type = '', $user_id = '' ) {
global $bp;
if ( !$type )
return false;
if ( !$item_id )
return false;
if ( !$user_id )
$user_id = $bp->loggedin_user->id;
if ( $type == 'activity' )
$user_likes = get_user_meta( $user_id, 'bp_liked_activities', true );
if ( $type == 'blogpost' )
$user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true );
if ( !$user_likes ){
return false;
} elseif ( !array_key_exists( $item_id, $user_likes ) ) {
return false;
} else {
return true;
};
}
/**
* bp_like_add_user_like()
*
* Registers that the user likes a given item.
*
*/
function bp_like_add_user_like( $item_id = '', $type = 'activity' ) {
global $bp;
if ( !$item_id )
return false;
if ( !$user_id )
$user_id = $bp->loggedin_user->id;
if ( $user_id == 0 ) {
echo bp_like_get_text( 'must_be_logged_in' );
return false;
}
if ( $type == 'activity' ) :
/* Add to the users liked activities. */
$user_likes = get_user_meta( $user_id, 'bp_liked_activities', true );
$user_likes[$item_id] = 'activity_liked';
update_user_meta( $user_id, 'bp_liked_activities', $user_likes );
/* Add to the total likes for this activity. */
$users_who_like = bp_activity_get_meta( $item_id, 'liked_count', true );
$users_who_like[$user_id] = 'user_likes';
bp_activity_update_meta( $item_id, 'liked_count', $users_who_like );
$liked_count = count( $users_who_like );
/***
* Hack: Post a screen notification to the user's notifications menu.
*/
bp_core_add_notification( $item_id, $user_id, $bp->bp_like->slug, 'new_bp_like' );
/* Publish to the activity stream if we're allowed to. */
if ( bp_like_get_settings( 'post_to_activity_stream' ) == 1 ) {
$activity = bp_activity_get_specific( array( 'activity_ids' => $item_id, 'component' => 'bp-like' ) );
$author_id = $activity['activities'][0]->user_id;
if ($user_id == $author_id)
$action = bp_like_get_text( 'record_activity_likes_own' );
elseif ($user_id == 0)
$action = bp_like_get_text( 'record_activity_likes_an' );
else
$action = bp_like_get_text( 'record_activity_likes_users' );
$liker = bp_core_get_userlink( $user_id );
$author = bp_core_get_userlink( $author_id );
$activity_url = bp_activity_get_permalink( $item_id );
/* Grab the content and make it into an excerpt of 140 chars if we're allowed */
if ( bp_like_get_settings( 'show_excerpt' ) == 1 ) {
$content = $activity['activities'][0]->content;
if ( strlen( $content ) > bp_like_get_settings( 'excerpt_length' ) ) {
$content = substr( $content, 0, bp_like_get_settings( 'excerpt_length' ) );
$content = $content.'...';
}
};
/* Filter out the placeholders */
$action = str_replace( '%user%', $liker, $action );
$action = str_replace( '%permalink%', $activity_url, $action );
$action = str_replace( '%author%', $author, $action );
bp_activity_add(
array(
'action' => $action,
'content' => $content,
'primary_link' => $activity_url,
'component' => 'bp-like',
'type' => 'activity_liked',
'user_id' => $user_id,
'item_id' => $item_id
)
);
};
elseif ( $type == 'blogpost' ) :
/* Add to the users liked blog posts. */
$user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true);
$user_likes[$item_id] = 'blogpost_liked';
update_user_meta( $user_id, 'bp_liked_blogposts', $user_likes );
/* Add to the total likes for this blog post. */
$users_who_like = get_post_meta( $item_id, 'liked_count', true );
$users_who_like[$user_id] = 'user_likes';
update_post_meta( $item_id, 'liked_count', $users_who_like );
$liked_count = count( $users_who_like );
/***
* Hack: Post a screen notification to the user's notifications menu.
*/
bp_core_add_notification( $item_id, $user_id, $bp->bp_like->slug, 'new_bp_like' );
if ( bp_like_get_settings( 'post_to_activity_stream' ) == 1 ) {
$post = get_post($item_id);
$author_id = $post->post_author;
$liker = bp_core_get_userlink( $user_id );
$permalink = get_permalink( $item_id );
$title = $post->post_title;
$author = bp_core_get_userlink( $post->post_author );
if ($user_id == $author_id)
$action = bp_like_get_text( 'record_activity_likes_own_blogpost' );
elseif ($user_id == 0)
$action = bp_like_get_text( 'record_activity_likes_a_blogpost' );
else
$action = bp_like_get_text( 'record_activity_likes_users_blogpost' );
/* Filter out the placeholders */
$action = str_replace( '%user%', $liker, $action );
$action = str_replace( '%permalink%', $permalink, $action );
$action = str_replace( '%title%', $title, $action );
$action = str_replace( '%author%', $author, $action );
/* Grab the content and make it into an excerpt of 140 chars if we're allowed */
if ( bp_like_get_settings( 'show_excerpt' ) == 1 ) {
$content = $post->post_content;
if ( strlen( $content ) > bp_like_get_settings( 'excerpt_length' ) ) {
$content = substr( $content, 0, bp_like_get_settings( 'excerpt_length' ) );
$content = $content.'...';
}
};
bp_activity_add(
array(
'action' => $action,
'content' => $content,
'component' => 'bp-like',
'type' => 'blogpost_liked',
'user_id' => $user_id,
'item_id' => $item_id,
'primary_link' => $permalink
)
);
// bp_like_send_notification( $snippet->id, $snippet->user_id, $snippet->item_id, $user_id, $content);
};
endif;
echo bp_like_get_text( 'unlike' );
echo ' ' . $liked_count . '
Unlike
';
}
/**
* bp_like_remove_user_like()
*
* Registers that the user has unliked a given item.
*
*/
function bp_like_remove_user_like( $item_id = '', $type = 'activity') {
global $bp;
if ( !$item_id )
return false;
if ( !$user_id )
$user_id = $bp->loggedin_user->id;
if ( $user_id == 0 ) {
echo bp_like_get_text( 'must_be_logged_in' );
return false;
}
if ( $type == 'activity' ) :
/* Remove this from the users liked activities. */
$user_likes = get_user_meta( $user_id, 'bp_liked_activities', true );
unset( $user_likes[$item_id] );
update_user_meta( $user_id, 'bp_liked_activities', $user_likes );
/* Update the total number of users who have liked this activity. */
$users_who_like = bp_activity_get_meta( $item_id, 'liked_count', true );
unset( $users_who_like[$user_id] );
/* If nobody likes the activity, delete the meta for it to save space, otherwise, update the meta */
if ( empty( $users_who_like ) )
bp_activity_delete_meta( $item_id, 'liked_count' );
else
bp_activity_update_meta( $item_id, 'liked_count', $users_who_like );
$liked_count = count( $users_who_like );
/* Remove the update on the users profile from when they liked the activity. */
$update_id = bp_activity_get_activity_id(
array(
'item_id' => $item_id,
'component' => 'bp-like',
'type' => 'activity_liked',
'user_id' => $user_id
)
);
bp_activity_delete(
array(
'id' => $update_id,
'item_id' => $item_id,
'component' => 'bp-like',
'type' => 'activity_liked',
'user_id' => $user_id
)
);
elseif ( $type == 'blogpost' ) :
/* Remove this from the users liked activities. */
$user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true );
unset( $user_likes[$item_id] );
update_user_meta( $user_id, 'bp_liked_blogposts', $user_likes );
/* Update the total number of users who have liked this blog post. */
$users_who_like = get_post_meta( $item_id, 'liked_count', true );
unset( $users_who_like[$user_id] );
/* If nobody likes the blog post, delete the meta for it to save space, otherwise, update the meta */
if ( empty( $users_who_like ) )
delete_post_meta( $item_id, 'liked_count' );
else
update_post_meta( $item_id, 'liked_count', $users_who_like );
$liked_count = count( $users_who_like );
/* Remove the update on the users profile from when they liked the activity. */
$update_id = bp_activity_get_activity_id(
array(
'item_id' => $item_id,
'component' => 'bp-like',
'type' => 'blogpost_liked',
'user_id' => $user_id
)
);
bp_activity_delete(
array(
'id' => $update_id,
'item_id' => $item_id,
'component' => 'bp-like',
'type' => 'blogpost_liked',
'user_id' => $user_id
)
);
endif;
echo bp_like_get_text( 'like' );
echo ' ' . $liked_count . '
Like this
';
}
/**
* bp_like_get_likes()
*
* Outputs a list of users who have liked a given item.
*
*/
function bp_like_get_likes( $item_id = '', $type = '', $user_id = '' ) {
global $bp;
if ( !$type || !$item_id )
return false;
if ( !$user_id )
$user_id = $bp->loggedin_user->id;
if ( $type == 'activity' ) :
/* Grab some core data we will need later on, specific to activities */
$users_who_like = array_keys( bp_activity_get_meta( $item_id, 'liked_count' ) );
$liked_count = count( bp_activity_get_meta( $item_id, 'liked_count' ) );
/* Intercept any messages if nobody likes it, just incase the button was clicked when it shouldn't be */
if ( $liked_count == 0 ) :
$output .= bp_like_get_text( 'get_likes_no_likes' );
/* We should show information about all likers */
elseif ( bp_like_get_settings( 'likers_visibility' ) == 'show_all' ) :
/* Settings say we should show their name. */
if ( bp_like_get_settings( 'name_or_avatar' ) == 'name' ) :
/* Current user likes it too, remove them from the liked count and output appropriate message */
if ( bp_like_is_liked( $item_id, 'activity', $user_id ) ) :
$liked_count = $liked_count-1;
if ( $liked_count == 1 )
$output .= bp_like_get_text( 'get_likes_you_and_singular' );
elseif ( $liked_count == 0 )
$output .= bp_like_get_text('get_likes_only_liker');
else
$output .= bp_like_get_text( 'get_likes_you_and_plural' );
else :
if ( $liked_count == 1 )
$output .= bp_like_get_text( 'get_likes_count_people_singular' );
else
$output .= bp_like_get_text( 'get_likes_count_people_plural' );
endif;
/* Now output the name of each person who has liked it (except the current user obviously) */
foreach( $users_who_like as $id ) :
if ( $id != $user_id )
$output .= ' · ' . bp_core_get_user_displayname( $id ) . '';
endforeach;
/* Settings say we should show their avatar. */
elseif ( bp_like_get_settings( 'name_or_avatar' ) == 'avatar' ) :
/* Output the avatar of each person who has liked it. */
foreach( $users_who_like as $id ) :
$output .= '' . bp_core_fetch_avatar( array( 'item_id' => $id, 'object' => 'user', 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ) . ' ';
endforeach;
endif;
/* We should show the information of friends, but only the number of non-friends. */
elseif ( bp_like_get_settings( 'likers_visibility' ) == 'friends_names_others_numbers' && bp_is_active( 'friends' ) ) :
/* Grab some information about their friends. */
$users_friends = friends_get_friend_user_ids( $user_id );
if ( !empty( $users_friends ) )
$friends_who_like = array_intersect( $users_who_like, $users_friends );
/* Current user likes it, so reduce the liked count by 1, to get the number of other people who like it. */
if ( bp_like_is_liked( $item_id, 'activity', $user_id ) )
$liked_count = $liked_count-1;
/* Settings say we should show their names. */
if ( bp_like_get_settings( 'name_or_avatar' ) == 'name' ) :
/* Current user likes it too, tell them. */
if ( bp_like_is_liked( $item_id, 'activity', $user_id ) )
$output .= 'You ';
/* Output the name of each friend who has liked it. */
foreach( $users_who_like as $id ) :
if ( in_array( $id, $friends_who_like ) ) {
$output .= ' · ' . bp_core_get_user_displayname( $id ) . ' ';
$liked_count = $liked_count-1;
}
endforeach;
/* If non-friends like it, say so. */
if ( $liked_count == 1 )
$output .= bp_like_get_text( 'get_likes_and_people_singular' );
elseif ( $liked_count > 1 )
$output .= bp_like_get_text( 'get_likes_and_people_plural' );
else
$output .= bp_like_get_text( 'get_likes_like_this' );
/* Settings say we should show their avatar. */
elseif ( bp_like_get_settings( 'name_or_avatar' ) == 'avatar' ) :
/* Output the avatar of each friend who has liked it, as well as the current users' if they have. */
if ( !empty( $friends_who_like ) ) :
foreach( $users_who_like as $id ) :
if ( $id == $user_id || in_array( $id, $friends_who_like ) ) {
$user_info = get_userdata( $id );
$output .= '' . get_avatar( $user_info->user_email, 30 ) . ' ';
}
endforeach;
endif;
endif;
elseif ( bp_like_get_settings( 'likers_visibility' ) == 'friends_names_others_numbers' && !bp_is_active( 'friends' ) ||bp_like_get_settings( 'likers_visibility' ) == 'just_numbers' ) :
/* Current user likes it too, remove them from the liked count and output appropriate message */
if ( bp_like_is_liked( $item_id, 'activity', $user_id ) ) :
$liked_count = $liked_count-1;
if ( $liked_count == 1 )
$output .= bp_like_get_text( 'get_likes_you_and_singular' );
elseif ( $liked_count == 0 )
$output .= bp_like_get_text('get_likes_only_liker');
else
$output .= bp_like_get_text( 'get_likes_you_and_plural' );
else :
if ( $liked_count == 1 )
$output .= bp_like_get_text( 'get_likes_count_people_singular' );
else
$output .= bp_like_get_text( 'get_likes_count_people_plural' );
endif;
endif;
endif;
/* Filter out the placeholder. */
$output = str_replace( '%count%', $liked_count, $output );
echo $output;
}
/**
* bp_like_button()
*
* Outputs the 'Like/Unlike' and 'View likes/Hide likes' buttons.
*
*/
function bp_like_button( $id = '', $type = '' ) {
$users_who_like = 0;
$liked_count = 0;
/* Set the type if not already set, and check whether we are outputting the button on a blogpost or not. */
if ( !$type && !is_single() )
$type = 'activity';
elseif ( !$type && is_single() )
$type = 'blogpost';
if ( $type == 'activity' ) :
$activity = bp_activity_get_specific( array( 'activity_ids' => bp_get_activity_id() ) );
$activity_type = $activity['activities'][0]->type;
if ( is_user_logged_in() && $activity_type !== 'activity_liked' ) :
if ( bp_activity_get_meta( bp_get_activity_id(), 'liked_count', true )) {
$users_who_like = array_keys( bp_activity_get_meta( bp_get_activity_id(), 'liked_count', true ) );
$liked_count = count( $users_who_like );
}
if ( !bp_like_is_liked( bp_get_activity_id(), 'activity' ) ) : ?>
ID;
$liked_count = count( get_post_meta( $id, 'liked_count', true ) );
if ( !bp_like_is_liked( $id, 'blogpost' ) ) : ?>