Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am encountering a strange problem which I couldn't solve so far.

I'm calling a .php script via cronjob (Debian/GNU Linux). To use wordpress functionailty I added:

define('WP_USE_THEMES', false);
require( '/full/path/to/wp-blog-header.php' );

Now database queries and default wordpress functionality all works fine, but I also call some functions provided by a plugin (namely advanced custom fields, the problem however affects other plugins as well as I tested) the following php error is returned:

PHP Fatal error:  Call to undefined function update_field() in executed.php on line 24

Which tells me that the function of that plugin has not been included. So it seems to me that require wp-blog-header.php dies not include plugin functionality (which it did when I started to develop the mentioned script, but now when I tested it, it produced an php error that).

Could it be, that the 3.5 upgrade of wordpress changed something here? Or does anyone of you has some piece of advice for me as to why this problem occures? Thank you!

edit

I made further tests. The problem seems to be, that I am executing the php in the shell using following command:

/usr/bin/php5 -q -d memory_limit=256M /path/to/executed.php

Thus certain variables are not set like $_SERVER['REQUEST_METHOD'] Wordpress would therefore give me warnings in debug-mode. So what I did is, I definied the DOCUMENT_ROOT variable, and included my function.php (which was alos not loaded) manualy:

$_SERVER['DOCUMENT_ROOT'] = '/full/path/to/my/document/root/';
define('WP_USE_THEMES', false);
require( '/full/path/to/wp-blog-header.php' );
require_once( '/full/path/to/themes/mytheme/functions.php' );

Now it is working. Yet it seems to me as a mere unhealthy walkaround ...

share|improve this question
add comment

2 Answers

You're probably calling the function before it's defined - why not hook into it?

Something like:

function someFunction() {
  require( '/full/path/to/wp-blog-header.php' );
} 
add_action('some_hook', 'someFunction');

Note: You might try the plugins_loaded hook.

share|improve this answer
    
Thank's for your suggestion. Since requiring the wp-blog-hreader.php sets up wordpress functions this solution doesn't work. The "add_actio" function has not been initialized. I tried to wrap my problematic function in your suggested one which resulted in this function not being executed at all. –  antix Jan 5 '13 at 20:31
add comment

I'm not sure if this solution will work, but try require_once the Plugin's main PHP file into your cron-job PHP file or you may simply recreate the functionality of that plugin in your own PHP to get the tasks of that Plugin done.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.