From 7f586ef47e48f06c455fc230d82f8d8b8be1c402 Mon Sep 17 00:00:00 2001 From: Mykyta Synelnikov Date: Tue, 18 Mar 2025 17:28:15 +0200 Subject: [PATCH] Update Ultimate Member to version 2.10.2 with filesystem fixes Introduced `maybe_init_wp_filesystem` for better WP_Filesystem initialization and added new utility methods like `remove_dir`. Improved cache handling and documentation annotations for several methods. These changes enhance file management and ensure smoother integration. --- includes/common/class-filesystem.php | 74 +++++++++++++++++++++++----- includes/common/class-users.php | 2 + ultimate-member.php | 2 +- 3 files changed, 65 insertions(+), 13 deletions(-) diff --git a/includes/common/class-filesystem.php b/includes/common/class-filesystem.php index b5b092d0..08893460 100644 --- a/includes/common/class-filesystem.php +++ b/includes/common/class-filesystem.php @@ -59,6 +59,13 @@ class Filesystem { $this->temp_upload_url = $this->get_upload_url( 'ultimatemember/temp' ); } + /** + * Files Age in the temp folder. By default, it's 24 hours. + * + * @return int Temp file age in seconds. + * @since 2.8.7 + * + */ public function files_age() { /** * Filters the maximum file age in the temp folder. By default, it's 24 hours. @@ -73,6 +80,17 @@ class Filesystem { return apply_filters( 'um_filesystem_max_file_age', 24 * HOUR_IN_SECONDS ); // Temp file age in seconds } + /** + * Image MIME Types + * + * Retrieves a list of image MIME types based on the context. + * + * @param string $context The context in which the MIME types are needed ('list' or 'allowed'). + * + * @return array List of image MIME types based on the context. + * + * @since 2.8.7 + */ public static function image_mimes( $context = 'list' ) { $mimes = array(); @@ -148,12 +166,7 @@ class Filesystem { public function clear_temp_dir() { global $wp_filesystem; - if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { - require_once ABSPATH . 'wp-admin/includes/file.php'; - - $credentials = request_filesystem_credentials( site_url() ); - WP_Filesystem( $credentials ); - } + self::maybe_init_wp_filesystem(); if ( ! $wp_filesystem->is_dir( $this->temp_upload_dir ) ) { return; @@ -197,12 +210,7 @@ class Filesystem { // Please add define('FS_METHOD', 'direct'); to avoid question about FTP. global $wp_filesystem; - if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { - require_once ABSPATH . 'wp-admin/includes/file.php'; - - $credentials = request_filesystem_credentials( site_url() ); - WP_Filesystem( $credentials ); - } + self::maybe_init_wp_filesystem(); if ( ! $blog_id ) { $blog_id = get_current_blog_id(); @@ -290,4 +298,46 @@ class Filesystem { return ''; } + + /** + * Probably define global $wp_filesystem. + * + * @since 2.10.2 + * + * @return void + */ + public static function maybe_init_wp_filesystem() { + global $wp_filesystem; + + // If you need to fix this issue on the localhost + // https://stackoverflow.com/questions/30688431/wordpress-needs-the-ftp-credentials-to-update-plugins + // Please add define('FS_METHOD', 'direct'); to avoid question about FTP. + if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { + require_once ABSPATH . 'wp-admin/includes/file.php'; + + $credentials = request_filesystem_credentials( site_url() ); + WP_Filesystem( $credentials ); + } + } + + /** + * Remove a directory using WP Filesystem. + * + * @param string $dir The directory path to be removed. Should end with DIRECTORY_SEPARATOR. + * + * @return bool True on success, false on failure or if directory doesn't exist. + * + * @since 2.10.2 + */ + public static function remove_dir( $dir ) { + global $wp_filesystem; + + self::maybe_init_wp_filesystem(); + + if ( ! $wp_filesystem->is_dir( $dir ) ) { + return false; + } + + return $wp_filesystem->delete( $dir, true ); + } } diff --git a/includes/common/class-users.php b/includes/common/class-users.php index b3c4a207..e6fcaa5e 100644 --- a/includes/common/class-users.php +++ b/includes/common/class-users.php @@ -216,6 +216,8 @@ class Users { /** * Reset User cache * + * @since 2.8.7 + * * @param int $user_id User ID. */ public function remove_cache( $user_id ) { diff --git a/ultimate-member.php b/ultimate-member.php index 54da7c77..960538ca 100644 --- a/ultimate-member.php +++ b/ultimate-member.php @@ -3,7 +3,7 @@ * Plugin Name: Ultimate Member * Plugin URI: http://ultimatemember.com/ * Description: The easiest way to create powerful online communities and beautiful user profiles with WordPress - * Version: 2.10.1 + * Version: 2.10.2 * Author: Ultimate Member * Author URI: http://ultimatemember.com/ * Text Domain: ultimate-member