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?


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']):


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.


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;
  • 1
    Where do you instantiate the object? You have to do that before the hook after_setup_theme is activated.
    – birgire
    Jan 25, 2014 at 11:43
  • What data $settings holds when instantiating? Jan 25, 2014 at 12:14
  • Cheers guys, I've added the requested info into the question.
    – 0Neji
    Jan 25, 2014 at 16:57
  • So you don't see the printed working... debug message? You should consider using a more specific class name, Theme is rather general. The hook after_setup_theme is activated after functions.php so that should be fine.
    – birgire
    Jan 25, 2014 at 17:08
  • If I am not mistaken, you are flushing permalinks on every page load. That is very inefficient.
    – s_ha_dum
    Jan 25, 2014 at 17:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.