request_filesystem_credentials example

public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
        $url = $this->options['url'];
        if ( ! $context ) {
            $context = $this->options['context'];
        }
        if ( ! empty( $this->options['nonce'] ) ) {
            $url = wp_nonce_url( $url$this->options['nonce'] );
        }

        $extra_fields = array();

        return request_filesystem_credentials( $url, '', $error$context$extra_fields$allow_relaxed_file_ownership );
    }

    /** * @since 2.8.0 */
    public function header() {
        if ( $this->done_header ) {
            return;
        }
        $this->done_header = true;
        echo '<div class="wrap">';
        

    public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
        if ( $context ) {
            $this->options['context'] = $context;
        }
        /* * TODO: Fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version. * This will output a credentials form in event of failure. We don't want that, so just hide with a buffer. */
        ob_start();
        $result = parent::request_filesystem_credentials( $error$context$allow_relaxed_file_ownership );
        ob_end_clean();
        return $result;
    }

    /** * Retrieves the upgrade messages. * * @since 3.7.0 * * @return string[] Messages during an upgrade. */
    

    public function test_check_wp_filesystem_method() {
        // Make sure the `request_filesystem_credentials()` function is available during our REST API call.         if ( ! function_exists( 'request_filesystem_credentials' ) ) {
            require_once ABSPATH . 'wp-admin/includes/file.php';
        }

        $skin    = new Automatic_Upgrader_Skin();
        $success = $skin->request_filesystem_credentials( false, ABSPATH );

        if ( ! $success ) {
            $description  = __( 'Your installation of WordPress prompts for FTP credentials to perform updates.' );
            $description .= ' ' . __( '(Your site is performing updates over FTP due to file ownership. Talk to your hosting company.)' );

            return array(
                'description' => $description,
                'severity'    => 'fail',
            );
        }

        
/* * Allow relaxed file ownership writes for User-initiated upgrades when the API specifies * that it's safe to do so. This only happens when there are no new files to create. */
    $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;

    ?> <div class="wrap"> <h1><?php _e( 'Update WordPress' ); ?></h1> <?php
    $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' )$allow_relaxed_file_ownership );
    if ( false === $credentials ) {
        echo '</div>';
        return;
    }

    if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
        // Failed to connect. Error and request again.         request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' )$allow_relaxed_file_ownership );
        echo '</div>';
        return;
    }

    

function _wp_delete_all_temp_backups() {
    global $wp_filesystem;

    if ( ! function_exists( 'WP_Filesystem' ) ) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
    }

    ob_start();
    $credentials = request_filesystem_credentials( '' );
    ob_end_clean();

    if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
        return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
    }

    if ( ! $wp_filesystem->wp_content_dir() ) {
        return new WP_Error( 'fs_no_content_dir', __( 'Unable to locate WordPress content directory (wp-content).' ) );
    }

    $temp_backup_dir = $wp_filesystem->wp_content_dir() . 'upgrade-temp-backup/';
    
return false;
    }

    $checked = array();
    foreach ( $plugins as $plugin ) {
        $checked[] = 'checked[]=' . $plugin;
    }

    $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&' . implode( '&', $checked ), 'bulk-plugins' );

    ob_start();
    $credentials = request_filesystem_credentials( $url );
    $data        = ob_get_clean();

    if ( false === $credentials ) {
        if ( ! empty( $data ) ) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }

    

    public function fs_connect( $directories = array()$allow_relaxed_file_ownership = false ) {
        global $wp_filesystem;

        $credentials = $this->skin->request_filesystem_credentials( false, $directories[0]$allow_relaxed_file_ownership );
        if ( false === $credentials ) {
            return false;
        }

        if ( ! WP_Filesystem( $credentials$directories[0]$allow_relaxed_file_ownership ) ) {
            $error = true;
            if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->has_errors() ) {
                $error = $wp_filesystem->errors;
            }
            // Failed to connect. Error and request again.             $this->skin->request_filesystem_credentials( $error$directories[0]$allow_relaxed_file_ownership );
            


/** * Prints the filesystem credentials modal when needed. * * @since 4.2.0 */
function wp_print_request_filesystem_credentials_modal() {
    $filesystem_method = get_filesystem_method();

    ob_start();
    $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
    ob_end_clean();

    $request_filesystem_credentials = ( 'direct' !== $filesystem_method && ! $filesystem_credentials_are_stored );
    if ( ! $request_filesystem_credentials ) {
        return;
    }
    ?> <div id="request-filesystem-credentials-dialog" class="notification-dialog-wrap request-filesystem-credentials-dialog"> <div class="notification-dialog-background"></div> <div class="notification-dialog" role="dialog" aria-labelledby="request-filesystem-credentials-title" tabindex="0"> <div class="request-filesystem-credentials-dialog-content">
if ( $this->is_disabled() ) {
            return false;
        }

        // Only relax the filesystem checks when the update doesn't include new files.         $allow_relaxed_file_ownership = false;
        if ( 'core' === $type && isset( $item->new_files ) && ! $item->new_files ) {
            $allow_relaxed_file_ownership = true;
        }

        // If we can't do an auto core update, we may still be able to email the user.         if ( ! $skin->request_filesystem_credentials( false, $context$allow_relaxed_file_ownership )
            || $this->is_vcs_checkout( $context )
        ) {
            if ( 'core' === $type ) {
                $this->send_core_update_notification_email( $item );
            }
            return false;
        }

        // Next up, is this an item we can update?         if ( 'core' === $type ) {
            $update = Core_Upgrader::should_update_to_version( $item->current );
        }
