WordPress如何阅读注释行 [英] How WordPress reading comment lines

查看:66
本文介绍了WordPress如何阅读注释行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WordPress中,注释行用于查找主题摘要,插件摘要,模板名称等.

In WordPress, comment lines are used to find theme summary, plugin summary, template name and so on.

例如:-

<?php
/*
Template Name: Snarfer
*/
?>

WordPress如何做到这一点?用什么代码读取注释行.

How WordPress doing this? What code is used to read comment lines.

推荐答案

这是在wp-includes/functions.php中的函数get_file_data中完成的,其关键代码部分为:

This is done in the function get_file_data in wp-includes/functions.php with the key code section being this:

    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中对其进行了引用:

For example for a plugin it is referenced in wp-admin/includes/plugin.php in the function get_plugin_data:

$plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );

这篇关于WordPress如何阅读注释行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