PHP in tables Extension 1.0
With this Extension, PHP code in table cells will be parsed and executed. This can be useful for dynamic content generation or integration of other plugins’ features. If you can, you should however avoid using this Extension, i.e. by developing your own Shortcode (remember: Those also work in tables!) as you’ll have control of the underlaying PHP code, and not the user who edits a table.
You should only use this Extension, if you are really sure that you need it and if you really know what you are doing: PHP code is very powerful. Code that is run from within the table lives in the same “area” as the WordPress (or plugin) PHP code and thus has the same rights and possibilities. However, it is not solely controlled by the admin, as plugin or WP core files usually are.
This is especially critical, if you have multiple users registered in your WordPress site: Anyone who can edit TablePress tables will be able to insert (and with that cause execution of) PHP code. And with that, he can do a lot of bad things, if he wanted to! What this means: If you want to use this Extension, make sure that only people who you trust can edit TablePress tables. Preferably, this should be only admins of your site. Again: Take this step seriously! If a user can edit tables, he will be able to enter any PHP code he wants!
For the PHP developers: The Extension uses PHP’s eval() function. That function takes a string (in our case the cell content) and executes it as PHP. Due to the internal structure of WordPress Shortcodes, we need some output buffering around that function, so that any outputs will not be sent to the browser directly, but together with the output of the
[table id=N /] Shortcode. (Take this into consideration before using the Extension, as output buffering on a large number of cells might slightly increase the time needed to render a table and the load on your webspace or server.)
Additionally, on certain hosts, the
eval() function might be disabled for security reasons.
To use this Extension, just install and activate it like a regular WordPress plugin. To then use PHP in a table, enter PHP code into your table cells. It has to be valid PHP syntax, including the opening and closing brackets (
?>). In those commands, you can use the regular
echo function to output text. Any text that is not within the brackets will be printed as-is.
If this Extension is helpful for you, please consider supporting further TablePress development with a donation. Thank you!