PHP in Tablepress not working
-
how can i use php inside tablepress cells.Also tried “PHP in tables” Plugin ,but no success,Please help me …
-
Hi,
thanks for your post, and sorry for the trouble.
Please provide more details here, like what error messages you are getting, or what exactly is not working.
Can you maybe provide a link to the table?Regards,
Tobiasthanks for the reply,
The table i used from tablepress is used in this page,
https://ccdsiu.byethost13.com/sadasd/
But i am not getting php code executed in tablepress cells.
I am getting blank cell where php code is inserted…
<?php /* Plugin Name: PHP Exec Plugin URI: https://priyadi.net/archives/2005/03/02/wordpress-php-exec-plugin/ Description: Execute PHP Code inside a post. Do NOT use this plugin if you don't trust your WP users. Version: 1.7 Author: Priyadi Iman Nurcahyo Author URI: https://priyadi.net/ Inspired by runphp plugin by Mark Somerville https://mark.scottishclimbs.com/archives/2004/07/02/running-php-in-wordpress-posts/ */ ### mask code before going to the nasty balanceTags ### function php_exec_pre($text) { $textarr = preg_split("/(<phpcode>.*<\\/phpcode>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between $stop = count($textarr);// loop stuff for ($phpexec_i = 0; $phpexec_i < $stop; $phpexec_i++) { $content = $textarr[$phpexec_i]; if (preg_match("/^<phpcode>(.*)<\\/phpcode>/Us", $content, $code)) { // If it's a phpcode $content = '[phpcode]' . base64_encode($code[1]) . '[/phpcode]'; } $output .= $content; } return $output; } ### unmask code after balanceTags ### function php_exec_post($text) { $textarr = preg_split("/(\\[phpcode\\].*\\[\\/phpcode\\])/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between $stop = count($textarr);// loop stuff for ($phpexec_i = 0; $phpexec_i < $stop; $phpexec_i++) { $content = $textarr[$phpexec_i]; if (preg_match("/^\\[phpcode\\](.*)\\[\\/phpcode\\]/Us", $content, $code)) { // If it's a phpcode $content = '<phpcode>' . base64_decode($code[1]) . '</phpcode>'; } $output .= $content; } return $output; } ### main routine ### function php_exec_process($phpexec_text) { $phpexec_userdata = get_userdatabylogin(the_author('login',false)); if($phpexec_userdata->user_level >= php_exec_getuserlevel()){ $phpexec_doeval = true; } $phpexec_textarr = preg_split("/(<phpcode>.*<\\/phpcode>)/Us", $phpexec_text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between $phpexec_stop = count($phpexec_textarr);// loop stuff for ($phpexec_i = 0; $phpexec_i < $phpexec_stop; $phpexec_i++) { $phpexec_content = $phpexec_textarr[$phpexec_i]; if (preg_match("/^<phpcode>(.*)<\\/phpcode>/Us", $phpexec_content, $phpexec_code)) { // If it's a phpcode $phpexec_php = $phpexec_code[1]; if ($phpexec_doeval) { ob_start(); eval("?>". $phpexec_php . "<?php "); $phpexec_output .= ob_get_clean(); } else { $phpexec_output .= htmlspecialchars($phpexec_php); } } else { $phpexec_output .= $phpexec_content; } } return $phpexec_output; } function php_exec_options() { if($_POST['php_exec_save']){ update_option('php_exec_userlevel',$_POST['php_exec_userlevel']); echo '<div class="updated"><p>User level saved successfully.</p></div>'; } ?> <div class="wrap"> <h2>PHPExec Options</h2> <form method="post" id="php_exec_options"> <fieldset class="options"> <legend>Minimum User Level</legend> <table width="100%" cellspacing="2" cellpadding="5" class="editform"> <tr valign="top"> <th width="33%" scope="row">User Level:</th> <td><input name="php_exec_userlevel" type="text" id="php_exec_userlevel" value="<?php echo get_option('php_exec_userlevel') ;?>" size="2" maxlength="1" /> <br />Sets the minimum level to allow users to run PHP code in posts. If option is not set, then defaults to 9.</td> </tr> </table> <p class="submit"><input type="submit" name="php_exec_save" value="Save" /></p> </fieldset> </form> </div> <?php } function php_exec_adminmenu(){ add_options_page('PHPExec Options', 'PHPExec', 9, 'phpexec.php', 'php_exec_options'); } function php_exec_getuserlevel(){ if($level = get_option('php_exec_userlevel')){ return $level; } else { return 9; } } add_action('admin_menu','php_exec_adminmenu',1); add_filter('content_save_pre', 'php_exec_pre', 29); add_filter('content_save_pre', 'php_exec_post', 71); add_filter('the_content', 'php_exec_process', 2); add_filter('excerpt_save_pre', 'php_exec_pre', 29); add_filter('excerpt_save_pre', 'php_exec_post', 71); add_filter('the_excerpt', 'php_exec_process', 2);
the above code is installed to run php in my site..Please help me
Hi,
the code that you posted above is not helpful in TablePress tables. That is code to be able to run PHP code in posts and pages.
To be able to run PHP code in cells of TablePress tables, you must install and activate the Extension from https://tablepress.org/extensions/php-in-tables/Regards,
Tobiasi have already installed that plugin..
but no success ??
shall i disable all php plugins , activate https://tablepress.org/extensions/php-in-tables/ and try that?Hi,
yes, please try that.
Then, please also give me an example of the PHP code that you are trying to run in the cell.Regards,
Tobiasi am attaching a pic .you can observe all in it.kindly check it and slove my problem
https://ccdsiu.byethost13.com/gallery/php_code_not_work_tables.jpg
i hope this can give you a clear idea
Hi,
ah, yes, I think I have an idea. The problem might the conversion of line breaks to HTML code.
Please try extending your table’s Shortcode to[table id=123 convert_line_breaks=false /]
Regards,
Tobiasthe first row is appearing now,
<?php
echo do_shortcode(‘[gallery]‘);
?>this is the php code in 2nd row
and this code is not working…Hi,
then there’s either no gallery registered, or it can not determine the current post. This is not something that I can help with, as this is not a problem with TablePress, but with the PHP code that you are using. Sorry.
By the way, why are you doing this as PHP code, instead of simply putting
[gallery]
into the table cell?
Now, as a side note: You seem to be trying to put a gallery into a table cell. That is wrong. A table should contain tabular data (like numbers, etc.), but it should not be used for styling purposes (e.g. to create a column layout). For that, you should use more modern webdesign approaches, e.g. with HTML
<div>
containers and relevant CSS formatting.Regards,
Tobiasya i got it now..Is this problem with gallery shortcode or all shortcodes in php are not executed in tablepress
Hi,
I’m not sure. Other Shortcodes should be fine, as the PHP code is executed in the same “layer” and variable scope as the rest.
Regards,
Tobiasokay thank you.You are the best ..I have other doubts also ,will let you know about them in coming days…Thanks a Ton ??
Hi,
no problem, you are very welcome! ??
Best wishes,
TobiasP.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!
Tobias i also have a question:
I have a tablepress table but the header and the the rows below are not in line.. Here is the picture
As you see, header borders and the column borders are not in line.
Hi,
thanks for your question, and sorry for the trouble.
The reason for that is the usage of the “Horizontal Scrolling” functionality. Unfortunately, that does not always work flawlessly on all sites/tables/themes. ??
You’ll either have to turn that off, or set a fixed column width on all columns of the table, with some CSS code (see the TablePress FAQ for an example. Note that you’ll have to add the
!important
keyword for each assignment). Additionally, you might need to add this (adjusted for your table ID) to the “Custom CSS” textarea:.tablepress-id-123 { table-layout: fixed; }
Regards,
Tobias
- The topic ‘PHP in Tablepress not working’ is closed to new replies.