I'm writing a simple plugin and want some settings in an array in the functions.php file.

I'm thinking of adding this in the theme functions.php

$test = array('haha' => 'hehe');
my_function( $test);

However I need to fetch it by actions and filters in the plugin. For example I have a function like this:

add_action('wp_head', 'tryit');
function tryit() {

I need it to put the $test array in there. Global variables are bad. Is it possible with do_action, add_action, do_filter, apply filter somehow? Example?


1 Answer 1


On top of my head scheme like this should work:

// functions.php

function prefix_get_settings() {
    return array('haha' => 'hehe');

add_filter( 'prefix_default_settings', 'prefix_get_settings', 9 );

// plugin

$default_settings = apply_filters( 'prefix_default_settings', array() );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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