filesystem_initialized ) { if ( ! class_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); $this->filesystem_initialized = true; } return true; } /** * Unzips a file to a specified location. * * @param string $path Path to the ZIP file. * @param string $to Destination directory. * @return bool|WP_Error True on success, WP_Error on failure. */ public function wp_unzip_file( $path, $to ) { $this->wp_init_filesystem(); return unzip_file( $path, $to ); } /** * Retrieves the upload directory information. * * @return array Array of upload directory information. */ public function wp_upload_dir() { return \wp_upload_dir(); } /** * Retrieves the root directory of the current theme. * * @return string The root directory of the current theme. */ public function wp_get_theme_root() { return \get_theme_root(); } /** * Checks if a variable is a WP_Error. * * @param mixed $thing Variable to check. * @return bool True if the variable is a WP_Error, false otherwise. */ public function is_wp_error( $thing ) { return is_wp_error( $thing ); } /** * Downloads a file from a URL. * * @param string $url The URL of the file to download. * @return string|WP_Error The local file path on success, WP_Error on failure. */ public function wp_download_url( $url ) { if ( ! function_exists( 'download_url' ) ) { include ABSPATH . '/wp-admin/includes/file.php'; } return download_url( $url ); } /** * Alias for WP_Filesystem::put_contents(). * * @param string $file_path The path to the file to write. * @param mixed $content The data to write to the file. * * @return mixed */ public function wp_filesystem_put_contents( $file_path, $content ) { global $wp_filesystem; $this->wp_init_filesystem(); return $wp_filesystem->put_contents( $file_path, $content ); } }