WP插件中的嵌套函数 [英] Nested function in WP Plugin

查看:72
本文介绍了WP插件中的嵌套函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个读取文本文件的PHP代码,它运行正常,没问题,请看看这段代码。

I write a php code that read text file and it is working fine with no problem , have a look at this code.

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



现在如果我尝试在里面使用Read功能以下输入它工作正常




now if i try to use Read function inside below input it works fine

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





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



I need to do the same thing using a wordpress plugin but i can't . have another look on below code

<?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时没有显示任何内容,我认为因为没有访问读取函数,所以如何通过表单创建函数访问Read函数



请记住,如果form_creation()没有嵌套函数,它将工作和形式显示。



now when i use myshortcode nothing displayed and i think that because read function didn't be accessed , so how can Read function be accessed by form creation function

keep in mind , if form_creation() has no nested function , it will work and form displayed .

推荐答案

filepath)
{
filepath) {


myfile = fopen(
myfile = fopen(


filepath, r die( 无法打开文件!);
filepath,"r") or die("Unable to open file!");


这篇关于WP插件中的嵌套函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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