Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to use some code that is stored as a settings option in WordPress. When I try to use the following code below however, it show up as plain text instead of executing. The option I have created contains the following PHP code:

echo get_option('profiles_templates_html'. $template .'');
share|improve this question
3  
You are trying to execute the PHP? –  s_ha_dum Mar 31 at 15:25
1  
Storing PHP code in the DB is so, SO wrong. Whatever you're trying to do, don't do it that way. Please. –  Dan Mar 31 at 15:50
    
then how should I do it. I am trying to have a few different templates that I can use. –  venn414 Mar 31 at 16:34
    
Have you wrapped it in <?php ... ?>? –  TheDeadMedic Mar 31 at 16:44
    
as in in the option.. then yes. please help. –  venn414 Mar 31 at 17:48

1 Answer 1

If you really want to execute code stored in a database, a quick google search reveals that you can use the eval() function to do just that. However, many people do say that Eval is Evil...

Instead of storing the entire PHP code of an option in the database, try storing a simple boolean flag for your option and then test whether to get your template's option data from there:

<?php

// Somewhere else in your code, store the settings option upon saving settings
update_option( 'my_setting_for_template', 1 );

// Test if get_option returns 1 from the database
if( get_option( 'my_setting_for_template' ) === 1 )
{
    echo get_option('profiles_templates_html'. $template .'');
}

?>

References:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.