Opened 17 months ago

Last modified 9 months ago

#19643 new defect (bug)

Allow array for $extra_fields in request_filesystem_credentials

Reported by: griffinjt Owned by:
Priority: normal Milestone: Awaiting Review
Component: Filesystem Version: 3.0
Severity: minor Keywords: has-patch needs-testing dev-feedback
Cc: thomas@…, travis@…, Otto42, kurtpayne

Description

The current implementation for passing extra fields through request_filesystem_credentials() does not allow for an array of data to be passed. I came across this issue when trying to process a bulk installation of plugins with my plugin installation class. My patch fixes this from what I can tell and doesn't break anything that I can see from my testing.

Attachments (4)

accept_array_fields.diff (762 bytes) - added by griffinjt 17 months ago.
allow array of data to be passed through $extra_fields
updated_array.diff (911 bytes) - added by griffinjt 17 months ago.
updated to fix notices
extra-fields-callback.diff (1.7 KB) - added by griffinjt 15 months ago.
callback function to accept any type of extra field
19643.patch (1.2 KB) - added by kurtpayne 9 months ago.
Alternate patch - handles multi-dimensional arrays

Download all attachments as: .zip

Change History (19)

allow array of data to be passed through $extra_fields

  • Keywords needs-testing added

That'll issue a PHP Notice on any $extra_fields which aren't in the incoming $_POST array. That's why there's a isset() call there

updated to fix notices

It's late - forgive me. :-) That should fix the error warnings now and still works fine as far as I have tested.

Instead of doing an is_array() check and duplicating the echo line, why not cast $_POST['field'] to an array and just have the foreach?

Doing that won't allow for the input name attribute to be set as an array. That's why I had the two echo lines.

Any word on this? Again with testing I haven't run into any bugs and it works perfectly for passing an array of data from a previous post entry.

  • Keywords dev-feedback added

Any word on this?

Most of us are taking a break after 3.3's release. 3.4 dev will be starting after the holiday season and people will look over it then most likely. Have patience.

Ok,cool. No worries!

  • Cc travis@… added

+1

  • Cc Otto42 added

Ok, here's my feeble attempt at providing a solution that will catch any type of value submitted via $extra_fields and parse it correctly within the input field. Because my knowledge of recursion is shoddy at best, I came up with this function instead.

All it does is sanitize and store all the data passed via $extra_fields into an array and then builds a query string based on that data. Then I just run through the query string and make input fields.

It works in all my testing. I don't know if this is the -best- method, but it is a -working- method that can at least get the ball rolling so that no data is lost when attempting to pass it once the user hits "Proceed".

callback function to accept any type of extra field

Just updated the patch to use (the newly discovered to me) WP's build_query function. Would love to get some feedback on this - no more losing data when having to enter FTP credentials. :-)

  • Type changed from enhancement to defect (bug)

Alternate patch - handles multi-dimensional arrays

  • Cc kurtpayne added

Submitting an alternate patch. This will handle multi-dimensional arrays, too. E.g.

<input type="hidden" name="field1[]" value="value1" />
<input type="hidden" name="field1[]" value="value2" />
<input type="hidden" name="field1[]" value="value3" />
<input type="hidden" name="field2[deep][array][value]" value="value4" />
<input type="hidden" name="field3[][][]" value="value5" />
<input type="hidden" name="field4" value="value6" />

And the corresponding php:

$form_fields = array ( 'field1', 'field2', 'field3', 'field4' );
request_filesystem_credentials($url, $method, false, false, $form_fields) );

I'm testing this with Otto's test filesystem plugin.

  • Severity changed from normal to minor
  • Version changed from 3.3 to 3.0
Note: See TracTickets for help on using tickets.