renventura/wp-package-parser

v1.0.0 2024-05-22 05:05 UTC

This package is auto-updated.

Last update: 2024-09-24 17:39:11 UTC


README

A PHP library for parsing WordPress plugin and theme metadata. Point it at a ZIP package and it will

  • Tell you whether it contains a plugin or a theme.
  • Give you the metadata from the comment header (Version, Description, Author URI, etc).
  • Parse readme.txt into a list of headers and sections.
  • Convert readme.txt contents from Markdown to HTML.

安装

建议使用 安装 composer 包.

composer require renventura/wp-package-parser

基本用法

提取插件元数据

require 'vendor/autoload.php';
$package = new RenVentura\WPPackageParser\WPPackage('/var/path/plugin.zip');
print_r($package->getMetaData());

示例输出

Array
(
    [name] => Hello Dolly
    [plugin_uri] => https://wordpresstheme.cn/plugins/hello-dolly/
    [version] => 1.6
    [description] => This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page.
    [author] => Matt Mullenweg
    [author_profile] => http://ma.tt/
    [text_domain] => hello-dolly
    [domain_path] => 
    [network] => 
    [plugin] => hello-dolly/hello.php
    [contributors] => Array
        (
            [0] => matt
        )

    [donate] => 
    [tags] => Array
        (
        )

    [requires] => 4.6
    [tested] => 4.7
    [stable] => 1.6
    [short_description] => This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong.
    [sections] => Array
        (
            [description] => 
This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page.


        )

    [readme] => 1
    [slug] => hello-dolly
)

提取主题元数据

require 'vendor/autoload.php';
$package = new RenVentura\WPPackageParser\WPPackage('/var/path/theme.zip');
print_r($package->getMetaData());

示例输出

Array
(
    [name] => Twenty Sixteen
    [theme_uri] => https://wordpresstheme.cn/themes/twentysixteen/
    [description] => Twenty Sixteen is a modernized take on an ever-popular WordPress layout — the horizontal masthead with an optional right sidebar that works perfectly for blogs and websites. It has custom color options with beautiful default color schemes, a harmonious fluid grid using a mobile-first approach, and impeccable polish in every detail. Twenty Sixteen will make your WordPress look beautiful everywhere.
    [author] => the WordPress team
    [author_uri] => https://wordpresstheme.cn/
    [version] => 1.3
    [template] => 
    [status] => 
    [tags] => Array
        (
            [0] => one-column
            [1] => two-columns
            [2] => right-sidebar
            [3] => accessibility-ready
            [4] => custom-background
            [5] => custom-colors
            [6] => custom-header
            [7] => custom-menu
            [8] => editor-style
            [9] => featured-images
            [10] => flexible-header
            [11] => microformats
            [12] => post-formats
            [13] => rtl-language-support
            [14] => sticky-post
            [15] => threaded-comments
            [16] => translation-ready
            [17] => blog
        )

    [text_domain] => twentysixteen
    [domain_path] => 
    [slug] => twentysixteen
)

要求

PHP >= 8.0.

致谢

This was forked from tutv/wp-package-parser. The original project was not updated for many years. I forked it, and modernized it for compatibility with

  • PHP8+
  • PHPUnit v9.6
  • 改进的编码标准
  • Composer 自动加载
  • GitHub Actions 用于自动 CI 测试

所有原始许可保持不变。感谢 @tutv 对其贡献。