WordPress.org

Make WordPress Core

Ticket #19643: extra-fields-callback.diff

File extra-fields-callback.diff, 1.7 KB (added by griffinjt, 6 years ago)

callback function to accept any type of extra field

  • wp-admin/includes/file.php

     
    10441044</table>
    10451045
    10461046<?php
    1047 foreach ( (array) $extra_fields as $field ) {
    1048         if ( isset( $_POST[ $field ] ) )
    1049                 echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( stripslashes( $_POST[ $field ] ) ) . '" />';
    1050 }
     1047output_filesystem_extra_fields( $extra_fields );
    10511048submit_button( __( 'Proceed' ), 'button', 'upgrade' );
    10521049?>
    10531050</div>
     
    10551052<?php
    10561053        return false;
    10571054}
     1055
     1056/**
     1057 * Callback function for outputting any extra fields passed through request_filesystem_credentials().
     1058 *
     1059 * This function will parse strings, arrays or multi-dimensional arrays passed within the $extra_fields
     1060 * parameter so that no data is lost.
     1061 *
     1062 * @since 3.4.0
     1063 *
     1064 * @uses build_query
     1065 * @param array $fields Extra fields passed through request_filesystem_credentials().
     1066 */
     1067function output_filesystem_extra_fields( $fields ) {
     1068
     1069        // Sanitize and store all passed data into one array
     1070        $qs = array();
     1071        foreach ( (array) $fields as $field ) {
     1072                if ( isset( $_POST[ $field ] ) )
     1073                        $qs[esc_attr( $field )] = is_array( $_POST[$field] ) ? $_POST[esc_attr( stripslashes_deep( $field ) )] : $_POST[esc_attr( stripslashes( $field ) )];
     1074        }
     1075       
     1076        // Build a query string out of the data and then parse the string into input fields
     1077        $query_string = build_query( $qs );
     1078        foreach ( explode( '&', $query_string ) as $kv_pair ) {
     1079                list( $name, $value ) = explode( '=', $kv_pair, 2 );
     1080                echo '<input type="hidden" name="' . urldecode( $name ) . '" value="' . urldecode( $value ) . '">' . "\r\n";
     1081        }
     1082
     1083}
     1084 No newline at end of file