<?php

/**
 * Register all actions and filters for the plugin
 *
 * @link       www.redefiningtheweb.com
 * @since      1.0.0
 *
 * @package    Rtwwpcp_Woocommerce_Pdf_Catalog_Pro
 * @subpackage Rtwwpcp_Woocommerce_Pdf_Catalog_Pro/includes
 */

/**
 * Register all actions and filters for the plugin.
 *
 * Maintain a list of all hooks that are registered throughout
 * the plugin, and register them with the WordPress API. Call the
 * run function to execute the list of actions and filters.
 *
 * @package    Rtwwpcp_Woocommerce_Pdf_Catalog_Pro
 * @subpackage Rtwwpcp_Woocommerce_Pdf_Catalog_Pro/includes
 * @author     RedefiningTheWeb <developer@redefiningtheweb.com>
 */
class Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_Loader {

	/**
	 * The array of actions registered with WordPress.
	 *
	 * @since    1.0.0
	 * @access   protected
	 * @var      array    $rtwwpcp_actions    The actions registered with WordPress to fire when the plugin loads.
	 */
	protected $rtwwpcp_actions;

	/**
	 * The array of filters registered with WordPress.
	 *
	 * @since    1.0.0
	 * @access   protected
	 * @var      array    $rtwwpcp_filters    The filters registered with WordPress to fire when the plugin loads.
	 */
	protected $rtwwpcp_filters;

	/**
	 * Initialize the collections used to maintain the actions and filters.
	 *
	 * @since    1.0.0
	 */
	public function __construct() {

		$this->rtwwpcp_actions = array();
		$this->rtwwpcp_filters = array();

	}

	/**
	 * Add a new action to the collection to be registered with WordPress.
	 *
	 * @since    1.0.0
	 * @param    string               $rtwwpcp_hook             The name of the WordPress action that is being registered.
	 * @param    object               $rtwwpcp_component        A reference to the instance of the object on which the action is defined.
	 * @param    string               $rtwwpcp_callback         The name of the function definition on the $rtwwpcp_component.
	 * @param    int                  $rtwwpcp_priority         Optional. The priority at which the function should be fired. Default is 10.
	 * @param    int                  $rtwwpcp_accepted_args    Optional. The number of arguments that should be passed to the $rtwwpcp_callback. Default is 1.
	 */
	public function rtwwpcp_add_action( $rtwwpcp_hook, $rtwwpcp_component, $rtwwpcp_callback, $rtwwpcp_priority = 10, $rtwwpcp_accepted_args = 1 ) {
		$this->rtwwpcp_actions = $this->rtwwpcp_add( $this->rtwwpcp_actions, $rtwwpcp_hook, $rtwwpcp_component, $rtwwpcp_callback, $rtwwpcp_priority, $rtwwpcp_accepted_args );
	}

	/**
	 * Add a new filter to the collection to be registered with WordPress.
	 *
	 * @since    1.0.0
	 * @param    string               $rtwwpcp_hook             The name of the WordPress filter that is being registered.
	 * @param    object               $rtwwpcp_component        A reference to the instance of the object on which the filter is defined.
	 * @param    string               $rtwwpcp_callback         The name of the function definition on the $rtwwpcp_component.
	 * @param    int                  $rtwwpcp_priority         Optional. The priority at which the function should be fired. Default is 10.
	 * @param    int                  $rtwwpcp_accepted_args    Optional. The number of arguments that should be passed to the $rtwwpcp_callback. Default is 1
	 */
	public function rtwwpcp_add_filter( $rtwwpcp_hook, $rtwwpcp_component, $rtwwpcp_callback, $rtwwpcp_priority = 10, $rtwwpcp_accepted_args = 1 ) {
		$this->rtwwpcp_filters = $this->rtwwpcp_add( $this->rtwwpcp_filters, $rtwwpcp_hook, $rtwwpcp_component, $rtwwpcp_callback, $rtwwpcp_priority, $rtwwpcp_accepted_args );
	}

	/**
	 * A utility function that is used to register the actions and hooks into a single
	 * collection.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @param    array                $rtwwpcp_hooks            The collection of hooks that is being registered (that is, actions or filters).
	 * @param    string               $rtwwpcp_hook             The name of the WordPress filter that is being registered.
	 * @param    object               $rtwwpcp_component        A reference to the instance of the object on which the filter is defined.
	 * @param    string               $rtwwpcp_callback         The name of the function definition on the $component.
	 * @param    int                  $rtwwpcp_priority         The priority at which the function should be fired.
	 * @param    int                  $rtwwpcp_accepted_args    The number of arguments that should be passed to the $rtwwpcp_callback.
	 * @return   array                                  The collection of actions and filters registered with WordPress.
	 */
	private function rtwwpcp_add( $rtwwpcp_hooks, $rtwwpcp_hook, $rtwwpcp_component, $rtwwpcp_callback, $rtwwpcp_priority, $rtwwpcp_accepted_args ) {

		$rtwwpcp_hooks[] = array(
			'hook'          => $rtwwpcp_hook,
			'component'     => $rtwwpcp_component,
			'callback'      => $rtwwpcp_callback,
			'priority'      => $rtwwpcp_priority,
			'accepted_args' => $rtwwpcp_accepted_args
		);

		return $rtwwpcp_hooks;

	}

	/**
	 * Register the filters and actions with WordPress.
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_run() {

		foreach ( $this->rtwwpcp_filters as $rtwwpcp_hook ) {
			add_filter( $rtwwpcp_hook['hook'], array( $rtwwpcp_hook['component'], $rtwwpcp_hook['callback'] ), $rtwwpcp_hook['priority'], $rtwwpcp_hook['accepted_args'] );
		}

		foreach ( $this->rtwwpcp_actions as $rtwwpcp_hook ) {
			add_action( $rtwwpcp_hook['hook'], array( $rtwwpcp_hook['component'], $rtwwpcp_hook['callback'] ), $rtwwpcp_hook['priority'], $rtwwpcp_hook['accepted_args'] );
		}

	}

}
