在WordPress中,注释行用于查找主题摘要、插件摘要、模板名称等。
例如:
<?php
/*
Template Name: Snarfer
*/
?>WordPress是如何做到这一点的?用来读取注释行的代码。
发布于 2011-08-19 16:28:33
这是在wp-includes/functions.php中的函数get_file_data中完成的,关键代码部分如下:
foreach ( $all_headers as $field => $regex ) {
preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
if ( !empty( ${$field} ) )
${$field} = _cleanup_header_comment( ${$field}[1] );
else
${$field} = '';
}例如,对于插件,它在函数get_plugin_data的wp-admin/includes/plugin.php中被引用
$plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );https://stackoverflow.com/questions/7118485
复制相似问题