Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress Category ID vs Eval Issue
    text
    copied!<p>Ok this is a little complex. I am creating a plugin, and want to find the category ID from the Post page.</p> <p>That's the easy part.</p> <p>What makes it complex is I am doing it within an ob_start (started in a 'template_redirect' action) as I want to edit the full page before it is returned to the browser. Again that is easy enough from the ob_start function.</p> <p>With the ID returned I want to evaluate some php stored in a sql field. I am trying to do this from within the ob_start function</p> <pre><code>$tui_cifp_insertvalue = tui_cifp_evaluate_html($tui_cifp_insertvalue); </code></pre> <p>This calls this</p> <pre><code>function tui_cifp_evaluate_html($string) { return preg_replace_callback("/(&lt;\?php|&lt;\?|&lt; \?php)(.*?)\?&gt;/si",'EvalBuffer', $string); } </code></pre> <p>Which in turn calls</p> <pre><code>function EvalBuffer($string) { ob_start(); eval("$string[2];"); $ret = ob_get_contents(); ob_end_clean(); return $ret; } </code></pre> <p>And the php I am trying to evaluate is.</p> <pre><code>&lt;?php tui_findPostThumbIMG([categoryID],100,100,'categoryintro-thumbnail','','',''); ?&gt; </code></pre> <p>This all works outside the ob_start routine, but here even simple php doesn't work. From within the ob_start routine the plugin breaks and a blank page returns.</p> <p>So I thought I could evaluate the php before the start of the ob_start and pass the result through a global variable. That works, but at the point this starts using the following, the category ID is not available.</p> <pre><code>if ( strpos($_SERVER['REQUEST_URI'], 'wp-admin') === false ) { global $holdvalue; $tui_cifp_insertvalue = get_option('tui_cifp_insertvalue'); $categories = get_the_category(); $categoryID = $categories[0]-&gt;cat_ID; $tui_cifp_insertvalue = str_replace("[categoryID]", $categoryID, $tui_cifp_insertvalue); $holdvalue = tui_cifp_evaluate_html($tui_cifp_insertvalue); add_action('template_redirect','tui_cifp_ob_start'); // } </code></pre> <p>The ob_start function</p> <pre><code>function tui_cifp_ob_start() { ob_start('tui_cifp_templatefilter'); } </code></pre> <p>Ok I am stumped ... any ideas?</p> <p>I either need to find a hook that executes at the right time so that I have access to the category ID, or I need to work out how to evaluate the php during the ob_start.</p> <p>Oh ... I guess I should say. What I want to do is replace a tag on a wordpress page with some other information saved in a string, but need to be able to do this once the full page if drawn.</p> <p>Thanks Stephen</p> <p>PS I have asked this on the wordpress forums without a response. Sorry for the cross posting but I am a little desperate. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload