Adding my own class to plugin (using boilerplate)


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() {
    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(‘’); 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?

, Terje Lundemo Tangen 3 years 2020-06-07T13:10:32-05:00 0 Answers 88 views 0

Leave an answer