database - update_option with text area containing html and php -


here's have going on. have single form field textarea on plugin's settings page. have far storing content in database correctly. content html/php, more content structure , template tags inside wordpress loop.

i using piece of code insert data in form database when form submits.

if (isset($_post["update_settings"])) {     $custompostlayout = esc_attr($_post["post-layout"]);       update_option('aw_wp_yca_postcontent', $custompostlayout);       } 

then displaying data this:

echo get_option('aw_wp_yca_postcontent'); 

so lets have in form:

<div id="wrapper">     <?php the_title(); ?> </div> 

when go frontend posts should display this:

<div id=\"wrapper\"> <?php the_title(); ?> </div> 

so instead of rendering inside loop outputting string. doing wrong here? i've tried using eval(), not preference, tried various stuff htmlspecialchars() , htmlentities(). i'm not understanding here.

when put in database, storing text string. when pull database, getting that, text string. if echo text string, code executed client code (html, javascript, css, etc.) if execute php code string, yes, going have use eval, not practice. however, don't think storing php in database practice either.

that notwithstanding, reason eval failed because eval() expects string of valid php code, ie, stuff in between <?php , ?>. code starts html, if want eval html properly, need edit bit.

eval("?> <b>foo</b> <?php ;"); 

for example, eval properly:

$myevalstring="?> ".get_option('aw_wp_yca_postcontent'). "<?php ;"; eval($myevalstring); 

another thing make php run code string write file, include it, this:

file_put_contents("/your/file/path/specialcode.php",get_option('aw_wp_yca_postcontent')); //your loop code... include '/your/file/path/specialcode.php'; //.. 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -