Brak opisu

class-woo-custom-emails-per-product-loader.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Responsible for coordinating actions and filters
  4. * between the core plugin and the administration class.
  5. *
  6. * @package woo_custom_emails_domain\includes
  7. */
  8. class Woo_Custom_Emails_Per_Product_Loader {
  9. // Define protected vars
  10. protected $actions;
  11. protected $filters;
  12. // Class constructor
  13. public function __construct() {
  14. // Define vars as arrays
  15. $this->actions = array();
  16. $this->filters = array();
  17. }
  18. // Function to add ACTIONS to array above
  19. public function add_action( $hook, $component, $callback ) {
  20. $this->actions = $this->add( $this->actions, $hook, $component, $callback );
  21. }
  22. // Function to add FILTERS to array above
  23. public function add_filter( $hook, $component, $callback ) {
  24. $this->filters = $this->add( $this->filters, $hook, $component, $callback );
  25. }
  26. // Function to add items into an array
  27. private function add( $hooks, $hook, $component, $callback ) {
  28. $hooks[] = array(
  29. 'hook' => $hook,
  30. 'component' => $component,
  31. 'callback' => $callback
  32. );
  33. return $hooks;
  34. }
  35. public function run() {
  36. foreach ( $this->filters as $hook ) {
  37. add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ) );
  38. }
  39. foreach ( $this->actions as $hook ) {
  40. add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ) );
  41. }
  42. }
  43. }