| 1 |
<?php |
| 2 |
/** |
| 3 |
* Singleton class that stores registered recipient types. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Recipient_Types |
| 6 |
* @version 1.0.0 |
| 7 |
* @author David Bisset |
| 8 |
* @copyright Copyright (c) 2022, WP Charitable LLC |
| 9 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Recipient_Types' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Charitable_Recipient_Types |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
class Charitable_Recipient_Types { |
| 25 |
|
| 26 |
/** |
| 27 |
* @var Charitable_Recipient_Types |
| 28 |
*/ |
| 29 |
private static $instance = null; |
| 30 |
|
| 31 |
/** |
| 32 |
* @var array |
| 33 |
*/ |
| 34 |
private $types = array(); |
| 35 |
|
| 36 |
/** |
| 37 |
* Create class object. |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
*/ |
| 41 |
private function __construct() {} |
| 42 |
|
| 43 |
/** |
| 44 |
* Returns the single instance of this class. |
| 45 |
* |
| 46 |
* @since 1.0.0 |
| 47 |
* |
| 48 |
* @return Charitable_Recipient_Types |
| 49 |
*/ |
| 50 |
public static function get_instance() { |
| 51 |
if ( is_null( self::$instance ) ) { |
| 52 |
self::$instance = new self(); |
| 53 |
} |
| 54 |
|
| 55 |
return self::$instance; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Registers a new recipient type. |
| 60 |
* |
| 61 |
* @since 1.0.0 |
| 62 |
* |
| 63 |
* @return Charitable_Recipient_Types |
| 64 |
*/ |
| 65 |
public function register( $recipient_type, $args = array() ) { |
| 66 |
$defaults = array( |
| 67 |
'label' => '', |
| 68 |
'description' => '', |
| 69 |
'admin_label' => '', |
| 70 |
'admin_description' => '', |
| 71 |
'searchable' => false, |
| 72 |
'search_placeholder' => '', |
| 73 |
'options' => array(), |
| 74 |
); |
| 75 |
|
| 76 |
$args = wp_parse_args( $args, $defaults ); |
| 77 |
|
| 78 |
$this->types[ $recipient_type ] = $args; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns all registered recipient types. |
| 83 |
* |
| 84 |
* @since 1.0.0 |
| 85 |
* |
| 86 |
* @return array |
| 87 |
*/ |
| 88 |
public function get_types() { |
| 89 |
return $this->types; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
endif; |
| 94 |
|