Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I write a php code that read text file and it is working fine with no problem , have a look at this code.
PHP
<?php
function Read($filepath)
{
$myfile = fopen($filepath,"r") or die("Unable to open file!");
$label=fread($myfile,filesize($filepath));
fclose($myfile);
echo $label;
}
?>

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

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


I need to do the same thing using a wordpress plugin but i can't . have another look on below code
PHP
<?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); ?>


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 .
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900