lucatume/wp-utils

WordPress 工具类。

2.1.10 2014-08-25 14:22 UTC

This package is auto-updated.

Last update: 2024-09-07 20:54:26 UTC


README

一组小型实用工具,用于加速 WordPress 开发。

tad_Script

一个工具类,可以轻松处理脚本和样式后缀。根据 SCRIPT_DEBUG 常量,它将尝试加载压缩版或非压缩版的脚本或样式。

$path = get_stylesheet_directory_uri() . '/assets/css/theme_style.css';
$debugDependantPath = tad_Script::suffix($path);

wp_enqueue_style('theme-style', $debugDependantPath);

tad_Str(ings)

将字符串从一种命名规范转换为另一种命名规范。

$string = 'some_name_here';

// someNameHere
$out = tad_Str::camelBack($string);
// some-name-here
$out = tad_Str::hyphen($string);
// some_name_here
$out = tad_Str::underscore($string);
// SomeNameHere
$out = tad_Str::camelCase($string);
// some/name/here (some\name\here on Win)
$out = tad_Str::toPath($string);

它还包含一些方法,可以基于字符或单词将字符串拆分为行,同时保留 HTML 标签。

$in = "lorem ipsum some other stuff here"

// lorem ipsum some other...
$out = tad_Str::atMostChars($in, 25, '...');

// <span class="line">lorem ipsum</span>
// <span class="line">some other</span>
// <span class="line">stuff here</span>
$out = tad_Str::splitLinesByWords($in, 2);

$in = 'some words are longer than others'

// <span class="line">some words are longer</span>
// <span class="line">than others</span>
$out = tad_Str::splitLinesByChars($in, 25);

tad_Arr(ays)

数组实用工具。

tad_JsObject

一组类似于 WordPress 特定的函数,旨在使在页面上打印 JavaScript 对象变得容易。该类将负责打印包含回调函数的对象。

$in = array(
    'value' => 'hello there',
    'callback' => 'function(){alert("hello there");}'
    );

$out = tad_JsObject::on($in)->getOut();

// or print on the page in WordPress
tad_JsObject::on($in)->localize();

更新日志

  • 2.0.0 - "更新"了包以支持 PHP 5.2
  • 1.1.0 - 第一次公开发布