0 && $content_length > $post_max_bytes; } /** * Message for the "POST body too large" case. * * @param string $post_max The `post_max_size` ini value (e.g. "8M"). * @return string */ public static function post_max_message( string $post_max = '' ): string { return sprintf( /* translators: 1: post_max_size, 2: remediation guidance. */ __( 'The upload was too large for this server (over the %1$s per-request limit). %2$s', 'agenticdaisy-calendar' ), '' !== $post_max ? $post_max : '?', self::remediation() ); } /** * Read a PHP size directive as a string, normalising the `false` that * `ini_get()` returns for unknown directives to an empty string. * * @param string $directive e.g. "upload_max_filesize". * @return string */ public static function ini_size( string $directive ): string { $value = ini_get( $directive ); return is_string( $value ) ? $value : ''; } /** * Convert a PHP shorthand size ("2M", "8M", "1G", "512K", "1024") to bytes. * * @param string $shorthand The ini shorthand value. * @return int Bytes (0 when unparseable/empty). */ public static function bytes( string $shorthand ): int { $shorthand = trim( $shorthand ); if ( '' === $shorthand ) { return 0; } $value = (int) $shorthand; $unit = strtolower( $shorthand[ strlen( $shorthand ) - 1 ] ); return match ( $unit ) { 'g' => $value * 1024 * 1024 * 1024, 'm' => $value * 1024 * 1024, 'k' => $value * 1024, default => $value, }; } /** * Shared remediation guidance: how to raise the limit or avoid the upload. * * @return string */ private static function remediation(): string { return __( 'To fix it: raise upload_max_filesize and post_max_size — in php.ini, in a .user.ini file in the site root on php-fpm hosts, or in .htaccess on Apache — or ask your host. If you cannot change those, upload the file to your server (for example into wp-content/uploads) with SFTP or your host\'s File Manager and choose it under "Import a file already on the server" below, or run "wp webcal migrate " with WP-CLI. Both bypass the upload limit entirely.', 'agenticdaisy-calendar' ); } }