WordPress – Executing PHP in Theme Options Panel

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:

Read More

http://i.imgur.com/alOAD.png

http://i.imgur.com/pYhW0.png

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'=&gt; ” ) ); ?&gt;

Related posts

Leave a Reply

5 comments

  1. First of all you must prevent WordPress from adding slashes to your content, using something like:

    update_option('my_option',stripslashes($_POST['my_option']));
    

    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.