Skip to content

Instantly share code, notes, and snippets.

@yahilmadakiya
Created August 24, 2017 13:53
Show Gist options
  • Save yahilmadakiya/0b3c67f2c5988bde53fae33dcba9f76c to your computer and use it in GitHub Desktop.
Save yahilmadakiya/0b3c67f2c5988bde53fae33dcba9f76c to your computer and use it in GitHub Desktop.
Append meta field value in BuddyPress activity,
// Add code in your theme's js file.
$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
try {
if ( originalOptions.data == null || typeof ( originalOptions.data ) == 'undefined' || typeof ( originalOptions.data.action ) == 'undefined' ) {
return true;
}
} catch ( e ) {
return true;
}
if ( 'post_update' == originalOptions.data.action ) {
// Set your meta field id [ TEXT BOX - ID ].
var activity_meta = '#activity_firstname';
options.data += "&activity_meta=" + jQuery( activity_meta ).val();
}
} );
// Add code in your theme's functions.php file.
function bp_append_meta_text( $activity ) {
$updated_content = $activity->content;
if ( isset( $_POST['activity_meta'] ) && '' != $_POST['activity_meta'] ) {
$first = '<div class="activity_meta"> ' . $_POST['activity_meta'] . ' </div>';
$activity->content = $first . $updated_content;
$activity->type = 'rtmedia_update';
}
}
add_action( 'bp_activity_before_save', 'bp_append_meta_text', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment