I’m yanking my hair out with the following code, please help.
I have 3 files.
File1.php:
Class File1 {
public function file1_register() {
//register some short codes;
}
public function file1_unregister() {
//unregister previous short codes;
}
}
File2.php:
Class File2 {
public function file2_register() {
//create some database tables.
}
public function file1_unregister() {
//delete previous tables.
}
}
MyPlugin.php:
function MyActivation() {
include_once (dirname(FILE).'/file1.php');
$File1 = new File1;
$File1::file1_register();
}
register_activation_hook(FILE, 'MyActivation');
The function file1_register just refuse to work, eventually I would like to run file2_register as well, but at this point, I can’t see the error or problem with my code, please help.
You have two options either define you register methods as static and then you can avoid instantiating your classes or even calling the
MyActivation
function ex:File1.php:
File2.php:
MyPlugin.php:
OR simply change the “Paamayim Nekudotayim” (::) to the arrow operator (->) in your current
MyActivation
function which means replace this line:with this: