WordPress.org

Make WordPress Core

Opened 13 months ago

Last modified 13 months ago

#20716 new enhancement

Control how and when request_filesystem_credentials outputs creds form

Reported by: griffinjt Owned by:
Priority: normal Milestone: Awaiting Review
Component: Filesystem Version: 3.4
Severity: normal Keywords: reporter-feedback
Cc:

Description

When using WP_Filesystem in a plugin or other external app, you can initialize it this way:

if ( false == ( $creds = request_filesystem_credentials( $url, $method, false, false, $form_fields ) ) ) {
    return true;
}

Makes sense. If the method isn't direct or we don't have the credentials we need, request_filesystem_credentials outputs a form and returns false. Then we check again to make sure the credentials can be verified, and it not, we continue to output the form until the credentials are good.

if ( ! WP_Filesystem( $creds ) ) {
    request_filesystem_credentials( $url, $method, true, false, $form_fields );
    return true;
}

request_filesystem_credentials arbitrarily outputs the form whether you want it to or not, unless you explicitly filter the request_filesystem_credentials function itself. Using this in conjunction with Ajax, you have to use output buffering to catch the output and return it to the Ajax script for processing or else you get errors. This definitely isn't ideal.

I'd suggest storing the form in a variable and possibly pass a parameter that determines whether or not we want to actually output the form or not. Or, if there is another (better) way, that's cool too. Just some way to help request_filesystem_credentials determine how we want to interact with credentials should we need them.

Change History (1)

comment:1 griffinjt13 months ago

Err, should be === instead of == in that first function. Typo.

Note: See TracTickets for help on using tickets.