piotrpress/wordpress-theme
最新稳定版本:v1.0.0
Composer 安装命令:
composer require piotrpress/wordpress-theme
包简介
This library is WordPress theme singleton base class with methods to get data from theme's header fields.
README 文档
README
This library is WordPress theme singleton base class with methods to get data from theme's header fields.
Installation
composer require piotrpress/wordpress-theme
Usage
/** * Theme Name: Example Theme * Theme URI: https://example.com/theme/ * Description: Example Theme description. * Tags: block-patterns, full-site-editing * Version: 1.0.0 * Tested up to: 6.8 * Requires at least: 6.0 * Requires PHP: 7.4 * Author: John Smith * Author URI: https://example.com/theme/author/ * License: GPL v3 or later * License URI: https://www.gnu.org/licenses/gpl-3.0.txt * Update URI: https://example.com/theme/update/ * Text Domain: example-theme * Domain Path: /languages */ require __DIR__ . '/vendor/autoload.php'; class Example extends \PiotrPress\WordPress\Theme {} echo Example::getName();
Methods
Basic static methods handling theme's default header fields
getName()- returnsstringwith the name of the theme fromTheme Nameheader fieldgetThemeURI()- returnsstringwith the home page of the theme or emptystringifTheme URIheader field is not setgetDescription()- returnsstringwith a short description of the theme or emptystringifDescriptionheader field is not setgetTags()- returnsstringwith the tags of the theme or emptystringifTagsheader field is not setgetVersion()- returnsstringwith the current version number of the theme or emptystringifVersionheader field is not setgetRequiresWP()- returnsstringwith the lowest WordPress version that the theme will work on or emptystringifRequires at leastheader field is not setgetRequiresPHP()- returnsstringwith the minimum required PHP version or emptystringifRequires PHPheader field is not setgetAuthor()- returnsstringwith the name of the theme's author or emptystringifAuthorheader field is not setgetAuthorURI()- returnsstringwith the website of the theme's author or emptystringifAuthor URIheader field is not setgetUpdateURI()- returnsstringwith third-party theme's update server or emptystringifUpdate URIheader field is not setgetTextDomain()- returnsstringwith the gettext text domain of the theme or emptystringifText Domainheader field is not setgetDomainPath()- returnsstringwith the path to translations directory or emptystringifDomain Pathheader field is not set
Additional static methods
getDir()- returnsstringwith the path to theme's directorygetUrl()- returnsstringwith the url to theme's directorygetSlug()- returnsstringwith the sanitized name of the themegetPrefix()- returnsstringwith the prefix for theme's hooks
Inherited Singleton's static methods
getInstance()- returns the instance of the Theme class
Handling custom theme's header fields
- Add WordPress support for extra theme's header fields using
extra_theme_headersfilter:
add_filter( 'extra_theme_headers', function () { return [ 'License', 'License URI' ]; } );
- Add methods to handle extra theme's header fields:
class Example extends \PiotrPress\WordPress\Theme { public static function getLicenseURI() { return self::get( 'License URI' ); } }
NOTE: get prefixed methods are automagically created for theme's header fields that meet valid function name rules. e.g. getLicense() method.
Requirements
PHP >= 7.4 version.
License
统计信息
- 总下载量: 51
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2025-06-12