Created
August 24, 2017 13:53
-
-
Save yahilmadakiya/0b3c67f2c5988bde53fae33dcba9f76c to your computer and use it in GitHub Desktop.
Append meta field value in BuddyPress activity,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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