I'm developing a plugin and I try to use a class (following the method of another plugin). But I don't understand why my constants are not globally available. This is my code:
/*
Plugin Name: Some simple plugin
*/
if (!session_id())
session_start();
class myPluginClass {
function __construct() {
/* Set the constants needed by the plugin. */
add_action( 'plugins_loaded', array( &$this, 'constants' ), 1 );
}
function constants() {
$upload_dir = wp_upload_dir();
define( 'SIMPLE_GALLERY_DIR', trailingslashit( str_replace('\\', '/', plugin_dir_path( __FILE__ )) ) );
//This works and outputs http://.....
echo SIMPLE_GALLERY_URL;
}
}
$sg = new simpleGallery();
//This does not work and outputs SIMPLE_GALLERY_URL.
echo SIMPLE_GALLERY_URL;
The result of the above two is:
SIMPLE_GALLERY_URLhttp://.....
This means that my last echo is executed before the class. Or is it?
constants() is attached to the plugins_loaded hook - could it be that this is executed after page is loaded?