Download the PHP package andrewmead/wordpress-proper without Composer
On this page you can find all versions of the php package andrewmead/wordpress-proper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andrewmead/wordpress-proper
More information about andrewmead/wordpress-proper
Files in andrewmead/wordpress-proper
Package wordpress-proper
Short Description A set of classes you may find useful for WordPress development
License MIT
Informations about the package wordpress-proper
WordPress Proper
A dependency-free set of classes you may find useful for WordPress development.
Docs
- Getting Started
- Periodic
- ::check($option_name, $date_interval): bool
- Number
- ::abbreviate($number, bool $round = false): string
- Timezone
- ::site_timezone(): DateTimeZone
- ::site_offset(): string
- ::site_offset_in_hours(): float
- ::site_offset_in_seconds(): float
- ::utc_timezone(): DateTimeZone
- ::utc_offset(): string
- ::utc_offset_in_hours(): float
- ::utc_offset_in_seconds(): float
Getting Started
WordPress Proper can be installed via composer:
From there, you can pull in whatever module you happen to need:
Periodic
Periodic::check(string $option_name, string|DateInterval $interval): bool
Periodic
gives you a way to periodically do something. It's powered by WordPress options and PHP's DateInterval
class.
It's perfect when you need to do something, but only every once in a while. In the example below, Periodic
is used to run some code once every 30 minutes.
The first argument is name of the option you want to use to back a periodic task. This option will store the last time the periodic task was run.
The second argument is where you define the period you want to wait. This can be represented as a DateInterval
or a valid string duration that the DateInterval
constructor would accept.
Calls to check
will always return a boolean value. The value will be true
if it's time to run the task. The value will be false
if the period of time hasn't passed since the task was last completed.
Number
Abbreviate
Number::abbreviate(int|float $number, bool $round = false): string
The abbreviate
methods abbreviates large numbers such as 742898
into shorter strings such as 743K
.
It provides abbreviations for:
- Thousands -
Number::abbreviate(133300)
returns the string133.3K
- Millions -
Number::abbreviate( 1300000 )
returns the string1.3M
- Billions -
Number::abbreviate( 999000000000 )
returns the string999B
- Trillions -
Number::abbreviate( 1000000000000 )
returns the string1T
Numbers below one thousand are not abbreviated. That means Number::abbreviate(978)
would return the string 978
.
Numbers at or above one quadrillion are not abbreviated. That means Number::abbreviate(1000000000000000)
would return the string 1,000,000,000,000,000
.
Behind the scenes, abbreviate
uses number_format_i18n
from WordPress to internationalize abbreviations. This ensures that Number::abbreviate(1500)
returns the string 1.5K
for en_US
and 1,5K
for de_DE
.
Timezone
A small set of functions that make it a bit easier to work with a WordPress site's timezone.
- ::site_timezone(): DateTimeZone
- ::site_offset(): string
- ::site_offset_in_hours(): float
- ::site_offset_in_seconds(): float
- ::utc_timezone(): DateTimeZone
- ::utc_offset(): string
- ::utc_offset_in_hours(): float
- ::utc_offset_in_seconds(): float
site_timezone
::site_timezone(): DateTimeZone
Get the WordPress site's timezone represent as a PHP DateTimeZone
.
site_offset
::site_offset(): string
Get the offset for the WordPress site's timezone. This is represented as a string. Examples include "-04:00"
, "+08:45"
, and "-11:30"
.
site_offset_in_hours
::site_offset_in_hours(): float
Get the decimal offset for the WordPress site's timezone. This is represented as a float. Examples include -4
, 8.75
, and -11.5
.
site_offset_in_seconds
::site_offset_in_seconds(): int
Get the offset for the WordPress site's timezone in seconds. This is represented as an int. Examples include -14400
, 31500
, and -41400
.
utc_timezone
::utc_timezone(): DateTimeZone
Get a DateTimeZone
instance that represents UTC. This will always return the same value, but serves as a handy counterpart to site_timezone
utc_offset
::utc_offset(): string
Get the offset for UTC. This will always return "+00:00"
. This will always return the same value, but serves as a handy counterpart to site_offset
.
utc_offset_in_hours
::utc_offset_in_hours(): float
Get the decimal offset for UTC. This will always return 0
. This will always return the same value, but serves as a handy counterpart to site_offset_in_hours
.
utc_offset_in_seconds
::utc_offset_in_seconds(): int
Get the decimal offset for UTC. This will always return 0
. This will always return the same value, but serves as a handy counterpart to site_offset_in_seconds
.