WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created an array with some default settings in a plugin, and want to allow it to be replaced from functions.php in a theme without using stored data (eg. add_option). I want this to be just a hook with new values.

example array inside plugin:

$default_settings = array(
   'key_one' => 0,
   'key_two' => 1

I need to allow this to be changed from a theme's functions.php, so a developer can add something like this:

function my_function(){
  $default_settings = array(
       'key_one' => 1, //changed value
       'key_two' => 1

If a developer makes this call, then I want the new values replacing the old array inside the plugin. Any help is appreciated.

share|improve this question
up vote 1 down vote accepted

You are already pretty close. Extending your example:

In your plugin put this:

$default_settings = array(
   'key_one' => 0,
   'key_two' => 1
$settings = apply_filters( 'example_filter', $default_settings);

Then a theme can change it like this:

function my_function($settings){
   $settings['key_one'] = 1;
   return $settings;
share|improve this answer
Just make sure to call apply_filters at an appropriate time. – still_learning Mar 21 '14 at 21:00
thanks for this, I do believe I have to call at a time like still_learning mentions, I can't see the new results. I added print_r($settings); right after $settings = apply_filters.... but I'm still getting the old values. Example: Array ( [key_one] => 0 [key_two] => 1 ) – Alex Pena Mar 21 '14 at 21:37
sorry, just figured out what i had to do, thanks. I added this into a new function, then an action with init. Works now. – Alex Pena Mar 21 '14 at 21:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.