• linchen

    (@linchen)


    Hello
    i added this extension (and activate plugin) but PHP dont work

    <?php
    /*
    Plugin Name: WP-Table Reloaded Extensions
    Plugin URI: https://tobias.baethge.com/wordpress-plugins/wp-table-reloaded-english/extensions/
    Description: Custom Extensions for WP-Table Reloaded
    Version: 1.0
    Author: YOU, Tobias Baethge
    */
    /**
     * Executes PHP code in table cells
     * @author Tobias Baethge
     * @see https://tobias.baethge.com/2010/02/extension-5-how-to-use-php-in-table-cells/
     */
    function wp_table_reloaded_execute_php_in_cells( $cell_content ) {
        ob_start();
        eval( '?>' . $cell_content );
        $output = ob_get_clean();
        return $output;
    }
    add_filter( 'wp_table_reloaded_cell_content', 'wp_table_reloaded_execute_php_in_cells' );
    ?>

    This is working:
    <?php echo "Hallo";?>
    This dont work
    <?php echo $hallo;?>
    The variable is exist and not empty.

    I use WordPress 3.1

    Greeting
    Linchen

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi Linchen,

    thanks for your question.

    You have to be careful with variables here: Where (in what scope) does the $hallo variable exist? Was it defined directly inside the table cell? Or is defined outside of the cell? In that case, you will need to make it global, with a statement like this:

    global $hallo;

    at the beginning of your cell.

    Also, there is an important thing that you have to keep in mind when using the PHP Extension in WP-Table Reloaded 1.9.1:
    You must turn of table output caching for all tables that use PHP (otherwise your PHP code will only be executed once daily), by unchecking the corresponsing checkbox on the table’s “Edit” screen.

    Regards,
    Tobias

    Thread Starter linchen

    (@linchen)

    Thanks Tobias
    if i write in my Post <?php echo $hallo;?> everything is fine
    but if i write this in the table cell with global or without the cell is empty. Turn off caching ? Where ?

    Regards
    Linchen

    Thread Starter linchen

    (@linchen)

    Me again
    Cache Table Output: The resulting HTML output of the table shall be cached in the WordPress database cache for faster page generation.
    is not activated.

    Regards
    Linchen

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ok, thanks for testing this.
    Not sure, why this is happening then… Where is $hallo defined or filled with content?
    And: Do you get any PHP errors somewhere, e.g. in the error log on your server?
    You might also need to set the “WP_DEBUG” constant to true in your wp-config.php to see errors.
    Can you try that?

    Regards,
    Tobias

    Thread Starter linchen

    (@linchen)

    Hello Tobias
    thanks for your answer.

    For show php in the posts i use the plugin PHP Execution.
    I have to include the include.php in every post for use the variables.

    The Error Log is empty.

    I put a table in the widget (text), maybe thats the problem ?

    Regards
    Linchen

    Thread Starter linchen

    (@linchen)

    Hi
    i installed PHP code widget now, but same result.

    <?php
    include_once('include.php');
    echo "$hallo";
    [table id=8 /]
    ?>

    Regards
    Linchen

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for that description.

    Now I’m a little bit confused ?? So, you are having a plugin to use PHP in posts, and my Extension to use PHP in table cells, right?

    In the code you posted, you are using a Shortcode inside of PHP. This will never work though, as Shortcodes have nothing to do with PHP. You should actually get a PHP parse error from that.
    Did you mean

    <?php
    include_once('include.php');
    echo "$hallo";
    ?>
    [table id=8 /]

    But then, what is the PHP code in the table cells of table 8?

    You might also need to use include() instead of include_once(), so that your file is actually included every time. Otherwise the variables will not exist in the function’s scope.

    Tobias

    Thread Starter linchen

    (@linchen)

    Hello Tobias
    i was trying the include.php is included or not in the widget.
    Sorry for my not really good description.
    This is correct

    <?php
    include_once('include.php');
    echo "$hallo";
    ?>
    [table id=8 /]

    Include php
    <?php $hallo="hallo";?>

    Widget

    <?php
    include_once('include.php');
    echo "$hallo";
    ?>
    [table id=8 /]

    Table 8 (cell)
    echo "$hallo";

    Widget is empty, cell is empty
    Regards
    Linchen

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ok, thanks for the clarification.

    Please try this:
    include.php

    <?php $hallo="hallo";?>

    widget (no PHP here!)

    [table id=8 /]

    cell (with the PHP extension for WP-Table Reloaded enabled)

    <?php
    include( 'include.php' );
    echo $hallo;
    ?>

    (Note: I’m not sure right now, where the include.php needs to be located, so that the include call can find it. You might need to experiment with some “../..” in front of the file name, or use an absolute path.)

    Tobias

    Thread Starter linchen

    (@linchen)

    Hallo Tobias
    thanks for your patience
    your cell code show me a error:

    Parse error: syntax error, unexpected '>' in /httpdocs/wp-content/plugins/wp-table-reloaded-extensions.php(16) : eval()'d code on line 1

    Regards
    Linchen

    Thread Starter linchen

    (@linchen)

    Hello again
    the problem is the include of the file this example work

    <?php
    $hallo="hallo";
    echo $hallo;
    ?>

    Regards
    Linchen

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi Linchen,

    yes, as I said, the location of the include.php is important.
    I’m not sure how file inclusion in terms of the file path is handled in eval().

    Try this PHP:

    <?php
    echo __FILE__;
    ?>

    This should result in something like “/www/user/httpdocs/wp-content/plugins/wp-table-reloaded-extensions.php”.
    Then take the first part of that and adjust it to the path for the include.php, probably something like “/www/user/httpdocs/include.php”, if your include.php is in the main directory of WordPress.
    Then use that path in the include() call, i.e.

    <?php
    include( 'www/user/httpdocs/include.php' );
    echo $hallo;
    ?>

    Regards,
    Tobias

    Thread Starter linchen

    (@linchen)

    Hello Tobias
    i tryed with absolute path, with http path and all what i found in the internet but it doesnt work.

    Regards
    Linchen

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ok. If you want, I can take a direct look at it in your admin area.
    For that, can you email me (address is in the main plugin file “wp-table-reloaded.php”)?

    Regards,
    Tobias

    Thread Starter linchen

    (@linchen)

    Hi
    i found the problem, it works only if you use php without space`<?php
    include(‘www/user/httpdocs/include.php’);echo $hallo;?>`

    Thanks
    Linchen

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘[Plugin: WP-Table Reloaded] PHP Extensions dont show variables’ is closed to new replies.