Skip to:
Content

BuddyPress.org

Changeset 10294


Ignore:
Timestamp:
10/21/2015 06:57:52 PM (11 years ago)
Author:
r-a-y
Message:

bp-legacy: Pass all $_POST data when a user makes a "What's New" activity update.

Previously, if a plugin developer added a custom field to the "What's New"
form, the data for that field would not get passed to our AJAX post handler

  • bp_legacy_theme_post_update(). This made things difficult for plugin

developers to save their custom activity data.

This commit passes all valid $_POST fields from the "What's New" form to
our AJAX post handler, which will allow plugin developers to find their
data and save it.

See https://buddypress.trac.wordpress.org/ticket/6569#comment:21 for a
brief example.

Props imath.

See #6569.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-legacy/js/buddypress.js

    r10214 r10294  
    105105                var last_date_recorded = 0,
    106106                        button = jq(this),
    107                         form   = button.closest('form#whats-new-form');
    108 
    109                 form.children().each( function() {
    110                         if ( jq.nodeName(this, 'textarea') || jq.nodeName(this, 'input') ) {
     107                        form   = button.closest('form#whats-new-form'),
     108                        inputs = {}, post_data;
     109
     110                // Get all inputs and organize them into an object {name: value}
     111                jq.each( form.serializeArray(), function( key, input ) {
     112                        // Only include public extra data
     113                        if ( '_' !== input.name.substr( 0, 1 ) && 'whats-new' !== input.name.substr( 0, 9 ) ) {
     114                                if ( ! inputs[ input.name ] ) {
     115                                        inputs[ input.name ] = input.value;
     116                                } else {
     117                                        // Checkboxes/dropdown list can have multiple selected value
     118                                        if ( ! jq.isArray( inputs[ input.name ] ) ) {
     119                                                inputs[ input.name ] = new Array( inputs[ input.name ], input.value );
     120                                        } else {
     121                                                inputs[ input.name ].push( input.value );
     122                                        }
     123                                }
     124                        }
     125                } );
     126
     127                form.find( '*' ).each( function() {
     128                        if ( jq.nodeName( this, 'textarea' ) || jq.nodeName( this, 'input' ) ) {
    111129                                jq(this).prop( 'disabled', true );
    112130                        }
    113                 });
     131                } );
    114132
    115133                /* Remove any errors */
     
    146164                }
    147165
    148                 jq.post( ajaxurl, {
     166                post_data = jq.extend( {
    149167                        action: 'post_update',
    150168                        'cookie': bp_get_cookies(),
     
    155173                        'since': last_date_recorded,
    156174                        '_bp_as_nonce': jq('#_bp_as_nonce').val() || ''
    157                 },
    158                 function(response) {
    159 
    160                         form.children().each( function() {
    161                                 if ( jq.nodeName(this, 'textarea') || jq.nodeName(this, 'input') ) {
     175                }, inputs );
     176
     177                jq.post( ajaxurl, post_data, function( response ) {
     178                        form.find( '*' ).each( function() {
     179                                if ( jq.nodeName( this, 'textarea' ) || jq.nodeName( this, 'input' ) ) {
    162180                                        jq(this).prop( 'disabled', false );
    163181                                }
     
    206224                                jq('li.new-update').removeClass( 'new-update' );
    207225                                jq('#whats-new').val('');
     226                                form.get(0).reset();
    208227
    209228                                // reset vars to get newest activities
Note: See TracChangeset for help on using the changeset viewer.