/**
  * Determines whether the upgrader needs FTP/SSH details in order to connect
  * to the filesystem.
  *
  * @since 3.7.0
  * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
  *
  * @see request_filesystem_credentials()
  *
  * @param bool   $error                        Optional. Whether the current request has failed to connect.
  *                                             Default false.
  * @param string $context                      Optional. Full path to the directory that is tested
  *                                             for being writable. Default empty.
  * @param bool   $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
  * @return bool True on success, false on failure.
  */
 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;
 }
Exemplo n.º 2
0
 /**
  * Connect to the filesystem.
  *
  * @since 2.8.0
  *
  * @param array $directories                  Optional. A list of directories. If any of these do
  *                                            not exist, a {@see WP_Error} object will be returned.
  *                                            Default empty array.
  * @param bool  $allow_relaxed_file_ownership Whether to allow relaxed file ownership.
  *                                            Default false.
  * @return bool|WP_Error True if able to connect, false or a {@see WP_Error} otherwise.
  */
 public function fs_connect($directories = array(), $allow_relaxed_file_ownership = false)
 {
     global $wp_filesystem;
     if (false === ($credentials = $this->skin->request_filesystem_credentials(false, $directories[0], $allow_relaxed_file_ownership))) {
         return false;
     }
     if (!WP_Filesystem($credentials, $directories[0], $allow_relaxed_file_ownership)) {
         $error = true;
         if (is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code()) {
             $error = $wp_filesystem->errors;
         }
         // Failed to connect, Error and request again
         $this->skin->request_filesystem_credentials($error, $directories[0], $allow_relaxed_file_ownership);
         return false;
     }
     if (!is_object($wp_filesystem)) {
         return new WP_Error('fs_unavailable', $this->strings['fs_unavailable']);
     }
     if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
         return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
     }
     foreach ((array) $directories as $dir) {
         switch ($dir) {
             case ABSPATH:
                 if (!$wp_filesystem->abspath()) {
                     return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']);
                 }
                 break;
             case WP_CONTENT_DIR:
                 if (!$wp_filesystem->wp_content_dir()) {
                     return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']);
                 }
                 break;
             case WP_PLUGIN_DIR:
                 if (!$wp_filesystem->wp_plugins_dir()) {
                     return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
                 }
                 break;
             case get_theme_root():
                 if (!$wp_filesystem->wp_themes_dir()) {
                     return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
                 }
                 break;
             default:
                 if (!$wp_filesystem->find_folder($dir)) {
                     return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], esc_html(basename($dir))));
                 }
                 break;
         }
     }
     return true;
 }
 function request_filesystem_credentials($error = false, $context = '')
 {
     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();
     set_current_screen('tools');
     // Only here to avoid PHP Notices from screen_icon() which is used within that HTML
     $result = parent::request_filesystem_credentials($error);
     ob_end_clean();
     return $result;
 }