errors->get_error_code() ) { $error = $wp_filesystem->errors; } // Failed to connect, Error and request again. ob_start(); request_filesystem_credentials( '', '', $error, $directories[0] ); ob_end_clean(); return false; } if ( ! is_object( $wp_filesystem) ) { return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.', 'advanced-ads' ) ); } if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { return new WP_Error( 'fs_error', __( 'Filesystem error.', 'advanced-ads' ), $wp_filesystem->errors); } foreach ( (array) $directories as $dir ) { switch ( $dir ) { case ABSPATH: if ( ! $wp_filesystem->abspath() ) return new WP_Error( 'fs_no_root_dir', __( 'Unable to locate WordPress root directory.', 'advanced-ads' ) ); break; case WP_CONTENT_DIR: if ( ! $wp_filesystem->wp_content_dir() ) return new WP_Error( 'fs_no_content_dir', __( 'Unable to locate WordPress content directory (wp-content).', 'advanced-ads' ) ); break; default: if ( ! $wp_filesystem->find_folder( $dir ) ) return new WP_Error( 'fs_no_folder', sprintf( __( 'Unable to locate needed folder (%s).', 'advanced-ads' ) , esc_html( basename( $dir ) ) ) ); break; } } return true; } /** * Replace the 'direct' absolute path with the Filesystem API path. Useful only when the 'direct' method is not used. * Check https://codex.wordpress.org/Filesystem_API for info * * @param string existing path * @return string normalized path */ public function normalize_path( $path ) { global $wp_filesystem; return str_replace( ABSPATH, $wp_filesystem->abspath(), $path ); } /** * Print the filesystem credentials modal when needed. */ public function 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 = ( $filesystem_method != 'direct' && ! $filesystem_credentials_are_stored ); if ( ! $request_filesystem_credentials ) { return; } ?>