When a plugin gets updated from the repo, does the “activation” hook fire again?
The activation hook is only fired when the plugin is first activated, not when it’s updated.
The activation hook is only fired when the plugin is first activated, not when it’s updated.
So the ‘activate_plugin’ was a typo in the question. But even so, as a friendly reminder (for all of us), activate_plugin() is an existing function in WordPress. And you should use unique prefix in your custom functions (that are defined in the global scope): function my_plugin_activate_plugin() { … } register_activation_hook( __FILE__, ‘my_plugin_activate_plugin’ ); The Problem … Read more
Link category is a simple taxonomy just like categories , named: link_category so to add one you can use wp_insert_term() eg: wp_insert_term( ‘My link category’, // the term ‘link_category’, // the taxonomy array( ‘description’=> ‘this is a description.’, ‘slug’ => ‘my-link-category’ ) ); and to make all this happen on plugin activation take a look … Read more
images folder is inside theme’s folder. But relative URLs do not work that way. They are relative to the URL not to the filesystem path. Your problem is here: <img id=”thinker01″ src=”https://wordpress.stackexchange.com/questions/74779/images/thinker01.png” width=”120″ height=”163″ /> If you look at the request (via HttpFox or other means) you will see that the browser is looking for … Read more
The basic process – on activation, check if is_multisite, get all of the sites with wp_get_sites, loop over the results with foreach and switch_to_blog for each site ID, and create the table. You’ll also need to hook the wpmu_new_blog action, check if is_plugin_active_for_network, switch to that blog ID and run your activation code, so sites … Read more
My approach to this would be to have a start_activation() method that calls the other methods. register_activation_hook( __FILE__, array( ‘my_plugin_loader’, ‘start_activation’ ) ); class my_plugin_loader { function start_activation() { $this->func1(); // or self::func1(); $this->func2(); // self::func2(); for static methods } function func1() { // do stuff } function func2() { // do other stuff } … Read more
WordPress is not magic. If you add and action hook (register_activation_hook just add an action hook) to WordPress be able to read and run it, have to load your main plugin file, it can’t guess its content. And if WordPress load your main plugin file, it will load all the functions defined there (or in … Read more
Why only the second? Because dbDelta() supports CREATE TABLE table_name format only. I.e. Exactly “CREATE TABLE” followed by (one space and) the table name. More specifically, dbDelta() uses this regular expression pattern: CREATE TABLE ([^ ]*) when parsing the queries into an array indexed by the table name; i.e. array( ‘table_1’ => ‘query’, ‘table_2’ => … Read more
It doesn’t really matter. If you simply must have it inside a class, I would use a constant and a static method. // in the main plugin file define( ‘MYPLUGIN_FILE’, __FILE__ ); // include another file with this class in class MyPlugin { public static function init() { register_activation_hook( MYPLUGIN_FILE, array( ‘MyPlugin’, ‘install’ )); } … Read more
You’re quite off with your code. That’s not how widgets are stored (at least not since 2.8), plus you’re trying to inject arrays into strings! Setting default widgets (at least in the admin) seems a complex & messy task. I would much rather opt for default widgets in the display logic instead. <?php if ( … Read more