Nested function in WP Plugin
-
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; } ?>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");?>" />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); ?>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 .
The topic ‘Nested function in WP Plugin’ is closed to new replies.