@@ -15,175 +15,175 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @type EE_Message_Factory $_instance |
|
20 | - */ |
|
21 | - protected static $_instance; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
26 | - */ |
|
27 | - protected $_message_resource_manager; |
|
28 | - |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * EE_Message_Factory constructor. |
|
33 | - * |
|
34 | - * @access protected |
|
35 | - * @param \EE_Message_Resource_Manager $Message_Resource_Manager |
|
36 | - */ |
|
37 | - protected function __construct( |
|
38 | - EE_Message_Resource_Manager $Message_Resource_Manager |
|
39 | - ) { |
|
40 | - $this->_message_resource_manager = $Message_Resource_Manager; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @singleton method used to instantiate class object |
|
47 | - * @access public |
|
48 | - * @param \EE_Message_Resource_Manager $Message_Resource_Manager |
|
49 | - * @return \EE_Message_Factory instance |
|
50 | - */ |
|
51 | - public static function instance(EE_Message_Resource_Manager $Message_Resource_Manager) |
|
52 | - { |
|
53 | - // check if class object is instantiated, and instantiated properly |
|
54 | - if (! self::$_instance instanceof EE_Message_Factory) { |
|
55 | - self::$_instance = new EE_Message_Factory($Message_Resource_Manager); |
|
56 | - } |
|
57 | - return self::$_instance; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @access public |
|
64 | - * @param array $props_n_values |
|
65 | - * @return EE_Message |
|
66 | - */ |
|
67 | - public static function create($props_n_values = array()) |
|
68 | - { |
|
69 | - /** @type EE_Message_Factory $Message_Factory */ |
|
70 | - $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory'); |
|
71 | - return $Message_Factory->_create($props_n_values); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @access public |
|
78 | - * @param \EE_Message $message |
|
79 | - * @return \EE_Message |
|
80 | - * @throws \EE_Error |
|
81 | - */ |
|
82 | - public static function set_messenger_and_message_type(EE_Message $message) |
|
83 | - { |
|
84 | - /** @type EE_Message_Factory $Message_Factory */ |
|
85 | - $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory'); |
|
86 | - return $Message_Factory->_set_messenger_and_message_type($message); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @access public |
|
93 | - * @param \EE_Message $message |
|
94 | - * @return \EE_Message |
|
95 | - * @throws \EE_Error |
|
96 | - */ |
|
97 | - public static function set_messenger(EE_Message $message) |
|
98 | - { |
|
99 | - /** @type EE_Message_Factory $Message_Factory */ |
|
100 | - $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory'); |
|
101 | - return $Message_Factory->_set_messenger($message); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @access public |
|
108 | - * @param \EE_Message $message |
|
109 | - * @return \EE_Message |
|
110 | - * @throws \EE_Error |
|
111 | - */ |
|
112 | - public static function set_message_type(EE_Message $message) |
|
113 | - { |
|
114 | - /** @type EE_Message_Factory $Message_Factory */ |
|
115 | - $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory'); |
|
116 | - return $Message_Factory->_set_message_type($message); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @access protected |
|
123 | - * @param array $props_n_values |
|
124 | - * @return \EE_Message |
|
125 | - * @throws \EE_Error |
|
126 | - */ |
|
127 | - protected function _create($props_n_values = array()) |
|
128 | - { |
|
129 | - $new_instance = false; |
|
130 | - if (! empty($props_n_values['MSG_ID'])) { |
|
131 | - $message = EE_Message::new_instance_from_db($props_n_values); |
|
132 | - } else { |
|
133 | - $message = EE_Message::new_instance($props_n_values); |
|
134 | - $new_instance = true; |
|
135 | - } |
|
136 | - return $this->_set_messenger_and_message_type($message, $new_instance); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @access public |
|
143 | - * @param \EE_Message $message |
|
144 | - * @param bool $new_instance Whether the message type was setup from the database (false) or not (true) |
|
145 | - * @return \EE_Message |
|
146 | - * @throws \EE_Error |
|
147 | - */ |
|
148 | - protected function _set_messenger_and_message_type(EE_Message $message, $new_instance = false) |
|
149 | - { |
|
150 | - $message = $this->_set_messenger($message); |
|
151 | - $message = $this->_set_message_type($message, $new_instance); |
|
152 | - return $message; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @access protected |
|
159 | - * @param \EE_Message $message |
|
160 | - * @return \EE_Message |
|
161 | - * @throws \EE_Error |
|
162 | - */ |
|
163 | - protected function _set_messenger(EE_Message $message) |
|
164 | - { |
|
165 | - $messenger = $this->_message_resource_manager->get_messenger($message->messenger()); |
|
166 | - if ($messenger instanceof EE_messenger) { |
|
167 | - $message->set_messenger_object($messenger); |
|
168 | - } |
|
169 | - return $message; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @access protected |
|
176 | - * @param \EE_Message $message |
|
177 | - * @param bool $new_instance Whether the message type was setup from the database (false) or not (true) |
|
178 | - * @return \EE_Message |
|
179 | - * @throws \EE_Error |
|
180 | - */ |
|
181 | - protected function _set_message_type(EE_Message $message, $new_instance = false) |
|
182 | - { |
|
183 | - $message_type = $this->_message_resource_manager->get_message_type($message->message_type()); |
|
184 | - if ($message_type instanceof EE_message_type) { |
|
185 | - $message->set_message_type_object($message_type, $new_instance); |
|
186 | - } |
|
187 | - return $message; |
|
188 | - } |
|
18 | + /** |
|
19 | + * @type EE_Message_Factory $_instance |
|
20 | + */ |
|
21 | + protected static $_instance; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
26 | + */ |
|
27 | + protected $_message_resource_manager; |
|
28 | + |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * EE_Message_Factory constructor. |
|
33 | + * |
|
34 | + * @access protected |
|
35 | + * @param \EE_Message_Resource_Manager $Message_Resource_Manager |
|
36 | + */ |
|
37 | + protected function __construct( |
|
38 | + EE_Message_Resource_Manager $Message_Resource_Manager |
|
39 | + ) { |
|
40 | + $this->_message_resource_manager = $Message_Resource_Manager; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @singleton method used to instantiate class object |
|
47 | + * @access public |
|
48 | + * @param \EE_Message_Resource_Manager $Message_Resource_Manager |
|
49 | + * @return \EE_Message_Factory instance |
|
50 | + */ |
|
51 | + public static function instance(EE_Message_Resource_Manager $Message_Resource_Manager) |
|
52 | + { |
|
53 | + // check if class object is instantiated, and instantiated properly |
|
54 | + if (! self::$_instance instanceof EE_Message_Factory) { |
|
55 | + self::$_instance = new EE_Message_Factory($Message_Resource_Manager); |
|
56 | + } |
|
57 | + return self::$_instance; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @access public |
|
64 | + * @param array $props_n_values |
|
65 | + * @return EE_Message |
|
66 | + */ |
|
67 | + public static function create($props_n_values = array()) |
|
68 | + { |
|
69 | + /** @type EE_Message_Factory $Message_Factory */ |
|
70 | + $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory'); |
|
71 | + return $Message_Factory->_create($props_n_values); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @access public |
|
78 | + * @param \EE_Message $message |
|
79 | + * @return \EE_Message |
|
80 | + * @throws \EE_Error |
|
81 | + */ |
|
82 | + public static function set_messenger_and_message_type(EE_Message $message) |
|
83 | + { |
|
84 | + /** @type EE_Message_Factory $Message_Factory */ |
|
85 | + $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory'); |
|
86 | + return $Message_Factory->_set_messenger_and_message_type($message); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @access public |
|
93 | + * @param \EE_Message $message |
|
94 | + * @return \EE_Message |
|
95 | + * @throws \EE_Error |
|
96 | + */ |
|
97 | + public static function set_messenger(EE_Message $message) |
|
98 | + { |
|
99 | + /** @type EE_Message_Factory $Message_Factory */ |
|
100 | + $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory'); |
|
101 | + return $Message_Factory->_set_messenger($message); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @access public |
|
108 | + * @param \EE_Message $message |
|
109 | + * @return \EE_Message |
|
110 | + * @throws \EE_Error |
|
111 | + */ |
|
112 | + public static function set_message_type(EE_Message $message) |
|
113 | + { |
|
114 | + /** @type EE_Message_Factory $Message_Factory */ |
|
115 | + $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory'); |
|
116 | + return $Message_Factory->_set_message_type($message); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @access protected |
|
123 | + * @param array $props_n_values |
|
124 | + * @return \EE_Message |
|
125 | + * @throws \EE_Error |
|
126 | + */ |
|
127 | + protected function _create($props_n_values = array()) |
|
128 | + { |
|
129 | + $new_instance = false; |
|
130 | + if (! empty($props_n_values['MSG_ID'])) { |
|
131 | + $message = EE_Message::new_instance_from_db($props_n_values); |
|
132 | + } else { |
|
133 | + $message = EE_Message::new_instance($props_n_values); |
|
134 | + $new_instance = true; |
|
135 | + } |
|
136 | + return $this->_set_messenger_and_message_type($message, $new_instance); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @access public |
|
143 | + * @param \EE_Message $message |
|
144 | + * @param bool $new_instance Whether the message type was setup from the database (false) or not (true) |
|
145 | + * @return \EE_Message |
|
146 | + * @throws \EE_Error |
|
147 | + */ |
|
148 | + protected function _set_messenger_and_message_type(EE_Message $message, $new_instance = false) |
|
149 | + { |
|
150 | + $message = $this->_set_messenger($message); |
|
151 | + $message = $this->_set_message_type($message, $new_instance); |
|
152 | + return $message; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @access protected |
|
159 | + * @param \EE_Message $message |
|
160 | + * @return \EE_Message |
|
161 | + * @throws \EE_Error |
|
162 | + */ |
|
163 | + protected function _set_messenger(EE_Message $message) |
|
164 | + { |
|
165 | + $messenger = $this->_message_resource_manager->get_messenger($message->messenger()); |
|
166 | + if ($messenger instanceof EE_messenger) { |
|
167 | + $message->set_messenger_object($messenger); |
|
168 | + } |
|
169 | + return $message; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @access protected |
|
176 | + * @param \EE_Message $message |
|
177 | + * @param bool $new_instance Whether the message type was setup from the database (false) or not (true) |
|
178 | + * @return \EE_Message |
|
179 | + * @throws \EE_Error |
|
180 | + */ |
|
181 | + protected function _set_message_type(EE_Message $message, $new_instance = false) |
|
182 | + { |
|
183 | + $message_type = $this->_message_resource_manager->get_message_type($message->message_type()); |
|
184 | + if ($message_type instanceof EE_message_type) { |
|
185 | + $message->set_message_type_object($message_type, $new_instance); |
|
186 | + } |
|
187 | + return $message; |
|
188 | + } |
|
189 | 189 | } |
@@ -10,203 +10,203 @@ |
||
10 | 10 | class EEM_Price_Type extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @var EEM_Price_Type |
|
15 | - */ |
|
16 | - protected static $_instance; |
|
17 | - |
|
18 | - // An array of the price type objects |
|
19 | - |
|
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $type; |
|
24 | - |
|
25 | - /** |
|
26 | - * Price Base types |
|
27 | - * Keys are INTs which are used in the database, |
|
28 | - * values are text-representations of the base type. |
|
29 | - * |
|
30 | - * @var string[] |
|
31 | - */ |
|
32 | - public $base_types; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * return an array of Base types. |
|
37 | - * |
|
38 | - * @return string[] |
|
39 | - */ |
|
40 | - public function get_base_types(): array |
|
41 | - { |
|
42 | - return $this->base_types; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Gets the name of the base |
|
48 | - * |
|
49 | - * @param int $base_type_int |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function get_base_type_name(int $base_type_int): string |
|
53 | - { |
|
54 | - return $this->base_types[ $base_type_int ]; |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * constants for price base types. In the DB, we decided to store the price base type |
|
60 | - * as an integer. So, to avoid just having magic numbers everywhere (eg, querying for |
|
61 | - * all price types with PBT_ID = 2), we define these constants, to make code more understandable. |
|
62 | - * So, as an example, to query for all price types that are a tax, we'd do |
|
63 | - * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax))) |
|
64 | - * instead of |
|
65 | - * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2))) |
|
66 | - * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever |
|
67 | - * change, we can continue to use the constant, by simply change its value. |
|
68 | - */ |
|
69 | - const base_type_base_price = 1; |
|
70 | - |
|
71 | - const base_type_discount = 2; |
|
72 | - |
|
73 | - const base_type_surcharge = 3; |
|
74 | - |
|
75 | - const base_type_tax = 4; |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * EEM_Price_Type constructor. |
|
80 | - * |
|
81 | - * @param string $timezone |
|
82 | - * @throws EE_Error |
|
83 | - */ |
|
84 | - protected function __construct(string $timezone = '') |
|
85 | - { |
|
86 | - $this->base_types = [ |
|
87 | - EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'), |
|
88 | - EEM_Price_Type::base_type_discount => esc_html__('Discount', 'event_espresso'), |
|
89 | - EEM_Price_Type::base_type_surcharge => esc_html__('Surcharge', 'event_espresso'), |
|
90 | - EEM_Price_Type::base_type_tax => esc_html__('Tax', 'event_espresso'), |
|
91 | - ]; |
|
92 | - $this->singular_item = esc_html__('Price Type', 'event_espresso'); |
|
93 | - $this->plural_item = esc_html__('Price Types', 'event_espresso'); |
|
94 | - |
|
95 | - $this->_tables = [ |
|
96 | - 'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID'), |
|
97 | - ]; |
|
98 | - $this->_fields = [ |
|
99 | - 'Price_Type' => [ |
|
100 | - 'PRT_ID' => new EE_Primary_Key_Int_Field( |
|
101 | - 'PRT_ID', |
|
102 | - esc_html__('Price Type ID', 'event_espresso') |
|
103 | - ), |
|
104 | - 'PRT_name' => new EE_Plain_Text_Field( |
|
105 | - 'PRT_name', |
|
106 | - esc_html__('Price Type Name', 'event_espresso'), |
|
107 | - false, |
|
108 | - '' |
|
109 | - ), |
|
110 | - 'PBT_ID' => new EE_Enum_Integer_Field( |
|
111 | - 'PBT_ID', |
|
112 | - esc_html__( |
|
113 | - 'Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - false, |
|
117 | - EEM_Price_Type::base_type_base_price, |
|
118 | - $this->base_types |
|
119 | - ), |
|
120 | - 'PRT_is_percent' => new EE_Boolean_Field( |
|
121 | - 'PRT_is_percent', |
|
122 | - esc_html__('Flag indicating price is a percentage', 'event_espresso'), |
|
123 | - false, |
|
124 | - false |
|
125 | - ), |
|
126 | - 'PRT_order' => new EE_Integer_Field( |
|
127 | - 'PRT_order', |
|
128 | - esc_html__('Order in which price should be applied. ', 'event_espresso'), |
|
129 | - false, |
|
130 | - 0 |
|
131 | - ), |
|
132 | - 'PRT_deleted' => new EE_Trashed_Flag_Field( |
|
133 | - 'PRT_deleted', |
|
134 | - esc_html__('Flag indicating price type has been trashed', 'event_espresso'), |
|
135 | - false, |
|
136 | - false |
|
137 | - ), |
|
138 | - 'PRT_wp_user' => new EE_WP_User_Field( |
|
139 | - 'PRT_wp_user', |
|
140 | - esc_html__('Price Type Creator ID', 'event_espresso'), |
|
141 | - false |
|
142 | - ), |
|
143 | - ], |
|
144 | - ]; |
|
145 | - $this->_model_relations = [ |
|
146 | - 'Price' => new EE_Has_Many_Relation(), |
|
147 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
148 | - ]; |
|
149 | - // this model is generally available for reading |
|
150 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
151 | - // all price types are "default" in terms of capability names |
|
152 | - $this->_caps_slug = 'default_price_types'; |
|
153 | - parent::__construct($timezone); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * instantiate a new price type object with blank/empty properties |
|
159 | - * |
|
160 | - * @return EE_Price_Type |
|
161 | - * @throws EE_Error |
|
162 | - * @throws ReflectionException |
|
163 | - */ |
|
164 | - public function get_new_price_type(): EE_Price_Type |
|
165 | - { |
|
166 | - return EE_Price_Type::new_instance(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * |
|
172 | - * @param array $query_params |
|
173 | - * @param boolean $allow_blocking if TRUE, matched objects will only be deleted |
|
174 | - * if there is no related model info that blocks it |
|
175 | - * (ie, there' sno other data that depends on this data); |
|
176 | - * if false, deletes regardless of other objects which may depend on it. |
|
177 | - * Its generally advisable to always leave this as TRUE, |
|
178 | - * otherwise you could easily corrupt your DB |
|
179 | - * @return boolean |
|
180 | - * @throws EE_Error |
|
181 | - * @throws ReflectionException |
|
182 | - */ |
|
183 | - public function delete_permanently($query_params = [], $allow_blocking = true): bool |
|
184 | - { |
|
185 | - |
|
186 | - $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params); |
|
187 | - $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types); |
|
188 | - |
|
189 | - $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ]; |
|
190 | - |
|
191 | - // check if any prices use this price type |
|
192 | - $prc_query_params = [['PRT_ID' => ['IN', $would_be_deleted_price_type_ids]]]; |
|
193 | - if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) { |
|
194 | - $prices_names_and_ids = []; |
|
195 | - foreach ($prices as $price) { |
|
196 | - /* @var $price EE_Price */ |
|
197 | - $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")"; |
|
198 | - } |
|
199 | - $msg = sprintf( |
|
200 | - esc_html__( |
|
201 | - 'The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type. If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', |
|
202 | - 'event_espresso' |
|
203 | - ), |
|
204 | - implode(",", $prices_names_and_ids) |
|
205 | - ); |
|
206 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - return parent::delete_permanently($query_params); |
|
211 | - } |
|
13 | + /** |
|
14 | + * @var EEM_Price_Type |
|
15 | + */ |
|
16 | + protected static $_instance; |
|
17 | + |
|
18 | + // An array of the price type objects |
|
19 | + |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $type; |
|
24 | + |
|
25 | + /** |
|
26 | + * Price Base types |
|
27 | + * Keys are INTs which are used in the database, |
|
28 | + * values are text-representations of the base type. |
|
29 | + * |
|
30 | + * @var string[] |
|
31 | + */ |
|
32 | + public $base_types; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * return an array of Base types. |
|
37 | + * |
|
38 | + * @return string[] |
|
39 | + */ |
|
40 | + public function get_base_types(): array |
|
41 | + { |
|
42 | + return $this->base_types; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Gets the name of the base |
|
48 | + * |
|
49 | + * @param int $base_type_int |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function get_base_type_name(int $base_type_int): string |
|
53 | + { |
|
54 | + return $this->base_types[ $base_type_int ]; |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * constants for price base types. In the DB, we decided to store the price base type |
|
60 | + * as an integer. So, to avoid just having magic numbers everywhere (eg, querying for |
|
61 | + * all price types with PBT_ID = 2), we define these constants, to make code more understandable. |
|
62 | + * So, as an example, to query for all price types that are a tax, we'd do |
|
63 | + * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax))) |
|
64 | + * instead of |
|
65 | + * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2))) |
|
66 | + * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever |
|
67 | + * change, we can continue to use the constant, by simply change its value. |
|
68 | + */ |
|
69 | + const base_type_base_price = 1; |
|
70 | + |
|
71 | + const base_type_discount = 2; |
|
72 | + |
|
73 | + const base_type_surcharge = 3; |
|
74 | + |
|
75 | + const base_type_tax = 4; |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * EEM_Price_Type constructor. |
|
80 | + * |
|
81 | + * @param string $timezone |
|
82 | + * @throws EE_Error |
|
83 | + */ |
|
84 | + protected function __construct(string $timezone = '') |
|
85 | + { |
|
86 | + $this->base_types = [ |
|
87 | + EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'), |
|
88 | + EEM_Price_Type::base_type_discount => esc_html__('Discount', 'event_espresso'), |
|
89 | + EEM_Price_Type::base_type_surcharge => esc_html__('Surcharge', 'event_espresso'), |
|
90 | + EEM_Price_Type::base_type_tax => esc_html__('Tax', 'event_espresso'), |
|
91 | + ]; |
|
92 | + $this->singular_item = esc_html__('Price Type', 'event_espresso'); |
|
93 | + $this->plural_item = esc_html__('Price Types', 'event_espresso'); |
|
94 | + |
|
95 | + $this->_tables = [ |
|
96 | + 'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID'), |
|
97 | + ]; |
|
98 | + $this->_fields = [ |
|
99 | + 'Price_Type' => [ |
|
100 | + 'PRT_ID' => new EE_Primary_Key_Int_Field( |
|
101 | + 'PRT_ID', |
|
102 | + esc_html__('Price Type ID', 'event_espresso') |
|
103 | + ), |
|
104 | + 'PRT_name' => new EE_Plain_Text_Field( |
|
105 | + 'PRT_name', |
|
106 | + esc_html__('Price Type Name', 'event_espresso'), |
|
107 | + false, |
|
108 | + '' |
|
109 | + ), |
|
110 | + 'PBT_ID' => new EE_Enum_Integer_Field( |
|
111 | + 'PBT_ID', |
|
112 | + esc_html__( |
|
113 | + 'Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + false, |
|
117 | + EEM_Price_Type::base_type_base_price, |
|
118 | + $this->base_types |
|
119 | + ), |
|
120 | + 'PRT_is_percent' => new EE_Boolean_Field( |
|
121 | + 'PRT_is_percent', |
|
122 | + esc_html__('Flag indicating price is a percentage', 'event_espresso'), |
|
123 | + false, |
|
124 | + false |
|
125 | + ), |
|
126 | + 'PRT_order' => new EE_Integer_Field( |
|
127 | + 'PRT_order', |
|
128 | + esc_html__('Order in which price should be applied. ', 'event_espresso'), |
|
129 | + false, |
|
130 | + 0 |
|
131 | + ), |
|
132 | + 'PRT_deleted' => new EE_Trashed_Flag_Field( |
|
133 | + 'PRT_deleted', |
|
134 | + esc_html__('Flag indicating price type has been trashed', 'event_espresso'), |
|
135 | + false, |
|
136 | + false |
|
137 | + ), |
|
138 | + 'PRT_wp_user' => new EE_WP_User_Field( |
|
139 | + 'PRT_wp_user', |
|
140 | + esc_html__('Price Type Creator ID', 'event_espresso'), |
|
141 | + false |
|
142 | + ), |
|
143 | + ], |
|
144 | + ]; |
|
145 | + $this->_model_relations = [ |
|
146 | + 'Price' => new EE_Has_Many_Relation(), |
|
147 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
148 | + ]; |
|
149 | + // this model is generally available for reading |
|
150 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
151 | + // all price types are "default" in terms of capability names |
|
152 | + $this->_caps_slug = 'default_price_types'; |
|
153 | + parent::__construct($timezone); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * instantiate a new price type object with blank/empty properties |
|
159 | + * |
|
160 | + * @return EE_Price_Type |
|
161 | + * @throws EE_Error |
|
162 | + * @throws ReflectionException |
|
163 | + */ |
|
164 | + public function get_new_price_type(): EE_Price_Type |
|
165 | + { |
|
166 | + return EE_Price_Type::new_instance(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * |
|
172 | + * @param array $query_params |
|
173 | + * @param boolean $allow_blocking if TRUE, matched objects will only be deleted |
|
174 | + * if there is no related model info that blocks it |
|
175 | + * (ie, there' sno other data that depends on this data); |
|
176 | + * if false, deletes regardless of other objects which may depend on it. |
|
177 | + * Its generally advisable to always leave this as TRUE, |
|
178 | + * otherwise you could easily corrupt your DB |
|
179 | + * @return boolean |
|
180 | + * @throws EE_Error |
|
181 | + * @throws ReflectionException |
|
182 | + */ |
|
183 | + public function delete_permanently($query_params = [], $allow_blocking = true): bool |
|
184 | + { |
|
185 | + |
|
186 | + $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params); |
|
187 | + $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types); |
|
188 | + |
|
189 | + $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ]; |
|
190 | + |
|
191 | + // check if any prices use this price type |
|
192 | + $prc_query_params = [['PRT_ID' => ['IN', $would_be_deleted_price_type_ids]]]; |
|
193 | + if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) { |
|
194 | + $prices_names_and_ids = []; |
|
195 | + foreach ($prices as $price) { |
|
196 | + /* @var $price EE_Price */ |
|
197 | + $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")"; |
|
198 | + } |
|
199 | + $msg = sprintf( |
|
200 | + esc_html__( |
|
201 | + 'The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type. If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', |
|
202 | + 'event_espresso' |
|
203 | + ), |
|
204 | + implode(",", $prices_names_and_ids) |
|
205 | + ); |
|
206 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + return parent::delete_permanently($query_params); |
|
211 | + } |
|
212 | 212 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function get_base_type_name(int $base_type_int): string |
53 | 53 | { |
54 | - return $this->base_types[ $base_type_int ]; |
|
54 | + return $this->base_types[$base_type_int]; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | protected function __construct(string $timezone = '') |
85 | 85 | { |
86 | - $this->base_types = [ |
|
86 | + $this->base_types = [ |
|
87 | 87 | EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'), |
88 | 88 | EEM_Price_Type::base_type_discount => esc_html__('Discount', 'event_espresso'), |
89 | 89 | EEM_Price_Type::base_type_surcharge => esc_html__('Surcharge', 'event_espresso'), |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | 'WP_User' => new EE_Belongs_To_Relation(), |
148 | 148 | ]; |
149 | 149 | // this model is generally available for reading |
150 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
150 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
151 | 151 | // all price types are "default" in terms of capability names |
152 | 152 | $this->_caps_slug = 'default_price_types'; |
153 | 153 | parent::__construct($timezone); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params); |
187 | 187 | $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types); |
188 | 188 | |
189 | - $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ]; |
|
189 | + $ID = $query_params[0][$this->get_primary_key_field()->get_name()]; |
|
190 | 190 | |
191 | 191 | // check if any prices use this price type |
192 | 192 | $prc_query_params = [['PRT_ID' => ['IN', $would_be_deleted_price_type_ids]]]; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $prices_names_and_ids = []; |
195 | 195 | foreach ($prices as $price) { |
196 | 196 | /* @var $price EE_Price */ |
197 | - $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")"; |
|
197 | + $prices_names_and_ids[] = $price->name()."(".$price->ID().")"; |
|
198 | 198 | } |
199 | 199 | $msg = sprintf( |
200 | 200 | esc_html__( |
@@ -10,144 +10,144 @@ |
||
10 | 10 | class EEM_Term_Taxonomy extends EEM_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @var EEM_Term_Taxonomy |
|
15 | - */ |
|
16 | - protected static $_instance; |
|
13 | + /** |
|
14 | + * @var EEM_Term_Taxonomy |
|
15 | + */ |
|
16 | + protected static $_instance; |
|
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * EEM_Term_Taxonomy constructor. |
|
21 | - * |
|
22 | - * @param string $timezone |
|
23 | - * @throws EE_Error |
|
24 | - */ |
|
25 | - protected function __construct(string $timezone = '') |
|
26 | - { |
|
27 | - $this->singular_item = esc_html__('Term Taxonomy', 'event_espresso'); |
|
28 | - $this->plural_item = esc_html__('Term Taxonomy', 'event_espresso'); |
|
29 | - $this->_tables = [ |
|
30 | - 'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'), |
|
31 | - ]; |
|
32 | - $this->_fields = [ |
|
33 | - 'Term_Taxonomy' => [ |
|
34 | - 'term_taxonomy_id' => new EE_Primary_Key_Int_Field( |
|
35 | - 'term_taxonomy_id', |
|
36 | - esc_html__('Term-Taxonomy ID', 'event_espresso') |
|
37 | - ), |
|
38 | - 'term_id' => new EE_Foreign_Key_Int_Field( |
|
39 | - 'term_id', |
|
40 | - esc_html__("Term Id", "event_espresso"), |
|
41 | - false, |
|
42 | - 0, |
|
43 | - 'Term' |
|
44 | - ), |
|
45 | - 'taxonomy' => new EE_Plain_Text_Field( |
|
46 | - 'taxonomy', |
|
47 | - esc_html__('Taxonomy Name', 'event_espresso'), |
|
48 | - false, |
|
49 | - 'category' |
|
50 | - ), |
|
51 | - 'description' => new EE_Post_Content_Field( |
|
52 | - 'description', |
|
53 | - esc_html__("Description of Term", "event_espresso"), |
|
54 | - false, |
|
55 | - '' |
|
56 | - ), |
|
57 | - 'parent' => new EE_Integer_Field( |
|
58 | - 'parent', |
|
59 | - esc_html__("Parent Term ID", "event_espresso"), |
|
60 | - false, |
|
61 | - 0 |
|
62 | - ), |
|
63 | - 'term_count' => new EE_Integer_Field( |
|
64 | - 'count', |
|
65 | - esc_html__("Count of Objects attached", 'event_espresso'), |
|
66 | - false, |
|
67 | - 0 |
|
68 | - ), |
|
69 | - ], |
|
70 | - ]; |
|
71 | - $this->_model_relations = [ |
|
72 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
73 | - 'Term' => new EE_Belongs_To_Relation(), |
|
74 | - ]; |
|
75 | - $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
76 | - foreach ($cpt_models as $model_name) { |
|
77 | - $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship'); |
|
78 | - } |
|
79 | - $this->_wp_core_model = true; |
|
80 | - $this->_indexes = [ |
|
81 | - 'term_id_taxonomy' => new EE_Unique_Index(['term_id', 'taxonomy']), |
|
82 | - ]; |
|
83 | - $path_to_tax_model = ''; |
|
84 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
85 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
86 | - = new EE_Restriction_Generator_Taxonomy_Protected( |
|
87 | - $path_to_tax_model |
|
88 | - ); |
|
89 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
90 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
91 | - // add cap restrictions for editing relating to the "ee_edit_*" |
|
92 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
93 | - [ |
|
94 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'], |
|
95 | - ] |
|
96 | - ); |
|
97 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
98 | - [ |
|
99 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'], |
|
100 | - ] |
|
101 | - ); |
|
102 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
103 | - [ |
|
104 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'], |
|
105 | - ] |
|
106 | - ); |
|
107 | - // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
108 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
109 | - [ |
|
110 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'], |
|
111 | - ] |
|
112 | - ); |
|
113 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
114 | - [ |
|
115 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'], |
|
116 | - ] |
|
117 | - ); |
|
118 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
119 | - [ |
|
120 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'], |
|
121 | - ] |
|
122 | - ); |
|
123 | - parent::__construct($timezone); |
|
124 | - add_filter('FHEE__Read__create_model_query_params', ['EEM_Term_Taxonomy', 'rest_api_query_params'], 10, 3); |
|
125 | - } |
|
19 | + /** |
|
20 | + * EEM_Term_Taxonomy constructor. |
|
21 | + * |
|
22 | + * @param string $timezone |
|
23 | + * @throws EE_Error |
|
24 | + */ |
|
25 | + protected function __construct(string $timezone = '') |
|
26 | + { |
|
27 | + $this->singular_item = esc_html__('Term Taxonomy', 'event_espresso'); |
|
28 | + $this->plural_item = esc_html__('Term Taxonomy', 'event_espresso'); |
|
29 | + $this->_tables = [ |
|
30 | + 'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'), |
|
31 | + ]; |
|
32 | + $this->_fields = [ |
|
33 | + 'Term_Taxonomy' => [ |
|
34 | + 'term_taxonomy_id' => new EE_Primary_Key_Int_Field( |
|
35 | + 'term_taxonomy_id', |
|
36 | + esc_html__('Term-Taxonomy ID', 'event_espresso') |
|
37 | + ), |
|
38 | + 'term_id' => new EE_Foreign_Key_Int_Field( |
|
39 | + 'term_id', |
|
40 | + esc_html__("Term Id", "event_espresso"), |
|
41 | + false, |
|
42 | + 0, |
|
43 | + 'Term' |
|
44 | + ), |
|
45 | + 'taxonomy' => new EE_Plain_Text_Field( |
|
46 | + 'taxonomy', |
|
47 | + esc_html__('Taxonomy Name', 'event_espresso'), |
|
48 | + false, |
|
49 | + 'category' |
|
50 | + ), |
|
51 | + 'description' => new EE_Post_Content_Field( |
|
52 | + 'description', |
|
53 | + esc_html__("Description of Term", "event_espresso"), |
|
54 | + false, |
|
55 | + '' |
|
56 | + ), |
|
57 | + 'parent' => new EE_Integer_Field( |
|
58 | + 'parent', |
|
59 | + esc_html__("Parent Term ID", "event_espresso"), |
|
60 | + false, |
|
61 | + 0 |
|
62 | + ), |
|
63 | + 'term_count' => new EE_Integer_Field( |
|
64 | + 'count', |
|
65 | + esc_html__("Count of Objects attached", 'event_espresso'), |
|
66 | + false, |
|
67 | + 0 |
|
68 | + ), |
|
69 | + ], |
|
70 | + ]; |
|
71 | + $this->_model_relations = [ |
|
72 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
73 | + 'Term' => new EE_Belongs_To_Relation(), |
|
74 | + ]; |
|
75 | + $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
76 | + foreach ($cpt_models as $model_name) { |
|
77 | + $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship'); |
|
78 | + } |
|
79 | + $this->_wp_core_model = true; |
|
80 | + $this->_indexes = [ |
|
81 | + 'term_id_taxonomy' => new EE_Unique_Index(['term_id', 'taxonomy']), |
|
82 | + ]; |
|
83 | + $path_to_tax_model = ''; |
|
84 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
85 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
86 | + = new EE_Restriction_Generator_Taxonomy_Protected( |
|
87 | + $path_to_tax_model |
|
88 | + ); |
|
89 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
90 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
91 | + // add cap restrictions for editing relating to the "ee_edit_*" |
|
92 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
93 | + [ |
|
94 | + $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'], |
|
95 | + ] |
|
96 | + ); |
|
97 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
98 | + [ |
|
99 | + $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'], |
|
100 | + ] |
|
101 | + ); |
|
102 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
103 | + [ |
|
104 | + $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'], |
|
105 | + ] |
|
106 | + ); |
|
107 | + // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
108 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
109 | + [ |
|
110 | + $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'], |
|
111 | + ] |
|
112 | + ); |
|
113 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
114 | + [ |
|
115 | + $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'], |
|
116 | + ] |
|
117 | + ); |
|
118 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
119 | + [ |
|
120 | + $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'], |
|
121 | + ] |
|
122 | + ); |
|
123 | + parent::__construct($timezone); |
|
124 | + add_filter('FHEE__Read__create_model_query_params', ['EEM_Term_Taxonomy', 'rest_api_query_params'], 10, 3); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | |
128 | - /** |
|
129 | - * Makes sure that during REST API queries, we only return term-taxonomies |
|
130 | - * for term taxonomies which should be shown in the rest api |
|
131 | - * |
|
132 | - * @param array $model_query_params |
|
133 | - * @param array $querystring_query_params |
|
134 | - * @param EEM_Base $model |
|
135 | - * @return array |
|
136 | - * @throws EE_Error |
|
137 | - */ |
|
138 | - public static function rest_api_query_params( |
|
139 | - array $model_query_params, |
|
140 | - array $querystring_query_params, |
|
141 | - EEM_Base $model |
|
142 | - ): array { |
|
143 | - if ($model === EEM_Term_Taxonomy::instance()) { |
|
144 | - $taxonomies = get_taxonomies(['show_in_rest' => true]); |
|
145 | - if (! empty($taxonomies)) { |
|
146 | - $model_query_params[0]['taxonomy'] = ['IN', $taxonomies]; |
|
147 | - } |
|
148 | - } |
|
149 | - return $model_query_params; |
|
150 | - } |
|
128 | + /** |
|
129 | + * Makes sure that during REST API queries, we only return term-taxonomies |
|
130 | + * for term taxonomies which should be shown in the rest api |
|
131 | + * |
|
132 | + * @param array $model_query_params |
|
133 | + * @param array $querystring_query_params |
|
134 | + * @param EEM_Base $model |
|
135 | + * @return array |
|
136 | + * @throws EE_Error |
|
137 | + */ |
|
138 | + public static function rest_api_query_params( |
|
139 | + array $model_query_params, |
|
140 | + array $querystring_query_params, |
|
141 | + EEM_Base $model |
|
142 | + ): array { |
|
143 | + if ($model === EEM_Term_Taxonomy::instance()) { |
|
144 | + $taxonomies = get_taxonomies(['show_in_rest' => true]); |
|
145 | + if (! empty($taxonomies)) { |
|
146 | + $model_query_params[0]['taxonomy'] = ['IN', $taxonomies]; |
|
147 | + } |
|
148 | + } |
|
149 | + return $model_query_params; |
|
150 | + } |
|
151 | 151 | } |
152 | 152 | // End of file EEM_Term_Taxonomy.model.php |
153 | 153 | // Location: /includes/models/EEM_Term_Taxonomy.model.php |
@@ -72,52 +72,52 @@ discard block |
||
72 | 72 | 'Term_Relationship' => new EE_Has_Many_Relation(), |
73 | 73 | 'Term' => new EE_Belongs_To_Relation(), |
74 | 74 | ]; |
75 | - $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
75 | + $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
76 | 76 | foreach ($cpt_models as $model_name) { |
77 | - $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship'); |
|
77 | + $this->_model_relations[$model_name] = new EE_HABTM_Relation('Term_Relationship'); |
|
78 | 78 | } |
79 | 79 | $this->_wp_core_model = true; |
80 | 80 | $this->_indexes = [ |
81 | 81 | 'term_id_taxonomy' => new EE_Unique_Index(['term_id', 'taxonomy']), |
82 | 82 | ]; |
83 | 83 | $path_to_tax_model = ''; |
84 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
85 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
84 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
85 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] |
|
86 | 86 | = new EE_Restriction_Generator_Taxonomy_Protected( |
87 | 87 | $path_to_tax_model |
88 | 88 | ); |
89 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
90 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
89 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
90 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
91 | 91 | // add cap restrictions for editing relating to the "ee_edit_*" |
92 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
92 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
93 | 93 | [ |
94 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'], |
|
94 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'], |
|
95 | 95 | ] |
96 | 96 | ); |
97 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
97 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
98 | 98 | [ |
99 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'], |
|
99 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'], |
|
100 | 100 | ] |
101 | 101 | ); |
102 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
102 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
103 | 103 | [ |
104 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'], |
|
104 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'], |
|
105 | 105 | ] |
106 | 106 | ); |
107 | 107 | // add cap restrictions for deleting relating to the "ee_deleting_*" |
108 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
108 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
109 | 109 | [ |
110 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'], |
|
110 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'], |
|
111 | 111 | ] |
112 | 112 | ); |
113 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
113 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
114 | 114 | [ |
115 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'], |
|
115 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'], |
|
116 | 116 | ] |
117 | 117 | ); |
118 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
118 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
119 | 119 | [ |
120 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'], |
|
120 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'], |
|
121 | 121 | ] |
122 | 122 | ); |
123 | 123 | parent::__construct($timezone); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | ): array { |
143 | 143 | if ($model === EEM_Term_Taxonomy::instance()) { |
144 | 144 | $taxonomies = get_taxonomies(['show_in_rest' => true]); |
145 | - if (! empty($taxonomies)) { |
|
145 | + if ( ! empty($taxonomies)) { |
|
146 | 146 | $model_query_params[0]['taxonomy'] = ['IN', $taxonomies]; |
147 | 147 | } |
148 | 148 | } |
@@ -16,45 +16,45 @@ |
||
16 | 16 | class EE_Soft_Delete_Where_Conditions extends EE_Default_Where_Conditions |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Gets the where default where conditions for a custom post type model |
|
21 | - * |
|
22 | - * @return array |
|
23 | - * @throws EE_Error |
|
24 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
25 | - */ |
|
26 | - protected function _get_default_where_conditions(): array |
|
27 | - { |
|
28 | - $trashed_field_name = $this->deleted_field_name(); |
|
29 | - return [ |
|
30 | - $trashed_field_name => false, |
|
31 | - ]; |
|
32 | - } |
|
19 | + /** |
|
20 | + * Gets the where default where conditions for a custom post type model |
|
21 | + * |
|
22 | + * @return array |
|
23 | + * @throws EE_Error |
|
24 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
25 | + */ |
|
26 | + protected function _get_default_where_conditions(): array |
|
27 | + { |
|
28 | + $trashed_field_name = $this->deleted_field_name(); |
|
29 | + return [ |
|
30 | + $trashed_field_name => false, |
|
31 | + ]; |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * Searches for field on the model of type 'deleted_flag'. if it is found, |
|
37 | - * returns it's name. |
|
38 | - * |
|
39 | - * @return string |
|
40 | - * @throws EE_Error |
|
41 | - */ |
|
42 | - private function deleted_field_name(): string |
|
43 | - { |
|
44 | - $field = $this->_model->get_a_field_of_type('EE_Trashed_Flag_Field'); |
|
45 | - if ($field) { |
|
46 | - return $field->get_name(); |
|
47 | - } else { |
|
48 | - throw new EE_Error( |
|
49 | - sprintf( |
|
50 | - esc_html__( |
|
51 | - 'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
52 | - 'event_espresso' |
|
53 | - ), |
|
54 | - get_class($this), |
|
55 | - get_class($this) |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
59 | - } |
|
35 | + /** |
|
36 | + * Searches for field on the model of type 'deleted_flag'. if it is found, |
|
37 | + * returns it's name. |
|
38 | + * |
|
39 | + * @return string |
|
40 | + * @throws EE_Error |
|
41 | + */ |
|
42 | + private function deleted_field_name(): string |
|
43 | + { |
|
44 | + $field = $this->_model->get_a_field_of_type('EE_Trashed_Flag_Field'); |
|
45 | + if ($field) { |
|
46 | + return $field->get_name(); |
|
47 | + } else { |
|
48 | + throw new EE_Error( |
|
49 | + sprintf( |
|
50 | + esc_html__( |
|
51 | + 'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
52 | + 'event_espresso' |
|
53 | + ), |
|
54 | + get_class($this), |
|
55 | + get_class($this) |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | } |
@@ -10,204 +10,204 @@ |
||
10 | 10 | class EEM_Country extends EEM_Base |
11 | 11 | { |
12 | 12 | |
13 | - // private instance of the Attendee object |
|
14 | - protected static $_instance; |
|
15 | - |
|
16 | - // array of all countries |
|
17 | - private static $_all_countries = false; |
|
18 | - |
|
19 | - // array of all active countries |
|
20 | - private static $_active_countries = false; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * Resets the country |
|
25 | - * |
|
26 | - * @param string $timezone |
|
27 | - * @return EEM_Country |
|
28 | - * @throws EE_Error |
|
29 | - * @throws ReflectionException |
|
30 | - */ |
|
31 | - public static function reset($timezone = ''): EEM_Country |
|
32 | - { |
|
33 | - self::$_active_countries = null; |
|
34 | - self::$_all_countries = null; |
|
35 | - return parent::reset($timezone); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * EEM_Country constructor. |
|
41 | - * |
|
42 | - * @param string $timezone |
|
43 | - * @throws EE_Error |
|
44 | - */ |
|
45 | - protected function __construct(string $timezone = '') |
|
46 | - { |
|
47 | - $this->singular_item = esc_html__('Country', 'event_espresso'); |
|
48 | - $this->plural_item = esc_html__('Countries', 'event_espresso'); |
|
49 | - |
|
50 | - $this->_tables = [ |
|
51 | - 'Country' => new EE_Primary_Table('esp_country', 'CNT_ISO'), |
|
52 | - ]; |
|
53 | - |
|
54 | - $this->_fields = [ |
|
55 | - 'Country' => [ |
|
56 | - 'CNT_active' => new EE_Boolean_Field( |
|
57 | - 'CNT_active', |
|
58 | - esc_html__( |
|
59 | - 'Country Appears in Dropdown Select Lists', |
|
60 | - 'event_espresso' |
|
61 | - ), |
|
62 | - false, |
|
63 | - true |
|
64 | - ), |
|
65 | - 'CNT_ISO' => new EE_Primary_Key_String_Field( |
|
66 | - 'CNT_ISO', |
|
67 | - esc_html__('Country ISO Code', 'event_espresso') |
|
68 | - ), |
|
69 | - 'CNT_ISO3' => new EE_All_Caps_Text_Field( |
|
70 | - 'CNT_ISO3', |
|
71 | - esc_html__('Country ISO3 Code', 'event_espresso'), |
|
72 | - false, |
|
73 | - '' |
|
74 | - ), |
|
75 | - 'RGN_ID' => new EE_Integer_Field( |
|
76 | - 'RGN_ID', |
|
77 | - esc_html__('Region ID', 'event_espresso'), |
|
78 | - false, |
|
79 | - 0 |
|
80 | - ), |
|
81 | - // should be a foreign key, but no region table exists yet |
|
82 | - 'CNT_name' => new EE_Plain_Text_Field( |
|
83 | - 'CNT_name', |
|
84 | - esc_html__('Country Name', 'event_espresso'), |
|
85 | - false, |
|
86 | - '' |
|
87 | - ), |
|
88 | - 'CNT_cur_code' => new EE_All_Caps_Text_Field( |
|
89 | - 'CNT_cur_code', |
|
90 | - esc_html__('Country Currency Code', 'event_espresso'), |
|
91 | - false |
|
92 | - ), |
|
93 | - 'CNT_cur_single' => new EE_Plain_Text_Field( |
|
94 | - 'CNT_cur_single', |
|
95 | - esc_html__('Currency Name Singular', 'event_espresso'), |
|
96 | - false |
|
97 | - ), |
|
98 | - 'CNT_cur_plural' => new EE_Plain_Text_Field( |
|
99 | - 'CNT_cur_plural', |
|
100 | - esc_html__('Currency Name Plural', 'event_espresso'), |
|
101 | - false |
|
102 | - ), |
|
103 | - 'CNT_cur_sign' => new EE_Plain_Text_Field( |
|
104 | - 'CNT_cur_sign', |
|
105 | - esc_html__('Currency Sign', 'event_espresso'), |
|
106 | - false |
|
107 | - ), |
|
108 | - 'CNT_cur_sign_b4' => new EE_Boolean_Field( |
|
109 | - 'CNT_cur_sign_b4', |
|
110 | - esc_html__('Currency Sign Before Number', 'event_espresso'), |
|
111 | - false, |
|
112 | - true |
|
113 | - ), |
|
114 | - 'CNT_cur_dec_plc' => new EE_Integer_Field( |
|
115 | - 'CNT_cur_dec_plc', |
|
116 | - esc_html__('Currency Decimal Places', 'event_espresso'), |
|
117 | - false, |
|
118 | - 2 |
|
119 | - ), |
|
120 | - 'CNT_cur_dec_mrk' => new EE_Plain_Text_Field( |
|
121 | - 'CNT_cur_dec_mrk', |
|
122 | - esc_html__('Currency Decimal Mark', 'event_espresso'), |
|
123 | - false, |
|
124 | - '.' |
|
125 | - ), |
|
126 | - 'CNT_cur_thsnds' => new EE_Plain_Text_Field( |
|
127 | - 'CNT_cur_thsnds', |
|
128 | - esc_html__('Currency Thousands Separator', 'event_espresso'), |
|
129 | - false, |
|
130 | - ',' |
|
131 | - ), |
|
132 | - 'CNT_tel_code' => new EE_Plain_Text_Field( |
|
133 | - 'CNT_tel_code', |
|
134 | - esc_html__('Country Telephone Code', 'event_espresso'), |
|
135 | - false, |
|
136 | - '' |
|
137 | - ), |
|
138 | - 'CNT_is_EU' => new EE_Boolean_Field( |
|
139 | - 'CNT_is_EU', |
|
140 | - esc_html__('Country is Member of EU', 'event_espresso'), |
|
141 | - false, |
|
142 | - false |
|
143 | - ), |
|
144 | - ], |
|
145 | - ]; |
|
146 | - $this->_model_relations = [ |
|
147 | - 'Attendee' => new EE_Has_Many_Relation(), |
|
148 | - 'State' => new EE_Has_Many_Relation(), |
|
149 | - 'Venue' => new EE_Has_Many_Relation(), |
|
150 | - ]; |
|
151 | - // only anyone to view, but only those with the default role can do anything |
|
152 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
153 | - |
|
154 | - parent::__construct($timezone); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return array |
|
160 | - * @throws EE_Error |
|
161 | - * @throws ReflectionException |
|
162 | - */ |
|
163 | - public function get_all_countries() |
|
164 | - { |
|
165 | - if (! self::$_all_countries) { |
|
166 | - self::$_all_countries = $this->get_all(['order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]); |
|
167 | - } |
|
168 | - return self::$_all_countries; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * _get_countries |
|
174 | - * Gets and caches the list of active countries. If you know the list of active countries |
|
175 | - * has changed during this request, first use EEM_Country::reset() to flush the cache |
|
176 | - * |
|
177 | - * @return array |
|
178 | - * @throws EE_Error |
|
179 | - * @throws ReflectionException |
|
180 | - */ |
|
181 | - public function get_all_active_countries() |
|
182 | - { |
|
183 | - if (! self::$_active_countries) { |
|
184 | - self::$_active_countries = |
|
185 | - $this->get_all([['CNT_active' => true], 'order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]); |
|
186 | - } |
|
187 | - return self::$_active_countries; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Gets the country's name by its ISO |
|
193 | - * |
|
194 | - * @param string $country_ISO |
|
195 | - * @return string |
|
196 | - * @throws EE_Error |
|
197 | - * @throws ReflectionException |
|
198 | - */ |
|
199 | - public function get_country_name_by_ISO($country_ISO) |
|
200 | - { |
|
201 | - if ( |
|
202 | - isset(self::$_all_countries[ $country_ISO ]) |
|
203 | - && self::$_all_countries[ $country_ISO ] instanceof EE_Country |
|
204 | - ) { |
|
205 | - return self::$_all_countries[ $country_ISO ]->name(); |
|
206 | - } |
|
207 | - $names = $this->get_col([['CNT_ISO' => $country_ISO], 'limit' => 1], 'CNT_name'); |
|
208 | - if (is_array($names) && ! empty($names)) { |
|
209 | - return reset($names); |
|
210 | - } |
|
211 | - return ''; |
|
212 | - } |
|
13 | + // private instance of the Attendee object |
|
14 | + protected static $_instance; |
|
15 | + |
|
16 | + // array of all countries |
|
17 | + private static $_all_countries = false; |
|
18 | + |
|
19 | + // array of all active countries |
|
20 | + private static $_active_countries = false; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * Resets the country |
|
25 | + * |
|
26 | + * @param string $timezone |
|
27 | + * @return EEM_Country |
|
28 | + * @throws EE_Error |
|
29 | + * @throws ReflectionException |
|
30 | + */ |
|
31 | + public static function reset($timezone = ''): EEM_Country |
|
32 | + { |
|
33 | + self::$_active_countries = null; |
|
34 | + self::$_all_countries = null; |
|
35 | + return parent::reset($timezone); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * EEM_Country constructor. |
|
41 | + * |
|
42 | + * @param string $timezone |
|
43 | + * @throws EE_Error |
|
44 | + */ |
|
45 | + protected function __construct(string $timezone = '') |
|
46 | + { |
|
47 | + $this->singular_item = esc_html__('Country', 'event_espresso'); |
|
48 | + $this->plural_item = esc_html__('Countries', 'event_espresso'); |
|
49 | + |
|
50 | + $this->_tables = [ |
|
51 | + 'Country' => new EE_Primary_Table('esp_country', 'CNT_ISO'), |
|
52 | + ]; |
|
53 | + |
|
54 | + $this->_fields = [ |
|
55 | + 'Country' => [ |
|
56 | + 'CNT_active' => new EE_Boolean_Field( |
|
57 | + 'CNT_active', |
|
58 | + esc_html__( |
|
59 | + 'Country Appears in Dropdown Select Lists', |
|
60 | + 'event_espresso' |
|
61 | + ), |
|
62 | + false, |
|
63 | + true |
|
64 | + ), |
|
65 | + 'CNT_ISO' => new EE_Primary_Key_String_Field( |
|
66 | + 'CNT_ISO', |
|
67 | + esc_html__('Country ISO Code', 'event_espresso') |
|
68 | + ), |
|
69 | + 'CNT_ISO3' => new EE_All_Caps_Text_Field( |
|
70 | + 'CNT_ISO3', |
|
71 | + esc_html__('Country ISO3 Code', 'event_espresso'), |
|
72 | + false, |
|
73 | + '' |
|
74 | + ), |
|
75 | + 'RGN_ID' => new EE_Integer_Field( |
|
76 | + 'RGN_ID', |
|
77 | + esc_html__('Region ID', 'event_espresso'), |
|
78 | + false, |
|
79 | + 0 |
|
80 | + ), |
|
81 | + // should be a foreign key, but no region table exists yet |
|
82 | + 'CNT_name' => new EE_Plain_Text_Field( |
|
83 | + 'CNT_name', |
|
84 | + esc_html__('Country Name', 'event_espresso'), |
|
85 | + false, |
|
86 | + '' |
|
87 | + ), |
|
88 | + 'CNT_cur_code' => new EE_All_Caps_Text_Field( |
|
89 | + 'CNT_cur_code', |
|
90 | + esc_html__('Country Currency Code', 'event_espresso'), |
|
91 | + false |
|
92 | + ), |
|
93 | + 'CNT_cur_single' => new EE_Plain_Text_Field( |
|
94 | + 'CNT_cur_single', |
|
95 | + esc_html__('Currency Name Singular', 'event_espresso'), |
|
96 | + false |
|
97 | + ), |
|
98 | + 'CNT_cur_plural' => new EE_Plain_Text_Field( |
|
99 | + 'CNT_cur_plural', |
|
100 | + esc_html__('Currency Name Plural', 'event_espresso'), |
|
101 | + false |
|
102 | + ), |
|
103 | + 'CNT_cur_sign' => new EE_Plain_Text_Field( |
|
104 | + 'CNT_cur_sign', |
|
105 | + esc_html__('Currency Sign', 'event_espresso'), |
|
106 | + false |
|
107 | + ), |
|
108 | + 'CNT_cur_sign_b4' => new EE_Boolean_Field( |
|
109 | + 'CNT_cur_sign_b4', |
|
110 | + esc_html__('Currency Sign Before Number', 'event_espresso'), |
|
111 | + false, |
|
112 | + true |
|
113 | + ), |
|
114 | + 'CNT_cur_dec_plc' => new EE_Integer_Field( |
|
115 | + 'CNT_cur_dec_plc', |
|
116 | + esc_html__('Currency Decimal Places', 'event_espresso'), |
|
117 | + false, |
|
118 | + 2 |
|
119 | + ), |
|
120 | + 'CNT_cur_dec_mrk' => new EE_Plain_Text_Field( |
|
121 | + 'CNT_cur_dec_mrk', |
|
122 | + esc_html__('Currency Decimal Mark', 'event_espresso'), |
|
123 | + false, |
|
124 | + '.' |
|
125 | + ), |
|
126 | + 'CNT_cur_thsnds' => new EE_Plain_Text_Field( |
|
127 | + 'CNT_cur_thsnds', |
|
128 | + esc_html__('Currency Thousands Separator', 'event_espresso'), |
|
129 | + false, |
|
130 | + ',' |
|
131 | + ), |
|
132 | + 'CNT_tel_code' => new EE_Plain_Text_Field( |
|
133 | + 'CNT_tel_code', |
|
134 | + esc_html__('Country Telephone Code', 'event_espresso'), |
|
135 | + false, |
|
136 | + '' |
|
137 | + ), |
|
138 | + 'CNT_is_EU' => new EE_Boolean_Field( |
|
139 | + 'CNT_is_EU', |
|
140 | + esc_html__('Country is Member of EU', 'event_espresso'), |
|
141 | + false, |
|
142 | + false |
|
143 | + ), |
|
144 | + ], |
|
145 | + ]; |
|
146 | + $this->_model_relations = [ |
|
147 | + 'Attendee' => new EE_Has_Many_Relation(), |
|
148 | + 'State' => new EE_Has_Many_Relation(), |
|
149 | + 'Venue' => new EE_Has_Many_Relation(), |
|
150 | + ]; |
|
151 | + // only anyone to view, but only those with the default role can do anything |
|
152 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
153 | + |
|
154 | + parent::__construct($timezone); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return array |
|
160 | + * @throws EE_Error |
|
161 | + * @throws ReflectionException |
|
162 | + */ |
|
163 | + public function get_all_countries() |
|
164 | + { |
|
165 | + if (! self::$_all_countries) { |
|
166 | + self::$_all_countries = $this->get_all(['order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]); |
|
167 | + } |
|
168 | + return self::$_all_countries; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * _get_countries |
|
174 | + * Gets and caches the list of active countries. If you know the list of active countries |
|
175 | + * has changed during this request, first use EEM_Country::reset() to flush the cache |
|
176 | + * |
|
177 | + * @return array |
|
178 | + * @throws EE_Error |
|
179 | + * @throws ReflectionException |
|
180 | + */ |
|
181 | + public function get_all_active_countries() |
|
182 | + { |
|
183 | + if (! self::$_active_countries) { |
|
184 | + self::$_active_countries = |
|
185 | + $this->get_all([['CNT_active' => true], 'order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]); |
|
186 | + } |
|
187 | + return self::$_active_countries; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Gets the country's name by its ISO |
|
193 | + * |
|
194 | + * @param string $country_ISO |
|
195 | + * @return string |
|
196 | + * @throws EE_Error |
|
197 | + * @throws ReflectionException |
|
198 | + */ |
|
199 | + public function get_country_name_by_ISO($country_ISO) |
|
200 | + { |
|
201 | + if ( |
|
202 | + isset(self::$_all_countries[ $country_ISO ]) |
|
203 | + && self::$_all_countries[ $country_ISO ] instanceof EE_Country |
|
204 | + ) { |
|
205 | + return self::$_all_countries[ $country_ISO ]->name(); |
|
206 | + } |
|
207 | + $names = $this->get_col([['CNT_ISO' => $country_ISO], 'limit' => 1], 'CNT_name'); |
|
208 | + if (is_array($names) && ! empty($names)) { |
|
209 | + return reset($names); |
|
210 | + } |
|
211 | + return ''; |
|
212 | + } |
|
213 | 213 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | 'Country' => new EE_Primary_Table('esp_country', 'CNT_ISO'), |
52 | 52 | ]; |
53 | 53 | |
54 | - $this->_fields = [ |
|
54 | + $this->_fields = [ |
|
55 | 55 | 'Country' => [ |
56 | 56 | 'CNT_active' => new EE_Boolean_Field( |
57 | 57 | 'CNT_active', |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | 'Venue' => new EE_Has_Many_Relation(), |
150 | 150 | ]; |
151 | 151 | // only anyone to view, but only those with the default role can do anything |
152 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
152 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
153 | 153 | |
154 | 154 | parent::__construct($timezone); |
155 | 155 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function get_all_countries() |
164 | 164 | { |
165 | - if (! self::$_all_countries) { |
|
165 | + if ( ! self::$_all_countries) { |
|
166 | 166 | self::$_all_countries = $this->get_all(['order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]); |
167 | 167 | } |
168 | 168 | return self::$_all_countries; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function get_all_active_countries() |
182 | 182 | { |
183 | - if (! self::$_active_countries) { |
|
183 | + if ( ! self::$_active_countries) { |
|
184 | 184 | self::$_active_countries = |
185 | 185 | $this->get_all([['CNT_active' => true], 'order_by' => ['CNT_name' => 'ASC'], 'limit' => [0, 99999]]); |
186 | 186 | } |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | public function get_country_name_by_ISO($country_ISO) |
200 | 200 | { |
201 | 201 | if ( |
202 | - isset(self::$_all_countries[ $country_ISO ]) |
|
203 | - && self::$_all_countries[ $country_ISO ] instanceof EE_Country |
|
202 | + isset(self::$_all_countries[$country_ISO]) |
|
203 | + && self::$_all_countries[$country_ISO] instanceof EE_Country |
|
204 | 204 | ) { |
205 | - return self::$_all_countries[ $country_ISO ]->name(); |
|
205 | + return self::$_all_countries[$country_ISO]->name(); |
|
206 | 206 | } |
207 | 207 | $names = $this->get_col([['CNT_ISO' => $country_ISO], 'limit' => 1], 'CNT_name'); |
208 | 208 | if (is_array($names) && ! empty($names)) { |
@@ -13,290 +13,290 @@ |
||
13 | 13 | class EEM_Term extends EEM_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var EEM_Term |
|
18 | - */ |
|
19 | - protected static $_instance; |
|
16 | + /** |
|
17 | + * @var EEM_Term |
|
18 | + */ |
|
19 | + protected static $_instance; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $timezone |
|
24 | - * @throws EE_Error |
|
25 | - */ |
|
26 | - protected function __construct(string $timezone = '') |
|
27 | - { |
|
28 | - $this->singular_item = esc_html__('Term', 'event_espresso'); |
|
29 | - $this->plural_item = esc_html__('Terms', 'event_espresso'); |
|
30 | - $this->_tables = [ |
|
31 | - 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
32 | - ]; |
|
33 | - $this->_fields = [ |
|
34 | - 'Term' => [ |
|
35 | - 'term_id' => new EE_Primary_Key_Int_Field( |
|
36 | - 'term_id', |
|
37 | - esc_html__('Term ID', 'event_espresso') |
|
38 | - ), |
|
39 | - 'name' => new EE_Plain_Text_Field( |
|
40 | - 'name', |
|
41 | - esc_html__('Term Name', 'event_espresso'), |
|
42 | - false, |
|
43 | - '' |
|
44 | - ), |
|
45 | - 'slug' => new EE_Slug_Field( |
|
46 | - 'slug', |
|
47 | - esc_html__('Term Slug', 'event_espresso'), |
|
48 | - false |
|
49 | - ), |
|
50 | - 'term_group' => new EE_Integer_Field( |
|
51 | - 'term_group', |
|
52 | - esc_html__("Term Group", "event_espresso"), |
|
53 | - false, |
|
54 | - 0 |
|
55 | - ), |
|
56 | - ], |
|
57 | - ]; |
|
58 | - $this->_model_relations = [ |
|
59 | - 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
60 | - ]; |
|
61 | - $this->_wp_core_model = true; |
|
62 | - $path_to_tax_model = 'Term_Taxonomy'; |
|
63 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
64 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
65 | - = new EE_Restriction_Generator_Taxonomy_Protected( |
|
66 | - $path_to_tax_model |
|
67 | - ); |
|
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
69 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
70 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
71 | - // add cap restrictions for editing relating to the "ee_edit_*" |
|
72 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
73 | - [ |
|
74 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'], |
|
75 | - ] |
|
76 | - ); |
|
77 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
78 | - [ |
|
79 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'], |
|
80 | - ] |
|
81 | - ); |
|
82 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
83 | - [ |
|
84 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'], |
|
85 | - ] |
|
86 | - ); |
|
87 | - // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
88 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
89 | - [ |
|
90 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'], |
|
91 | - ] |
|
92 | - ); |
|
93 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
94 | - [ |
|
95 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'], |
|
96 | - ] |
|
97 | - ); |
|
98 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
99 | - [ |
|
100 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'], |
|
101 | - ] |
|
102 | - ); |
|
103 | - parent::__construct($timezone); |
|
104 | - add_filter('FHEE__Read__create_model_query_params', ['EEM_Term', 'rest_api_query_params'], 10, 3); |
|
105 | - } |
|
22 | + /** |
|
23 | + * @param string $timezone |
|
24 | + * @throws EE_Error |
|
25 | + */ |
|
26 | + protected function __construct(string $timezone = '') |
|
27 | + { |
|
28 | + $this->singular_item = esc_html__('Term', 'event_espresso'); |
|
29 | + $this->plural_item = esc_html__('Terms', 'event_espresso'); |
|
30 | + $this->_tables = [ |
|
31 | + 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
32 | + ]; |
|
33 | + $this->_fields = [ |
|
34 | + 'Term' => [ |
|
35 | + 'term_id' => new EE_Primary_Key_Int_Field( |
|
36 | + 'term_id', |
|
37 | + esc_html__('Term ID', 'event_espresso') |
|
38 | + ), |
|
39 | + 'name' => new EE_Plain_Text_Field( |
|
40 | + 'name', |
|
41 | + esc_html__('Term Name', 'event_espresso'), |
|
42 | + false, |
|
43 | + '' |
|
44 | + ), |
|
45 | + 'slug' => new EE_Slug_Field( |
|
46 | + 'slug', |
|
47 | + esc_html__('Term Slug', 'event_espresso'), |
|
48 | + false |
|
49 | + ), |
|
50 | + 'term_group' => new EE_Integer_Field( |
|
51 | + 'term_group', |
|
52 | + esc_html__("Term Group", "event_espresso"), |
|
53 | + false, |
|
54 | + 0 |
|
55 | + ), |
|
56 | + ], |
|
57 | + ]; |
|
58 | + $this->_model_relations = [ |
|
59 | + 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
60 | + ]; |
|
61 | + $this->_wp_core_model = true; |
|
62 | + $path_to_tax_model = 'Term_Taxonomy'; |
|
63 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
64 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
65 | + = new EE_Restriction_Generator_Taxonomy_Protected( |
|
66 | + $path_to_tax_model |
|
67 | + ); |
|
68 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
69 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
70 | + $path_to_tax_model = $path_to_tax_model . '.'; |
|
71 | + // add cap restrictions for editing relating to the "ee_edit_*" |
|
72 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
73 | + [ |
|
74 | + $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'], |
|
75 | + ] |
|
76 | + ); |
|
77 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
78 | + [ |
|
79 | + $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'], |
|
80 | + ] |
|
81 | + ); |
|
82 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
83 | + [ |
|
84 | + $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'], |
|
85 | + ] |
|
86 | + ); |
|
87 | + // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
88 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
89 | + [ |
|
90 | + $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'], |
|
91 | + ] |
|
92 | + ); |
|
93 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
94 | + [ |
|
95 | + $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'], |
|
96 | + ] |
|
97 | + ); |
|
98 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
99 | + [ |
|
100 | + $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'], |
|
101 | + ] |
|
102 | + ); |
|
103 | + parent::__construct($timezone); |
|
104 | + add_filter('FHEE__Read__create_model_query_params', ['EEM_Term', 'rest_api_query_params'], 10, 3); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * retrieves a list of all EE event categories |
|
110 | - * |
|
111 | - * @access public |
|
112 | - * @param bool $show_uncategorized |
|
113 | - * @return EE_Base_Class[] |
|
114 | - * @throws EE_Error |
|
115 | - * @throws ReflectionException |
|
116 | - */ |
|
117 | - public function get_all_ee_categories(bool $show_uncategorized = false): array |
|
118 | - { |
|
119 | - $where_params = [ |
|
120 | - 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
121 | - 'NOT' => ['name' => esc_html__('Uncategorized', 'event_espresso')], |
|
122 | - ]; |
|
123 | - if ($show_uncategorized) { |
|
124 | - unset($where_params['NOT']); |
|
125 | - } |
|
126 | - return EEM_Term::instance()->get_all( |
|
127 | - [ |
|
128 | - $where_params, |
|
129 | - 'order_by' => ['name' => 'ASC'], |
|
130 | - ] |
|
131 | - ); |
|
132 | - } |
|
108 | + /** |
|
109 | + * retrieves a list of all EE event categories |
|
110 | + * |
|
111 | + * @access public |
|
112 | + * @param bool $show_uncategorized |
|
113 | + * @return EE_Base_Class[] |
|
114 | + * @throws EE_Error |
|
115 | + * @throws ReflectionException |
|
116 | + */ |
|
117 | + public function get_all_ee_categories(bool $show_uncategorized = false): array |
|
118 | + { |
|
119 | + $where_params = [ |
|
120 | + 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
121 | + 'NOT' => ['name' => esc_html__('Uncategorized', 'event_espresso')], |
|
122 | + ]; |
|
123 | + if ($show_uncategorized) { |
|
124 | + unset($where_params['NOT']); |
|
125 | + } |
|
126 | + return EEM_Term::instance()->get_all( |
|
127 | + [ |
|
128 | + $where_params, |
|
129 | + 'order_by' => ['name' => 'ASC'], |
|
130 | + ] |
|
131 | + ); |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | - /** |
|
136 | - * retrieves a list of all post_tags associated with an EE CPT |
|
137 | - * |
|
138 | - * @access public |
|
139 | - * @param string $post_type |
|
140 | - * @return array |
|
141 | - * @throws EE_Error |
|
142 | - * @throws ReflectionException |
|
143 | - */ |
|
144 | - public function get_all_CPT_post_tags(string $post_type = ''): array |
|
145 | - { |
|
146 | - switch ($post_type) { |
|
147 | - case 'espresso_events': |
|
148 | - return $this->get_all_event_post_tags(); |
|
149 | - case 'espresso_venues': |
|
150 | - return $this->get_all_venue_post_tags(); |
|
151 | - default: |
|
152 | - $event_tags = $this->get_all_event_post_tags(); |
|
153 | - $venue_tags = $this->get_all_venue_post_tags(); |
|
154 | - return array_merge($event_tags, $venue_tags); |
|
155 | - } |
|
156 | - } |
|
135 | + /** |
|
136 | + * retrieves a list of all post_tags associated with an EE CPT |
|
137 | + * |
|
138 | + * @access public |
|
139 | + * @param string $post_type |
|
140 | + * @return array |
|
141 | + * @throws EE_Error |
|
142 | + * @throws ReflectionException |
|
143 | + */ |
|
144 | + public function get_all_CPT_post_tags(string $post_type = ''): array |
|
145 | + { |
|
146 | + switch ($post_type) { |
|
147 | + case 'espresso_events': |
|
148 | + return $this->get_all_event_post_tags(); |
|
149 | + case 'espresso_venues': |
|
150 | + return $this->get_all_venue_post_tags(); |
|
151 | + default: |
|
152 | + $event_tags = $this->get_all_event_post_tags(); |
|
153 | + $venue_tags = $this->get_all_venue_post_tags(); |
|
154 | + return array_merge($event_tags, $venue_tags); |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - /** |
|
160 | - * returns an EE_Term object for the given tag |
|
161 | - * if it has been utilized by any EE_Events or EE_Venues |
|
162 | - * |
|
163 | - * @param string $tag |
|
164 | - * @return EE_Term|null |
|
165 | - * @throws EE_Error |
|
166 | - * @throws InvalidArgumentException |
|
167 | - * @throws InvalidDataTypeException |
|
168 | - * @throws InvalidInterfaceException |
|
169 | - * @throws ReflectionException |
|
170 | - */ |
|
171 | - public function get_post_tag_for_event_or_venue(string $tag): ?EE_Term |
|
172 | - { |
|
173 | - $post_tag_results = $this->get_all_wpdb_results( |
|
174 | - [ |
|
175 | - [ |
|
176 | - 'slug' => $tag, |
|
177 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
178 | - 'OR' => [ |
|
179 | - 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
180 | - 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
181 | - ], |
|
182 | - ], |
|
183 | - 'default_where_conditions' => 'none', |
|
184 | - 'extra_selects' => [ |
|
185 | - 'event_post_type' => ['Term_Taxonomy___Event_CPT.post_type', '%s'], |
|
186 | - 'venue_post_type' => ['Term_Taxonomy___Venue_CPT.post_type', '%s'], |
|
187 | - ], |
|
188 | - 'group_by' => [ |
|
189 | - 'event_post_type', |
|
190 | - 'venue_post_type', |
|
191 | - ], |
|
192 | - 'limit' => 2, |
|
193 | - ] |
|
194 | - ); |
|
159 | + /** |
|
160 | + * returns an EE_Term object for the given tag |
|
161 | + * if it has been utilized by any EE_Events or EE_Venues |
|
162 | + * |
|
163 | + * @param string $tag |
|
164 | + * @return EE_Term|null |
|
165 | + * @throws EE_Error |
|
166 | + * @throws InvalidArgumentException |
|
167 | + * @throws InvalidDataTypeException |
|
168 | + * @throws InvalidInterfaceException |
|
169 | + * @throws ReflectionException |
|
170 | + */ |
|
171 | + public function get_post_tag_for_event_or_venue(string $tag): ?EE_Term |
|
172 | + { |
|
173 | + $post_tag_results = $this->get_all_wpdb_results( |
|
174 | + [ |
|
175 | + [ |
|
176 | + 'slug' => $tag, |
|
177 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
178 | + 'OR' => [ |
|
179 | + 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
180 | + 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
181 | + ], |
|
182 | + ], |
|
183 | + 'default_where_conditions' => 'none', |
|
184 | + 'extra_selects' => [ |
|
185 | + 'event_post_type' => ['Term_Taxonomy___Event_CPT.post_type', '%s'], |
|
186 | + 'venue_post_type' => ['Term_Taxonomy___Venue_CPT.post_type', '%s'], |
|
187 | + ], |
|
188 | + 'group_by' => [ |
|
189 | + 'event_post_type', |
|
190 | + 'venue_post_type', |
|
191 | + ], |
|
192 | + 'limit' => 2, |
|
193 | + ] |
|
194 | + ); |
|
195 | 195 | |
196 | - $post_types = []; |
|
197 | - foreach ((array) $post_tag_results as $row) { |
|
198 | - if ($row['event_post_type'] === 'espresso_events') { |
|
199 | - $post_types[] = EEM_Event::instance()->post_type(); |
|
200 | - } elseif ($row['venue_post_type'] === 'espresso_venues') { |
|
201 | - $post_types[] = EEM_Venue::instance()->post_type(); |
|
202 | - } |
|
203 | - } |
|
204 | - $post_tag_row = reset($post_tag_results); |
|
205 | - $post_tag = $this->instantiate_class_from_array_or_object($post_tag_row); |
|
206 | - if (! $post_tag instanceof EE_Term) { |
|
207 | - return null; |
|
208 | - } |
|
196 | + $post_types = []; |
|
197 | + foreach ((array) $post_tag_results as $row) { |
|
198 | + if ($row['event_post_type'] === 'espresso_events') { |
|
199 | + $post_types[] = EEM_Event::instance()->post_type(); |
|
200 | + } elseif ($row['venue_post_type'] === 'espresso_venues') { |
|
201 | + $post_types[] = EEM_Venue::instance()->post_type(); |
|
202 | + } |
|
203 | + } |
|
204 | + $post_tag_row = reset($post_tag_results); |
|
205 | + $post_tag = $this->instantiate_class_from_array_or_object($post_tag_row); |
|
206 | + if (! $post_tag instanceof EE_Term) { |
|
207 | + return null; |
|
208 | + } |
|
209 | 209 | |
210 | - if ($post_tag->post_type === null) { |
|
211 | - $post_tag->post_type = []; |
|
212 | - } |
|
213 | - $post_tag->post_type = array_merge($post_tag->post_type, array_unique($post_types)); |
|
214 | - return $post_tag; |
|
215 | - } |
|
210 | + if ($post_tag->post_type === null) { |
|
211 | + $post_tag->post_type = []; |
|
212 | + } |
|
213 | + $post_tag->post_type = array_merge($post_tag->post_type, array_unique($post_types)); |
|
214 | + return $post_tag; |
|
215 | + } |
|
216 | 216 | |
217 | 217 | |
218 | - /** |
|
219 | - * get_all_event_post_tags |
|
220 | - * |
|
221 | - * @return EE_Base_Class[] |
|
222 | - * @throws EE_Error |
|
223 | - * @throws ReflectionException |
|
224 | - */ |
|
225 | - public function get_all_event_post_tags(): array |
|
226 | - { |
|
227 | - $post_tags = EEM_Term::instance()->get_all( |
|
228 | - [ |
|
229 | - [ |
|
230 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
231 | - 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
232 | - ], |
|
233 | - 'order_by' => ['name' => 'ASC'], |
|
234 | - 'force_join' => ['Term_Taxonomy.Event'], |
|
235 | - ] |
|
236 | - ); |
|
237 | - foreach ($post_tags as $key => $post_tag) { |
|
238 | - if (! isset($post_tag->post_type)) { |
|
239 | - $post_tag->post_type = []; |
|
240 | - } |
|
241 | - $post_tag->post_type[] = 'espresso_events'; |
|
242 | - $post_tags[ $key ] = $post_tag; |
|
243 | - } |
|
244 | - return $post_tags; |
|
245 | - } |
|
218 | + /** |
|
219 | + * get_all_event_post_tags |
|
220 | + * |
|
221 | + * @return EE_Base_Class[] |
|
222 | + * @throws EE_Error |
|
223 | + * @throws ReflectionException |
|
224 | + */ |
|
225 | + public function get_all_event_post_tags(): array |
|
226 | + { |
|
227 | + $post_tags = EEM_Term::instance()->get_all( |
|
228 | + [ |
|
229 | + [ |
|
230 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
231 | + 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
232 | + ], |
|
233 | + 'order_by' => ['name' => 'ASC'], |
|
234 | + 'force_join' => ['Term_Taxonomy.Event'], |
|
235 | + ] |
|
236 | + ); |
|
237 | + foreach ($post_tags as $key => $post_tag) { |
|
238 | + if (! isset($post_tag->post_type)) { |
|
239 | + $post_tag->post_type = []; |
|
240 | + } |
|
241 | + $post_tag->post_type[] = 'espresso_events'; |
|
242 | + $post_tags[ $key ] = $post_tag; |
|
243 | + } |
|
244 | + return $post_tags; |
|
245 | + } |
|
246 | 246 | |
247 | 247 | |
248 | - /** |
|
249 | - * get_all_venue_post_tags |
|
250 | - * |
|
251 | - * @return EE_Base_Class[] |
|
252 | - * @throws EE_Error |
|
253 | - * @throws ReflectionException |
|
254 | - */ |
|
255 | - public function get_all_venue_post_tags(): array |
|
256 | - { |
|
257 | - $post_tags = EEM_Term::instance()->get_all( |
|
258 | - [ |
|
259 | - [ |
|
260 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
261 | - 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
262 | - ], |
|
263 | - 'order_by' => ['name' => 'ASC'], |
|
264 | - 'force_join' => ['Term_Taxonomy'], |
|
265 | - ] |
|
266 | - ); |
|
267 | - foreach ($post_tags as $key => $post_tag) { |
|
268 | - if (! isset($post_tag->post_type)) { |
|
269 | - $post_tag->post_type = []; |
|
270 | - } |
|
271 | - $post_tag->post_type[] = 'espresso_venues'; |
|
272 | - $post_tags[ $key ] = $post_tag; |
|
273 | - } |
|
274 | - return $post_tags; |
|
275 | - } |
|
248 | + /** |
|
249 | + * get_all_venue_post_tags |
|
250 | + * |
|
251 | + * @return EE_Base_Class[] |
|
252 | + * @throws EE_Error |
|
253 | + * @throws ReflectionException |
|
254 | + */ |
|
255 | + public function get_all_venue_post_tags(): array |
|
256 | + { |
|
257 | + $post_tags = EEM_Term::instance()->get_all( |
|
258 | + [ |
|
259 | + [ |
|
260 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
261 | + 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
262 | + ], |
|
263 | + 'order_by' => ['name' => 'ASC'], |
|
264 | + 'force_join' => ['Term_Taxonomy'], |
|
265 | + ] |
|
266 | + ); |
|
267 | + foreach ($post_tags as $key => $post_tag) { |
|
268 | + if (! isset($post_tag->post_type)) { |
|
269 | + $post_tag->post_type = []; |
|
270 | + } |
|
271 | + $post_tag->post_type[] = 'espresso_venues'; |
|
272 | + $post_tags[ $key ] = $post_tag; |
|
273 | + } |
|
274 | + return $post_tags; |
|
275 | + } |
|
276 | 276 | |
277 | 277 | |
278 | - /** |
|
279 | - * Makes sure that during REST API queries, we only return terms |
|
280 | - * for term taxonomies which should be shown in the rest api |
|
281 | - * |
|
282 | - * @param array $model_query_params |
|
283 | - * @param array $querystring_query_params |
|
284 | - * @param EEM_Base $model |
|
285 | - * @return array |
|
286 | - * @throws EE_Error |
|
287 | - * @throws EE_Error |
|
288 | - */ |
|
289 | - public static function rest_api_query_params( |
|
290 | - array $model_query_params, |
|
291 | - array $querystring_query_params, |
|
292 | - EEM_Base $model |
|
293 | - ): array { |
|
294 | - if ($model === EEM_Term::instance()) { |
|
295 | - $taxonomies = get_taxonomies(['show_in_rest' => true]); |
|
296 | - if (! empty($taxonomies)) { |
|
297 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies]; |
|
298 | - } |
|
299 | - } |
|
300 | - return $model_query_params; |
|
301 | - } |
|
278 | + /** |
|
279 | + * Makes sure that during REST API queries, we only return terms |
|
280 | + * for term taxonomies which should be shown in the rest api |
|
281 | + * |
|
282 | + * @param array $model_query_params |
|
283 | + * @param array $querystring_query_params |
|
284 | + * @param EEM_Base $model |
|
285 | + * @return array |
|
286 | + * @throws EE_Error |
|
287 | + * @throws EE_Error |
|
288 | + */ |
|
289 | + public static function rest_api_query_params( |
|
290 | + array $model_query_params, |
|
291 | + array $querystring_query_params, |
|
292 | + EEM_Base $model |
|
293 | + ): array { |
|
294 | + if ($model === EEM_Term::instance()) { |
|
295 | + $taxonomies = get_taxonomies(['show_in_rest' => true]); |
|
296 | + if (! empty($taxonomies)) { |
|
297 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies]; |
|
298 | + } |
|
299 | + } |
|
300 | + return $model_query_params; |
|
301 | + } |
|
302 | 302 | } |
@@ -60,44 +60,44 @@ discard block |
||
60 | 60 | ]; |
61 | 61 | $this->_wp_core_model = true; |
62 | 62 | $path_to_tax_model = 'Term_Taxonomy'; |
63 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
64 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] |
|
63 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
64 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] |
|
65 | 65 | = new EE_Restriction_Generator_Taxonomy_Protected( |
66 | 66 | $path_to_tax_model |
67 | 67 | ); |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
69 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
70 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
69 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
70 | + $path_to_tax_model = $path_to_tax_model.'.'; |
|
71 | 71 | // add cap restrictions for editing relating to the "ee_edit_*" |
72 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
72 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
73 | 73 | [ |
74 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'], |
|
74 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'], |
|
75 | 75 | ] |
76 | 76 | ); |
77 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
77 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
78 | 78 | [ |
79 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'], |
|
79 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'], |
|
80 | 80 | ] |
81 | 81 | ); |
82 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
82 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
83 | 83 | [ |
84 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'], |
|
84 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'], |
|
85 | 85 | ] |
86 | 86 | ); |
87 | 87 | // add cap restrictions for deleting relating to the "ee_deleting_*" |
88 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
88 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
89 | 89 | [ |
90 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'], |
|
90 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'], |
|
91 | 91 | ] |
92 | 92 | ); |
93 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
93 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
94 | 94 | [ |
95 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'], |
|
95 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'], |
|
96 | 96 | ] |
97 | 97 | ); |
98 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
98 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
99 | 99 | [ |
100 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'], |
|
100 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'], |
|
101 | 101 | ] |
102 | 102 | ); |
103 | 103 | parent::__construct($timezone); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | } |
204 | 204 | $post_tag_row = reset($post_tag_results); |
205 | 205 | $post_tag = $this->instantiate_class_from_array_or_object($post_tag_row); |
206 | - if (! $post_tag instanceof EE_Term) { |
|
206 | + if ( ! $post_tag instanceof EE_Term) { |
|
207 | 207 | return null; |
208 | 208 | } |
209 | 209 | |
@@ -235,11 +235,11 @@ discard block |
||
235 | 235 | ] |
236 | 236 | ); |
237 | 237 | foreach ($post_tags as $key => $post_tag) { |
238 | - if (! isset($post_tag->post_type)) { |
|
238 | + if ( ! isset($post_tag->post_type)) { |
|
239 | 239 | $post_tag->post_type = []; |
240 | 240 | } |
241 | 241 | $post_tag->post_type[] = 'espresso_events'; |
242 | - $post_tags[ $key ] = $post_tag; |
|
242 | + $post_tags[$key] = $post_tag; |
|
243 | 243 | } |
244 | 244 | return $post_tags; |
245 | 245 | } |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | ] |
266 | 266 | ); |
267 | 267 | foreach ($post_tags as $key => $post_tag) { |
268 | - if (! isset($post_tag->post_type)) { |
|
268 | + if ( ! isset($post_tag->post_type)) { |
|
269 | 269 | $post_tag->post_type = []; |
270 | 270 | } |
271 | 271 | $post_tag->post_type[] = 'espresso_venues'; |
272 | - $post_tags[ $key ] = $post_tag; |
|
272 | + $post_tags[$key] = $post_tag; |
|
273 | 273 | } |
274 | 274 | return $post_tags; |
275 | 275 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | ): array { |
294 | 294 | if ($model === EEM_Term::instance()) { |
295 | 295 | $taxonomies = get_taxonomies(['show_in_rest' => true]); |
296 | - if (! empty($taxonomies)) { |
|
296 | + if ( ! empty($taxonomies)) { |
|
297 | 297 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies]; |
298 | 298 | } |
299 | 299 | } |
@@ -17,465 +17,465 @@ |
||
17 | 17 | class EEM_Payment_Method extends EEM_Base |
18 | 18 | { |
19 | 19 | |
20 | - const scope_cart = 'CART'; |
|
21 | - |
|
22 | - const scope_admin = 'ADMIN'; |
|
23 | - |
|
24 | - const scope_api = 'API'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type EEM_Payment_Method |
|
28 | - */ |
|
29 | - protected static $_instance; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * private constructor to prevent direct creation |
|
34 | - * |
|
35 | - * @param null $timezone |
|
36 | - * @throws EE_Error |
|
37 | - */ |
|
38 | - protected function __construct(string $timezone = '') |
|
39 | - { |
|
40 | - $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
41 | - $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
42 | - $this->_tables = [ |
|
43 | - 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
44 | - ]; |
|
45 | - $this->_fields = [ |
|
46 | - 'Payment_Method' => [ |
|
47 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
48 | - 'PMD_ID', |
|
49 | - esc_html__('ID', 'event_espresso') |
|
50 | - ), |
|
51 | - 'PMD_type' => new EE_Plain_Text_Field( |
|
52 | - 'PMD_type', |
|
53 | - esc_html__('Payment Method Type', 'event_espresso'), |
|
54 | - false, |
|
55 | - 'Admin_Only' |
|
56 | - ), |
|
57 | - 'PMD_name' => new EE_Plain_Text_Field( |
|
58 | - 'PMD_name', |
|
59 | - esc_html__('Name', 'event_espresso'), |
|
60 | - false |
|
61 | - ), |
|
62 | - 'PMD_desc' => new EE_Post_Content_Field( |
|
63 | - 'PMD_desc', |
|
64 | - esc_html__('Description', 'event_espresso'), |
|
65 | - false, |
|
66 | - '' |
|
67 | - ), |
|
68 | - 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
69 | - 'PMD_admin_name', |
|
70 | - esc_html__('Admin-Only Name', 'event_espresso'), |
|
71 | - true |
|
72 | - ), |
|
73 | - 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
74 | - 'PMD_admin_desc', |
|
75 | - esc_html__('Admin-Only Description', 'event_espresso'), |
|
76 | - true |
|
77 | - ), |
|
78 | - 'PMD_slug' => new EE_Slug_Field( |
|
79 | - 'PMD_slug', |
|
80 | - esc_html__('Slug', 'event_espresso'), |
|
81 | - false |
|
82 | - ), |
|
83 | - 'PMD_order' => new EE_Integer_Field( |
|
84 | - 'PMD_order', |
|
85 | - esc_html__('Order', 'event_espresso'), |
|
86 | - false, |
|
87 | - 0 |
|
88 | - ), |
|
89 | - 'PMD_debug_mode' => new EE_Boolean_Field( |
|
90 | - 'PMD_debug_mode', |
|
91 | - esc_html__('Debug Mode On?', 'event_espresso'), |
|
92 | - false, |
|
93 | - false |
|
94 | - ), |
|
95 | - 'PMD_wp_user' => new EE_WP_User_Field( |
|
96 | - 'PMD_wp_user', |
|
97 | - esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
98 | - false |
|
99 | - ), |
|
100 | - 'PMD_open_by_default' => new EE_Boolean_Field( |
|
101 | - 'PMD_open_by_default', |
|
102 | - esc_html__('Open by Default?', 'event_espresso'), |
|
103 | - false, |
|
104 | - false |
|
105 | - ), |
|
106 | - 'PMD_button_url' => new EE_Plain_Text_Field( |
|
107 | - 'PMD_button_url', |
|
108 | - esc_html__('Button URL', 'event_espresso'), |
|
109 | - true, |
|
110 | - '' |
|
111 | - ), |
|
112 | - 'PMD_scope' => new EE_Serialized_Text_Field( |
|
113 | - 'PMD_scope', |
|
114 | - esc_html__('Usable From?', 'event_espresso'), |
|
115 | - false, |
|
116 | - []// possible values currently are 'CART','ADMIN','API' |
|
117 | - ), |
|
118 | - ], |
|
119 | - ]; |
|
120 | - $this->_model_relations = [ |
|
121 | - 'Payment' => new EE_Has_Many_Relation(), |
|
122 | - 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
123 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
124 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
125 | - ]; |
|
126 | - parent::__construct($timezone); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Gets one by the slug provided |
|
132 | - * |
|
133 | - * @param string $slug |
|
134 | - * @return EE_Payment_Method|null |
|
135 | - * @throws EE_Error |
|
136 | - * @throws ReflectionException |
|
137 | - */ |
|
138 | - public function get_one_by_slug(string $slug): ?EE_Payment_Method |
|
139 | - { |
|
140 | - return $this->get_one([['PMD_slug' => $slug]]); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * Gets all the acceptable scopes for payment methods. |
|
146 | - * Keys are their names as store din the DB, and values are nice names for displaying them |
|
147 | - * |
|
148 | - * @return array |
|
149 | - */ |
|
150 | - public function scopes(): array |
|
151 | - { |
|
152 | - return apply_filters( |
|
153 | - 'FHEE__EEM_Payment_Method__scopes', |
|
154 | - [ |
|
155 | - EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
156 | - EEM_Payment_Method::scope_admin => esc_html__( |
|
157 | - 'Admin Registration Page (no online processing)', |
|
158 | - 'event_espresso' |
|
159 | - ), |
|
160 | - ] |
|
161 | - ); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Determines if this is an valid scope |
|
167 | - * |
|
168 | - * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
169 | - * @return boolean |
|
170 | - */ |
|
171 | - public function is_valid_scope(string $scope): bool |
|
172 | - { |
|
173 | - $scopes = $this->scopes(); |
|
174 | - if (isset($scopes[ $scope ])) { |
|
175 | - return true; |
|
176 | - } |
|
177 | - return false; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Gets all active payment methods |
|
183 | - * |
|
184 | - * @param string $scope one of |
|
185 | - * @param array $query_params |
|
186 | - * @return EE_Payment_Method[] |
|
187 | - * @throws EE_Error |
|
188 | - * @throws ReflectionException |
|
189 | - */ |
|
190 | - public function get_all_active(string $scope = '', array $query_params = []): array |
|
191 | - { |
|
192 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
193 | - $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
194 | - } |
|
195 | - return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Counts all active gateways in the specified scope |
|
201 | - * |
|
202 | - * @param string $scope one of EEM_Payment_Method::scope_* |
|
203 | - * @param array $query_params |
|
204 | - * @return int |
|
205 | - * @throws EE_Error |
|
206 | - * @throws ReflectionException |
|
207 | - */ |
|
208 | - public function count_active(string $scope = '', array $query_params = []): int |
|
209 | - { |
|
210 | - return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
216 | - * argument to get all active for a given scope |
|
217 | - * |
|
218 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
219 | - * @param array $query_params |
|
220 | - * @return array |
|
221 | - * @throws EE_Error |
|
222 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
223 | - */ |
|
224 | - protected function _get_query_params_for_all_active(string $scope = '', array $query_params = []): array |
|
225 | - { |
|
226 | - if (! empty($scope)) { |
|
227 | - if ($this->is_valid_scope($scope)) { |
|
228 | - return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
229 | - } |
|
230 | - throw new EE_Error( |
|
231 | - sprintf( |
|
232 | - esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
233 | - $scope |
|
234 | - ) |
|
235 | - ); |
|
236 | - } |
|
237 | - $acceptable_scopes = []; |
|
238 | - $count = 0; |
|
239 | - foreach ($this->scopes() as $scope_name => $desc) { |
|
240 | - $count++; |
|
241 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
242 | - } |
|
243 | - return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
249 | - * argument to get all active for a given scope |
|
250 | - * |
|
251 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
252 | - * @param array $query_params |
|
253 | - * @return array |
|
254 | - * @throws EE_Error |
|
255 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
256 | - */ |
|
257 | - public function get_query_params_for_all_active(string $scope = '', array $query_params = []): array |
|
258 | - { |
|
259 | - return $this->_get_query_params_for_all_active($scope, $query_params); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * Gets one active payment method. see @get_all_active for documentation |
|
265 | - * |
|
266 | - * @param string $scope |
|
267 | - * @param array $query_params |
|
268 | - * @return EE_Payment_Method|null |
|
269 | - * @throws EE_Error |
|
270 | - * @throws ReflectionException |
|
271 | - */ |
|
272 | - public function get_one_active(string $scope = '', array $query_params = []): ?EE_Payment_Method |
|
273 | - { |
|
274 | - return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * Gets one payment method of that type, regardless of whether its active or not |
|
280 | - * |
|
281 | - * @param string $type |
|
282 | - * @return EE_Payment_Method|null |
|
283 | - * @throws EE_Error |
|
284 | - * @throws ReflectionException |
|
285 | - */ |
|
286 | - public function get_one_of_type(string $type): ?EE_Payment_Method |
|
287 | - { |
|
288 | - return $this->get_one([['PMD_type' => $type]]); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Overrides parent to also check by the slug |
|
294 | - * |
|
295 | - * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
296 | - * @param boolean $ensure_is_in_db |
|
297 | - * @return EE_Payment_Method|null |
|
298 | - * @throws EE_Error |
|
299 | - * @throws ReflectionException |
|
300 | - * @see EEM_Base::ensure_is_obj() |
|
301 | - */ |
|
302 | - public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false): ?EE_Payment_Method |
|
303 | - { |
|
304 | - // first: check if it's a slug |
|
305 | - if (is_string($base_class_obj_or_id)) { |
|
306 | - $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
307 | - if ($obj) { |
|
308 | - return $obj; |
|
309 | - } |
|
310 | - } |
|
311 | - // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
312 | - try { |
|
313 | - return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
314 | - } catch (EE_Error $e) { |
|
315 | - throw new EE_Error( |
|
316 | - sprintf( |
|
317 | - esc_html__("'%s' is neither a Payment Method ID, slug, nor object: %s", 'event_espresso'), |
|
318 | - $base_class_obj_or_id, |
|
319 | - $e->getMessage() |
|
320 | - ) |
|
321 | - ); |
|
322 | - } |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * Gets the ID of this object, or if its a string finds the object's id |
|
328 | - * associated with that slug |
|
329 | - * |
|
330 | - * @param int|string $base_obj_or_id_or_slug |
|
331 | - * @return int |
|
332 | - * @throws EE_Error |
|
333 | - * @throws ReflectionException |
|
334 | - */ |
|
335 | - public function ensure_is_ID($base_obj_or_id_or_slug): int |
|
336 | - { |
|
337 | - if (is_string($base_obj_or_id_or_slug)) { |
|
338 | - // assume it's a slug |
|
339 | - $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
340 | - } |
|
341 | - return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * Verifies the button urls on all the passed payment methods have a valid button url. |
|
347 | - * If not, resets them to their default. |
|
348 | - * |
|
349 | - * @param EE_Payment_Method[]|null $payment_methods if NULL, defaults to all payment methods active in the cart |
|
350 | - * @throws EE_Error |
|
351 | - * @throws ReflectionException |
|
352 | - */ |
|
353 | - public function verify_button_urls(array $payment_methods = []) |
|
354 | - { |
|
355 | - $payment_methods = ! empty($payment_methods) && is_array($payment_methods) |
|
356 | - ? $payment_methods |
|
357 | - : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
358 | - foreach ($payment_methods as $payment_method) { |
|
359 | - try { |
|
360 | - // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
361 | - // though this is a caffeinated install, reset it to the default. |
|
362 | - $current_button_url = $payment_method->button_url(); |
|
363 | - if ( |
|
364 | - empty($current_button_url) |
|
365 | - || ( |
|
366 | - strpos($current_button_url, 'decaf') !== false |
|
367 | - && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
368 | - ) |
|
369 | - ) { |
|
370 | - $payment_method->save( |
|
371 | - [ |
|
372 | - 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
373 | - ] |
|
374 | - ); |
|
375 | - } |
|
376 | - } catch (EE_Error $e) { |
|
377 | - $payment_method->deactivate(); |
|
378 | - } |
|
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
385 | - * but also verifies the payment method type of each is a usable object. If not, |
|
386 | - * deactivate it, sets a notification, and deactivates it |
|
387 | - * |
|
388 | - * @param array $rows |
|
389 | - * @return EE_Payment_Method[] |
|
390 | - * @throws EE_Error |
|
391 | - * @throws InvalidDataTypeException |
|
392 | - * @throws ReflectionException |
|
393 | - */ |
|
394 | - protected function _create_objects($rows = []): array |
|
395 | - { |
|
396 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
397 | - $payment_methods = parent::_create_objects($rows); |
|
398 | - /* @var $payment_methods EE_Payment_Method[] */ |
|
399 | - $usable_payment_methods = []; |
|
400 | - foreach ($payment_methods as $key => $payment_method) { |
|
401 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
402 | - $usable_payment_methods[ $key ] = $payment_method; |
|
403 | - // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
404 | - // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
405 | - // its scripts). but for backwards-compat we should continue to do that |
|
406 | - $payment_method->type_obj(); |
|
407 | - } elseif ($payment_method->active()) { |
|
408 | - // only deactivate and notify the admin if the payment is active somewhere |
|
409 | - $payment_method->deactivate(); |
|
410 | - $payment_method->save(); |
|
411 | - do_action( |
|
412 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
413 | - $payment_method |
|
414 | - ); |
|
415 | - new PersistentAdminNotice( |
|
416 | - 'auto-deactivated-' . $payment_method->type(), |
|
417 | - sprintf( |
|
418 | - esc_html__( |
|
419 | - 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
420 | - 'event_espresso' |
|
421 | - ), |
|
422 | - $payment_method->admin_name(), |
|
423 | - '<br />', |
|
424 | - '<a href="' . admin_url('plugins.php') . '">', |
|
425 | - '</a>' |
|
426 | - ), |
|
427 | - true |
|
428 | - ); |
|
429 | - } |
|
430 | - } |
|
431 | - return $usable_payment_methods; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Gets all the payment methods which can be used for transaction |
|
437 | - * (according to the relations between payment methods and events, and |
|
438 | - * the currencies used for the transaction and their relation to payment methods) |
|
439 | - * |
|
440 | - * @param EE_Transaction $transaction |
|
441 | - * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
442 | - * @return EE_Payment_Method[] |
|
443 | - * @throws EE_Error |
|
444 | - * @throws ReflectionException |
|
445 | - */ |
|
446 | - public function get_all_for_transaction(EE_Transaction $transaction, string $scope): array |
|
447 | - { |
|
448 | - // give addons a chance to override what payment methods are chosen based on the transaction |
|
449 | - return apply_filters( |
|
450 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
451 | - $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
452 | - $transaction, |
|
453 | - $scope |
|
454 | - ); |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * Returns the payment method used for the last payment made for a registration. |
|
460 | - * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
461 | - * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
462 | - * |
|
463 | - * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
464 | - * registration. |
|
465 | - * @return EE_Payment|null |
|
466 | - * @throws EE_Error |
|
467 | - * @throws ReflectionException |
|
468 | - */ |
|
469 | - public function get_last_used_for_registration($registration_or_reg_id): ?EE_Payment |
|
470 | - { |
|
471 | - $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
472 | - |
|
473 | - $query_params = [ |
|
474 | - 0 => [ |
|
475 | - 'Payment.Registration.REG_ID' => $registration_id, |
|
476 | - ], |
|
477 | - 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
478 | - ]; |
|
479 | - return $this->get_one($query_params); |
|
480 | - } |
|
20 | + const scope_cart = 'CART'; |
|
21 | + |
|
22 | + const scope_admin = 'ADMIN'; |
|
23 | + |
|
24 | + const scope_api = 'API'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type EEM_Payment_Method |
|
28 | + */ |
|
29 | + protected static $_instance; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * private constructor to prevent direct creation |
|
34 | + * |
|
35 | + * @param null $timezone |
|
36 | + * @throws EE_Error |
|
37 | + */ |
|
38 | + protected function __construct(string $timezone = '') |
|
39 | + { |
|
40 | + $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
41 | + $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
42 | + $this->_tables = [ |
|
43 | + 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
44 | + ]; |
|
45 | + $this->_fields = [ |
|
46 | + 'Payment_Method' => [ |
|
47 | + 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
48 | + 'PMD_ID', |
|
49 | + esc_html__('ID', 'event_espresso') |
|
50 | + ), |
|
51 | + 'PMD_type' => new EE_Plain_Text_Field( |
|
52 | + 'PMD_type', |
|
53 | + esc_html__('Payment Method Type', 'event_espresso'), |
|
54 | + false, |
|
55 | + 'Admin_Only' |
|
56 | + ), |
|
57 | + 'PMD_name' => new EE_Plain_Text_Field( |
|
58 | + 'PMD_name', |
|
59 | + esc_html__('Name', 'event_espresso'), |
|
60 | + false |
|
61 | + ), |
|
62 | + 'PMD_desc' => new EE_Post_Content_Field( |
|
63 | + 'PMD_desc', |
|
64 | + esc_html__('Description', 'event_espresso'), |
|
65 | + false, |
|
66 | + '' |
|
67 | + ), |
|
68 | + 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
69 | + 'PMD_admin_name', |
|
70 | + esc_html__('Admin-Only Name', 'event_espresso'), |
|
71 | + true |
|
72 | + ), |
|
73 | + 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
74 | + 'PMD_admin_desc', |
|
75 | + esc_html__('Admin-Only Description', 'event_espresso'), |
|
76 | + true |
|
77 | + ), |
|
78 | + 'PMD_slug' => new EE_Slug_Field( |
|
79 | + 'PMD_slug', |
|
80 | + esc_html__('Slug', 'event_espresso'), |
|
81 | + false |
|
82 | + ), |
|
83 | + 'PMD_order' => new EE_Integer_Field( |
|
84 | + 'PMD_order', |
|
85 | + esc_html__('Order', 'event_espresso'), |
|
86 | + false, |
|
87 | + 0 |
|
88 | + ), |
|
89 | + 'PMD_debug_mode' => new EE_Boolean_Field( |
|
90 | + 'PMD_debug_mode', |
|
91 | + esc_html__('Debug Mode On?', 'event_espresso'), |
|
92 | + false, |
|
93 | + false |
|
94 | + ), |
|
95 | + 'PMD_wp_user' => new EE_WP_User_Field( |
|
96 | + 'PMD_wp_user', |
|
97 | + esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
98 | + false |
|
99 | + ), |
|
100 | + 'PMD_open_by_default' => new EE_Boolean_Field( |
|
101 | + 'PMD_open_by_default', |
|
102 | + esc_html__('Open by Default?', 'event_espresso'), |
|
103 | + false, |
|
104 | + false |
|
105 | + ), |
|
106 | + 'PMD_button_url' => new EE_Plain_Text_Field( |
|
107 | + 'PMD_button_url', |
|
108 | + esc_html__('Button URL', 'event_espresso'), |
|
109 | + true, |
|
110 | + '' |
|
111 | + ), |
|
112 | + 'PMD_scope' => new EE_Serialized_Text_Field( |
|
113 | + 'PMD_scope', |
|
114 | + esc_html__('Usable From?', 'event_espresso'), |
|
115 | + false, |
|
116 | + []// possible values currently are 'CART','ADMIN','API' |
|
117 | + ), |
|
118 | + ], |
|
119 | + ]; |
|
120 | + $this->_model_relations = [ |
|
121 | + 'Payment' => new EE_Has_Many_Relation(), |
|
122 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
123 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
124 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
125 | + ]; |
|
126 | + parent::__construct($timezone); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Gets one by the slug provided |
|
132 | + * |
|
133 | + * @param string $slug |
|
134 | + * @return EE_Payment_Method|null |
|
135 | + * @throws EE_Error |
|
136 | + * @throws ReflectionException |
|
137 | + */ |
|
138 | + public function get_one_by_slug(string $slug): ?EE_Payment_Method |
|
139 | + { |
|
140 | + return $this->get_one([['PMD_slug' => $slug]]); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * Gets all the acceptable scopes for payment methods. |
|
146 | + * Keys are their names as store din the DB, and values are nice names for displaying them |
|
147 | + * |
|
148 | + * @return array |
|
149 | + */ |
|
150 | + public function scopes(): array |
|
151 | + { |
|
152 | + return apply_filters( |
|
153 | + 'FHEE__EEM_Payment_Method__scopes', |
|
154 | + [ |
|
155 | + EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
156 | + EEM_Payment_Method::scope_admin => esc_html__( |
|
157 | + 'Admin Registration Page (no online processing)', |
|
158 | + 'event_espresso' |
|
159 | + ), |
|
160 | + ] |
|
161 | + ); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Determines if this is an valid scope |
|
167 | + * |
|
168 | + * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
169 | + * @return boolean |
|
170 | + */ |
|
171 | + public function is_valid_scope(string $scope): bool |
|
172 | + { |
|
173 | + $scopes = $this->scopes(); |
|
174 | + if (isset($scopes[ $scope ])) { |
|
175 | + return true; |
|
176 | + } |
|
177 | + return false; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Gets all active payment methods |
|
183 | + * |
|
184 | + * @param string $scope one of |
|
185 | + * @param array $query_params |
|
186 | + * @return EE_Payment_Method[] |
|
187 | + * @throws EE_Error |
|
188 | + * @throws ReflectionException |
|
189 | + */ |
|
190 | + public function get_all_active(string $scope = '', array $query_params = []): array |
|
191 | + { |
|
192 | + if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
193 | + $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
194 | + } |
|
195 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Counts all active gateways in the specified scope |
|
201 | + * |
|
202 | + * @param string $scope one of EEM_Payment_Method::scope_* |
|
203 | + * @param array $query_params |
|
204 | + * @return int |
|
205 | + * @throws EE_Error |
|
206 | + * @throws ReflectionException |
|
207 | + */ |
|
208 | + public function count_active(string $scope = '', array $query_params = []): int |
|
209 | + { |
|
210 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
216 | + * argument to get all active for a given scope |
|
217 | + * |
|
218 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
219 | + * @param array $query_params |
|
220 | + * @return array |
|
221 | + * @throws EE_Error |
|
222 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
223 | + */ |
|
224 | + protected function _get_query_params_for_all_active(string $scope = '', array $query_params = []): array |
|
225 | + { |
|
226 | + if (! empty($scope)) { |
|
227 | + if ($this->is_valid_scope($scope)) { |
|
228 | + return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
229 | + } |
|
230 | + throw new EE_Error( |
|
231 | + sprintf( |
|
232 | + esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
233 | + $scope |
|
234 | + ) |
|
235 | + ); |
|
236 | + } |
|
237 | + $acceptable_scopes = []; |
|
238 | + $count = 0; |
|
239 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
240 | + $count++; |
|
241 | + $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
242 | + } |
|
243 | + return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
249 | + * argument to get all active for a given scope |
|
250 | + * |
|
251 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
252 | + * @param array $query_params |
|
253 | + * @return array |
|
254 | + * @throws EE_Error |
|
255 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
256 | + */ |
|
257 | + public function get_query_params_for_all_active(string $scope = '', array $query_params = []): array |
|
258 | + { |
|
259 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * Gets one active payment method. see @get_all_active for documentation |
|
265 | + * |
|
266 | + * @param string $scope |
|
267 | + * @param array $query_params |
|
268 | + * @return EE_Payment_Method|null |
|
269 | + * @throws EE_Error |
|
270 | + * @throws ReflectionException |
|
271 | + */ |
|
272 | + public function get_one_active(string $scope = '', array $query_params = []): ?EE_Payment_Method |
|
273 | + { |
|
274 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * Gets one payment method of that type, regardless of whether its active or not |
|
280 | + * |
|
281 | + * @param string $type |
|
282 | + * @return EE_Payment_Method|null |
|
283 | + * @throws EE_Error |
|
284 | + * @throws ReflectionException |
|
285 | + */ |
|
286 | + public function get_one_of_type(string $type): ?EE_Payment_Method |
|
287 | + { |
|
288 | + return $this->get_one([['PMD_type' => $type]]); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Overrides parent to also check by the slug |
|
294 | + * |
|
295 | + * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
296 | + * @param boolean $ensure_is_in_db |
|
297 | + * @return EE_Payment_Method|null |
|
298 | + * @throws EE_Error |
|
299 | + * @throws ReflectionException |
|
300 | + * @see EEM_Base::ensure_is_obj() |
|
301 | + */ |
|
302 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false): ?EE_Payment_Method |
|
303 | + { |
|
304 | + // first: check if it's a slug |
|
305 | + if (is_string($base_class_obj_or_id)) { |
|
306 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
307 | + if ($obj) { |
|
308 | + return $obj; |
|
309 | + } |
|
310 | + } |
|
311 | + // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
312 | + try { |
|
313 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
314 | + } catch (EE_Error $e) { |
|
315 | + throw new EE_Error( |
|
316 | + sprintf( |
|
317 | + esc_html__("'%s' is neither a Payment Method ID, slug, nor object: %s", 'event_espresso'), |
|
318 | + $base_class_obj_or_id, |
|
319 | + $e->getMessage() |
|
320 | + ) |
|
321 | + ); |
|
322 | + } |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * Gets the ID of this object, or if its a string finds the object's id |
|
328 | + * associated with that slug |
|
329 | + * |
|
330 | + * @param int|string $base_obj_or_id_or_slug |
|
331 | + * @return int |
|
332 | + * @throws EE_Error |
|
333 | + * @throws ReflectionException |
|
334 | + */ |
|
335 | + public function ensure_is_ID($base_obj_or_id_or_slug): int |
|
336 | + { |
|
337 | + if (is_string($base_obj_or_id_or_slug)) { |
|
338 | + // assume it's a slug |
|
339 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
340 | + } |
|
341 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * Verifies the button urls on all the passed payment methods have a valid button url. |
|
347 | + * If not, resets them to their default. |
|
348 | + * |
|
349 | + * @param EE_Payment_Method[]|null $payment_methods if NULL, defaults to all payment methods active in the cart |
|
350 | + * @throws EE_Error |
|
351 | + * @throws ReflectionException |
|
352 | + */ |
|
353 | + public function verify_button_urls(array $payment_methods = []) |
|
354 | + { |
|
355 | + $payment_methods = ! empty($payment_methods) && is_array($payment_methods) |
|
356 | + ? $payment_methods |
|
357 | + : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
358 | + foreach ($payment_methods as $payment_method) { |
|
359 | + try { |
|
360 | + // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
361 | + // though this is a caffeinated install, reset it to the default. |
|
362 | + $current_button_url = $payment_method->button_url(); |
|
363 | + if ( |
|
364 | + empty($current_button_url) |
|
365 | + || ( |
|
366 | + strpos($current_button_url, 'decaf') !== false |
|
367 | + && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
368 | + ) |
|
369 | + ) { |
|
370 | + $payment_method->save( |
|
371 | + [ |
|
372 | + 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
373 | + ] |
|
374 | + ); |
|
375 | + } |
|
376 | + } catch (EE_Error $e) { |
|
377 | + $payment_method->deactivate(); |
|
378 | + } |
|
379 | + } |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
385 | + * but also verifies the payment method type of each is a usable object. If not, |
|
386 | + * deactivate it, sets a notification, and deactivates it |
|
387 | + * |
|
388 | + * @param array $rows |
|
389 | + * @return EE_Payment_Method[] |
|
390 | + * @throws EE_Error |
|
391 | + * @throws InvalidDataTypeException |
|
392 | + * @throws ReflectionException |
|
393 | + */ |
|
394 | + protected function _create_objects($rows = []): array |
|
395 | + { |
|
396 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
397 | + $payment_methods = parent::_create_objects($rows); |
|
398 | + /* @var $payment_methods EE_Payment_Method[] */ |
|
399 | + $usable_payment_methods = []; |
|
400 | + foreach ($payment_methods as $key => $payment_method) { |
|
401 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
402 | + $usable_payment_methods[ $key ] = $payment_method; |
|
403 | + // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
404 | + // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
405 | + // its scripts). but for backwards-compat we should continue to do that |
|
406 | + $payment_method->type_obj(); |
|
407 | + } elseif ($payment_method->active()) { |
|
408 | + // only deactivate and notify the admin if the payment is active somewhere |
|
409 | + $payment_method->deactivate(); |
|
410 | + $payment_method->save(); |
|
411 | + do_action( |
|
412 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
413 | + $payment_method |
|
414 | + ); |
|
415 | + new PersistentAdminNotice( |
|
416 | + 'auto-deactivated-' . $payment_method->type(), |
|
417 | + sprintf( |
|
418 | + esc_html__( |
|
419 | + 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
420 | + 'event_espresso' |
|
421 | + ), |
|
422 | + $payment_method->admin_name(), |
|
423 | + '<br />', |
|
424 | + '<a href="' . admin_url('plugins.php') . '">', |
|
425 | + '</a>' |
|
426 | + ), |
|
427 | + true |
|
428 | + ); |
|
429 | + } |
|
430 | + } |
|
431 | + return $usable_payment_methods; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Gets all the payment methods which can be used for transaction |
|
437 | + * (according to the relations between payment methods and events, and |
|
438 | + * the currencies used for the transaction and their relation to payment methods) |
|
439 | + * |
|
440 | + * @param EE_Transaction $transaction |
|
441 | + * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
442 | + * @return EE_Payment_Method[] |
|
443 | + * @throws EE_Error |
|
444 | + * @throws ReflectionException |
|
445 | + */ |
|
446 | + public function get_all_for_transaction(EE_Transaction $transaction, string $scope): array |
|
447 | + { |
|
448 | + // give addons a chance to override what payment methods are chosen based on the transaction |
|
449 | + return apply_filters( |
|
450 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
451 | + $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
452 | + $transaction, |
|
453 | + $scope |
|
454 | + ); |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * Returns the payment method used for the last payment made for a registration. |
|
460 | + * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
461 | + * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
462 | + * |
|
463 | + * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
464 | + * registration. |
|
465 | + * @return EE_Payment|null |
|
466 | + * @throws EE_Error |
|
467 | + * @throws ReflectionException |
|
468 | + */ |
|
469 | + public function get_last_used_for_registration($registration_or_reg_id): ?EE_Payment |
|
470 | + { |
|
471 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
472 | + |
|
473 | + $query_params = [ |
|
474 | + 0 => [ |
|
475 | + 'Payment.Registration.REG_ID' => $registration_id, |
|
476 | + ], |
|
477 | + 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
478 | + ]; |
|
479 | + return $this->get_one($query_params); |
|
480 | + } |
|
481 | 481 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | public function is_valid_scope(string $scope): bool |
172 | 172 | { |
173 | 173 | $scopes = $this->scopes(); |
174 | - if (isset($scopes[ $scope ])) { |
|
174 | + if (isset($scopes[$scope])) { |
|
175 | 175 | return true; |
176 | 176 | } |
177 | 177 | return false; |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function get_all_active(string $scope = '', array $query_params = []): array |
191 | 191 | { |
192 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
192 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
193 | 193 | $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
194 | 194 | } |
195 | 195 | return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | protected function _get_query_params_for_all_active(string $scope = '', array $query_params = []): array |
225 | 225 | { |
226 | - if (! empty($scope)) { |
|
226 | + if ( ! empty($scope)) { |
|
227 | 227 | if ($this->is_valid_scope($scope)) { |
228 | 228 | return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
229 | 229 | } |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | $count = 0; |
239 | 239 | foreach ($this->scopes() as $scope_name => $desc) { |
240 | 240 | $count++; |
241 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
241 | + $acceptable_scopes['PMD_scope*'.$count] = ['LIKE', '%'.$scope_name.'%']; |
|
242 | 242 | } |
243 | 243 | return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
244 | 244 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | $usable_payment_methods = []; |
400 | 400 | foreach ($payment_methods as $key => $payment_method) { |
401 | 401 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
402 | - $usable_payment_methods[ $key ] = $payment_method; |
|
402 | + $usable_payment_methods[$key] = $payment_method; |
|
403 | 403 | // some payment methods enqueue their scripts in EE_PMT_*::__construct |
404 | 404 | // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
405 | 405 | // its scripts). but for backwards-compat we should continue to do that |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | $payment_method |
414 | 414 | ); |
415 | 415 | new PersistentAdminNotice( |
416 | - 'auto-deactivated-' . $payment_method->type(), |
|
416 | + 'auto-deactivated-'.$payment_method->type(), |
|
417 | 417 | sprintf( |
418 | 418 | esc_html__( |
419 | 419 | 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | ), |
422 | 422 | $payment_method->admin_name(), |
423 | 423 | '<br />', |
424 | - '<a href="' . admin_url('plugins.php') . '">', |
|
424 | + '<a href="'.admin_url('plugins.php').'">', |
|
425 | 425 | '</a>' |
426 | 426 | ), |
427 | 427 | true |
@@ -6,392 +6,392 @@ |
||
6 | 6 | class EEM_System_Status |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @var EEM_System_Status |
|
11 | - */ |
|
12 | - protected static $_instance; |
|
13 | - |
|
14 | - |
|
15 | - /** |
|
16 | - * This function is a singleton method used to instantiate the EEM_Attendee object |
|
17 | - * |
|
18 | - * @return EEM_System_Status |
|
19 | - */ |
|
20 | - public static function instance(): EEM_System_Status |
|
21 | - { |
|
22 | - |
|
23 | - // check if instance of EEM_System_Status already exists |
|
24 | - if (self::$_instance === null) { |
|
25 | - // instantiate EEM_System_Status |
|
26 | - self::$_instance = new self(); |
|
27 | - } |
|
28 | - return self::$_instance; |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - private function __construct() |
|
33 | - { |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return array where each key is a function name on this class, and each value is SOMETHING-- |
|
39 | - * it might be a value, an array, or an object |
|
40 | - */ |
|
41 | - public function get_system_stati(): array |
|
42 | - { |
|
43 | - return apply_filters( |
|
44 | - 'FHEE__EEM_System_Status__get_system_stati', |
|
45 | - [ |
|
46 | - 'ee_version' => $this->get_ee_version(), |
|
47 | - 'ee_activation_history' => $this->get_ee_activation_history(), |
|
48 | - 'ee_config' => $this->get_ee_config(), |
|
49 | - 'ee_migration_history' => $this->get_ee_migration_history(), |
|
50 | - 'active_plugins' => $this->get_active_plugins(), |
|
51 | - 'wp_settings' => $this->get_wp_settings(), |
|
52 | - 'wp_maintenance_mode' => $this->get_wp_maintenance_mode(), |
|
53 | - 'https_enabled' => $this->get_https_enabled(), |
|
54 | - 'logging_enabled' => $this->get_logging_enabled(), |
|
55 | - 'remote_posting' => $this->get_remote_posting(), |
|
56 | - 'php_version' => $this->php_version(), |
|
57 | - 'php.ini_settings' => $this->get_php_ini_all(), |
|
58 | - 'php_info' => $this->get_php_info(), |
|
59 | - ], |
|
60 | - $this |
|
61 | - ); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function get_ee_version(): string |
|
70 | - { |
|
71 | - return espresso_version(); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function php_version(): string |
|
80 | - { |
|
81 | - return phpversion(); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * |
|
87 | - * @return array, where each key is a plugin name (lower-cased), values are sub-arrays. |
|
88 | - * Sub-arrays like described in wp function get_plugin_data. Ie, * |
|
89 | - * 'Name' => 'Plugin Name', |
|
90 | - * 'PluginURI' => 'Plugin URI', |
|
91 | - * 'Version' => 'Version', |
|
92 | - * 'Description' => 'Description', |
|
93 | - * 'Author' => 'Author', |
|
94 | - * 'AuthorURI' => 'Author URI', |
|
95 | - * 'TextDomain' => 'Text Domain', |
|
96 | - * 'DomainPath' => 'Domain Path', |
|
97 | - * 'Network' => 'Network', |
|
98 | - */ |
|
99 | - public function get_active_plugins(): array |
|
100 | - { |
|
101 | - $active_plugins = (array) get_option('active_plugins', []); |
|
102 | - if (is_multisite()) { |
|
103 | - $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', [])); |
|
104 | - } |
|
105 | - $active_plugins = array_map('strtolower', $active_plugins); |
|
106 | - $plugin_info = []; |
|
107 | - foreach ($active_plugins as $plugin) { |
|
108 | - $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
109 | - |
|
110 | - $plugin_info[ $plugin ] = $plugin_data; |
|
111 | - } |
|
112 | - return $plugin_info; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * |
|
118 | - * @return array with keys 'home_url' and 'site_url' |
|
119 | - */ |
|
120 | - public function get_wp_settings(): array |
|
121 | - { |
|
122 | - $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT); |
|
123 | - if ($wp_memory_int < 67108864) { |
|
124 | - $wp_memory_to_display = '<mark class="error">' |
|
125 | - . sprintf( |
|
126 | - esc_html__( |
|
127 | - '%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', |
|
128 | - 'event_espresso' |
|
129 | - ), |
|
130 | - WP_MEMORY_LIMIT, |
|
131 | - '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', |
|
132 | - '</a>"' |
|
133 | - ) |
|
134 | - . '</mark>'; |
|
135 | - } else { |
|
136 | - $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
137 | - } |
|
138 | - return [ |
|
139 | - 'name' => get_bloginfo('name', 'display'), |
|
140 | - 'is_multisite' => is_multisite(), |
|
141 | - 'version' => get_bloginfo('version', 'display'), |
|
142 | - 'home_url' => home_url(), |
|
143 | - 'site_url' => site_url(), |
|
144 | - 'WP_DEBUG' => WP_DEBUG, |
|
145 | - 'permalink_structure' => get_option('permalink_structure'), |
|
146 | - 'theme' => wp_get_theme(), |
|
147 | - 'gmt_offset' => get_option('gmt_offset'), |
|
148 | - 'timezone_string' => get_option('timezone_string'), |
|
149 | - 'admin_email' => get_bloginfo('admin_email', 'display'), |
|
150 | - 'language' => get_bloginfo('language', 'display'), |
|
151 | - 'wp_max_upload_size' => size_format(wp_max_upload_size()), |
|
152 | - 'wp_memory' => $wp_memory_to_display, |
|
153 | - ]; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * Gets an array of information about the history of ee versions installed |
|
159 | - * |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - public function get_ee_activation_history(): array |
|
163 | - { |
|
164 | - return get_option('espresso_db_update'); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that |
|
170 | - * version was installed |
|
171 | - * |
|
172 | - * @return EE_Data_Migration_Script_Base[] |
|
173 | - */ |
|
174 | - public function get_ee_migration_history(): array |
|
175 | - { |
|
176 | - $presentable_migration_scripts = []; |
|
177 | - $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
|
178 | - foreach ($options as $option_array) { |
|
179 | - $key = str_replace( |
|
180 | - EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
181 | - '', |
|
182 | - $option_array['option_name'] |
|
183 | - ); |
|
184 | - $presentable_migration_scripts[ $key ] = maybe_unserialize($option_array['option_value']); |
|
185 | - } |
|
186 | - return $presentable_migration_scripts; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * |
|
192 | - * @return EE_Config |
|
193 | - */ |
|
194 | - public function get_ee_config(): EE_Config |
|
195 | - { |
|
196 | - return EE_Config::instance(); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463 |
|
202 | - * |
|
203 | - * @return array like the output of phpinfo(), but in an array |
|
204 | - */ |
|
205 | - public function get_php_info(): array |
|
206 | - { |
|
207 | - ob_start(); |
|
208 | - phpinfo(-1); |
|
209 | - |
|
210 | - $pi = preg_replace( |
|
211 | - [ |
|
212 | - '#^.*<body>(.*)</body>.*$#ms', |
|
213 | - '#<h2>PHP License</h2>.*$#ms', |
|
214 | - '#<h1>Configuration</h1>#', |
|
215 | - "#\r?\n#", |
|
216 | - "#</(h1|h2|h3|tr)>#", |
|
217 | - '# +<#', |
|
218 | - "#[ \t]+#", |
|
219 | - '# #', |
|
220 | - '# +#', |
|
221 | - '# class=".*?"#', |
|
222 | - '%'%', |
|
223 | - '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
|
224 | - . '<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
|
225 | - '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
|
226 | - '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
|
227 | - "# +#", |
|
228 | - '#<tr>#', |
|
229 | - '#</tr>#', |
|
230 | - ], |
|
231 | - [ |
|
232 | - '$1', |
|
233 | - '', |
|
234 | - '', |
|
235 | - '', |
|
236 | - '</$1>' . "\n", |
|
237 | - '<', |
|
238 | - ' ', |
|
239 | - ' ', |
|
240 | - ' ', |
|
241 | - '', |
|
242 | - ' ', |
|
243 | - '<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' . |
|
244 | - "\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
245 | - '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
|
246 | - '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
247 | - '<tr><td>Zend Egg</td><td>$1</td></tr>', |
|
248 | - ' ', |
|
249 | - '%S%', |
|
250 | - '%E%', |
|
251 | - ], |
|
252 | - ob_get_clean() |
|
253 | - ); |
|
254 | - |
|
255 | - $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>')); |
|
256 | - unset($sections[0]); |
|
257 | - |
|
258 | - $pi = []; |
|
259 | - foreach ($sections as $section) { |
|
260 | - $n = substr($section, 0, strpos($section, '</h2>')); |
|
261 | - preg_match_all( |
|
262 | - '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', |
|
263 | - $section, |
|
264 | - $ask_apache, |
|
265 | - PREG_SET_ORDER |
|
266 | - ); |
|
267 | - foreach ($ask_apache as $m) { |
|
268 | - $m2 = $m[2] ?? null; |
|
269 | - } |
|
270 | - $pi[ $n ][ $m[1] ] = (! isset($m[3]) || $m2 == $m[3]) |
|
271 | - ? $m2 |
|
272 | - : array_slice($m, 2); |
|
273 | - } |
|
274 | - |
|
275 | - return $pi; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Checks if site responds ot HTTPS |
|
281 | - * |
|
282 | - * @return string |
|
283 | - */ |
|
284 | - public function get_https_enabled(): string |
|
285 | - { |
|
286 | - $home = str_replace("http://", "https://", home_url()); |
|
287 | - $response = wp_remote_get($home); |
|
288 | - if ($response instanceof WP_Error) { |
|
289 | - $error_string = ''; |
|
290 | - foreach ($response->errors as $short_name => $description_array) { |
|
291 | - $error_string .= "<b>$short_name</b>: " . implode(", ", $description_array); |
|
292 | - } |
|
293 | - return $error_string; |
|
294 | - } |
|
295 | - return "ok!"; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * Whether or not a .maintenance file is detected |
|
301 | - * |
|
302 | - * @return string wp_maintenance_mode status |
|
303 | - */ |
|
304 | - public function get_wp_maintenance_mode(): string |
|
305 | - { |
|
306 | - $opened = file_exists(ABSPATH . '.maintenance'); |
|
307 | - return $opened |
|
308 | - ? sprintf( |
|
309 | - esc_html__( |
|
310 | - '%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', |
|
311 | - 'event_espresso' |
|
312 | - ), |
|
313 | - '<strong>', |
|
314 | - '</strong>' |
|
315 | - ) |
|
316 | - : esc_html__('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso'); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * Whether or not logging is enabled |
|
322 | - * |
|
323 | - * @return string logging's status |
|
324 | - */ |
|
325 | - public function get_logging_enabled(): string |
|
326 | - { |
|
327 | - $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
328 | - return $opened |
|
329 | - ? esc_html__('Log Directory is writable', 'event_espresso') |
|
330 | - : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>'); |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Whether curl ro fsock works |
|
336 | - * |
|
337 | - * @return string describing posting's status |
|
338 | - */ |
|
339 | - public function get_remote_posting(): string |
|
340 | - { |
|
341 | - $fsock_works = function_exists('fsockopen'); |
|
342 | - $curl_works = function_exists('curl_init'); |
|
343 | - if ($fsock_works && $curl_works) { |
|
344 | - $status = esc_html__('Your server has fsockopen and cURL enabled.', 'event_espresso'); |
|
345 | - } elseif ($fsock_works) { |
|
346 | - $status = esc_html__('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso'); |
|
347 | - } elseif ($curl_works) { |
|
348 | - $status = esc_html__('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
|
349 | - } else { |
|
350 | - $status = esc_html__( |
|
351 | - 'Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', |
|
352 | - 'event_espresso' |
|
353 | - ) . '</mark>'; |
|
354 | - } |
|
355 | - return $status; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * Gets all the php.ini settings |
|
361 | - * |
|
362 | - * @return array |
|
363 | - */ |
|
364 | - public function get_php_ini_all(): array |
|
365 | - { |
|
366 | - return ini_get_all(); |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * Transforms the php.ini notation for numbers (like '2M') to an integer. |
|
372 | - * |
|
373 | - * @param string $size |
|
374 | - * @return int |
|
375 | - * @noinspection PhpMissingBreakStatementInspection |
|
376 | - */ |
|
377 | - public function let_to_num(string $size): int |
|
378 | - { |
|
379 | - $l = substr($size, -1); |
|
380 | - $ret = substr($size, 0, -1); |
|
381 | - // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
382 | - switch (strtoupper($l)) { |
|
383 | - case 'P': |
|
384 | - $ret *= 1024; |
|
385 | - case 'T': |
|
386 | - $ret *= 1024; |
|
387 | - case 'G': |
|
388 | - $ret *= 1024; |
|
389 | - case 'M': |
|
390 | - $ret *= 1024; |
|
391 | - case 'K': |
|
392 | - $ret *= 1024; |
|
393 | - } |
|
394 | - // phpcs:enable |
|
395 | - return $ret; |
|
396 | - } |
|
9 | + /** |
|
10 | + * @var EEM_System_Status |
|
11 | + */ |
|
12 | + protected static $_instance; |
|
13 | + |
|
14 | + |
|
15 | + /** |
|
16 | + * This function is a singleton method used to instantiate the EEM_Attendee object |
|
17 | + * |
|
18 | + * @return EEM_System_Status |
|
19 | + */ |
|
20 | + public static function instance(): EEM_System_Status |
|
21 | + { |
|
22 | + |
|
23 | + // check if instance of EEM_System_Status already exists |
|
24 | + if (self::$_instance === null) { |
|
25 | + // instantiate EEM_System_Status |
|
26 | + self::$_instance = new self(); |
|
27 | + } |
|
28 | + return self::$_instance; |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + private function __construct() |
|
33 | + { |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return array where each key is a function name on this class, and each value is SOMETHING-- |
|
39 | + * it might be a value, an array, or an object |
|
40 | + */ |
|
41 | + public function get_system_stati(): array |
|
42 | + { |
|
43 | + return apply_filters( |
|
44 | + 'FHEE__EEM_System_Status__get_system_stati', |
|
45 | + [ |
|
46 | + 'ee_version' => $this->get_ee_version(), |
|
47 | + 'ee_activation_history' => $this->get_ee_activation_history(), |
|
48 | + 'ee_config' => $this->get_ee_config(), |
|
49 | + 'ee_migration_history' => $this->get_ee_migration_history(), |
|
50 | + 'active_plugins' => $this->get_active_plugins(), |
|
51 | + 'wp_settings' => $this->get_wp_settings(), |
|
52 | + 'wp_maintenance_mode' => $this->get_wp_maintenance_mode(), |
|
53 | + 'https_enabled' => $this->get_https_enabled(), |
|
54 | + 'logging_enabled' => $this->get_logging_enabled(), |
|
55 | + 'remote_posting' => $this->get_remote_posting(), |
|
56 | + 'php_version' => $this->php_version(), |
|
57 | + 'php.ini_settings' => $this->get_php_ini_all(), |
|
58 | + 'php_info' => $this->get_php_info(), |
|
59 | + ], |
|
60 | + $this |
|
61 | + ); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function get_ee_version(): string |
|
70 | + { |
|
71 | + return espresso_version(); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function php_version(): string |
|
80 | + { |
|
81 | + return phpversion(); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * |
|
87 | + * @return array, where each key is a plugin name (lower-cased), values are sub-arrays. |
|
88 | + * Sub-arrays like described in wp function get_plugin_data. Ie, * |
|
89 | + * 'Name' => 'Plugin Name', |
|
90 | + * 'PluginURI' => 'Plugin URI', |
|
91 | + * 'Version' => 'Version', |
|
92 | + * 'Description' => 'Description', |
|
93 | + * 'Author' => 'Author', |
|
94 | + * 'AuthorURI' => 'Author URI', |
|
95 | + * 'TextDomain' => 'Text Domain', |
|
96 | + * 'DomainPath' => 'Domain Path', |
|
97 | + * 'Network' => 'Network', |
|
98 | + */ |
|
99 | + public function get_active_plugins(): array |
|
100 | + { |
|
101 | + $active_plugins = (array) get_option('active_plugins', []); |
|
102 | + if (is_multisite()) { |
|
103 | + $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', [])); |
|
104 | + } |
|
105 | + $active_plugins = array_map('strtolower', $active_plugins); |
|
106 | + $plugin_info = []; |
|
107 | + foreach ($active_plugins as $plugin) { |
|
108 | + $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
109 | + |
|
110 | + $plugin_info[ $plugin ] = $plugin_data; |
|
111 | + } |
|
112 | + return $plugin_info; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * |
|
118 | + * @return array with keys 'home_url' and 'site_url' |
|
119 | + */ |
|
120 | + public function get_wp_settings(): array |
|
121 | + { |
|
122 | + $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT); |
|
123 | + if ($wp_memory_int < 67108864) { |
|
124 | + $wp_memory_to_display = '<mark class="error">' |
|
125 | + . sprintf( |
|
126 | + esc_html__( |
|
127 | + '%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', |
|
128 | + 'event_espresso' |
|
129 | + ), |
|
130 | + WP_MEMORY_LIMIT, |
|
131 | + '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', |
|
132 | + '</a>"' |
|
133 | + ) |
|
134 | + . '</mark>'; |
|
135 | + } else { |
|
136 | + $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
137 | + } |
|
138 | + return [ |
|
139 | + 'name' => get_bloginfo('name', 'display'), |
|
140 | + 'is_multisite' => is_multisite(), |
|
141 | + 'version' => get_bloginfo('version', 'display'), |
|
142 | + 'home_url' => home_url(), |
|
143 | + 'site_url' => site_url(), |
|
144 | + 'WP_DEBUG' => WP_DEBUG, |
|
145 | + 'permalink_structure' => get_option('permalink_structure'), |
|
146 | + 'theme' => wp_get_theme(), |
|
147 | + 'gmt_offset' => get_option('gmt_offset'), |
|
148 | + 'timezone_string' => get_option('timezone_string'), |
|
149 | + 'admin_email' => get_bloginfo('admin_email', 'display'), |
|
150 | + 'language' => get_bloginfo('language', 'display'), |
|
151 | + 'wp_max_upload_size' => size_format(wp_max_upload_size()), |
|
152 | + 'wp_memory' => $wp_memory_to_display, |
|
153 | + ]; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * Gets an array of information about the history of ee versions installed |
|
159 | + * |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + public function get_ee_activation_history(): array |
|
163 | + { |
|
164 | + return get_option('espresso_db_update'); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that |
|
170 | + * version was installed |
|
171 | + * |
|
172 | + * @return EE_Data_Migration_Script_Base[] |
|
173 | + */ |
|
174 | + public function get_ee_migration_history(): array |
|
175 | + { |
|
176 | + $presentable_migration_scripts = []; |
|
177 | + $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
|
178 | + foreach ($options as $option_array) { |
|
179 | + $key = str_replace( |
|
180 | + EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
181 | + '', |
|
182 | + $option_array['option_name'] |
|
183 | + ); |
|
184 | + $presentable_migration_scripts[ $key ] = maybe_unserialize($option_array['option_value']); |
|
185 | + } |
|
186 | + return $presentable_migration_scripts; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * |
|
192 | + * @return EE_Config |
|
193 | + */ |
|
194 | + public function get_ee_config(): EE_Config |
|
195 | + { |
|
196 | + return EE_Config::instance(); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463 |
|
202 | + * |
|
203 | + * @return array like the output of phpinfo(), but in an array |
|
204 | + */ |
|
205 | + public function get_php_info(): array |
|
206 | + { |
|
207 | + ob_start(); |
|
208 | + phpinfo(-1); |
|
209 | + |
|
210 | + $pi = preg_replace( |
|
211 | + [ |
|
212 | + '#^.*<body>(.*)</body>.*$#ms', |
|
213 | + '#<h2>PHP License</h2>.*$#ms', |
|
214 | + '#<h1>Configuration</h1>#', |
|
215 | + "#\r?\n#", |
|
216 | + "#</(h1|h2|h3|tr)>#", |
|
217 | + '# +<#', |
|
218 | + "#[ \t]+#", |
|
219 | + '# #', |
|
220 | + '# +#', |
|
221 | + '# class=".*?"#', |
|
222 | + '%'%', |
|
223 | + '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
|
224 | + . '<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
|
225 | + '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
|
226 | + '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
|
227 | + "# +#", |
|
228 | + '#<tr>#', |
|
229 | + '#</tr>#', |
|
230 | + ], |
|
231 | + [ |
|
232 | + '$1', |
|
233 | + '', |
|
234 | + '', |
|
235 | + '', |
|
236 | + '</$1>' . "\n", |
|
237 | + '<', |
|
238 | + ' ', |
|
239 | + ' ', |
|
240 | + ' ', |
|
241 | + '', |
|
242 | + ' ', |
|
243 | + '<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' . |
|
244 | + "\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
245 | + '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
|
246 | + '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
247 | + '<tr><td>Zend Egg</td><td>$1</td></tr>', |
|
248 | + ' ', |
|
249 | + '%S%', |
|
250 | + '%E%', |
|
251 | + ], |
|
252 | + ob_get_clean() |
|
253 | + ); |
|
254 | + |
|
255 | + $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>')); |
|
256 | + unset($sections[0]); |
|
257 | + |
|
258 | + $pi = []; |
|
259 | + foreach ($sections as $section) { |
|
260 | + $n = substr($section, 0, strpos($section, '</h2>')); |
|
261 | + preg_match_all( |
|
262 | + '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', |
|
263 | + $section, |
|
264 | + $ask_apache, |
|
265 | + PREG_SET_ORDER |
|
266 | + ); |
|
267 | + foreach ($ask_apache as $m) { |
|
268 | + $m2 = $m[2] ?? null; |
|
269 | + } |
|
270 | + $pi[ $n ][ $m[1] ] = (! isset($m[3]) || $m2 == $m[3]) |
|
271 | + ? $m2 |
|
272 | + : array_slice($m, 2); |
|
273 | + } |
|
274 | + |
|
275 | + return $pi; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Checks if site responds ot HTTPS |
|
281 | + * |
|
282 | + * @return string |
|
283 | + */ |
|
284 | + public function get_https_enabled(): string |
|
285 | + { |
|
286 | + $home = str_replace("http://", "https://", home_url()); |
|
287 | + $response = wp_remote_get($home); |
|
288 | + if ($response instanceof WP_Error) { |
|
289 | + $error_string = ''; |
|
290 | + foreach ($response->errors as $short_name => $description_array) { |
|
291 | + $error_string .= "<b>$short_name</b>: " . implode(", ", $description_array); |
|
292 | + } |
|
293 | + return $error_string; |
|
294 | + } |
|
295 | + return "ok!"; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * Whether or not a .maintenance file is detected |
|
301 | + * |
|
302 | + * @return string wp_maintenance_mode status |
|
303 | + */ |
|
304 | + public function get_wp_maintenance_mode(): string |
|
305 | + { |
|
306 | + $opened = file_exists(ABSPATH . '.maintenance'); |
|
307 | + return $opened |
|
308 | + ? sprintf( |
|
309 | + esc_html__( |
|
310 | + '%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', |
|
311 | + 'event_espresso' |
|
312 | + ), |
|
313 | + '<strong>', |
|
314 | + '</strong>' |
|
315 | + ) |
|
316 | + : esc_html__('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso'); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * Whether or not logging is enabled |
|
322 | + * |
|
323 | + * @return string logging's status |
|
324 | + */ |
|
325 | + public function get_logging_enabled(): string |
|
326 | + { |
|
327 | + $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
328 | + return $opened |
|
329 | + ? esc_html__('Log Directory is writable', 'event_espresso') |
|
330 | + : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>'); |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Whether curl ro fsock works |
|
336 | + * |
|
337 | + * @return string describing posting's status |
|
338 | + */ |
|
339 | + public function get_remote_posting(): string |
|
340 | + { |
|
341 | + $fsock_works = function_exists('fsockopen'); |
|
342 | + $curl_works = function_exists('curl_init'); |
|
343 | + if ($fsock_works && $curl_works) { |
|
344 | + $status = esc_html__('Your server has fsockopen and cURL enabled.', 'event_espresso'); |
|
345 | + } elseif ($fsock_works) { |
|
346 | + $status = esc_html__('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso'); |
|
347 | + } elseif ($curl_works) { |
|
348 | + $status = esc_html__('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
|
349 | + } else { |
|
350 | + $status = esc_html__( |
|
351 | + 'Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', |
|
352 | + 'event_espresso' |
|
353 | + ) . '</mark>'; |
|
354 | + } |
|
355 | + return $status; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * Gets all the php.ini settings |
|
361 | + * |
|
362 | + * @return array |
|
363 | + */ |
|
364 | + public function get_php_ini_all(): array |
|
365 | + { |
|
366 | + return ini_get_all(); |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * Transforms the php.ini notation for numbers (like '2M') to an integer. |
|
372 | + * |
|
373 | + * @param string $size |
|
374 | + * @return int |
|
375 | + * @noinspection PhpMissingBreakStatementInspection |
|
376 | + */ |
|
377 | + public function let_to_num(string $size): int |
|
378 | + { |
|
379 | + $l = substr($size, -1); |
|
380 | + $ret = substr($size, 0, -1); |
|
381 | + // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
382 | + switch (strtoupper($l)) { |
|
383 | + case 'P': |
|
384 | + $ret *= 1024; |
|
385 | + case 'T': |
|
386 | + $ret *= 1024; |
|
387 | + case 'G': |
|
388 | + $ret *= 1024; |
|
389 | + case 'M': |
|
390 | + $ret *= 1024; |
|
391 | + case 'K': |
|
392 | + $ret *= 1024; |
|
393 | + } |
|
394 | + // phpcs:enable |
|
395 | + return $ret; |
|
396 | + } |
|
397 | 397 | } |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | $active_plugins = array_map('strtolower', $active_plugins); |
106 | 106 | $plugin_info = []; |
107 | 107 | foreach ($active_plugins as $plugin) { |
108 | - $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
108 | + $plugin_data = @get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin); |
|
109 | 109 | |
110 | - $plugin_info[ $plugin ] = $plugin_data; |
|
110 | + $plugin_info[$plugin] = $plugin_data; |
|
111 | 111 | } |
112 | 112 | return $plugin_info; |
113 | 113 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | ) |
134 | 134 | . '</mark>'; |
135 | 135 | } else { |
136 | - $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
136 | + $wp_memory_to_display = '<mark class="yes">'.size_format($wp_memory_int).'</mark>'; |
|
137 | 137 | } |
138 | 138 | return [ |
139 | 139 | 'name' => get_bloginfo('name', 'display'), |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | $presentable_migration_scripts = []; |
177 | 177 | $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
178 | 178 | foreach ($options as $option_array) { |
179 | - $key = str_replace( |
|
179 | + $key = str_replace( |
|
180 | 180 | EE_Data_Migration_Manager::data_migration_script_option_prefix, |
181 | 181 | '', |
182 | 182 | $option_array['option_name'] |
183 | 183 | ); |
184 | - $presentable_migration_scripts[ $key ] = maybe_unserialize($option_array['option_value']); |
|
184 | + $presentable_migration_scripts[$key] = maybe_unserialize($option_array['option_value']); |
|
185 | 185 | } |
186 | 186 | return $presentable_migration_scripts; |
187 | 187 | } |
@@ -233,17 +233,17 @@ discard block |
||
233 | 233 | '', |
234 | 234 | '', |
235 | 235 | '', |
236 | - '</$1>' . "\n", |
|
236 | + '</$1>'."\n", |
|
237 | 237 | '<', |
238 | 238 | ' ', |
239 | 239 | ' ', |
240 | 240 | ' ', |
241 | 241 | '', |
242 | 242 | ' ', |
243 | - '<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' . |
|
244 | - "\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
243 | + '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'. |
|
244 | + "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
245 | 245 | '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
246 | - '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
246 | + '<tr><td>Zend Engine</td><td>$2</td></tr>'."\n". |
|
247 | 247 | '<tr><td>Zend Egg</td><td>$1</td></tr>', |
248 | 248 | ' ', |
249 | 249 | '%S%', |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | foreach ($ask_apache as $m) { |
268 | 268 | $m2 = $m[2] ?? null; |
269 | 269 | } |
270 | - $pi[ $n ][ $m[1] ] = (! isset($m[3]) || $m2 == $m[3]) |
|
270 | + $pi[$n][$m[1]] = ( ! isset($m[3]) || $m2 == $m[3]) |
|
271 | 271 | ? $m2 |
272 | 272 | : array_slice($m, 2); |
273 | 273 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | if ($response instanceof WP_Error) { |
289 | 289 | $error_string = ''; |
290 | 290 | foreach ($response->errors as $short_name => $description_array) { |
291 | - $error_string .= "<b>$short_name</b>: " . implode(", ", $description_array); |
|
291 | + $error_string .= "<b>$short_name</b>: ".implode(", ", $description_array); |
|
292 | 292 | } |
293 | 293 | return $error_string; |
294 | 294 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public function get_wp_maintenance_mode(): string |
305 | 305 | { |
306 | - $opened = file_exists(ABSPATH . '.maintenance'); |
|
306 | + $opened = file_exists(ABSPATH.'.maintenance'); |
|
307 | 307 | return $opened |
308 | 308 | ? sprintf( |
309 | 309 | esc_html__( |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | */ |
325 | 325 | public function get_logging_enabled(): string |
326 | 326 | { |
327 | - $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
327 | + $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR.'/logs/espresso_log.txt', 'a'); |
|
328 | 328 | return $opened |
329 | 329 | ? esc_html__('Log Directory is writable', 'event_espresso') |
330 | 330 | : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>'); |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | $status = esc_html__( |
351 | 351 | 'Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', |
352 | 352 | 'event_espresso' |
353 | - ) . '</mark>'; |
|
353 | + ).'</mark>'; |
|
354 | 354 | } |
355 | 355 | return $status; |
356 | 356 | } |
@@ -12,482 +12,482 @@ |
||
12 | 12 | class EEM_Message_Template_Group extends EEM_Soft_Delete_Base |
13 | 13 | { |
14 | 14 | |
15 | - // private instance of the EEM_Message_Template_Group object |
|
16 | - protected static $_instance; |
|
17 | - |
|
18 | - |
|
19 | - protected function __construct(string $timezone = '') |
|
20 | - { |
|
21 | - $this->singular_item = esc_html__('Message Template Group', 'event_espresso'); |
|
22 | - $this->plural_item = esc_html__('Message Template Groups', 'event_espresso'); |
|
23 | - $this->_tables = [ |
|
24 | - 'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID'), |
|
25 | - ]; |
|
26 | - $this->_fields = [ |
|
27 | - 'Message_Template_Group' => [ |
|
28 | - 'GRP_ID' => new EE_Primary_Key_Int_Field( |
|
29 | - 'GRP_ID', esc_html__('Message Template Group ID', 'event_espresso') |
|
30 | - ), |
|
31 | - 'MTP_name' => new EE_Plain_Text_Field( |
|
32 | - 'MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, '' |
|
33 | - ), |
|
34 | - 'MTP_description' => new EE_Simple_HTML_Field( |
|
35 | - 'MTP_description', |
|
36 | - esc_html__('A brief description about this template.', 'event_espresso'), |
|
37 | - false, |
|
38 | - '' |
|
39 | - ), |
|
40 | - 'MTP_user_id' => new EE_WP_User_Field( |
|
41 | - 'MTP_user_id', |
|
42 | - esc_html__('Template Creator ID', 'event_espresso'), |
|
43 | - false |
|
44 | - ), |
|
45 | - 'MTP_messenger' => new EE_Plain_Text_Field( |
|
46 | - 'MTP_messenger', |
|
47 | - esc_html__('Messenger Used for Template', 'event_espresso'), |
|
48 | - false, |
|
49 | - 'email' |
|
50 | - ), |
|
51 | - 'MTP_message_type' => new EE_Plain_Text_Field( |
|
52 | - 'MTP_message_type', |
|
53 | - esc_html__('Message Type', 'event_espresso'), |
|
54 | - false, |
|
55 | - 'registration' |
|
56 | - ), |
|
57 | - 'MTP_is_global' => new EE_Boolean_Field( |
|
58 | - 'MTP_is_global', |
|
59 | - esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), |
|
60 | - false, |
|
61 | - true |
|
62 | - ), |
|
63 | - 'MTP_is_override' => new EE_Boolean_Field( |
|
64 | - 'MTP_is_override', |
|
65 | - esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/message type combination', |
|
66 | - 'event_espresso'), |
|
67 | - false, |
|
68 | - false |
|
69 | - ), |
|
70 | - 'MTP_deleted' => new EE_Trashed_Flag_Field( |
|
71 | - 'MTP_deleted', |
|
72 | - esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), |
|
73 | - false, |
|
74 | - false |
|
75 | - ), |
|
76 | - 'MTP_is_active' => new EE_Boolean_Field( |
|
77 | - 'MTP_is_active', |
|
78 | - esc_html__('Flag indicating whether template group is active', 'event_espresso'), |
|
79 | - false, |
|
80 | - true |
|
81 | - ), |
|
82 | - ], |
|
83 | - ]; |
|
84 | - $this->_model_relations = [ |
|
85 | - 'Message_Template' => new EE_Has_Many_Relation(), |
|
86 | - 'Message' => new EE_Has_Many_Relation(), |
|
87 | - 'Event' => new EE_HABTM_Relation('Event_Message_Template'), |
|
88 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
89 | - ]; |
|
90 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
91 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
92 | - } |
|
93 | - $this->_caps_slug = 'messages'; |
|
94 | - |
|
95 | - parent::__construct($timezone); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * get_all_trashed_message_templates_by_event |
|
101 | - * |
|
102 | - * @param int $EVT_ID specific event id |
|
103 | - * @param string $orderby |
|
104 | - * @param string $order |
|
105 | - * @param int|null $limit |
|
106 | - * @param bool $count |
|
107 | - * @return EE_Message_Template_Group[]|int message template objects that are attached to a specific event. |
|
108 | - */ |
|
109 | - public function get_all_trashed_message_templates_by_event( |
|
110 | - int $EVT_ID, |
|
111 | - string $orderby = 'GRP_ID', |
|
112 | - string $order = 'ASC', |
|
113 | - int $limit = null, |
|
114 | - bool $count = false |
|
115 | - ) { |
|
116 | - $query_params = [['Event.EVT_ID' => $EVT_ID], 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
117 | - return $count |
|
118 | - ? $this->count_deleted($query_params, 'GRP_ID', true) |
|
119 | - : $this->get_all_deleted($query_params); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * get_all_message_templates_by_messenger |
|
125 | - * |
|
126 | - * @param string $messenger |
|
127 | - * @param string $orderby |
|
128 | - * @param string $order |
|
129 | - * @return EE_Message_Template_Group[] all (including trashed or inactive) message template group objects for the |
|
130 | - * given messenger |
|
131 | - */ |
|
132 | - public function get_all_message_templates_by_messenger(string $messenger, |
|
133 | - string $orderby = 'GRP_ID', |
|
134 | - string $order = 'ASC'): array |
|
135 | - { |
|
136 | - return $this->get_all_deleted_and_undeleted( |
|
137 | - [['MTP_messenger' => $messenger], 'order_by' => [$orderby => $order]] |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * This simply adds on any messenger/message type filters that may be present in the $_POST global |
|
144 | - * |
|
145 | - * @param array $_where any existing where conditions to append these to. |
|
146 | - * @return EE_Message_Template_Group[] original where conditions or original with additional filters. |
|
147 | - */ |
|
148 | - protected function _maybe_mtp_filters(array $_where = []): array |
|
149 | - { |
|
150 | - // account for messenger or message type filters |
|
151 | - if ( |
|
152 | - isset($_REQUEST['ee_messenger_filter_by']) |
|
153 | - && $_REQUEST['ee_messenger_filter_by'] != 'none_selected' |
|
154 | - && $_REQUEST['ee_messenger_filter_by'] != 'all' |
|
155 | - ) { |
|
156 | - $_where['MTP_messenger'] = $_REQUEST['ee_messenger_filter_by']; |
|
157 | - } |
|
158 | - |
|
159 | - if ( |
|
160 | - isset($_REQUEST['ee_message_type_filter_by']) |
|
161 | - && $_REQUEST['ee_message_type_filter_by'] != 'none_selected' |
|
162 | - ) { |
|
163 | - $_where['MTP_message_type'] = $_REQUEST['ee_message_type_filter_by']; |
|
164 | - } |
|
165 | - |
|
166 | - return $_where; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * get_all_active_message_templates groups |
|
172 | - * |
|
173 | - * @param string $orderby |
|
174 | - * @param string $order |
|
175 | - * @param int|null $limit |
|
176 | - * @param bool $count |
|
177 | - * @param bool $global |
|
178 | - * @param bool $user_check |
|
179 | - * @return EE_Message_Template_Group[]|int all active (non_trashed, active) message template objects |
|
180 | - * @throws EE_Error |
|
181 | - * @throws ReflectionException |
|
182 | - */ |
|
183 | - public function get_all_active_message_templates( |
|
184 | - string $orderby = 'GRP_ID', |
|
185 | - string $order = 'ASC', |
|
186 | - int $limit = null, |
|
187 | - bool $count = false, |
|
188 | - bool $global = true, |
|
189 | - bool $user_check = false |
|
190 | - ): array { |
|
191 | - $_where = $global ? ['MTP_is_global' => true] : ['MTP_is_global' => false]; |
|
192 | - $_where['MTP_is_active'] = true; |
|
193 | - $_where = $this->_maybe_mtp_filters($_where); |
|
194 | - |
|
195 | - if ( |
|
196 | - $user_check |
|
197 | - && ! $global |
|
198 | - && ! EE_Registry::instance()->CAP->current_user_can( |
|
199 | - 'ee_read_others_messages', |
|
200 | - 'get_all_active_message_templates' |
|
201 | - ) |
|
202 | - ) { |
|
203 | - $_where['MTP_user_id'] = get_current_user_id(); |
|
204 | - } |
|
205 | - |
|
206 | - $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
207 | - |
|
208 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * retrieve ALL message_template groups from db regardless of wht |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @param string $orderby |
|
217 | - * @param string $order |
|
218 | - * @param int|null $limit |
|
219 | - * @param bool $count |
|
220 | - * @return EE_Message_Template_Group[] |
|
221 | - */ |
|
222 | - public function get_all_message_templates( |
|
223 | - string $orderby = 'GRP_ID', |
|
224 | - string $order = 'ASC', |
|
225 | - int $limit = null, |
|
226 | - bool $count = false |
|
227 | - ): array { |
|
228 | - $_where = $this->_maybe_mtp_filters(); |
|
229 | - |
|
230 | - $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
231 | - |
|
232 | - return $count |
|
233 | - ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
|
234 | - : $this->get_all_deleted_and_undeleted($query_params); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * This gets all the custom templates attached to a specific event |
|
240 | - * |
|
241 | - * @param int $EVT_ID event id |
|
242 | - * @param array $query_params @see |
|
243 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
244 | - * @return EE_Message_Template_Group[] |
|
245 | - * @throws EE_Error |
|
246 | - * @throws ReflectionException |
|
247 | - */ |
|
248 | - public function get_all_custom_templates_by_event(int $EVT_ID, array $query_params = []): array |
|
249 | - { |
|
250 | - $where = array_merge($query_params, ['Event.EVT_ID' => $EVT_ID]); |
|
251 | - return $this->get_all([$where]); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * get_all_trashed_grouped_message_templates |
|
257 | - * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed |
|
258 | - * |
|
259 | - * @param string $orderby |
|
260 | - * @param string $order |
|
261 | - * @param int|null $limit |
|
262 | - * @param bool $count |
|
263 | - * @param bool $global |
|
264 | - * @return EE_Message_Template_Group[]|int message template groups. |
|
265 | - */ |
|
266 | - public function get_all_trashed_grouped_message_templates( |
|
267 | - string $orderby = 'GRP_ID', |
|
268 | - string $order = 'ASC', |
|
269 | - int $limit = null, |
|
270 | - bool $count = false, |
|
271 | - bool $global = true |
|
272 | - ) { |
|
273 | - $_where = $global ? ['MTP_is_global' => true] : ['MTP_is_global' => false]; |
|
274 | - $_where['MTP_is_active'] = true; |
|
275 | - $_where = $this->_maybe_mtp_filters($_where); |
|
276 | - |
|
277 | - $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
278 | - |
|
279 | - return $count |
|
280 | - ? $this->count_deleted($query_params, 'GRP_ID', true) |
|
281 | - : $this->get_all_deleted($query_params); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * this returns the message template group(s) for a given event, messenger, and message template |
|
287 | - * |
|
288 | - * @param string $messenger |
|
289 | - * @param string $message_type |
|
290 | - * @param int $evt_id |
|
291 | - * @param string $orderby pointless at this point but still included |
|
292 | - * @param string $order |
|
293 | - * @param int|null $limit |
|
294 | - * @param bool $count true = just return count, false = objects |
|
295 | - * @param bool $active ignore "active" or not. (default only return active) |
|
296 | - * @return EE_Message_Template_Group[]|int depending on $count. |
|
297 | - * @throws EE_Error |
|
298 | - * @throws ReflectionException |
|
299 | - */ |
|
300 | - public function get_event_message_templates_by_m_and_mt_and_evt( |
|
301 | - string $messenger, |
|
302 | - string $message_type, |
|
303 | - int $evt_id, |
|
304 | - string $orderby = 'GRP_ID', |
|
305 | - string $order = 'ASC', |
|
306 | - int $limit = null, |
|
307 | - bool $count = false, |
|
308 | - bool $active = true |
|
309 | - ) { |
|
310 | - $_where = [ |
|
311 | - 'MTP_messenger' => $messenger, |
|
312 | - 'MTP_message_type' => $message_type, |
|
313 | - 'Event.EVT_ID' => $evt_id, |
|
314 | - 'MTP_is_global' => true, |
|
315 | - 'MTP_is_active' => $active, |
|
316 | - ]; |
|
317 | - |
|
318 | - $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
319 | - |
|
320 | - return $count |
|
321 | - ? $this->count($query_params, 'GRP_ID', true) |
|
322 | - : $this->get_all($query_params); |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * get all GLOBAL message template groups for the given messenger and message type |
|
328 | - * |
|
329 | - * @param string $messenger slug for messenger |
|
330 | - * @param string $message_type slug for message type |
|
331 | - * @param string $orderby what column to orderby |
|
332 | - * @param string $order ASC or DESC |
|
333 | - * @param int|null $limit |
|
334 | - * @param bool $count true = just return count, false = objects |
|
335 | - * @param bool $active ignore "active" or not. (default only return active) - |
|
336 | - * 'all' means return both inactive AND inactive. |
|
337 | - * @return EE_Message_Template_Group[]|int message template objects that are global (i.e. non-event) |
|
338 | - * @throws EE_Error |
|
339 | - * @throws ReflectionException |
|
340 | - */ |
|
341 | - public function get_global_message_template_by_m_and_mt( |
|
342 | - string $messenger, |
|
343 | - string $message_type, |
|
344 | - string $orderby = 'GRP_ID', |
|
345 | - string $order = 'ASC', |
|
346 | - int $limit = null, |
|
347 | - bool $count = false, |
|
348 | - bool $active = true |
|
349 | - ) { |
|
350 | - $_where = [ |
|
351 | - 'MTP_messenger' => $messenger, |
|
352 | - 'MTP_message_type' => $message_type, |
|
353 | - 'MTP_is_global' => true, |
|
354 | - ]; |
|
355 | - |
|
356 | - if ($active != 'all') { |
|
357 | - $_where['MTP_is_active'] = $active; |
|
358 | - } |
|
359 | - |
|
360 | - $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
361 | - |
|
362 | - return $count |
|
363 | - ? $this->count($query_params, 'GRP_ID', true) |
|
364 | - : $this->get_all($query_params); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * get all custom message template groups for the given messenger and message type |
|
370 | - * |
|
371 | - * @param string $messenger |
|
372 | - * @param string $message_type |
|
373 | - * @param array $query_params same as EEM_Base->get_all() |
|
374 | - * @return EE_Message_Template_Group[] |
|
375 | - * @throws EE_Error |
|
376 | - * @throws ReflectionException |
|
377 | - */ |
|
378 | - public function get_custom_message_template_by_m_and_mt(string $messenger, string $message_type, array $query_params = []): array |
|
379 | - { |
|
380 | - return $this->get_all( |
|
381 | - array_merge( |
|
382 | - $query_params, |
|
383 | - [ |
|
384 | - [ |
|
385 | - 'MTP_is_global' => false, |
|
386 | - 'MTP_messenger' => $messenger, |
|
387 | - 'MTP_message_type' => $message_type, |
|
388 | - ], |
|
389 | - ] |
|
390 | - ) |
|
391 | - ); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * This sends things to the validator for the given messenger and message type. |
|
397 | - * |
|
398 | - * @param array $fields the incoming fields to check. |
|
399 | - * Note this array is in the formatted fields from the form fields setup. |
|
400 | - * So we need to reformat this into an array of expected field refs by the validator. |
|
401 | - * Note also that this is not only the fields for the Message Template Group |
|
402 | - * but ALSO for Message Template. |
|
403 | - * @param string $context The context the fields were obtained from. |
|
404 | - * @param string $messenger The messenger we are validating |
|
405 | - * @param string $message_type The message type we are validating. |
|
406 | - * @return mixed If the fields all check out then we return true otherwise error messages are returned |
|
407 | - * (indexed by field name); |
|
408 | - * @throws EE_Error |
|
409 | - * @throws ReflectionException |
|
410 | - */ |
|
411 | - public function validate(array $fields, string $context, string $messenger, string $message_type) |
|
412 | - { |
|
413 | - |
|
414 | - $assembled_fields = []; |
|
415 | - |
|
416 | - // let's loop through all the fields and set them up in the right format |
|
417 | - foreach ($fields as $value) { |
|
418 | - // first let's figure out if the value['content'] in the current index is an array. |
|
419 | - // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
420 | - if (is_array($value['content'])) { |
|
421 | - $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
422 | - // loop through the content and get the other fields. |
|
423 | - foreach ($value['content'] as $name => $val) { |
|
424 | - if ($name == 'main') { |
|
425 | - continue; |
|
426 | - } |
|
427 | - $assembled_fields[ $name ] = $val; |
|
428 | - } |
|
429 | - continue; |
|
430 | - } |
|
431 | - |
|
432 | - // okay if we're here then this is just a straight field=>$value arrangement |
|
433 | - $assembled_fields[ $value['name'] ] = $value['content']; |
|
434 | - } |
|
435 | - |
|
436 | - // now we've got the assembled_fields. |
|
437 | - // We need to setup the string for the appropriate validator class and call that. |
|
438 | - $m_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
439 | - $m_ref = str_replace(' ', '_', $m_ref); |
|
440 | - $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
441 | - $mt_ref = str_replace(' ', '_', $mt_ref); |
|
442 | - |
|
443 | - $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
444 | - |
|
445 | - if (! class_exists($classname)) { |
|
446 | - $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
447 | - $msg[] = sprintf( |
|
448 | - esc_html__( |
|
449 | - 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
450 | - 'event_espresso' |
|
451 | - ), |
|
452 | - $classname |
|
453 | - ); |
|
454 | - throw new EE_Error(implode('||', $msg)); |
|
455 | - } |
|
456 | - |
|
457 | - $a = new ReflectionClass($classname); |
|
458 | - $_VLD = $a->newInstance($assembled_fields, $context); |
|
459 | - return $_VLD->validate(); |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * Updates all message template groups matching the incoming arguments to inactive status. |
|
465 | - * |
|
466 | - * @param array $messenger_names The messenger slugs. |
|
467 | - * If empty then all templates matching the message types are marked inactive. |
|
468 | - * Otherwise only templates matching the messengers and message types. |
|
469 | - * @param array $message_type_names The message type slugs. |
|
470 | - * If empty then all templates matching the messengers are marked inactive. |
|
471 | - * Otherwise only templates matching the messengers and message types. |
|
472 | - * |
|
473 | - * @return int count of updated records. |
|
474 | - * @throws EE_Error |
|
475 | - * @throws ReflectionException |
|
476 | - */ |
|
477 | - public function deactivate_message_template_groups_for( |
|
478 | - array $messenger_names = [], |
|
479 | - array $message_type_names = [] |
|
480 | - ): int { |
|
481 | - $query_args = []; |
|
482 | - if (empty($messenger_names) && empty($message_type_names)) { |
|
483 | - return 0; |
|
484 | - } |
|
485 | - if (! empty($messenger_names)) { |
|
486 | - $query_args[0]['MTP_messenger'] = ['IN', $messenger_names]; |
|
487 | - } |
|
488 | - if (! empty($message_type_names)) { |
|
489 | - $query_args[0]['MTP_message_type'] = ['IN', $message_type_names]; |
|
490 | - } |
|
491 | - return $this->update(['MTP_is_active' => false], $query_args); |
|
492 | - } |
|
15 | + // private instance of the EEM_Message_Template_Group object |
|
16 | + protected static $_instance; |
|
17 | + |
|
18 | + |
|
19 | + protected function __construct(string $timezone = '') |
|
20 | + { |
|
21 | + $this->singular_item = esc_html__('Message Template Group', 'event_espresso'); |
|
22 | + $this->plural_item = esc_html__('Message Template Groups', 'event_espresso'); |
|
23 | + $this->_tables = [ |
|
24 | + 'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID'), |
|
25 | + ]; |
|
26 | + $this->_fields = [ |
|
27 | + 'Message_Template_Group' => [ |
|
28 | + 'GRP_ID' => new EE_Primary_Key_Int_Field( |
|
29 | + 'GRP_ID', esc_html__('Message Template Group ID', 'event_espresso') |
|
30 | + ), |
|
31 | + 'MTP_name' => new EE_Plain_Text_Field( |
|
32 | + 'MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, '' |
|
33 | + ), |
|
34 | + 'MTP_description' => new EE_Simple_HTML_Field( |
|
35 | + 'MTP_description', |
|
36 | + esc_html__('A brief description about this template.', 'event_espresso'), |
|
37 | + false, |
|
38 | + '' |
|
39 | + ), |
|
40 | + 'MTP_user_id' => new EE_WP_User_Field( |
|
41 | + 'MTP_user_id', |
|
42 | + esc_html__('Template Creator ID', 'event_espresso'), |
|
43 | + false |
|
44 | + ), |
|
45 | + 'MTP_messenger' => new EE_Plain_Text_Field( |
|
46 | + 'MTP_messenger', |
|
47 | + esc_html__('Messenger Used for Template', 'event_espresso'), |
|
48 | + false, |
|
49 | + 'email' |
|
50 | + ), |
|
51 | + 'MTP_message_type' => new EE_Plain_Text_Field( |
|
52 | + 'MTP_message_type', |
|
53 | + esc_html__('Message Type', 'event_espresso'), |
|
54 | + false, |
|
55 | + 'registration' |
|
56 | + ), |
|
57 | + 'MTP_is_global' => new EE_Boolean_Field( |
|
58 | + 'MTP_is_global', |
|
59 | + esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), |
|
60 | + false, |
|
61 | + true |
|
62 | + ), |
|
63 | + 'MTP_is_override' => new EE_Boolean_Field( |
|
64 | + 'MTP_is_override', |
|
65 | + esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/message type combination', |
|
66 | + 'event_espresso'), |
|
67 | + false, |
|
68 | + false |
|
69 | + ), |
|
70 | + 'MTP_deleted' => new EE_Trashed_Flag_Field( |
|
71 | + 'MTP_deleted', |
|
72 | + esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), |
|
73 | + false, |
|
74 | + false |
|
75 | + ), |
|
76 | + 'MTP_is_active' => new EE_Boolean_Field( |
|
77 | + 'MTP_is_active', |
|
78 | + esc_html__('Flag indicating whether template group is active', 'event_espresso'), |
|
79 | + false, |
|
80 | + true |
|
81 | + ), |
|
82 | + ], |
|
83 | + ]; |
|
84 | + $this->_model_relations = [ |
|
85 | + 'Message_Template' => new EE_Has_Many_Relation(), |
|
86 | + 'Message' => new EE_Has_Many_Relation(), |
|
87 | + 'Event' => new EE_HABTM_Relation('Event_Message_Template'), |
|
88 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
89 | + ]; |
|
90 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
91 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
92 | + } |
|
93 | + $this->_caps_slug = 'messages'; |
|
94 | + |
|
95 | + parent::__construct($timezone); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * get_all_trashed_message_templates_by_event |
|
101 | + * |
|
102 | + * @param int $EVT_ID specific event id |
|
103 | + * @param string $orderby |
|
104 | + * @param string $order |
|
105 | + * @param int|null $limit |
|
106 | + * @param bool $count |
|
107 | + * @return EE_Message_Template_Group[]|int message template objects that are attached to a specific event. |
|
108 | + */ |
|
109 | + public function get_all_trashed_message_templates_by_event( |
|
110 | + int $EVT_ID, |
|
111 | + string $orderby = 'GRP_ID', |
|
112 | + string $order = 'ASC', |
|
113 | + int $limit = null, |
|
114 | + bool $count = false |
|
115 | + ) { |
|
116 | + $query_params = [['Event.EVT_ID' => $EVT_ID], 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
117 | + return $count |
|
118 | + ? $this->count_deleted($query_params, 'GRP_ID', true) |
|
119 | + : $this->get_all_deleted($query_params); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * get_all_message_templates_by_messenger |
|
125 | + * |
|
126 | + * @param string $messenger |
|
127 | + * @param string $orderby |
|
128 | + * @param string $order |
|
129 | + * @return EE_Message_Template_Group[] all (including trashed or inactive) message template group objects for the |
|
130 | + * given messenger |
|
131 | + */ |
|
132 | + public function get_all_message_templates_by_messenger(string $messenger, |
|
133 | + string $orderby = 'GRP_ID', |
|
134 | + string $order = 'ASC'): array |
|
135 | + { |
|
136 | + return $this->get_all_deleted_and_undeleted( |
|
137 | + [['MTP_messenger' => $messenger], 'order_by' => [$orderby => $order]] |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * This simply adds on any messenger/message type filters that may be present in the $_POST global |
|
144 | + * |
|
145 | + * @param array $_where any existing where conditions to append these to. |
|
146 | + * @return EE_Message_Template_Group[] original where conditions or original with additional filters. |
|
147 | + */ |
|
148 | + protected function _maybe_mtp_filters(array $_where = []): array |
|
149 | + { |
|
150 | + // account for messenger or message type filters |
|
151 | + if ( |
|
152 | + isset($_REQUEST['ee_messenger_filter_by']) |
|
153 | + && $_REQUEST['ee_messenger_filter_by'] != 'none_selected' |
|
154 | + && $_REQUEST['ee_messenger_filter_by'] != 'all' |
|
155 | + ) { |
|
156 | + $_where['MTP_messenger'] = $_REQUEST['ee_messenger_filter_by']; |
|
157 | + } |
|
158 | + |
|
159 | + if ( |
|
160 | + isset($_REQUEST['ee_message_type_filter_by']) |
|
161 | + && $_REQUEST['ee_message_type_filter_by'] != 'none_selected' |
|
162 | + ) { |
|
163 | + $_where['MTP_message_type'] = $_REQUEST['ee_message_type_filter_by']; |
|
164 | + } |
|
165 | + |
|
166 | + return $_where; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * get_all_active_message_templates groups |
|
172 | + * |
|
173 | + * @param string $orderby |
|
174 | + * @param string $order |
|
175 | + * @param int|null $limit |
|
176 | + * @param bool $count |
|
177 | + * @param bool $global |
|
178 | + * @param bool $user_check |
|
179 | + * @return EE_Message_Template_Group[]|int all active (non_trashed, active) message template objects |
|
180 | + * @throws EE_Error |
|
181 | + * @throws ReflectionException |
|
182 | + */ |
|
183 | + public function get_all_active_message_templates( |
|
184 | + string $orderby = 'GRP_ID', |
|
185 | + string $order = 'ASC', |
|
186 | + int $limit = null, |
|
187 | + bool $count = false, |
|
188 | + bool $global = true, |
|
189 | + bool $user_check = false |
|
190 | + ): array { |
|
191 | + $_where = $global ? ['MTP_is_global' => true] : ['MTP_is_global' => false]; |
|
192 | + $_where['MTP_is_active'] = true; |
|
193 | + $_where = $this->_maybe_mtp_filters($_where); |
|
194 | + |
|
195 | + if ( |
|
196 | + $user_check |
|
197 | + && ! $global |
|
198 | + && ! EE_Registry::instance()->CAP->current_user_can( |
|
199 | + 'ee_read_others_messages', |
|
200 | + 'get_all_active_message_templates' |
|
201 | + ) |
|
202 | + ) { |
|
203 | + $_where['MTP_user_id'] = get_current_user_id(); |
|
204 | + } |
|
205 | + |
|
206 | + $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
207 | + |
|
208 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * retrieve ALL message_template groups from db regardless of wht |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @param string $orderby |
|
217 | + * @param string $order |
|
218 | + * @param int|null $limit |
|
219 | + * @param bool $count |
|
220 | + * @return EE_Message_Template_Group[] |
|
221 | + */ |
|
222 | + public function get_all_message_templates( |
|
223 | + string $orderby = 'GRP_ID', |
|
224 | + string $order = 'ASC', |
|
225 | + int $limit = null, |
|
226 | + bool $count = false |
|
227 | + ): array { |
|
228 | + $_where = $this->_maybe_mtp_filters(); |
|
229 | + |
|
230 | + $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
231 | + |
|
232 | + return $count |
|
233 | + ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
|
234 | + : $this->get_all_deleted_and_undeleted($query_params); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * This gets all the custom templates attached to a specific event |
|
240 | + * |
|
241 | + * @param int $EVT_ID event id |
|
242 | + * @param array $query_params @see |
|
243 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
244 | + * @return EE_Message_Template_Group[] |
|
245 | + * @throws EE_Error |
|
246 | + * @throws ReflectionException |
|
247 | + */ |
|
248 | + public function get_all_custom_templates_by_event(int $EVT_ID, array $query_params = []): array |
|
249 | + { |
|
250 | + $where = array_merge($query_params, ['Event.EVT_ID' => $EVT_ID]); |
|
251 | + return $this->get_all([$where]); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * get_all_trashed_grouped_message_templates |
|
257 | + * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed |
|
258 | + * |
|
259 | + * @param string $orderby |
|
260 | + * @param string $order |
|
261 | + * @param int|null $limit |
|
262 | + * @param bool $count |
|
263 | + * @param bool $global |
|
264 | + * @return EE_Message_Template_Group[]|int message template groups. |
|
265 | + */ |
|
266 | + public function get_all_trashed_grouped_message_templates( |
|
267 | + string $orderby = 'GRP_ID', |
|
268 | + string $order = 'ASC', |
|
269 | + int $limit = null, |
|
270 | + bool $count = false, |
|
271 | + bool $global = true |
|
272 | + ) { |
|
273 | + $_where = $global ? ['MTP_is_global' => true] : ['MTP_is_global' => false]; |
|
274 | + $_where['MTP_is_active'] = true; |
|
275 | + $_where = $this->_maybe_mtp_filters($_where); |
|
276 | + |
|
277 | + $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
278 | + |
|
279 | + return $count |
|
280 | + ? $this->count_deleted($query_params, 'GRP_ID', true) |
|
281 | + : $this->get_all_deleted($query_params); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * this returns the message template group(s) for a given event, messenger, and message template |
|
287 | + * |
|
288 | + * @param string $messenger |
|
289 | + * @param string $message_type |
|
290 | + * @param int $evt_id |
|
291 | + * @param string $orderby pointless at this point but still included |
|
292 | + * @param string $order |
|
293 | + * @param int|null $limit |
|
294 | + * @param bool $count true = just return count, false = objects |
|
295 | + * @param bool $active ignore "active" or not. (default only return active) |
|
296 | + * @return EE_Message_Template_Group[]|int depending on $count. |
|
297 | + * @throws EE_Error |
|
298 | + * @throws ReflectionException |
|
299 | + */ |
|
300 | + public function get_event_message_templates_by_m_and_mt_and_evt( |
|
301 | + string $messenger, |
|
302 | + string $message_type, |
|
303 | + int $evt_id, |
|
304 | + string $orderby = 'GRP_ID', |
|
305 | + string $order = 'ASC', |
|
306 | + int $limit = null, |
|
307 | + bool $count = false, |
|
308 | + bool $active = true |
|
309 | + ) { |
|
310 | + $_where = [ |
|
311 | + 'MTP_messenger' => $messenger, |
|
312 | + 'MTP_message_type' => $message_type, |
|
313 | + 'Event.EVT_ID' => $evt_id, |
|
314 | + 'MTP_is_global' => true, |
|
315 | + 'MTP_is_active' => $active, |
|
316 | + ]; |
|
317 | + |
|
318 | + $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
319 | + |
|
320 | + return $count |
|
321 | + ? $this->count($query_params, 'GRP_ID', true) |
|
322 | + : $this->get_all($query_params); |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * get all GLOBAL message template groups for the given messenger and message type |
|
328 | + * |
|
329 | + * @param string $messenger slug for messenger |
|
330 | + * @param string $message_type slug for message type |
|
331 | + * @param string $orderby what column to orderby |
|
332 | + * @param string $order ASC or DESC |
|
333 | + * @param int|null $limit |
|
334 | + * @param bool $count true = just return count, false = objects |
|
335 | + * @param bool $active ignore "active" or not. (default only return active) - |
|
336 | + * 'all' means return both inactive AND inactive. |
|
337 | + * @return EE_Message_Template_Group[]|int message template objects that are global (i.e. non-event) |
|
338 | + * @throws EE_Error |
|
339 | + * @throws ReflectionException |
|
340 | + */ |
|
341 | + public function get_global_message_template_by_m_and_mt( |
|
342 | + string $messenger, |
|
343 | + string $message_type, |
|
344 | + string $orderby = 'GRP_ID', |
|
345 | + string $order = 'ASC', |
|
346 | + int $limit = null, |
|
347 | + bool $count = false, |
|
348 | + bool $active = true |
|
349 | + ) { |
|
350 | + $_where = [ |
|
351 | + 'MTP_messenger' => $messenger, |
|
352 | + 'MTP_message_type' => $message_type, |
|
353 | + 'MTP_is_global' => true, |
|
354 | + ]; |
|
355 | + |
|
356 | + if ($active != 'all') { |
|
357 | + $_where['MTP_is_active'] = $active; |
|
358 | + } |
|
359 | + |
|
360 | + $query_params = [$_where, 'order_by' => [$orderby => $order], 'limit' => $limit]; |
|
361 | + |
|
362 | + return $count |
|
363 | + ? $this->count($query_params, 'GRP_ID', true) |
|
364 | + : $this->get_all($query_params); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * get all custom message template groups for the given messenger and message type |
|
370 | + * |
|
371 | + * @param string $messenger |
|
372 | + * @param string $message_type |
|
373 | + * @param array $query_params same as EEM_Base->get_all() |
|
374 | + * @return EE_Message_Template_Group[] |
|
375 | + * @throws EE_Error |
|
376 | + * @throws ReflectionException |
|
377 | + */ |
|
378 | + public function get_custom_message_template_by_m_and_mt(string $messenger, string $message_type, array $query_params = []): array |
|
379 | + { |
|
380 | + return $this->get_all( |
|
381 | + array_merge( |
|
382 | + $query_params, |
|
383 | + [ |
|
384 | + [ |
|
385 | + 'MTP_is_global' => false, |
|
386 | + 'MTP_messenger' => $messenger, |
|
387 | + 'MTP_message_type' => $message_type, |
|
388 | + ], |
|
389 | + ] |
|
390 | + ) |
|
391 | + ); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * This sends things to the validator for the given messenger and message type. |
|
397 | + * |
|
398 | + * @param array $fields the incoming fields to check. |
|
399 | + * Note this array is in the formatted fields from the form fields setup. |
|
400 | + * So we need to reformat this into an array of expected field refs by the validator. |
|
401 | + * Note also that this is not only the fields for the Message Template Group |
|
402 | + * but ALSO for Message Template. |
|
403 | + * @param string $context The context the fields were obtained from. |
|
404 | + * @param string $messenger The messenger we are validating |
|
405 | + * @param string $message_type The message type we are validating. |
|
406 | + * @return mixed If the fields all check out then we return true otherwise error messages are returned |
|
407 | + * (indexed by field name); |
|
408 | + * @throws EE_Error |
|
409 | + * @throws ReflectionException |
|
410 | + */ |
|
411 | + public function validate(array $fields, string $context, string $messenger, string $message_type) |
|
412 | + { |
|
413 | + |
|
414 | + $assembled_fields = []; |
|
415 | + |
|
416 | + // let's loop through all the fields and set them up in the right format |
|
417 | + foreach ($fields as $value) { |
|
418 | + // first let's figure out if the value['content'] in the current index is an array. |
|
419 | + // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
420 | + if (is_array($value['content'])) { |
|
421 | + $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
422 | + // loop through the content and get the other fields. |
|
423 | + foreach ($value['content'] as $name => $val) { |
|
424 | + if ($name == 'main') { |
|
425 | + continue; |
|
426 | + } |
|
427 | + $assembled_fields[ $name ] = $val; |
|
428 | + } |
|
429 | + continue; |
|
430 | + } |
|
431 | + |
|
432 | + // okay if we're here then this is just a straight field=>$value arrangement |
|
433 | + $assembled_fields[ $value['name'] ] = $value['content']; |
|
434 | + } |
|
435 | + |
|
436 | + // now we've got the assembled_fields. |
|
437 | + // We need to setup the string for the appropriate validator class and call that. |
|
438 | + $m_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
439 | + $m_ref = str_replace(' ', '_', $m_ref); |
|
440 | + $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
441 | + $mt_ref = str_replace(' ', '_', $mt_ref); |
|
442 | + |
|
443 | + $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
444 | + |
|
445 | + if (! class_exists($classname)) { |
|
446 | + $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
447 | + $msg[] = sprintf( |
|
448 | + esc_html__( |
|
449 | + 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
450 | + 'event_espresso' |
|
451 | + ), |
|
452 | + $classname |
|
453 | + ); |
|
454 | + throw new EE_Error(implode('||', $msg)); |
|
455 | + } |
|
456 | + |
|
457 | + $a = new ReflectionClass($classname); |
|
458 | + $_VLD = $a->newInstance($assembled_fields, $context); |
|
459 | + return $_VLD->validate(); |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * Updates all message template groups matching the incoming arguments to inactive status. |
|
465 | + * |
|
466 | + * @param array $messenger_names The messenger slugs. |
|
467 | + * If empty then all templates matching the message types are marked inactive. |
|
468 | + * Otherwise only templates matching the messengers and message types. |
|
469 | + * @param array $message_type_names The message type slugs. |
|
470 | + * If empty then all templates matching the messengers are marked inactive. |
|
471 | + * Otherwise only templates matching the messengers and message types. |
|
472 | + * |
|
473 | + * @return int count of updated records. |
|
474 | + * @throws EE_Error |
|
475 | + * @throws ReflectionException |
|
476 | + */ |
|
477 | + public function deactivate_message_template_groups_for( |
|
478 | + array $messenger_names = [], |
|
479 | + array $message_type_names = [] |
|
480 | + ): int { |
|
481 | + $query_args = []; |
|
482 | + if (empty($messenger_names) && empty($message_type_names)) { |
|
483 | + return 0; |
|
484 | + } |
|
485 | + if (! empty($messenger_names)) { |
|
486 | + $query_args[0]['MTP_messenger'] = ['IN', $messenger_names]; |
|
487 | + } |
|
488 | + if (! empty($message_type_names)) { |
|
489 | + $query_args[0]['MTP_message_type'] = ['IN', $message_type_names]; |
|
490 | + } |
|
491 | + return $this->update(['MTP_is_active' => false], $query_args); |
|
492 | + } |
|
493 | 493 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | 'WP_User' => new EE_Belongs_To_Relation(), |
89 | 89 | ]; |
90 | 90 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
91 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
91 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
92 | 92 | } |
93 | 93 | $this->_caps_slug = 'messages'; |
94 | 94 | |
@@ -418,19 +418,19 @@ discard block |
||
418 | 418 | // first let's figure out if the value['content'] in the current index is an array. |
419 | 419 | // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
420 | 420 | if (is_array($value['content'])) { |
421 | - $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
421 | + $assembled_fields[$value['name']] = $value['content']['main']; |
|
422 | 422 | // loop through the content and get the other fields. |
423 | 423 | foreach ($value['content'] as $name => $val) { |
424 | 424 | if ($name == 'main') { |
425 | 425 | continue; |
426 | 426 | } |
427 | - $assembled_fields[ $name ] = $val; |
|
427 | + $assembled_fields[$name] = $val; |
|
428 | 428 | } |
429 | 429 | continue; |
430 | 430 | } |
431 | 431 | |
432 | 432 | // okay if we're here then this is just a straight field=>$value arrangement |
433 | - $assembled_fields[ $value['name'] ] = $value['content']; |
|
433 | + $assembled_fields[$value['name']] = $value['content']; |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | // now we've got the assembled_fields. |
@@ -440,9 +440,9 @@ discard block |
||
440 | 440 | $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
441 | 441 | $mt_ref = str_replace(' ', '_', $mt_ref); |
442 | 442 | |
443 | - $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
443 | + $classname = 'EE_Messages_'.$m_ref.'_'.$mt_ref.'_Validator'; |
|
444 | 444 | |
445 | - if (! class_exists($classname)) { |
|
445 | + if ( ! class_exists($classname)) { |
|
446 | 446 | $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
447 | 447 | $msg[] = sprintf( |
448 | 448 | esc_html__( |
@@ -482,10 +482,10 @@ discard block |
||
482 | 482 | if (empty($messenger_names) && empty($message_type_names)) { |
483 | 483 | return 0; |
484 | 484 | } |
485 | - if (! empty($messenger_names)) { |
|
485 | + if ( ! empty($messenger_names)) { |
|
486 | 486 | $query_args[0]['MTP_messenger'] = ['IN', $messenger_names]; |
487 | 487 | } |
488 | - if (! empty($message_type_names)) { |
|
488 | + if ( ! empty($message_type_names)) { |
|
489 | 489 | $query_args[0]['MTP_message_type'] = ['IN', $message_type_names]; |
490 | 490 | } |
491 | 491 | return $this->update(['MTP_is_active' => false], $query_args); |