Support » Plugins » Hacks » Using WordPress functions inside classes without constructs?

  • Resolved Jerry


    Before I begin to ask, please see my file structure

    /functions.php has just a little bit of code, aside from my copyright statments:

    new lbInvoke;
    // Setup the settings and registration variables
    $lbSettings = new lbSettings;

    The last line is causing an issue, I get “Fatal error: Call to undefined function register_setting()” and it’s referencing the settings file, line 37. The settings file looks like so:

    class lbSettings{
    	function lbSettings(){
    	function __construct(){
    	public function registerSettings(){
    		$settingsArray = array(
    		// General Settings
    			'lbTemplate',	// The selected template
    		// PostMeta Settings
    			'lbLandTypes', // Land types, will be an array()
    			'lbLandStyle', // Grass, snow, etc... an array of course
    			'lbLandManagers', // Users that will be able to have management options for the box in SL.
    		foreach($settingsArray as $setting){
    			register_setting('lbSettingsGroup', $setting);

    During the last foreach loop is what it’s saying is a fatal error!

    So before you say, “use the action hook in your construct” please know that’s not the solution I’m looking for. So my question is, how come WordPress functions cannot be utilized inside a class when it’s called the way I did? I’m lost and would appreciate an explanation of my failure if possible.

Viewing 2 replies - 1 through 2 (of 2 total)
  • FYI this is the only workaround I can see to utilize the plugin functions within a class without adding action hooks:

    function __construct(){

    I would still like to know why I have to require a file just to use functions that are available anywhere outside the class.

    Well since no one cares to entertain my brain with an explanation, and counting that I have utilized a workaround, I’ll mark this as resolved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using WordPress functions inside classes without constructs?’ is closed to new replies.