Timeline for How to properly setup an activation hook
Current License: CC BY-SA 4.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 13, 2018 at 11:23 | comment | added | Matt |
@Cyclonecode I've tested the code in my answer and it works, if yours is the same, I don't see why yours doesn't. The error clearly states class 'MyPluginAdmin' not found . If you're sure the include is correct, then the only other things I can think of is a typo in class name or incorrect permissions. I'm sure if you create a function in MyPluginAdmin and call it from the main class, you will get an error. The MyPLuginAdmin is not included.
|
|
Sep 13, 2018 at 10:33 | comment | added | Cyclonecode | Yes of course I'm including the directory path in the second example. The path is absolutely correct, since it is the same path used for including the actual file. The above is just an example, shouldn't matter if it is in a sub folder as long as the path is correct. I updated the question to match the actual structure of my plugin files. | |
Sep 13, 2018 at 10:23 | comment | added | Matt |
@Cyclonecode No, MyPluginAdmin::activate is not run in the second version. You can test this by just putting an echo in the activate function (activation hooks aren't allowed to output). The first example fails to activate with a The plugin generated x characters of unexpected output during activation. whereas the second activates as the function is not run. Are you including the directory in the include ie. include_once(plugin_dir_path(__FILE__) . 'admin/my-plugin-admin.php'); , because you haven't in your example code.
|
|
Sep 13, 2018 at 9:53 | comment | added | Cyclonecode |
The MyPluginAdmin::activate method are run in both cases? The real plugin has its admin file located in a subfolder i.e admin/my-plugin-admin.php . Very strange that only the second version works without throwing a warning?
|
|
Sep 13, 2018 at 8:18 | history | edited | Matt | CC BY-SA 4.0 |
added 555 characters in body
|
Sep 13, 2018 at 8:09 | history | edited | Matt | CC BY-SA 4.0 |
added 555 characters in body
|
Sep 13, 2018 at 7:57 | comment | added | Matt |
@Cyclonecode your second version activates the plugin, but the activation function isn't run. The $file parameter is definitely incorrect, you end up with something like my-plugin.php/my-plugin-admin.php . Are both of the files in the same directory?
|
|
Sep 13, 2018 at 7:36 | comment | added | Cyclonecode | That was just a typo, the path to the file is correct, so this seems not to be the problem. | |
Sep 13, 2018 at 7:31 | history | answered | Matt | CC BY-SA 4.0 |