如何使用PHP解析主题和插件的注释/标题?
Wordpress插件和主题在顶部有如下注释:如何使用PHP解析主题和插件的注释/标题?,php,wordpress,parsing,documentation,comments,Php,Wordpress,Parsing,Documentation,Comments,Wordpress插件和主题在顶部有如下注释: /** * @package Akismet */ /* Plugin Name: Akismet Plugin URI: http://akismet.com/?return=true Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from comment
/**
* @package Akismet
*/
/*
Plugin Name: Akismet
Plugin URI: http://akismet.com/?return=true
Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from comment and trackback spam</strong>. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) <a href="http://akismet.com/get/?return=true">Sign up for an Akismet API key</a>, and 3) Go to your <a href="admin.php?page=akismet-key-config">Akismet configuration</a> page, and save your API key.
Version: 2.5.6
Author: Automattic
Author URI: http://automattic.com/wordpress-plugins/
License: GPLv2 or later
*/
/**
*@packakismet
*/
/*
插件名称:Akismet
插件URI:http://akismet.com/?return=true
描述:Akismet被数百万人使用,它很可能是世界上保护您的博客免受评论和回溯垃圾邮件影响的最佳方式。即使在你睡觉的时候,它也能保护你的网站免受垃圾邮件的攻击。要开始:1)单击本说明左侧的“激活”链接,2)和3)转到页面,保存API密钥。
版本:2.5.6
作者:Automatic
作者URI:http://automattic.com/wordpress-plugins/
许可证:GPLv2或更高版本
*/
当您在管理界面中访问插件页面时,插件如下所示:
这是文档的标准语法吗?我假设它在插件文件上有一个文件获取内容,但是Wordpress如何将其解析为可操作的、标准化的信息,以便在PHP中使用呢 有关WordPress解析器,请参见wp admin/includes/plugin.php
。
更具体地说,提取发生在wp includes/functions.php中:
function get_file_data( $file, $default_headers, $context = '' ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 );
// PHP will close file handle, but we are good citizens.
fclose( $fp );
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
$extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
$all_headers = array_merge( $extra_headers, (array) $default_headers );
} else {
$all_headers = $default_headers;
}
foreach ( $all_headers as $field => $regex ) {
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $ma
$all_headers[ $field ] = _cleanup_header_comment( $match[1] );
else
$all_headers[ $field ] = '';
}
WP之外也有类似的实现。请参阅以获取示例。PHP不会这样做。Wordpress扫描这个评论块(大概是regex)并将其打印出来。@mario-我认为它实际上被解析了,因为他们会提取版本号以用于检查更新等。@guerrla,你不适合将内容添加到其他用户的帖子中。。。尤其是那些可能会模糊实际答案代码的无关内容。因此,我已回滚您的编辑。如果你觉得某篇文章缺少一些重要的信息,那么要么给作者添加一条评论告诉他们,要么添加你自己的文章来提及它。然而,我应该指出,如果你添加了一个答案来显示你在这篇文章中添加的评论,它几乎肯定会被否决,因为这是不相关的。