@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter; |
| 3 | 3 | |
| 4 | 4 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 5 | - exit('No direct script access allowed'); |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -19,480 +19,480 @@ discard block |
||
| 19 | 19 | abstract class EE_Form_Section_Base |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * the URL the form is submitted to |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $_action; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * POST (default) or GET |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $_method; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * html_id and html_name are derived from this by default |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $_name; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * $_html_id |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - protected $_html_id; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * $_html_class |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - protected $_html_class; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * $_html_style |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - protected $_html_style; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * $_other_html_attributes |
|
| 63 | - * @var string |
|
| 64 | - */ |
|
| 65 | - protected $_other_html_attributes; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * The form section of which this form section is a part |
|
| 69 | - * |
|
| 70 | - * @var EE_Form_Section_Proper |
|
| 71 | - */ |
|
| 72 | - protected $_parent_section; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * flag indicating that _construct_finalize has been called. |
|
| 76 | - * If it has not been called and we try to use functions which require it, we call it |
|
| 77 | - * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
| 78 | - * |
|
| 79 | - * @var boolean |
|
| 80 | - */ |
|
| 81 | - protected $_construction_finalized; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Strategy for parsing the form HTML upon display |
|
| 85 | - * |
|
| 86 | - * @var FormHtmlFilter |
|
| 87 | - */ |
|
| 88 | - protected $_form_html_filter; |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param array $options_array { |
|
| 94 | - * @type $name string the name for this form section, if you want to explicitly define it |
|
| 95 | - * } |
|
| 96 | - */ |
|
| 97 | - public function __construct($options_array = array()) |
|
| 98 | - { |
|
| 99 | - // used by display strategies |
|
| 100 | - // assign incoming values to properties |
|
| 101 | - foreach ($options_array as $key => $value) { |
|
| 102 | - $key = '_' . $key; |
|
| 103 | - if (property_exists($this, $key) && empty($this->{$key})) { |
|
| 104 | - $this->{$key} = $value; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - // set parser which allows the form section's rendered HTML to be filtered |
|
| 108 | - if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
| 109 | - $this->_form_html_filter = $options_array['form_html_filter']; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param $parent_form_section |
|
| 117 | - * @param $name |
|
| 118 | - * @throws \EE_Error |
|
| 119 | - */ |
|
| 120 | - protected function _construct_finalize($parent_form_section, $name) |
|
| 121 | - { |
|
| 122 | - $this->_construction_finalized = true; |
|
| 123 | - $this->_parent_section = $parent_form_section; |
|
| 124 | - if ($name !== null) { |
|
| 125 | - $this->_name = $name; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 133 | - * |
|
| 134 | - * @return void |
|
| 135 | - * @throws \EE_Error |
|
| 136 | - */ |
|
| 137 | - public function ensure_construct_finalized_called() |
|
| 138 | - { |
|
| 139 | - if (! $this->_construction_finalized) { |
|
| 140 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function action() |
|
| 150 | - { |
|
| 151 | - return $this->_action; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @param string $action |
|
| 158 | - */ |
|
| 159 | - public function set_action($action) |
|
| 160 | - { |
|
| 161 | - $this->_action = $action; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - public function method() |
|
| 170 | - { |
|
| 171 | - return ! empty($this->_method) ? $this->_method : 'POST'; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param string $method |
|
| 178 | - */ |
|
| 179 | - public function set_method($method) |
|
| 180 | - { |
|
| 181 | - switch ($method) { |
|
| 182 | - case 'get' : |
|
| 183 | - case 'GET' : |
|
| 184 | - $this->_method = 'GET'; |
|
| 185 | - break; |
|
| 186 | - default : |
|
| 187 | - $this->_method = 'POST'; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Sets the html_id to its default value, if none was specified in the constructor. |
|
| 195 | - * Calculation involves using the name and the parent's html id |
|
| 196 | - * return void |
|
| 197 | - * |
|
| 198 | - * @throws \EE_Error |
|
| 199 | - */ |
|
| 200 | - protected function _set_default_html_id_if_empty() |
|
| 201 | - { |
|
| 202 | - if (! $this->_html_id) { |
|
| 203 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
| 204 | - $this->_html_id = $this->_parent_section->html_id() |
|
| 205 | - . '-' |
|
| 206 | - . $this->_prep_name_for_html_id($this->name()); |
|
| 207 | - } else { |
|
| 208 | - $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * _prep_name_for_html_id |
|
| 217 | - * |
|
| 218 | - * @param $name |
|
| 219 | - * @return string |
|
| 220 | - */ |
|
| 221 | - private function _prep_name_for_html_id($name) |
|
| 222 | - { |
|
| 223 | - return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
| 224 | - } |
|
| 22 | + /** |
|
| 23 | + * the URL the form is submitted to |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $_action; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * POST (default) or GET |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $_method; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * html_id and html_name are derived from this by default |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $_name; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * $_html_id |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + protected $_html_id; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * $_html_class |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + protected $_html_class; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * $_html_style |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + protected $_html_style; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * $_other_html_attributes |
|
| 63 | + * @var string |
|
| 64 | + */ |
|
| 65 | + protected $_other_html_attributes; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * The form section of which this form section is a part |
|
| 69 | + * |
|
| 70 | + * @var EE_Form_Section_Proper |
|
| 71 | + */ |
|
| 72 | + protected $_parent_section; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * flag indicating that _construct_finalize has been called. |
|
| 76 | + * If it has not been called and we try to use functions which require it, we call it |
|
| 77 | + * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
| 78 | + * |
|
| 79 | + * @var boolean |
|
| 80 | + */ |
|
| 81 | + protected $_construction_finalized; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Strategy for parsing the form HTML upon display |
|
| 85 | + * |
|
| 86 | + * @var FormHtmlFilter |
|
| 87 | + */ |
|
| 88 | + protected $_form_html_filter; |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param array $options_array { |
|
| 94 | + * @type $name string the name for this form section, if you want to explicitly define it |
|
| 95 | + * } |
|
| 96 | + */ |
|
| 97 | + public function __construct($options_array = array()) |
|
| 98 | + { |
|
| 99 | + // used by display strategies |
|
| 100 | + // assign incoming values to properties |
|
| 101 | + foreach ($options_array as $key => $value) { |
|
| 102 | + $key = '_' . $key; |
|
| 103 | + if (property_exists($this, $key) && empty($this->{$key})) { |
|
| 104 | + $this->{$key} = $value; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + // set parser which allows the form section's rendered HTML to be filtered |
|
| 108 | + if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
| 109 | + $this->_form_html_filter = $options_array['form_html_filter']; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param $parent_form_section |
|
| 117 | + * @param $name |
|
| 118 | + * @throws \EE_Error |
|
| 119 | + */ |
|
| 120 | + protected function _construct_finalize($parent_form_section, $name) |
|
| 121 | + { |
|
| 122 | + $this->_construction_finalized = true; |
|
| 123 | + $this->_parent_section = $parent_form_section; |
|
| 124 | + if ($name !== null) { |
|
| 125 | + $this->_name = $name; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 133 | + * |
|
| 134 | + * @return void |
|
| 135 | + * @throws \EE_Error |
|
| 136 | + */ |
|
| 137 | + public function ensure_construct_finalized_called() |
|
| 138 | + { |
|
| 139 | + if (! $this->_construction_finalized) { |
|
| 140 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function action() |
|
| 150 | + { |
|
| 151 | + return $this->_action; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @param string $action |
|
| 158 | + */ |
|
| 159 | + public function set_action($action) |
|
| 160 | + { |
|
| 161 | + $this->_action = $action; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + public function method() |
|
| 170 | + { |
|
| 171 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param string $method |
|
| 178 | + */ |
|
| 179 | + public function set_method($method) |
|
| 180 | + { |
|
| 181 | + switch ($method) { |
|
| 182 | + case 'get' : |
|
| 183 | + case 'GET' : |
|
| 184 | + $this->_method = 'GET'; |
|
| 185 | + break; |
|
| 186 | + default : |
|
| 187 | + $this->_method = 'POST'; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Sets the html_id to its default value, if none was specified in the constructor. |
|
| 195 | + * Calculation involves using the name and the parent's html id |
|
| 196 | + * return void |
|
| 197 | + * |
|
| 198 | + * @throws \EE_Error |
|
| 199 | + */ |
|
| 200 | + protected function _set_default_html_id_if_empty() |
|
| 201 | + { |
|
| 202 | + if (! $this->_html_id) { |
|
| 203 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
| 204 | + $this->_html_id = $this->_parent_section->html_id() |
|
| 205 | + . '-' |
|
| 206 | + . $this->_prep_name_for_html_id($this->name()); |
|
| 207 | + } else { |
|
| 208 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * _prep_name_for_html_id |
|
| 217 | + * |
|
| 218 | + * @param $name |
|
| 219 | + * @return string |
|
| 220 | + */ |
|
| 221 | + private function _prep_name_for_html_id($name) |
|
| 222 | + { |
|
| 223 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | |
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
| 230 | - * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
| 231 | - * and call get_html when you want to output the html. Calling get_html_and_js after |
|
| 232 | - * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
| 233 | - * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
| 234 | - * and so might stop working anytime. |
|
| 235 | - * |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function get_html_and_js() |
|
| 239 | - { |
|
| 240 | - return $this->get_html(); |
|
| 241 | - } |
|
| 228 | + /** |
|
| 229 | + * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
| 230 | + * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
| 231 | + * and call get_html when you want to output the html. Calling get_html_and_js after |
|
| 232 | + * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
| 233 | + * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
| 234 | + * and so might stop working anytime. |
|
| 235 | + * |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function get_html_and_js() |
|
| 239 | + { |
|
| 240 | + return $this->get_html(); |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | 243 | |
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Gets the HTML for displaying this form section |
|
| 247 | - * |
|
| 248 | - * @return string |
|
| 249 | - */ |
|
| 250 | - public abstract function get_html(); |
|
| 245 | + /** |
|
| 246 | + * Gets the HTML for displaying this form section |
|
| 247 | + * |
|
| 248 | + * @return string |
|
| 249 | + */ |
|
| 250 | + public abstract function get_html(); |
|
| 251 | 251 | |
| 252 | 252 | |
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * @param bool $add_pound_sign |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function html_id($add_pound_sign = false) |
|
| 259 | - { |
|
| 260 | - $this->_set_default_html_id_if_empty(); |
|
| 261 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
| 262 | - } |
|
| 254 | + /** |
|
| 255 | + * @param bool $add_pound_sign |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function html_id($add_pound_sign = false) |
|
| 259 | + { |
|
| 260 | + $this->_set_default_html_id_if_empty(); |
|
| 261 | + return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | 264 | |
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - public function html_class() |
|
| 270 | - { |
|
| 271 | - return $this->_html_class; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @return string |
|
| 278 | - */ |
|
| 279 | - public function html_style() |
|
| 280 | - { |
|
| 281 | - return $this->_html_style; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param mixed $html_class |
|
| 288 | - */ |
|
| 289 | - public function set_html_class($html_class) |
|
| 290 | - { |
|
| 291 | - $this->_html_class = $html_class; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * @param mixed $html_id |
|
| 298 | - */ |
|
| 299 | - public function set_html_id($html_id) |
|
| 300 | - { |
|
| 301 | - $this->_html_id = $html_id; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @param mixed $html_style |
|
| 308 | - */ |
|
| 309 | - public function set_html_style($html_style) |
|
| 310 | - { |
|
| 311 | - $this->_html_style = $html_style; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * @param string $other_html_attributes |
|
| 318 | - */ |
|
| 319 | - public function set_other_html_attributes($other_html_attributes) |
|
| 320 | - { |
|
| 321 | - $this->_other_html_attributes = $other_html_attributes; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @return string |
|
| 328 | - */ |
|
| 329 | - public function other_html_attributes() |
|
| 330 | - { |
|
| 331 | - return $this->_other_html_attributes; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Gets the name of the form section. This is not the same as the HTML name. |
|
| 338 | - * |
|
| 339 | - * @throws EE_Error |
|
| 340 | - * @return string |
|
| 341 | - */ |
|
| 342 | - public function name() |
|
| 343 | - { |
|
| 344 | - if (! $this->_construction_finalized) { |
|
| 345 | - throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
| 346 | - 'event_espresso'), get_class($this))); |
|
| 347 | - } |
|
| 348 | - return $this->_name; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Gets the parent section |
|
| 355 | - * |
|
| 356 | - * @return EE_Form_Section_Proper |
|
| 357 | - */ |
|
| 358 | - public function parent_section() |
|
| 359 | - { |
|
| 360 | - return $this->_parent_section; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * returns HTML for generating the opening form HTML tag (<form>) |
|
| 367 | - * |
|
| 368 | - * @param string $action the URL the form is submitted to |
|
| 369 | - * @param string $method POST (default) or GET |
|
| 370 | - * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
| 371 | - * @return string |
|
| 372 | - */ |
|
| 373 | - public function form_open($action = '', $method = '', $other_attributes = '') |
|
| 374 | - { |
|
| 375 | - if (! empty($action)) { |
|
| 376 | - $this->set_action($action); |
|
| 377 | - } |
|
| 378 | - if (! empty($method)) { |
|
| 379 | - $this->set_method($method); |
|
| 380 | - } |
|
| 381 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
| 382 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
| 383 | - $html .= ' action="' . $this->action() . '"'; |
|
| 384 | - $html .= ' method="' . $this->method() . '"'; |
|
| 385 | - $html .= $other_attributes . '>'; |
|
| 386 | - return $html; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * ensures that html id for form either ends in "-form" or "-frm" |
|
| 393 | - * so that id doesn't conflict/collide with other elements |
|
| 394 | - * |
|
| 395 | - * @param string $html_id |
|
| 396 | - * @return string |
|
| 397 | - */ |
|
| 398 | - protected function get_html_id_for_form($html_id) |
|
| 399 | - { |
|
| 400 | - $strlen = strlen($html_id); |
|
| 401 | - $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
| 402 | - ? $html_id |
|
| 403 | - : $html_id . '-frm'; |
|
| 404 | - return $html_id; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * returns HTML for generating the closing form HTML tag (</form>) |
|
| 411 | - * |
|
| 412 | - * @return string |
|
| 413 | - */ |
|
| 414 | - public function form_close() |
|
| 415 | - { |
|
| 416 | - return EEH_HTML::nl(-1, 'form') |
|
| 417 | - . '</form>' |
|
| 418 | - . EEH_HTML::nl() |
|
| 419 | - . '<!-- end of ee-' |
|
| 420 | - . $this->html_id() |
|
| 421 | - . '-form -->' |
|
| 422 | - . EEH_HTML::nl(); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
| 429 | - * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
| 430 | - * Default does nothing, but child classes can override |
|
| 431 | - * |
|
| 432 | - * @return void |
|
| 433 | - */ |
|
| 434 | - public function enqueue_js() |
|
| 435 | - { |
|
| 436 | - //defaults to enqueue NO js or css |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
| 443 | - * with it, and it will be on each form section's 'other_data' property. |
|
| 444 | - * By default nothing is added, but child classes can extend this method to add something. |
|
| 445 | - * Eg, if you have an input that will cause a modal dialog to appear, |
|
| 446 | - * here you could add an entry like 'modal_dialog_inputs' to this array |
|
| 447 | - * to map between the input's html ID and the modal dialogue's ID, so that |
|
| 448 | - * your JS code will know where to find the modal dialog when the input is pressed. |
|
| 449 | - * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
| 450 | - * |
|
| 451 | - * @param array $form_other_js_data |
|
| 452 | - * @return array |
|
| 453 | - */ |
|
| 454 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 455 | - { |
|
| 456 | - return $form_other_js_data; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 463 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 464 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 465 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 466 | - * which will be returned. |
|
| 467 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 468 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 469 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 470 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 471 | - * Etc |
|
| 472 | - * |
|
| 473 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 474 | - * @return EE_Form_Section_Base |
|
| 475 | - */ |
|
| 476 | - public function find_section_from_path($form_section_path) |
|
| 477 | - { |
|
| 478 | - if (strpos($form_section_path, '/') === 0) { |
|
| 479 | - $form_section_path = substr($form_section_path, strlen('/')); |
|
| 480 | - } |
|
| 481 | - if (empty($form_section_path)) { |
|
| 482 | - return $this; |
|
| 483 | - } |
|
| 484 | - if (strpos($form_section_path, '../') === 0) { |
|
| 485 | - $parent = $this->parent_section(); |
|
| 486 | - $form_section_path = substr($form_section_path, strlen('../')); |
|
| 487 | - if ($parent instanceof EE_Form_Section_Base) { |
|
| 488 | - return $parent->find_section_from_path($form_section_path); |
|
| 489 | - } elseif (empty($form_section_path)) { |
|
| 490 | - return $this; |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - //couldn't find it using simple parent following |
|
| 494 | - return null; |
|
| 495 | - } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + public function html_class() |
|
| 270 | + { |
|
| 271 | + return $this->_html_class; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @return string |
|
| 278 | + */ |
|
| 279 | + public function html_style() |
|
| 280 | + { |
|
| 281 | + return $this->_html_style; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param mixed $html_class |
|
| 288 | + */ |
|
| 289 | + public function set_html_class($html_class) |
|
| 290 | + { |
|
| 291 | + $this->_html_class = $html_class; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * @param mixed $html_id |
|
| 298 | + */ |
|
| 299 | + public function set_html_id($html_id) |
|
| 300 | + { |
|
| 301 | + $this->_html_id = $html_id; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * @param mixed $html_style |
|
| 308 | + */ |
|
| 309 | + public function set_html_style($html_style) |
|
| 310 | + { |
|
| 311 | + $this->_html_style = $html_style; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @param string $other_html_attributes |
|
| 318 | + */ |
|
| 319 | + public function set_other_html_attributes($other_html_attributes) |
|
| 320 | + { |
|
| 321 | + $this->_other_html_attributes = $other_html_attributes; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @return string |
|
| 328 | + */ |
|
| 329 | + public function other_html_attributes() |
|
| 330 | + { |
|
| 331 | + return $this->_other_html_attributes; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Gets the name of the form section. This is not the same as the HTML name. |
|
| 338 | + * |
|
| 339 | + * @throws EE_Error |
|
| 340 | + * @return string |
|
| 341 | + */ |
|
| 342 | + public function name() |
|
| 343 | + { |
|
| 344 | + if (! $this->_construction_finalized) { |
|
| 345 | + throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
| 346 | + 'event_espresso'), get_class($this))); |
|
| 347 | + } |
|
| 348 | + return $this->_name; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Gets the parent section |
|
| 355 | + * |
|
| 356 | + * @return EE_Form_Section_Proper |
|
| 357 | + */ |
|
| 358 | + public function parent_section() |
|
| 359 | + { |
|
| 360 | + return $this->_parent_section; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * returns HTML for generating the opening form HTML tag (<form>) |
|
| 367 | + * |
|
| 368 | + * @param string $action the URL the form is submitted to |
|
| 369 | + * @param string $method POST (default) or GET |
|
| 370 | + * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
| 371 | + * @return string |
|
| 372 | + */ |
|
| 373 | + public function form_open($action = '', $method = '', $other_attributes = '') |
|
| 374 | + { |
|
| 375 | + if (! empty($action)) { |
|
| 376 | + $this->set_action($action); |
|
| 377 | + } |
|
| 378 | + if (! empty($method)) { |
|
| 379 | + $this->set_method($method); |
|
| 380 | + } |
|
| 381 | + $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
| 382 | + $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
| 383 | + $html .= ' action="' . $this->action() . '"'; |
|
| 384 | + $html .= ' method="' . $this->method() . '"'; |
|
| 385 | + $html .= $other_attributes . '>'; |
|
| 386 | + return $html; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * ensures that html id for form either ends in "-form" or "-frm" |
|
| 393 | + * so that id doesn't conflict/collide with other elements |
|
| 394 | + * |
|
| 395 | + * @param string $html_id |
|
| 396 | + * @return string |
|
| 397 | + */ |
|
| 398 | + protected function get_html_id_for_form($html_id) |
|
| 399 | + { |
|
| 400 | + $strlen = strlen($html_id); |
|
| 401 | + $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
| 402 | + ? $html_id |
|
| 403 | + : $html_id . '-frm'; |
|
| 404 | + return $html_id; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * returns HTML for generating the closing form HTML tag (</form>) |
|
| 411 | + * |
|
| 412 | + * @return string |
|
| 413 | + */ |
|
| 414 | + public function form_close() |
|
| 415 | + { |
|
| 416 | + return EEH_HTML::nl(-1, 'form') |
|
| 417 | + . '</form>' |
|
| 418 | + . EEH_HTML::nl() |
|
| 419 | + . '<!-- end of ee-' |
|
| 420 | + . $this->html_id() |
|
| 421 | + . '-form -->' |
|
| 422 | + . EEH_HTML::nl(); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
| 429 | + * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
| 430 | + * Default does nothing, but child classes can override |
|
| 431 | + * |
|
| 432 | + * @return void |
|
| 433 | + */ |
|
| 434 | + public function enqueue_js() |
|
| 435 | + { |
|
| 436 | + //defaults to enqueue NO js or css |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
| 443 | + * with it, and it will be on each form section's 'other_data' property. |
|
| 444 | + * By default nothing is added, but child classes can extend this method to add something. |
|
| 445 | + * Eg, if you have an input that will cause a modal dialog to appear, |
|
| 446 | + * here you could add an entry like 'modal_dialog_inputs' to this array |
|
| 447 | + * to map between the input's html ID and the modal dialogue's ID, so that |
|
| 448 | + * your JS code will know where to find the modal dialog when the input is pressed. |
|
| 449 | + * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
| 450 | + * |
|
| 451 | + * @param array $form_other_js_data |
|
| 452 | + * @return array |
|
| 453 | + */ |
|
| 454 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 455 | + { |
|
| 456 | + return $form_other_js_data; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 463 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 464 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 465 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 466 | + * which will be returned. |
|
| 467 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 468 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 469 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 470 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 471 | + * Etc |
|
| 472 | + * |
|
| 473 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 474 | + * @return EE_Form_Section_Base |
|
| 475 | + */ |
|
| 476 | + public function find_section_from_path($form_section_path) |
|
| 477 | + { |
|
| 478 | + if (strpos($form_section_path, '/') === 0) { |
|
| 479 | + $form_section_path = substr($form_section_path, strlen('/')); |
|
| 480 | + } |
|
| 481 | + if (empty($form_section_path)) { |
|
| 482 | + return $this; |
|
| 483 | + } |
|
| 484 | + if (strpos($form_section_path, '../') === 0) { |
|
| 485 | + $parent = $this->parent_section(); |
|
| 486 | + $form_section_path = substr($form_section_path, strlen('../')); |
|
| 487 | + if ($parent instanceof EE_Form_Section_Base) { |
|
| 488 | + return $parent->find_section_from_path($form_section_path); |
|
| 489 | + } elseif (empty($form_section_path)) { |
|
| 490 | + return $this; |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + //couldn't find it using simple parent following |
|
| 494 | + return null; |
|
| 495 | + } |
|
| 496 | 496 | |
| 497 | 497 | |
| 498 | 498 | } |
@@ -18,1000 +18,1000 @@ discard block |
||
| 18 | 18 | final class EE_Capabilities extends EE_Base |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * the name of the wp option used to store caps previously initialized |
|
| 23 | - */ |
|
| 24 | - const option_name = 'ee_caps_initialized'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * instance of EE_Capabilities object |
|
| 28 | - * |
|
| 29 | - * @var EE_Capabilities |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | - * Array is indexed by Role and values are ee capabilities. |
|
| 37 | - * |
|
| 38 | - * @since 4.5.0 |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $capabilities_map = array(); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | - * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | - * |
|
| 48 | - * @var EE_Meta_Capability_Map[] |
|
| 49 | - */ |
|
| 50 | - private $_meta_caps = array(); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | - * This flag tracks whether that has happened or not. |
|
| 55 | - * But for this to work, we need three states to indicate: |
|
| 56 | - * initialization has not occurred at all |
|
| 57 | - * initialization has started but is not complete |
|
| 58 | - * initialization is complete |
|
| 59 | - * The reason this is needed is because the addCaps() method |
|
| 60 | - * normally requires the $capabilities_map to be initialized, |
|
| 61 | - * but is also used during the initialization process. |
|
| 62 | - * So: |
|
| 63 | - * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | - * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | - * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | - * |
|
| 67 | - * @var boolean|null $initialized |
|
| 68 | - */ |
|
| 69 | - private $initialized; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var boolean $reset |
|
| 73 | - */ |
|
| 74 | - private $reset = false; |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * singleton method used to instantiate class object |
|
| 80 | - * |
|
| 81 | - * @since 4.5.0 |
|
| 82 | - * |
|
| 83 | - * @return EE_Capabilities |
|
| 84 | - */ |
|
| 85 | - public static function instance() |
|
| 86 | - { |
|
| 87 | - //check if instantiated, and if not do so. |
|
| 88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | - self::$_instance = new self(); |
|
| 90 | - } |
|
| 91 | - return self::$_instance; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * private constructor |
|
| 98 | - * |
|
| 99 | - * @since 4.5.0 |
|
| 100 | - */ |
|
| 101 | - private function __construct() |
|
| 102 | - { |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | - * |
|
| 110 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | - * ensures that they are up to date. |
|
| 113 | - * |
|
| 114 | - * @since 4.5.0 |
|
| 115 | - * @return bool |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function init_caps($reset = false) |
|
| 119 | - { |
|
| 120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | - return false; |
|
| 122 | - } |
|
| 123 | - $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | - // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | - if ($this->reset) { |
|
| 126 | - $this->initialized = null; |
|
| 127 | - $this->capabilities_map = array(); |
|
| 128 | - delete_option(self::option_name); |
|
| 129 | - } |
|
| 130 | - if ($this->initialized === null) { |
|
| 131 | - $this->initialized = false; |
|
| 132 | - do_action( |
|
| 133 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | - $this->reset |
|
| 135 | - ); |
|
| 136 | - $this->addCaps($this->_init_caps_map()); |
|
| 137 | - $this->_set_meta_caps(); |
|
| 138 | - do_action( |
|
| 139 | - 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | - $this->capabilities_map |
|
| 141 | - ); |
|
| 142 | - $this->initialized = true; |
|
| 143 | - } |
|
| 144 | - // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | - $this->reset = false; |
|
| 146 | - return true; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * This sets the meta caps property. |
|
| 154 | - * |
|
| 155 | - * @since 4.5.0 |
|
| 156 | - * @return void |
|
| 157 | - * @throws EE_Error |
|
| 158 | - */ |
|
| 159 | - private function _set_meta_caps() |
|
| 160 | - { |
|
| 161 | - // get default meta caps and filter the returned array |
|
| 162 | - $this->_meta_caps = apply_filters( |
|
| 163 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 164 | - $this->_get_default_meta_caps_array() |
|
| 165 | - ); |
|
| 166 | - //add filter for map_meta_caps but only if models can query. |
|
| 167 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 168 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * This builds and returns the default meta_caps array only once. |
|
| 176 | - * |
|
| 177 | - * @since 4.8.28.rc.012 |
|
| 178 | - * @return array |
|
| 179 | - * @throws EE_Error |
|
| 180 | - */ |
|
| 181 | - private function _get_default_meta_caps_array() |
|
| 182 | - { |
|
| 183 | - static $default_meta_caps = array(); |
|
| 184 | - // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 185 | - if (empty($default_meta_caps)) { |
|
| 186 | - $default_meta_caps = array( |
|
| 187 | - //edits |
|
| 188 | - new EE_Meta_Capability_Map_Edit( |
|
| 189 | - 'ee_edit_event', |
|
| 190 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 191 | - ), |
|
| 192 | - new EE_Meta_Capability_Map_Edit( |
|
| 193 | - 'ee_edit_venue', |
|
| 194 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 195 | - ), |
|
| 196 | - new EE_Meta_Capability_Map_Edit( |
|
| 197 | - 'ee_edit_registration', |
|
| 198 | - array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 199 | - ), |
|
| 200 | - new EE_Meta_Capability_Map_Edit( |
|
| 201 | - 'ee_edit_checkin', |
|
| 202 | - array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 203 | - ), |
|
| 204 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 205 | - 'ee_edit_message', |
|
| 206 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 207 | - ), |
|
| 208 | - new EE_Meta_Capability_Map_Edit( |
|
| 209 | - 'ee_edit_default_ticket', |
|
| 210 | - array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 211 | - ), |
|
| 212 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 213 | - 'ee_edit_question', |
|
| 214 | - array('Question', '', '', 'ee_edit_system_questions') |
|
| 215 | - ), |
|
| 216 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 217 | - 'ee_edit_question_group', |
|
| 218 | - array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 219 | - ), |
|
| 220 | - new EE_Meta_Capability_Map_Edit( |
|
| 221 | - 'ee_edit_payment_method', |
|
| 222 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 223 | - ), |
|
| 224 | - //reads |
|
| 225 | - new EE_Meta_Capability_Map_Read( |
|
| 226 | - 'ee_read_event', |
|
| 227 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 228 | - ), |
|
| 229 | - new EE_Meta_Capability_Map_Read( |
|
| 230 | - 'ee_read_venue', |
|
| 231 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 232 | - ), |
|
| 233 | - new EE_Meta_Capability_Map_Read( |
|
| 234 | - 'ee_read_registration', |
|
| 235 | - array('Registration', '', 'ee_read_others_registrations', '') |
|
| 236 | - ), |
|
| 237 | - new EE_Meta_Capability_Map_Read( |
|
| 238 | - 'ee_read_checkin', |
|
| 239 | - array('Registration', '', 'ee_read_others_checkins', '') |
|
| 240 | - ), |
|
| 241 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 242 | - 'ee_read_message', |
|
| 243 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 244 | - ), |
|
| 245 | - new EE_Meta_Capability_Map_Read( |
|
| 246 | - 'ee_read_default_ticket', |
|
| 247 | - array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 248 | - ), |
|
| 249 | - new EE_Meta_Capability_Map_Read( |
|
| 250 | - 'ee_read_payment_method', |
|
| 251 | - array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 252 | - ), |
|
| 253 | - //deletes |
|
| 254 | - new EE_Meta_Capability_Map_Delete( |
|
| 255 | - 'ee_delete_event', |
|
| 256 | - array( |
|
| 257 | - 'Event', |
|
| 258 | - 'ee_delete_published_events', |
|
| 259 | - 'ee_delete_others_events', |
|
| 260 | - 'ee_delete_private_events', |
|
| 261 | - ) |
|
| 262 | - ), |
|
| 263 | - new EE_Meta_Capability_Map_Delete( |
|
| 264 | - 'ee_delete_venue', |
|
| 265 | - array( |
|
| 266 | - 'Venue', |
|
| 267 | - 'ee_delete_published_venues', |
|
| 268 | - 'ee_delete_others_venues', |
|
| 269 | - 'ee_delete_private_venues', |
|
| 270 | - ) |
|
| 271 | - ), |
|
| 272 | - new EE_Meta_Capability_Map_Delete( |
|
| 273 | - 'ee_delete_registration', |
|
| 274 | - array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 275 | - ), |
|
| 276 | - new EE_Meta_Capability_Map_Delete( |
|
| 277 | - 'ee_delete_checkin', |
|
| 278 | - array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 279 | - ), |
|
| 280 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 281 | - 'ee_delete_message', |
|
| 282 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 283 | - ), |
|
| 284 | - new EE_Meta_Capability_Map_Delete( |
|
| 285 | - 'ee_delete_default_ticket', |
|
| 286 | - array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 287 | - ), |
|
| 288 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 289 | - 'ee_delete_question', |
|
| 290 | - array('Question', '', '', 'delete_system_questions') |
|
| 291 | - ), |
|
| 292 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 293 | - 'ee_delete_question_group', |
|
| 294 | - array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 295 | - ), |
|
| 296 | - new EE_Meta_Capability_Map_Delete( |
|
| 297 | - 'ee_delete_payment_method', |
|
| 298 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 299 | - ), |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - return $default_meta_caps; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 309 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 310 | - * |
|
| 311 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 312 | - * |
|
| 313 | - * @since 4.5.0 |
|
| 314 | - * @see wp-includes/capabilities.php |
|
| 315 | - * |
|
| 316 | - * @param array $caps actual users capabilities |
|
| 317 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 318 | - * @param int $user_id The user id |
|
| 319 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 320 | - * @return array actual users capabilities |
|
| 321 | - * @throws EE_Error |
|
| 322 | - */ |
|
| 323 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 324 | - { |
|
| 325 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 326 | - //loop through our _meta_caps array |
|
| 327 | - foreach ($this->_meta_caps as $meta_map) { |
|
| 328 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 329 | - continue; |
|
| 330 | - } |
|
| 331 | - // don't load models if there is no object ID in the args |
|
| 332 | - if (! empty($args[0])) { |
|
| 333 | - $meta_map->ensure_is_model(); |
|
| 334 | - } |
|
| 335 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - return $caps; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
| 345 | - * Note this array is filtered. |
|
| 346 | - * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 347 | - * |
|
| 348 | - * @since 4.5.0 |
|
| 349 | - * |
|
| 350 | - * @return array |
|
| 351 | - */ |
|
| 352 | - private function _init_caps_map() |
|
| 353 | - { |
|
| 354 | - return apply_filters( |
|
| 355 | - 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 356 | - array( |
|
| 357 | - 'administrator' => array( |
|
| 358 | - //basic access |
|
| 359 | - 'ee_read_ee', |
|
| 360 | - //gateways |
|
| 361 | - /** |
|
| 362 | - * note that with payment method capabilities, although we've implemented |
|
| 363 | - * capability mapping which will be used for accessing payment methods owned by |
|
| 364 | - * other users. This is not fully implemented yet in the payment method ui. |
|
| 365 | - * Currently only the "plural" caps are in active use. |
|
| 366 | - * (Specific payment method caps are in use as well). |
|
| 367 | - **/ |
|
| 368 | - 'ee_manage_gateways', |
|
| 369 | - 'ee_read_payment_methods', |
|
| 370 | - 'ee_read_others_payment_methods', |
|
| 371 | - 'ee_edit_payment_methods', |
|
| 372 | - 'ee_edit_others_payment_methods', |
|
| 373 | - 'ee_delete_payment_methods', |
|
| 374 | - //events |
|
| 375 | - 'ee_publish_events', |
|
| 376 | - 'ee_read_private_events', |
|
| 377 | - 'ee_read_others_events', |
|
| 378 | - 'ee_read_events', |
|
| 379 | - 'ee_edit_events', |
|
| 380 | - 'ee_edit_published_events', |
|
| 381 | - 'ee_edit_others_events', |
|
| 382 | - 'ee_edit_private_events', |
|
| 383 | - 'ee_delete_published_events', |
|
| 384 | - 'ee_delete_private_events', |
|
| 385 | - 'ee_delete_events', |
|
| 386 | - 'ee_delete_others_events', |
|
| 387 | - //event categories |
|
| 388 | - 'ee_manage_event_categories', |
|
| 389 | - 'ee_edit_event_category', |
|
| 390 | - 'ee_delete_event_category', |
|
| 391 | - 'ee_assign_event_category', |
|
| 392 | - //venues |
|
| 393 | - 'ee_publish_venues', |
|
| 394 | - 'ee_read_venues', |
|
| 395 | - 'ee_read_others_venues', |
|
| 396 | - 'ee_read_private_venues', |
|
| 397 | - 'ee_edit_venues', |
|
| 398 | - 'ee_edit_others_venues', |
|
| 399 | - 'ee_edit_published_venues', |
|
| 400 | - 'ee_edit_private_venues', |
|
| 401 | - 'ee_delete_venues', |
|
| 402 | - 'ee_delete_others_venues', |
|
| 403 | - 'ee_delete_private_venues', |
|
| 404 | - 'ee_delete_published_venues', |
|
| 405 | - //venue categories |
|
| 406 | - 'ee_manage_venue_categories', |
|
| 407 | - 'ee_edit_venue_category', |
|
| 408 | - 'ee_delete_venue_category', |
|
| 409 | - 'ee_assign_venue_category', |
|
| 410 | - //contacts |
|
| 411 | - 'ee_read_contacts', |
|
| 412 | - 'ee_edit_contacts', |
|
| 413 | - 'ee_delete_contacts', |
|
| 414 | - //registrations |
|
| 415 | - 'ee_read_registrations', |
|
| 416 | - 'ee_read_others_registrations', |
|
| 417 | - 'ee_edit_registrations', |
|
| 418 | - 'ee_edit_others_registrations', |
|
| 419 | - 'ee_delete_registrations', |
|
| 420 | - //checkins |
|
| 421 | - 'ee_read_others_checkins', |
|
| 422 | - 'ee_read_checkins', |
|
| 423 | - 'ee_edit_checkins', |
|
| 424 | - 'ee_edit_others_checkins', |
|
| 425 | - 'ee_delete_checkins', |
|
| 426 | - 'ee_delete_others_checkins', |
|
| 427 | - //transactions && payments |
|
| 428 | - 'ee_read_transaction', |
|
| 429 | - 'ee_read_transactions', |
|
| 430 | - 'ee_edit_payments', |
|
| 431 | - 'ee_delete_payments', |
|
| 432 | - //messages |
|
| 433 | - 'ee_read_messages', |
|
| 434 | - 'ee_read_others_messages', |
|
| 435 | - 'ee_read_global_messages', |
|
| 436 | - 'ee_edit_global_messages', |
|
| 437 | - 'ee_edit_messages', |
|
| 438 | - 'ee_edit_others_messages', |
|
| 439 | - 'ee_delete_messages', |
|
| 440 | - 'ee_delete_others_messages', |
|
| 441 | - 'ee_delete_global_messages', |
|
| 442 | - 'ee_send_message', |
|
| 443 | - //tickets |
|
| 444 | - 'ee_read_default_tickets', |
|
| 445 | - 'ee_read_others_default_tickets', |
|
| 446 | - 'ee_edit_default_tickets', |
|
| 447 | - 'ee_edit_others_default_tickets', |
|
| 448 | - 'ee_delete_default_tickets', |
|
| 449 | - 'ee_delete_others_default_tickets', |
|
| 450 | - //prices |
|
| 451 | - 'ee_edit_default_price', |
|
| 452 | - 'ee_edit_default_prices', |
|
| 453 | - 'ee_delete_default_price', |
|
| 454 | - 'ee_delete_default_prices', |
|
| 455 | - 'ee_edit_default_price_type', |
|
| 456 | - 'ee_edit_default_price_types', |
|
| 457 | - 'ee_delete_default_price_type', |
|
| 458 | - 'ee_delete_default_price_types', |
|
| 459 | - 'ee_read_default_prices', |
|
| 460 | - 'ee_read_default_price_types', |
|
| 461 | - //registration form |
|
| 462 | - 'ee_edit_questions', |
|
| 463 | - 'ee_edit_system_questions', |
|
| 464 | - 'ee_read_questions', |
|
| 465 | - 'ee_delete_questions', |
|
| 466 | - 'ee_edit_question_groups', |
|
| 467 | - 'ee_read_question_groups', |
|
| 468 | - 'ee_edit_system_question_groups', |
|
| 469 | - 'ee_delete_question_groups', |
|
| 470 | - //event_type taxonomy |
|
| 471 | - 'ee_assign_event_type', |
|
| 472 | - 'ee_manage_event_types', |
|
| 473 | - 'ee_edit_event_type', |
|
| 474 | - 'ee_delete_event_type', |
|
| 475 | - ), |
|
| 476 | - 'ee_events_administrator' => array( |
|
| 477 | - //core wp caps |
|
| 478 | - 'read', |
|
| 479 | - 'read_private_pages', |
|
| 480 | - 'read_private_posts', |
|
| 481 | - 'edit_users', |
|
| 482 | - 'edit_posts', |
|
| 483 | - 'edit_pages', |
|
| 484 | - 'edit_published_posts', |
|
| 485 | - 'edit_published_pages', |
|
| 486 | - 'edit_private_pages', |
|
| 487 | - 'edit_private_posts', |
|
| 488 | - 'edit_others_posts', |
|
| 489 | - 'edit_others_pages', |
|
| 490 | - 'publish_posts', |
|
| 491 | - 'publish_pages', |
|
| 492 | - 'delete_posts', |
|
| 493 | - 'delete_pages', |
|
| 494 | - 'delete_private_pages', |
|
| 495 | - 'delete_private_posts', |
|
| 496 | - 'delete_published_pages', |
|
| 497 | - 'delete_published_posts', |
|
| 498 | - 'delete_others_posts', |
|
| 499 | - 'delete_others_pages', |
|
| 500 | - 'manage_categories', |
|
| 501 | - 'manage_links', |
|
| 502 | - 'moderate_comments', |
|
| 503 | - 'unfiltered_html', |
|
| 504 | - 'upload_files', |
|
| 505 | - 'export', |
|
| 506 | - 'import', |
|
| 507 | - 'list_users', |
|
| 508 | - 'level_1', //required if user with this role shows up in author dropdowns |
|
| 509 | - //basic ee access |
|
| 510 | - 'ee_read_ee', |
|
| 511 | - //events |
|
| 512 | - 'ee_publish_events', |
|
| 513 | - 'ee_read_private_events', |
|
| 514 | - 'ee_read_others_events', |
|
| 515 | - 'ee_read_event', |
|
| 516 | - 'ee_read_events', |
|
| 517 | - 'ee_edit_event', |
|
| 518 | - 'ee_edit_events', |
|
| 519 | - 'ee_edit_published_events', |
|
| 520 | - 'ee_edit_others_events', |
|
| 521 | - 'ee_edit_private_events', |
|
| 522 | - 'ee_delete_published_events', |
|
| 523 | - 'ee_delete_private_events', |
|
| 524 | - 'ee_delete_event', |
|
| 525 | - 'ee_delete_events', |
|
| 526 | - 'ee_delete_others_events', |
|
| 527 | - //event categories |
|
| 528 | - 'ee_manage_event_categories', |
|
| 529 | - 'ee_edit_event_category', |
|
| 530 | - 'ee_delete_event_category', |
|
| 531 | - 'ee_assign_event_category', |
|
| 532 | - //venues |
|
| 533 | - 'ee_publish_venues', |
|
| 534 | - 'ee_read_venue', |
|
| 535 | - 'ee_read_venues', |
|
| 536 | - 'ee_read_others_venues', |
|
| 537 | - 'ee_read_private_venues', |
|
| 538 | - 'ee_edit_venue', |
|
| 539 | - 'ee_edit_venues', |
|
| 540 | - 'ee_edit_others_venues', |
|
| 541 | - 'ee_edit_published_venues', |
|
| 542 | - 'ee_edit_private_venues', |
|
| 543 | - 'ee_delete_venue', |
|
| 544 | - 'ee_delete_venues', |
|
| 545 | - 'ee_delete_others_venues', |
|
| 546 | - 'ee_delete_private_venues', |
|
| 547 | - 'ee_delete_published_venues', |
|
| 548 | - //venue categories |
|
| 549 | - 'ee_manage_venue_categories', |
|
| 550 | - 'ee_edit_venue_category', |
|
| 551 | - 'ee_delete_venue_category', |
|
| 552 | - 'ee_assign_venue_category', |
|
| 553 | - //contacts |
|
| 554 | - 'ee_read_contacts', |
|
| 555 | - 'ee_edit_contacts', |
|
| 556 | - 'ee_delete_contacts', |
|
| 557 | - //registrations |
|
| 558 | - 'ee_read_registrations', |
|
| 559 | - 'ee_read_others_registrations', |
|
| 560 | - 'ee_edit_registration', |
|
| 561 | - 'ee_edit_registrations', |
|
| 562 | - 'ee_edit_others_registrations', |
|
| 563 | - 'ee_delete_registration', |
|
| 564 | - 'ee_delete_registrations', |
|
| 565 | - //checkins |
|
| 566 | - 'ee_read_others_checkins', |
|
| 567 | - 'ee_read_checkins', |
|
| 568 | - 'ee_edit_checkins', |
|
| 569 | - 'ee_edit_others_checkins', |
|
| 570 | - 'ee_delete_checkins', |
|
| 571 | - 'ee_delete_others_checkins', |
|
| 572 | - //transactions && payments |
|
| 573 | - 'ee_read_transaction', |
|
| 574 | - 'ee_read_transactions', |
|
| 575 | - 'ee_edit_payments', |
|
| 576 | - 'ee_delete_payments', |
|
| 577 | - //messages |
|
| 578 | - 'ee_read_messages', |
|
| 579 | - 'ee_read_others_messages', |
|
| 580 | - 'ee_read_global_messages', |
|
| 581 | - 'ee_edit_global_messages', |
|
| 582 | - 'ee_edit_messages', |
|
| 583 | - 'ee_edit_others_messages', |
|
| 584 | - 'ee_delete_messages', |
|
| 585 | - 'ee_delete_others_messages', |
|
| 586 | - 'ee_delete_global_messages', |
|
| 587 | - 'ee_send_message', |
|
| 588 | - //tickets |
|
| 589 | - 'ee_read_default_tickets', |
|
| 590 | - 'ee_read_others_default_tickets', |
|
| 591 | - 'ee_edit_default_tickets', |
|
| 592 | - 'ee_edit_others_default_tickets', |
|
| 593 | - 'ee_delete_default_tickets', |
|
| 594 | - 'ee_delete_others_default_tickets', |
|
| 595 | - //prices |
|
| 596 | - 'ee_edit_default_price', |
|
| 597 | - 'ee_edit_default_prices', |
|
| 598 | - 'ee_delete_default_price', |
|
| 599 | - 'ee_delete_default_prices', |
|
| 600 | - 'ee_edit_default_price_type', |
|
| 601 | - 'ee_edit_default_price_types', |
|
| 602 | - 'ee_delete_default_price_type', |
|
| 603 | - 'ee_delete_default_price_types', |
|
| 604 | - 'ee_read_default_prices', |
|
| 605 | - 'ee_read_default_price_types', |
|
| 606 | - //registration form |
|
| 607 | - 'ee_edit_questions', |
|
| 608 | - 'ee_edit_system_questions', |
|
| 609 | - 'ee_read_questions', |
|
| 610 | - 'ee_delete_questions', |
|
| 611 | - 'ee_edit_question_groups', |
|
| 612 | - 'ee_read_question_groups', |
|
| 613 | - 'ee_edit_system_question_groups', |
|
| 614 | - 'ee_delete_question_groups', |
|
| 615 | - //event_type taxonomy |
|
| 616 | - 'ee_assign_event_type', |
|
| 617 | - 'ee_manage_event_types', |
|
| 618 | - 'ee_edit_event_type', |
|
| 619 | - 'ee_delete_event_type', |
|
| 620 | - ) |
|
| 621 | - ) |
|
| 622 | - ); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * @return bool |
|
| 629 | - * @throws EE_Error |
|
| 630 | - */ |
|
| 631 | - private function setupCapabilitiesMap() |
|
| 632 | - { |
|
| 633 | - // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 634 | - if($this->initialized === null) { |
|
| 635 | - return $this->init_caps(); |
|
| 636 | - } |
|
| 637 | - // unless resetting, get caps from db if we haven't already |
|
| 638 | - $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 639 | - ? $this->capabilities_map |
|
| 640 | - : get_option(self::option_name, array()); |
|
| 641 | - return true; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * @param bool $update |
|
| 648 | - * @return bool |
|
| 649 | - */ |
|
| 650 | - private function updateCapabilitiesMap($update = true) |
|
| 651 | - { |
|
| 652 | - return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Adds capabilities to roles. |
|
| 659 | - * |
|
| 660 | - * @since 4.9.42 |
|
| 661 | - * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 662 | - * Note that this should ONLY be called on activation hook |
|
| 663 | - * otherwise the caps will be added on every request. |
|
| 664 | - * @return bool |
|
| 665 | - * @throws \EE_Error |
|
| 666 | - */ |
|
| 667 | - public function addCaps(array $capabilities_to_add) |
|
| 668 | - { |
|
| 669 | - // don't do anything if the capabilities map can not be initialized |
|
| 670 | - if (! $this->setupCapabilitiesMap()) { |
|
| 671 | - return false; |
|
| 672 | - } |
|
| 673 | - // and filter the array so others can get in on the fun during resets |
|
| 674 | - $capabilities_to_add = apply_filters( |
|
| 675 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 676 | - $capabilities_to_add, |
|
| 677 | - $this->reset, |
|
| 678 | - $this->capabilities_map |
|
| 679 | - ); |
|
| 680 | - $update_capabilities_map = false; |
|
| 681 | - // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 682 | - foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 683 | - if (is_array($caps_for_role)) { |
|
| 684 | - foreach ($caps_for_role as $cap) { |
|
| 685 | - if ( |
|
| 686 | - ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 687 | - && $this->add_cap_to_role($role, $cap, true, false) |
|
| 688 | - ) { |
|
| 689 | - $update_capabilities_map = true; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - // now let's just save the cap that has been set but only if there's been a change. |
|
| 695 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 696 | - $this->flushWpUser($updated); |
|
| 697 | - do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 698 | - return $updated; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 705 | - * |
|
| 706 | - * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 707 | - * @return bool |
|
| 708 | - * @throws \EE_Error |
|
| 709 | - */ |
|
| 710 | - public function removeCaps($caps_map) |
|
| 711 | - { |
|
| 712 | - // don't do anything if the capabilities map can not be initialized |
|
| 713 | - if (! $this->setupCapabilitiesMap()) { |
|
| 714 | - return false; |
|
| 715 | - } |
|
| 716 | - $update_capabilities_map = false; |
|
| 717 | - foreach ($caps_map as $role => $caps_for_role) { |
|
| 718 | - if (is_array($caps_for_role)) { |
|
| 719 | - foreach ($caps_for_role as $cap) { |
|
| 720 | - if ($this->capHasBeenAddedToRole($role, $cap) |
|
| 721 | - && $this->remove_cap_from_role($role, $cap, false) |
|
| 722 | - ) { |
|
| 723 | - $update_capabilities_map = true; |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - // maybe resave the caps |
|
| 729 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 730 | - $this->flushWpUser($updated); |
|
| 731 | - return $updated; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from |
|
| 737 | - * the roles on that user. |
|
| 738 | - * |
|
| 739 | - * @param bool $flush Default is to flush the WP_User object. If false, then this method effectively does nothing. |
|
| 740 | - */ |
|
| 741 | - private function flushWpUser($flush = true) |
|
| 742 | - { |
|
| 743 | - if ($flush) { |
|
| 744 | - $user = wp_get_current_user(); |
|
| 745 | - if ($user instanceof WP_User) { |
|
| 746 | - $user->get_role_caps(); |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 755 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 756 | - * this is a wrapper for $wp_role->add_cap() |
|
| 757 | - * |
|
| 758 | - * @see wp-includes/capabilities.php |
|
| 759 | - * @since 4.5.0 |
|
| 760 | - * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 761 | - * @param string $cap The capability being added to the role |
|
| 762 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
| 763 | - * @param bool $update_capabilities_map |
|
| 764 | - * @return bool |
|
| 765 | - * @throws \EE_Error |
|
| 766 | - */ |
|
| 767 | - public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 768 | - { |
|
| 769 | - // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 770 | - $orig_role = $role; |
|
| 771 | - $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 772 | - //if the role isn't available then we create it. |
|
| 773 | - if (! $role instanceof WP_Role) { |
|
| 774 | - // if a plugin wants to create a specific role name then they should create the role before |
|
| 775 | - // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 776 | - // - removes any `ee_` namespacing from the start of the slug. |
|
| 777 | - // - replaces `_` with ` ` (empty space). |
|
| 778 | - // - sentence case on the resulting string. |
|
| 779 | - $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 780 | - $role = add_role($orig_role, $role_label); |
|
| 781 | - } |
|
| 782 | - if ($role instanceof WP_Role) { |
|
| 783 | - // don't do anything if the capabilities map can not be initialized |
|
| 784 | - if (! $this->setupCapabilitiesMap()) { |
|
| 785 | - return false; |
|
| 786 | - } |
|
| 787 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 788 | - $role->add_cap($cap, $grant); |
|
| 789 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
| 790 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 791 | - return true; |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - return false; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 801 | - * Wrapper for $wp_role->remove_cap() |
|
| 802 | - * |
|
| 803 | - * @see wp-includes/capabilities.php |
|
| 804 | - * @since 4.5.0 |
|
| 805 | - * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 806 | - * @param string $cap The capability being removed |
|
| 807 | - * @param bool $update_capabilities_map |
|
| 808 | - * @return bool |
|
| 809 | - * @throws \EE_Error |
|
| 810 | - */ |
|
| 811 | - public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 812 | - { |
|
| 813 | - // don't do anything if the capabilities map can not be initialized |
|
| 814 | - if (! $this->setupCapabilitiesMap()) { |
|
| 815 | - return false; |
|
| 816 | - } |
|
| 817 | - $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 818 | - if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 819 | - $role->remove_cap($cap); |
|
| 820 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 821 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 822 | - return true; |
|
| 823 | - } |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * @param string $role_name |
|
| 831 | - * @param string $cap |
|
| 832 | - * @param bool $get_index |
|
| 833 | - * @return bool|mixed |
|
| 834 | - */ |
|
| 835 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 836 | - { |
|
| 837 | - if ( |
|
| 838 | - isset($this->capabilities_map[$role_name]) |
|
| 839 | - && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 840 | - ) { |
|
| 841 | - return $get_index ? $index : true; |
|
| 842 | - } |
|
| 843 | - return false; |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * Wrapper for the native WP current_user_can() method. |
|
| 850 | - * This is provided as a handy method for a couple things: |
|
| 851 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 852 | - * write those filters wherever current_user_can is called). |
|
| 853 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 854 | - * |
|
| 855 | - * @since 4.5.0 |
|
| 856 | - * |
|
| 857 | - * @param string $cap The cap being checked. |
|
| 858 | - * @param string $context The context where the current_user_can is being called from. |
|
| 859 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 860 | - * filters. |
|
| 861 | - * |
|
| 862 | - * @return bool Whether user can or not. |
|
| 863 | - */ |
|
| 864 | - public function current_user_can($cap, $context, $id = 0) |
|
| 865 | - { |
|
| 866 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 867 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 868 | - $filtered_cap = apply_filters( |
|
| 869 | - 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 870 | - $filtered_cap, |
|
| 871 | - $context, |
|
| 872 | - $cap, |
|
| 873 | - $id |
|
| 874 | - ); |
|
| 875 | - return ! empty($id) |
|
| 876 | - ? current_user_can($filtered_cap, $id) |
|
| 877 | - : current_user_can($filtered_cap); |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 884 | - * |
|
| 885 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 886 | - * @param string $cap The capability string being checked |
|
| 887 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
| 888 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 889 | - * filters) |
|
| 890 | - * |
|
| 891 | - * @return bool Whether user can or not. |
|
| 892 | - */ |
|
| 893 | - public function user_can($user, $cap, $context, $id = 0) |
|
| 894 | - { |
|
| 895 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 896 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 897 | - $filtered_cap = apply_filters( |
|
| 898 | - 'FHEE__EE_Capabilities__user_can__cap', |
|
| 899 | - $filtered_cap, |
|
| 900 | - $context, |
|
| 901 | - $cap, |
|
| 902 | - $user, |
|
| 903 | - $id |
|
| 904 | - ); |
|
| 905 | - return ! empty($id) |
|
| 906 | - ? user_can($user, $filtered_cap, $id) |
|
| 907 | - : user_can($user, $filtered_cap); |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 914 | - * This is provided as a handy method for a couple things: |
|
| 915 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 916 | - * write those filters wherever current_user_can is called). |
|
| 917 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 918 | - * |
|
| 919 | - * @since 4.5.0 |
|
| 920 | - * |
|
| 921 | - * @param int $blog_id The blog id that is being checked for. |
|
| 922 | - * @param string $cap The cap being checked. |
|
| 923 | - * @param string $context The context where the current_user_can is being called from. |
|
| 924 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 925 | - * filters. |
|
| 926 | - * |
|
| 927 | - * @return bool Whether user can or not. |
|
| 928 | - */ |
|
| 929 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 930 | - { |
|
| 931 | - $user_can = ! empty($id) |
|
| 932 | - ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 933 | - : current_user_can($blog_id, $cap); |
|
| 934 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 935 | - $user_can = apply_filters( |
|
| 936 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 937 | - $user_can, |
|
| 938 | - $blog_id, |
|
| 939 | - $cap, |
|
| 940 | - $id |
|
| 941 | - ); |
|
| 942 | - $user_can = apply_filters( |
|
| 943 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 944 | - $user_can, |
|
| 945 | - $context, |
|
| 946 | - $blog_id, |
|
| 947 | - $cap, |
|
| 948 | - $id |
|
| 949 | - ); |
|
| 950 | - return $user_can; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * This helper method just returns an array of registered EE capabilities. |
|
| 957 | - * |
|
| 958 | - * @since 4.5.0 |
|
| 959 | - * @param string $role If empty then the entire role/capability map is returned. |
|
| 960 | - * Otherwise just the capabilities for the given role are returned. |
|
| 961 | - * @return array |
|
| 962 | - * @throws EE_Error |
|
| 963 | - */ |
|
| 964 | - public function get_ee_capabilities($role = 'administrator') |
|
| 965 | - { |
|
| 966 | - if (! $this->initialized) { |
|
| 967 | - $this->init_caps(); |
|
| 968 | - } |
|
| 969 | - if (empty($role)) { |
|
| 970 | - return $this->capabilities_map; |
|
| 971 | - } |
|
| 972 | - return isset($this->capabilities_map[ $role ]) |
|
| 973 | - ? $this->capabilities_map[ $role ] |
|
| 974 | - : array(); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - /** |
|
| 980 | - * @deprecated 4.9.42 |
|
| 981 | - * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 982 | - * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 983 | - * @param array $caps_map Optional. |
|
| 984 | - * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 985 | - * Note that this should ONLY be called on activation hook or some other one-time |
|
| 986 | - * task otherwise the caps will be added on every request. |
|
| 987 | - * @return void |
|
| 988 | - * @throws EE_Error |
|
| 989 | - */ |
|
| 990 | - public function init_role_caps($reset = false, $caps_map = array()) |
|
| 991 | - { |
|
| 992 | - // If this method is called directly and reset is set as 'true', |
|
| 993 | - // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 994 | - // to guarantee that everything is set up correctly. |
|
| 995 | - // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 996 | - if ($reset) { |
|
| 997 | - EE_Error::doing_it_wrong( |
|
| 998 | - __METHOD__, |
|
| 999 | - sprintf( |
|
| 1000 | - esc_html__( |
|
| 1001 | - 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 1002 | - 'event_espresso' |
|
| 1003 | - ), |
|
| 1004 | - '$reset', |
|
| 1005 | - __METHOD__ . '()', |
|
| 1006 | - 'EE_Capabilities::init_caps()', |
|
| 1007 | - 'true' |
|
| 1008 | - ), |
|
| 1009 | - '4.9.42', |
|
| 1010 | - '5.0.0' |
|
| 1011 | - ); |
|
| 1012 | - } |
|
| 1013 | - $this->addCaps($caps_map); |
|
| 1014 | - } |
|
| 21 | + /** |
|
| 22 | + * the name of the wp option used to store caps previously initialized |
|
| 23 | + */ |
|
| 24 | + const option_name = 'ee_caps_initialized'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * instance of EE_Capabilities object |
|
| 28 | + * |
|
| 29 | + * @var EE_Capabilities |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | + * Array is indexed by Role and values are ee capabilities. |
|
| 37 | + * |
|
| 38 | + * @since 4.5.0 |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $capabilities_map = array(); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | + * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | + * |
|
| 48 | + * @var EE_Meta_Capability_Map[] |
|
| 49 | + */ |
|
| 50 | + private $_meta_caps = array(); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | + * This flag tracks whether that has happened or not. |
|
| 55 | + * But for this to work, we need three states to indicate: |
|
| 56 | + * initialization has not occurred at all |
|
| 57 | + * initialization has started but is not complete |
|
| 58 | + * initialization is complete |
|
| 59 | + * The reason this is needed is because the addCaps() method |
|
| 60 | + * normally requires the $capabilities_map to be initialized, |
|
| 61 | + * but is also used during the initialization process. |
|
| 62 | + * So: |
|
| 63 | + * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | + * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | + * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | + * |
|
| 67 | + * @var boolean|null $initialized |
|
| 68 | + */ |
|
| 69 | + private $initialized; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var boolean $reset |
|
| 73 | + */ |
|
| 74 | + private $reset = false; |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * singleton method used to instantiate class object |
|
| 80 | + * |
|
| 81 | + * @since 4.5.0 |
|
| 82 | + * |
|
| 83 | + * @return EE_Capabilities |
|
| 84 | + */ |
|
| 85 | + public static function instance() |
|
| 86 | + { |
|
| 87 | + //check if instantiated, and if not do so. |
|
| 88 | + if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | + self::$_instance = new self(); |
|
| 90 | + } |
|
| 91 | + return self::$_instance; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * private constructor |
|
| 98 | + * |
|
| 99 | + * @since 4.5.0 |
|
| 100 | + */ |
|
| 101 | + private function __construct() |
|
| 102 | + { |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | + * |
|
| 110 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | + * ensures that they are up to date. |
|
| 113 | + * |
|
| 114 | + * @since 4.5.0 |
|
| 115 | + * @return bool |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function init_caps($reset = false) |
|
| 119 | + { |
|
| 120 | + if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 123 | + $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | + // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | + if ($this->reset) { |
|
| 126 | + $this->initialized = null; |
|
| 127 | + $this->capabilities_map = array(); |
|
| 128 | + delete_option(self::option_name); |
|
| 129 | + } |
|
| 130 | + if ($this->initialized === null) { |
|
| 131 | + $this->initialized = false; |
|
| 132 | + do_action( |
|
| 133 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | + $this->reset |
|
| 135 | + ); |
|
| 136 | + $this->addCaps($this->_init_caps_map()); |
|
| 137 | + $this->_set_meta_caps(); |
|
| 138 | + do_action( |
|
| 139 | + 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | + $this->capabilities_map |
|
| 141 | + ); |
|
| 142 | + $this->initialized = true; |
|
| 143 | + } |
|
| 144 | + // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | + $this->reset = false; |
|
| 146 | + return true; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * This sets the meta caps property. |
|
| 154 | + * |
|
| 155 | + * @since 4.5.0 |
|
| 156 | + * @return void |
|
| 157 | + * @throws EE_Error |
|
| 158 | + */ |
|
| 159 | + private function _set_meta_caps() |
|
| 160 | + { |
|
| 161 | + // get default meta caps and filter the returned array |
|
| 162 | + $this->_meta_caps = apply_filters( |
|
| 163 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 164 | + $this->_get_default_meta_caps_array() |
|
| 165 | + ); |
|
| 166 | + //add filter for map_meta_caps but only if models can query. |
|
| 167 | + if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 168 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * This builds and returns the default meta_caps array only once. |
|
| 176 | + * |
|
| 177 | + * @since 4.8.28.rc.012 |
|
| 178 | + * @return array |
|
| 179 | + * @throws EE_Error |
|
| 180 | + */ |
|
| 181 | + private function _get_default_meta_caps_array() |
|
| 182 | + { |
|
| 183 | + static $default_meta_caps = array(); |
|
| 184 | + // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 185 | + if (empty($default_meta_caps)) { |
|
| 186 | + $default_meta_caps = array( |
|
| 187 | + //edits |
|
| 188 | + new EE_Meta_Capability_Map_Edit( |
|
| 189 | + 'ee_edit_event', |
|
| 190 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 191 | + ), |
|
| 192 | + new EE_Meta_Capability_Map_Edit( |
|
| 193 | + 'ee_edit_venue', |
|
| 194 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 195 | + ), |
|
| 196 | + new EE_Meta_Capability_Map_Edit( |
|
| 197 | + 'ee_edit_registration', |
|
| 198 | + array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 199 | + ), |
|
| 200 | + new EE_Meta_Capability_Map_Edit( |
|
| 201 | + 'ee_edit_checkin', |
|
| 202 | + array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 203 | + ), |
|
| 204 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 205 | + 'ee_edit_message', |
|
| 206 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 207 | + ), |
|
| 208 | + new EE_Meta_Capability_Map_Edit( |
|
| 209 | + 'ee_edit_default_ticket', |
|
| 210 | + array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 211 | + ), |
|
| 212 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 213 | + 'ee_edit_question', |
|
| 214 | + array('Question', '', '', 'ee_edit_system_questions') |
|
| 215 | + ), |
|
| 216 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 217 | + 'ee_edit_question_group', |
|
| 218 | + array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 219 | + ), |
|
| 220 | + new EE_Meta_Capability_Map_Edit( |
|
| 221 | + 'ee_edit_payment_method', |
|
| 222 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 223 | + ), |
|
| 224 | + //reads |
|
| 225 | + new EE_Meta_Capability_Map_Read( |
|
| 226 | + 'ee_read_event', |
|
| 227 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 228 | + ), |
|
| 229 | + new EE_Meta_Capability_Map_Read( |
|
| 230 | + 'ee_read_venue', |
|
| 231 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 232 | + ), |
|
| 233 | + new EE_Meta_Capability_Map_Read( |
|
| 234 | + 'ee_read_registration', |
|
| 235 | + array('Registration', '', 'ee_read_others_registrations', '') |
|
| 236 | + ), |
|
| 237 | + new EE_Meta_Capability_Map_Read( |
|
| 238 | + 'ee_read_checkin', |
|
| 239 | + array('Registration', '', 'ee_read_others_checkins', '') |
|
| 240 | + ), |
|
| 241 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 242 | + 'ee_read_message', |
|
| 243 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 244 | + ), |
|
| 245 | + new EE_Meta_Capability_Map_Read( |
|
| 246 | + 'ee_read_default_ticket', |
|
| 247 | + array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 248 | + ), |
|
| 249 | + new EE_Meta_Capability_Map_Read( |
|
| 250 | + 'ee_read_payment_method', |
|
| 251 | + array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 252 | + ), |
|
| 253 | + //deletes |
|
| 254 | + new EE_Meta_Capability_Map_Delete( |
|
| 255 | + 'ee_delete_event', |
|
| 256 | + array( |
|
| 257 | + 'Event', |
|
| 258 | + 'ee_delete_published_events', |
|
| 259 | + 'ee_delete_others_events', |
|
| 260 | + 'ee_delete_private_events', |
|
| 261 | + ) |
|
| 262 | + ), |
|
| 263 | + new EE_Meta_Capability_Map_Delete( |
|
| 264 | + 'ee_delete_venue', |
|
| 265 | + array( |
|
| 266 | + 'Venue', |
|
| 267 | + 'ee_delete_published_venues', |
|
| 268 | + 'ee_delete_others_venues', |
|
| 269 | + 'ee_delete_private_venues', |
|
| 270 | + ) |
|
| 271 | + ), |
|
| 272 | + new EE_Meta_Capability_Map_Delete( |
|
| 273 | + 'ee_delete_registration', |
|
| 274 | + array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 275 | + ), |
|
| 276 | + new EE_Meta_Capability_Map_Delete( |
|
| 277 | + 'ee_delete_checkin', |
|
| 278 | + array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 279 | + ), |
|
| 280 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 281 | + 'ee_delete_message', |
|
| 282 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 283 | + ), |
|
| 284 | + new EE_Meta_Capability_Map_Delete( |
|
| 285 | + 'ee_delete_default_ticket', |
|
| 286 | + array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 287 | + ), |
|
| 288 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 289 | + 'ee_delete_question', |
|
| 290 | + array('Question', '', '', 'delete_system_questions') |
|
| 291 | + ), |
|
| 292 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 293 | + 'ee_delete_question_group', |
|
| 294 | + array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 295 | + ), |
|
| 296 | + new EE_Meta_Capability_Map_Delete( |
|
| 297 | + 'ee_delete_payment_method', |
|
| 298 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 299 | + ), |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + return $default_meta_caps; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 309 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 310 | + * |
|
| 311 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 312 | + * |
|
| 313 | + * @since 4.5.0 |
|
| 314 | + * @see wp-includes/capabilities.php |
|
| 315 | + * |
|
| 316 | + * @param array $caps actual users capabilities |
|
| 317 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 318 | + * @param int $user_id The user id |
|
| 319 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 320 | + * @return array actual users capabilities |
|
| 321 | + * @throws EE_Error |
|
| 322 | + */ |
|
| 323 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 324 | + { |
|
| 325 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 326 | + //loop through our _meta_caps array |
|
| 327 | + foreach ($this->_meta_caps as $meta_map) { |
|
| 328 | + if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 329 | + continue; |
|
| 330 | + } |
|
| 331 | + // don't load models if there is no object ID in the args |
|
| 332 | + if (! empty($args[0])) { |
|
| 333 | + $meta_map->ensure_is_model(); |
|
| 334 | + } |
|
| 335 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + return $caps; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
| 345 | + * Note this array is filtered. |
|
| 346 | + * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 347 | + * |
|
| 348 | + * @since 4.5.0 |
|
| 349 | + * |
|
| 350 | + * @return array |
|
| 351 | + */ |
|
| 352 | + private function _init_caps_map() |
|
| 353 | + { |
|
| 354 | + return apply_filters( |
|
| 355 | + 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 356 | + array( |
|
| 357 | + 'administrator' => array( |
|
| 358 | + //basic access |
|
| 359 | + 'ee_read_ee', |
|
| 360 | + //gateways |
|
| 361 | + /** |
|
| 362 | + * note that with payment method capabilities, although we've implemented |
|
| 363 | + * capability mapping which will be used for accessing payment methods owned by |
|
| 364 | + * other users. This is not fully implemented yet in the payment method ui. |
|
| 365 | + * Currently only the "plural" caps are in active use. |
|
| 366 | + * (Specific payment method caps are in use as well). |
|
| 367 | + **/ |
|
| 368 | + 'ee_manage_gateways', |
|
| 369 | + 'ee_read_payment_methods', |
|
| 370 | + 'ee_read_others_payment_methods', |
|
| 371 | + 'ee_edit_payment_methods', |
|
| 372 | + 'ee_edit_others_payment_methods', |
|
| 373 | + 'ee_delete_payment_methods', |
|
| 374 | + //events |
|
| 375 | + 'ee_publish_events', |
|
| 376 | + 'ee_read_private_events', |
|
| 377 | + 'ee_read_others_events', |
|
| 378 | + 'ee_read_events', |
|
| 379 | + 'ee_edit_events', |
|
| 380 | + 'ee_edit_published_events', |
|
| 381 | + 'ee_edit_others_events', |
|
| 382 | + 'ee_edit_private_events', |
|
| 383 | + 'ee_delete_published_events', |
|
| 384 | + 'ee_delete_private_events', |
|
| 385 | + 'ee_delete_events', |
|
| 386 | + 'ee_delete_others_events', |
|
| 387 | + //event categories |
|
| 388 | + 'ee_manage_event_categories', |
|
| 389 | + 'ee_edit_event_category', |
|
| 390 | + 'ee_delete_event_category', |
|
| 391 | + 'ee_assign_event_category', |
|
| 392 | + //venues |
|
| 393 | + 'ee_publish_venues', |
|
| 394 | + 'ee_read_venues', |
|
| 395 | + 'ee_read_others_venues', |
|
| 396 | + 'ee_read_private_venues', |
|
| 397 | + 'ee_edit_venues', |
|
| 398 | + 'ee_edit_others_venues', |
|
| 399 | + 'ee_edit_published_venues', |
|
| 400 | + 'ee_edit_private_venues', |
|
| 401 | + 'ee_delete_venues', |
|
| 402 | + 'ee_delete_others_venues', |
|
| 403 | + 'ee_delete_private_venues', |
|
| 404 | + 'ee_delete_published_venues', |
|
| 405 | + //venue categories |
|
| 406 | + 'ee_manage_venue_categories', |
|
| 407 | + 'ee_edit_venue_category', |
|
| 408 | + 'ee_delete_venue_category', |
|
| 409 | + 'ee_assign_venue_category', |
|
| 410 | + //contacts |
|
| 411 | + 'ee_read_contacts', |
|
| 412 | + 'ee_edit_contacts', |
|
| 413 | + 'ee_delete_contacts', |
|
| 414 | + //registrations |
|
| 415 | + 'ee_read_registrations', |
|
| 416 | + 'ee_read_others_registrations', |
|
| 417 | + 'ee_edit_registrations', |
|
| 418 | + 'ee_edit_others_registrations', |
|
| 419 | + 'ee_delete_registrations', |
|
| 420 | + //checkins |
|
| 421 | + 'ee_read_others_checkins', |
|
| 422 | + 'ee_read_checkins', |
|
| 423 | + 'ee_edit_checkins', |
|
| 424 | + 'ee_edit_others_checkins', |
|
| 425 | + 'ee_delete_checkins', |
|
| 426 | + 'ee_delete_others_checkins', |
|
| 427 | + //transactions && payments |
|
| 428 | + 'ee_read_transaction', |
|
| 429 | + 'ee_read_transactions', |
|
| 430 | + 'ee_edit_payments', |
|
| 431 | + 'ee_delete_payments', |
|
| 432 | + //messages |
|
| 433 | + 'ee_read_messages', |
|
| 434 | + 'ee_read_others_messages', |
|
| 435 | + 'ee_read_global_messages', |
|
| 436 | + 'ee_edit_global_messages', |
|
| 437 | + 'ee_edit_messages', |
|
| 438 | + 'ee_edit_others_messages', |
|
| 439 | + 'ee_delete_messages', |
|
| 440 | + 'ee_delete_others_messages', |
|
| 441 | + 'ee_delete_global_messages', |
|
| 442 | + 'ee_send_message', |
|
| 443 | + //tickets |
|
| 444 | + 'ee_read_default_tickets', |
|
| 445 | + 'ee_read_others_default_tickets', |
|
| 446 | + 'ee_edit_default_tickets', |
|
| 447 | + 'ee_edit_others_default_tickets', |
|
| 448 | + 'ee_delete_default_tickets', |
|
| 449 | + 'ee_delete_others_default_tickets', |
|
| 450 | + //prices |
|
| 451 | + 'ee_edit_default_price', |
|
| 452 | + 'ee_edit_default_prices', |
|
| 453 | + 'ee_delete_default_price', |
|
| 454 | + 'ee_delete_default_prices', |
|
| 455 | + 'ee_edit_default_price_type', |
|
| 456 | + 'ee_edit_default_price_types', |
|
| 457 | + 'ee_delete_default_price_type', |
|
| 458 | + 'ee_delete_default_price_types', |
|
| 459 | + 'ee_read_default_prices', |
|
| 460 | + 'ee_read_default_price_types', |
|
| 461 | + //registration form |
|
| 462 | + 'ee_edit_questions', |
|
| 463 | + 'ee_edit_system_questions', |
|
| 464 | + 'ee_read_questions', |
|
| 465 | + 'ee_delete_questions', |
|
| 466 | + 'ee_edit_question_groups', |
|
| 467 | + 'ee_read_question_groups', |
|
| 468 | + 'ee_edit_system_question_groups', |
|
| 469 | + 'ee_delete_question_groups', |
|
| 470 | + //event_type taxonomy |
|
| 471 | + 'ee_assign_event_type', |
|
| 472 | + 'ee_manage_event_types', |
|
| 473 | + 'ee_edit_event_type', |
|
| 474 | + 'ee_delete_event_type', |
|
| 475 | + ), |
|
| 476 | + 'ee_events_administrator' => array( |
|
| 477 | + //core wp caps |
|
| 478 | + 'read', |
|
| 479 | + 'read_private_pages', |
|
| 480 | + 'read_private_posts', |
|
| 481 | + 'edit_users', |
|
| 482 | + 'edit_posts', |
|
| 483 | + 'edit_pages', |
|
| 484 | + 'edit_published_posts', |
|
| 485 | + 'edit_published_pages', |
|
| 486 | + 'edit_private_pages', |
|
| 487 | + 'edit_private_posts', |
|
| 488 | + 'edit_others_posts', |
|
| 489 | + 'edit_others_pages', |
|
| 490 | + 'publish_posts', |
|
| 491 | + 'publish_pages', |
|
| 492 | + 'delete_posts', |
|
| 493 | + 'delete_pages', |
|
| 494 | + 'delete_private_pages', |
|
| 495 | + 'delete_private_posts', |
|
| 496 | + 'delete_published_pages', |
|
| 497 | + 'delete_published_posts', |
|
| 498 | + 'delete_others_posts', |
|
| 499 | + 'delete_others_pages', |
|
| 500 | + 'manage_categories', |
|
| 501 | + 'manage_links', |
|
| 502 | + 'moderate_comments', |
|
| 503 | + 'unfiltered_html', |
|
| 504 | + 'upload_files', |
|
| 505 | + 'export', |
|
| 506 | + 'import', |
|
| 507 | + 'list_users', |
|
| 508 | + 'level_1', //required if user with this role shows up in author dropdowns |
|
| 509 | + //basic ee access |
|
| 510 | + 'ee_read_ee', |
|
| 511 | + //events |
|
| 512 | + 'ee_publish_events', |
|
| 513 | + 'ee_read_private_events', |
|
| 514 | + 'ee_read_others_events', |
|
| 515 | + 'ee_read_event', |
|
| 516 | + 'ee_read_events', |
|
| 517 | + 'ee_edit_event', |
|
| 518 | + 'ee_edit_events', |
|
| 519 | + 'ee_edit_published_events', |
|
| 520 | + 'ee_edit_others_events', |
|
| 521 | + 'ee_edit_private_events', |
|
| 522 | + 'ee_delete_published_events', |
|
| 523 | + 'ee_delete_private_events', |
|
| 524 | + 'ee_delete_event', |
|
| 525 | + 'ee_delete_events', |
|
| 526 | + 'ee_delete_others_events', |
|
| 527 | + //event categories |
|
| 528 | + 'ee_manage_event_categories', |
|
| 529 | + 'ee_edit_event_category', |
|
| 530 | + 'ee_delete_event_category', |
|
| 531 | + 'ee_assign_event_category', |
|
| 532 | + //venues |
|
| 533 | + 'ee_publish_venues', |
|
| 534 | + 'ee_read_venue', |
|
| 535 | + 'ee_read_venues', |
|
| 536 | + 'ee_read_others_venues', |
|
| 537 | + 'ee_read_private_venues', |
|
| 538 | + 'ee_edit_venue', |
|
| 539 | + 'ee_edit_venues', |
|
| 540 | + 'ee_edit_others_venues', |
|
| 541 | + 'ee_edit_published_venues', |
|
| 542 | + 'ee_edit_private_venues', |
|
| 543 | + 'ee_delete_venue', |
|
| 544 | + 'ee_delete_venues', |
|
| 545 | + 'ee_delete_others_venues', |
|
| 546 | + 'ee_delete_private_venues', |
|
| 547 | + 'ee_delete_published_venues', |
|
| 548 | + //venue categories |
|
| 549 | + 'ee_manage_venue_categories', |
|
| 550 | + 'ee_edit_venue_category', |
|
| 551 | + 'ee_delete_venue_category', |
|
| 552 | + 'ee_assign_venue_category', |
|
| 553 | + //contacts |
|
| 554 | + 'ee_read_contacts', |
|
| 555 | + 'ee_edit_contacts', |
|
| 556 | + 'ee_delete_contacts', |
|
| 557 | + //registrations |
|
| 558 | + 'ee_read_registrations', |
|
| 559 | + 'ee_read_others_registrations', |
|
| 560 | + 'ee_edit_registration', |
|
| 561 | + 'ee_edit_registrations', |
|
| 562 | + 'ee_edit_others_registrations', |
|
| 563 | + 'ee_delete_registration', |
|
| 564 | + 'ee_delete_registrations', |
|
| 565 | + //checkins |
|
| 566 | + 'ee_read_others_checkins', |
|
| 567 | + 'ee_read_checkins', |
|
| 568 | + 'ee_edit_checkins', |
|
| 569 | + 'ee_edit_others_checkins', |
|
| 570 | + 'ee_delete_checkins', |
|
| 571 | + 'ee_delete_others_checkins', |
|
| 572 | + //transactions && payments |
|
| 573 | + 'ee_read_transaction', |
|
| 574 | + 'ee_read_transactions', |
|
| 575 | + 'ee_edit_payments', |
|
| 576 | + 'ee_delete_payments', |
|
| 577 | + //messages |
|
| 578 | + 'ee_read_messages', |
|
| 579 | + 'ee_read_others_messages', |
|
| 580 | + 'ee_read_global_messages', |
|
| 581 | + 'ee_edit_global_messages', |
|
| 582 | + 'ee_edit_messages', |
|
| 583 | + 'ee_edit_others_messages', |
|
| 584 | + 'ee_delete_messages', |
|
| 585 | + 'ee_delete_others_messages', |
|
| 586 | + 'ee_delete_global_messages', |
|
| 587 | + 'ee_send_message', |
|
| 588 | + //tickets |
|
| 589 | + 'ee_read_default_tickets', |
|
| 590 | + 'ee_read_others_default_tickets', |
|
| 591 | + 'ee_edit_default_tickets', |
|
| 592 | + 'ee_edit_others_default_tickets', |
|
| 593 | + 'ee_delete_default_tickets', |
|
| 594 | + 'ee_delete_others_default_tickets', |
|
| 595 | + //prices |
|
| 596 | + 'ee_edit_default_price', |
|
| 597 | + 'ee_edit_default_prices', |
|
| 598 | + 'ee_delete_default_price', |
|
| 599 | + 'ee_delete_default_prices', |
|
| 600 | + 'ee_edit_default_price_type', |
|
| 601 | + 'ee_edit_default_price_types', |
|
| 602 | + 'ee_delete_default_price_type', |
|
| 603 | + 'ee_delete_default_price_types', |
|
| 604 | + 'ee_read_default_prices', |
|
| 605 | + 'ee_read_default_price_types', |
|
| 606 | + //registration form |
|
| 607 | + 'ee_edit_questions', |
|
| 608 | + 'ee_edit_system_questions', |
|
| 609 | + 'ee_read_questions', |
|
| 610 | + 'ee_delete_questions', |
|
| 611 | + 'ee_edit_question_groups', |
|
| 612 | + 'ee_read_question_groups', |
|
| 613 | + 'ee_edit_system_question_groups', |
|
| 614 | + 'ee_delete_question_groups', |
|
| 615 | + //event_type taxonomy |
|
| 616 | + 'ee_assign_event_type', |
|
| 617 | + 'ee_manage_event_types', |
|
| 618 | + 'ee_edit_event_type', |
|
| 619 | + 'ee_delete_event_type', |
|
| 620 | + ) |
|
| 621 | + ) |
|
| 622 | + ); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * @return bool |
|
| 629 | + * @throws EE_Error |
|
| 630 | + */ |
|
| 631 | + private function setupCapabilitiesMap() |
|
| 632 | + { |
|
| 633 | + // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 634 | + if($this->initialized === null) { |
|
| 635 | + return $this->init_caps(); |
|
| 636 | + } |
|
| 637 | + // unless resetting, get caps from db if we haven't already |
|
| 638 | + $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 639 | + ? $this->capabilities_map |
|
| 640 | + : get_option(self::option_name, array()); |
|
| 641 | + return true; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * @param bool $update |
|
| 648 | + * @return bool |
|
| 649 | + */ |
|
| 650 | + private function updateCapabilitiesMap($update = true) |
|
| 651 | + { |
|
| 652 | + return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Adds capabilities to roles. |
|
| 659 | + * |
|
| 660 | + * @since 4.9.42 |
|
| 661 | + * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 662 | + * Note that this should ONLY be called on activation hook |
|
| 663 | + * otherwise the caps will be added on every request. |
|
| 664 | + * @return bool |
|
| 665 | + * @throws \EE_Error |
|
| 666 | + */ |
|
| 667 | + public function addCaps(array $capabilities_to_add) |
|
| 668 | + { |
|
| 669 | + // don't do anything if the capabilities map can not be initialized |
|
| 670 | + if (! $this->setupCapabilitiesMap()) { |
|
| 671 | + return false; |
|
| 672 | + } |
|
| 673 | + // and filter the array so others can get in on the fun during resets |
|
| 674 | + $capabilities_to_add = apply_filters( |
|
| 675 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 676 | + $capabilities_to_add, |
|
| 677 | + $this->reset, |
|
| 678 | + $this->capabilities_map |
|
| 679 | + ); |
|
| 680 | + $update_capabilities_map = false; |
|
| 681 | + // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 682 | + foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 683 | + if (is_array($caps_for_role)) { |
|
| 684 | + foreach ($caps_for_role as $cap) { |
|
| 685 | + if ( |
|
| 686 | + ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 687 | + && $this->add_cap_to_role($role, $cap, true, false) |
|
| 688 | + ) { |
|
| 689 | + $update_capabilities_map = true; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + // now let's just save the cap that has been set but only if there's been a change. |
|
| 695 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 696 | + $this->flushWpUser($updated); |
|
| 697 | + do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 698 | + return $updated; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 705 | + * |
|
| 706 | + * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 707 | + * @return bool |
|
| 708 | + * @throws \EE_Error |
|
| 709 | + */ |
|
| 710 | + public function removeCaps($caps_map) |
|
| 711 | + { |
|
| 712 | + // don't do anything if the capabilities map can not be initialized |
|
| 713 | + if (! $this->setupCapabilitiesMap()) { |
|
| 714 | + return false; |
|
| 715 | + } |
|
| 716 | + $update_capabilities_map = false; |
|
| 717 | + foreach ($caps_map as $role => $caps_for_role) { |
|
| 718 | + if (is_array($caps_for_role)) { |
|
| 719 | + foreach ($caps_for_role as $cap) { |
|
| 720 | + if ($this->capHasBeenAddedToRole($role, $cap) |
|
| 721 | + && $this->remove_cap_from_role($role, $cap, false) |
|
| 722 | + ) { |
|
| 723 | + $update_capabilities_map = true; |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + // maybe resave the caps |
|
| 729 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 730 | + $this->flushWpUser($updated); |
|
| 731 | + return $updated; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from |
|
| 737 | + * the roles on that user. |
|
| 738 | + * |
|
| 739 | + * @param bool $flush Default is to flush the WP_User object. If false, then this method effectively does nothing. |
|
| 740 | + */ |
|
| 741 | + private function flushWpUser($flush = true) |
|
| 742 | + { |
|
| 743 | + if ($flush) { |
|
| 744 | + $user = wp_get_current_user(); |
|
| 745 | + if ($user instanceof WP_User) { |
|
| 746 | + $user->get_role_caps(); |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 755 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 756 | + * this is a wrapper for $wp_role->add_cap() |
|
| 757 | + * |
|
| 758 | + * @see wp-includes/capabilities.php |
|
| 759 | + * @since 4.5.0 |
|
| 760 | + * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 761 | + * @param string $cap The capability being added to the role |
|
| 762 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
| 763 | + * @param bool $update_capabilities_map |
|
| 764 | + * @return bool |
|
| 765 | + * @throws \EE_Error |
|
| 766 | + */ |
|
| 767 | + public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 768 | + { |
|
| 769 | + // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 770 | + $orig_role = $role; |
|
| 771 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 772 | + //if the role isn't available then we create it. |
|
| 773 | + if (! $role instanceof WP_Role) { |
|
| 774 | + // if a plugin wants to create a specific role name then they should create the role before |
|
| 775 | + // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 776 | + // - removes any `ee_` namespacing from the start of the slug. |
|
| 777 | + // - replaces `_` with ` ` (empty space). |
|
| 778 | + // - sentence case on the resulting string. |
|
| 779 | + $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 780 | + $role = add_role($orig_role, $role_label); |
|
| 781 | + } |
|
| 782 | + if ($role instanceof WP_Role) { |
|
| 783 | + // don't do anything if the capabilities map can not be initialized |
|
| 784 | + if (! $this->setupCapabilitiesMap()) { |
|
| 785 | + return false; |
|
| 786 | + } |
|
| 787 | + if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 788 | + $role->add_cap($cap, $grant); |
|
| 789 | + $this->capabilities_map[ $role->name ][] = $cap; |
|
| 790 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 791 | + return true; |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + return false; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 801 | + * Wrapper for $wp_role->remove_cap() |
|
| 802 | + * |
|
| 803 | + * @see wp-includes/capabilities.php |
|
| 804 | + * @since 4.5.0 |
|
| 805 | + * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 806 | + * @param string $cap The capability being removed |
|
| 807 | + * @param bool $update_capabilities_map |
|
| 808 | + * @return bool |
|
| 809 | + * @throws \EE_Error |
|
| 810 | + */ |
|
| 811 | + public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 812 | + { |
|
| 813 | + // don't do anything if the capabilities map can not be initialized |
|
| 814 | + if (! $this->setupCapabilitiesMap()) { |
|
| 815 | + return false; |
|
| 816 | + } |
|
| 817 | + $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 818 | + if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 819 | + $role->remove_cap($cap); |
|
| 820 | + unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 821 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 822 | + return true; |
|
| 823 | + } |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * @param string $role_name |
|
| 831 | + * @param string $cap |
|
| 832 | + * @param bool $get_index |
|
| 833 | + * @return bool|mixed |
|
| 834 | + */ |
|
| 835 | + private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 836 | + { |
|
| 837 | + if ( |
|
| 838 | + isset($this->capabilities_map[$role_name]) |
|
| 839 | + && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 840 | + ) { |
|
| 841 | + return $get_index ? $index : true; |
|
| 842 | + } |
|
| 843 | + return false; |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * Wrapper for the native WP current_user_can() method. |
|
| 850 | + * This is provided as a handy method for a couple things: |
|
| 851 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 852 | + * write those filters wherever current_user_can is called). |
|
| 853 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 854 | + * |
|
| 855 | + * @since 4.5.0 |
|
| 856 | + * |
|
| 857 | + * @param string $cap The cap being checked. |
|
| 858 | + * @param string $context The context where the current_user_can is being called from. |
|
| 859 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 860 | + * filters. |
|
| 861 | + * |
|
| 862 | + * @return bool Whether user can or not. |
|
| 863 | + */ |
|
| 864 | + public function current_user_can($cap, $context, $id = 0) |
|
| 865 | + { |
|
| 866 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 867 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 868 | + $filtered_cap = apply_filters( |
|
| 869 | + 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 870 | + $filtered_cap, |
|
| 871 | + $context, |
|
| 872 | + $cap, |
|
| 873 | + $id |
|
| 874 | + ); |
|
| 875 | + return ! empty($id) |
|
| 876 | + ? current_user_can($filtered_cap, $id) |
|
| 877 | + : current_user_can($filtered_cap); |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 884 | + * |
|
| 885 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 886 | + * @param string $cap The capability string being checked |
|
| 887 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
| 888 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 889 | + * filters) |
|
| 890 | + * |
|
| 891 | + * @return bool Whether user can or not. |
|
| 892 | + */ |
|
| 893 | + public function user_can($user, $cap, $context, $id = 0) |
|
| 894 | + { |
|
| 895 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 896 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 897 | + $filtered_cap = apply_filters( |
|
| 898 | + 'FHEE__EE_Capabilities__user_can__cap', |
|
| 899 | + $filtered_cap, |
|
| 900 | + $context, |
|
| 901 | + $cap, |
|
| 902 | + $user, |
|
| 903 | + $id |
|
| 904 | + ); |
|
| 905 | + return ! empty($id) |
|
| 906 | + ? user_can($user, $filtered_cap, $id) |
|
| 907 | + : user_can($user, $filtered_cap); |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 914 | + * This is provided as a handy method for a couple things: |
|
| 915 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 916 | + * write those filters wherever current_user_can is called). |
|
| 917 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 918 | + * |
|
| 919 | + * @since 4.5.0 |
|
| 920 | + * |
|
| 921 | + * @param int $blog_id The blog id that is being checked for. |
|
| 922 | + * @param string $cap The cap being checked. |
|
| 923 | + * @param string $context The context where the current_user_can is being called from. |
|
| 924 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 925 | + * filters. |
|
| 926 | + * |
|
| 927 | + * @return bool Whether user can or not. |
|
| 928 | + */ |
|
| 929 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 930 | + { |
|
| 931 | + $user_can = ! empty($id) |
|
| 932 | + ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 933 | + : current_user_can($blog_id, $cap); |
|
| 934 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 935 | + $user_can = apply_filters( |
|
| 936 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 937 | + $user_can, |
|
| 938 | + $blog_id, |
|
| 939 | + $cap, |
|
| 940 | + $id |
|
| 941 | + ); |
|
| 942 | + $user_can = apply_filters( |
|
| 943 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 944 | + $user_can, |
|
| 945 | + $context, |
|
| 946 | + $blog_id, |
|
| 947 | + $cap, |
|
| 948 | + $id |
|
| 949 | + ); |
|
| 950 | + return $user_can; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * This helper method just returns an array of registered EE capabilities. |
|
| 957 | + * |
|
| 958 | + * @since 4.5.0 |
|
| 959 | + * @param string $role If empty then the entire role/capability map is returned. |
|
| 960 | + * Otherwise just the capabilities for the given role are returned. |
|
| 961 | + * @return array |
|
| 962 | + * @throws EE_Error |
|
| 963 | + */ |
|
| 964 | + public function get_ee_capabilities($role = 'administrator') |
|
| 965 | + { |
|
| 966 | + if (! $this->initialized) { |
|
| 967 | + $this->init_caps(); |
|
| 968 | + } |
|
| 969 | + if (empty($role)) { |
|
| 970 | + return $this->capabilities_map; |
|
| 971 | + } |
|
| 972 | + return isset($this->capabilities_map[ $role ]) |
|
| 973 | + ? $this->capabilities_map[ $role ] |
|
| 974 | + : array(); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + /** |
|
| 980 | + * @deprecated 4.9.42 |
|
| 981 | + * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 982 | + * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 983 | + * @param array $caps_map Optional. |
|
| 984 | + * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 985 | + * Note that this should ONLY be called on activation hook or some other one-time |
|
| 986 | + * task otherwise the caps will be added on every request. |
|
| 987 | + * @return void |
|
| 988 | + * @throws EE_Error |
|
| 989 | + */ |
|
| 990 | + public function init_role_caps($reset = false, $caps_map = array()) |
|
| 991 | + { |
|
| 992 | + // If this method is called directly and reset is set as 'true', |
|
| 993 | + // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 994 | + // to guarantee that everything is set up correctly. |
|
| 995 | + // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 996 | + if ($reset) { |
|
| 997 | + EE_Error::doing_it_wrong( |
|
| 998 | + __METHOD__, |
|
| 999 | + sprintf( |
|
| 1000 | + esc_html__( |
|
| 1001 | + 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 1002 | + 'event_espresso' |
|
| 1003 | + ), |
|
| 1004 | + '$reset', |
|
| 1005 | + __METHOD__ . '()', |
|
| 1006 | + 'EE_Capabilities::init_caps()', |
|
| 1007 | + 'true' |
|
| 1008 | + ), |
|
| 1009 | + '4.9.42', |
|
| 1010 | + '5.0.0' |
|
| 1011 | + ); |
|
| 1012 | + } |
|
| 1013 | + $this->addCaps($caps_map); |
|
| 1014 | + } |
|
| 1015 | 1015 | |
| 1016 | 1016 | |
| 1017 | 1017 | |
@@ -1032,142 +1032,142 @@ discard block |
||
| 1032 | 1032 | abstract class EE_Meta_Capability_Map |
| 1033 | 1033 | { |
| 1034 | 1034 | |
| 1035 | - public $meta_cap; |
|
| 1036 | - |
|
| 1037 | - /** |
|
| 1038 | - * @var EEM_Base |
|
| 1039 | - */ |
|
| 1040 | - protected $_model; |
|
| 1041 | - |
|
| 1042 | - protected $_model_name; |
|
| 1043 | - |
|
| 1044 | - public $published_cap = ''; |
|
| 1045 | - |
|
| 1046 | - public $others_cap = ''; |
|
| 1047 | - |
|
| 1048 | - public $private_cap = ''; |
|
| 1049 | - |
|
| 1050 | - |
|
| 1051 | - /** |
|
| 1052 | - * constructor. |
|
| 1053 | - * Receives the setup arguments for the map. |
|
| 1054 | - * |
|
| 1055 | - * @since 4.5.0 |
|
| 1056 | - * |
|
| 1057 | - * @param string $meta_cap What meta capability is this mapping. |
|
| 1058 | - * @param array $map_values array { |
|
| 1059 | - * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1060 | - * capabilities that don't get mapped to. |
|
| 1061 | - * |
|
| 1062 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1063 | - * should always be used when Menu Maps are registered via the |
|
| 1064 | - * plugin API as models are not allowed to be instantiated when |
|
| 1065 | - * in maintenance mode 2 (migrations). |
|
| 1066 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1067 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1068 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1069 | - * } |
|
| 1070 | - * @throws EE_Error |
|
| 1071 | - */ |
|
| 1072 | - public function __construct($meta_cap, $map_values) |
|
| 1073 | - { |
|
| 1074 | - $this->meta_cap = $meta_cap; |
|
| 1075 | - //verify there are four args in the $map_values array; |
|
| 1076 | - if (count($map_values) !== 4) { |
|
| 1077 | - throw new EE_Error( |
|
| 1078 | - sprintf( |
|
| 1079 | - __( |
|
| 1080 | - 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1081 | - 'event_espresso' |
|
| 1082 | - ), |
|
| 1083 | - '<br>' . print_r($map_values, true) |
|
| 1084 | - ) |
|
| 1085 | - ); |
|
| 1086 | - } |
|
| 1087 | - //set properties |
|
| 1088 | - $this->_model = null; |
|
| 1089 | - $this->_model_name = $map_values[0]; |
|
| 1090 | - $this->published_cap = (string)$map_values[1]; |
|
| 1091 | - $this->others_cap = (string)$map_values[2]; |
|
| 1092 | - $this->private_cap = (string)$map_values[3]; |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * Makes it so this object stops filtering caps |
|
| 1097 | - */ |
|
| 1098 | - public function remove_filters() |
|
| 1099 | - { |
|
| 1100 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1106 | - * |
|
| 1107 | - * @since 4.5.0 |
|
| 1108 | - * @throws EE_Error |
|
| 1109 | - * |
|
| 1110 | - * @return void |
|
| 1111 | - */ |
|
| 1112 | - public function ensure_is_model() |
|
| 1113 | - { |
|
| 1114 | - //is it already instantiated? |
|
| 1115 | - if ($this->_model instanceof EEM_Base) { |
|
| 1116 | - return; |
|
| 1117 | - } |
|
| 1118 | - //ensure model name is string |
|
| 1119 | - $this->_model_name = (string)$this->_model_name; |
|
| 1120 | - //error proof if the name has EEM in it |
|
| 1121 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1122 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1123 | - if (! $this->_model instanceof EEM_Base) { |
|
| 1124 | - throw new EE_Error( |
|
| 1125 | - sprintf( |
|
| 1126 | - __( |
|
| 1127 | - 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1128 | - 'event_espresso' |
|
| 1129 | - ), |
|
| 1130 | - get_class($this), |
|
| 1131 | - $this->_model |
|
| 1132 | - ) |
|
| 1133 | - ); |
|
| 1134 | - } |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - |
|
| 1138 | - /** |
|
| 1139 | - * |
|
| 1140 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1141 | - * @since 4.6.x |
|
| 1142 | - * |
|
| 1143 | - * @param $caps |
|
| 1144 | - * @param $cap |
|
| 1145 | - * @param $user_id |
|
| 1146 | - * @param $args |
|
| 1147 | - * |
|
| 1148 | - * @return array |
|
| 1149 | - */ |
|
| 1150 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1151 | - { |
|
| 1152 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - |
|
| 1156 | - /** |
|
| 1157 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1158 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1159 | - * |
|
| 1160 | - * @since 4.5.0 |
|
| 1161 | - * @see wp-includes/capabilities.php |
|
| 1162 | - * |
|
| 1163 | - * @param array $caps actual users capabilities |
|
| 1164 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1165 | - * @param int $user_id The user id |
|
| 1166 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1167 | - * |
|
| 1168 | - * @return array actual users capabilities |
|
| 1169 | - */ |
|
| 1170 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1035 | + public $meta_cap; |
|
| 1036 | + |
|
| 1037 | + /** |
|
| 1038 | + * @var EEM_Base |
|
| 1039 | + */ |
|
| 1040 | + protected $_model; |
|
| 1041 | + |
|
| 1042 | + protected $_model_name; |
|
| 1043 | + |
|
| 1044 | + public $published_cap = ''; |
|
| 1045 | + |
|
| 1046 | + public $others_cap = ''; |
|
| 1047 | + |
|
| 1048 | + public $private_cap = ''; |
|
| 1049 | + |
|
| 1050 | + |
|
| 1051 | + /** |
|
| 1052 | + * constructor. |
|
| 1053 | + * Receives the setup arguments for the map. |
|
| 1054 | + * |
|
| 1055 | + * @since 4.5.0 |
|
| 1056 | + * |
|
| 1057 | + * @param string $meta_cap What meta capability is this mapping. |
|
| 1058 | + * @param array $map_values array { |
|
| 1059 | + * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1060 | + * capabilities that don't get mapped to. |
|
| 1061 | + * |
|
| 1062 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1063 | + * should always be used when Menu Maps are registered via the |
|
| 1064 | + * plugin API as models are not allowed to be instantiated when |
|
| 1065 | + * in maintenance mode 2 (migrations). |
|
| 1066 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1067 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1068 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1069 | + * } |
|
| 1070 | + * @throws EE_Error |
|
| 1071 | + */ |
|
| 1072 | + public function __construct($meta_cap, $map_values) |
|
| 1073 | + { |
|
| 1074 | + $this->meta_cap = $meta_cap; |
|
| 1075 | + //verify there are four args in the $map_values array; |
|
| 1076 | + if (count($map_values) !== 4) { |
|
| 1077 | + throw new EE_Error( |
|
| 1078 | + sprintf( |
|
| 1079 | + __( |
|
| 1080 | + 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1081 | + 'event_espresso' |
|
| 1082 | + ), |
|
| 1083 | + '<br>' . print_r($map_values, true) |
|
| 1084 | + ) |
|
| 1085 | + ); |
|
| 1086 | + } |
|
| 1087 | + //set properties |
|
| 1088 | + $this->_model = null; |
|
| 1089 | + $this->_model_name = $map_values[0]; |
|
| 1090 | + $this->published_cap = (string)$map_values[1]; |
|
| 1091 | + $this->others_cap = (string)$map_values[2]; |
|
| 1092 | + $this->private_cap = (string)$map_values[3]; |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * Makes it so this object stops filtering caps |
|
| 1097 | + */ |
|
| 1098 | + public function remove_filters() |
|
| 1099 | + { |
|
| 1100 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1106 | + * |
|
| 1107 | + * @since 4.5.0 |
|
| 1108 | + * @throws EE_Error |
|
| 1109 | + * |
|
| 1110 | + * @return void |
|
| 1111 | + */ |
|
| 1112 | + public function ensure_is_model() |
|
| 1113 | + { |
|
| 1114 | + //is it already instantiated? |
|
| 1115 | + if ($this->_model instanceof EEM_Base) { |
|
| 1116 | + return; |
|
| 1117 | + } |
|
| 1118 | + //ensure model name is string |
|
| 1119 | + $this->_model_name = (string)$this->_model_name; |
|
| 1120 | + //error proof if the name has EEM in it |
|
| 1121 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1122 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1123 | + if (! $this->_model instanceof EEM_Base) { |
|
| 1124 | + throw new EE_Error( |
|
| 1125 | + sprintf( |
|
| 1126 | + __( |
|
| 1127 | + 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1128 | + 'event_espresso' |
|
| 1129 | + ), |
|
| 1130 | + get_class($this), |
|
| 1131 | + $this->_model |
|
| 1132 | + ) |
|
| 1133 | + ); |
|
| 1134 | + } |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + |
|
| 1138 | + /** |
|
| 1139 | + * |
|
| 1140 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1141 | + * @since 4.6.x |
|
| 1142 | + * |
|
| 1143 | + * @param $caps |
|
| 1144 | + * @param $cap |
|
| 1145 | + * @param $user_id |
|
| 1146 | + * @param $args |
|
| 1147 | + * |
|
| 1148 | + * @return array |
|
| 1149 | + */ |
|
| 1150 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1151 | + { |
|
| 1152 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + |
|
| 1156 | + /** |
|
| 1157 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1158 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1159 | + * |
|
| 1160 | + * @since 4.5.0 |
|
| 1161 | + * @see wp-includes/capabilities.php |
|
| 1162 | + * |
|
| 1163 | + * @param array $caps actual users capabilities |
|
| 1164 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1165 | + * @param int $user_id The user id |
|
| 1166 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1167 | + * |
|
| 1168 | + * @return array actual users capabilities |
|
| 1169 | + */ |
|
| 1170 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | 1173 | |
@@ -1183,81 +1183,81 @@ discard block |
||
| 1183 | 1183 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
| 1184 | 1184 | { |
| 1185 | 1185 | |
| 1186 | - /** |
|
| 1187 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1188 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1189 | - * |
|
| 1190 | - * @since 4.5.0 |
|
| 1191 | - * @see wp-includes/capabilities.php |
|
| 1192 | - * |
|
| 1193 | - * @param array $caps actual users capabilities |
|
| 1194 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1195 | - * @param int $user_id The user id |
|
| 1196 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1197 | - * |
|
| 1198 | - * @return array actual users capabilities |
|
| 1199 | - */ |
|
| 1200 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1201 | - { |
|
| 1202 | - //only process if we're checking our mapped_cap |
|
| 1203 | - if ($cap !== $this->meta_cap) { |
|
| 1204 | - return $caps; |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1208 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1209 | - unset($caps[$key]); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - //cast $user_id to int for later explicit comparisons |
|
| 1213 | - $user_id = (int) $user_id; |
|
| 1214 | - |
|
| 1215 | - /** @var EE_Base_Class $obj */ |
|
| 1216 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1217 | - //if no obj then let's just do cap |
|
| 1218 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1219 | - $caps[] = 'do_not_allow'; |
|
| 1220 | - return $caps; |
|
| 1221 | - } |
|
| 1222 | - $caps[] = $cap . 's'; |
|
| 1223 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1224 | - //if the item author is set and the user is the author... |
|
| 1225 | - if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1226 | - //if obj is published... |
|
| 1227 | - if ($obj->status() === 'publish') { |
|
| 1228 | - $caps[] = $this->published_cap; |
|
| 1229 | - } |
|
| 1230 | - } else { |
|
| 1231 | - //the user is trying to edit someone else's obj |
|
| 1232 | - if (! empty($this->others_cap)) { |
|
| 1233 | - $caps[] = $this->others_cap; |
|
| 1234 | - } |
|
| 1235 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1236 | - $caps[] = $this->published_cap; |
|
| 1237 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1238 | - $caps[] = $this->private_cap; |
|
| 1239 | - } |
|
| 1240 | - } |
|
| 1241 | - } else { |
|
| 1242 | - //not a cpt object so handled differently |
|
| 1243 | - $has_cap = false; |
|
| 1244 | - try { |
|
| 1245 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1246 | - && $obj->wp_user() |
|
| 1247 | - && $obj->wp_user() === $user_id; |
|
| 1248 | - } catch (Exception $e) { |
|
| 1249 | - if (WP_DEBUG) { |
|
| 1250 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1251 | - } |
|
| 1252 | - } |
|
| 1253 | - if (! $has_cap) { |
|
| 1254 | - if (! empty($this->others_cap)) { |
|
| 1255 | - $caps[] = $this->others_cap; |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - return $caps; |
|
| 1260 | - } |
|
| 1186 | + /** |
|
| 1187 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1188 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1189 | + * |
|
| 1190 | + * @since 4.5.0 |
|
| 1191 | + * @see wp-includes/capabilities.php |
|
| 1192 | + * |
|
| 1193 | + * @param array $caps actual users capabilities |
|
| 1194 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1195 | + * @param int $user_id The user id |
|
| 1196 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1197 | + * |
|
| 1198 | + * @return array actual users capabilities |
|
| 1199 | + */ |
|
| 1200 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1201 | + { |
|
| 1202 | + //only process if we're checking our mapped_cap |
|
| 1203 | + if ($cap !== $this->meta_cap) { |
|
| 1204 | + return $caps; |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1208 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1209 | + unset($caps[$key]); |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + //cast $user_id to int for later explicit comparisons |
|
| 1213 | + $user_id = (int) $user_id; |
|
| 1214 | + |
|
| 1215 | + /** @var EE_Base_Class $obj */ |
|
| 1216 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1217 | + //if no obj then let's just do cap |
|
| 1218 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1219 | + $caps[] = 'do_not_allow'; |
|
| 1220 | + return $caps; |
|
| 1221 | + } |
|
| 1222 | + $caps[] = $cap . 's'; |
|
| 1223 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1224 | + //if the item author is set and the user is the author... |
|
| 1225 | + if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1226 | + //if obj is published... |
|
| 1227 | + if ($obj->status() === 'publish') { |
|
| 1228 | + $caps[] = $this->published_cap; |
|
| 1229 | + } |
|
| 1230 | + } else { |
|
| 1231 | + //the user is trying to edit someone else's obj |
|
| 1232 | + if (! empty($this->others_cap)) { |
|
| 1233 | + $caps[] = $this->others_cap; |
|
| 1234 | + } |
|
| 1235 | + if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1236 | + $caps[] = $this->published_cap; |
|
| 1237 | + } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1238 | + $caps[] = $this->private_cap; |
|
| 1239 | + } |
|
| 1240 | + } |
|
| 1241 | + } else { |
|
| 1242 | + //not a cpt object so handled differently |
|
| 1243 | + $has_cap = false; |
|
| 1244 | + try { |
|
| 1245 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1246 | + && $obj->wp_user() |
|
| 1247 | + && $obj->wp_user() === $user_id; |
|
| 1248 | + } catch (Exception $e) { |
|
| 1249 | + if (WP_DEBUG) { |
|
| 1250 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1251 | + } |
|
| 1252 | + } |
|
| 1253 | + if (! $has_cap) { |
|
| 1254 | + if (! empty($this->others_cap)) { |
|
| 1255 | + $caps[] = $this->others_cap; |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + return $caps; |
|
| 1260 | + } |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | |
@@ -1274,24 +1274,24 @@ discard block |
||
| 1274 | 1274 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
| 1275 | 1275 | { |
| 1276 | 1276 | |
| 1277 | - /** |
|
| 1278 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1279 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1280 | - * |
|
| 1281 | - * @since 4.5.0 |
|
| 1282 | - * @see wp-includes/capabilities.php |
|
| 1283 | - * |
|
| 1284 | - * @param array $caps actual users capabilities |
|
| 1285 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1286 | - * @param int $user_id The user id |
|
| 1287 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1288 | - * |
|
| 1289 | - * @return array actual users capabilities |
|
| 1290 | - */ |
|
| 1291 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1292 | - { |
|
| 1293 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1294 | - } |
|
| 1277 | + /** |
|
| 1278 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1279 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1280 | + * |
|
| 1281 | + * @since 4.5.0 |
|
| 1282 | + * @see wp-includes/capabilities.php |
|
| 1283 | + * |
|
| 1284 | + * @param array $caps actual users capabilities |
|
| 1285 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1286 | + * @param int $user_id The user id |
|
| 1287 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1288 | + * |
|
| 1289 | + * @return array actual users capabilities |
|
| 1290 | + */ |
|
| 1291 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1292 | + { |
|
| 1293 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1294 | + } |
|
| 1295 | 1295 | } |
| 1296 | 1296 | |
| 1297 | 1297 | |
@@ -1307,85 +1307,85 @@ discard block |
||
| 1307 | 1307 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
| 1308 | 1308 | { |
| 1309 | 1309 | |
| 1310 | - /** |
|
| 1311 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1312 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1313 | - * |
|
| 1314 | - * @since 4.5.0 |
|
| 1315 | - * @see wp-includes/capabilities.php |
|
| 1316 | - * |
|
| 1317 | - * @param array $caps actual users capabilities |
|
| 1318 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1319 | - * @param int $user_id The user id |
|
| 1320 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1321 | - * |
|
| 1322 | - * @return array actual users capabilities |
|
| 1323 | - */ |
|
| 1324 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1325 | - { |
|
| 1326 | - //only process if we're checking our mapped cap; |
|
| 1327 | - if ($cap !== $this->meta_cap) { |
|
| 1328 | - return $caps; |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1332 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1333 | - unset($caps[$key]); |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - //cast $user_id to int for later explicit comparisons |
|
| 1337 | - $user_id = (int) $user_id; |
|
| 1338 | - |
|
| 1339 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1340 | - //if no obj then let's just do cap |
|
| 1341 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1342 | - $caps[] = 'do_not_allow'; |
|
| 1343 | - return $caps; |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - $caps[] = $cap . 's'; |
|
| 1347 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1348 | - $status_obj = get_post_status_object($obj->status()); |
|
| 1349 | - if ($status_obj->public) { |
|
| 1350 | - return $caps; |
|
| 1351 | - } |
|
| 1352 | - //if the item author is set and the user is not the author... |
|
| 1353 | - if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1354 | - if (! empty($this->others_cap)) { |
|
| 1355 | - $caps[] = $this->others_cap; |
|
| 1356 | - } |
|
| 1357 | - } |
|
| 1358 | - //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1359 | - if ($status_obj->private |
|
| 1360 | - && ! empty($this->private_cap) |
|
| 1361 | - && $obj->wp_user() !== $user_id |
|
| 1362 | - ) { |
|
| 1363 | - //the user is trying to view a private object for an object they don't own. |
|
| 1364 | - $caps[] = $this->private_cap; |
|
| 1365 | - } |
|
| 1366 | - } else { |
|
| 1367 | - //not a cpt object so handled differently |
|
| 1368 | - $has_cap = false; |
|
| 1369 | - try { |
|
| 1370 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1371 | - && $obj->wp_user() |
|
| 1372 | - && $obj->wp_user() === $user_id; |
|
| 1373 | - } catch (Exception $e) { |
|
| 1374 | - if (WP_DEBUG) { |
|
| 1375 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1376 | - } |
|
| 1377 | - } |
|
| 1378 | - if (! $has_cap) { |
|
| 1379 | - if (! empty($this->private_cap)) { |
|
| 1380 | - $caps[] = $this->private_cap; |
|
| 1381 | - } |
|
| 1382 | - if (! empty($this->others_cap)) { |
|
| 1383 | - $caps[] = $this->others_cap; |
|
| 1384 | - } |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - return $caps; |
|
| 1388 | - } |
|
| 1310 | + /** |
|
| 1311 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1312 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1313 | + * |
|
| 1314 | + * @since 4.5.0 |
|
| 1315 | + * @see wp-includes/capabilities.php |
|
| 1316 | + * |
|
| 1317 | + * @param array $caps actual users capabilities |
|
| 1318 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1319 | + * @param int $user_id The user id |
|
| 1320 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1321 | + * |
|
| 1322 | + * @return array actual users capabilities |
|
| 1323 | + */ |
|
| 1324 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1325 | + { |
|
| 1326 | + //only process if we're checking our mapped cap; |
|
| 1327 | + if ($cap !== $this->meta_cap) { |
|
| 1328 | + return $caps; |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1332 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1333 | + unset($caps[$key]); |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + //cast $user_id to int for later explicit comparisons |
|
| 1337 | + $user_id = (int) $user_id; |
|
| 1338 | + |
|
| 1339 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1340 | + //if no obj then let's just do cap |
|
| 1341 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1342 | + $caps[] = 'do_not_allow'; |
|
| 1343 | + return $caps; |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + $caps[] = $cap . 's'; |
|
| 1347 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1348 | + $status_obj = get_post_status_object($obj->status()); |
|
| 1349 | + if ($status_obj->public) { |
|
| 1350 | + return $caps; |
|
| 1351 | + } |
|
| 1352 | + //if the item author is set and the user is not the author... |
|
| 1353 | + if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1354 | + if (! empty($this->others_cap)) { |
|
| 1355 | + $caps[] = $this->others_cap; |
|
| 1356 | + } |
|
| 1357 | + } |
|
| 1358 | + //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1359 | + if ($status_obj->private |
|
| 1360 | + && ! empty($this->private_cap) |
|
| 1361 | + && $obj->wp_user() !== $user_id |
|
| 1362 | + ) { |
|
| 1363 | + //the user is trying to view a private object for an object they don't own. |
|
| 1364 | + $caps[] = $this->private_cap; |
|
| 1365 | + } |
|
| 1366 | + } else { |
|
| 1367 | + //not a cpt object so handled differently |
|
| 1368 | + $has_cap = false; |
|
| 1369 | + try { |
|
| 1370 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1371 | + && $obj->wp_user() |
|
| 1372 | + && $obj->wp_user() === $user_id; |
|
| 1373 | + } catch (Exception $e) { |
|
| 1374 | + if (WP_DEBUG) { |
|
| 1375 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1376 | + } |
|
| 1377 | + } |
|
| 1378 | + if (! $has_cap) { |
|
| 1379 | + if (! empty($this->private_cap)) { |
|
| 1380 | + $caps[] = $this->private_cap; |
|
| 1381 | + } |
|
| 1382 | + if (! empty($this->others_cap)) { |
|
| 1383 | + $caps[] = $this->others_cap; |
|
| 1384 | + } |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + return $caps; |
|
| 1388 | + } |
|
| 1389 | 1389 | } |
| 1390 | 1390 | |
| 1391 | 1391 | |
@@ -1402,56 +1402,56 @@ discard block |
||
| 1402 | 1402 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
| 1403 | 1403 | { |
| 1404 | 1404 | |
| 1405 | - /** |
|
| 1406 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1407 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1408 | - * |
|
| 1409 | - * @since 4.5.0 |
|
| 1410 | - * @see wp-includes/capabilities.php |
|
| 1411 | - * |
|
| 1412 | - * @param array $caps actual users capabilities |
|
| 1413 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1414 | - * @param int $user_id The user id |
|
| 1415 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1416 | - * |
|
| 1417 | - * @return array actual users capabilities |
|
| 1418 | - */ |
|
| 1419 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1420 | - { |
|
| 1421 | - //only process if we're checking our mapped_cap |
|
| 1422 | - if ($cap !== $this->meta_cap) { |
|
| 1423 | - return $caps; |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1427 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1428 | - unset($caps[$key]); |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - //cast $user_id to int for later explicit comparisons |
|
| 1432 | - $user_id = (int) $user_id; |
|
| 1433 | - |
|
| 1434 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1435 | - //if no obj then let's just do cap |
|
| 1436 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1437 | - $caps[] = 'do_not_allow'; |
|
| 1438 | - return $caps; |
|
| 1439 | - } |
|
| 1440 | - $caps[] = $cap . 's'; |
|
| 1441 | - $is_global = $obj->is_global(); |
|
| 1442 | - if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1443 | - if ($is_global) { |
|
| 1444 | - $caps[] = $this->private_cap; |
|
| 1445 | - } |
|
| 1446 | - } else { |
|
| 1447 | - if ($is_global) { |
|
| 1448 | - $caps[] = $this->private_cap; |
|
| 1449 | - } else { |
|
| 1450 | - $caps[] = $this->others_cap; |
|
| 1451 | - } |
|
| 1452 | - } |
|
| 1453 | - return $caps; |
|
| 1454 | - } |
|
| 1405 | + /** |
|
| 1406 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1407 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1408 | + * |
|
| 1409 | + * @since 4.5.0 |
|
| 1410 | + * @see wp-includes/capabilities.php |
|
| 1411 | + * |
|
| 1412 | + * @param array $caps actual users capabilities |
|
| 1413 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1414 | + * @param int $user_id The user id |
|
| 1415 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1416 | + * |
|
| 1417 | + * @return array actual users capabilities |
|
| 1418 | + */ |
|
| 1419 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1420 | + { |
|
| 1421 | + //only process if we're checking our mapped_cap |
|
| 1422 | + if ($cap !== $this->meta_cap) { |
|
| 1423 | + return $caps; |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1427 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1428 | + unset($caps[$key]); |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + //cast $user_id to int for later explicit comparisons |
|
| 1432 | + $user_id = (int) $user_id; |
|
| 1433 | + |
|
| 1434 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1435 | + //if no obj then let's just do cap |
|
| 1436 | + if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1437 | + $caps[] = 'do_not_allow'; |
|
| 1438 | + return $caps; |
|
| 1439 | + } |
|
| 1440 | + $caps[] = $cap . 's'; |
|
| 1441 | + $is_global = $obj->is_global(); |
|
| 1442 | + if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1443 | + if ($is_global) { |
|
| 1444 | + $caps[] = $this->private_cap; |
|
| 1445 | + } |
|
| 1446 | + } else { |
|
| 1447 | + if ($is_global) { |
|
| 1448 | + $caps[] = $this->private_cap; |
|
| 1449 | + } else { |
|
| 1450 | + $caps[] = $this->others_cap; |
|
| 1451 | + } |
|
| 1452 | + } |
|
| 1453 | + return $caps; |
|
| 1454 | + } |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | |
@@ -1468,40 +1468,40 @@ discard block |
||
| 1468 | 1468 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
| 1469 | 1469 | { |
| 1470 | 1470 | |
| 1471 | - /** |
|
| 1472 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1473 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1474 | - * |
|
| 1475 | - * @since 4.5.0 |
|
| 1476 | - * @see wp-includes/capabilities.php |
|
| 1477 | - * @param array $caps actual users capabilities |
|
| 1478 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1479 | - * @param int $user_id The user id |
|
| 1480 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1481 | - * @return array actual users capabilities |
|
| 1482 | - */ |
|
| 1483 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1484 | - { |
|
| 1485 | - //only process if we're checking our mapped_cap |
|
| 1486 | - if ($cap !== $this->meta_cap) { |
|
| 1487 | - return $caps; |
|
| 1488 | - } |
|
| 1489 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1490 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1491 | - unset($caps[$key]); |
|
| 1492 | - } |
|
| 1493 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1494 | - //if no obj then let's just do cap |
|
| 1495 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1496 | - $caps[] = 'do_not_allow'; |
|
| 1497 | - return $caps; |
|
| 1498 | - } |
|
| 1499 | - $caps[] = $cap . 's'; |
|
| 1500 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1501 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1502 | - if ($is_system) { |
|
| 1503 | - $caps[] = $this->private_cap; |
|
| 1504 | - } |
|
| 1505 | - return $caps; |
|
| 1506 | - } |
|
| 1471 | + /** |
|
| 1472 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1473 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1474 | + * |
|
| 1475 | + * @since 4.5.0 |
|
| 1476 | + * @see wp-includes/capabilities.php |
|
| 1477 | + * @param array $caps actual users capabilities |
|
| 1478 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1479 | + * @param int $user_id The user id |
|
| 1480 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1481 | + * @return array actual users capabilities |
|
| 1482 | + */ |
|
| 1483 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1484 | + { |
|
| 1485 | + //only process if we're checking our mapped_cap |
|
| 1486 | + if ($cap !== $this->meta_cap) { |
|
| 1487 | + return $caps; |
|
| 1488 | + } |
|
| 1489 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1490 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1491 | + unset($caps[$key]); |
|
| 1492 | + } |
|
| 1493 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1494 | + //if no obj then let's just do cap |
|
| 1495 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1496 | + $caps[] = 'do_not_allow'; |
|
| 1497 | + return $caps; |
|
| 1498 | + } |
|
| 1499 | + $caps[] = $cap . 's'; |
|
| 1500 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1501 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1502 | + if ($is_system) { |
|
| 1503 | + $caps[] = $this->private_cap; |
|
| 1504 | + } |
|
| 1505 | + return $caps; |
|
| 1506 | + } |
|
| 1507 | 1507 | } |
@@ -22,103 +22,103 @@ |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var LoaderDecoratorInterface $new_loader |
|
| 27 | - */ |
|
| 28 | - private $new_loader; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var LoaderDecoratorInterface $shared_loader |
|
| 33 | - */ |
|
| 34 | - private $shared_loader; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Loader constructor. |
|
| 40 | - * |
|
| 41 | - * @param LoaderDecoratorInterface|null $new_loader |
|
| 42 | - * @param LoaderDecoratorInterface|null $shared_loader |
|
| 43 | - * @throws InvalidInterfaceException |
|
| 44 | - * @throws InvalidArgumentException |
|
| 45 | - * @throws InvalidDataTypeException |
|
| 46 | - */ |
|
| 47 | - public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader) |
|
| 48 | - { |
|
| 49 | - $this->new_loader = $new_loader; |
|
| 50 | - $this->shared_loader = $shared_loader; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return LoaderDecoratorInterface |
|
| 57 | - */ |
|
| 58 | - public function getNewLoader() |
|
| 59 | - { |
|
| 60 | - return $this->new_loader; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return LoaderDecoratorInterface |
|
| 67 | - */ |
|
| 68 | - public function getSharedLoader() |
|
| 69 | - { |
|
| 70 | - return $this->shared_loader; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $fqcn |
|
| 77 | - * @param array $arguments |
|
| 78 | - * @param bool $shared |
|
| 79 | - * @return mixed |
|
| 80 | - */ |
|
| 81 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 82 | - { |
|
| 83 | - return $shared |
|
| 84 | - ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
| 85 | - : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param string $fqcn |
|
| 92 | - * @param array $arguments |
|
| 93 | - * @return mixed |
|
| 94 | - */ |
|
| 95 | - public function getNew($fqcn, $arguments = array()) |
|
| 96 | - { |
|
| 97 | - return $this->getNewLoader()->load($fqcn, $arguments, false); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param string $fqcn |
|
| 104 | - * @param array $arguments |
|
| 105 | - * @return mixed |
|
| 106 | - */ |
|
| 107 | - public function getShared($fqcn, $arguments = array()) |
|
| 108 | - { |
|
| 109 | - return $this->getSharedLoader()->load($fqcn, $arguments, true); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * calls reset() on loaders if that method exists |
|
| 116 | - */ |
|
| 117 | - public function reset() |
|
| 118 | - { |
|
| 119 | - $this->new_loader->reset(); |
|
| 120 | - $this->shared_loader->reset(); |
|
| 121 | - } |
|
| 25 | + /** |
|
| 26 | + * @var LoaderDecoratorInterface $new_loader |
|
| 27 | + */ |
|
| 28 | + private $new_loader; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var LoaderDecoratorInterface $shared_loader |
|
| 33 | + */ |
|
| 34 | + private $shared_loader; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Loader constructor. |
|
| 40 | + * |
|
| 41 | + * @param LoaderDecoratorInterface|null $new_loader |
|
| 42 | + * @param LoaderDecoratorInterface|null $shared_loader |
|
| 43 | + * @throws InvalidInterfaceException |
|
| 44 | + * @throws InvalidArgumentException |
|
| 45 | + * @throws InvalidDataTypeException |
|
| 46 | + */ |
|
| 47 | + public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader) |
|
| 48 | + { |
|
| 49 | + $this->new_loader = $new_loader; |
|
| 50 | + $this->shared_loader = $shared_loader; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return LoaderDecoratorInterface |
|
| 57 | + */ |
|
| 58 | + public function getNewLoader() |
|
| 59 | + { |
|
| 60 | + return $this->new_loader; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return LoaderDecoratorInterface |
|
| 67 | + */ |
|
| 68 | + public function getSharedLoader() |
|
| 69 | + { |
|
| 70 | + return $this->shared_loader; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $fqcn |
|
| 77 | + * @param array $arguments |
|
| 78 | + * @param bool $shared |
|
| 79 | + * @return mixed |
|
| 80 | + */ |
|
| 81 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 82 | + { |
|
| 83 | + return $shared |
|
| 84 | + ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
| 85 | + : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param string $fqcn |
|
| 92 | + * @param array $arguments |
|
| 93 | + * @return mixed |
|
| 94 | + */ |
|
| 95 | + public function getNew($fqcn, $arguments = array()) |
|
| 96 | + { |
|
| 97 | + return $this->getNewLoader()->load($fqcn, $arguments, false); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param string $fqcn |
|
| 104 | + * @param array $arguments |
|
| 105 | + * @return mixed |
|
| 106 | + */ |
|
| 107 | + public function getShared($fqcn, $arguments = array()) |
|
| 108 | + { |
|
| 109 | + return $this->getSharedLoader()->load($fqcn, $arguments, true); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * calls reset() on loaders if that method exists |
|
| 116 | + */ |
|
| 117 | + public function reset() |
|
| 118 | + { |
|
| 119 | + $this->new_loader->reset(); |
|
| 120 | + $this->shared_loader->reset(); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | // End of file Loader.php |
@@ -26,67 +26,67 @@ |
||
| 26 | 26 | class CoreLoader implements LoaderDecoratorInterface |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var EE_Registry|CoffeeShop $generator |
|
| 31 | - */ |
|
| 32 | - private $generator; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * CoreLoader constructor. |
|
| 38 | - * |
|
| 39 | - * @param EE_Registry|CoffeeShop $generator |
|
| 40 | - * @throws InvalidArgumentException |
|
| 41 | - */ |
|
| 42 | - public function __construct($generator) |
|
| 43 | - { |
|
| 44 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 45 | - throw new InvalidArgumentException( |
|
| 46 | - esc_html__( |
|
| 47 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 48 | - 'event_espresso' |
|
| 49 | - ) |
|
| 50 | - ); |
|
| 51 | - } |
|
| 52 | - $this->generator = $generator; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $fqcn |
|
| 59 | - * @param array $arguments |
|
| 60 | - * @param bool $shared |
|
| 61 | - * @return mixed |
|
| 62 | - * @throws EE_Error |
|
| 63 | - * @throws ServiceNotFoundException |
|
| 64 | - * @throws ReflectionException |
|
| 65 | - */ |
|
| 66 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 67 | - { |
|
| 68 | - if($this->generator instanceof EE_Registry) { |
|
| 69 | - return $this->generator->create($fqcn, $arguments, $shared); |
|
| 70 | - } |
|
| 71 | - $shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW; |
|
| 72 | - return $this->generator->brew($fqcn, $arguments, $shared); |
|
| 73 | - |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * calls reset() on generator if method exists |
|
| 80 | - * |
|
| 81 | - * @throws EE_Error |
|
| 82 | - * @throws ReflectionException |
|
| 83 | - */ |
|
| 84 | - public function reset() |
|
| 85 | - { |
|
| 86 | - if (method_exists($this->generator, 'reset')) { |
|
| 87 | - $this->generator->reset(); |
|
| 88 | - } |
|
| 89 | - } |
|
| 29 | + /** |
|
| 30 | + * @var EE_Registry|CoffeeShop $generator |
|
| 31 | + */ |
|
| 32 | + private $generator; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * CoreLoader constructor. |
|
| 38 | + * |
|
| 39 | + * @param EE_Registry|CoffeeShop $generator |
|
| 40 | + * @throws InvalidArgumentException |
|
| 41 | + */ |
|
| 42 | + public function __construct($generator) |
|
| 43 | + { |
|
| 44 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 45 | + throw new InvalidArgumentException( |
|
| 46 | + esc_html__( |
|
| 47 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 48 | + 'event_espresso' |
|
| 49 | + ) |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | + $this->generator = $generator; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $fqcn |
|
| 59 | + * @param array $arguments |
|
| 60 | + * @param bool $shared |
|
| 61 | + * @return mixed |
|
| 62 | + * @throws EE_Error |
|
| 63 | + * @throws ServiceNotFoundException |
|
| 64 | + * @throws ReflectionException |
|
| 65 | + */ |
|
| 66 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 67 | + { |
|
| 68 | + if($this->generator instanceof EE_Registry) { |
|
| 69 | + return $this->generator->create($fqcn, $arguments, $shared); |
|
| 70 | + } |
|
| 71 | + $shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW; |
|
| 72 | + return $this->generator->brew($fqcn, $arguments, $shared); |
|
| 73 | + |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * calls reset() on generator if method exists |
|
| 80 | + * |
|
| 81 | + * @throws EE_Error |
|
| 82 | + * @throws ReflectionException |
|
| 83 | + */ |
|
| 84 | + public function reset() |
|
| 85 | + { |
|
| 86 | + if (method_exists($this->generator, 'reset')) { |
|
| 87 | + $this->generator->reset(); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | // End of file CoreLoader.php |
@@ -20,159 +20,159 @@ |
||
| 20 | 20 | class EE_Register_Shortcode implements EEI_Plugin_API |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Holds values for registered shortcodes |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected static $_settings = array(); |
|
| 23 | + /** |
|
| 24 | + * Holds values for registered shortcodes |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected static $_settings = array(); |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Method for registering new EE_Shortcodes |
|
| 33 | - * |
|
| 34 | - * @since 4.3.0 |
|
| 35 | - * @since 4.9.46.rc.025 for the new `shortcode_fqcns` array argument. |
|
| 36 | - * @param string $shortcode_id a unique identifier for this set of modules Required. |
|
| 37 | - * @param array $setup_args an array of arguments provided for registering shortcodes Required. |
|
| 38 | - * @type array shortcode_paths an array of full server paths to folders containing any |
|
| 39 | - * EES_Shortcodes |
|
| 40 | - * @type array shortcode_fqcns an array of fully qualified class names for any new shortcode |
|
| 41 | - * classes to register. Shortcode classes should extend |
|
| 42 | - * EspressoShortcode and be properly namespaced so they are |
|
| 43 | - * autoloaded. |
|
| 44 | - * @throws EE_Error |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - public static function register($shortcode_id = null, $setup_args = array()) |
|
| 48 | - { |
|
| 49 | - //required fields MUST be present, so let's make sure they are. |
|
| 50 | - if (empty($shortcode_id) |
|
| 51 | - || ! is_array($setup_args) |
|
| 52 | - || ( |
|
| 53 | - empty($setup_args['shortcode_paths'])) |
|
| 54 | - && empty($setup_args['shortcode_fqcns']) |
|
| 55 | - ) { |
|
| 56 | - throw new EE_Error( |
|
| 57 | - esc_html__( |
|
| 58 | - 'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)', |
|
| 59 | - 'event_espresso' |
|
| 60 | - ) |
|
| 61 | - ); |
|
| 62 | - } |
|
| 31 | + /** |
|
| 32 | + * Method for registering new EE_Shortcodes |
|
| 33 | + * |
|
| 34 | + * @since 4.3.0 |
|
| 35 | + * @since 4.9.46.rc.025 for the new `shortcode_fqcns` array argument. |
|
| 36 | + * @param string $shortcode_id a unique identifier for this set of modules Required. |
|
| 37 | + * @param array $setup_args an array of arguments provided for registering shortcodes Required. |
|
| 38 | + * @type array shortcode_paths an array of full server paths to folders containing any |
|
| 39 | + * EES_Shortcodes |
|
| 40 | + * @type array shortcode_fqcns an array of fully qualified class names for any new shortcode |
|
| 41 | + * classes to register. Shortcode classes should extend |
|
| 42 | + * EspressoShortcode and be properly namespaced so they are |
|
| 43 | + * autoloaded. |
|
| 44 | + * @throws EE_Error |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + public static function register($shortcode_id = null, $setup_args = array()) |
|
| 48 | + { |
|
| 49 | + //required fields MUST be present, so let's make sure they are. |
|
| 50 | + if (empty($shortcode_id) |
|
| 51 | + || ! is_array($setup_args) |
|
| 52 | + || ( |
|
| 53 | + empty($setup_args['shortcode_paths'])) |
|
| 54 | + && empty($setup_args['shortcode_fqcns']) |
|
| 55 | + ) { |
|
| 56 | + throw new EE_Error( |
|
| 57 | + esc_html__( |
|
| 58 | + 'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)', |
|
| 59 | + 'event_espresso' |
|
| 60 | + ) |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - //make sure we don't register twice |
|
| 65 | - if (isset(self::$_settings[$shortcode_id])) { |
|
| 66 | - return; |
|
| 67 | - } |
|
| 64 | + //make sure we don't register twice |
|
| 65 | + if (isset(self::$_settings[$shortcode_id])) { |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - //make sure this was called in the right place! |
|
| 70 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 71 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
| 72 | - ) { |
|
| 73 | - EE_Error::doing_it_wrong( |
|
| 74 | - __METHOD__, |
|
| 75 | - esc_html__( |
|
| 76 | - 'An attempt to register shortcodes has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ), |
|
| 79 | - '4.3.0' |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - //setup $_settings array from incoming values. |
|
| 83 | - self::$_settings[$shortcode_id] = array( |
|
| 84 | - // array of full server paths to any EES_Shortcodes used by the shortcode |
|
| 85 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 86 | - ? (array) $setup_args['shortcode_paths'] |
|
| 87 | - : array(), |
|
| 88 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 89 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 90 | - : array() |
|
| 91 | - ); |
|
| 92 | - // add to list of shortcodes to be registered |
|
| 93 | - add_filter( |
|
| 94 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 95 | - array('EE_Register_Shortcode', 'add_shortcodes') |
|
| 96 | - ); |
|
| 69 | + //make sure this was called in the right place! |
|
| 70 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 71 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
| 72 | + ) { |
|
| 73 | + EE_Error::doing_it_wrong( |
|
| 74 | + __METHOD__, |
|
| 75 | + esc_html__( |
|
| 76 | + 'An attempt to register shortcodes has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ), |
|
| 79 | + '4.3.0' |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + //setup $_settings array from incoming values. |
|
| 83 | + self::$_settings[$shortcode_id] = array( |
|
| 84 | + // array of full server paths to any EES_Shortcodes used by the shortcode |
|
| 85 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 86 | + ? (array) $setup_args['shortcode_paths'] |
|
| 87 | + : array(), |
|
| 88 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 89 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 90 | + : array() |
|
| 91 | + ); |
|
| 92 | + // add to list of shortcodes to be registered |
|
| 93 | + add_filter( |
|
| 94 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 95 | + array('EE_Register_Shortcode', 'add_shortcodes') |
|
| 96 | + ); |
|
| 97 | 97 | |
| 98 | - add_filter( |
|
| 99 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
| 100 | - array('EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection') |
|
| 101 | - ); |
|
| 102 | - } |
|
| 98 | + add_filter( |
|
| 99 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
| 100 | + array('EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection') |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Filters the list of shortcodes to add ours. |
|
| 107 | - * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
| 108 | - * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...) |
|
| 109 | - * |
|
| 110 | - * @param array $shortcodes_to_register array of paths to all shortcodes that require registering |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public static function add_shortcodes($shortcodes_to_register) |
|
| 114 | - { |
|
| 115 | - foreach (self::$_settings as $settings) { |
|
| 116 | - $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']); |
|
| 117 | - } |
|
| 118 | - return $shortcodes_to_register; |
|
| 119 | - } |
|
| 105 | + /** |
|
| 106 | + * Filters the list of shortcodes to add ours. |
|
| 107 | + * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
| 108 | + * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...) |
|
| 109 | + * |
|
| 110 | + * @param array $shortcodes_to_register array of paths to all shortcodes that require registering |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public static function add_shortcodes($shortcodes_to_register) |
|
| 114 | + { |
|
| 115 | + foreach (self::$_settings as $settings) { |
|
| 116 | + $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']); |
|
| 117 | + } |
|
| 118 | + return $shortcodes_to_register; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Hooks into FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection |
|
| 124 | - * and registers any provided shortcode fully qualified class names. |
|
| 125 | - * @param CollectionInterface $shortcodes_collection |
|
| 126 | - * @return CollectionInterface |
|
| 127 | - * @throws InvalidArgumentException |
|
| 128 | - * @throws InvalidClassException |
|
| 129 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 130 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 131 | - */ |
|
| 132 | - public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection) |
|
| 133 | - { |
|
| 134 | - foreach (self::$_settings as $settings) { |
|
| 135 | - if (! empty($settings['shortcode_fqcns'])) { |
|
| 136 | - foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
|
| 137 | - if (! class_exists($shortcode_fqcn)) { |
|
| 138 | - throw new InvalidClassException( |
|
| 139 | - sprintf( |
|
| 140 | - esc_html__( |
|
| 141 | - 'Are you sure %s is the right fully qualified class name for the shortcode class?', |
|
| 142 | - 'event_espresso' |
|
| 143 | - ), |
|
| 144 | - $shortcode_fqcn |
|
| 145 | - ) |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
| 149 | - //register dependencies |
|
| 150 | - EE_Dependency_Map::register_dependencies( |
|
| 151 | - $shortcode_fqcn, |
|
| 152 | - array( |
|
| 153 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 154 | - ) |
|
| 155 | - ); |
|
| 156 | - } |
|
| 157 | - $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn)); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - return $shortcodes_collection; |
|
| 162 | - } |
|
| 122 | + /** |
|
| 123 | + * Hooks into FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection |
|
| 124 | + * and registers any provided shortcode fully qualified class names. |
|
| 125 | + * @param CollectionInterface $shortcodes_collection |
|
| 126 | + * @return CollectionInterface |
|
| 127 | + * @throws InvalidArgumentException |
|
| 128 | + * @throws InvalidClassException |
|
| 129 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 130 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 131 | + */ |
|
| 132 | + public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection) |
|
| 133 | + { |
|
| 134 | + foreach (self::$_settings as $settings) { |
|
| 135 | + if (! empty($settings['shortcode_fqcns'])) { |
|
| 136 | + foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
|
| 137 | + if (! class_exists($shortcode_fqcn)) { |
|
| 138 | + throw new InvalidClassException( |
|
| 139 | + sprintf( |
|
| 140 | + esc_html__( |
|
| 141 | + 'Are you sure %s is the right fully qualified class name for the shortcode class?', |
|
| 142 | + 'event_espresso' |
|
| 143 | + ), |
|
| 144 | + $shortcode_fqcn |
|
| 145 | + ) |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
| 149 | + //register dependencies |
|
| 150 | + EE_Dependency_Map::register_dependencies( |
|
| 151 | + $shortcode_fqcn, |
|
| 152 | + array( |
|
| 153 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 154 | + ) |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | + $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn)); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + return $shortcodes_collection; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * This deregisters a shortcode that was previously registered with a specific $shortcode_id. |
|
| 167 | - * |
|
| 168 | - * @since 4.3.0 |
|
| 169 | - * @param string $shortcode_id the name for the shortcode that was previously registered |
|
| 170 | - * @return void |
|
| 171 | - */ |
|
| 172 | - public static function deregister($shortcode_id = null) |
|
| 173 | - { |
|
| 174 | - if (isset(self::$_settings[$shortcode_id])) { |
|
| 175 | - unset(self::$_settings[$shortcode_id]); |
|
| 176 | - } |
|
| 177 | - } |
|
| 165 | + /** |
|
| 166 | + * This deregisters a shortcode that was previously registered with a specific $shortcode_id. |
|
| 167 | + * |
|
| 168 | + * @since 4.3.0 |
|
| 169 | + * @param string $shortcode_id the name for the shortcode that was previously registered |
|
| 170 | + * @return void |
|
| 171 | + */ |
|
| 172 | + public static function deregister($shortcode_id = null) |
|
| 173 | + { |
|
| 174 | + if (isset(self::$_settings[$shortcode_id])) { |
|
| 175 | + unset(self::$_settings[$shortcode_id]); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | 178 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | //make sure this was called in the right place! |
| 70 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 70 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 71 | 71 | || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
| 72 | 72 | ) { |
| 73 | 73 | EE_Error::doing_it_wrong( |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection) |
| 133 | 133 | { |
| 134 | 134 | foreach (self::$_settings as $settings) { |
| 135 | - if (! empty($settings['shortcode_fqcns'])) { |
|
| 135 | + if ( ! empty($settings['shortcode_fqcns'])) { |
|
| 136 | 136 | foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
| 137 | - if (! class_exists($shortcode_fqcn)) { |
|
| 137 | + if ( ! class_exists($shortcode_fqcn)) { |
|
| 138 | 138 | throw new InvalidClassException( |
| 139 | 139 | sprintf( |
| 140 | 140 | esc_html__( |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | ) |
| 146 | 146 | ); |
| 147 | 147 | } |
| 148 | - if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
| 148 | + if ( ! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
| 149 | 149 | //register dependencies |
| 150 | 150 | EE_Dependency_Map::register_dependencies( |
| 151 | 151 | $shortcode_fqcn, |
@@ -14,249 +14,249 @@ |
||
| 14 | 14 | class EEH_URL |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * _add_query_arg |
|
| 19 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 20 | - * |
|
| 21 | - * @access public |
|
| 22 | - * @param array $args |
|
| 23 | - * @param string $url |
|
| 24 | - * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
| 28 | - { |
|
| 29 | - if (empty($url)) { |
|
| 30 | - $user_msg = esc_html__( |
|
| 31 | - 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
| 32 | - 'event_espresso' |
|
| 33 | - ); |
|
| 34 | - $dev_msg = $user_msg . "\n" |
|
| 35 | - . sprintf( |
|
| 36 | - esc_html__( |
|
| 37 | - 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
|
| 38 | - 'event_espresso' |
|
| 39 | - ), |
|
| 40 | - __CLASS__ . '::add_query_args_and_nonce' |
|
| 41 | - ); |
|
| 42 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 43 | - } |
|
| 44 | - // check that an action exists and add nonce |
|
| 45 | - if (! $exclude_nonce) { |
|
| 46 | - if (isset($args['action']) && ! empty($args['action'])) { |
|
| 47 | - $args = array_merge( |
|
| 48 | - $args, |
|
| 49 | - array( |
|
| 50 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 53 | - } else { |
|
| 54 | - $args = array_merge( |
|
| 55 | - $args, |
|
| 56 | - array( |
|
| 57 | - 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
| 58 | - ) |
|
| 59 | - ); |
|
| 60 | - } |
|
| 61 | - } |
|
| 17 | + /** |
|
| 18 | + * _add_query_arg |
|
| 19 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 20 | + * |
|
| 21 | + * @access public |
|
| 22 | + * @param array $args |
|
| 23 | + * @param string $url |
|
| 24 | + * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
| 28 | + { |
|
| 29 | + if (empty($url)) { |
|
| 30 | + $user_msg = esc_html__( |
|
| 31 | + 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
| 32 | + 'event_espresso' |
|
| 33 | + ); |
|
| 34 | + $dev_msg = $user_msg . "\n" |
|
| 35 | + . sprintf( |
|
| 36 | + esc_html__( |
|
| 37 | + 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
|
| 38 | + 'event_espresso' |
|
| 39 | + ), |
|
| 40 | + __CLASS__ . '::add_query_args_and_nonce' |
|
| 41 | + ); |
|
| 42 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 43 | + } |
|
| 44 | + // check that an action exists and add nonce |
|
| 45 | + if (! $exclude_nonce) { |
|
| 46 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
| 47 | + $args = array_merge( |
|
| 48 | + $args, |
|
| 49 | + array( |
|
| 50 | + $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | + } else { |
|
| 54 | + $args = array_merge( |
|
| 55 | + $args, |
|
| 56 | + array( |
|
| 57 | + 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
| 58 | + ) |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - //finally, let's always add a return address (if present) :) |
|
| 64 | - $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
| 65 | - ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
| 66 | - : $args; |
|
| 63 | + //finally, let's always add a return address (if present) :) |
|
| 64 | + $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
| 65 | + ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
| 66 | + : $args; |
|
| 67 | 67 | |
| 68 | - return add_query_arg($args, $url); |
|
| 69 | - } |
|
| 68 | + return add_query_arg($args, $url); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Returns whether not the remote file exists. |
|
| 74 | - * Checking via GET because HEAD requests are blocked on some server configurations. |
|
| 75 | - * |
|
| 76 | - * @param string $url |
|
| 77 | - * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
| 78 | - * @return boolean |
|
| 79 | - */ |
|
| 80 | - public static function remote_file_exists($url, $args = array()) |
|
| 81 | - { |
|
| 82 | - $results = wp_remote_request( |
|
| 83 | - $url, |
|
| 84 | - array_merge( |
|
| 85 | - array( |
|
| 86 | - 'method' => 'GET', |
|
| 87 | - 'redirection' => 1, |
|
| 88 | - ), |
|
| 89 | - $args |
|
| 90 | - ) |
|
| 91 | - ); |
|
| 92 | - if (! $results instanceof WP_Error && |
|
| 93 | - isset($results['response']) && |
|
| 94 | - isset($results['response']['code']) && |
|
| 95 | - $results['response']['code'] == '200') { |
|
| 96 | - return true; |
|
| 97 | - } else { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - } |
|
| 72 | + /** |
|
| 73 | + * Returns whether not the remote file exists. |
|
| 74 | + * Checking via GET because HEAD requests are blocked on some server configurations. |
|
| 75 | + * |
|
| 76 | + * @param string $url |
|
| 77 | + * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
| 78 | + * @return boolean |
|
| 79 | + */ |
|
| 80 | + public static function remote_file_exists($url, $args = array()) |
|
| 81 | + { |
|
| 82 | + $results = wp_remote_request( |
|
| 83 | + $url, |
|
| 84 | + array_merge( |
|
| 85 | + array( |
|
| 86 | + 'method' => 'GET', |
|
| 87 | + 'redirection' => 1, |
|
| 88 | + ), |
|
| 89 | + $args |
|
| 90 | + ) |
|
| 91 | + ); |
|
| 92 | + if (! $results instanceof WP_Error && |
|
| 93 | + isset($results['response']) && |
|
| 94 | + isset($results['response']['code']) && |
|
| 95 | + $results['response']['code'] == '200') { |
|
| 96 | + return true; |
|
| 97 | + } else { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * refactor_url |
|
| 105 | - * primarily used for removing the query string from a URL |
|
| 106 | - * |
|
| 107 | - * @param string $url |
|
| 108 | - * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
| 109 | - * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
| 113 | - { |
|
| 114 | - // break apart incoming URL |
|
| 115 | - $url_bits = parse_url($url); |
|
| 116 | - // HTTP or HTTPS ? |
|
| 117 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 118 | - // domain |
|
| 119 | - $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 120 | - // if only the base URL is requested, then return that now |
|
| 121 | - if ($base_url_only) { |
|
| 122 | - return $scheme . $host; |
|
| 123 | - } |
|
| 124 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 125 | - $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 126 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 127 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 128 | - $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 129 | - // if the query string is not required, then return what we have so far |
|
| 130 | - if ($remove_query) { |
|
| 131 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 132 | - } |
|
| 133 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 134 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 135 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 136 | - } |
|
| 103 | + /** |
|
| 104 | + * refactor_url |
|
| 105 | + * primarily used for removing the query string from a URL |
|
| 106 | + * |
|
| 107 | + * @param string $url |
|
| 108 | + * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
| 109 | + * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
| 113 | + { |
|
| 114 | + // break apart incoming URL |
|
| 115 | + $url_bits = parse_url($url); |
|
| 116 | + // HTTP or HTTPS ? |
|
| 117 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 118 | + // domain |
|
| 119 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 120 | + // if only the base URL is requested, then return that now |
|
| 121 | + if ($base_url_only) { |
|
| 122 | + return $scheme . $host; |
|
| 123 | + } |
|
| 124 | + $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 125 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 126 | + $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 127 | + $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 128 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 129 | + // if the query string is not required, then return what we have so far |
|
| 130 | + if ($remove_query) { |
|
| 131 | + return $scheme . $user . $pass . $host . $port . $path; |
|
| 132 | + } |
|
| 133 | + $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 134 | + $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 135 | + return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * get_query_string |
|
| 141 | - * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
| 142 | - * |
|
| 143 | - * @param string $url |
|
| 144 | - * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
| 145 | - * simply return the query string |
|
| 146 | - * @return string|array |
|
| 147 | - */ |
|
| 148 | - public static function get_query_string($url = '', $as_array = true) |
|
| 149 | - { |
|
| 150 | - // decode, then break apart incoming URL |
|
| 151 | - $url_bits = parse_url(html_entity_decode($url)); |
|
| 152 | - // grab query string from URL |
|
| 153 | - $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 154 | - // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
| 155 | - if (! $as_array) { |
|
| 156 | - return $query; |
|
| 157 | - } |
|
| 158 | - // if no query string exists then just return an empty array now |
|
| 159 | - if (empty($query)) { |
|
| 160 | - return array(); |
|
| 161 | - } |
|
| 162 | - // empty array to hold results |
|
| 163 | - $query_params = array(); |
|
| 164 | - // now break apart the query string into separate params |
|
| 165 | - $query = explode('&', $query); |
|
| 166 | - // loop thru our query params |
|
| 167 | - foreach ($query as $query_args) { |
|
| 168 | - // break apart the key value pairs |
|
| 169 | - $query_args = explode('=', $query_args); |
|
| 170 | - // and add to our results array |
|
| 171 | - $query_params[$query_args[0]] = $query_args[1]; |
|
| 172 | - } |
|
| 173 | - return $query_params; |
|
| 174 | - } |
|
| 139 | + /** |
|
| 140 | + * get_query_string |
|
| 141 | + * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
| 142 | + * |
|
| 143 | + * @param string $url |
|
| 144 | + * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
| 145 | + * simply return the query string |
|
| 146 | + * @return string|array |
|
| 147 | + */ |
|
| 148 | + public static function get_query_string($url = '', $as_array = true) |
|
| 149 | + { |
|
| 150 | + // decode, then break apart incoming URL |
|
| 151 | + $url_bits = parse_url(html_entity_decode($url)); |
|
| 152 | + // grab query string from URL |
|
| 153 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 154 | + // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
| 155 | + if (! $as_array) { |
|
| 156 | + return $query; |
|
| 157 | + } |
|
| 158 | + // if no query string exists then just return an empty array now |
|
| 159 | + if (empty($query)) { |
|
| 160 | + return array(); |
|
| 161 | + } |
|
| 162 | + // empty array to hold results |
|
| 163 | + $query_params = array(); |
|
| 164 | + // now break apart the query string into separate params |
|
| 165 | + $query = explode('&', $query); |
|
| 166 | + // loop thru our query params |
|
| 167 | + foreach ($query as $query_args) { |
|
| 168 | + // break apart the key value pairs |
|
| 169 | + $query_args = explode('=', $query_args); |
|
| 170 | + // and add to our results array |
|
| 171 | + $query_params[$query_args[0]] = $query_args[1]; |
|
| 172 | + } |
|
| 173 | + return $query_params; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * prevent_prefetching |
|
| 179 | - * |
|
| 180 | - * @return void |
|
| 181 | - */ |
|
| 182 | - public static function prevent_prefetching() |
|
| 183 | - { |
|
| 184 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
| 185 | - // with the registration process |
|
| 186 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 187 | - } |
|
| 177 | + /** |
|
| 178 | + * prevent_prefetching |
|
| 179 | + * |
|
| 180 | + * @return void |
|
| 181 | + */ |
|
| 182 | + public static function prevent_prefetching() |
|
| 183 | + { |
|
| 184 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
| 185 | + // with the registration process |
|
| 186 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * This generates a unique site-specific string. |
|
| 192 | - * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
| 193 | - * urls. |
|
| 194 | - * |
|
| 195 | - * @param string $prefix Use this to prefix the string with something. |
|
| 196 | - * @return string |
|
| 197 | - */ |
|
| 198 | - public static function generate_unique_token($prefix = '') |
|
| 199 | - { |
|
| 200 | - $token = md5(uniqid() . mt_rand()); |
|
| 201 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 202 | - } |
|
| 190 | + /** |
|
| 191 | + * This generates a unique site-specific string. |
|
| 192 | + * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
| 193 | + * urls. |
|
| 194 | + * |
|
| 195 | + * @param string $prefix Use this to prefix the string with something. |
|
| 196 | + * @return string |
|
| 197 | + */ |
|
| 198 | + public static function generate_unique_token($prefix = '') |
|
| 199 | + { |
|
| 200 | + $token = md5(uniqid() . mt_rand()); |
|
| 201 | + return $prefix ? $prefix . '_' . $token : $token; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * filter_input_server_url |
|
| 207 | - * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
| 208 | - * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
| 209 | - * |
|
| 210 | - * @param string $server_variable |
|
| 211 | - * @return string |
|
| 212 | - */ |
|
| 213 | - public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
| 214 | - { |
|
| 215 | - $URL = ''; |
|
| 216 | - $server_variables = array( |
|
| 217 | - 'REQUEST_URI' => 1, |
|
| 218 | - 'HTTP_HOST' => 1, |
|
| 219 | - 'PHP_SELF' => 1, |
|
| 220 | - ); |
|
| 221 | - $server_variable = strtoupper($server_variable); |
|
| 222 | - // whitelist INPUT_SERVER var |
|
| 223 | - if (isset($server_variables[$server_variable])) { |
|
| 224 | - $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 225 | - if (empty($URL)) { |
|
| 226 | - // fallback sanitization if the above fails |
|
| 227 | - $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - return $URL; |
|
| 231 | - } |
|
| 205 | + /** |
|
| 206 | + * filter_input_server_url |
|
| 207 | + * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
| 208 | + * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
| 209 | + * |
|
| 210 | + * @param string $server_variable |
|
| 211 | + * @return string |
|
| 212 | + */ |
|
| 213 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
| 214 | + { |
|
| 215 | + $URL = ''; |
|
| 216 | + $server_variables = array( |
|
| 217 | + 'REQUEST_URI' => 1, |
|
| 218 | + 'HTTP_HOST' => 1, |
|
| 219 | + 'PHP_SELF' => 1, |
|
| 220 | + ); |
|
| 221 | + $server_variable = strtoupper($server_variable); |
|
| 222 | + // whitelist INPUT_SERVER var |
|
| 223 | + if (isset($server_variables[$server_variable])) { |
|
| 224 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 225 | + if (empty($URL)) { |
|
| 226 | + // fallback sanitization if the above fails |
|
| 227 | + $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + return $URL; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Gets the current page's full URL. |
|
| 236 | - * |
|
| 237 | - * @return string |
|
| 238 | - */ |
|
| 239 | - public static function current_url() |
|
| 240 | - { |
|
| 241 | - $url = ''; |
|
| 242 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 243 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
| 244 | - $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 245 | - $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 246 | - } |
|
| 247 | - return $url; |
|
| 248 | - } |
|
| 234 | + /** |
|
| 235 | + * Gets the current page's full URL. |
|
| 236 | + * |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 239 | + public static function current_url() |
|
| 240 | + { |
|
| 241 | + $url = ''; |
|
| 242 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 243 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
| 244 | + $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 245 | + $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 246 | + } |
|
| 247 | + return $url; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
| 253 | - * |
|
| 254 | - * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
| 255 | - * @since 4.9.46.rc.029 |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public static function current_url_without_query_paramaters(array $query_parameters) |
|
| 259 | - { |
|
| 260 | - return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
| 261 | - } |
|
| 251 | + /** |
|
| 252 | + * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
| 253 | + * |
|
| 254 | + * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
| 255 | + * @since 4.9.46.rc.029 |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public static function current_url_without_query_paramaters(array $query_parameters) |
|
| 259 | + { |
|
| 260 | + return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
| 261 | + } |
|
| 262 | 262 | } |
@@ -31,23 +31,23 @@ discard block |
||
| 31 | 31 | 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
| 32 | 32 | 'event_espresso' |
| 33 | 33 | ); |
| 34 | - $dev_msg = $user_msg . "\n" |
|
| 34 | + $dev_msg = $user_msg."\n" |
|
| 35 | 35 | . sprintf( |
| 36 | 36 | esc_html__( |
| 37 | 37 | 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
| 38 | 38 | 'event_espresso' |
| 39 | 39 | ), |
| 40 | - __CLASS__ . '::add_query_args_and_nonce' |
|
| 40 | + __CLASS__.'::add_query_args_and_nonce' |
|
| 41 | 41 | ); |
| 42 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 42 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 43 | 43 | } |
| 44 | 44 | // check that an action exists and add nonce |
| 45 | - if (! $exclude_nonce) { |
|
| 45 | + if ( ! $exclude_nonce) { |
|
| 46 | 46 | if (isset($args['action']) && ! empty($args['action'])) { |
| 47 | 47 | $args = array_merge( |
| 48 | 48 | $args, |
| 49 | 49 | array( |
| 50 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 50 | + $args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce') |
|
| 51 | 51 | ) |
| 52 | 52 | ); |
| 53 | 53 | } else { |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $args |
| 90 | 90 | ) |
| 91 | 91 | ); |
| 92 | - if (! $results instanceof WP_Error && |
|
| 92 | + if ( ! $results instanceof WP_Error && |
|
| 93 | 93 | isset($results['response']) && |
| 94 | 94 | isset($results['response']['code']) && |
| 95 | 95 | $results['response']['code'] == '200') { |
@@ -114,25 +114,25 @@ discard block |
||
| 114 | 114 | // break apart incoming URL |
| 115 | 115 | $url_bits = parse_url($url); |
| 116 | 116 | // HTTP or HTTPS ? |
| 117 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 117 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://'; |
|
| 118 | 118 | // domain |
| 119 | 119 | $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
| 120 | 120 | // if only the base URL is requested, then return that now |
| 121 | 121 | if ($base_url_only) { |
| 122 | - return $scheme . $host; |
|
| 122 | + return $scheme.$host; |
|
| 123 | 123 | } |
| 124 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 124 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
| 125 | 125 | $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
| 126 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 127 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 126 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
| 127 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
| 128 | 128 | $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
| 129 | 129 | // if the query string is not required, then return what we have so far |
| 130 | 130 | if ($remove_query) { |
| 131 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 131 | + return $scheme.$user.$pass.$host.$port.$path; |
|
| 132 | 132 | } |
| 133 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 134 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 135 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 133 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
| 134 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
| 135 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | // grab query string from URL |
| 153 | 153 | $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
| 154 | 154 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
| 155 | - if (! $as_array) { |
|
| 155 | + if ( ! $as_array) { |
|
| 156 | 156 | return $query; |
| 157 | 157 | } |
| 158 | 158 | // if no query string exists then just return an empty array now |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public static function generate_unique_token($prefix = '') |
| 199 | 199 | { |
| 200 | - $token = md5(uniqid() . mt_rand()); |
|
| 201 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 200 | + $token = md5(uniqid().mt_rand()); |
|
| 201 | + return $prefix ? $prefix.'_'.$token : $token; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | 'HTTP_HOST' => 1, |
| 219 | 219 | 'PHP_SELF' => 1, |
| 220 | 220 | ); |
| 221 | - $server_variable = strtoupper($server_variable); |
|
| 221 | + $server_variable = strtoupper($server_variable); |
|
| 222 | 222 | // whitelist INPUT_SERVER var |
| 223 | 223 | if (isset($server_variables[$server_variable])) { |
| 224 | 224 | $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
@@ -21,345 +21,345 @@ |
||
| 21 | 21 | class TicketSelectorRowStandard extends TicketSelectorRow |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var TicketDetails $ticket_details |
|
| 26 | - */ |
|
| 27 | - protected $ticket_details; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var \EE_Ticket_Selector_Config $template_settings |
|
| 31 | - */ |
|
| 32 | - protected $template_settings; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var EE_Tax_Config $tax_settings |
|
| 36 | - */ |
|
| 37 | - protected $tax_settings; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var boolean $prices_displayed_including_taxes |
|
| 41 | - */ |
|
| 42 | - protected $prices_displayed_including_taxes; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var int $row |
|
| 46 | - */ |
|
| 47 | - protected $row; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var int $cols |
|
| 51 | - */ |
|
| 52 | - protected $cols; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var boolean $hidden_input_qty |
|
| 56 | - */ |
|
| 57 | - protected $hidden_input_qty; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var string $ticket_datetime_classes |
|
| 61 | - */ |
|
| 62 | - protected $ticket_datetime_classes; |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * TicketDetails constructor. |
|
| 68 | - * |
|
| 69 | - * @param TicketDetails $ticket_details |
|
| 70 | - * @param EE_Tax_Config $tax_settings |
|
| 71 | - * @param int $total_tickets |
|
| 72 | - * @param int $max_attendees |
|
| 73 | - * @param int $row |
|
| 74 | - * @param int $cols |
|
| 75 | - * @param boolean $required_ticket_sold_out |
|
| 76 | - * @param string $event_status |
|
| 77 | - * @param string $ticket_datetime_classes |
|
| 78 | - * @throws EE_Error |
|
| 79 | - * @throws UnexpectedEntityException |
|
| 80 | - */ |
|
| 81 | - public function __construct( |
|
| 82 | - TicketDetails $ticket_details, |
|
| 83 | - EE_Tax_Config $tax_settings, |
|
| 84 | - $total_tickets, |
|
| 85 | - $max_attendees, |
|
| 86 | - $row, |
|
| 87 | - $cols, |
|
| 88 | - $required_ticket_sold_out, |
|
| 89 | - $event_status, |
|
| 90 | - $ticket_datetime_classes |
|
| 91 | - ) { |
|
| 92 | - $this->ticket_details = $ticket_details; |
|
| 93 | - $this->template_settings = $ticket_details->getTemplateSettings(); |
|
| 94 | - $this->tax_settings = $tax_settings; |
|
| 95 | - $this->row = $row; |
|
| 96 | - $this->cols = $cols; |
|
| 97 | - $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
| 98 | - parent::__construct( |
|
| 99 | - $ticket_details->getTicket(), |
|
| 100 | - $max_attendees, |
|
| 101 | - $ticket_details->getDateFormat(), |
|
| 102 | - $event_status, |
|
| 103 | - $required_ticket_sold_out, |
|
| 104 | - $total_tickets |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * other ticket rows will need to know if a required ticket is sold out, |
|
| 112 | - * so that they are not offered for sale |
|
| 113 | - * |
|
| 114 | - * @return boolean |
|
| 115 | - */ |
|
| 116 | - public function getRequiredTicketSoldOut() |
|
| 117 | - { |
|
| 118 | - return $this->required_ticket_sold_out; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @return int |
|
| 125 | - */ |
|
| 126 | - public function getCols() |
|
| 127 | - { |
|
| 128 | - return $this->cols; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * getHtml |
|
| 135 | - * |
|
| 136 | - * @return string |
|
| 137 | - * @throws EE_Error |
|
| 138 | - */ |
|
| 139 | - public function getHtml() |
|
| 140 | - { |
|
| 141 | - $this->min = 0; |
|
| 142 | - $this->max = $this->ticket->max(); |
|
| 143 | - $remaining = $this->ticket->remaining(); |
|
| 144 | - if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) { |
|
| 145 | - $this->setTicketMinAndMax($remaining); |
|
| 146 | - } else { |
|
| 147 | - // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
| 148 | - $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
| 149 | - ? $this->ticket->start_date() |
|
| 150 | - : $this->required_ticket_sold_out; |
|
| 151 | - } |
|
| 152 | - $this->setTicketPriceDetails(); |
|
| 153 | - $this->setTicketStatusClasses($remaining); |
|
| 154 | - $filtered_row_html = $this->getFilteredRowHtml(); |
|
| 155 | - if ($filtered_row_html !== false) { |
|
| 156 | - return $filtered_row_html; |
|
| 157 | - } |
|
| 158 | - $ticket_selector_row_html = EEH_HTML::tr( |
|
| 159 | - '', '', |
|
| 160 | - "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
| 161 | - . espresso_get_object_css_class($this->ticket) |
|
| 162 | - ); |
|
| 163 | - $filtered_row_content = $this->getFilteredRowContents(); |
|
| 164 | - if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
| 165 | - return $ticket_selector_row_html |
|
| 166 | - . $filtered_row_content |
|
| 167 | - . $this->ticketQtyAndIdHiddenInputs() |
|
| 168 | - . EEH_HTML::trx(); |
|
| 169 | - } |
|
| 170 | - if ($filtered_row_content !== false) { |
|
| 171 | - return $ticket_selector_row_html |
|
| 172 | - . $filtered_row_content |
|
| 173 | - . EEH_HTML::trx(); |
|
| 174 | - } |
|
| 175 | - $this->hidden_input_qty = $this->max_attendees > 1; |
|
| 176 | - |
|
| 177 | - $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
| 178 | - $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
| 179 | - $ticket_selector_row_html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr'); |
|
| 180 | - $this->setTicketStatusDisplay($remaining); |
|
| 181 | - if (empty($this->ticket_status_display)) { |
|
| 182 | - if ($this->max_attendees === 1) { |
|
| 183 | - // only ONE attendee is allowed to register at a time |
|
| 184 | - $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
| 185 | - } elseif ($this->max > 0) { |
|
| 186 | - $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - $ticket_selector_row_html .= $this->ticket_status_display; |
|
| 190 | - $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
| 191 | - $ticket_selector_row_html .= $this->ticket_details->display( |
|
| 192 | - $this->ticket_price, |
|
| 193 | - $remaining, |
|
| 194 | - $this->cols |
|
| 195 | - ); |
|
| 196 | - $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
| 197 | - $ticket_selector_row_html .= EEH_HTML::trx(); |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - $this->row++; |
|
| 201 | - return $ticket_selector_row_html; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * getTicketPriceDetails |
|
| 209 | - * |
|
| 210 | - * @return void |
|
| 211 | - * @throws EE_Error |
|
| 212 | - */ |
|
| 213 | - protected function setTicketPriceDetails() |
|
| 214 | - { |
|
| 215 | - $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
| 216 | - ? $this->ticket->get_ticket_total_with_taxes() |
|
| 217 | - : $this->ticket->get_ticket_subtotal(); |
|
| 218 | - $this->ticket_bundle = false; |
|
| 219 | - $ticket_min = $this->ticket->min(); |
|
| 220 | - // for ticket bundles, set min and max qty the same |
|
| 221 | - if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
| 222 | - $this->ticket_price *= $ticket_min; |
|
| 223 | - $this->ticket_bundle = true; |
|
| 224 | - } |
|
| 225 | - $this->ticket_price = apply_filters( |
|
| 226 | - 'FHEE__ticket_selector_chart_template__ticket_price', |
|
| 227 | - $this->ticket_price, |
|
| 228 | - $this->ticket |
|
| 229 | - ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * ticketNameTableCell |
|
| 237 | - * |
|
| 238 | - * @return string |
|
| 239 | - * @throws EE_Error |
|
| 240 | - */ |
|
| 241 | - protected function ticketNameTableCell() |
|
| 242 | - { |
|
| 243 | - $html = EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name'); |
|
| 244 | - $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
| 245 | - $html .= $this->ticket_details->getShowHideLinks(); |
|
| 246 | - if ($this->ticket->required()) { |
|
| 247 | - $html .= EEH_HTML::p( |
|
| 248 | - apply_filters( |
|
| 249 | - 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
| 250 | - esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
| 251 | - ), |
|
| 252 | - '', 'ticket-required-pg' |
|
| 253 | - ); |
|
| 254 | - } |
|
| 255 | - $html .= EEH_HTML::tdx(); |
|
| 256 | - return $html; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * ticketPriceTableCell |
|
| 263 | - * |
|
| 264 | - * @return string |
|
| 265 | - * @throws EE_Error |
|
| 266 | - */ |
|
| 267 | - protected function ticketPriceTableCell() |
|
| 268 | - { |
|
| 269 | - $html = ''; |
|
| 270 | - if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
| 271 | - $html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght'); |
|
| 272 | - $html .= \EEH_Template::format_currency($this->ticket_price); |
|
| 273 | - $html .= $this->ticket->taxable() |
|
| 274 | - ? EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' ) |
|
| 275 | - : ''; |
|
| 276 | - $html .= ' '; |
|
| 277 | - $html .= EEH_HTML::span( |
|
| 278 | - $this->ticket_bundle |
|
| 279 | - ? apply_filters( |
|
| 280 | - 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
| 281 | - __(' / bundle', 'event_espresso') |
|
| 282 | - ) |
|
| 283 | - : apply_filters( |
|
| 284 | - 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
| 285 | - __('', 'event_espresso') |
|
| 286 | - ), |
|
| 287 | - '', 'smaller-text no-bold' |
|
| 288 | - ); |
|
| 289 | - $html .= ' '; |
|
| 290 | - $html .= EEH_HTML::tdx(); |
|
| 291 | - $this->cols++; |
|
| 292 | - } |
|
| 293 | - return $html; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * onlyOneAttendeeCanRegister |
|
| 300 | - * |
|
| 301 | - * @return string |
|
| 302 | - */ |
|
| 303 | - protected function onlyOneAttendeeCanRegister() |
|
| 304 | - { |
|
| 305 | - // display submit button since we have tickets available |
|
| 306 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 307 | - $this->hidden_input_qty = false; |
|
| 308 | - $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
| 309 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
| 310 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
| 311 | - $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
| 312 | - $html .= ' title=""/>'; |
|
| 313 | - return $html; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * ticketQuantitySelector |
|
| 320 | - * |
|
| 321 | - * @return string |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - protected function ticketQuantitySelector() |
|
| 325 | - { |
|
| 326 | - // display submit button since we have tickets available |
|
| 327 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 328 | - $this->hidden_input_qty = false; |
|
| 329 | - $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
| 330 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
| 331 | - $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
| 332 | - // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
| 333 | - if ($this->min !== 0 && ! $this->ticket->required()) { |
|
| 334 | - $html .= '<option value="0"> 0 </option>'; |
|
| 335 | - } |
|
| 336 | - // offer ticket quantities from the min to the max |
|
| 337 | - for ($i = $this->min; $i <= $this->max; $i++) { |
|
| 338 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
| 339 | - } |
|
| 340 | - $html .= '</select>'; |
|
| 341 | - return $html; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * getHiddenInputs |
|
| 348 | - * |
|
| 349 | - * @return string |
|
| 350 | - * @throws EE_Error |
|
| 351 | - */ |
|
| 352 | - protected function ticketQtyAndIdHiddenInputs() |
|
| 353 | - { |
|
| 354 | - $html = ''; |
|
| 355 | - // depending on group reg we need to change the format for qty |
|
| 356 | - if ($this->hidden_input_qty) { |
|
| 357 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
| 358 | - } |
|
| 359 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
| 360 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
| 361 | - return $html; |
|
| 362 | - } |
|
| 24 | + /** |
|
| 25 | + * @var TicketDetails $ticket_details |
|
| 26 | + */ |
|
| 27 | + protected $ticket_details; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var \EE_Ticket_Selector_Config $template_settings |
|
| 31 | + */ |
|
| 32 | + protected $template_settings; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var EE_Tax_Config $tax_settings |
|
| 36 | + */ |
|
| 37 | + protected $tax_settings; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var boolean $prices_displayed_including_taxes |
|
| 41 | + */ |
|
| 42 | + protected $prices_displayed_including_taxes; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var int $row |
|
| 46 | + */ |
|
| 47 | + protected $row; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var int $cols |
|
| 51 | + */ |
|
| 52 | + protected $cols; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var boolean $hidden_input_qty |
|
| 56 | + */ |
|
| 57 | + protected $hidden_input_qty; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var string $ticket_datetime_classes |
|
| 61 | + */ |
|
| 62 | + protected $ticket_datetime_classes; |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * TicketDetails constructor. |
|
| 68 | + * |
|
| 69 | + * @param TicketDetails $ticket_details |
|
| 70 | + * @param EE_Tax_Config $tax_settings |
|
| 71 | + * @param int $total_tickets |
|
| 72 | + * @param int $max_attendees |
|
| 73 | + * @param int $row |
|
| 74 | + * @param int $cols |
|
| 75 | + * @param boolean $required_ticket_sold_out |
|
| 76 | + * @param string $event_status |
|
| 77 | + * @param string $ticket_datetime_classes |
|
| 78 | + * @throws EE_Error |
|
| 79 | + * @throws UnexpectedEntityException |
|
| 80 | + */ |
|
| 81 | + public function __construct( |
|
| 82 | + TicketDetails $ticket_details, |
|
| 83 | + EE_Tax_Config $tax_settings, |
|
| 84 | + $total_tickets, |
|
| 85 | + $max_attendees, |
|
| 86 | + $row, |
|
| 87 | + $cols, |
|
| 88 | + $required_ticket_sold_out, |
|
| 89 | + $event_status, |
|
| 90 | + $ticket_datetime_classes |
|
| 91 | + ) { |
|
| 92 | + $this->ticket_details = $ticket_details; |
|
| 93 | + $this->template_settings = $ticket_details->getTemplateSettings(); |
|
| 94 | + $this->tax_settings = $tax_settings; |
|
| 95 | + $this->row = $row; |
|
| 96 | + $this->cols = $cols; |
|
| 97 | + $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
| 98 | + parent::__construct( |
|
| 99 | + $ticket_details->getTicket(), |
|
| 100 | + $max_attendees, |
|
| 101 | + $ticket_details->getDateFormat(), |
|
| 102 | + $event_status, |
|
| 103 | + $required_ticket_sold_out, |
|
| 104 | + $total_tickets |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * other ticket rows will need to know if a required ticket is sold out, |
|
| 112 | + * so that they are not offered for sale |
|
| 113 | + * |
|
| 114 | + * @return boolean |
|
| 115 | + */ |
|
| 116 | + public function getRequiredTicketSoldOut() |
|
| 117 | + { |
|
| 118 | + return $this->required_ticket_sold_out; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @return int |
|
| 125 | + */ |
|
| 126 | + public function getCols() |
|
| 127 | + { |
|
| 128 | + return $this->cols; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * getHtml |
|
| 135 | + * |
|
| 136 | + * @return string |
|
| 137 | + * @throws EE_Error |
|
| 138 | + */ |
|
| 139 | + public function getHtml() |
|
| 140 | + { |
|
| 141 | + $this->min = 0; |
|
| 142 | + $this->max = $this->ticket->max(); |
|
| 143 | + $remaining = $this->ticket->remaining(); |
|
| 144 | + if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) { |
|
| 145 | + $this->setTicketMinAndMax($remaining); |
|
| 146 | + } else { |
|
| 147 | + // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
| 148 | + $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
| 149 | + ? $this->ticket->start_date() |
|
| 150 | + : $this->required_ticket_sold_out; |
|
| 151 | + } |
|
| 152 | + $this->setTicketPriceDetails(); |
|
| 153 | + $this->setTicketStatusClasses($remaining); |
|
| 154 | + $filtered_row_html = $this->getFilteredRowHtml(); |
|
| 155 | + if ($filtered_row_html !== false) { |
|
| 156 | + return $filtered_row_html; |
|
| 157 | + } |
|
| 158 | + $ticket_selector_row_html = EEH_HTML::tr( |
|
| 159 | + '', '', |
|
| 160 | + "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
| 161 | + . espresso_get_object_css_class($this->ticket) |
|
| 162 | + ); |
|
| 163 | + $filtered_row_content = $this->getFilteredRowContents(); |
|
| 164 | + if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
| 165 | + return $ticket_selector_row_html |
|
| 166 | + . $filtered_row_content |
|
| 167 | + . $this->ticketQtyAndIdHiddenInputs() |
|
| 168 | + . EEH_HTML::trx(); |
|
| 169 | + } |
|
| 170 | + if ($filtered_row_content !== false) { |
|
| 171 | + return $ticket_selector_row_html |
|
| 172 | + . $filtered_row_content |
|
| 173 | + . EEH_HTML::trx(); |
|
| 174 | + } |
|
| 175 | + $this->hidden_input_qty = $this->max_attendees > 1; |
|
| 176 | + |
|
| 177 | + $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
| 178 | + $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
| 179 | + $ticket_selector_row_html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr'); |
|
| 180 | + $this->setTicketStatusDisplay($remaining); |
|
| 181 | + if (empty($this->ticket_status_display)) { |
|
| 182 | + if ($this->max_attendees === 1) { |
|
| 183 | + // only ONE attendee is allowed to register at a time |
|
| 184 | + $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
| 185 | + } elseif ($this->max > 0) { |
|
| 186 | + $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + $ticket_selector_row_html .= $this->ticket_status_display; |
|
| 190 | + $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
| 191 | + $ticket_selector_row_html .= $this->ticket_details->display( |
|
| 192 | + $this->ticket_price, |
|
| 193 | + $remaining, |
|
| 194 | + $this->cols |
|
| 195 | + ); |
|
| 196 | + $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
| 197 | + $ticket_selector_row_html .= EEH_HTML::trx(); |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + $this->row++; |
|
| 201 | + return $ticket_selector_row_html; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * getTicketPriceDetails |
|
| 209 | + * |
|
| 210 | + * @return void |
|
| 211 | + * @throws EE_Error |
|
| 212 | + */ |
|
| 213 | + protected function setTicketPriceDetails() |
|
| 214 | + { |
|
| 215 | + $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
| 216 | + ? $this->ticket->get_ticket_total_with_taxes() |
|
| 217 | + : $this->ticket->get_ticket_subtotal(); |
|
| 218 | + $this->ticket_bundle = false; |
|
| 219 | + $ticket_min = $this->ticket->min(); |
|
| 220 | + // for ticket bundles, set min and max qty the same |
|
| 221 | + if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
| 222 | + $this->ticket_price *= $ticket_min; |
|
| 223 | + $this->ticket_bundle = true; |
|
| 224 | + } |
|
| 225 | + $this->ticket_price = apply_filters( |
|
| 226 | + 'FHEE__ticket_selector_chart_template__ticket_price', |
|
| 227 | + $this->ticket_price, |
|
| 228 | + $this->ticket |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * ticketNameTableCell |
|
| 237 | + * |
|
| 238 | + * @return string |
|
| 239 | + * @throws EE_Error |
|
| 240 | + */ |
|
| 241 | + protected function ticketNameTableCell() |
|
| 242 | + { |
|
| 243 | + $html = EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name'); |
|
| 244 | + $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
| 245 | + $html .= $this->ticket_details->getShowHideLinks(); |
|
| 246 | + if ($this->ticket->required()) { |
|
| 247 | + $html .= EEH_HTML::p( |
|
| 248 | + apply_filters( |
|
| 249 | + 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
| 250 | + esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
| 251 | + ), |
|
| 252 | + '', 'ticket-required-pg' |
|
| 253 | + ); |
|
| 254 | + } |
|
| 255 | + $html .= EEH_HTML::tdx(); |
|
| 256 | + return $html; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * ticketPriceTableCell |
|
| 263 | + * |
|
| 264 | + * @return string |
|
| 265 | + * @throws EE_Error |
|
| 266 | + */ |
|
| 267 | + protected function ticketPriceTableCell() |
|
| 268 | + { |
|
| 269 | + $html = ''; |
|
| 270 | + if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
| 271 | + $html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght'); |
|
| 272 | + $html .= \EEH_Template::format_currency($this->ticket_price); |
|
| 273 | + $html .= $this->ticket->taxable() |
|
| 274 | + ? EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' ) |
|
| 275 | + : ''; |
|
| 276 | + $html .= ' '; |
|
| 277 | + $html .= EEH_HTML::span( |
|
| 278 | + $this->ticket_bundle |
|
| 279 | + ? apply_filters( |
|
| 280 | + 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
| 281 | + __(' / bundle', 'event_espresso') |
|
| 282 | + ) |
|
| 283 | + : apply_filters( |
|
| 284 | + 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
| 285 | + __('', 'event_espresso') |
|
| 286 | + ), |
|
| 287 | + '', 'smaller-text no-bold' |
|
| 288 | + ); |
|
| 289 | + $html .= ' '; |
|
| 290 | + $html .= EEH_HTML::tdx(); |
|
| 291 | + $this->cols++; |
|
| 292 | + } |
|
| 293 | + return $html; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * onlyOneAttendeeCanRegister |
|
| 300 | + * |
|
| 301 | + * @return string |
|
| 302 | + */ |
|
| 303 | + protected function onlyOneAttendeeCanRegister() |
|
| 304 | + { |
|
| 305 | + // display submit button since we have tickets available |
|
| 306 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 307 | + $this->hidden_input_qty = false; |
|
| 308 | + $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
| 309 | + $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
| 310 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
| 311 | + $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
| 312 | + $html .= ' title=""/>'; |
|
| 313 | + return $html; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * ticketQuantitySelector |
|
| 320 | + * |
|
| 321 | + * @return string |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + protected function ticketQuantitySelector() |
|
| 325 | + { |
|
| 326 | + // display submit button since we have tickets available |
|
| 327 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 328 | + $this->hidden_input_qty = false; |
|
| 329 | + $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
| 330 | + $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
| 331 | + $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
| 332 | + // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
| 333 | + if ($this->min !== 0 && ! $this->ticket->required()) { |
|
| 334 | + $html .= '<option value="0"> 0 </option>'; |
|
| 335 | + } |
|
| 336 | + // offer ticket quantities from the min to the max |
|
| 337 | + for ($i = $this->min; $i <= $this->max; $i++) { |
|
| 338 | + $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
| 339 | + } |
|
| 340 | + $html .= '</select>'; |
|
| 341 | + return $html; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * getHiddenInputs |
|
| 348 | + * |
|
| 349 | + * @return string |
|
| 350 | + * @throws EE_Error |
|
| 351 | + */ |
|
| 352 | + protected function ticketQtyAndIdHiddenInputs() |
|
| 353 | + { |
|
| 354 | + $html = ''; |
|
| 355 | + // depending on group reg we need to change the format for qty |
|
| 356 | + if ($this->hidden_input_qty) { |
|
| 357 | + $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
| 358 | + } |
|
| 359 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
| 360 | + $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
| 361 | + return $html; |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | 364 | } |
| 365 | 365 | // End of file TicketSelectorRowStandard.php |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | $html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght'); |
| 272 | 272 | $html .= \EEH_Template::format_currency($this->ticket_price); |
| 273 | 273 | $html .= $this->ticket->taxable() |
| 274 | - ? EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' ) |
|
| 274 | + ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
| 275 | 275 | : ''; |
| 276 | 276 | $html .= ' '; |
| 277 | 277 | $html .= EEH_HTML::span( |
@@ -305,9 +305,9 @@ discard block |
||
| 305 | 305 | // display submit button since we have tickets available |
| 306 | 306 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
| 307 | 307 | $this->hidden_input_qty = false; |
| 308 | - $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
| 309 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
| 310 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
| 308 | + $html = '<input type="radio" name="tkt-slctr-qty-'.$this->EVT_ID.'"'; |
|
| 309 | + $html .= ' id="ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row.'"'; |
|
| 310 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="'.$this->row.'-1"'; |
|
| 311 | 311 | $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
| 312 | 312 | $html .= ' title=""/>'; |
| 313 | 313 | return $html; |
@@ -326,8 +326,8 @@ discard block |
||
| 326 | 326 | // display submit button since we have tickets available |
| 327 | 327 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
| 328 | 328 | $this->hidden_input_qty = false; |
| 329 | - $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
| 330 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
| 329 | + $html = '<select name="tkt-slctr-qty-'.$this->EVT_ID.'[]"'; |
|
| 330 | + $html .= ' id="ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row.'"'; |
|
| 331 | 331 | $html .= ' class="ticket-selector-tbl-qty-slct">'; |
| 332 | 332 | // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
| 333 | 333 | if ($this->min !== 0 && ! $this->ticket->required()) { |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | } |
| 336 | 336 | // offer ticket quantities from the min to the max |
| 337 | 337 | for ($i = $this->min; $i <= $this->max; $i++) { |
| 338 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
| 338 | + $html .= '<option value="'.$i.'"> '.$i.' </option>'; |
|
| 339 | 339 | } |
| 340 | 340 | $html .= '</select>'; |
| 341 | 341 | return $html; |
@@ -354,10 +354,10 @@ discard block |
||
| 354 | 354 | $html = ''; |
| 355 | 355 | // depending on group reg we need to change the format for qty |
| 356 | 356 | if ($this->hidden_input_qty) { |
| 357 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
| 357 | + $html .= '<input type="hidden" name="tkt-slctr-qty-'.$this->EVT_ID.'[]" value="0"/>'; |
|
| 358 | 358 | } |
| 359 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
| 360 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
| 359 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-'.$this->EVT_ID.'[]"'; |
|
| 360 | + $html .= ' value="'.$this->ticket->ID().'"/>'; |
|
| 361 | 361 | return $html; |
| 362 | 362 | } |
| 363 | 363 | |
@@ -22,370 +22,370 @@ |
||
| 22 | 22 | abstract class TicketSelectorRow |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var EE_Ticket $ticket |
|
| 27 | - */ |
|
| 28 | - protected $ticket; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var int $total_tickets |
|
| 32 | - */ |
|
| 33 | - protected $total_tickets; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var int $max_attendees |
|
| 37 | - */ |
|
| 38 | - protected $max_attendees; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string $date_format |
|
| 42 | - */ |
|
| 43 | - protected $date_format; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var int $EVT_ID |
|
| 47 | - */ |
|
| 48 | - protected $EVT_ID; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var string $event_status |
|
| 52 | - */ |
|
| 53 | - protected $event_status; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var boolean $required_ticket_sold_out |
|
| 57 | - */ |
|
| 58 | - protected $required_ticket_sold_out; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var string $ticket_status_display |
|
| 62 | - */ |
|
| 63 | - protected $ticket_status_display; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var int $max |
|
| 67 | - */ |
|
| 68 | - protected $max = 0; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var int $min |
|
| 72 | - */ |
|
| 73 | - protected $min = 0; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var float $ticket_price |
|
| 77 | - */ |
|
| 78 | - protected $ticket_price = 0.00; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var bool $ticket_bundle |
|
| 82 | - */ |
|
| 83 | - protected $ticket_bundle = false; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @var string $ticket_status_id |
|
| 87 | - */ |
|
| 88 | - protected $ticket_status_id = EE_Ticket::sold_out; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @var string $ticket_status_html |
|
| 92 | - */ |
|
| 93 | - protected $ticket_status_html = 'ticket-sales-sold-out'; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @var string $status_class |
|
| 97 | - */ |
|
| 98 | - protected $status_class = 'ticket-sales-sold-out lt-grey-text'; |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param EE_Ticket $ticket |
|
| 104 | - * @param int $max_attendees |
|
| 105 | - * @param string $date_format |
|
| 106 | - * @param string $event_status |
|
| 107 | - * @param bool $required_ticket_sold_out |
|
| 108 | - * @param int $total_tickets |
|
| 109 | - * @throws EE_Error |
|
| 110 | - * @throws UnexpectedEntityException |
|
| 111 | - */ |
|
| 112 | - public function __construct( |
|
| 113 | - EE_Ticket $ticket, |
|
| 114 | - $max_attendees, |
|
| 115 | - $date_format, |
|
| 116 | - $event_status, |
|
| 117 | - $required_ticket_sold_out = false, |
|
| 118 | - $total_tickets = 1 |
|
| 119 | - ) { |
|
| 120 | - $this->ticket = $ticket; |
|
| 121 | - $this->max_attendees = $max_attendees; |
|
| 122 | - $this->date_format = $date_format; |
|
| 123 | - $this->EVT_ID = $this->ticket->get_event_ID(); |
|
| 124 | - $this->event_status = $event_status; |
|
| 125 | - $this->required_ticket_sold_out = $required_ticket_sold_out; |
|
| 126 | - $this->total_tickets = $total_tickets; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * getTicketStatusClasses |
|
| 133 | - * |
|
| 134 | - * @param int $remaining |
|
| 135 | - * @return void |
|
| 136 | - * @throws EE_Error |
|
| 137 | - */ |
|
| 138 | - protected function setTicketStatusClasses($remaining = 0) |
|
| 139 | - { |
|
| 140 | - // if a previous required ticket with the same sale start date is sold out, |
|
| 141 | - // then mark this ticket as sold out as well. |
|
| 142 | - // tickets that go on sale at a later date than the required ticket will NOT be affected |
|
| 143 | - $this->ticket_status_id = $this->required_ticket_sold_out !== false |
|
| 144 | - && $this->required_ticket_sold_out === $this->ticket->start_date() |
|
| 145 | - ? EE_Ticket::sold_out |
|
| 146 | - : $this->ticket->ticket_status(); |
|
| 147 | - $this->ticket_status_id = $this->event_status === EE_Datetime::sold_out |
|
| 148 | - ? EE_Ticket::sold_out |
|
| 149 | - : $this->ticket_status_id; |
|
| 150 | - // check ticket status |
|
| 151 | - switch ($this->ticket_status_id) { |
|
| 152 | - // sold_out |
|
| 153 | - case EE_Ticket::sold_out : |
|
| 154 | - $ticket_status_class = 'ticket-sales-sold-out'; |
|
| 155 | - $this->status_class = 'ticket-sales-sold-out lt-grey-text'; |
|
| 156 | - break; |
|
| 157 | - // expired |
|
| 158 | - case EE_Ticket::expired : |
|
| 159 | - $ticket_status_class = 'ticket-sales-expired'; |
|
| 160 | - $this->status_class = 'ticket-sales-expired lt-grey-text'; |
|
| 161 | - break; |
|
| 162 | - // archived |
|
| 163 | - case EE_Ticket::archived : |
|
| 164 | - $ticket_status_class = 'archived-ticket'; |
|
| 165 | - $this->status_class = 'archived-ticket hidden'; |
|
| 166 | - break; |
|
| 167 | - // pending |
|
| 168 | - case EE_Ticket::pending : |
|
| 169 | - $ticket_status_class = 'ticket-pending'; |
|
| 170 | - $this->status_class = 'ticket-pending'; |
|
| 171 | - break; |
|
| 172 | - // on sale |
|
| 173 | - case EE_Ticket::onsale : |
|
| 174 | - default : |
|
| 175 | - $ticket_status_class = 'ticket-on-sale'; |
|
| 176 | - $this->status_class = 'ticket-on-sale'; |
|
| 177 | - break; |
|
| 178 | - } |
|
| 179 | - $this->ticket_status_html = EEH_HTML::span( |
|
| 180 | - $this->ticket->ticket_status(true, ($remaining > 0)), |
|
| 181 | - "{$ticket_status_class}-{$this->ticket->ID()}", |
|
| 182 | - $ticket_status_class |
|
| 183 | - ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 190 | - public function getTicketStatusDisplay() |
|
| 191 | - { |
|
| 192 | - return $this->ticket_status_display; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * setTicketStatusDisplay |
|
| 199 | - * |
|
| 200 | - * @param int $remaining |
|
| 201 | - * @throws EE_Error |
|
| 202 | - */ |
|
| 203 | - protected function setTicketStatusDisplay($remaining) { |
|
| 204 | - $this->ticket_status_display = ''; |
|
| 205 | - // now depending on the ticket and other circumstances... |
|
| 206 | - if ($this->max_attendees === 0) { |
|
| 207 | - // registration is CLOSED because admin set max attendees to ZERO |
|
| 208 | - $this->ticket_status_display = $this->registrationClosed(); |
|
| 209 | - } elseif ($this->ticket_status_id === EE_Ticket::sold_out || $remaining === 0) { |
|
| 210 | - // SOLD OUT - no tickets remaining |
|
| 211 | - $this->ticket_status_display = $this->ticketsSoldOut(); |
|
| 212 | - } elseif ($this->ticket_status_id === EE_Ticket::expired || $this->ticket_status_id === EE_Ticket::archived) { |
|
| 213 | - // expired or archived ticket |
|
| 214 | - $this->ticket_status_display = $this->ticket_status_html; |
|
| 215 | - } elseif ($this->ticket_status_id === EE_Ticket::pending) { |
|
| 216 | - // ticket not on sale yet |
|
| 217 | - $this->ticket_status_display = $this->ticketsSalesPending(); |
|
| 218 | - } elseif ($this->ticket->min() > $remaining) { |
|
| 219 | - // min qty purchasable is less than tickets available |
|
| 220 | - $this->ticket_status_display = $this->notEnoughTicketsAvailable(); |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * registrationClosed |
|
| 228 | - */ |
|
| 229 | - protected function registrationClosed() |
|
| 230 | - { |
|
| 231 | - return EEH_HTML::span( |
|
| 232 | - apply_filters( |
|
| 233 | - 'FHEE__ticket_selector_chart_template__ticket_closed_msg', |
|
| 234 | - __('Closed', 'event_espresso') |
|
| 235 | - ), |
|
| 236 | - '', 'sold-out' |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * ticketsSoldOut |
|
| 244 | - */ |
|
| 245 | - protected function ticketsSoldOut() |
|
| 246 | - { |
|
| 247 | - return EEH_HTML::span( |
|
| 248 | - apply_filters( |
|
| 249 | - 'FHEE__ticket_selector_chart_template__ticket_sold_out_msg', |
|
| 250 | - __('Sold Out', 'event_espresso') |
|
| 251 | - ), |
|
| 252 | - '', 'sold-out' |
|
| 253 | - ); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * ticketsSalesPending |
|
| 260 | - * |
|
| 261 | - * @throws EE_Error |
|
| 262 | - */ |
|
| 263 | - protected function ticketsSalesPending() |
|
| 264 | - { |
|
| 265 | - return EEH_HTML::span( |
|
| 266 | - EEH_HTML::span( |
|
| 267 | - apply_filters( |
|
| 268 | - 'FHEE__ticket_selector_chart_template__ticket_goes_on_sale_msg', |
|
| 269 | - __('Goes On Sale', 'event_espresso') |
|
| 270 | - ), |
|
| 271 | - '', 'ticket-pending' |
|
| 272 | - ) |
|
| 273 | - . EEH_HTML::br() |
|
| 274 | - . EEH_HTML::span( |
|
| 275 | - $this->ticket->get_i18n_datetime( |
|
| 276 | - 'TKT_start_date', |
|
| 277 | - apply_filters( |
|
| 278 | - 'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format', |
|
| 279 | - $this->date_format |
|
| 280 | - ) |
|
| 281 | - ), |
|
| 282 | - '', 'small-text' |
|
| 283 | - ), |
|
| 284 | - '', 'ticket-pending-pg' |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * notEnoughTicketsAvailable |
|
| 292 | - */ |
|
| 293 | - protected function notEnoughTicketsAvailable() |
|
| 294 | - { |
|
| 295 | - return EEH_HTML::div( |
|
| 296 | - EEH_HTML::span( |
|
| 297 | - apply_filters( |
|
| 298 | - 'FHEE__ticket_selector_chart_template__ticket_not_available_msg', |
|
| 299 | - __('Not Available', 'event_espresso') |
|
| 300 | - ), |
|
| 301 | - '', 'archived-ticket small-text' |
|
| 302 | - ) |
|
| 303 | - . EEH_HTML::br(), |
|
| 304 | - '', 'archived-ticket-pg' |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * setTicketMinAndMax |
|
| 312 | - * |
|
| 313 | - * @param int $remaining |
|
| 314 | - * @return void |
|
| 315 | - * @throws EE_Error |
|
| 316 | - */ |
|
| 317 | - protected function setTicketMinAndMax($remaining) |
|
| 318 | - { |
|
| 319 | - // offer the number of $tickets_remaining or $this->max_attendees, whichever is smaller |
|
| 320 | - $this->max = min($remaining, $this->max_attendees); |
|
| 321 | - // but... we also want to restrict the number of tickets by the ticket max setting, |
|
| 322 | - // however, the max still can't be higher than what was just set above |
|
| 323 | - $this->max = $this->ticket->max() > 0 |
|
| 324 | - ? min($this->ticket->max(), $this->max) |
|
| 325 | - : $this->max; |
|
| 326 | - // and we also want to restrict the minimum number of tickets by the ticket min setting |
|
| 327 | - $this->min = $this->ticket->min() > 0 |
|
| 328 | - ? $this->ticket->min() |
|
| 329 | - : 0; |
|
| 330 | - // and if the ticket is required, then make sure that min qty is at least 1 |
|
| 331 | - $this->min = $this->ticket->required() |
|
| 332 | - ? max($this->min, 1) |
|
| 333 | - : $this->min; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Allow plugins to hook in and abort the generation and display of this row to do |
|
| 339 | - * something elseif they want. |
|
| 340 | - * For an addon to abort things, all they have to do is register a filter with this hook, and |
|
| 341 | - * return a value that is NOT false. Whatever is returned gets echoed instead of the |
|
| 342 | - * current row. |
|
| 343 | - * |
|
| 344 | - * @return string|bool |
|
| 345 | - */ |
|
| 346 | - protected function getFilteredRowHtml() { |
|
| 347 | - return apply_filters( |
|
| 348 | - 'FHEE__ticket_selector_chart_template__do_ticket_entire_row', |
|
| 349 | - false, |
|
| 350 | - $this->ticket, |
|
| 351 | - $this->max, |
|
| 352 | - $this->min, |
|
| 353 | - $this->required_ticket_sold_out, |
|
| 354 | - $this->ticket_price, |
|
| 355 | - $this->ticket_bundle, |
|
| 356 | - $this->ticket_status_html, |
|
| 357 | - $this->status_class, |
|
| 358 | - $this |
|
| 359 | - ); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Allow plugins to hook in and abort the generation and display of the contents of this |
|
| 366 | - * row to do something elseif they want. |
|
| 367 | - * For an addon to abort things, all they have to do is register a filter with this hook, and |
|
| 368 | - * return a value that is NOT false. Whatever is returned gets echoed instead of the |
|
| 369 | - * current row. |
|
| 370 | - * |
|
| 371 | - * @return string|bool |
|
| 372 | - */ |
|
| 373 | - protected function getFilteredRowContents() |
|
| 374 | - { |
|
| 375 | - return apply_filters( |
|
| 376 | - 'FHEE__ticket_selector_chart_template__do_ticket_inside_row', |
|
| 377 | - false, |
|
| 378 | - $this->ticket, |
|
| 379 | - $this->max, |
|
| 380 | - $this->min, |
|
| 381 | - $this->required_ticket_sold_out, |
|
| 382 | - $this->ticket_price, |
|
| 383 | - $this->ticket_bundle, |
|
| 384 | - $this->ticket_status_html, |
|
| 385 | - $this->status_class, |
|
| 386 | - $this |
|
| 387 | - ); |
|
| 388 | - } |
|
| 25 | + /** |
|
| 26 | + * @var EE_Ticket $ticket |
|
| 27 | + */ |
|
| 28 | + protected $ticket; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var int $total_tickets |
|
| 32 | + */ |
|
| 33 | + protected $total_tickets; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var int $max_attendees |
|
| 37 | + */ |
|
| 38 | + protected $max_attendees; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string $date_format |
|
| 42 | + */ |
|
| 43 | + protected $date_format; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var int $EVT_ID |
|
| 47 | + */ |
|
| 48 | + protected $EVT_ID; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var string $event_status |
|
| 52 | + */ |
|
| 53 | + protected $event_status; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var boolean $required_ticket_sold_out |
|
| 57 | + */ |
|
| 58 | + protected $required_ticket_sold_out; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var string $ticket_status_display |
|
| 62 | + */ |
|
| 63 | + protected $ticket_status_display; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var int $max |
|
| 67 | + */ |
|
| 68 | + protected $max = 0; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var int $min |
|
| 72 | + */ |
|
| 73 | + protected $min = 0; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var float $ticket_price |
|
| 77 | + */ |
|
| 78 | + protected $ticket_price = 0.00; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @var bool $ticket_bundle |
|
| 82 | + */ |
|
| 83 | + protected $ticket_bundle = false; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @var string $ticket_status_id |
|
| 87 | + */ |
|
| 88 | + protected $ticket_status_id = EE_Ticket::sold_out; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @var string $ticket_status_html |
|
| 92 | + */ |
|
| 93 | + protected $ticket_status_html = 'ticket-sales-sold-out'; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @var string $status_class |
|
| 97 | + */ |
|
| 98 | + protected $status_class = 'ticket-sales-sold-out lt-grey-text'; |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param EE_Ticket $ticket |
|
| 104 | + * @param int $max_attendees |
|
| 105 | + * @param string $date_format |
|
| 106 | + * @param string $event_status |
|
| 107 | + * @param bool $required_ticket_sold_out |
|
| 108 | + * @param int $total_tickets |
|
| 109 | + * @throws EE_Error |
|
| 110 | + * @throws UnexpectedEntityException |
|
| 111 | + */ |
|
| 112 | + public function __construct( |
|
| 113 | + EE_Ticket $ticket, |
|
| 114 | + $max_attendees, |
|
| 115 | + $date_format, |
|
| 116 | + $event_status, |
|
| 117 | + $required_ticket_sold_out = false, |
|
| 118 | + $total_tickets = 1 |
|
| 119 | + ) { |
|
| 120 | + $this->ticket = $ticket; |
|
| 121 | + $this->max_attendees = $max_attendees; |
|
| 122 | + $this->date_format = $date_format; |
|
| 123 | + $this->EVT_ID = $this->ticket->get_event_ID(); |
|
| 124 | + $this->event_status = $event_status; |
|
| 125 | + $this->required_ticket_sold_out = $required_ticket_sold_out; |
|
| 126 | + $this->total_tickets = $total_tickets; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * getTicketStatusClasses |
|
| 133 | + * |
|
| 134 | + * @param int $remaining |
|
| 135 | + * @return void |
|
| 136 | + * @throws EE_Error |
|
| 137 | + */ |
|
| 138 | + protected function setTicketStatusClasses($remaining = 0) |
|
| 139 | + { |
|
| 140 | + // if a previous required ticket with the same sale start date is sold out, |
|
| 141 | + // then mark this ticket as sold out as well. |
|
| 142 | + // tickets that go on sale at a later date than the required ticket will NOT be affected |
|
| 143 | + $this->ticket_status_id = $this->required_ticket_sold_out !== false |
|
| 144 | + && $this->required_ticket_sold_out === $this->ticket->start_date() |
|
| 145 | + ? EE_Ticket::sold_out |
|
| 146 | + : $this->ticket->ticket_status(); |
|
| 147 | + $this->ticket_status_id = $this->event_status === EE_Datetime::sold_out |
|
| 148 | + ? EE_Ticket::sold_out |
|
| 149 | + : $this->ticket_status_id; |
|
| 150 | + // check ticket status |
|
| 151 | + switch ($this->ticket_status_id) { |
|
| 152 | + // sold_out |
|
| 153 | + case EE_Ticket::sold_out : |
|
| 154 | + $ticket_status_class = 'ticket-sales-sold-out'; |
|
| 155 | + $this->status_class = 'ticket-sales-sold-out lt-grey-text'; |
|
| 156 | + break; |
|
| 157 | + // expired |
|
| 158 | + case EE_Ticket::expired : |
|
| 159 | + $ticket_status_class = 'ticket-sales-expired'; |
|
| 160 | + $this->status_class = 'ticket-sales-expired lt-grey-text'; |
|
| 161 | + break; |
|
| 162 | + // archived |
|
| 163 | + case EE_Ticket::archived : |
|
| 164 | + $ticket_status_class = 'archived-ticket'; |
|
| 165 | + $this->status_class = 'archived-ticket hidden'; |
|
| 166 | + break; |
|
| 167 | + // pending |
|
| 168 | + case EE_Ticket::pending : |
|
| 169 | + $ticket_status_class = 'ticket-pending'; |
|
| 170 | + $this->status_class = 'ticket-pending'; |
|
| 171 | + break; |
|
| 172 | + // on sale |
|
| 173 | + case EE_Ticket::onsale : |
|
| 174 | + default : |
|
| 175 | + $ticket_status_class = 'ticket-on-sale'; |
|
| 176 | + $this->status_class = 'ticket-on-sale'; |
|
| 177 | + break; |
|
| 178 | + } |
|
| 179 | + $this->ticket_status_html = EEH_HTML::span( |
|
| 180 | + $this->ticket->ticket_status(true, ($remaining > 0)), |
|
| 181 | + "{$ticket_status_class}-{$this->ticket->ID()}", |
|
| 182 | + $ticket_status_class |
|
| 183 | + ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | + public function getTicketStatusDisplay() |
|
| 191 | + { |
|
| 192 | + return $this->ticket_status_display; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * setTicketStatusDisplay |
|
| 199 | + * |
|
| 200 | + * @param int $remaining |
|
| 201 | + * @throws EE_Error |
|
| 202 | + */ |
|
| 203 | + protected function setTicketStatusDisplay($remaining) { |
|
| 204 | + $this->ticket_status_display = ''; |
|
| 205 | + // now depending on the ticket and other circumstances... |
|
| 206 | + if ($this->max_attendees === 0) { |
|
| 207 | + // registration is CLOSED because admin set max attendees to ZERO |
|
| 208 | + $this->ticket_status_display = $this->registrationClosed(); |
|
| 209 | + } elseif ($this->ticket_status_id === EE_Ticket::sold_out || $remaining === 0) { |
|
| 210 | + // SOLD OUT - no tickets remaining |
|
| 211 | + $this->ticket_status_display = $this->ticketsSoldOut(); |
|
| 212 | + } elseif ($this->ticket_status_id === EE_Ticket::expired || $this->ticket_status_id === EE_Ticket::archived) { |
|
| 213 | + // expired or archived ticket |
|
| 214 | + $this->ticket_status_display = $this->ticket_status_html; |
|
| 215 | + } elseif ($this->ticket_status_id === EE_Ticket::pending) { |
|
| 216 | + // ticket not on sale yet |
|
| 217 | + $this->ticket_status_display = $this->ticketsSalesPending(); |
|
| 218 | + } elseif ($this->ticket->min() > $remaining) { |
|
| 219 | + // min qty purchasable is less than tickets available |
|
| 220 | + $this->ticket_status_display = $this->notEnoughTicketsAvailable(); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * registrationClosed |
|
| 228 | + */ |
|
| 229 | + protected function registrationClosed() |
|
| 230 | + { |
|
| 231 | + return EEH_HTML::span( |
|
| 232 | + apply_filters( |
|
| 233 | + 'FHEE__ticket_selector_chart_template__ticket_closed_msg', |
|
| 234 | + __('Closed', 'event_espresso') |
|
| 235 | + ), |
|
| 236 | + '', 'sold-out' |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * ticketsSoldOut |
|
| 244 | + */ |
|
| 245 | + protected function ticketsSoldOut() |
|
| 246 | + { |
|
| 247 | + return EEH_HTML::span( |
|
| 248 | + apply_filters( |
|
| 249 | + 'FHEE__ticket_selector_chart_template__ticket_sold_out_msg', |
|
| 250 | + __('Sold Out', 'event_espresso') |
|
| 251 | + ), |
|
| 252 | + '', 'sold-out' |
|
| 253 | + ); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * ticketsSalesPending |
|
| 260 | + * |
|
| 261 | + * @throws EE_Error |
|
| 262 | + */ |
|
| 263 | + protected function ticketsSalesPending() |
|
| 264 | + { |
|
| 265 | + return EEH_HTML::span( |
|
| 266 | + EEH_HTML::span( |
|
| 267 | + apply_filters( |
|
| 268 | + 'FHEE__ticket_selector_chart_template__ticket_goes_on_sale_msg', |
|
| 269 | + __('Goes On Sale', 'event_espresso') |
|
| 270 | + ), |
|
| 271 | + '', 'ticket-pending' |
|
| 272 | + ) |
|
| 273 | + . EEH_HTML::br() |
|
| 274 | + . EEH_HTML::span( |
|
| 275 | + $this->ticket->get_i18n_datetime( |
|
| 276 | + 'TKT_start_date', |
|
| 277 | + apply_filters( |
|
| 278 | + 'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format', |
|
| 279 | + $this->date_format |
|
| 280 | + ) |
|
| 281 | + ), |
|
| 282 | + '', 'small-text' |
|
| 283 | + ), |
|
| 284 | + '', 'ticket-pending-pg' |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * notEnoughTicketsAvailable |
|
| 292 | + */ |
|
| 293 | + protected function notEnoughTicketsAvailable() |
|
| 294 | + { |
|
| 295 | + return EEH_HTML::div( |
|
| 296 | + EEH_HTML::span( |
|
| 297 | + apply_filters( |
|
| 298 | + 'FHEE__ticket_selector_chart_template__ticket_not_available_msg', |
|
| 299 | + __('Not Available', 'event_espresso') |
|
| 300 | + ), |
|
| 301 | + '', 'archived-ticket small-text' |
|
| 302 | + ) |
|
| 303 | + . EEH_HTML::br(), |
|
| 304 | + '', 'archived-ticket-pg' |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * setTicketMinAndMax |
|
| 312 | + * |
|
| 313 | + * @param int $remaining |
|
| 314 | + * @return void |
|
| 315 | + * @throws EE_Error |
|
| 316 | + */ |
|
| 317 | + protected function setTicketMinAndMax($remaining) |
|
| 318 | + { |
|
| 319 | + // offer the number of $tickets_remaining or $this->max_attendees, whichever is smaller |
|
| 320 | + $this->max = min($remaining, $this->max_attendees); |
|
| 321 | + // but... we also want to restrict the number of tickets by the ticket max setting, |
|
| 322 | + // however, the max still can't be higher than what was just set above |
|
| 323 | + $this->max = $this->ticket->max() > 0 |
|
| 324 | + ? min($this->ticket->max(), $this->max) |
|
| 325 | + : $this->max; |
|
| 326 | + // and we also want to restrict the minimum number of tickets by the ticket min setting |
|
| 327 | + $this->min = $this->ticket->min() > 0 |
|
| 328 | + ? $this->ticket->min() |
|
| 329 | + : 0; |
|
| 330 | + // and if the ticket is required, then make sure that min qty is at least 1 |
|
| 331 | + $this->min = $this->ticket->required() |
|
| 332 | + ? max($this->min, 1) |
|
| 333 | + : $this->min; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Allow plugins to hook in and abort the generation and display of this row to do |
|
| 339 | + * something elseif they want. |
|
| 340 | + * For an addon to abort things, all they have to do is register a filter with this hook, and |
|
| 341 | + * return a value that is NOT false. Whatever is returned gets echoed instead of the |
|
| 342 | + * current row. |
|
| 343 | + * |
|
| 344 | + * @return string|bool |
|
| 345 | + */ |
|
| 346 | + protected function getFilteredRowHtml() { |
|
| 347 | + return apply_filters( |
|
| 348 | + 'FHEE__ticket_selector_chart_template__do_ticket_entire_row', |
|
| 349 | + false, |
|
| 350 | + $this->ticket, |
|
| 351 | + $this->max, |
|
| 352 | + $this->min, |
|
| 353 | + $this->required_ticket_sold_out, |
|
| 354 | + $this->ticket_price, |
|
| 355 | + $this->ticket_bundle, |
|
| 356 | + $this->ticket_status_html, |
|
| 357 | + $this->status_class, |
|
| 358 | + $this |
|
| 359 | + ); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Allow plugins to hook in and abort the generation and display of the contents of this |
|
| 366 | + * row to do something elseif they want. |
|
| 367 | + * For an addon to abort things, all they have to do is register a filter with this hook, and |
|
| 368 | + * return a value that is NOT false. Whatever is returned gets echoed instead of the |
|
| 369 | + * current row. |
|
| 370 | + * |
|
| 371 | + * @return string|bool |
|
| 372 | + */ |
|
| 373 | + protected function getFilteredRowContents() |
|
| 374 | + { |
|
| 375 | + return apply_filters( |
|
| 376 | + 'FHEE__ticket_selector_chart_template__do_ticket_inside_row', |
|
| 377 | + false, |
|
| 378 | + $this->ticket, |
|
| 379 | + $this->max, |
|
| 380 | + $this->min, |
|
| 381 | + $this->required_ticket_sold_out, |
|
| 382 | + $this->ticket_price, |
|
| 383 | + $this->ticket_bundle, |
|
| 384 | + $this->ticket_status_html, |
|
| 385 | + $this->status_class, |
|
| 386 | + $this |
|
| 387 | + ); |
|
| 388 | + } |
|
| 389 | 389 | |
| 390 | 390 | } |
| 391 | 391 | // End of file TicketSelectorRow.php |
@@ -12,13 +12,13 @@ discard block |
||
| 12 | 12 | <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/> |
| 13 | 13 | <?php |
| 14 | 14 | if ( $ticket instanceof EE_Ticket ) { |
| 15 | - do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); |
|
| 16 | - $ticket_description .= ! empty( $ticket_description ) |
|
| 17 | - ? '<br />' . $ticket_status_display |
|
| 18 | - : $ticket_status_display; |
|
| 19 | - if (strpos( $ticket_description, '<div' ) === false) { |
|
| 20 | - $ticket_description = "<p>{$ticket_description}</p>"; |
|
| 21 | - } |
|
| 15 | + do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); |
|
| 16 | + $ticket_description .= ! empty( $ticket_description ) |
|
| 17 | + ? '<br />' . $ticket_status_display |
|
| 18 | + : $ticket_status_display; |
|
| 19 | + if (strpos( $ticket_description, '<div' ) === false) { |
|
| 20 | + $ticket_description = "<p>{$ticket_description}</p>"; |
|
| 21 | + } |
|
| 22 | 22 | ?> |
| 23 | 23 | <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv"> |
| 24 | 24 | <div class="no-tkt-slctr-ticket-content-dv"> |
@@ -28,6 +28,6 @@ discard block |
||
| 28 | 28 | <?php } ?> |
| 29 | 29 | </div><!-- .no-tkt-slctr-ticket-content-dv --> |
| 30 | 30 | <?php |
| 31 | - do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
| 31 | + do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
| 32 | 32 | } |
| 33 | 33 | ?> |
@@ -11,23 +11,23 @@ |
||
| 11 | 11 | <input type="hidden" name="tkt-slctr-qty-<?php echo $EVT_ID; ?>[]" value="1"/> |
| 12 | 12 | <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/> |
| 13 | 13 | <?php |
| 14 | -if ( $ticket instanceof EE_Ticket ) { |
|
| 15 | - do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); |
|
| 16 | - $ticket_description .= ! empty( $ticket_description ) |
|
| 17 | - ? '<br />' . $ticket_status_display |
|
| 14 | +if ($ticket instanceof EE_Ticket) { |
|
| 15 | + do_action('AHEE__ticket_selector_chart__template__before_ticket_selector', $event); |
|
| 16 | + $ticket_description .= ! empty($ticket_description) |
|
| 17 | + ? '<br />'.$ticket_status_display |
|
| 18 | 18 | : $ticket_status_display; |
| 19 | - if (strpos( $ticket_description, '<div' ) === false) { |
|
| 19 | + if (strpos($ticket_description, '<div') === false) { |
|
| 20 | 20 | $ticket_description = "<p>{$ticket_description}</p>"; |
| 21 | 21 | } |
| 22 | 22 | ?> |
| 23 | 23 | <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv"> |
| 24 | 24 | <div class="no-tkt-slctr-ticket-content-dv"> |
| 25 | 25 | <h5><?php echo $ticket->name(); ?></h5> |
| 26 | - <?php if ( ! empty( $ticket_description ) ) { ?> |
|
| 26 | + <?php if ( ! empty($ticket_description)) { ?> |
|
| 27 | 27 | <?php echo $ticket_description; ?> |
| 28 | 28 | <?php } ?> |
| 29 | 29 | </div><!-- .no-tkt-slctr-ticket-content-dv --> |
| 30 | 30 | <?php |
| 31 | - do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
| 31 | + do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event); |
|
| 32 | 32 | } |
| 33 | 33 | ?> |