Problem to include php files from wordpress page or post
I just installed a plugin that allows me to run scripts directly from WordPress pages and posts called exec_php. It worked great as long as I didn’t try to include or require php files.
Problem
For example, these snippets to include and require the existing file Log.php in a page or post
<?php include(”http://www.codeode.com/scripts/Log.php”); ?> or <?php require_once(”/scripts/Log.php”); ?>
would generate the following warnings:
Warning: Unknown(): URL file-access is disabled in the server configuration in /mnt/local/home/codeode/codeode.com/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 4
Warning: Unknown(http://www.codeode.com/scripts/Log.php): failed to open stream: no suitable wrapper could be found in /mnt/local/home/codeode/codeode.com/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 4
Warning: Unknown(http://www.codeode.com/scripts/Log.php): failed to open stream: no suitable wrapper could be found in /mnt/local/home/codeode/codeode.com/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 4
Warning: (null)() [function.include]: Failed opening ‘http://www.codeode.com/scripts/Log.php’ for inclusion (include_path=’.:/usr/local/lib/php’) in /mnt/local/home/codeode/codeode.com/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 4
Ok, as a WordPress rookie I am not completly sure why this is happening in the first place, anyone?
I started to search for solutions to the problem, but couldn’t find any good ones, only cumbersome that indicated me into changing the php.ini.
Solution
I ended up looking into WordPress code and found that they internally are using a variable called ABSPATH. This worked for me with WordPress 2.5.1:
<?php require_once(ABSPATH . “/scripts/Log.php”); ?>
I hope this post helps someone out there ![]()
November 6th, 2008 at 6:33 pm
Haha!!! I was out researching CMS:s and e-commerce solutions and found this blog post! I´m thinking about leaving Wordpress for Drupal - it seems to be MUCH more powerful, even compared to TYPO3. And Wordpress… I dunno…
November 7th, 2008 at 1:18 am
Haha =) I’ve not tested any other CMS than Wordpress but from what I’ve heard Drupal should be good!
December 19th, 2008 at 10:26 pm
Thanks the author!