$wp_memory_limit, 'php_memory_limit' => $php_memory_limit, 'effective_bytes' => $effective_limit, 'effective_mb' => round( $effective_limit / 1024 / 1024 ), ); $limit_mb = $details['effective_mb']; if ( $limit_mb < 64 ) { return static::fail( 'high', sprintf( /* translators: %d: memory in MB */ \__( 'Your PHP memory limit is only %d MB. This is very low and may cause errors on your site, especially when using page builders or uploading images.', '0-day-analytics' ), $limit_mb ), \__( 'Contact your hosting provider to increase the memory limit to at least 256 MB. You can also try adding define(\'WP_MEMORY_LIMIT\', \'256M\'); to wp-config.php.', '0-day-analytics' ), $details ); } if ( $limit_mb < 128 ) { return static::warning( sprintf( /* translators: %d: memory in MB */ \__( 'Your PHP memory limit is %d MB. While this may work for basic sites, you may encounter issues with larger pages or media uploads.', '0-day-analytics' ), $limit_mb ), \__( 'Consider increasing to 256 MB for more headroom. Add define(\'WP_MEMORY_LIMIT\', \'256M\'); to wp-config.php or contact your host.', '0-day-analytics' ), $details ); } if ( $limit_mb < 256 ) { return static::info( sprintf( /* translators: %d: memory in MB */ \__( 'Your PHP memory limit is %d MB. This is adequate for most sites, though complex sites with page builders may benefit from 256 MB.', '0-day-analytics' ), $limit_mb ), $details ); } return static::pass( sprintf( /* translators: %d: memory in MB */ \__( 'Your PHP memory limit is %d MB, which provides plenty of headroom for WordPress and plugins to operate.', '0-day-analytics' ), $limit_mb ), $details ); } /** * Convert memory string to bytes. * * @param string $value Memory value string (e.g., '256M'). * * @return int Bytes. * * @since 4.9.0 * * The memory limit can be specified in php.ini or wp-config.php using shorthand notation (e.g., '256M' for 256 megabytes). This function converts those values into bytes for easier comparison. * * It handles the following cases: * - Unlimited: '-1' is treated as unlimited and returns PHP_INT_MAX. * - Gigabytes (G): Multiplies the number by 1024^3. * - Megabytes (M): Multiplies the number by 1024^2. * - Kilobytes (K): Multiplies the number by 1024. * - Bytes: If no unit is specified, it treats the value as bytes. * * Example usage: * - '256M' => 268435456 bytes * - '1G' => 1073741824 bytes * - '512K' => 524288 bytes * - '-1' => PHP_INT_MAX (unlimited) */ private static function convert_to_bytes( $value ) { $value = trim( $value ); if ( '-1' === $value ) { // Unlimited - return a very high number. return PHP_INT_MAX; } $unit = strtoupper( substr( $value, -1 ) ); $num = (int) $value; switch ( $unit ) { case 'G': return $num * 1024 * 1024 * 1024; case 'M': return $num * 1024 * 1024; case 'K': return $num * 1024; default: return $num; } } } }