Adding my own class to plugin (using boilerplate)
Question
I’m converting a plugin to OOP using boilerplate, and I want to clean up the code.
- In the construct part of “class-plugin.php” I’m able set $this->my_mailer();
-
In load_dependencies() I include “class-my-mailer.php” and pass it to the loader.
// class-plugin.php public function __construct() { ... $this->load_dependencies(); $this->set_locale(); $this->define_admin_hooks(); $this->define_public_hooks(); $this->my_mailer(); } private function load_dependencies() { ... require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-my-mailer.php'; } public function my_mailer() { $my_mail = new My_Mailer(); // test sending mail on load // $this->loader->add_action( 'init', $my_mail, 'send_mail' ); // callback needed }
I see the solution using a callback method. What I’m trying to accomplish is to use $my_mail->send_mail(‘tosomeone@world.com’); where necessary. WordPress keep saying the variable $my_mail does not exist.
Can someone please show me the right way to do this, or point me in the right direction?
0
oop, plugin-development
3 years
2020-06-07T13:10:32-05:00
2020-06-07T13:10:32-05:00 0 Answers
88 views
0
Leave an answer