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!
January 22nd, 2009 at 4:19 pm
Hello my friend,
I found your article after a good search on Google for problems with php and wordpress.
I am having problems, my wordpress is 2.7 and I’m using this php plugin because php_exec wouldn’t install.
http://www.hongkiat.com/blog/execute-php-in-wordpress-post-page-and-widget-sidebar/
Now… when I start with a ‘php include’ it is exactly like your four lines of error messages. So I tried your ABSPATH solution and I now get this different message……
Parse error: syntax error, unexpected ‘:’ in /home/mind1stu/public_html/wp-content/plugins/phpexec.php(61) : eval()’d code on line 3
I will look up this error tonight and let you know how I get on. But, I have never touched php before so it is all a little scary.
Take care,
Brian
January 22nd, 2009 at 4:30 pm
Ooooops, sorry.
I should give you more information. I am trying to call an index php file to open a small shopping cart in the same directory as my wordpress installation. I want the cart to open in the wordpress page, but I can’t call it.
I know what the above message was about…. the ‘:’ was in the http address I used.
Any ideas? I don’t know if it is the plugin, my incorrect directory address or the shopping cart isn’t compatible with the page (it physically fits due to the style being adequate).
Ok, thanks
Brian
January 28th, 2009 at 1:58 pm
Hi…. in the end I have settled for the html iframe command.
Thanks
Brian