I'm trying to write a relatively simple plugin. I have two php files, one is included within the other like this:
define( 'PLUGIN_DIR', dirname(__FILE__).'/' );
include_once(PLUGIN_DIR . '/included_file.php');
Things look fine. However I'm getting errors when I try to call some wordpress functions from within the included file:
Fatal error: Call to undefined function xxx() ...
The odd this is, only on some functions but not others. For example, if I place this code at the top of the included file:
if (!function_exists('add_action')) echo "<h1>add_action not found</h1>";
if (!function_exists('check_admin_referer')) echo "<h1>check_admin_referer not found</h1>";
if (!function_exists('wp_verify_nonce')) echo "<h1>wp_verify_nonce not found</h1>";
if (!function_exists('wp_nonce_field')) echo "<h1>wp_nonce_field not found</h1>";
I get this output:
check_admin_referer not found
wp_verify_nonce not found
so only two out of these four functions are accessible in the included file...
I'm probably missing something very basic, but I'm a bit stuck.
UPDATE: I tried creating a very basic plugin:
<?php
/*
Plugin Name: Test this
Plugin URI: http://www.gingerlime.com
Description: test
Author: Yoav Aner
Version: 1.0
Requires at least: 3.1
Author URI: http://blog.gingerlime.com
License: GPL 2.0, @see http://www.gnu.org/licenses/gpl-2.0.html
*/
if (!function_exists('add_action')) echo "<h1>add_action not found</h1>";
if (!function_exists('check_admin_referer')) echo "<h1>check_admin_referer not found</h1>";
if (!function_exists('wp_verify_nonce')) echo "<h1>wp_verify_nonce not found</h1>";
if (!function_exists('wp_nonce_field')) echo "<h1>wp_nonce_field not found</h1>";
if (function_exists('add_action')) echo "<h1>add_action found</h1>";
if (function_exists('check_admin_referer')) echo "<h1>check_admin_referer found</h1>";
if (function_exists('wp_verify_nonce')) echo "<h1>wp_verify_nonce found</h1>";
if (function_exists('wp_nonce_field')) echo "<h1>wp_nonce_field found</h1>";
?>
as soon as the plugin is activated it prints
check_admin_referer not found
wp_verify_nonce not found
add_action found
wp_nonce_field found
I tried it on two wordpress installations. I might try a completely fresh wordpress and see what's going on. Strange.