I have created a theme options panel for a client however they would like the ability to enter PHP code in the textareas and have it executed on the front end.
However, when they enter the code, it does not display properly in the front end, please see the following two screenshots:
It looks like the code is being stripped when displayed on the front end. Its displayed using this code:
<?php global $options;
foreach ($options as $value) {
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
?>
<?php echo $ag_footer_top; ?>
How can I get it to work properly? Is it possible?
If I enter the following into the theme options:
<?php wp_nav_menu( array( 'theme_location' => 'first','fallback_cb'=> â ) ); ?>
It gets saved INTO the database as:
<?php wp_nav_menu( array( 'theme_location' => 'first','fallback_cb'=> â ) ); ?>
And its displayed on the front end as:
'first','fallback_cb'=> â ) ); ?>
First of all you must prevent WordPress from adding slashes to your content, using something like:
The other thing is that you want your code to be executed… well I do not know how to do this exactly, but a lot of Plugins provide this functionality, like
Linkable Title Html and Php Widget
You should download the Plugin and figure out how it works.
Just take the content of the field from the database now and try to parse it in some way.
Use stripslashes to unescape the string before evaluating/displaying the code.
You should replace
â
with''
you can use this functon of PHP
PHP: eval();
you can take the code in textarea save it to options as string and whenever you want to execute it, retrieve from options and pass it to eval.
Thanks
-Shak
I personally use Exec-PHP. It should be quite easy for your clients to use.