Support for extra POST fields in WP_Filesystem. props dd32. see #12094

git-svn-id: https://develop.svn.wordpress.org/trunk@13577 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2010-03-03 19:53:39 +00:00
parent 1604a2e58b
commit c7fdac20df
1 changed files with 12 additions and 8 deletions

View File

@ -807,10 +807,11 @@ function get_filesystem_method($args = array(), $context = false) {
* @param string $type the chosen Filesystem method in use * @param string $type the chosen Filesystem method in use
* @param boolean $error if the current request has failed to connect * @param boolean $error if the current request has failed to connect
* @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method() * @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method()
* @param string $extra_fields Extra POST fields which should be checked for to be included in the post.
* @return boolean False on failure. True on success. * @return boolean False on failure. True on success.
*/ */
function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false) { function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false, $extra_fields = null) {
$req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error, $context); $req_cred = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields );
if ( '' !== $req_cred ) if ( '' !== $req_cred )
return $req_cred; return $req_cred;
@ -820,6 +821,9 @@ function request_filesystem_credentials($form_post, $type = '', $error = false,
if ( 'direct' == $type ) if ( 'direct' == $type )
return true; return true;
if ( is_null( $extra_fields ) )
$extra_fields = array( 'version', 'locale' );
$credentials = get_option('ftp_credentials', array( 'hostname' => '', 'username' => '')); $credentials = get_option('ftp_credentials', array( 'hostname' => '', 'username' => ''));
// If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option) // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
@ -954,12 +958,12 @@ jQuery(function($){
</tr> </tr>
</table> </table>
<?php if ( isset( $_POST['version'] ) ) : ?> <?php
<input type="hidden" name="version" value="<?php echo esc_attr(stripslashes($_POST['version'])) ?>" /> foreach ( (array) $extra_fields as $field ) {
<?php endif; ?> if ( isset( $_POST[ $field ] ) )
<?php if ( isset( $_POST['locale'] ) ) : ?> echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( stripslashes( $_POST[ $field ] ) ) . '" />';
<input type="hidden" name="locale" value="<?php echo esc_attr(stripslashes($_POST['locale'])) ?>" /> }
<?php endif; ?> ?>
<p class="submit"> <p class="submit">
<input id="upgrade" name="upgrade" type="submit" class="button" value="<?php esc_attr_e('Proceed'); ?>" /> <input id="upgrade" name="upgrade" type="submit" class="button" value="<?php esc_attr_e('Proceed'); ?>" />
</p> </p>