Recent

Helpersclass

Helpers

Helper utilities used across the plugin.

Namespace: WebberZone\Image_Optimizer\Util
Since: 1.0.0
Source: includes/util/class-helpers.php line 19

Methods

get_formats() static

Get target formats in <picture> delivery preference order.

Since: 1.0.0
Line: 47

static public function get_formats(  ): array;

Returns: array — string> Format slugs.

get_mime_type() static

Get the MIME type for a target format.

Since: 1.0.0
Line: 59

static public function get_mime_type( string $format ): string;
Type Name Description
string $format Format slug.

Returns: string — MIME type, or an empty string when unknown.

get_upload_basedir() static

Get the uploads base directory, without the year/month subdirectory.

Since: 1.0.0
Line: 70

static public function get_upload_basedir(  ): string;

Returns: string — Absolute path with no trailing slash, or an empty string on failure.

get_upload_baseurl() static

Get the uploads base URL, without the year/month subdirectory.

Since: 1.0.0
Line: 87

static public function get_upload_baseurl(  ): string;

Returns: string — URL with no trailing slash, or an empty string on failure.

url_to_path() static

Convert an uploads URL to a path, normalizing scheme differences.

Since: 1.0.0
Line: 105

static public function url_to_path( string $url ): string;
Type Name Description
string $url Image URL.

Returns: string — Absolute path, or an empty string when the URL is not local.

path_to_url() static

Convert an absolute file path inside the uploads directory to a URL.

Since: 1.0.0
Line: 150

static public function path_to_url( string $path ): string;
Type Name Description
string $path Absolute file path.

Returns: string — URL, or an empty string when the path is outside the uploads directory.

sanitize_relative_path() static

Strip traversal segments from a relative path.

Since: 1.0.0
Line: 177

static public function sanitize_relative_path( string $relative ): string;
Type Name Description
string $relative Relative path.

Returns: string — Sanitised relative path.

sidecar_path() static

Build the sidecar path for a source file and target format.

Default is append (photo.jpgphoto.jpg.webp); see the sidecar_naming setting.

Since: 1.0.0
Line: 199

static public function sidecar_path( string $file, string $format ): string;
Type Name Description
string $file Absolute path or filename of the source image.
string $format Target format slug.

Returns: string — Sidecar path or filename.

apply_sidecar_naming() static

Apply shared sidecar naming so filesystem paths and URLs agree.

Since: 1.0.0
Line: 212

static public function apply_sidecar_naming( string $path, string $format ): string;
Type Name Description
string $path Absolute path, filename, or URL path.
string $format Target format slug.

Returns: string — Path or URL with the sidecar naming applied.

get_memory_limit() static

Get the PHP memory limit in bytes.

Since: 1.0.0
Line: 227

static public function get_memory_limit(  ): int;

Returns: int — Memory limit in bytes. 0 means unlimited.

can_allocate_image() static

Estimate decode headroom, including intermediate bitmap copies.

Since: 1.0.0
Line: 248

static public function can_allocate_image( int $width, int $height ): bool;
Type Name Description
int $width Image width in pixels.
int $height Image height in pixels.

Returns: bool — True when there is enough headroom, false otherwise.

is_animated_gif() static

Determine whether a GIF file contains more than one frame.

Since: 1.0.0
Line: 279

static public function is_animated_gif( string $file ): bool;
Type Name Description
string $file Absolute path to the file.

Returns: bool — True when the GIF is animated.

format_bytes() static

Format a byte count for display.

Since: 1.0.0
Line: 312

static public function format_bytes( int $bytes ): string;
Type Name Description
int $bytes Number of bytes.

Returns: string — Human readable size.

delete_file() static

Delete a file through the WordPress filesystem hooks.

Since: 1.0.0
Line: 324

static public function delete_file( string $file ): bool;
Type Name Description
string $file Absolute path to the file.

Returns: bool — True when the file no longer exists.