Title: Using WordPress functions inside classes without constructs?
Last modified: August 20, 2016

---

# Using WordPress functions inside classes without constructs?

 *  Resolved [Jay](https://wordpress.org/support/users/phyrax/)
 * (@phyrax)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/using-wordpress-functions-inside-classes-without-constructs/)
 * Before I begin to ask, please see my file structure
    /functions.php /lib /lib/
   settings.php
 * /functions.php has just a little bit of code, aside from my copyright statments:
 *     ```
       require_once(TEMPLATEPATH.'/../landBaronSl/lib/admin.php');
       require_once(TEMPLATEPATH.'/../landBaronSl/lib/postMeta.php');
       require_once(TEMPLATEPATH.'/../landBaronSl/lib/settings.php');
       require_once(TEMPLATEPATH.'/../landBaronSl/lib/invoke.php');
   
       new lbInvoke;
   
       // Setup the settings and registration variables
       $lbSettings = new lbSettings;
       register_activation_hook(__FILE__,$lbSettings->registerSettings());
       ```
   
 * 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(){
       		$this->__construct();
       	}
   
       	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)

 *  Thread Starter [Jay](https://wordpress.org/support/users/phyrax/)
 * (@phyrax)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/using-wordpress-functions-inside-classes-without-constructs/#post-2486831)
 * FYI this is the only workaround I can see to utilize the plugin functions within
   a class without adding action hooks:
 *     ```
       function __construct(){
       		require_once(ABSPATH.'/wp-admin/includes/plugin.php');
       	}
       ```
   
 * I would still like to know why I have to require a file just to use functions
   that are available anywhere outside the class.
 *  Thread Starter [Jay](https://wordpress.org/support/users/phyrax/)
 * (@phyrax)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/using-wordpress-functions-inside-classes-without-constructs/#post-2487005)
 * 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.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 1 participant
 * Last reply from: [Jay](https://wordpress.org/support/users/phyrax/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/using-wordpress-functions-inside-classes-without-constructs/#post-2487005)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
