WP插件中的嵌套函数


Nested function in WP Plugin

我写了一个读取文本文件的php代码,它工作正常,没有问题,看看这段代码。

<?php
function Read($filepath)
{
$myfile = fopen($filepath,"r") or die("Unable to open file!");
$label=fread($myfile,filesize($filepath));
fclose($myfile);
echo $label;
}
?>

现在,如果我尝试在下面的输入中使用读取功能,它可以正常工作

<input type="text" id="txtname" name="txtname" placeholder="<?php Read("resources/name_ar.txt");?>" />

我需要使用 wordpress 插件做同样的事情,但我不能. 再看看下面的代码

<?php
/*
Plugin Name: my plugin
Description: my plugin
Version: 4.0
Author: me
License: GPL
*/
?>
<?php
//PHP Function to read resources files.
function Read($filepath)
{
$myfile = fopen($filepath,"r") or die("Unable to open file!");
$label=fread($myfile,filesize($filepath));
fclose($myfile);
echo $label;
}
?>
<?php
function  form_creation()
{
    global $wpdb;
    ob_start();
?>
<form action="<?php get_permalink();?>" method="post" id="myform">
<table>
<tr>
<td>
    <h2>Asking Support</h2>
</td>
</tr>
<tr>
<td> <input type="text" id="txtname" name="txtname" placeholder="<?php Read("resources/name_ar.txt");?>" /> </td>
</tr>
</table>
</form>
<?php return ob_get_clean(); } ?>
<?php add_shortcode('myshortcode',form_creation); ?>

现在当我使用 myshortcode 时,什么都没有显示,我认为因为没有访问读取功能,所以如何通过表单创建函数访问读取函数

请记住,如果form_creation()没有嵌套函数,它将工作并显示表单。

似乎"读取"功能找不到该文件。调用函数时,请尝试以下操作:

<?php Read(dirname(__FILE__) . "resources/name_ar.txt");?>