title: WordPress: Add custom add_filter for custom functions
body: <p>I am coping with the scenario where I need to filter content of my custom function. My function is used for sending emails but I need to filter it just like wp_mail hook do.</p>
  
  <p>Here is my function:</p>
  
  <pre><code>function koku_crm_send_sendgrid($sendgrid_api_key, $to, $subject, $text, $html) {
  
      $sendgrid = new \SendGrid($sendgrid_api_key);
      $mail = new KCSendGrid\Mail();
      $from = new KCSendGrid\Email(get_bloginfo( 'name' ), get_bloginfo( 'admin_email' ));
      $mail-&gt;setFrom($from);
      $mail-&gt;setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
  
      $content = new KCSendGrid\Content("text/plain", $text);
      $mail-&gt;addContent($content);
  
      $content = new KCSendGrid\Content("text/html", $html);
      $mail-&gt;addContent($content);
  
      $personalization = new KCSendGrid\Personalization();
      $to = new KCSendGrid\Email(null, $to);
      $personalization-&gt;addTo($to);
      $mail-&gt;addPersonalization($personalization);
  
      $sendgrid-&gt;client-&gt;mail()-&gt;send()-&gt;post($mail);
  
  }
  </code></pre>
  
  <p>I want to filter that "$to" variable before sending the email. Something similar to the <a href="https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail" rel="nofollow noreferrer">wp_mail filter hook</a>.</p>
  
  <p>I have search a lot, please help me in this regards. Thank you so much in advance.</p>