I'm making a simple theme framework for personal use and I'm try to set up various options in a class.
Basically, I want to use add_action within my class but the function doesn't seem to be firing (but neither am I getting any errors). I've searched for an answer to this but can't find anything that helped.
What am I doing wrong here?
<?php
class Theme {
private $settings;
public function __construct($settings)
{
$this->settings = $settings;
add_action('after_setup_theme', array(&$this, 'boco_set_permalink_structure'));
}
/*
| --------------------------------------------------------------------
| Set Permalink Structure
| --------------------------------------------------------------------
|
| Changes the Wordpress permalink structure.
|
*/
public function boco_set_permalink_structure()
{
echo 'working...';
global $wp_rewrite;
if ($this->settings['change-permalink-structure']):
$wp_rewrite->set_permalink_structure($this->settings['permalink-structure']);
flush_rewrite_rules();
endif;
}
}
I'm instantiating the object like so:
$theme = new Theme($settings);
If I call the boco_set_permalink_structure method manually it works just fine. It just seems that add_action isn't actually doing anything.
Thanks in advance for any help.
EDIT:
As requested in the comments:
The object is instantiated from a file which is included into the functions.php file. $settings is setup as follows:
$settings['change-permalink-structure'] = true;
$settings['permalink-structure'] = '/%postname%/';
$settings['enable-post-thumbnails'] = true;
after_setup_theme
is activated.$settings
holds when instantiating?working...
debug message? You should consider using a more specific class name,Theme
is rather general. The hookafter_setup_theme
is activated afterfunctions.php
so that should be fine.