Skip to content

Instantly share code, notes, and snippets.

@sbrajesh
Last active December 13, 2015 17:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sbrajesh/4949784 to your computer and use it in GitHub Desktop.
Save sbrajesh/4949784 to your computer and use it in GitHub Desktop.
BuddyPress Activity as wire
add_action('init', 'bdev_fix_activity_posting_hooks');
function bdev_fix_activity_posting_hooks() {
remove_action('wp_ajax_post_update', 'bp_dtheme_post_update');
}
//add our own handler for activity posting
add_action('wp_ajax_post_update', 'bp_mytheme_post_update');
/* AJAX update posting */
function bp_mytheme_post_update() {
global $bp;
/* Check the nonce */
check_admin_referer('post_update', '_wpnonce_post_update');
if (!is_user_logged_in()) {
echo '-1';
exit(0);
}
if (empty($_POST['content'])) {
echo '-1<div id="message"><p>' . __('Please enter some content to post.', 'buddypress') . '</p></div>';
exit(0);
}
if (empty($_POST['object']) && function_exists('bp_activity_post_update')) {
//this is what I have changed
if (!bp_is_home() && bp_is_member())
$content = "@" . bp_get_displayed_user_username() . " " . $_POST['content'];
else
$content = $_POST['content'];
//let us get the last activity id, we will use it to reset user's last activity
$last_update = bp_get_user_meta(bp_loggedin_user_id(), 'bp_latest_update', true);
$activity_id = bp_activity_post_update(array('content' => $content));
//reset the last update
bp_update_user_meta(bp_loggedin_user_id(), 'bp_latest_update', $last_update);
//end of my changes
} elseif ($_POST['object'] == 'groups') {
if (!empty($_POST['item_id']) && function_exists('groups_post_update'))
$activity_id = groups_post_update(array('content' => $_POST['content'], 'group_id' => $_POST['item_id']));
} else
$activity_id = apply_filters('bp_activity_custom_update', $_POST['object'], $_POST['item_id'], $_POST['content']);
if (!$activity_id) {
echo '-1<div id="message"><p>' . __('There was a problem posting your update, please try again.', 'buddypress') . '</p></div>';
exit(0);
}
if (bp_has_activities('include=' . $activity_id)) :
?>
<?php while (bp_activities()) : bp_the_activity(); ?>
<?php locate_template(array('activity/entry.php'), true) ?>
<?php endwhile; ?>
<?php
endif;
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment