Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bp-groups/bp-groups-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,11 @@ function groups_record_activity( $args = '' ) {
}
}


$args = array(
'id' => $activity->id,
'action' => ! empty( $args['action'] ) ? $args['action'] : $activity->action,
'post_title' => ! empty( $args['post_title'] ) ? $args['post_title'] : $activity->post_title,
'post_title' => ! empty( $args['post_title'] ) ? $args['post_title'] : ( ! empty( $args['post_title_cleared'] ) ? '' : $activity->post_title ),
'title_required' => ! empty( $args['title_required'] ) ? $args['title_required'] : $activity->title_required,
'content' => ! empty( $args['content'] ) ? $args['content'] : '',
'component' => $activity->component,
Expand Down
53 changes: 28 additions & 25 deletions src/bp-groups/bp-groups-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1767,16 +1767,17 @@ function groups_post_update( $args = '' ) {
$r = bp_parse_args(
$args,
array(
'id' => false,
'post_title' => false,
'title_required' => function_exists( 'bb_is_activity_post_title_enabled' ) ? bb_is_activity_post_title_enabled() : false,
'content' => false,
'user_id' => bp_loggedin_user_id(),
'group_id' => 0,
'privacy' => 'public',
'error_type' => 'bool',
'status' => bb_get_activity_published_status(),
'recorded_time' => bp_core_current_time(),
'id' => false,
'post_title' => false,
'post_title_cleared' => false,
'title_required' => function_exists( 'bb_is_activity_post_title_enabled' ) ? bb_is_activity_post_title_enabled() : false,
'content' => false,
'user_id' => bp_loggedin_user_id(),
'group_id' => 0,
'privacy' => 'public',
'error_type' => 'bool',
'status' => bb_get_activity_published_status(),
'recorded_time' => bp_core_current_time(),
),
'groups_post_update'
);
Expand Down Expand Up @@ -1830,22 +1831,24 @@ function groups_post_update( $args = '' ) {
*/
$post_title_filtered = apply_filters( 'bb_groups_activity_new_update_post_title', $post_title );

$activity_id = groups_record_activity(
array(
'id' => $id,
'user_id' => $user_id,
'action' => $action,
'post_title' => $post_title_filtered,
'title_required' => $r['title_required'],
'content' => $content_filtered,
'type' => 'activity_update',
'item_id' => $group_id,
'privacy' => $privacy,
'error_type' => $error_type,
'status' => $status,
'recorded_time' => $recorded_time,
)
$record_args = array(
'id' => $id,
'user_id' => $user_id,
'action' => $action,
'post_title' => $post_title_filtered,
'title_required' => $r['title_required'],
'content' => $content_filtered,
'type' => 'activity_update',
'item_id' => $group_id,
'privacy' => $privacy,
'error_type' => $error_type,
'status' => $status,
'recorded_time' => $recorded_time,
);
if ( ! empty( $r['post_title_cleared'] ) ) {
$record_args['post_title_cleared'] = 1;
}
$activity_id = groups_record_activity( $record_args );

groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );

Expand Down
9 changes: 8 additions & 1 deletion src/bp-templates/bp-nouveau/includes/activity/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,10 @@ function_exists( 'bb_pro_activity_post_feature_image_instance' )
}
}

$post_title = ! empty( $_POST['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['post_title'] ) ) : '';
$post_title = isset( $_POST['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['post_title'] ) ) : ( isset( $_POST['whats-new-title'] ) ? sanitize_text_field( wp_unslash( $_POST['whats-new-title'] ) ) : '' );
if ( ! empty( $_POST['id'] ) && ! empty( $_POST['post_title_cleared'] ) ) {
$post_title = '';
}
$validation = bb_validate_activity_post_title( $post_title );
if ( ! $validation['valid'] ) {
wp_send_json_error(
Expand Down Expand Up @@ -1060,6 +1063,10 @@ function_exists( 'bb_pro_activity_post_feature_image_instance' )
'group_id' => $item_id,
);

if ( ! empty( $_POST['post_title_cleared'] ) ) {
$post_array['post_title_cleared'] = 1;
}

if ( $is_scheduled ) {
$post_array['recorded_time'] = $schedule_date_time;
$post_array['status'] = $activity_status;
Expand Down
44 changes: 29 additions & 15 deletions src/bp-templates/bp-nouveau/js/buddypress-activity-post-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1233,10 +1233,8 @@ window.bp = window.bp || {};

self.postForm.model.set( 'content', content, {silent: true} );

var activityPostTitle = self.postForm.$el.find( '#whats-new-title' ).val();
if ( activityPostTitle ) {
self.postForm.model.set( 'post_title', activityPostTitle, {silent: true} );
}
var activityPostTitle = self.postForm.$el.find( '#whats-new-title' ).val() || '';
self.postForm.model.set( 'post_title', activityPostTitle, {silent: true} );

// Silently add meta.
self.postForm.model.set( meta, {silent: true} );
Expand Down Expand Up @@ -6148,7 +6146,9 @@ window.bp = window.bp || {};

postUpdate: function ( event ) {
var self = this,
meta = {}, edit = false;
meta = { post_title: '' },
edit = false,
$form = ( event && event.target && $( event.target ).is( 'form' ) ) ? $( event.target ) : self.$el;

if ( event ) {
if ( 'keydown' === event.type && ( 13 !== event.keyCode || ! event.ctrlKey ) ) {
Expand All @@ -6161,14 +6161,18 @@ window.bp = window.bp || {};
// unset all errors before submit.
self.model.unset( 'errors' );

// Set the content and meta.
// Set the content and meta from the submitted form.
_.each(
self.$el.serializeArray(),
$form.serializeArray(),
function ( pair ) {
pair.name = pair.name.replace( '[]', '' );
if ( pair.name.startsWith( 'bb-poll-question-option[' ) ) {
pair.name = pair.name.replace( /\[\d+\]/, '' );
}
if ( 'whats-new-title' === pair.name || 'bb-rl-whats-new-title' === pair.name ) {
meta.post_title = ( pair.value || '' ).trim();
return;
}
if ( -1 === _.indexOf( [ 'aw-whats-new-submit', 'whats-new-post-in', 'bb-schedule-activity-date-field', 'bb-schedule-activity-meridian', 'bb-schedule-activity-time-field', 'bb-poll-question-field', 'bb-poll-duration', 'bb-poll-question-option', 'bb-poll-allow-multiple-answer', 'bb-poll-allow-new-option', 'whats-new-title' ], pair.name ) ) {
if ( _.isUndefined( meta[ pair.name ] ) ) {
meta[ pair.name ] = pair.value;
Expand All @@ -6184,7 +6188,7 @@ window.bp = window.bp || {};
);

// Post content.
var $whatsNew = self.$el.find( '#whats-new' );
var $whatsNew = $form.find( '#whats-new' );

var atwho_query = $whatsNew.find( 'span.atwho-query' );
for ( var i = 0; i < atwho_query.length; i++ ) {
Expand Down Expand Up @@ -6214,19 +6218,15 @@ window.bp = window.bp || {};

self.model.set( 'content', content, { silent: true } );

var activityPostTitle = self.$el.find( '#whats-new-title' );
if ( self.$el.find( '#bb-rl-whats-new-title' ).length ) {
activityPostTitle = self.$el.find( '#bb-rl-whats-new-title' );
}
if ( activityPostTitle.length && activityPostTitle.val() !== '' ) {
activityPostTitle = activityPostTitle.val();
var activityPostTitle = $form.find( '#bb-rl-whats-new-title' ).length ? $form.find( '#bb-rl-whats-new-title' ).val() || '' : $form.find( '#whats-new-title' ).val() || '';
if ( activityPostTitle.length > 0 ) {
var maxPostTitleLength = BP_Nouveau.activity.params.activity_post_title_maxlength;
// Maximum 80 characters allowed.
if ( activityPostTitle.length > maxPostTitleLength ) {
activityPostTitle = activityPostTitle.slice( 0, maxPostTitleLength );
}
self.model.set( 'post_title', activityPostTitle, { silent: true } );
}
self.model.set( 'post_title', activityPostTitle, { silent: true } );

// Silently add meta.
self.model.set( meta, { silent: true } );
Expand Down Expand Up @@ -6381,6 +6381,20 @@ window.bp = window.bp || {};
}
);

// Force post_title from visible input right before send - ensures cleared title is always sent.
var $titleEl = $form.find( 'input.whats-new-title, input#whats-new-title, input.bb-rl-whats-new-title, input#bb-rl-whats-new-title' ).first();
if ( ! $titleEl.length ) {
$titleEl = $( 'input.whats-new-title, input#whats-new-title, input.bb-rl-whats-new-title, input#bb-rl-whats-new-title' ).filter( ':visible' ).first();
}
data.post_title = $titleEl.length ? ( $titleEl.val() || '' ).trim() : ( meta.post_title || '' );
if ( data.post_title.length > 0 && BP_Nouveau.activity.params.activity_post_title_maxlength ) {
data.post_title = data.post_title.slice( 0, BP_Nouveau.activity.params.activity_post_title_maxlength );
}
// Explicit flag when user cleared title during edit - ensures empty is saved even if empty params are stripped.
if ( edit && data.post_title.length === 0 ) {
data.post_title_cleared = 1;
}

bp.ajax.post( 'post_update', data ).done(
function ( response ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,8 @@ window.bp = window.bp || {};

self.postForm.model.set( 'content', content, {silent: true} );

var activityPostTitle = self.postForm.$el.find( '#bb-rl-whats-new-title' ).val();
if ( activityPostTitle ) {
self.postForm.model.set( 'post_title', activityPostTitle, {silent: true} );
}
var activityPostTitle = self.postForm.$el.find( '#bb-rl-whats-new-title' ).val() || '';
self.postForm.model.set( 'post_title', activityPostTitle, {silent: true} );

// Silently add meta.
self.postForm.model.set( meta, {silent: true} );
Expand Down Expand Up @@ -5458,16 +5456,15 @@ window.bp = window.bp || {};

self.model.set( 'content', content, { silent: true } );

var postTitle = self.$el.find( '#bb-rl-whats-new-title' );
if ( postTitle.length && postTitle.val() !== '' ) {
postTitle = postTitle.val();
var postTitle = self.$el.find( '#bb-rl-whats-new-title' ).val() || '';
if ( postTitle.length > 0 ) {
var maxPostTitleLength = BP_Nouveau.activity.params.activity_post_title_maxlength;
// Maximum 80 characters allowed.
if ( postTitle.length > maxPostTitleLength ) {
postTitle = postTitle.slice( 0, maxPostTitleLength );
}
self.model.set( 'post_title', postTitle, { silent: true } );
}
self.model.set( 'post_title', postTitle, { silent: true } );

// Silently add meta.
self.model.set( meta, { silent: true } );
Expand Down Expand Up @@ -5629,6 +5626,21 @@ window.bp = window.bp || {};
}
);

// Force post_title from visible input right before send - ensures cleared title is always sent.
var $form = ( event && event.target && $( event.target ).is( 'form' ) ) ? $( event.target ) : self.$el;
var $titleEl = $form.find( 'input#bb-rl-whats-new-title, input.bb-rl-whats-new-title' ).first();
if ( ! $titleEl.length ) {
$titleEl = $( 'input#bb-rl-whats-new-title, input.bb-rl-whats-new-title' ).filter( ':visible' ).first();
}
data.post_title = $titleEl.length ? ( $titleEl.val() || '' ).trim() : ( self.model.get( 'post_title' ) || '' );
if ( data.post_title.length > 0 && BP_Nouveau.activity.params.activity_post_title_maxlength ) {
data.post_title = data.post_title.slice( 0, BP_Nouveau.activity.params.activity_post_title_maxlength );
}
// Explicit flag when user cleared title during edit - ensures empty is saved even if empty params are stripped.
if ( edit && data.post_title.length === 0 ) {
data.post_title_cleared = 1;
}

bp.ajax.post( 'post_update', data ).done(
function ( response ) {

Expand Down
Loading