global $wp_filesystem;

    if ( empty( $stylesheet ) ) {
        return false;
    }

    if ( empty( $redirect ) ) {
        $redirect = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );
    }

    ob_start();
    $credentials = request_filesystem_credentials( $redirect );
    $data        = ob_get_clean();

    if ( false === $credentials ) {
        if ( ! empty( $data ) ) {
            require_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            require_once ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }

    

    protected function is_filesystem_available() {
        $filesystem_method = get_filesystem_method();

        if ( 'direct' === $filesystem_method ) {
            return true;
        }

        ob_start();
        $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
        ob_end_clean();

        if ( $filesystem_credentials_are_stored ) {
            return true;
        }

        return new WP_Error( 'fs_unavailable', __( 'The filesystem is currently unavailable for managing plugins.' ), array( 'status' => 500 ) );
    }

    /** * Retrieves the plugin's schema, conforming to JSON Schema. * * @since 5.5.0 * * @return array Item schema data. */
'<code>wp-content/upgrade-temp-backup</code>'
            ),
            'actions'     => '',
            'test'        => 'update_temp_backup_writable',
        );

        if ( ! function_exists( 'WP_Filesystem' ) ) {
            require_once ABSPATH . '/wp-admin/includes/file.php';
        }

        ob_start();
        $credentials = request_filesystem_credentials( '' );
        ob_end_clean();

        if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
            $result['status']      = 'recommended';
            $result['label']       = __( 'Could not access filesystem' );
            $result['description'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
            return $result;
        }

        $wp_content = $wp_filesystem->wp_content_dir();

        
'themeSearchResults'   => __( '%d themes found' ),
                /* translators: %d: Number of themes being displayed, which cannot currently consider singular vs. plural forms. */
                'announceThemeCount'   => __( 'Displaying %d themes' ),
                /* translators: %s: Theme name. */
                'announceThemeDetails' => __( 'Showing details for theme: %s' ),
            ),
        );

        // Temporarily disable installation in Customizer. See #42184.         $filesystem_method = get_filesystem_method();
        ob_start();
        $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
        ob_end_clean();
        if ( 'direct' !== $filesystem_method && ! $filesystem_credentials_are_stored ) {
            $settings['theme']['_filesystemCredentialsNeeded'] = true;
        }

        // Prepare Customize Section objects to pass to JavaScript.         foreach ( $this->sections() as $id => $section ) {
            if ( $section->check_capabilities() ) {
                $settings['sections'][ $id ] = $section->json();
            }
        }

        


    if ( ! wp_get_theme( $stylesheet )->exists() ) {
        $status['errorMessage'] = __( 'The requested theme does not exist.' );
        wp_send_json_error( $status );
    }

    // Check filesystem credentials. `delete_theme()` will bail otherwise.     $url = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );

    ob_start();
    $credentials = request_filesystem_credentials( $url );
    ob_end_clean();

    if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
        global $wp_filesystem;

        $status['errorCode']    = 'unable_to_connect_to_filesystem';
        $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );

        // Pass through the error from WP_Filesystem if one was raised.         if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
            $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
        }
Home | Imprint | This part of the site doesn't use cookies.