Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

lets say I have my main plugin file. mainpluginfile.php

I also have a function that is not yet included the file like,

function my_function_to_be_added(){

  echo 'hello this is a test';

}
add_action('wp_head','my_function_to_be_added');

SO how can I go about including the file when a click on something let say a button that I have in the admin page.

so that when I activate the plugin, this function does not exist until when I click the button that's when it is added into the plugin.

Is this accomplishable?

thanks.

share|improve this question
clarify the downvote please. – Ronny Jul 7 '12 at 13:25
1  
You didn’t explain why the function has to be declared by JavaScript – which is impossible as you probably know. – toscho Jul 7 '12 at 13:49

closed as not a real question by toscho Oct 9 '12 at 22:12

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

2 Answers

As @toscho points out, the answer is: no, it is not acomplishable.

If you go the regular way, you'll have a checkbox in your plugin's page that, when enabled and the options are saved/updated, will activate the action hook.

share|improve this answer
Or we are misunderstanding your question, in which case you should rephrase/reframe it.... – brasofilo Jul 7 '12 at 15:16

go ahead and include the function in your mainpluginfile.php

then, add the action conditionally on if the button has been pressed.

if( get_option( 'some_option' ) ) add_action('wp_head','my_function_to_be_added');

bind your button to a function that updates the option.

share|improve this answer

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