• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 689
  • Last Modified:

Wordpress plugin error "include() [function.include]: Failed opening"

I have a wordpress plugin that throws the following code when you add the shortcode to a post:

Warning: include() [function.include]: Failed opening '/home/magicald/public_html/api3/php_files/api3.php' for inclusion (include_path='.:/usr/local/php52/pear') in /home/magicald/public_html/wp-content/plugins/api3/index.php on line 18

you can see the example at http://www.magicaldvd.com/tron-legacy-2010-12-17/

I have confirmed that all the files are located in the proper directory.  

I have included the code that is throwing the error.

I can't figure it out can someone please help.
<?php
/*
Plugin Name: API 3
Plugin URI: http://e2interactive.com/api3/
Description: Shopping.com API3 PHP Script
Version: 1.0
Author: e2interactive
Author URI: http://e2interactive.com
*/

function e2_add_api_keyword_shortcode($atts) {
	extract(shortcode_atts(array(
		'keyword' => $defaultkeyword,'pid'=>''), $atts));
	if($atts['pid']!=''){
		$keyword='';
		$pidnum = $atts['pid'];
	}
	$api3_output = include($_SERVER['DOCUMENT_ROOT'].'/api3/php_files/api3.php');
	return $api3_output;
}
add_shortcode('api3', 'e2_add_api_keyword_shortcode');

?>

Open in new window

0
dthardy
Asked:
dthardy
2 Solutions
 
stergiumCommented:
Hello dthardy.
Your $_SERVER['DOCUMENT_ROOT'] what does it contain on the current line?
printing this $_SERVER['DOCUMENT_ROOT'].'/api3/php_files/api3.php' do you get the the right path?
probably not.
my best guess is that the path is wrong OR already included. try changing path as a test.
keep it on root for example. how about permissions?...
hope that helps.
please feed back.
0
 
Ray PaseurCommented:
See this statement on line 18 from the code snippet posted with the question:
$api3_output = include($_SERVER['DOCUMENT_ROOT'].'/api3/php_files/api3.php');

The statement obscures the actual path by creating it in the argument of a function.  Please try changing it to this so we can see what the actual, fully-resolved path is:
$api3_pathto = $_SERVER['DOCUMENT_ROOT'] . '/api3/php_files/api3.php';
var_dump($api3_pathto);
$api3_output = include($api3_pathto);

You may find that it is useful to know the current path:
var_dump( getcwd() );

You can see the server variables, including DOCUMENT_ROOT with this script:
<?php phpinfo();

You may want to set error_reporting(E_ALL); to be certain that the code is not relying on an undefined variable or something goofy like that.
0
 
jeremyjared74Commented:
In WordPress the path to the plug-in directory is :
plugins_url(plugin_basename(dirname(__FILE__)));

Open in new window


Your plug-in is pretty much ignoring all best practices for WordPress API.

I couldn't download the plugin to check it, but here the code as I think it should be:

<?php
/*
Plugin Name: API 3
Plugin URI: http://e2interactive.com/api3/
Description: Shopping.com API3 PHP Script
Version: 1.0
Author: e2interactive
Author URI: http://e2interactive.com
*/
if ( ! function_exists('api_keyword_shortcode') ) {
	function apikeeword_paths() {
		if ( !defined('APIKEEWORD') )
			define('APIKEEWORD_URL', plugin_dir_url(__FILE__));
			
		if ( !defined('APIKEEWORD_PATH') )
			define('APIKEEWORD_PATH', plugin_dir_path(__FILE__));
	}
	add_action( 'plugins_loaded', 'api_keyword_shortcode', 50 );
}
function e2_add_api_keyword_shortcode($atts) {
        extract(shortcode_atts(array(
                'keyword' => $defaultkeyword,'pid'=>''), $atts));
        if($atts['pid']!=''){
                $keyword='';
                $pidnum = $atts['pid'];
        }
        $api3_output = include(plugin_dir_path(__FILE__).'/api3/php_files/api3.php');
        return $api3_output;
}
add_shortcode('api3', 'e2_add_api_keyword_shortcode');
?>

Open in new window

View the WordPress codex for more info:
WP Codex LINK
0
 
Ray PaseurCommented:
@jeremyjared74: ... pretty much ignoring all best practices ... -- No kidding!
0
 
dthardyAuthor Commented:
Everyone is correct the plugin I purchased has a lot to be desired.  

It ended up having several problems to fix.  The ideas of dumping the vars and moving the folder around led to the eventual fixes.  There were a few spelling and coding errors in the files the plugin accessed.

Thanks for the help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now