WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Category ID Issue (2 posts)

  1. stephenbaugh
    Member
    Posted 5 years ago #

    Hi

    Ok this is a little complex. I am creating a plugin, and want to find the category ID from the Post page.

    That's the easy part.

    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.

    With the ID returned I want to execute some php stored in an sql field. I am trying to do this from with the ob_start function

    <b> $tui_cifp_insertvalue = tui_cifp_evaluate_html($tui_cifp_insertvalue); </b>

    function tui_cifp_evaluate_html($string) {
    return preg_replace_callback("/(<\?php|<\?|< \?php)(.*?)\?>/si",'EvalBuffer', $string);
    }

    // Runs (evals()) a '$string' of PHP code.
    function EvalBuffer($string) {
    ob_start();
    eval("$string[2];");
    $ret = ob_get_contents();
    ob_end_clean();
    return $ret;
    }

    And the php I am trying to execute.

    <?php tui_findPostThumbIMG([categoryID],100,100,"categoryintro-thumbnail","","",""); ?>

    This all works outside the ob_start routine even simple php doesn't work. From within the ob_start routine the plugin breaks and a blank page returns.

    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.


    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]->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'); //

    }

    function tui_cifp_ob_start()
    {

    ob_start('tui_cifp_templatefilter');

    }

    Ok I am stumped ... any ideas?

    Thanks
    Stephen

  2. stephenbaugh
    Member
    Posted 5 years ago #

    You can find a solution to this over at stake overflow.

    http://stackoverflow.com/questions/448470/wordpress-category-id-vs-eval-issue#449848

    Cheers
    Stephen

Topic Closed

This topic has been closed to new replies.

About this Topic