andrewmead/wordpress-proper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

andrewmead/wordpress-proper

Composer 安装命令:

composer require andrewmead/wordpress-proper

包简介

A set of classes you may find useful for WordPress development

README 文档

README

Build Status

WordPress Proper

A dependency-free set of classes you may find useful for WordPress development.

Docs

Getting Started

WordPress Proper can be installed via composer:

composer require andrewmead/wordpress-proper

From there, you can pull in whatever module you happen to need:

use Proper\Number;

Number::abbreviate(654201); // 654.2K

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.

<?php

use Proper\Periodic;

if (Periodic::check('verify_geo_database_file', 'PT30M')) {
    // Run some code 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.

// Define the period using a string
$should_verify = Periodic::check('verify_geo_database_file', 'PT3S');

// Define the period using a DateInterval
$interval = new DateInterval('PT3S');
$should_verify = Periodic::check('verify_geo_database_file', $interval);

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.

<?php

use Proper\Number;

Number::abbreviate(1260000); // 1.3M

Number::abbreviate(133800); // 133.8K

// Round off decimals 
Number::abbreviate(133800, true); // 134K

It provides abbreviations for:

  1. Thousands - Number::abbreviate(133300) returns the string 133.3K
  2. Millions - Number::abbreviate( 1300000 ) returns the string 1.3M
  3. Billions - Number::abbreviate( 999000000000 ) returns the string 999B
  4. Trillions - Number::abbreviate( 1000000000000 ) returns the string 1T

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

::site_timezone(): DateTimeZone

Get the WordPress site's timezone represent as a PHP DateTimeZone.

<?php

use Proper\Timezone;

Timezone::site_timezone(); // new DateTimeZone('America/New_York')

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".

<?php

use Proper\Timezone;

Timezone::site_offset(); // "-04:00"

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.

<?php

use Proper\Timezone;

Timezone::site_offset_in_hours(); // -4

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.

<?php

use Proper\Timezone;

Timezone::site_offset_in_seconds(); // -14400

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

<?php

use Proper\Timezone;

Timezone::utc_timezone(); // Will always return new DateTimeZone('UTC');

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.

<?php

use Proper\Timezone;

Timezone::utc_offset(); // Will always return "+00:00"

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.

<?php

use Proper\Timezone;

Timezone::utc_offset_in_hours(); // Will always return 0

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.

<?php

use Proper\Timezone;

Timezone::utc_offset_in_seconds(); // Will always return 0

andrewmead/wordpress-proper 适用场景与选型建议

andrewmead/wordpress-proper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.07k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 andrewmead/wordpress-proper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 andrewmead/wordpress-proper 我们能提供哪些服务?
定制开发 / 二次开发

基于 andrewmead/wordpress-proper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-23