@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | protected static function _set_hooks_for_changes() |
125 | 125 | { |
126 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api/changes'), false); |
|
126 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api/changes'), false); |
|
127 | 127 | foreach ($folder_contents as $classname_in_namespace => $filepath) { |
128 | 128 | // ignore the base parent class |
129 | 129 | // and legacy named classes |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | ) { |
134 | 134 | continue; |
135 | 135 | } |
136 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
136 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace; |
|
137 | 137 | if (class_exists($full_classname)) { |
138 | 138 | $instance_of_class = new $full_classname(); |
139 | 139 | if ($instance_of_class instanceof ChangesInBase) { |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * } |
179 | 179 | */ |
180 | 180 | // skip route options |
181 | - if (! is_numeric($endpoint_key)) { |
|
181 | + if ( ! is_numeric($endpoint_key)) { |
|
182 | 182 | continue; |
183 | 183 | } |
184 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
184 | + if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
185 | 185 | throw new EE_Error( |
186 | 186 | esc_html__( |
187 | 187 | // @codingStandardsIgnoreStart |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | } |
203 | 203 | if (isset($data_for_single_endpoint['callback_args'])) { |
204 | 204 | $callback_args = $data_for_single_endpoint['callback_args']; |
205 | - $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
205 | + $single_endpoint_args['callback'] = function(\WP_REST_Request $request) use ( |
|
206 | 206 | $callback, |
207 | 207 | $callback_args |
208 | 208 | ) { |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | // the REST API will issue a _doing_it_wrong notice. |
220 | 220 | // Since the EE REST API defers capabilities to the db model system, |
221 | 221 | // we will just use the generic WP callback for public endpoints |
222 | - if (! isset($single_endpoint_args['permission_callback'])) { |
|
222 | + if ( ! isset($single_endpoint_args['permission_callback'])) { |
|
223 | 223 | $single_endpoint_args['permission_callback'] = '__return_true'; |
224 | 224 | } |
225 | 225 | $multiple_endpoint_args[] = $single_endpoint_args; |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $schema_route_data = $data_for_multiple_endpoints['schema']; |
229 | 229 | $schema_callback = $schema_route_data['schema_callback']; |
230 | 230 | $callback_args = $schema_route_data['callback_args']; |
231 | - $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) { |
|
231 | + $multiple_endpoint_args['schema'] = function() use ($schema_callback, $callback_args) { |
|
232 | 232 | return call_user_func_array( |
233 | 233 | $schema_callback, |
234 | 234 | $callback_args |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | { |
271 | 271 | // delete the saved EE REST API routes |
272 | 272 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
273 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
273 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | { |
290 | 290 | $ee_routes = array(); |
291 | 291 | foreach (self::versions_served() as $version => $hidden_endpoints) { |
292 | - $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version( |
|
292 | + $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version( |
|
293 | 293 | $version, |
294 | 294 | $hidden_endpoints |
295 | 295 | ); |
@@ -309,8 +309,8 @@ discard block |
||
309 | 309 | */ |
310 | 310 | protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
311 | 311 | { |
312 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
313 | - if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
312 | + $ee_routes = get_option(self::saved_routes_option_names.$version, null); |
|
313 | + if ( ! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
314 | 314 | $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
315 | 315 | } |
316 | 316 | return $ee_routes; |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
338 | 338 | ) |
339 | 339 | ); |
340 | - $option_name = self::saved_routes_option_names . $version; |
|
340 | + $option_name = self::saved_routes_option_names.$version; |
|
341 | 341 | if (get_option($option_name)) { |
342 | 342 | update_option($option_name, $routes, true); |
343 | 343 | } else { |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | { |
383 | 383 | $model_routes = array(); |
384 | 384 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
385 | - $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
386 | - . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
385 | + $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
386 | + . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
387 | 387 | } |
388 | 388 | return $model_routes; |
389 | 389 | } |
@@ -452,13 +452,13 @@ discard block |
||
452 | 452 | foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
453 | 453 | $model = \EE_Registry::instance()->load_model($model_name); |
454 | 454 | // if this isn't a valid model then let's skip iterate to the next item in the loop. |
455 | - if (! $model instanceof EEM_Base) { |
|
455 | + if ( ! $model instanceof EEM_Base) { |
|
456 | 456 | continue; |
457 | 457 | } |
458 | 458 | // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
459 | 459 | $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
460 | 460 | $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
461 | - $model_routes[ $plural_model_route ] = array( |
|
461 | + $model_routes[$plural_model_route] = array( |
|
462 | 462 | array( |
463 | 463 | 'callback' => array( |
464 | 464 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | 'hidden_endpoint' => $hidden_endpoint, |
470 | 470 | 'args' => $this->_get_read_query_params($model, $version), |
471 | 471 | '_links' => array( |
472 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
472 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route), |
|
473 | 473 | ), |
474 | 474 | ), |
475 | 475 | 'schema' => array( |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | 'callback_args' => array($version, $model_name), |
481 | 481 | ), |
482 | 482 | ); |
483 | - $model_routes[ $singular_model_route ] = array( |
|
483 | + $model_routes[$singular_model_route] = array( |
|
484 | 484 | array( |
485 | 485 | 'callback' => array( |
486 | 486 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | $model |
500 | 500 | ) |
501 | 501 | ) { |
502 | - $model_routes[ $plural_model_route ][] = array( |
|
502 | + $model_routes[$plural_model_route][] = array( |
|
503 | 503 | 'callback' => array( |
504 | 504 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
505 | 505 | 'handleRequestInsert', |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | 'hidden_endpoint' => $hidden_endpoint, |
510 | 510 | 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
511 | 511 | ); |
512 | - $model_routes[ $singular_model_route ] = array_merge( |
|
513 | - $model_routes[ $singular_model_route ], |
|
512 | + $model_routes[$singular_model_route] = array_merge( |
|
513 | + $model_routes[$singular_model_route], |
|
514 | 514 | array( |
515 | 515 | array( |
516 | 516 | 'callback' => array( |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | '(?P<id>[^\/]+)', |
542 | 542 | $relation_obj |
543 | 543 | ); |
544 | - $model_routes[ $related_route ] = array( |
|
544 | + $model_routes[$related_route] = array( |
|
545 | 545 | array( |
546 | 546 | 'callback' => array( |
547 | 547 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -554,8 +554,8 @@ discard block |
||
554 | 554 | ), |
555 | 555 | ); |
556 | 556 | |
557 | - $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
558 | - $model_routes[ $related_write_route ] = array( |
|
557 | + $related_write_route = $related_route.'/'.'(?P<related_id>[^\/]+)'; |
|
558 | + $model_routes[$related_write_route] = array( |
|
559 | 559 | array( |
560 | 560 | 'callback' => array( |
561 | 561 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | */ |
609 | 609 | public static function get_entity_route($model, $id) |
610 | 610 | { |
611 | - return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
611 | + return EED_Core_Rest_Api::get_collection_route($model).'/'.$id; |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | $relation_obj->get_other_model()->get_this_model_name(), |
629 | 629 | $relation_obj |
630 | 630 | ); |
631 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
631 | + return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part; |
|
632 | 632 | } |
633 | 633 | |
634 | 634 | |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | */ |
643 | 643 | public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
644 | 644 | { |
645 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
645 | + return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route; |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | { |
657 | 657 | $routes = array(); |
658 | 658 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
659 | - $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
659 | + $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version( |
|
660 | 660 | $version, |
661 | 661 | $hidden_endpoint |
662 | 662 | ); |
@@ -779,12 +779,12 @@ discard block |
||
779 | 779 | { |
780 | 780 | // if they're related through a HABTM relation, check for any non-FKs |
781 | 781 | $all_relation_settings = $source_model->relation_settings(); |
782 | - $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
782 | + $relation_settings = $all_relation_settings[$related_model->get_this_model_name()]; |
|
783 | 783 | $params = array(); |
784 | 784 | if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
785 | 785 | foreach ($relation_settings->getNonKeyFields() as $field) { |
786 | 786 | /* @var $field EE_Model_Field_Base */ |
787 | - $params[ $field->get_name() ] = array( |
|
787 | + $params[$field->get_name()] = array( |
|
788 | 788 | 'required' => ! $field->is_nullable(), |
789 | 789 | 'default' => ModelDataTranslator::prepareFieldValueForJson($field, $field->get_default_value(), $version), |
790 | 790 | 'type' => $field->getSchemaType(), |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | { |
810 | 810 | $default_orderby = array(); |
811 | 811 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
812 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
812 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
813 | 813 | } |
814 | 814 | return array_merge( |
815 | 815 | $this->_get_response_selection_query_params($model, $version), |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | 'type' => array( |
844 | 844 | 'object', |
845 | 845 | 'string', |
846 | - ),// because we accept a variety of types, WP core validation and sanitization |
|
846 | + ), // because we accept a variety of types, WP core validation and sanitization |
|
847 | 847 | // freaks out. We'll just validate this argument while handling the request |
848 | 848 | 'validate_callback' => null, |
849 | 849 | 'sanitize_callback' => null, |
@@ -942,7 +942,7 @@ discard block |
||
942 | 942 | $sanitize_callback = null; |
943 | 943 | } |
944 | 944 | $arg_info['sanitize_callback'] = $sanitize_callback; |
945 | - $args_info[ $field_name ] = $arg_info; |
|
945 | + $args_info[$field_name] = $arg_info; |
|
946 | 946 | if ($field_obj instanceof EE_Datetime_Field) { |
947 | 947 | $gmt_arg_info = $arg_info; |
948 | 948 | $gmt_arg_info['description'] = sprintf( |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | $field_obj->get_nicename(), |
954 | 954 | $field_name |
955 | 955 | ); |
956 | - $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
956 | + $args_info[$field_name.'_gmt'] = $gmt_arg_info; |
|
957 | 957 | } |
958 | 958 | } |
959 | 959 | return $args_info; |
@@ -977,18 +977,18 @@ discard block |
||
977 | 977 | { |
978 | 978 | $attributes = $request->get_attributes(); |
979 | 979 | if ( |
980 | - ! isset($attributes['args'][ $param ]) |
|
981 | - || ! is_array($attributes['args'][ $param ]) |
|
980 | + ! isset($attributes['args'][$param]) |
|
981 | + || ! is_array($attributes['args'][$param]) |
|
982 | 982 | ) { |
983 | 983 | $validation_result = true; |
984 | 984 | } else { |
985 | - $args = $attributes['args'][ $param ]; |
|
985 | + $args = $attributes['args'][$param]; |
|
986 | 986 | if ( |
987 | 987 | ( |
988 | 988 | $value === '' |
989 | 989 | || $value === null |
990 | 990 | ) |
991 | - && (! isset($args['required']) |
|
991 | + && ( ! isset($args['required']) |
|
992 | 992 | || $args['required'] === false |
993 | 993 | ) |
994 | 994 | ) { |
@@ -999,7 +999,7 @@ discard block |
||
999 | 999 | && $args['format'] === 'email' |
1000 | 1000 | ) { |
1001 | 1001 | $validation_result = true; |
1002 | - if (! self::_validate_email($value)) { |
|
1002 | + if ( ! self::_validate_email($value)) { |
|
1003 | 1003 | $validation_result = new WP_Error( |
1004 | 1004 | 'rest_invalid_param', |
1005 | 1005 | esc_html__( |
@@ -1049,7 +1049,7 @@ discard block |
||
1049 | 1049 | { |
1050 | 1050 | $config_routes = array(); |
1051 | 1051 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
1052 | - $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
1052 | + $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version( |
|
1053 | 1053 | $version, |
1054 | 1054 | $hidden_endpoint |
1055 | 1055 | ); |
@@ -1104,7 +1104,7 @@ discard block |
||
1104 | 1104 | { |
1105 | 1105 | $meta_routes = array(); |
1106 | 1106 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
1107 | - $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
1107 | + $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version( |
|
1108 | 1108 | $version, |
1109 | 1109 | $hidden_endpoint |
1110 | 1110 | ); |
@@ -1156,7 +1156,7 @@ discard block |
||
1156 | 1156 | foreach ($relative_urls as $resource_name => $endpoints) { |
1157 | 1157 | foreach ($endpoints as $key => $endpoint) { |
1158 | 1158 | // skip schema and other route options |
1159 | - if (! is_numeric($key)) { |
|
1159 | + if ( ! is_numeric($key)) { |
|
1160 | 1160 | continue; |
1161 | 1161 | } |
1162 | 1162 | // by default, hide "hidden_endpoint"s, unless the request indicates |
@@ -1166,9 +1166,9 @@ discard block |
||
1166 | 1166 | ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
1167 | 1167 | || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
1168 | 1168 | ) { |
1169 | - $full_route = '/' . ltrim($namespace, '/'); |
|
1170 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
1171 | - unset($route_data[ $full_route ]); |
|
1169 | + $full_route = '/'.ltrim($namespace, '/'); |
|
1170 | + $full_route .= '/'.ltrim($resource_name, '/'); |
|
1171 | + unset($route_data[$full_route]); |
|
1172 | 1172 | } |
1173 | 1173 | } |
1174 | 1174 | } |
@@ -1242,13 +1242,13 @@ discard block |
||
1242 | 1242 | |
1243 | 1243 | if ($key_versioned_endpoint === $latest_version) { |
1244 | 1244 | // don't hide the latest version in the index |
1245 | - $versions_served[ $key_versioned_endpoint ] = false; |
|
1245 | + $versions_served[$key_versioned_endpoint] = false; |
|
1246 | 1246 | } elseif ( |
1247 | 1247 | version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
1248 | 1248 | && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
1249 | 1249 | ) { |
1250 | 1250 | // include, but hide, previous versions which are still supported |
1251 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1251 | + $versions_served[$key_versioned_endpoint] = true; |
|
1252 | 1252 | } elseif ( |
1253 | 1253 | apply_filters( |
1254 | 1254 | 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
@@ -1257,7 +1257,7 @@ discard block |
||
1257 | 1257 | ) |
1258 | 1258 | ) { |
1259 | 1259 | // if a version is no longer supported, don't include it in index or list of versions served |
1260 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1260 | + $versions_served[$key_versioned_endpoint] = true; |
|
1261 | 1261 | } |
1262 | 1262 | } |
1263 | 1263 | return $versions_served; |
@@ -1315,7 +1315,7 @@ discard block |
||
1315 | 1315 | $model_names = self::model_names_with_plural_routes($version); |
1316 | 1316 | $collection_routes = array(); |
1317 | 1317 | foreach ($model_names as $model_name => $model_class_name) { |
1318 | - $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/' |
|
1318 | + $collection_routes[strtolower($model_name)] = '/'.self::ee_api_namespace.$version.'/' |
|
1319 | 1319 | . EEH_Inflector::pluralize_and_lower($model_name); |
1320 | 1320 | } |
1321 | 1321 | return $collection_routes; |
@@ -1336,9 +1336,9 @@ discard block |
||
1336 | 1336 | $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
1337 | 1337 | foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
1338 | 1338 | if (count($primary_keys) > 1) { |
1339 | - $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
1339 | + $primary_key_items[strtolower($model_name)][] = $primary_key_name; |
|
1340 | 1340 | } else { |
1341 | - $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
1341 | + $primary_key_items[strtolower($model_name)] = $primary_key_name; |
|
1342 | 1342 | } |
1343 | 1343 | } |
1344 | 1344 | } |
@@ -22,1352 +22,1352 @@ |
||
22 | 22 | */ |
23 | 23 | class EED_Core_Rest_Api extends \EED_Module |
24 | 24 | { |
25 | - const ee_api_namespace = Domain::API_NAMESPACE; |
|
26 | - |
|
27 | - const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
28 | - |
|
29 | - const saved_routes_option_names = 'ee_core_routes'; |
|
30 | - |
|
31 | - /** |
|
32 | - * string used in _links response bodies to make them globally unique. |
|
33 | - * |
|
34 | - * @see http://v2.wp-api.org/extending/linking/ |
|
35 | - */ |
|
36 | - const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var CalculatedModelFields |
|
40 | - */ |
|
41 | - protected static $_field_calculator; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @return EED_Core_Rest_Api|EED_Module |
|
46 | - */ |
|
47 | - public static function instance() |
|
48 | - { |
|
49 | - self::$_field_calculator = LoaderFactory::getLoader()->load('EventEspresso\core\libraries\rest_api\CalculatedModelFields'); |
|
50 | - return parent::get_instance(__CLASS__); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
56 | - * |
|
57 | - * @access public |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public static function set_hooks() |
|
61 | - { |
|
62 | - self::set_hooks_both(); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
68 | - * |
|
69 | - * @access public |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public static function set_hooks_admin() |
|
73 | - { |
|
74 | - self::set_hooks_both(); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - public static function set_hooks_both() |
|
79 | - { |
|
80 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
81 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
82 | - add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
83 | - add_filter( |
|
84 | - 'rest_index', |
|
85 | - array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex') |
|
86 | - ); |
|
87 | - EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * sets up hooks which only need to be included as part of REST API requests; |
|
93 | - * other requests like to the frontend or admin etc don't need them |
|
94 | - * |
|
95 | - * @throws \EE_Error |
|
96 | - */ |
|
97 | - public static function set_hooks_rest_api() |
|
98 | - { |
|
99 | - // set hooks which account for changes made to the API |
|
100 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * public wrapper of _set_hooks_for_changes. |
|
106 | - * Loads all the hooks which make requests to old versions of the API |
|
107 | - * appear the same as they always did |
|
108 | - * |
|
109 | - * @throws EE_Error |
|
110 | - */ |
|
111 | - public static function set_hooks_for_changes() |
|
112 | - { |
|
113 | - self::_set_hooks_for_changes(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * Loads all the hooks which make requests to old versions of the API |
|
119 | - * appear the same as they always did |
|
120 | - * |
|
121 | - * @throws EE_Error |
|
122 | - */ |
|
123 | - protected static function _set_hooks_for_changes() |
|
124 | - { |
|
125 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api/changes'), false); |
|
126 | - foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
127 | - // ignore the base parent class |
|
128 | - // and legacy named classes |
|
129 | - if ( |
|
130 | - $classname_in_namespace === 'ChangesInBase' |
|
131 | - || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
132 | - ) { |
|
133 | - continue; |
|
134 | - } |
|
135 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
136 | - if (class_exists($full_classname)) { |
|
137 | - $instance_of_class = new $full_classname(); |
|
138 | - if ($instance_of_class instanceof ChangesInBase) { |
|
139 | - $instance_of_class->setHooks(); |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
148 | - * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
149 | - * |
|
150 | - * @throws \EE_Error |
|
151 | - */ |
|
152 | - public static function register_routes() |
|
153 | - { |
|
154 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
155 | - foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
156 | - /** |
|
157 | - * @var array $data_for_multiple_endpoints numerically indexed array |
|
158 | - * but can also contain route options like { |
|
159 | - * @type array $schema { |
|
160 | - * @type callable $schema_callback |
|
161 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
162 | - * WP_REST_Request of course |
|
163 | - * } |
|
164 | - * } |
|
165 | - */ |
|
166 | - // when registering routes, register all the endpoints' data at the same time |
|
167 | - $multiple_endpoint_args = array(); |
|
168 | - foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
169 | - /** |
|
170 | - * @var array $data_for_single_endpoint { |
|
171 | - * @type callable $callback |
|
172 | - * @type string methods |
|
173 | - * @type array args |
|
174 | - * @type array _links |
|
175 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
176 | - * WP_REST_Request of course |
|
177 | - * } |
|
178 | - */ |
|
179 | - // skip route options |
|
180 | - if (! is_numeric($endpoint_key)) { |
|
181 | - continue; |
|
182 | - } |
|
183 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
184 | - throw new EE_Error( |
|
185 | - esc_html__( |
|
186 | - // @codingStandardsIgnoreStart |
|
187 | - 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
188 | - // @codingStandardsIgnoreEnd |
|
189 | - 'event_espresso' |
|
190 | - ) |
|
191 | - ); |
|
192 | - } |
|
193 | - $callback = $data_for_single_endpoint['callback']; |
|
194 | - $single_endpoint_args = array( |
|
195 | - 'methods' => $data_for_single_endpoint['methods'], |
|
196 | - 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
197 | - : array(), |
|
198 | - ); |
|
199 | - if (isset($data_for_single_endpoint['_links'])) { |
|
200 | - $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
201 | - } |
|
202 | - if (isset($data_for_single_endpoint['callback_args'])) { |
|
203 | - $callback_args = $data_for_single_endpoint['callback_args']; |
|
204 | - $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
205 | - $callback, |
|
206 | - $callback_args |
|
207 | - ) { |
|
208 | - array_unshift($callback_args, $request); |
|
209 | - return call_user_func_array( |
|
210 | - $callback, |
|
211 | - $callback_args |
|
212 | - ); |
|
213 | - }; |
|
214 | - } else { |
|
215 | - $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
216 | - } |
|
217 | - // As of WordPress 5.5, if a permission_callback is not provided, |
|
218 | - // the REST API will issue a _doing_it_wrong notice. |
|
219 | - // Since the EE REST API defers capabilities to the db model system, |
|
220 | - // we will just use the generic WP callback for public endpoints |
|
221 | - if (! isset($single_endpoint_args['permission_callback'])) { |
|
222 | - $single_endpoint_args['permission_callback'] = '__return_true'; |
|
223 | - } |
|
224 | - $multiple_endpoint_args[] = $single_endpoint_args; |
|
225 | - } |
|
226 | - if (isset($data_for_multiple_endpoints['schema'])) { |
|
227 | - $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
228 | - $schema_callback = $schema_route_data['schema_callback']; |
|
229 | - $callback_args = $schema_route_data['callback_args']; |
|
230 | - $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) { |
|
231 | - return call_user_func_array( |
|
232 | - $schema_callback, |
|
233 | - $callback_args |
|
234 | - ); |
|
235 | - }; |
|
236 | - } |
|
237 | - register_rest_route( |
|
238 | - $namespace, |
|
239 | - $relative_route, |
|
240 | - $multiple_endpoint_args |
|
241 | - ); |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Checks if there was a version change or something that merits invalidating the cached |
|
249 | - * route data. If so, invalidates the cached route data so that it gets refreshed |
|
250 | - * next time the WP API is used |
|
251 | - */ |
|
252 | - public static function invalidate_cached_route_data_on_version_change() |
|
253 | - { |
|
254 | - if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
255 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
256 | - } |
|
257 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
258 | - if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
259 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
260 | - } |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * Removes the cached route data so it will get refreshed next time the WP API is used |
|
267 | - */ |
|
268 | - public static function invalidate_cached_route_data() |
|
269 | - { |
|
270 | - // delete the saved EE REST API routes |
|
271 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
272 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * Gets the EE route data |
|
279 | - * |
|
280 | - * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
281 | - * @throws \EE_Error |
|
282 | - * @type string|array $callback |
|
283 | - * @type string $methods |
|
284 | - * @type boolean $hidden_endpoint |
|
285 | - * } |
|
286 | - */ |
|
287 | - public static function get_ee_route_data() |
|
288 | - { |
|
289 | - $ee_routes = array(); |
|
290 | - foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
291 | - $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version( |
|
292 | - $version, |
|
293 | - $hidden_endpoints |
|
294 | - ); |
|
295 | - } |
|
296 | - return $ee_routes; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * Gets the EE route data from the wp options if it exists already, |
|
302 | - * otherwise re-generates it and saves it to the option |
|
303 | - * |
|
304 | - * @param string $version |
|
305 | - * @param boolean $hidden_endpoints |
|
306 | - * @return array |
|
307 | - * @throws \EE_Error |
|
308 | - */ |
|
309 | - protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
310 | - { |
|
311 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
312 | - if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
313 | - $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
314 | - } |
|
315 | - return $ee_routes; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * Saves the EE REST API route data to a wp option and returns it |
|
321 | - * |
|
322 | - * @param string $version |
|
323 | - * @param boolean $hidden_endpoints |
|
324 | - * @return mixed|null |
|
325 | - * @throws \EE_Error |
|
326 | - */ |
|
327 | - protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
328 | - { |
|
329 | - $instance = self::instance(); |
|
330 | - $routes = apply_filters( |
|
331 | - 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
332 | - array_replace_recursive( |
|
333 | - $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
334 | - $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
335 | - $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
336 | - $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
337 | - ) |
|
338 | - ); |
|
339 | - $option_name = self::saved_routes_option_names . $version; |
|
340 | - if (get_option($option_name)) { |
|
341 | - update_option($option_name, $routes, true); |
|
342 | - } else { |
|
343 | - add_option($option_name, $routes, null, 'no'); |
|
344 | - } |
|
345 | - return $routes; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
351 | - * need to calculate it on every request |
|
352 | - * |
|
353 | - * @deprecated since version 4.9.1 |
|
354 | - * @return void |
|
355 | - */ |
|
356 | - public static function save_ee_routes() |
|
357 | - { |
|
358 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
359 | - $instance = self::instance(); |
|
360 | - $routes = apply_filters( |
|
361 | - 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
362 | - array_replace_recursive( |
|
363 | - $instance->_register_config_routes(), |
|
364 | - $instance->_register_meta_routes(), |
|
365 | - $instance->_register_model_routes(), |
|
366 | - $instance->_register_rpc_routes() |
|
367 | - ) |
|
368 | - ); |
|
369 | - update_option(self::saved_routes_option_names, $routes, true); |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * Gets all the route information relating to EE models |
|
376 | - * |
|
377 | - * @return array @see get_ee_route_data |
|
378 | - * @deprecated since version 4.9.1 |
|
379 | - */ |
|
380 | - protected function _register_model_routes() |
|
381 | - { |
|
382 | - $model_routes = array(); |
|
383 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
384 | - $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
385 | - . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
386 | - } |
|
387 | - return $model_routes; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Decides whether or not to add write endpoints for this model. |
|
393 | - * |
|
394 | - * Currently, this defaults to exclude all global tables and models |
|
395 | - * which would allow inserting WP core data (we don't want to duplicate |
|
396 | - * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
397 | - * |
|
398 | - * @param EEM_Base $model |
|
399 | - * @return bool |
|
400 | - */ |
|
401 | - public static function should_have_write_endpoints(EEM_Base $model) |
|
402 | - { |
|
403 | - if ($model->is_wp_core_model()) { |
|
404 | - return false; |
|
405 | - } |
|
406 | - foreach ($model->get_tables() as $table) { |
|
407 | - if ($table->is_global()) { |
|
408 | - return false; |
|
409 | - } |
|
410 | - } |
|
411 | - return true; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
417 | - * in this versioned namespace of EE4 |
|
418 | - * |
|
419 | - * @param $version |
|
420 | - * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
421 | - */ |
|
422 | - public static function model_names_with_plural_routes($version) |
|
423 | - { |
|
424 | - $model_version_info = new ModelVersionInfo($version); |
|
425 | - $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
426 | - // let's not bother having endpoints for extra metas |
|
427 | - unset( |
|
428 | - $models_to_register['Extra_Meta'], |
|
429 | - $models_to_register['Extra_Join'], |
|
430 | - $models_to_register['Post_Meta'] |
|
431 | - ); |
|
432 | - return apply_filters( |
|
433 | - 'FHEE__EED_Core_REST_API___register_model_routes', |
|
434 | - $models_to_register |
|
435 | - ); |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * Gets the route data for EE models in the specified version |
|
441 | - * |
|
442 | - * @param string $version |
|
443 | - * @param boolean $hidden_endpoint |
|
444 | - * @return array |
|
445 | - * @throws EE_Error |
|
446 | - */ |
|
447 | - protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
448 | - { |
|
449 | - $model_routes = array(); |
|
450 | - $model_version_info = new ModelVersionInfo($version); |
|
451 | - foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
452 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
453 | - // if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
454 | - if (! $model instanceof EEM_Base) { |
|
455 | - continue; |
|
456 | - } |
|
457 | - // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
458 | - $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
459 | - $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
460 | - $model_routes[ $plural_model_route ] = array( |
|
461 | - array( |
|
462 | - 'callback' => array( |
|
463 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
464 | - 'handleRequestGetAll', |
|
465 | - ), |
|
466 | - 'callback_args' => array($version, $model_name), |
|
467 | - 'methods' => WP_REST_Server::READABLE, |
|
468 | - 'hidden_endpoint' => $hidden_endpoint, |
|
469 | - 'args' => $this->_get_read_query_params($model, $version), |
|
470 | - '_links' => array( |
|
471 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
472 | - ), |
|
473 | - ), |
|
474 | - 'schema' => array( |
|
475 | - 'schema_callback' => array( |
|
476 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
477 | - 'handleSchemaRequest', |
|
478 | - ), |
|
479 | - 'callback_args' => array($version, $model_name), |
|
480 | - ), |
|
481 | - ); |
|
482 | - $model_routes[ $singular_model_route ] = array( |
|
483 | - array( |
|
484 | - 'callback' => array( |
|
485 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
486 | - 'handleRequestGetOne', |
|
487 | - ), |
|
488 | - 'callback_args' => array($version, $model_name), |
|
489 | - 'methods' => WP_REST_Server::READABLE, |
|
490 | - 'hidden_endpoint' => $hidden_endpoint, |
|
491 | - 'args' => $this->_get_response_selection_query_params($model, $version, true), |
|
492 | - ), |
|
493 | - ); |
|
494 | - if ( |
|
495 | - apply_filters( |
|
496 | - 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
497 | - EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
498 | - $model |
|
499 | - ) |
|
500 | - ) { |
|
501 | - $model_routes[ $plural_model_route ][] = array( |
|
502 | - 'callback' => array( |
|
503 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
504 | - 'handleRequestInsert', |
|
505 | - ), |
|
506 | - 'callback_args' => array($version, $model_name), |
|
507 | - 'methods' => WP_REST_Server::CREATABLE, |
|
508 | - 'hidden_endpoint' => $hidden_endpoint, |
|
509 | - 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
510 | - ); |
|
511 | - $model_routes[ $singular_model_route ] = array_merge( |
|
512 | - $model_routes[ $singular_model_route ], |
|
513 | - array( |
|
514 | - array( |
|
515 | - 'callback' => array( |
|
516 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
517 | - 'handleRequestUpdate', |
|
518 | - ), |
|
519 | - 'callback_args' => array($version, $model_name), |
|
520 | - 'methods' => WP_REST_Server::EDITABLE, |
|
521 | - 'hidden_endpoint' => $hidden_endpoint, |
|
522 | - 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
523 | - ), |
|
524 | - array( |
|
525 | - 'callback' => array( |
|
526 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
527 | - 'handleRequestDelete', |
|
528 | - ), |
|
529 | - 'callback_args' => array($version, $model_name), |
|
530 | - 'methods' => WP_REST_Server::DELETABLE, |
|
531 | - 'hidden_endpoint' => $hidden_endpoint, |
|
532 | - 'args' => $this->_get_delete_query_params($model, $version), |
|
533 | - ), |
|
534 | - ) |
|
535 | - ); |
|
536 | - } |
|
537 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
538 | - $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
539 | - $model, |
|
540 | - '(?P<id>[^\/]+)', |
|
541 | - $relation_obj |
|
542 | - ); |
|
543 | - $model_routes[ $related_route ] = array( |
|
544 | - array( |
|
545 | - 'callback' => array( |
|
546 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
547 | - 'handleRequestGetRelated', |
|
548 | - ), |
|
549 | - 'callback_args' => array($version, $model_name, $relation_name), |
|
550 | - 'methods' => WP_REST_Server::READABLE, |
|
551 | - 'hidden_endpoint' => $hidden_endpoint, |
|
552 | - 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
553 | - ), |
|
554 | - ); |
|
555 | - |
|
556 | - $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
557 | - $model_routes[ $related_write_route ] = array( |
|
558 | - array( |
|
559 | - 'callback' => array( |
|
560 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
561 | - 'handleRequestAddRelation', |
|
562 | - ), |
|
563 | - 'callback_args' => array($version, $model_name, $relation_name), |
|
564 | - 'methods' => WP_REST_Server::EDITABLE, |
|
565 | - 'hidden_endpoint' => $hidden_endpoint, |
|
566 | - 'args' => $this->_get_add_relation_query_params($model, $relation_obj->get_other_model(), $version) |
|
567 | - ), |
|
568 | - array( |
|
569 | - 'callback' => array( |
|
570 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
571 | - 'handleRequestRemoveRelation', |
|
572 | - ), |
|
573 | - 'callback_args' => array($version, $model_name, $relation_name), |
|
574 | - 'methods' => WP_REST_Server::DELETABLE, |
|
575 | - 'hidden_endpoint' => $hidden_endpoint, |
|
576 | - 'args' => array() |
|
577 | - ), |
|
578 | - ); |
|
579 | - } |
|
580 | - } |
|
581 | - return $model_routes; |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
587 | - * excluding the preceding slash. |
|
588 | - * Eg you pass get_plural_route_to('Event') = 'events' |
|
589 | - * |
|
590 | - * @param EEM_Base $model |
|
591 | - * @return string |
|
592 | - */ |
|
593 | - public static function get_collection_route(EEM_Base $model) |
|
594 | - { |
|
595 | - return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
601 | - * excluding the preceding slash. |
|
602 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
603 | - * |
|
604 | - * @param EEM_Base $model eg Event or Venue |
|
605 | - * @param string $id |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public static function get_entity_route($model, $id) |
|
609 | - { |
|
610 | - return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
611 | - } |
|
612 | - |
|
613 | - |
|
614 | - /** |
|
615 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
616 | - * excluding the preceding slash. |
|
617 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
618 | - * |
|
619 | - * @param EEM_Base $model eg Event or Venue |
|
620 | - * @param string $id |
|
621 | - * @param EE_Model_Relation_Base $relation_obj |
|
622 | - * @return string |
|
623 | - */ |
|
624 | - public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
625 | - { |
|
626 | - $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
627 | - $relation_obj->get_other_model()->get_this_model_name(), |
|
628 | - $relation_obj |
|
629 | - ); |
|
630 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - /** |
|
635 | - * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
636 | - * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
637 | - * |
|
638 | - * @param string $relative_route |
|
639 | - * @param string $version |
|
640 | - * @return string |
|
641 | - */ |
|
642 | - public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
|
643 | - { |
|
644 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
650 | - * routes that don't conform to the traditional REST CRUD-style). |
|
651 | - * |
|
652 | - * @deprecated since 4.9.1 |
|
653 | - */ |
|
654 | - protected function _register_rpc_routes() |
|
655 | - { |
|
656 | - $routes = array(); |
|
657 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
658 | - $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
659 | - $version, |
|
660 | - $hidden_endpoint |
|
661 | - ); |
|
662 | - } |
|
663 | - return $routes; |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * @param string $version |
|
669 | - * @param boolean $hidden_endpoint |
|
670 | - * @return array |
|
671 | - */ |
|
672 | - protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
673 | - { |
|
674 | - $this_versions_routes = array(); |
|
675 | - // checkin endpoint |
|
676 | - $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
677 | - array( |
|
678 | - 'callback' => array( |
|
679 | - 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
680 | - 'handleRequestToggleCheckin', |
|
681 | - ), |
|
682 | - 'methods' => WP_REST_Server::CREATABLE, |
|
683 | - 'hidden_endpoint' => $hidden_endpoint, |
|
684 | - 'args' => array( |
|
685 | - 'force' => array( |
|
686 | - 'required' => false, |
|
687 | - 'default' => false, |
|
688 | - 'description' => esc_html__( |
|
689 | - // @codingStandardsIgnoreStart |
|
690 | - 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
691 | - // @codingStandardsIgnoreEnd |
|
692 | - 'event_espresso' |
|
693 | - ), |
|
694 | - ), |
|
695 | - ), |
|
696 | - 'callback_args' => array($version), |
|
697 | - ), |
|
698 | - ); |
|
699 | - return apply_filters( |
|
700 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
701 | - $this_versions_routes, |
|
702 | - $version, |
|
703 | - $hidden_endpoint |
|
704 | - ); |
|
705 | - } |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * Gets the query params that can be used when request one or many |
|
710 | - * |
|
711 | - * @param EEM_Base $model |
|
712 | - * @param string $version |
|
713 | - * @return array |
|
714 | - */ |
|
715 | - protected function _get_response_selection_query_params(\EEM_Base $model, $version, $single_only = false) |
|
716 | - { |
|
717 | - $query_params = array( |
|
718 | - 'include' => array( |
|
719 | - 'required' => false, |
|
720 | - 'default' => '*', |
|
721 | - 'type' => 'string', |
|
722 | - ), |
|
723 | - 'calculate' => array( |
|
724 | - 'required' => false, |
|
725 | - 'default' => '', |
|
726 | - 'enum' => self::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
727 | - 'type' => 'string', |
|
728 | - // because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
729 | - // freaks out. We'll just validate this argument while handling the request |
|
730 | - 'validate_callback' => null, |
|
731 | - 'sanitize_callback' => null, |
|
732 | - ), |
|
733 | - 'password' => array( |
|
734 | - 'required' => false, |
|
735 | - 'default' => '', |
|
736 | - 'type' => 'string' |
|
737 | - ) |
|
738 | - ); |
|
739 | - return apply_filters( |
|
740 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
741 | - $query_params, |
|
742 | - $model, |
|
743 | - $version |
|
744 | - ); |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * Gets the parameters acceptable for delete requests |
|
750 | - * |
|
751 | - * @param \EEM_Base $model |
|
752 | - * @param string $version |
|
753 | - * @return array |
|
754 | - */ |
|
755 | - protected function _get_delete_query_params(\EEM_Base $model, $version) |
|
756 | - { |
|
757 | - $params_for_delete = array( |
|
758 | - 'allow_blocking' => array( |
|
759 | - 'required' => false, |
|
760 | - 'default' => true, |
|
761 | - 'type' => 'boolean', |
|
762 | - ), |
|
763 | - ); |
|
764 | - $params_for_delete['force'] = array( |
|
765 | - 'required' => false, |
|
766 | - 'default' => false, |
|
767 | - 'type' => 'boolean', |
|
768 | - ); |
|
769 | - return apply_filters( |
|
770 | - 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
771 | - $params_for_delete, |
|
772 | - $model, |
|
773 | - $version |
|
774 | - ); |
|
775 | - } |
|
776 | - |
|
777 | - protected function _get_add_relation_query_params(\EEM_Base $source_model, \EEM_Base $related_model, $version) |
|
778 | - { |
|
779 | - // if they're related through a HABTM relation, check for any non-FKs |
|
780 | - $all_relation_settings = $source_model->relation_settings(); |
|
781 | - $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
782 | - $params = array(); |
|
783 | - if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
|
784 | - foreach ($relation_settings->getNonKeyFields() as $field) { |
|
785 | - /* @var $field EE_Model_Field_Base */ |
|
786 | - $params[ $field->get_name() ] = array( |
|
787 | - 'required' => ! $field->is_nullable(), |
|
788 | - 'default' => ModelDataTranslator::prepareFieldValueForJson($field, $field->get_default_value(), $version), |
|
789 | - 'type' => $field->getSchemaType(), |
|
790 | - 'validate_callbaack' => null, |
|
791 | - 'sanitize_callback' => null |
|
792 | - ); |
|
793 | - } |
|
794 | - } |
|
795 | - return $params; |
|
796 | - } |
|
797 | - |
|
798 | - |
|
799 | - /** |
|
800 | - * Gets info about reading query params that are acceptable |
|
801 | - * |
|
802 | - * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
803 | - * @param string $version |
|
804 | - * @return array describing the args acceptable when querying this model |
|
805 | - * @throws EE_Error |
|
806 | - */ |
|
807 | - protected function _get_read_query_params(\EEM_Base $model, $version) |
|
808 | - { |
|
809 | - $default_orderby = array(); |
|
810 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
811 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
812 | - } |
|
813 | - return array_merge( |
|
814 | - $this->_get_response_selection_query_params($model, $version), |
|
815 | - array( |
|
816 | - 'where' => array( |
|
817 | - 'required' => false, |
|
818 | - 'default' => array(), |
|
819 | - 'type' => 'object', |
|
820 | - // because we accept an almost infinite list of possible where conditions, WP |
|
821 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
822 | - // while handling the request |
|
823 | - 'validate_callback' => null, |
|
824 | - 'sanitize_callback' => null, |
|
825 | - ), |
|
826 | - 'limit' => array( |
|
827 | - 'required' => false, |
|
828 | - 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
829 | - 'type' => array( |
|
830 | - 'array', |
|
831 | - 'string', |
|
832 | - 'integer', |
|
833 | - ), |
|
834 | - // because we accept a variety of types, WP core validation and sanitization |
|
835 | - // freaks out. We'll just validate this argument while handling the request |
|
836 | - 'validate_callback' => null, |
|
837 | - 'sanitize_callback' => null, |
|
838 | - ), |
|
839 | - 'order_by' => array( |
|
840 | - 'required' => false, |
|
841 | - 'default' => $default_orderby, |
|
842 | - 'type' => array( |
|
843 | - 'object', |
|
844 | - 'string', |
|
845 | - ),// because we accept a variety of types, WP core validation and sanitization |
|
846 | - // freaks out. We'll just validate this argument while handling the request |
|
847 | - 'validate_callback' => null, |
|
848 | - 'sanitize_callback' => null, |
|
849 | - ), |
|
850 | - 'group_by' => array( |
|
851 | - 'required' => false, |
|
852 | - 'default' => null, |
|
853 | - 'type' => array( |
|
854 | - 'object', |
|
855 | - 'string', |
|
856 | - ), |
|
857 | - // because we accept an almost infinite list of possible groupings, |
|
858 | - // WP core validation and sanitization |
|
859 | - // freaks out. We'll just validate this argument while handling the request |
|
860 | - 'validate_callback' => null, |
|
861 | - 'sanitize_callback' => null, |
|
862 | - ), |
|
863 | - 'having' => array( |
|
864 | - 'required' => false, |
|
865 | - 'default' => null, |
|
866 | - 'type' => 'object', |
|
867 | - // because we accept an almost infinite list of possible where conditions, WP |
|
868 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
869 | - // while handling the request |
|
870 | - 'validate_callback' => null, |
|
871 | - 'sanitize_callback' => null, |
|
872 | - ), |
|
873 | - 'caps' => array( |
|
874 | - 'required' => false, |
|
875 | - 'default' => EEM_Base::caps_read, |
|
876 | - 'type' => 'string', |
|
877 | - 'enum' => array( |
|
878 | - EEM_Base::caps_read, |
|
879 | - EEM_Base::caps_read_admin, |
|
880 | - EEM_Base::caps_edit, |
|
881 | - EEM_Base::caps_delete, |
|
882 | - ), |
|
883 | - ), |
|
884 | - ) |
|
885 | - ); |
|
886 | - } |
|
887 | - |
|
888 | - |
|
889 | - /** |
|
890 | - * Gets parameter information for a model regarding writing data |
|
891 | - * |
|
892 | - * @param string $model_name |
|
893 | - * @param ModelVersionInfo $model_version_info |
|
894 | - * @param boolean $create whether this is for request to create (in |
|
895 | - * which case we need all required params) or |
|
896 | - * just to update (in which case we don't |
|
897 | - * need those on every request) |
|
898 | - * @return array |
|
899 | - */ |
|
900 | - protected function _get_write_params( |
|
901 | - $model_name, |
|
902 | - ModelVersionInfo $model_version_info, |
|
903 | - $create = false |
|
904 | - ) { |
|
905 | - $model = EE_Registry::instance()->load_model($model_name); |
|
906 | - $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
907 | - $args_info = array(); |
|
908 | - foreach ($fields as $field_name => $field_obj) { |
|
909 | - if ($field_obj->is_auto_increment()) { |
|
910 | - // totally ignore auto increment IDs |
|
911 | - continue; |
|
912 | - } |
|
913 | - $arg_info = $field_obj->getSchema(); |
|
914 | - $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
915 | - $arg_info['required'] = $required; |
|
916 | - // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
917 | - unset($arg_info['readonly']); |
|
918 | - $schema_properties = $field_obj->getSchemaProperties(); |
|
919 | - if ( |
|
920 | - isset($schema_properties['raw']) |
|
921 | - && $field_obj->getSchemaType() === 'object' |
|
922 | - ) { |
|
923 | - // if there's a "raw" form of this argument, use those properties instead |
|
924 | - $arg_info = array_replace( |
|
925 | - $arg_info, |
|
926 | - $schema_properties['raw'] |
|
927 | - ); |
|
928 | - } |
|
929 | - $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
930 | - $field_obj, |
|
931 | - $field_obj->get_default_value(), |
|
932 | - $model_version_info->requestedVersion() |
|
933 | - ); |
|
934 | - // we do our own validation and sanitization within the controller |
|
935 | - if (function_exists('rest_validate_value_from_schema')) { |
|
936 | - $sanitize_callback = array( |
|
937 | - 'EED_Core_Rest_Api', |
|
938 | - 'default_sanitize_callback', |
|
939 | - ); |
|
940 | - } else { |
|
941 | - $sanitize_callback = null; |
|
942 | - } |
|
943 | - $arg_info['sanitize_callback'] = $sanitize_callback; |
|
944 | - $args_info[ $field_name ] = $arg_info; |
|
945 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
946 | - $gmt_arg_info = $arg_info; |
|
947 | - $gmt_arg_info['description'] = sprintf( |
|
948 | - esc_html__( |
|
949 | - '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
950 | - 'event_espresso' |
|
951 | - ), |
|
952 | - $field_obj->get_nicename(), |
|
953 | - $field_name |
|
954 | - ); |
|
955 | - $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
956 | - } |
|
957 | - } |
|
958 | - return $args_info; |
|
959 | - } |
|
960 | - |
|
961 | - |
|
962 | - /** |
|
963 | - * Replacement for WP API's 'rest_parse_request_arg'. |
|
964 | - * If the value is blank but not required, don't bother validating it. |
|
965 | - * Also, it uses our email validation instead of WP API's default. |
|
966 | - * |
|
967 | - * @param $value |
|
968 | - * @param WP_REST_Request $request |
|
969 | - * @param $param |
|
970 | - * @return bool|true|WP_Error |
|
971 | - * @throws InvalidArgumentException |
|
972 | - * @throws InvalidInterfaceException |
|
973 | - * @throws InvalidDataTypeException |
|
974 | - */ |
|
975 | - public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
976 | - { |
|
977 | - $attributes = $request->get_attributes(); |
|
978 | - if ( |
|
979 | - ! isset($attributes['args'][ $param ]) |
|
980 | - || ! is_array($attributes['args'][ $param ]) |
|
981 | - ) { |
|
982 | - $validation_result = true; |
|
983 | - } else { |
|
984 | - $args = $attributes['args'][ $param ]; |
|
985 | - if ( |
|
986 | - ( |
|
987 | - $value === '' |
|
988 | - || $value === null |
|
989 | - ) |
|
990 | - && (! isset($args['required']) |
|
991 | - || $args['required'] === false |
|
992 | - ) |
|
993 | - ) { |
|
994 | - // not required and not provided? that's cool |
|
995 | - $validation_result = true; |
|
996 | - } elseif ( |
|
997 | - isset($args['format']) |
|
998 | - && $args['format'] === 'email' |
|
999 | - ) { |
|
1000 | - $validation_result = true; |
|
1001 | - if (! self::_validate_email($value)) { |
|
1002 | - $validation_result = new WP_Error( |
|
1003 | - 'rest_invalid_param', |
|
1004 | - esc_html__( |
|
1005 | - 'The email address is not valid or does not exist.', |
|
1006 | - 'event_espresso' |
|
1007 | - ) |
|
1008 | - ); |
|
1009 | - } |
|
1010 | - } else { |
|
1011 | - $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
1012 | - } |
|
1013 | - } |
|
1014 | - if (is_wp_error($validation_result)) { |
|
1015 | - return $validation_result; |
|
1016 | - } |
|
1017 | - return rest_sanitize_request_arg($value, $request, $param); |
|
1018 | - } |
|
1019 | - |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
1023 | - * |
|
1024 | - * @param $email |
|
1025 | - * @return bool |
|
1026 | - * @throws InvalidArgumentException |
|
1027 | - * @throws InvalidInterfaceException |
|
1028 | - * @throws InvalidDataTypeException |
|
1029 | - */ |
|
1030 | - protected static function _validate_email($email) |
|
1031 | - { |
|
1032 | - try { |
|
1033 | - EmailAddressFactory::create($email); |
|
1034 | - return true; |
|
1035 | - } catch (EmailValidationException $e) { |
|
1036 | - return false; |
|
1037 | - } |
|
1038 | - } |
|
1039 | - |
|
1040 | - |
|
1041 | - /** |
|
1042 | - * Gets routes for the config |
|
1043 | - * |
|
1044 | - * @return array @see _register_model_routes |
|
1045 | - * @deprecated since version 4.9.1 |
|
1046 | - */ |
|
1047 | - protected function _register_config_routes() |
|
1048 | - { |
|
1049 | - $config_routes = array(); |
|
1050 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
1051 | - $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
1052 | - $version, |
|
1053 | - $hidden_endpoint |
|
1054 | - ); |
|
1055 | - } |
|
1056 | - return $config_routes; |
|
1057 | - } |
|
1058 | - |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * Gets routes for the config for the specified version |
|
1062 | - * |
|
1063 | - * @param string $version |
|
1064 | - * @param boolean $hidden_endpoint |
|
1065 | - * @return array |
|
1066 | - */ |
|
1067 | - protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
1068 | - { |
|
1069 | - return array( |
|
1070 | - 'config' => array( |
|
1071 | - array( |
|
1072 | - 'callback' => array( |
|
1073 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1074 | - 'handleRequest', |
|
1075 | - ), |
|
1076 | - 'methods' => WP_REST_Server::READABLE, |
|
1077 | - 'hidden_endpoint' => $hidden_endpoint, |
|
1078 | - 'callback_args' => array($version), |
|
1079 | - ), |
|
1080 | - ), |
|
1081 | - 'site_info' => array( |
|
1082 | - array( |
|
1083 | - 'callback' => array( |
|
1084 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1085 | - 'handleRequestSiteInfo', |
|
1086 | - ), |
|
1087 | - 'methods' => WP_REST_Server::READABLE, |
|
1088 | - 'hidden_endpoint' => $hidden_endpoint, |
|
1089 | - 'callback_args' => array($version), |
|
1090 | - ), |
|
1091 | - ), |
|
1092 | - ); |
|
1093 | - } |
|
1094 | - |
|
1095 | - |
|
1096 | - /** |
|
1097 | - * Gets the meta info routes |
|
1098 | - * |
|
1099 | - * @return array @see _register_model_routes |
|
1100 | - * @deprecated since version 4.9.1 |
|
1101 | - */ |
|
1102 | - protected function _register_meta_routes() |
|
1103 | - { |
|
1104 | - $meta_routes = array(); |
|
1105 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
1106 | - $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
1107 | - $version, |
|
1108 | - $hidden_endpoint |
|
1109 | - ); |
|
1110 | - } |
|
1111 | - return $meta_routes; |
|
1112 | - } |
|
1113 | - |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * @param string $version |
|
1117 | - * @param boolean $hidden_endpoint |
|
1118 | - * @return array |
|
1119 | - */ |
|
1120 | - protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
1121 | - { |
|
1122 | - return array( |
|
1123 | - 'resources' => array( |
|
1124 | - array( |
|
1125 | - 'callback' => array( |
|
1126 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
1127 | - 'handleRequestModelsMeta', |
|
1128 | - ), |
|
1129 | - 'methods' => WP_REST_Server::READABLE, |
|
1130 | - 'hidden_endpoint' => $hidden_endpoint, |
|
1131 | - 'callback_args' => array($version), |
|
1132 | - ), |
|
1133 | - ), |
|
1134 | - ); |
|
1135 | - } |
|
1136 | - |
|
1137 | - |
|
1138 | - /** |
|
1139 | - * Tries to hide old 4.6 endpoints from the |
|
1140 | - * |
|
1141 | - * @param array $route_data |
|
1142 | - * @return array |
|
1143 | - * @throws \EE_Error |
|
1144 | - */ |
|
1145 | - public static function hide_old_endpoints($route_data) |
|
1146 | - { |
|
1147 | - // allow API clients to override which endpoints get hidden, in case |
|
1148 | - // they want to discover particular endpoints |
|
1149 | - // also, we don't have access to the request so we have to just grab it from the superglobal |
|
1150 | - $force_show_ee_namespace = ltrim( |
|
1151 | - EED_Core_Rest_Api::getRequest()->getRequestParam('force_show_ee_namespace'), |
|
1152 | - '/' |
|
1153 | - ); |
|
1154 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
1155 | - foreach ($relative_urls as $resource_name => $endpoints) { |
|
1156 | - foreach ($endpoints as $key => $endpoint) { |
|
1157 | - // skip schema and other route options |
|
1158 | - if (! is_numeric($key)) { |
|
1159 | - continue; |
|
1160 | - } |
|
1161 | - // by default, hide "hidden_endpoint"s, unless the request indicates |
|
1162 | - // to $force_show_ee_namespace, in which case only show that one |
|
1163 | - // namespace's endpoints (and hide all others) |
|
1164 | - if ( |
|
1165 | - ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
1166 | - || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
1167 | - ) { |
|
1168 | - $full_route = '/' . ltrim($namespace, '/'); |
|
1169 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
1170 | - unset($route_data[ $full_route ]); |
|
1171 | - } |
|
1172 | - } |
|
1173 | - } |
|
1174 | - } |
|
1175 | - return $route_data; |
|
1176 | - } |
|
1177 | - |
|
1178 | - |
|
1179 | - /** |
|
1180 | - * Returns an array describing which versions of core support serving requests for. |
|
1181 | - * Keys are core versions' major and minor version, and values are the |
|
1182 | - * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
1183 | - * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
1184 | - * the answers table entirely, in which case it would be very difficult for |
|
1185 | - * it to serve 4.6-style responses. |
|
1186 | - * Versions of core that are missing from this array are unknowns. |
|
1187 | - * previous ver |
|
1188 | - * |
|
1189 | - * @return array |
|
1190 | - */ |
|
1191 | - public static function version_compatibilities() |
|
1192 | - { |
|
1193 | - return apply_filters( |
|
1194 | - 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
1195 | - array( |
|
1196 | - '4.8.29' => '4.8.29', |
|
1197 | - '4.8.33' => '4.8.29', |
|
1198 | - '4.8.34' => '4.8.29', |
|
1199 | - '4.8.36' => '4.8.29', |
|
1200 | - ) |
|
1201 | - ); |
|
1202 | - } |
|
1203 | - |
|
1204 | - |
|
1205 | - /** |
|
1206 | - * Gets the latest API version served. Eg if there |
|
1207 | - * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
1208 | - * we are on core version 4.8.34, it will return the string "4.8.32" |
|
1209 | - * |
|
1210 | - * @return string |
|
1211 | - */ |
|
1212 | - public static function latest_rest_api_version() |
|
1213 | - { |
|
1214 | - $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
1215 | - $versions_served_keys = array_keys($versions_served); |
|
1216 | - return end($versions_served_keys); |
|
1217 | - } |
|
1218 | - |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
1222 | - * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
1223 | - * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
1224 | - * We also indicate whether or not this version should be put in the index or not |
|
1225 | - * |
|
1226 | - * @return array keys are API version numbers (just major and minor numbers), and values |
|
1227 | - * are whether or not they should be hidden |
|
1228 | - */ |
|
1229 | - public static function versions_served() |
|
1230 | - { |
|
1231 | - $versions_served = array(); |
|
1232 | - $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
1233 | - $lowest_compatible_version = end($possibly_served_versions); |
|
1234 | - reset($possibly_served_versions); |
|
1235 | - $versions_served_historically = array_keys($possibly_served_versions); |
|
1236 | - $latest_version = end($versions_served_historically); |
|
1237 | - reset($versions_served_historically); |
|
1238 | - // for each version of core we have ever served: |
|
1239 | - foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
1240 | - // if it's not above the current core version, and it's compatible with the current version of core |
|
1241 | - |
|
1242 | - if ($key_versioned_endpoint === $latest_version) { |
|
1243 | - // don't hide the latest version in the index |
|
1244 | - $versions_served[ $key_versioned_endpoint ] = false; |
|
1245 | - } elseif ( |
|
1246 | - version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
|
1247 | - && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
|
1248 | - ) { |
|
1249 | - // include, but hide, previous versions which are still supported |
|
1250 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1251 | - } elseif ( |
|
1252 | - apply_filters( |
|
1253 | - 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
1254 | - false, |
|
1255 | - $possibly_served_versions |
|
1256 | - ) |
|
1257 | - ) { |
|
1258 | - // if a version is no longer supported, don't include it in index or list of versions served |
|
1259 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1260 | - } |
|
1261 | - } |
|
1262 | - return $versions_served; |
|
1263 | - } |
|
1264 | - |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * Gets the major and minor version of EE core's version string |
|
1268 | - * |
|
1269 | - * @return string |
|
1270 | - */ |
|
1271 | - public static function core_version() |
|
1272 | - { |
|
1273 | - return apply_filters( |
|
1274 | - 'FHEE__EED_Core_REST_API__core_version', |
|
1275 | - implode( |
|
1276 | - '.', |
|
1277 | - array_slice( |
|
1278 | - explode( |
|
1279 | - '.', |
|
1280 | - espresso_version() |
|
1281 | - ), |
|
1282 | - 0, |
|
1283 | - 3 |
|
1284 | - ) |
|
1285 | - ) |
|
1286 | - ); |
|
1287 | - } |
|
1288 | - |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * Gets the default limit that should be used when querying for resources |
|
1292 | - * |
|
1293 | - * @return int |
|
1294 | - */ |
|
1295 | - public static function get_default_query_limit() |
|
1296 | - { |
|
1297 | - // we actually don't use a const because we want folks to always use |
|
1298 | - // this method, not the const directly |
|
1299 | - return apply_filters( |
|
1300 | - 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
1301 | - 50 |
|
1302 | - ); |
|
1303 | - } |
|
1304 | - |
|
1305 | - |
|
1306 | - /** |
|
1307 | - * |
|
1308 | - * @param string $version api version string (i.e. '4.8.36') |
|
1309 | - * @return array |
|
1310 | - */ |
|
1311 | - public static function getCollectionRoutesIndexedByModelName($version = '') |
|
1312 | - { |
|
1313 | - $version = empty($version) ? self::latest_rest_api_version() : $version; |
|
1314 | - $model_names = self::model_names_with_plural_routes($version); |
|
1315 | - $collection_routes = array(); |
|
1316 | - foreach ($model_names as $model_name => $model_class_name) { |
|
1317 | - $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/' |
|
1318 | - . EEH_Inflector::pluralize_and_lower($model_name); |
|
1319 | - } |
|
1320 | - return $collection_routes; |
|
1321 | - } |
|
1322 | - |
|
1323 | - |
|
1324 | - /** |
|
1325 | - * Returns an array of primary key names indexed by model names. |
|
1326 | - * @param string $version |
|
1327 | - * @return array |
|
1328 | - */ |
|
1329 | - public static function getPrimaryKeyNamesIndexedByModelName($version = '') |
|
1330 | - { |
|
1331 | - $version = empty($version) ? self::latest_rest_api_version() : $version; |
|
1332 | - $model_names = self::model_names_with_plural_routes($version); |
|
1333 | - $primary_key_items = array(); |
|
1334 | - foreach ($model_names as $model_name => $model_class_name) { |
|
1335 | - $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
|
1336 | - foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
|
1337 | - if (count($primary_keys) > 1) { |
|
1338 | - $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
1339 | - } else { |
|
1340 | - $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
1341 | - } |
|
1342 | - } |
|
1343 | - } |
|
1344 | - return $primary_key_items; |
|
1345 | - } |
|
1346 | - |
|
1347 | - /** |
|
1348 | - * Determines the EE REST API debug mode is activated, or not. |
|
1349 | - * @since 4.9.76.p |
|
1350 | - * @return bool |
|
1351 | - */ |
|
1352 | - public static function debugMode() |
|
1353 | - { |
|
1354 | - static $debug_mode = null; // could be class prop |
|
1355 | - if ($debug_mode === null) { |
|
1356 | - $debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE; |
|
1357 | - } |
|
1358 | - return $debug_mode; |
|
1359 | - } |
|
1360 | - |
|
1361 | - |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * run - initial module setup |
|
1365 | - * |
|
1366 | - * @access public |
|
1367 | - * @param WP $WP |
|
1368 | - * @return void |
|
1369 | - */ |
|
1370 | - public function run($WP) |
|
1371 | - { |
|
1372 | - } |
|
25 | + const ee_api_namespace = Domain::API_NAMESPACE; |
|
26 | + |
|
27 | + const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
28 | + |
|
29 | + const saved_routes_option_names = 'ee_core_routes'; |
|
30 | + |
|
31 | + /** |
|
32 | + * string used in _links response bodies to make them globally unique. |
|
33 | + * |
|
34 | + * @see http://v2.wp-api.org/extending/linking/ |
|
35 | + */ |
|
36 | + const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var CalculatedModelFields |
|
40 | + */ |
|
41 | + protected static $_field_calculator; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @return EED_Core_Rest_Api|EED_Module |
|
46 | + */ |
|
47 | + public static function instance() |
|
48 | + { |
|
49 | + self::$_field_calculator = LoaderFactory::getLoader()->load('EventEspresso\core\libraries\rest_api\CalculatedModelFields'); |
|
50 | + return parent::get_instance(__CLASS__); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
56 | + * |
|
57 | + * @access public |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public static function set_hooks() |
|
61 | + { |
|
62 | + self::set_hooks_both(); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
68 | + * |
|
69 | + * @access public |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public static function set_hooks_admin() |
|
73 | + { |
|
74 | + self::set_hooks_both(); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + public static function set_hooks_both() |
|
79 | + { |
|
80 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
81 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
82 | + add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
83 | + add_filter( |
|
84 | + 'rest_index', |
|
85 | + array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex') |
|
86 | + ); |
|
87 | + EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * sets up hooks which only need to be included as part of REST API requests; |
|
93 | + * other requests like to the frontend or admin etc don't need them |
|
94 | + * |
|
95 | + * @throws \EE_Error |
|
96 | + */ |
|
97 | + public static function set_hooks_rest_api() |
|
98 | + { |
|
99 | + // set hooks which account for changes made to the API |
|
100 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * public wrapper of _set_hooks_for_changes. |
|
106 | + * Loads all the hooks which make requests to old versions of the API |
|
107 | + * appear the same as they always did |
|
108 | + * |
|
109 | + * @throws EE_Error |
|
110 | + */ |
|
111 | + public static function set_hooks_for_changes() |
|
112 | + { |
|
113 | + self::_set_hooks_for_changes(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * Loads all the hooks which make requests to old versions of the API |
|
119 | + * appear the same as they always did |
|
120 | + * |
|
121 | + * @throws EE_Error |
|
122 | + */ |
|
123 | + protected static function _set_hooks_for_changes() |
|
124 | + { |
|
125 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api/changes'), false); |
|
126 | + foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
127 | + // ignore the base parent class |
|
128 | + // and legacy named classes |
|
129 | + if ( |
|
130 | + $classname_in_namespace === 'ChangesInBase' |
|
131 | + || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
132 | + ) { |
|
133 | + continue; |
|
134 | + } |
|
135 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
136 | + if (class_exists($full_classname)) { |
|
137 | + $instance_of_class = new $full_classname(); |
|
138 | + if ($instance_of_class instanceof ChangesInBase) { |
|
139 | + $instance_of_class->setHooks(); |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
148 | + * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
149 | + * |
|
150 | + * @throws \EE_Error |
|
151 | + */ |
|
152 | + public static function register_routes() |
|
153 | + { |
|
154 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
155 | + foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
156 | + /** |
|
157 | + * @var array $data_for_multiple_endpoints numerically indexed array |
|
158 | + * but can also contain route options like { |
|
159 | + * @type array $schema { |
|
160 | + * @type callable $schema_callback |
|
161 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
162 | + * WP_REST_Request of course |
|
163 | + * } |
|
164 | + * } |
|
165 | + */ |
|
166 | + // when registering routes, register all the endpoints' data at the same time |
|
167 | + $multiple_endpoint_args = array(); |
|
168 | + foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
169 | + /** |
|
170 | + * @var array $data_for_single_endpoint { |
|
171 | + * @type callable $callback |
|
172 | + * @type string methods |
|
173 | + * @type array args |
|
174 | + * @type array _links |
|
175 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
176 | + * WP_REST_Request of course |
|
177 | + * } |
|
178 | + */ |
|
179 | + // skip route options |
|
180 | + if (! is_numeric($endpoint_key)) { |
|
181 | + continue; |
|
182 | + } |
|
183 | + if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
184 | + throw new EE_Error( |
|
185 | + esc_html__( |
|
186 | + // @codingStandardsIgnoreStart |
|
187 | + 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
188 | + // @codingStandardsIgnoreEnd |
|
189 | + 'event_espresso' |
|
190 | + ) |
|
191 | + ); |
|
192 | + } |
|
193 | + $callback = $data_for_single_endpoint['callback']; |
|
194 | + $single_endpoint_args = array( |
|
195 | + 'methods' => $data_for_single_endpoint['methods'], |
|
196 | + 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
197 | + : array(), |
|
198 | + ); |
|
199 | + if (isset($data_for_single_endpoint['_links'])) { |
|
200 | + $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
201 | + } |
|
202 | + if (isset($data_for_single_endpoint['callback_args'])) { |
|
203 | + $callback_args = $data_for_single_endpoint['callback_args']; |
|
204 | + $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
205 | + $callback, |
|
206 | + $callback_args |
|
207 | + ) { |
|
208 | + array_unshift($callback_args, $request); |
|
209 | + return call_user_func_array( |
|
210 | + $callback, |
|
211 | + $callback_args |
|
212 | + ); |
|
213 | + }; |
|
214 | + } else { |
|
215 | + $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
216 | + } |
|
217 | + // As of WordPress 5.5, if a permission_callback is not provided, |
|
218 | + // the REST API will issue a _doing_it_wrong notice. |
|
219 | + // Since the EE REST API defers capabilities to the db model system, |
|
220 | + // we will just use the generic WP callback for public endpoints |
|
221 | + if (! isset($single_endpoint_args['permission_callback'])) { |
|
222 | + $single_endpoint_args['permission_callback'] = '__return_true'; |
|
223 | + } |
|
224 | + $multiple_endpoint_args[] = $single_endpoint_args; |
|
225 | + } |
|
226 | + if (isset($data_for_multiple_endpoints['schema'])) { |
|
227 | + $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
228 | + $schema_callback = $schema_route_data['schema_callback']; |
|
229 | + $callback_args = $schema_route_data['callback_args']; |
|
230 | + $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) { |
|
231 | + return call_user_func_array( |
|
232 | + $schema_callback, |
|
233 | + $callback_args |
|
234 | + ); |
|
235 | + }; |
|
236 | + } |
|
237 | + register_rest_route( |
|
238 | + $namespace, |
|
239 | + $relative_route, |
|
240 | + $multiple_endpoint_args |
|
241 | + ); |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Checks if there was a version change or something that merits invalidating the cached |
|
249 | + * route data. If so, invalidates the cached route data so that it gets refreshed |
|
250 | + * next time the WP API is used |
|
251 | + */ |
|
252 | + public static function invalidate_cached_route_data_on_version_change() |
|
253 | + { |
|
254 | + if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
255 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
256 | + } |
|
257 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
258 | + if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
259 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
260 | + } |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * Removes the cached route data so it will get refreshed next time the WP API is used |
|
267 | + */ |
|
268 | + public static function invalidate_cached_route_data() |
|
269 | + { |
|
270 | + // delete the saved EE REST API routes |
|
271 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
272 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * Gets the EE route data |
|
279 | + * |
|
280 | + * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
281 | + * @throws \EE_Error |
|
282 | + * @type string|array $callback |
|
283 | + * @type string $methods |
|
284 | + * @type boolean $hidden_endpoint |
|
285 | + * } |
|
286 | + */ |
|
287 | + public static function get_ee_route_data() |
|
288 | + { |
|
289 | + $ee_routes = array(); |
|
290 | + foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
291 | + $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version( |
|
292 | + $version, |
|
293 | + $hidden_endpoints |
|
294 | + ); |
|
295 | + } |
|
296 | + return $ee_routes; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * Gets the EE route data from the wp options if it exists already, |
|
302 | + * otherwise re-generates it and saves it to the option |
|
303 | + * |
|
304 | + * @param string $version |
|
305 | + * @param boolean $hidden_endpoints |
|
306 | + * @return array |
|
307 | + * @throws \EE_Error |
|
308 | + */ |
|
309 | + protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
310 | + { |
|
311 | + $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
312 | + if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
313 | + $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
314 | + } |
|
315 | + return $ee_routes; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * Saves the EE REST API route data to a wp option and returns it |
|
321 | + * |
|
322 | + * @param string $version |
|
323 | + * @param boolean $hidden_endpoints |
|
324 | + * @return mixed|null |
|
325 | + * @throws \EE_Error |
|
326 | + */ |
|
327 | + protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
328 | + { |
|
329 | + $instance = self::instance(); |
|
330 | + $routes = apply_filters( |
|
331 | + 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
332 | + array_replace_recursive( |
|
333 | + $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
334 | + $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
335 | + $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
336 | + $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
337 | + ) |
|
338 | + ); |
|
339 | + $option_name = self::saved_routes_option_names . $version; |
|
340 | + if (get_option($option_name)) { |
|
341 | + update_option($option_name, $routes, true); |
|
342 | + } else { |
|
343 | + add_option($option_name, $routes, null, 'no'); |
|
344 | + } |
|
345 | + return $routes; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
351 | + * need to calculate it on every request |
|
352 | + * |
|
353 | + * @deprecated since version 4.9.1 |
|
354 | + * @return void |
|
355 | + */ |
|
356 | + public static function save_ee_routes() |
|
357 | + { |
|
358 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
359 | + $instance = self::instance(); |
|
360 | + $routes = apply_filters( |
|
361 | + 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
362 | + array_replace_recursive( |
|
363 | + $instance->_register_config_routes(), |
|
364 | + $instance->_register_meta_routes(), |
|
365 | + $instance->_register_model_routes(), |
|
366 | + $instance->_register_rpc_routes() |
|
367 | + ) |
|
368 | + ); |
|
369 | + update_option(self::saved_routes_option_names, $routes, true); |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * Gets all the route information relating to EE models |
|
376 | + * |
|
377 | + * @return array @see get_ee_route_data |
|
378 | + * @deprecated since version 4.9.1 |
|
379 | + */ |
|
380 | + protected function _register_model_routes() |
|
381 | + { |
|
382 | + $model_routes = array(); |
|
383 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
384 | + $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
385 | + . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
386 | + } |
|
387 | + return $model_routes; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Decides whether or not to add write endpoints for this model. |
|
393 | + * |
|
394 | + * Currently, this defaults to exclude all global tables and models |
|
395 | + * which would allow inserting WP core data (we don't want to duplicate |
|
396 | + * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
397 | + * |
|
398 | + * @param EEM_Base $model |
|
399 | + * @return bool |
|
400 | + */ |
|
401 | + public static function should_have_write_endpoints(EEM_Base $model) |
|
402 | + { |
|
403 | + if ($model->is_wp_core_model()) { |
|
404 | + return false; |
|
405 | + } |
|
406 | + foreach ($model->get_tables() as $table) { |
|
407 | + if ($table->is_global()) { |
|
408 | + return false; |
|
409 | + } |
|
410 | + } |
|
411 | + return true; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
417 | + * in this versioned namespace of EE4 |
|
418 | + * |
|
419 | + * @param $version |
|
420 | + * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
421 | + */ |
|
422 | + public static function model_names_with_plural_routes($version) |
|
423 | + { |
|
424 | + $model_version_info = new ModelVersionInfo($version); |
|
425 | + $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
426 | + // let's not bother having endpoints for extra metas |
|
427 | + unset( |
|
428 | + $models_to_register['Extra_Meta'], |
|
429 | + $models_to_register['Extra_Join'], |
|
430 | + $models_to_register['Post_Meta'] |
|
431 | + ); |
|
432 | + return apply_filters( |
|
433 | + 'FHEE__EED_Core_REST_API___register_model_routes', |
|
434 | + $models_to_register |
|
435 | + ); |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * Gets the route data for EE models in the specified version |
|
441 | + * |
|
442 | + * @param string $version |
|
443 | + * @param boolean $hidden_endpoint |
|
444 | + * @return array |
|
445 | + * @throws EE_Error |
|
446 | + */ |
|
447 | + protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
448 | + { |
|
449 | + $model_routes = array(); |
|
450 | + $model_version_info = new ModelVersionInfo($version); |
|
451 | + foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
452 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
453 | + // if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
454 | + if (! $model instanceof EEM_Base) { |
|
455 | + continue; |
|
456 | + } |
|
457 | + // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
458 | + $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
459 | + $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
460 | + $model_routes[ $plural_model_route ] = array( |
|
461 | + array( |
|
462 | + 'callback' => array( |
|
463 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
464 | + 'handleRequestGetAll', |
|
465 | + ), |
|
466 | + 'callback_args' => array($version, $model_name), |
|
467 | + 'methods' => WP_REST_Server::READABLE, |
|
468 | + 'hidden_endpoint' => $hidden_endpoint, |
|
469 | + 'args' => $this->_get_read_query_params($model, $version), |
|
470 | + '_links' => array( |
|
471 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
472 | + ), |
|
473 | + ), |
|
474 | + 'schema' => array( |
|
475 | + 'schema_callback' => array( |
|
476 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
477 | + 'handleSchemaRequest', |
|
478 | + ), |
|
479 | + 'callback_args' => array($version, $model_name), |
|
480 | + ), |
|
481 | + ); |
|
482 | + $model_routes[ $singular_model_route ] = array( |
|
483 | + array( |
|
484 | + 'callback' => array( |
|
485 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
486 | + 'handleRequestGetOne', |
|
487 | + ), |
|
488 | + 'callback_args' => array($version, $model_name), |
|
489 | + 'methods' => WP_REST_Server::READABLE, |
|
490 | + 'hidden_endpoint' => $hidden_endpoint, |
|
491 | + 'args' => $this->_get_response_selection_query_params($model, $version, true), |
|
492 | + ), |
|
493 | + ); |
|
494 | + if ( |
|
495 | + apply_filters( |
|
496 | + 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
497 | + EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
498 | + $model |
|
499 | + ) |
|
500 | + ) { |
|
501 | + $model_routes[ $plural_model_route ][] = array( |
|
502 | + 'callback' => array( |
|
503 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
504 | + 'handleRequestInsert', |
|
505 | + ), |
|
506 | + 'callback_args' => array($version, $model_name), |
|
507 | + 'methods' => WP_REST_Server::CREATABLE, |
|
508 | + 'hidden_endpoint' => $hidden_endpoint, |
|
509 | + 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
510 | + ); |
|
511 | + $model_routes[ $singular_model_route ] = array_merge( |
|
512 | + $model_routes[ $singular_model_route ], |
|
513 | + array( |
|
514 | + array( |
|
515 | + 'callback' => array( |
|
516 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
517 | + 'handleRequestUpdate', |
|
518 | + ), |
|
519 | + 'callback_args' => array($version, $model_name), |
|
520 | + 'methods' => WP_REST_Server::EDITABLE, |
|
521 | + 'hidden_endpoint' => $hidden_endpoint, |
|
522 | + 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
523 | + ), |
|
524 | + array( |
|
525 | + 'callback' => array( |
|
526 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
527 | + 'handleRequestDelete', |
|
528 | + ), |
|
529 | + 'callback_args' => array($version, $model_name), |
|
530 | + 'methods' => WP_REST_Server::DELETABLE, |
|
531 | + 'hidden_endpoint' => $hidden_endpoint, |
|
532 | + 'args' => $this->_get_delete_query_params($model, $version), |
|
533 | + ), |
|
534 | + ) |
|
535 | + ); |
|
536 | + } |
|
537 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
538 | + $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
539 | + $model, |
|
540 | + '(?P<id>[^\/]+)', |
|
541 | + $relation_obj |
|
542 | + ); |
|
543 | + $model_routes[ $related_route ] = array( |
|
544 | + array( |
|
545 | + 'callback' => array( |
|
546 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
547 | + 'handleRequestGetRelated', |
|
548 | + ), |
|
549 | + 'callback_args' => array($version, $model_name, $relation_name), |
|
550 | + 'methods' => WP_REST_Server::READABLE, |
|
551 | + 'hidden_endpoint' => $hidden_endpoint, |
|
552 | + 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
553 | + ), |
|
554 | + ); |
|
555 | + |
|
556 | + $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
557 | + $model_routes[ $related_write_route ] = array( |
|
558 | + array( |
|
559 | + 'callback' => array( |
|
560 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
561 | + 'handleRequestAddRelation', |
|
562 | + ), |
|
563 | + 'callback_args' => array($version, $model_name, $relation_name), |
|
564 | + 'methods' => WP_REST_Server::EDITABLE, |
|
565 | + 'hidden_endpoint' => $hidden_endpoint, |
|
566 | + 'args' => $this->_get_add_relation_query_params($model, $relation_obj->get_other_model(), $version) |
|
567 | + ), |
|
568 | + array( |
|
569 | + 'callback' => array( |
|
570 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
571 | + 'handleRequestRemoveRelation', |
|
572 | + ), |
|
573 | + 'callback_args' => array($version, $model_name, $relation_name), |
|
574 | + 'methods' => WP_REST_Server::DELETABLE, |
|
575 | + 'hidden_endpoint' => $hidden_endpoint, |
|
576 | + 'args' => array() |
|
577 | + ), |
|
578 | + ); |
|
579 | + } |
|
580 | + } |
|
581 | + return $model_routes; |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
587 | + * excluding the preceding slash. |
|
588 | + * Eg you pass get_plural_route_to('Event') = 'events' |
|
589 | + * |
|
590 | + * @param EEM_Base $model |
|
591 | + * @return string |
|
592 | + */ |
|
593 | + public static function get_collection_route(EEM_Base $model) |
|
594 | + { |
|
595 | + return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
601 | + * excluding the preceding slash. |
|
602 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
603 | + * |
|
604 | + * @param EEM_Base $model eg Event or Venue |
|
605 | + * @param string $id |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public static function get_entity_route($model, $id) |
|
609 | + { |
|
610 | + return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
611 | + } |
|
612 | + |
|
613 | + |
|
614 | + /** |
|
615 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
616 | + * excluding the preceding slash. |
|
617 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
618 | + * |
|
619 | + * @param EEM_Base $model eg Event or Venue |
|
620 | + * @param string $id |
|
621 | + * @param EE_Model_Relation_Base $relation_obj |
|
622 | + * @return string |
|
623 | + */ |
|
624 | + public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
625 | + { |
|
626 | + $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
627 | + $relation_obj->get_other_model()->get_this_model_name(), |
|
628 | + $relation_obj |
|
629 | + ); |
|
630 | + return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + /** |
|
635 | + * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
636 | + * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
637 | + * |
|
638 | + * @param string $relative_route |
|
639 | + * @param string $version |
|
640 | + * @return string |
|
641 | + */ |
|
642 | + public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
|
643 | + { |
|
644 | + return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
650 | + * routes that don't conform to the traditional REST CRUD-style). |
|
651 | + * |
|
652 | + * @deprecated since 4.9.1 |
|
653 | + */ |
|
654 | + protected function _register_rpc_routes() |
|
655 | + { |
|
656 | + $routes = array(); |
|
657 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
658 | + $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
659 | + $version, |
|
660 | + $hidden_endpoint |
|
661 | + ); |
|
662 | + } |
|
663 | + return $routes; |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * @param string $version |
|
669 | + * @param boolean $hidden_endpoint |
|
670 | + * @return array |
|
671 | + */ |
|
672 | + protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
673 | + { |
|
674 | + $this_versions_routes = array(); |
|
675 | + // checkin endpoint |
|
676 | + $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
677 | + array( |
|
678 | + 'callback' => array( |
|
679 | + 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
680 | + 'handleRequestToggleCheckin', |
|
681 | + ), |
|
682 | + 'methods' => WP_REST_Server::CREATABLE, |
|
683 | + 'hidden_endpoint' => $hidden_endpoint, |
|
684 | + 'args' => array( |
|
685 | + 'force' => array( |
|
686 | + 'required' => false, |
|
687 | + 'default' => false, |
|
688 | + 'description' => esc_html__( |
|
689 | + // @codingStandardsIgnoreStart |
|
690 | + 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
691 | + // @codingStandardsIgnoreEnd |
|
692 | + 'event_espresso' |
|
693 | + ), |
|
694 | + ), |
|
695 | + ), |
|
696 | + 'callback_args' => array($version), |
|
697 | + ), |
|
698 | + ); |
|
699 | + return apply_filters( |
|
700 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
701 | + $this_versions_routes, |
|
702 | + $version, |
|
703 | + $hidden_endpoint |
|
704 | + ); |
|
705 | + } |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * Gets the query params that can be used when request one or many |
|
710 | + * |
|
711 | + * @param EEM_Base $model |
|
712 | + * @param string $version |
|
713 | + * @return array |
|
714 | + */ |
|
715 | + protected function _get_response_selection_query_params(\EEM_Base $model, $version, $single_only = false) |
|
716 | + { |
|
717 | + $query_params = array( |
|
718 | + 'include' => array( |
|
719 | + 'required' => false, |
|
720 | + 'default' => '*', |
|
721 | + 'type' => 'string', |
|
722 | + ), |
|
723 | + 'calculate' => array( |
|
724 | + 'required' => false, |
|
725 | + 'default' => '', |
|
726 | + 'enum' => self::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
727 | + 'type' => 'string', |
|
728 | + // because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
729 | + // freaks out. We'll just validate this argument while handling the request |
|
730 | + 'validate_callback' => null, |
|
731 | + 'sanitize_callback' => null, |
|
732 | + ), |
|
733 | + 'password' => array( |
|
734 | + 'required' => false, |
|
735 | + 'default' => '', |
|
736 | + 'type' => 'string' |
|
737 | + ) |
|
738 | + ); |
|
739 | + return apply_filters( |
|
740 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
741 | + $query_params, |
|
742 | + $model, |
|
743 | + $version |
|
744 | + ); |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * Gets the parameters acceptable for delete requests |
|
750 | + * |
|
751 | + * @param \EEM_Base $model |
|
752 | + * @param string $version |
|
753 | + * @return array |
|
754 | + */ |
|
755 | + protected function _get_delete_query_params(\EEM_Base $model, $version) |
|
756 | + { |
|
757 | + $params_for_delete = array( |
|
758 | + 'allow_blocking' => array( |
|
759 | + 'required' => false, |
|
760 | + 'default' => true, |
|
761 | + 'type' => 'boolean', |
|
762 | + ), |
|
763 | + ); |
|
764 | + $params_for_delete['force'] = array( |
|
765 | + 'required' => false, |
|
766 | + 'default' => false, |
|
767 | + 'type' => 'boolean', |
|
768 | + ); |
|
769 | + return apply_filters( |
|
770 | + 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
771 | + $params_for_delete, |
|
772 | + $model, |
|
773 | + $version |
|
774 | + ); |
|
775 | + } |
|
776 | + |
|
777 | + protected function _get_add_relation_query_params(\EEM_Base $source_model, \EEM_Base $related_model, $version) |
|
778 | + { |
|
779 | + // if they're related through a HABTM relation, check for any non-FKs |
|
780 | + $all_relation_settings = $source_model->relation_settings(); |
|
781 | + $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
782 | + $params = array(); |
|
783 | + if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
|
784 | + foreach ($relation_settings->getNonKeyFields() as $field) { |
|
785 | + /* @var $field EE_Model_Field_Base */ |
|
786 | + $params[ $field->get_name() ] = array( |
|
787 | + 'required' => ! $field->is_nullable(), |
|
788 | + 'default' => ModelDataTranslator::prepareFieldValueForJson($field, $field->get_default_value(), $version), |
|
789 | + 'type' => $field->getSchemaType(), |
|
790 | + 'validate_callbaack' => null, |
|
791 | + 'sanitize_callback' => null |
|
792 | + ); |
|
793 | + } |
|
794 | + } |
|
795 | + return $params; |
|
796 | + } |
|
797 | + |
|
798 | + |
|
799 | + /** |
|
800 | + * Gets info about reading query params that are acceptable |
|
801 | + * |
|
802 | + * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
803 | + * @param string $version |
|
804 | + * @return array describing the args acceptable when querying this model |
|
805 | + * @throws EE_Error |
|
806 | + */ |
|
807 | + protected function _get_read_query_params(\EEM_Base $model, $version) |
|
808 | + { |
|
809 | + $default_orderby = array(); |
|
810 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
811 | + $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
812 | + } |
|
813 | + return array_merge( |
|
814 | + $this->_get_response_selection_query_params($model, $version), |
|
815 | + array( |
|
816 | + 'where' => array( |
|
817 | + 'required' => false, |
|
818 | + 'default' => array(), |
|
819 | + 'type' => 'object', |
|
820 | + // because we accept an almost infinite list of possible where conditions, WP |
|
821 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
822 | + // while handling the request |
|
823 | + 'validate_callback' => null, |
|
824 | + 'sanitize_callback' => null, |
|
825 | + ), |
|
826 | + 'limit' => array( |
|
827 | + 'required' => false, |
|
828 | + 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
829 | + 'type' => array( |
|
830 | + 'array', |
|
831 | + 'string', |
|
832 | + 'integer', |
|
833 | + ), |
|
834 | + // because we accept a variety of types, WP core validation and sanitization |
|
835 | + // freaks out. We'll just validate this argument while handling the request |
|
836 | + 'validate_callback' => null, |
|
837 | + 'sanitize_callback' => null, |
|
838 | + ), |
|
839 | + 'order_by' => array( |
|
840 | + 'required' => false, |
|
841 | + 'default' => $default_orderby, |
|
842 | + 'type' => array( |
|
843 | + 'object', |
|
844 | + 'string', |
|
845 | + ),// because we accept a variety of types, WP core validation and sanitization |
|
846 | + // freaks out. We'll just validate this argument while handling the request |
|
847 | + 'validate_callback' => null, |
|
848 | + 'sanitize_callback' => null, |
|
849 | + ), |
|
850 | + 'group_by' => array( |
|
851 | + 'required' => false, |
|
852 | + 'default' => null, |
|
853 | + 'type' => array( |
|
854 | + 'object', |
|
855 | + 'string', |
|
856 | + ), |
|
857 | + // because we accept an almost infinite list of possible groupings, |
|
858 | + // WP core validation and sanitization |
|
859 | + // freaks out. We'll just validate this argument while handling the request |
|
860 | + 'validate_callback' => null, |
|
861 | + 'sanitize_callback' => null, |
|
862 | + ), |
|
863 | + 'having' => array( |
|
864 | + 'required' => false, |
|
865 | + 'default' => null, |
|
866 | + 'type' => 'object', |
|
867 | + // because we accept an almost infinite list of possible where conditions, WP |
|
868 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
869 | + // while handling the request |
|
870 | + 'validate_callback' => null, |
|
871 | + 'sanitize_callback' => null, |
|
872 | + ), |
|
873 | + 'caps' => array( |
|
874 | + 'required' => false, |
|
875 | + 'default' => EEM_Base::caps_read, |
|
876 | + 'type' => 'string', |
|
877 | + 'enum' => array( |
|
878 | + EEM_Base::caps_read, |
|
879 | + EEM_Base::caps_read_admin, |
|
880 | + EEM_Base::caps_edit, |
|
881 | + EEM_Base::caps_delete, |
|
882 | + ), |
|
883 | + ), |
|
884 | + ) |
|
885 | + ); |
|
886 | + } |
|
887 | + |
|
888 | + |
|
889 | + /** |
|
890 | + * Gets parameter information for a model regarding writing data |
|
891 | + * |
|
892 | + * @param string $model_name |
|
893 | + * @param ModelVersionInfo $model_version_info |
|
894 | + * @param boolean $create whether this is for request to create (in |
|
895 | + * which case we need all required params) or |
|
896 | + * just to update (in which case we don't |
|
897 | + * need those on every request) |
|
898 | + * @return array |
|
899 | + */ |
|
900 | + protected function _get_write_params( |
|
901 | + $model_name, |
|
902 | + ModelVersionInfo $model_version_info, |
|
903 | + $create = false |
|
904 | + ) { |
|
905 | + $model = EE_Registry::instance()->load_model($model_name); |
|
906 | + $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
907 | + $args_info = array(); |
|
908 | + foreach ($fields as $field_name => $field_obj) { |
|
909 | + if ($field_obj->is_auto_increment()) { |
|
910 | + // totally ignore auto increment IDs |
|
911 | + continue; |
|
912 | + } |
|
913 | + $arg_info = $field_obj->getSchema(); |
|
914 | + $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
915 | + $arg_info['required'] = $required; |
|
916 | + // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
917 | + unset($arg_info['readonly']); |
|
918 | + $schema_properties = $field_obj->getSchemaProperties(); |
|
919 | + if ( |
|
920 | + isset($schema_properties['raw']) |
|
921 | + && $field_obj->getSchemaType() === 'object' |
|
922 | + ) { |
|
923 | + // if there's a "raw" form of this argument, use those properties instead |
|
924 | + $arg_info = array_replace( |
|
925 | + $arg_info, |
|
926 | + $schema_properties['raw'] |
|
927 | + ); |
|
928 | + } |
|
929 | + $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
930 | + $field_obj, |
|
931 | + $field_obj->get_default_value(), |
|
932 | + $model_version_info->requestedVersion() |
|
933 | + ); |
|
934 | + // we do our own validation and sanitization within the controller |
|
935 | + if (function_exists('rest_validate_value_from_schema')) { |
|
936 | + $sanitize_callback = array( |
|
937 | + 'EED_Core_Rest_Api', |
|
938 | + 'default_sanitize_callback', |
|
939 | + ); |
|
940 | + } else { |
|
941 | + $sanitize_callback = null; |
|
942 | + } |
|
943 | + $arg_info['sanitize_callback'] = $sanitize_callback; |
|
944 | + $args_info[ $field_name ] = $arg_info; |
|
945 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
946 | + $gmt_arg_info = $arg_info; |
|
947 | + $gmt_arg_info['description'] = sprintf( |
|
948 | + esc_html__( |
|
949 | + '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
950 | + 'event_espresso' |
|
951 | + ), |
|
952 | + $field_obj->get_nicename(), |
|
953 | + $field_name |
|
954 | + ); |
|
955 | + $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
956 | + } |
|
957 | + } |
|
958 | + return $args_info; |
|
959 | + } |
|
960 | + |
|
961 | + |
|
962 | + /** |
|
963 | + * Replacement for WP API's 'rest_parse_request_arg'. |
|
964 | + * If the value is blank but not required, don't bother validating it. |
|
965 | + * Also, it uses our email validation instead of WP API's default. |
|
966 | + * |
|
967 | + * @param $value |
|
968 | + * @param WP_REST_Request $request |
|
969 | + * @param $param |
|
970 | + * @return bool|true|WP_Error |
|
971 | + * @throws InvalidArgumentException |
|
972 | + * @throws InvalidInterfaceException |
|
973 | + * @throws InvalidDataTypeException |
|
974 | + */ |
|
975 | + public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
976 | + { |
|
977 | + $attributes = $request->get_attributes(); |
|
978 | + if ( |
|
979 | + ! isset($attributes['args'][ $param ]) |
|
980 | + || ! is_array($attributes['args'][ $param ]) |
|
981 | + ) { |
|
982 | + $validation_result = true; |
|
983 | + } else { |
|
984 | + $args = $attributes['args'][ $param ]; |
|
985 | + if ( |
|
986 | + ( |
|
987 | + $value === '' |
|
988 | + || $value === null |
|
989 | + ) |
|
990 | + && (! isset($args['required']) |
|
991 | + || $args['required'] === false |
|
992 | + ) |
|
993 | + ) { |
|
994 | + // not required and not provided? that's cool |
|
995 | + $validation_result = true; |
|
996 | + } elseif ( |
|
997 | + isset($args['format']) |
|
998 | + && $args['format'] === 'email' |
|
999 | + ) { |
|
1000 | + $validation_result = true; |
|
1001 | + if (! self::_validate_email($value)) { |
|
1002 | + $validation_result = new WP_Error( |
|
1003 | + 'rest_invalid_param', |
|
1004 | + esc_html__( |
|
1005 | + 'The email address is not valid or does not exist.', |
|
1006 | + 'event_espresso' |
|
1007 | + ) |
|
1008 | + ); |
|
1009 | + } |
|
1010 | + } else { |
|
1011 | + $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
1012 | + } |
|
1013 | + } |
|
1014 | + if (is_wp_error($validation_result)) { |
|
1015 | + return $validation_result; |
|
1016 | + } |
|
1017 | + return rest_sanitize_request_arg($value, $request, $param); |
|
1018 | + } |
|
1019 | + |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
1023 | + * |
|
1024 | + * @param $email |
|
1025 | + * @return bool |
|
1026 | + * @throws InvalidArgumentException |
|
1027 | + * @throws InvalidInterfaceException |
|
1028 | + * @throws InvalidDataTypeException |
|
1029 | + */ |
|
1030 | + protected static function _validate_email($email) |
|
1031 | + { |
|
1032 | + try { |
|
1033 | + EmailAddressFactory::create($email); |
|
1034 | + return true; |
|
1035 | + } catch (EmailValidationException $e) { |
|
1036 | + return false; |
|
1037 | + } |
|
1038 | + } |
|
1039 | + |
|
1040 | + |
|
1041 | + /** |
|
1042 | + * Gets routes for the config |
|
1043 | + * |
|
1044 | + * @return array @see _register_model_routes |
|
1045 | + * @deprecated since version 4.9.1 |
|
1046 | + */ |
|
1047 | + protected function _register_config_routes() |
|
1048 | + { |
|
1049 | + $config_routes = array(); |
|
1050 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
1051 | + $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
1052 | + $version, |
|
1053 | + $hidden_endpoint |
|
1054 | + ); |
|
1055 | + } |
|
1056 | + return $config_routes; |
|
1057 | + } |
|
1058 | + |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * Gets routes for the config for the specified version |
|
1062 | + * |
|
1063 | + * @param string $version |
|
1064 | + * @param boolean $hidden_endpoint |
|
1065 | + * @return array |
|
1066 | + */ |
|
1067 | + protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
1068 | + { |
|
1069 | + return array( |
|
1070 | + 'config' => array( |
|
1071 | + array( |
|
1072 | + 'callback' => array( |
|
1073 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1074 | + 'handleRequest', |
|
1075 | + ), |
|
1076 | + 'methods' => WP_REST_Server::READABLE, |
|
1077 | + 'hidden_endpoint' => $hidden_endpoint, |
|
1078 | + 'callback_args' => array($version), |
|
1079 | + ), |
|
1080 | + ), |
|
1081 | + 'site_info' => array( |
|
1082 | + array( |
|
1083 | + 'callback' => array( |
|
1084 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1085 | + 'handleRequestSiteInfo', |
|
1086 | + ), |
|
1087 | + 'methods' => WP_REST_Server::READABLE, |
|
1088 | + 'hidden_endpoint' => $hidden_endpoint, |
|
1089 | + 'callback_args' => array($version), |
|
1090 | + ), |
|
1091 | + ), |
|
1092 | + ); |
|
1093 | + } |
|
1094 | + |
|
1095 | + |
|
1096 | + /** |
|
1097 | + * Gets the meta info routes |
|
1098 | + * |
|
1099 | + * @return array @see _register_model_routes |
|
1100 | + * @deprecated since version 4.9.1 |
|
1101 | + */ |
|
1102 | + protected function _register_meta_routes() |
|
1103 | + { |
|
1104 | + $meta_routes = array(); |
|
1105 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
1106 | + $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
1107 | + $version, |
|
1108 | + $hidden_endpoint |
|
1109 | + ); |
|
1110 | + } |
|
1111 | + return $meta_routes; |
|
1112 | + } |
|
1113 | + |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * @param string $version |
|
1117 | + * @param boolean $hidden_endpoint |
|
1118 | + * @return array |
|
1119 | + */ |
|
1120 | + protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
1121 | + { |
|
1122 | + return array( |
|
1123 | + 'resources' => array( |
|
1124 | + array( |
|
1125 | + 'callback' => array( |
|
1126 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
1127 | + 'handleRequestModelsMeta', |
|
1128 | + ), |
|
1129 | + 'methods' => WP_REST_Server::READABLE, |
|
1130 | + 'hidden_endpoint' => $hidden_endpoint, |
|
1131 | + 'callback_args' => array($version), |
|
1132 | + ), |
|
1133 | + ), |
|
1134 | + ); |
|
1135 | + } |
|
1136 | + |
|
1137 | + |
|
1138 | + /** |
|
1139 | + * Tries to hide old 4.6 endpoints from the |
|
1140 | + * |
|
1141 | + * @param array $route_data |
|
1142 | + * @return array |
|
1143 | + * @throws \EE_Error |
|
1144 | + */ |
|
1145 | + public static function hide_old_endpoints($route_data) |
|
1146 | + { |
|
1147 | + // allow API clients to override which endpoints get hidden, in case |
|
1148 | + // they want to discover particular endpoints |
|
1149 | + // also, we don't have access to the request so we have to just grab it from the superglobal |
|
1150 | + $force_show_ee_namespace = ltrim( |
|
1151 | + EED_Core_Rest_Api::getRequest()->getRequestParam('force_show_ee_namespace'), |
|
1152 | + '/' |
|
1153 | + ); |
|
1154 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
1155 | + foreach ($relative_urls as $resource_name => $endpoints) { |
|
1156 | + foreach ($endpoints as $key => $endpoint) { |
|
1157 | + // skip schema and other route options |
|
1158 | + if (! is_numeric($key)) { |
|
1159 | + continue; |
|
1160 | + } |
|
1161 | + // by default, hide "hidden_endpoint"s, unless the request indicates |
|
1162 | + // to $force_show_ee_namespace, in which case only show that one |
|
1163 | + // namespace's endpoints (and hide all others) |
|
1164 | + if ( |
|
1165 | + ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
1166 | + || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
1167 | + ) { |
|
1168 | + $full_route = '/' . ltrim($namespace, '/'); |
|
1169 | + $full_route .= '/' . ltrim($resource_name, '/'); |
|
1170 | + unset($route_data[ $full_route ]); |
|
1171 | + } |
|
1172 | + } |
|
1173 | + } |
|
1174 | + } |
|
1175 | + return $route_data; |
|
1176 | + } |
|
1177 | + |
|
1178 | + |
|
1179 | + /** |
|
1180 | + * Returns an array describing which versions of core support serving requests for. |
|
1181 | + * Keys are core versions' major and minor version, and values are the |
|
1182 | + * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
1183 | + * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
1184 | + * the answers table entirely, in which case it would be very difficult for |
|
1185 | + * it to serve 4.6-style responses. |
|
1186 | + * Versions of core that are missing from this array are unknowns. |
|
1187 | + * previous ver |
|
1188 | + * |
|
1189 | + * @return array |
|
1190 | + */ |
|
1191 | + public static function version_compatibilities() |
|
1192 | + { |
|
1193 | + return apply_filters( |
|
1194 | + 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
1195 | + array( |
|
1196 | + '4.8.29' => '4.8.29', |
|
1197 | + '4.8.33' => '4.8.29', |
|
1198 | + '4.8.34' => '4.8.29', |
|
1199 | + '4.8.36' => '4.8.29', |
|
1200 | + ) |
|
1201 | + ); |
|
1202 | + } |
|
1203 | + |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * Gets the latest API version served. Eg if there |
|
1207 | + * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
1208 | + * we are on core version 4.8.34, it will return the string "4.8.32" |
|
1209 | + * |
|
1210 | + * @return string |
|
1211 | + */ |
|
1212 | + public static function latest_rest_api_version() |
|
1213 | + { |
|
1214 | + $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
1215 | + $versions_served_keys = array_keys($versions_served); |
|
1216 | + return end($versions_served_keys); |
|
1217 | + } |
|
1218 | + |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
1222 | + * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
1223 | + * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
1224 | + * We also indicate whether or not this version should be put in the index or not |
|
1225 | + * |
|
1226 | + * @return array keys are API version numbers (just major and minor numbers), and values |
|
1227 | + * are whether or not they should be hidden |
|
1228 | + */ |
|
1229 | + public static function versions_served() |
|
1230 | + { |
|
1231 | + $versions_served = array(); |
|
1232 | + $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
1233 | + $lowest_compatible_version = end($possibly_served_versions); |
|
1234 | + reset($possibly_served_versions); |
|
1235 | + $versions_served_historically = array_keys($possibly_served_versions); |
|
1236 | + $latest_version = end($versions_served_historically); |
|
1237 | + reset($versions_served_historically); |
|
1238 | + // for each version of core we have ever served: |
|
1239 | + foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
1240 | + // if it's not above the current core version, and it's compatible with the current version of core |
|
1241 | + |
|
1242 | + if ($key_versioned_endpoint === $latest_version) { |
|
1243 | + // don't hide the latest version in the index |
|
1244 | + $versions_served[ $key_versioned_endpoint ] = false; |
|
1245 | + } elseif ( |
|
1246 | + version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
|
1247 | + && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
|
1248 | + ) { |
|
1249 | + // include, but hide, previous versions which are still supported |
|
1250 | + $versions_served[ $key_versioned_endpoint ] = true; |
|
1251 | + } elseif ( |
|
1252 | + apply_filters( |
|
1253 | + 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
1254 | + false, |
|
1255 | + $possibly_served_versions |
|
1256 | + ) |
|
1257 | + ) { |
|
1258 | + // if a version is no longer supported, don't include it in index or list of versions served |
|
1259 | + $versions_served[ $key_versioned_endpoint ] = true; |
|
1260 | + } |
|
1261 | + } |
|
1262 | + return $versions_served; |
|
1263 | + } |
|
1264 | + |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * Gets the major and minor version of EE core's version string |
|
1268 | + * |
|
1269 | + * @return string |
|
1270 | + */ |
|
1271 | + public static function core_version() |
|
1272 | + { |
|
1273 | + return apply_filters( |
|
1274 | + 'FHEE__EED_Core_REST_API__core_version', |
|
1275 | + implode( |
|
1276 | + '.', |
|
1277 | + array_slice( |
|
1278 | + explode( |
|
1279 | + '.', |
|
1280 | + espresso_version() |
|
1281 | + ), |
|
1282 | + 0, |
|
1283 | + 3 |
|
1284 | + ) |
|
1285 | + ) |
|
1286 | + ); |
|
1287 | + } |
|
1288 | + |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * Gets the default limit that should be used when querying for resources |
|
1292 | + * |
|
1293 | + * @return int |
|
1294 | + */ |
|
1295 | + public static function get_default_query_limit() |
|
1296 | + { |
|
1297 | + // we actually don't use a const because we want folks to always use |
|
1298 | + // this method, not the const directly |
|
1299 | + return apply_filters( |
|
1300 | + 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
1301 | + 50 |
|
1302 | + ); |
|
1303 | + } |
|
1304 | + |
|
1305 | + |
|
1306 | + /** |
|
1307 | + * |
|
1308 | + * @param string $version api version string (i.e. '4.8.36') |
|
1309 | + * @return array |
|
1310 | + */ |
|
1311 | + public static function getCollectionRoutesIndexedByModelName($version = '') |
|
1312 | + { |
|
1313 | + $version = empty($version) ? self::latest_rest_api_version() : $version; |
|
1314 | + $model_names = self::model_names_with_plural_routes($version); |
|
1315 | + $collection_routes = array(); |
|
1316 | + foreach ($model_names as $model_name => $model_class_name) { |
|
1317 | + $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/' |
|
1318 | + . EEH_Inflector::pluralize_and_lower($model_name); |
|
1319 | + } |
|
1320 | + return $collection_routes; |
|
1321 | + } |
|
1322 | + |
|
1323 | + |
|
1324 | + /** |
|
1325 | + * Returns an array of primary key names indexed by model names. |
|
1326 | + * @param string $version |
|
1327 | + * @return array |
|
1328 | + */ |
|
1329 | + public static function getPrimaryKeyNamesIndexedByModelName($version = '') |
|
1330 | + { |
|
1331 | + $version = empty($version) ? self::latest_rest_api_version() : $version; |
|
1332 | + $model_names = self::model_names_with_plural_routes($version); |
|
1333 | + $primary_key_items = array(); |
|
1334 | + foreach ($model_names as $model_name => $model_class_name) { |
|
1335 | + $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
|
1336 | + foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
|
1337 | + if (count($primary_keys) > 1) { |
|
1338 | + $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
1339 | + } else { |
|
1340 | + $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
1341 | + } |
|
1342 | + } |
|
1343 | + } |
|
1344 | + return $primary_key_items; |
|
1345 | + } |
|
1346 | + |
|
1347 | + /** |
|
1348 | + * Determines the EE REST API debug mode is activated, or not. |
|
1349 | + * @since 4.9.76.p |
|
1350 | + * @return bool |
|
1351 | + */ |
|
1352 | + public static function debugMode() |
|
1353 | + { |
|
1354 | + static $debug_mode = null; // could be class prop |
|
1355 | + if ($debug_mode === null) { |
|
1356 | + $debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE; |
|
1357 | + } |
|
1358 | + return $debug_mode; |
|
1359 | + } |
|
1360 | + |
|
1361 | + |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * run - initial module setup |
|
1365 | + * |
|
1366 | + * @access public |
|
1367 | + * @param WP $WP |
|
1368 | + * @return void |
|
1369 | + */ |
|
1370 | + public function run($WP) |
|
1371 | + { |
|
1372 | + } |
|
1373 | 1373 | } |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
139 | 139 | return; |
140 | 140 | } |
141 | - define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
141 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
142 | 142 | define( |
143 | 143 | 'TICKET_SELECTOR_TEMPLATES_PATH', |
144 | - str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/' |
|
144 | + str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/' |
|
145 | 145 | ); |
146 | 146 | // initialize config |
147 | 147 | EED_Ticket_Selector::instance()->set_config(); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public static function ticketSelector() |
165 | 165 | { |
166 | - if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
166 | + if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
167 | 167 | EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector( |
168 | 168 | EED_Ticket_Selector::getRequest(), |
169 | 169 | EED_Ticket_Selector::ticketConfig(), |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public static function getIframeEmbedButton() |
192 | 192 | { |
193 | - if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
193 | + if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
194 | 194 | self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
195 | 195 | } |
196 | 196 | return self::$iframe_embed_button; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | // add some style |
299 | 299 | wp_register_style( |
300 | 300 | 'ticket_selector', |
301 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
301 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css', |
|
302 | 302 | [], |
303 | 303 | EVENT_ESPRESSO_VERSION |
304 | 304 | ); |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | // make it dance |
307 | 307 | wp_register_script( |
308 | 308 | 'ticket_selector', |
309 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
309 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js', |
|
310 | 310 | ['espresso_core'], |
311 | 311 | EVENT_ESPRESSO_VERSION, |
312 | 312 | true |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | */ |
354 | 354 | public static function iframeCss(array $iframe_css) |
355 | 355 | { |
356 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
356 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css'; |
|
357 | 357 | return $iframe_css; |
358 | 358 | } |
359 | 359 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | */ |
367 | 367 | public static function iframeJs(array $iframe_js) |
368 | 368 | { |
369 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
369 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js'; |
|
370 | 370 | return $iframe_js; |
371 | 371 | } |
372 | 372 |
@@ -18,491 +18,491 @@ |
||
18 | 18 | */ |
19 | 19 | class EED_Ticket_Selector extends EED_Module |
20 | 20 | { |
21 | - /** |
|
22 | - * @var DisplayTicketSelector $ticket_selector |
|
23 | - */ |
|
24 | - private static $ticket_selector; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var TicketSelectorIframeEmbedButton $iframe_embed_button |
|
28 | - */ |
|
29 | - private static $iframe_embed_button; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @return EED_Module|EED_Ticket_Selector |
|
34 | - * @throws EE_Error |
|
35 | - * @throws ReflectionException |
|
36 | - */ |
|
37 | - public static function instance() |
|
38 | - { |
|
39 | - return parent::get_instance(__CLASS__); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @return EE_Ticket_Selector_Config |
|
45 | - * @throws EE_Error |
|
46 | - * @throws ReflectionException |
|
47 | - */ |
|
48 | - public static function ticketConfig() |
|
49 | - { |
|
50 | - EED_Ticket_Selector::instance()->set_config(); |
|
51 | - return EED_Ticket_Selector::instance()->config(); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - protected function set_config() |
|
59 | - { |
|
60 | - if ($this->_config instanceof EE_Ticket_Selector_Config) { |
|
61 | - return; |
|
62 | - } |
|
63 | - $this->set_config_section('template_settings'); |
|
64 | - $this->set_config_class('EE_Ticket_Selector_Config'); |
|
65 | - $this->set_config_name('EED_Ticket_Selector'); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
71 | - * |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public static function set_hooks() |
|
75 | - { |
|
76 | - // routing |
|
77 | - EE_Config::register_route( |
|
78 | - 'iframe', |
|
79 | - 'EED_Ticket_Selector', |
|
80 | - 'ticket_selector_iframe', |
|
81 | - 'ticket_selector' |
|
82 | - ); |
|
83 | - EE_Config::register_route( |
|
84 | - 'process_ticket_selections', |
|
85 | - 'EED_Ticket_Selector', |
|
86 | - 'process_ticket_selections' |
|
87 | - ); |
|
88 | - EE_Config::register_route( |
|
89 | - 'cancel_ticket_selections', |
|
90 | - 'EED_Ticket_Selector', |
|
91 | - 'cancel_ticket_selections' |
|
92 | - ); |
|
93 | - add_action('wp_loaded', ['EED_Ticket_Selector', 'set_definitions'], 2); |
|
94 | - add_action('AHEE_event_details_header_bottom', ['EED_Ticket_Selector', 'display_ticket_selector'], 10, 1); |
|
95 | - add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'translate_js_strings'], 0); |
|
96 | - add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'load_tckt_slctr_assets'], 10); |
|
97 | - EED_Ticket_Selector::loadIframeAssets(); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
103 | - * |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public static function set_hooks_admin() |
|
107 | - { |
|
108 | - // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
109 | - // to load assets for "espresso_events" page on the "edit" route (action) |
|
110 | - add_action( |
|
111 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit', |
|
112 | - ['EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'], |
|
113 | - 10 |
|
114 | - ); |
|
115 | - /** |
|
116 | - * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
117 | - * registrations work. |
|
118 | - */ |
|
119 | - add_action( |
|
120 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
121 | - ['EED_Ticket_Selector', 'set_definitions'], |
|
122 | - 10 |
|
123 | - ); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * set_definitions |
|
129 | - * |
|
130 | - * @return void |
|
131 | - * @throws EE_Error |
|
132 | - * @throws ReflectionException |
|
133 | - */ |
|
134 | - public static function set_definitions() |
|
135 | - { |
|
136 | - // don't do this twice |
|
137 | - if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
138 | - return; |
|
139 | - } |
|
140 | - define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
141 | - define( |
|
142 | - 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
143 | - str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/' |
|
144 | - ); |
|
145 | - // initialize config |
|
146 | - EED_Ticket_Selector::instance()->set_config(); |
|
147 | - // if config is not set, initialize |
|
148 | - if ( |
|
149 | - ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
150 | - ) { |
|
151 | - EED_Ticket_Selector::instance()->set_config(); |
|
152 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = |
|
153 | - EED_Ticket_Selector::instance()->config(); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return DisplayTicketSelector |
|
160 | - * @throws EE_Error |
|
161 | - * @throws ReflectionException |
|
162 | - */ |
|
163 | - public static function ticketSelector() |
|
164 | - { |
|
165 | - if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
166 | - EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector( |
|
167 | - EED_Ticket_Selector::getRequest(), |
|
168 | - EED_Ticket_Selector::ticketConfig(), |
|
169 | - EED_Events_Archive::is_iframe() |
|
170 | - ); |
|
171 | - } |
|
172 | - return EED_Ticket_Selector::$ticket_selector; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * gets the ball rolling |
|
178 | - * |
|
179 | - * @param WP $WP |
|
180 | - * @return void |
|
181 | - */ |
|
182 | - public function run($WP) |
|
183 | - { |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @return TicketSelectorIframeEmbedButton |
|
189 | - */ |
|
190 | - public static function getIframeEmbedButton() |
|
191 | - { |
|
192 | - if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
193 | - self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
|
194 | - } |
|
195 | - return self::$iframe_embed_button; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * ticket_selector_iframe_embed_button |
|
201 | - * |
|
202 | - * @return void |
|
203 | - */ |
|
204 | - public static function ticket_selector_iframe_embed_button() |
|
205 | - { |
|
206 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
207 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * ticket_selector_iframe |
|
213 | - * |
|
214 | - * @return void |
|
215 | - * @throws DomainException |
|
216 | - */ |
|
217 | - public function ticket_selector_iframe() |
|
218 | - { |
|
219 | - EE_Dependency_Map::register_dependencies( |
|
220 | - TicketSelectorIframe::class, |
|
221 | - [ |
|
222 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
223 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
224 | - 'EventEspresso\core\services\request\RequestInterface' => EE_Dependency_Map::load_from_cache, |
|
225 | - ] |
|
226 | - ); |
|
227 | - $ticket_selector_iframe = LoaderFactory::getLoader()->getNew(TicketSelectorIframe::class); |
|
228 | - $ticket_selector_iframe->display(); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * creates buttons for selecting number of attendees for an event |
|
234 | - * |
|
235 | - * @param WP_Post|int $event |
|
236 | - * @param bool $view_details |
|
237 | - * @return string |
|
238 | - * @throws EE_Error |
|
239 | - * @throws ReflectionException |
|
240 | - */ |
|
241 | - public static function display_ticket_selector($event = null, $view_details = false) |
|
242 | - { |
|
243 | - return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @return bool or FALSE |
|
249 | - * @throws EE_Error |
|
250 | - * @throws InvalidArgumentException |
|
251 | - * @throws InvalidInterfaceException |
|
252 | - * @throws InvalidDataTypeException |
|
253 | - * @throws ReflectionException |
|
254 | - */ |
|
255 | - public function process_ticket_selections() |
|
256 | - { |
|
257 | - /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
258 | - $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
259 | - return $form->processTicketSelections(); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * @return bool |
|
265 | - * @throws InvalidArgumentException |
|
266 | - * @throws InvalidInterfaceException |
|
267 | - * @throws InvalidDataTypeException |
|
268 | - * @throws EE_Error |
|
269 | - * @throws ReflectionException |
|
270 | - */ |
|
271 | - public static function cancel_ticket_selections() |
|
272 | - { |
|
273 | - /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
274 | - $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
275 | - return $form->cancelTicketSelections(); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - public static function translate_js_strings() |
|
283 | - { |
|
284 | - EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
285 | - 'please select a datetime', |
|
286 | - 'event_espresso' |
|
287 | - ); |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * @return void |
|
293 | - */ |
|
294 | - public static function load_tckt_slctr_assets() |
|
295 | - { |
|
296 | - if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
297 | - // add some style |
|
298 | - wp_register_style( |
|
299 | - 'ticket_selector', |
|
300 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
301 | - [], |
|
302 | - EVENT_ESPRESSO_VERSION |
|
303 | - ); |
|
304 | - wp_enqueue_style('ticket_selector'); |
|
305 | - // make it dance |
|
306 | - wp_register_script( |
|
307 | - 'ticket_selector', |
|
308 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
309 | - ['espresso_core'], |
|
310 | - EVENT_ESPRESSO_VERSION, |
|
311 | - true |
|
312 | - ); |
|
313 | - wp_enqueue_script('ticket_selector'); |
|
314 | - require_once EE_LIBRARIES |
|
315 | - . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'; |
|
316 | - EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * @return void |
|
323 | - */ |
|
324 | - public static function loadIframeAssets() |
|
325 | - { |
|
326 | - // for event lists |
|
327 | - add_filter( |
|
328 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
329 | - ['EED_Ticket_Selector', 'iframeCss'] |
|
330 | - ); |
|
331 | - add_filter( |
|
332 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
333 | - ['EED_Ticket_Selector', 'iframeJs'] |
|
334 | - ); |
|
335 | - // for ticket selectors |
|
336 | - add_filter( |
|
337 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
338 | - ['EED_Ticket_Selector', 'iframeCss'] |
|
339 | - ); |
|
340 | - add_filter( |
|
341 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
342 | - ['EED_Ticket_Selector', 'iframeJs'] |
|
343 | - ); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
349 | - * |
|
350 | - * @param array $iframe_css |
|
351 | - * @return array |
|
352 | - */ |
|
353 | - public static function iframeCss(array $iframe_css) |
|
354 | - { |
|
355 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
356 | - return $iframe_css; |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
362 | - * |
|
363 | - * @param array $iframe_js |
|
364 | - * @return array |
|
365 | - */ |
|
366 | - public static function iframeJs(array $iframe_js) |
|
367 | - { |
|
368 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
369 | - return $iframe_js; |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /****************************** DEPRECATED ******************************/ |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @return string |
|
378 | - * @throws EE_Error |
|
379 | - * @throws ReflectionException |
|
380 | - * @deprecated |
|
381 | - */ |
|
382 | - public static function display_view_details_btn() |
|
383 | - { |
|
384 | - // todo add doing_it_wrong() notice during next major version |
|
385 | - return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * @return string |
|
391 | - * @throws EE_Error |
|
392 | - * @throws ReflectionException |
|
393 | - * @deprecated |
|
394 | - */ |
|
395 | - public static function display_ticket_selector_submit() |
|
396 | - { |
|
397 | - // todo add doing_it_wrong() notice during next major version |
|
398 | - return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * @param string $permalink_string |
|
404 | - * @param int $id |
|
405 | - * @param string $new_title |
|
406 | - * @param string $new_slug |
|
407 | - * @return string |
|
408 | - * @throws InvalidArgumentException |
|
409 | - * @throws InvalidDataTypeException |
|
410 | - * @throws InvalidInterfaceException |
|
411 | - * @deprecated |
|
412 | - */ |
|
413 | - public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
414 | - { |
|
415 | - $request = self::getRequest(); |
|
416 | - // todo add doing_it_wrong() notice during next major version |
|
417 | - if ( |
|
418 | - $request->getRequestParam('page') === 'espresso_events' |
|
419 | - && $request->getRequestParam('action') === 'edit' |
|
420 | - ) { |
|
421 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
422 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
423 | - } |
|
424 | - return ''; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * @param int $ID |
|
430 | - * @param string $external_url |
|
431 | - * @return string |
|
432 | - * @throws EE_Error |
|
433 | - * @throws ReflectionException |
|
434 | - * @deprecated |
|
435 | - */ |
|
436 | - public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
437 | - { |
|
438 | - // todo add doing_it_wrong() notice during next major version |
|
439 | - return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * @return string |
|
445 | - * @throws EE_Error |
|
446 | - * @throws ReflectionException |
|
447 | - * @deprecated |
|
448 | - */ |
|
449 | - public static function ticket_selector_form_close() |
|
450 | - { |
|
451 | - // todo add doing_it_wrong() notice during next major version |
|
452 | - return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * @return string |
|
458 | - * @throws EE_Error |
|
459 | - * @throws ReflectionException |
|
460 | - * @deprecated |
|
461 | - */ |
|
462 | - public static function no_tkt_slctr_end_dv() |
|
463 | - { |
|
464 | - // todo add doing_it_wrong() notice during next major version |
|
465 | - return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * @return string |
|
471 | - * @throws EE_Error |
|
472 | - * @throws ReflectionException |
|
473 | - * @deprecated 4.9.13 |
|
474 | - */ |
|
475 | - public static function tkt_slctr_end_dv() |
|
476 | - { |
|
477 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * @return string |
|
483 | - * @throws EE_Error |
|
484 | - * @throws ReflectionException |
|
485 | - * @deprecated |
|
486 | - */ |
|
487 | - public static function clear_tkt_slctr() |
|
488 | - { |
|
489 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * @deprecated |
|
495 | - */ |
|
496 | - public static function load_tckt_slctr_assets_admin() |
|
497 | - { |
|
498 | - $request = self::getRequest(); |
|
499 | - // todo add doing_it_wrong() notice during next major version |
|
500 | - if ( |
|
501 | - $request->getRequestParam('page') === 'espresso_events' |
|
502 | - && $request->getRequestParam('action') === 'edit' |
|
503 | - ) { |
|
504 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
505 | - $iframe_embed_button->embedButtonAssets(); |
|
506 | - } |
|
507 | - } |
|
21 | + /** |
|
22 | + * @var DisplayTicketSelector $ticket_selector |
|
23 | + */ |
|
24 | + private static $ticket_selector; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var TicketSelectorIframeEmbedButton $iframe_embed_button |
|
28 | + */ |
|
29 | + private static $iframe_embed_button; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @return EED_Module|EED_Ticket_Selector |
|
34 | + * @throws EE_Error |
|
35 | + * @throws ReflectionException |
|
36 | + */ |
|
37 | + public static function instance() |
|
38 | + { |
|
39 | + return parent::get_instance(__CLASS__); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @return EE_Ticket_Selector_Config |
|
45 | + * @throws EE_Error |
|
46 | + * @throws ReflectionException |
|
47 | + */ |
|
48 | + public static function ticketConfig() |
|
49 | + { |
|
50 | + EED_Ticket_Selector::instance()->set_config(); |
|
51 | + return EED_Ticket_Selector::instance()->config(); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + protected function set_config() |
|
59 | + { |
|
60 | + if ($this->_config instanceof EE_Ticket_Selector_Config) { |
|
61 | + return; |
|
62 | + } |
|
63 | + $this->set_config_section('template_settings'); |
|
64 | + $this->set_config_class('EE_Ticket_Selector_Config'); |
|
65 | + $this->set_config_name('EED_Ticket_Selector'); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
71 | + * |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public static function set_hooks() |
|
75 | + { |
|
76 | + // routing |
|
77 | + EE_Config::register_route( |
|
78 | + 'iframe', |
|
79 | + 'EED_Ticket_Selector', |
|
80 | + 'ticket_selector_iframe', |
|
81 | + 'ticket_selector' |
|
82 | + ); |
|
83 | + EE_Config::register_route( |
|
84 | + 'process_ticket_selections', |
|
85 | + 'EED_Ticket_Selector', |
|
86 | + 'process_ticket_selections' |
|
87 | + ); |
|
88 | + EE_Config::register_route( |
|
89 | + 'cancel_ticket_selections', |
|
90 | + 'EED_Ticket_Selector', |
|
91 | + 'cancel_ticket_selections' |
|
92 | + ); |
|
93 | + add_action('wp_loaded', ['EED_Ticket_Selector', 'set_definitions'], 2); |
|
94 | + add_action('AHEE_event_details_header_bottom', ['EED_Ticket_Selector', 'display_ticket_selector'], 10, 1); |
|
95 | + add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'translate_js_strings'], 0); |
|
96 | + add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'load_tckt_slctr_assets'], 10); |
|
97 | + EED_Ticket_Selector::loadIframeAssets(); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
103 | + * |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public static function set_hooks_admin() |
|
107 | + { |
|
108 | + // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
109 | + // to load assets for "espresso_events" page on the "edit" route (action) |
|
110 | + add_action( |
|
111 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit', |
|
112 | + ['EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'], |
|
113 | + 10 |
|
114 | + ); |
|
115 | + /** |
|
116 | + * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
117 | + * registrations work. |
|
118 | + */ |
|
119 | + add_action( |
|
120 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
121 | + ['EED_Ticket_Selector', 'set_definitions'], |
|
122 | + 10 |
|
123 | + ); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * set_definitions |
|
129 | + * |
|
130 | + * @return void |
|
131 | + * @throws EE_Error |
|
132 | + * @throws ReflectionException |
|
133 | + */ |
|
134 | + public static function set_definitions() |
|
135 | + { |
|
136 | + // don't do this twice |
|
137 | + if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
138 | + return; |
|
139 | + } |
|
140 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
141 | + define( |
|
142 | + 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
143 | + str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/' |
|
144 | + ); |
|
145 | + // initialize config |
|
146 | + EED_Ticket_Selector::instance()->set_config(); |
|
147 | + // if config is not set, initialize |
|
148 | + if ( |
|
149 | + ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
150 | + ) { |
|
151 | + EED_Ticket_Selector::instance()->set_config(); |
|
152 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = |
|
153 | + EED_Ticket_Selector::instance()->config(); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return DisplayTicketSelector |
|
160 | + * @throws EE_Error |
|
161 | + * @throws ReflectionException |
|
162 | + */ |
|
163 | + public static function ticketSelector() |
|
164 | + { |
|
165 | + if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
166 | + EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector( |
|
167 | + EED_Ticket_Selector::getRequest(), |
|
168 | + EED_Ticket_Selector::ticketConfig(), |
|
169 | + EED_Events_Archive::is_iframe() |
|
170 | + ); |
|
171 | + } |
|
172 | + return EED_Ticket_Selector::$ticket_selector; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * gets the ball rolling |
|
178 | + * |
|
179 | + * @param WP $WP |
|
180 | + * @return void |
|
181 | + */ |
|
182 | + public function run($WP) |
|
183 | + { |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @return TicketSelectorIframeEmbedButton |
|
189 | + */ |
|
190 | + public static function getIframeEmbedButton() |
|
191 | + { |
|
192 | + if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
193 | + self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
|
194 | + } |
|
195 | + return self::$iframe_embed_button; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * ticket_selector_iframe_embed_button |
|
201 | + * |
|
202 | + * @return void |
|
203 | + */ |
|
204 | + public static function ticket_selector_iframe_embed_button() |
|
205 | + { |
|
206 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
207 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * ticket_selector_iframe |
|
213 | + * |
|
214 | + * @return void |
|
215 | + * @throws DomainException |
|
216 | + */ |
|
217 | + public function ticket_selector_iframe() |
|
218 | + { |
|
219 | + EE_Dependency_Map::register_dependencies( |
|
220 | + TicketSelectorIframe::class, |
|
221 | + [ |
|
222 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
223 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
224 | + 'EventEspresso\core\services\request\RequestInterface' => EE_Dependency_Map::load_from_cache, |
|
225 | + ] |
|
226 | + ); |
|
227 | + $ticket_selector_iframe = LoaderFactory::getLoader()->getNew(TicketSelectorIframe::class); |
|
228 | + $ticket_selector_iframe->display(); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * creates buttons for selecting number of attendees for an event |
|
234 | + * |
|
235 | + * @param WP_Post|int $event |
|
236 | + * @param bool $view_details |
|
237 | + * @return string |
|
238 | + * @throws EE_Error |
|
239 | + * @throws ReflectionException |
|
240 | + */ |
|
241 | + public static function display_ticket_selector($event = null, $view_details = false) |
|
242 | + { |
|
243 | + return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @return bool or FALSE |
|
249 | + * @throws EE_Error |
|
250 | + * @throws InvalidArgumentException |
|
251 | + * @throws InvalidInterfaceException |
|
252 | + * @throws InvalidDataTypeException |
|
253 | + * @throws ReflectionException |
|
254 | + */ |
|
255 | + public function process_ticket_selections() |
|
256 | + { |
|
257 | + /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
258 | + $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
259 | + return $form->processTicketSelections(); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * @return bool |
|
265 | + * @throws InvalidArgumentException |
|
266 | + * @throws InvalidInterfaceException |
|
267 | + * @throws InvalidDataTypeException |
|
268 | + * @throws EE_Error |
|
269 | + * @throws ReflectionException |
|
270 | + */ |
|
271 | + public static function cancel_ticket_selections() |
|
272 | + { |
|
273 | + /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
274 | + $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
275 | + return $form->cancelTicketSelections(); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + public static function translate_js_strings() |
|
283 | + { |
|
284 | + EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
285 | + 'please select a datetime', |
|
286 | + 'event_espresso' |
|
287 | + ); |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * @return void |
|
293 | + */ |
|
294 | + public static function load_tckt_slctr_assets() |
|
295 | + { |
|
296 | + if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
297 | + // add some style |
|
298 | + wp_register_style( |
|
299 | + 'ticket_selector', |
|
300 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
301 | + [], |
|
302 | + EVENT_ESPRESSO_VERSION |
|
303 | + ); |
|
304 | + wp_enqueue_style('ticket_selector'); |
|
305 | + // make it dance |
|
306 | + wp_register_script( |
|
307 | + 'ticket_selector', |
|
308 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
309 | + ['espresso_core'], |
|
310 | + EVENT_ESPRESSO_VERSION, |
|
311 | + true |
|
312 | + ); |
|
313 | + wp_enqueue_script('ticket_selector'); |
|
314 | + require_once EE_LIBRARIES |
|
315 | + . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'; |
|
316 | + EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * @return void |
|
323 | + */ |
|
324 | + public static function loadIframeAssets() |
|
325 | + { |
|
326 | + // for event lists |
|
327 | + add_filter( |
|
328 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
329 | + ['EED_Ticket_Selector', 'iframeCss'] |
|
330 | + ); |
|
331 | + add_filter( |
|
332 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
333 | + ['EED_Ticket_Selector', 'iframeJs'] |
|
334 | + ); |
|
335 | + // for ticket selectors |
|
336 | + add_filter( |
|
337 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
338 | + ['EED_Ticket_Selector', 'iframeCss'] |
|
339 | + ); |
|
340 | + add_filter( |
|
341 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
342 | + ['EED_Ticket_Selector', 'iframeJs'] |
|
343 | + ); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
349 | + * |
|
350 | + * @param array $iframe_css |
|
351 | + * @return array |
|
352 | + */ |
|
353 | + public static function iframeCss(array $iframe_css) |
|
354 | + { |
|
355 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
356 | + return $iframe_css; |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
362 | + * |
|
363 | + * @param array $iframe_js |
|
364 | + * @return array |
|
365 | + */ |
|
366 | + public static function iframeJs(array $iframe_js) |
|
367 | + { |
|
368 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
369 | + return $iframe_js; |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /****************************** DEPRECATED ******************************/ |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @return string |
|
378 | + * @throws EE_Error |
|
379 | + * @throws ReflectionException |
|
380 | + * @deprecated |
|
381 | + */ |
|
382 | + public static function display_view_details_btn() |
|
383 | + { |
|
384 | + // todo add doing_it_wrong() notice during next major version |
|
385 | + return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * @return string |
|
391 | + * @throws EE_Error |
|
392 | + * @throws ReflectionException |
|
393 | + * @deprecated |
|
394 | + */ |
|
395 | + public static function display_ticket_selector_submit() |
|
396 | + { |
|
397 | + // todo add doing_it_wrong() notice during next major version |
|
398 | + return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * @param string $permalink_string |
|
404 | + * @param int $id |
|
405 | + * @param string $new_title |
|
406 | + * @param string $new_slug |
|
407 | + * @return string |
|
408 | + * @throws InvalidArgumentException |
|
409 | + * @throws InvalidDataTypeException |
|
410 | + * @throws InvalidInterfaceException |
|
411 | + * @deprecated |
|
412 | + */ |
|
413 | + public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
414 | + { |
|
415 | + $request = self::getRequest(); |
|
416 | + // todo add doing_it_wrong() notice during next major version |
|
417 | + if ( |
|
418 | + $request->getRequestParam('page') === 'espresso_events' |
|
419 | + && $request->getRequestParam('action') === 'edit' |
|
420 | + ) { |
|
421 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
422 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
423 | + } |
|
424 | + return ''; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * @param int $ID |
|
430 | + * @param string $external_url |
|
431 | + * @return string |
|
432 | + * @throws EE_Error |
|
433 | + * @throws ReflectionException |
|
434 | + * @deprecated |
|
435 | + */ |
|
436 | + public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
437 | + { |
|
438 | + // todo add doing_it_wrong() notice during next major version |
|
439 | + return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * @return string |
|
445 | + * @throws EE_Error |
|
446 | + * @throws ReflectionException |
|
447 | + * @deprecated |
|
448 | + */ |
|
449 | + public static function ticket_selector_form_close() |
|
450 | + { |
|
451 | + // todo add doing_it_wrong() notice during next major version |
|
452 | + return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * @return string |
|
458 | + * @throws EE_Error |
|
459 | + * @throws ReflectionException |
|
460 | + * @deprecated |
|
461 | + */ |
|
462 | + public static function no_tkt_slctr_end_dv() |
|
463 | + { |
|
464 | + // todo add doing_it_wrong() notice during next major version |
|
465 | + return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * @return string |
|
471 | + * @throws EE_Error |
|
472 | + * @throws ReflectionException |
|
473 | + * @deprecated 4.9.13 |
|
474 | + */ |
|
475 | + public static function tkt_slctr_end_dv() |
|
476 | + { |
|
477 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * @return string |
|
483 | + * @throws EE_Error |
|
484 | + * @throws ReflectionException |
|
485 | + * @deprecated |
|
486 | + */ |
|
487 | + public static function clear_tkt_slctr() |
|
488 | + { |
|
489 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * @deprecated |
|
495 | + */ |
|
496 | + public static function load_tckt_slctr_assets_admin() |
|
497 | + { |
|
498 | + $request = self::getRequest(); |
|
499 | + // todo add doing_it_wrong() notice during next major version |
|
500 | + if ( |
|
501 | + $request->getRequestParam('page') === 'espresso_events' |
|
502 | + && $request->getRequestParam('action') === 'edit' |
|
503 | + ) { |
|
504 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
505 | + $iframe_embed_button->embedButtonAssets(); |
|
506 | + } |
|
507 | + } |
|
508 | 508 | } |
@@ -3,102 +3,102 @@ |
||
3 | 3 | |
4 | 4 | <h4> |
5 | 5 | <?php |
6 | - esc_html_e( |
|
7 | - 'You may be able to find an answer for your question or concern here:', |
|
8 | - 'event_espresso' |
|
9 | - ); |
|
10 | - ?> |
|
6 | + esc_html_e( |
|
7 | + 'You may be able to find an answer for your question or concern here:', |
|
8 | + 'event_espresso' |
|
9 | + ); |
|
10 | + ?> |
|
11 | 11 | </h4> |
12 | 12 | <ol> |
13 | 13 | <li> |
14 | 14 | <strong><em><?php esc_html_e('A known issue.', 'event_espresso'); ?></em></strong> |
15 | 15 | <?php |
16 | - printf( |
|
17 | - esc_html__( |
|
18 | - 'Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', |
|
19 | - 'event_espresso' |
|
20 | - ), |
|
21 | - '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">', |
|
22 | - '</a>', |
|
23 | - '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', |
|
24 | - '<a href="https://eventespresso.com/support/forums/" target="_blank">' |
|
25 | - ); |
|
26 | - ?> |
|
16 | + printf( |
|
17 | + esc_html__( |
|
18 | + 'Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', |
|
19 | + 'event_espresso' |
|
20 | + ), |
|
21 | + '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">', |
|
22 | + '</a>', |
|
23 | + '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', |
|
24 | + '<a href="https://eventespresso.com/support/forums/" target="_blank">' |
|
25 | + ); |
|
26 | + ?> |
|
27 | 27 | </li> |
28 | 28 | <li> |
29 | 29 | <strong><em><?php esc_html_e('A plugin conflict.', 'event_espresso'); ?></em></strong> |
30 | 30 | <?php |
31 | - esc_html_e( |
|
32 | - 'You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', |
|
33 | - 'event_espresso' |
|
34 | - ); |
|
35 | - ?> |
|
31 | + esc_html_e( |
|
32 | + 'You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', |
|
33 | + 'event_espresso' |
|
34 | + ); |
|
35 | + ?> |
|
36 | 36 | </li> |
37 | 37 | <li> |
38 | 38 | <strong><em><?php esc_html_e('A theme conflict.', 'event_espresso'); ?></em></strong> |
39 | 39 | <?php |
40 | - $default_theme = wp_get_theme(WP_DEFAULT_THEME); |
|
40 | + $default_theme = wp_get_theme(WP_DEFAULT_THEME); |
|
41 | 41 | |
42 | - if ($default_theme->exists()) { |
|
43 | - printf( |
|
44 | - esc_html__( |
|
45 | - 'If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', |
|
46 | - 'event_espresso' |
|
47 | - ), |
|
48 | - $default_theme->get('Name') |
|
49 | - ); |
|
50 | - } else { |
|
51 | - esc_html_e( |
|
52 | - 'If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', |
|
53 | - 'event_espresso' |
|
54 | - ); |
|
55 | - } |
|
56 | - ?> |
|
42 | + if ($default_theme->exists()) { |
|
43 | + printf( |
|
44 | + esc_html__( |
|
45 | + 'If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', |
|
46 | + 'event_espresso' |
|
47 | + ), |
|
48 | + $default_theme->get('Name') |
|
49 | + ); |
|
50 | + } else { |
|
51 | + esc_html_e( |
|
52 | + 'If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', |
|
53 | + 'event_espresso' |
|
54 | + ); |
|
55 | + } |
|
56 | + ?> |
|
57 | 57 | <?php |
58 | - esc_html_e( |
|
59 | - 'If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', |
|
60 | - 'event_espresso' |
|
61 | - ); |
|
62 | - ?> |
|
58 | + esc_html_e( |
|
59 | + 'If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', |
|
60 | + 'event_espresso' |
|
61 | + ); |
|
62 | + ?> |
|
63 | 63 | </li> |
64 | 64 | </ol> |
65 | 65 | |
66 | 66 | <p> |
67 | 67 | <?php |
68 | - esc_html_e( |
|
69 | - 'If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', |
|
70 | - 'event_espresso' |
|
71 | - ); |
|
72 | - ?> |
|
68 | + esc_html_e( |
|
69 | + 'If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', |
|
70 | + 'event_espresso' |
|
71 | + ); |
|
72 | + ?> |
|
73 | 73 | </p> |
74 | 74 | <p> |
75 | 75 | <?php |
76 | - printf( |
|
77 | - esc_html__( |
|
78 | - 'Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - '<a href="https://eventespresso.com/support/forums/" target="_blank">', |
|
82 | - '</a>', |
|
83 | - '<strong>', |
|
84 | - '</strong>', |
|
85 | - '<a href="#espresso_important_information_settings">' |
|
86 | - ); |
|
87 | - ?> |
|
76 | + printf( |
|
77 | + esc_html__( |
|
78 | + 'Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + '<a href="https://eventespresso.com/support/forums/" target="_blank">', |
|
82 | + '</a>', |
|
83 | + '<strong>', |
|
84 | + '</strong>', |
|
85 | + '<a href="#espresso_important_information_settings">' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | |
90 | 90 | <h4><?php esc_html_e('Have an emergency?', 'event_espresso'); ?></h4> |
91 | 91 | |
92 | 92 | <p> |
93 | 93 | <?php |
94 | - printf( |
|
95 | - esc_html__( |
|
96 | - 'We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', |
|
97 | - 'event_espresso' |
|
98 | - ), |
|
99 | - '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">', |
|
100 | - '</a>' |
|
101 | - ); |
|
102 | - ?> |
|
94 | + printf( |
|
95 | + esc_html__( |
|
96 | + 'We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', |
|
97 | + 'event_espresso' |
|
98 | + ), |
|
99 | + '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">', |
|
100 | + '</a>' |
|
101 | + ); |
|
102 | + ?> |
|
103 | 103 | </p> |
104 | 104 | </div> |
105 | 105 | \ No newline at end of file |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function __construct($routing = true) |
55 | 55 | { |
56 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
57 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
56 | + require_once(EE_MODELS.'EEM_Question.model.php'); |
|
57 | + require_once(EE_MODELS.'EEM_Question_Group.model.php'); |
|
58 | 58 | $this->_question_model = EEM_Question::instance(); |
59 | 59 | $this->_question_group_model = EEM_Question_Group::instance(); |
60 | 60 | parent::__construct($routing); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | protected function _set_page_routes() |
93 | 93 | { |
94 | - $qst_id = |
|
94 | + $qst_id = |
|
95 | 95 | ! empty($this->_req_data['QST_ID']) |
96 | 96 | ? $this->_req_data['QST_ID'] |
97 | 97 | : 0; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | { |
235 | 235 | wp_register_style( |
236 | 236 | 'espresso_registration', |
237 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', |
|
237 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', |
|
238 | 238 | [], |
239 | 239 | EVENT_ESPRESSO_VERSION |
240 | 240 | ); |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $this->load_scripts_styles_forms(); |
292 | 292 | wp_register_script( |
293 | 293 | 'espresso_registration_form_single', |
294 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', |
|
294 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', |
|
295 | 295 | ['jquery-ui-sortable'], |
296 | 296 | EVENT_ESPRESSO_VERSION, |
297 | 297 | true |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | |
311 | 311 | public function recaptcha_info_help_tab() |
312 | 312 | { |
313 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
313 | + $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php'; |
|
314 | 314 | EEH_Template::display_template($template, []); |
315 | 315 | } |
316 | 316 | |
@@ -359,16 +359,16 @@ discard block |
||
359 | 359 | { |
360 | 360 | $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
361 | 361 | $this->_template_args['preview_img'] = |
362 | - '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' |
|
362 | + '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="' |
|
363 | 363 | . esc_attr__( |
364 | 364 | 'Preview Question Groups Overview List Table screenshot', |
365 | 365 | 'event_espresso' |
366 | - ) . '" />'; |
|
366 | + ).'" />'; |
|
367 | 367 | $this->_template_args['preview_text'] = '<strong>' |
368 | 368 | . esc_html__( |
369 | 369 | 'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
370 | 370 | 'event_espresso' |
371 | - ) . '</strong>'; |
|
371 | + ).'</strong>'; |
|
372 | 372 | $this->display_admin_caf_preview_page('question_groups_tab'); |
373 | 373 | } |
374 | 374 | |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | |
388 | 388 | // some initial checks for proper values. |
389 | 389 | // if QST_admin_only, then no matter what QST_required is we disable. |
390 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
390 | + if ( ! empty($this->_req_data['QST_admin_only'])) { |
|
391 | 391 | $this->_req_data['QST_required'] = 0; |
392 | 392 | } |
393 | 393 | // if the question shouldn't have a max length, don't let them set one |
@@ -414,19 +414,19 @@ discard block |
||
414 | 414 | $QSG_name = isset($this->_req_data['QSG_name']) |
415 | 415 | ? $this->_req_data['QSG_name'] |
416 | 416 | : ''; |
417 | - $set_column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
417 | + $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true); |
|
418 | 418 | } elseif ( |
419 | 419 | $fieldName === 'QST_admin_label' |
420 | 420 | && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label'])) |
421 | 421 | ) { |
422 | 422 | // the admin label is blank, use a slug version of the question text |
423 | - $QST_text = |
|
423 | + $QST_text = |
|
424 | 424 | isset($this->_req_data['QST_display_text']) |
425 | 425 | ? $this->_req_data['QST_display_text'] |
426 | 426 | : ''; |
427 | - $set_column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
428 | - } elseif ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
429 | - $set_column_values[ $fieldName ] = 0; |
|
427 | + $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
428 | + } elseif ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) { |
|
429 | + $set_column_values[$fieldName] = 0; |
|
430 | 430 | } elseif ($fieldName === 'QST_max') { |
431 | 431 | $qst_system = EEM_Question::instance()->get_var( |
432 | 432 | [ |
@@ -438,23 +438,23 @@ discard block |
||
438 | 438 | ], |
439 | 439 | 'QST_system' |
440 | 440 | ); |
441 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
441 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
442 | 442 | if ( |
443 | 443 | empty($this->_req_data['QST_max']) || $this->_req_data['QST_max'] > $max_max |
444 | 444 | ) { |
445 | - $set_column_values[ $fieldName ] = $max_max; |
|
445 | + $set_column_values[$fieldName] = $max_max; |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | |
449 | 449 | |
450 | 450 | // only add a property to the array if it's not null (otherwise the model should just use the default value) |
451 | 451 | if ( |
452 | - ! isset($set_column_values[ $fieldName ]) && isset($this->_req_data[ $fieldName ]) |
|
452 | + ! isset($set_column_values[$fieldName]) && isset($this->_req_data[$fieldName]) |
|
453 | 453 | ) { |
454 | - $set_column_values[ $fieldName ] = $this->_req_data[ $fieldName ]; |
|
454 | + $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
455 | 455 | } |
456 | 456 | } |
457 | - return $set_column_values;// validation fo this data to be performed by the model before insertion. |
|
457 | + return $set_column_values; // validation fo this data to be performed by the model before insertion. |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | // add PRC_ID to title if editing |
497 | 497 | $this->_admin_page_title = |
498 | 498 | $ID |
499 | - ? $this->_admin_page_title . ' # ' . $ID |
|
499 | + ? $this->_admin_page_title.' # '.$ID |
|
500 | 500 | : $this->_admin_page_title; |
501 | 501 | if ($ID) { |
502 | 502 | $question = $this->_question_model->get_one_by_ID($ID); |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
533 | 533 | $this->_set_publish_post_box_vars('id', $ID); |
534 | 534 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
535 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
535 | + REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', |
|
536 | 536 | $this->_template_args, |
537 | 537 | true |
538 | 538 | ); |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
555 | 555 | foreach ($question_type_descriptions as $type => $question_type_description) { |
556 | 556 | if ($type == 'HTML_TEXTAREA') { |
557 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
557 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
558 | 558 | $question_type_description .= sprintf( |
559 | 559 | esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
560 | 560 | '<br/>', |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | } |
564 | 564 | $descriptions .= EEH_HTML::p( |
565 | 565 | $question_type_description, |
566 | - 'question_type_description-' . $type, |
|
566 | + 'question_type_description-'.$type, |
|
567 | 567 | 'question_type_description description', |
568 | 568 | 'display:none;' |
569 | 569 | ); |
@@ -598,11 +598,11 @@ discard block |
||
598 | 598 | // trash removed options, save old ones |
599 | 599 | // get list of all options |
600 | 600 | $options = $question->options(); |
601 | - if (! empty($options)) { |
|
601 | + if ( ! empty($options)) { |
|
602 | 602 | foreach ($options as $option_ID => $option) { |
603 | 603 | $option_req_index = $this->_get_option_req_data_index($option_ID); |
604 | 604 | if ($option_req_index !== false) { |
605 | - $option->save($this->_req_data['question_options'][ $option_req_index ]); |
|
605 | + $option->save($this->_req_data['question_options'][$option_req_index]); |
|
606 | 606 | } else { |
607 | 607 | // not found, remove it |
608 | 608 | $option->delete(); |
@@ -693,11 +693,11 @@ discard block |
||
693 | 693 | (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
694 | 694 | ? $this->_req_data['order'] |
695 | 695 | : 'ASC'; |
696 | - $orderby_field = |
|
696 | + $orderby_field = |
|
697 | 697 | $model instanceof EEM_Question |
698 | 698 | ? 'QST_ID' |
699 | 699 | : 'QSG_order'; |
700 | - $field_to_order_by = |
|
700 | + $field_to_order_by = |
|
701 | 701 | empty($this->_req_data['orderby']) |
702 | 702 | ? $orderby_field |
703 | 703 | : $this->_req_data['orderby']; |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | array_key_exists('s', $this->_req_data) |
707 | 707 | ? $this->_req_data['s'] |
708 | 708 | : null; |
709 | - if (! empty($search_string)) { |
|
709 | + if ( ! empty($search_string)) { |
|
710 | 710 | if ($model instanceof EEM_Question_Group) { |
711 | 711 | $query_params[0] = [ |
712 | 712 | 'OR' => [ |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | $QST = EEM_Question::instance(); |
769 | 769 | $query_params = $this->get_query_params($QST, $per_page, $current_page); |
770 | 770 | if ($count) { |
771 | - $where = |
|
771 | + $where = |
|
772 | 772 | isset($query_params[0]) |
773 | 773 | ? [$query_params[0]] |
774 | 774 | : []; |
@@ -15,707 +15,707 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class Registration_Form_Admin_Page extends EE_Admin_Page |
17 | 17 | { |
18 | - /** |
|
19 | - * holds the specific question object for the question details screen |
|
20 | - * |
|
21 | - * @var EE_Question $_question |
|
22 | - */ |
|
23 | - protected $_question; |
|
24 | - |
|
25 | - /** |
|
26 | - * holds the specific question group object for the question group details screen |
|
27 | - * |
|
28 | - * @var EE_Question_Group $_question_group |
|
29 | - */ |
|
30 | - protected $_question_group; |
|
31 | - |
|
32 | - /** |
|
33 | - *_question_model EEM_Question model instance (for queries) |
|
34 | - * |
|
35 | - * @var EEM_Question $_question_model ; |
|
36 | - */ |
|
37 | - protected $_question_model; |
|
38 | - |
|
39 | - /** |
|
40 | - * _question_group_model EEM_Question_group instance (for queries) |
|
41 | - * |
|
42 | - * @var EEM_Question_Group $_question_group_model |
|
43 | - */ |
|
44 | - protected $_question_group_model; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @Constructor |
|
49 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
50 | - * @throws EE_Error |
|
51 | - * @throws ReflectionException |
|
52 | - */ |
|
53 | - public function __construct($routing = true) |
|
54 | - { |
|
55 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
56 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
57 | - $this->_question_model = EEM_Question::instance(); |
|
58 | - $this->_question_group_model = EEM_Question_Group::instance(); |
|
59 | - parent::__construct($routing); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - protected function _init_page_props() |
|
64 | - { |
|
65 | - $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
66 | - $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
67 | - $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
68 | - $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - protected function _ajax_hooks() |
|
73 | - { |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - protected function _define_page_props() |
|
78 | - { |
|
79 | - $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
80 | - $this->_labels = [ |
|
81 | - 'buttons' => [ |
|
82 | - 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
83 | - ], |
|
84 | - ]; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - *_set_page_routes |
|
90 | - */ |
|
91 | - protected function _set_page_routes() |
|
92 | - { |
|
93 | - $qst_id = |
|
94 | - ! empty($this->_req_data['QST_ID']) |
|
95 | - ? $this->_req_data['QST_ID'] |
|
96 | - : 0; |
|
97 | - $this->_page_routes = [ |
|
98 | - 'default' => [ |
|
99 | - 'func' => '_questions_overview_list_table', |
|
100 | - 'capability' => 'ee_read_questions', |
|
101 | - ], |
|
102 | - |
|
103 | - 'edit_question' => [ |
|
104 | - 'func' => '_edit_question', |
|
105 | - 'capability' => 'ee_edit_question', |
|
106 | - 'obj_id' => $qst_id, |
|
107 | - 'args' => ['edit'], |
|
108 | - ], |
|
109 | - |
|
110 | - 'question_groups' => [ |
|
111 | - 'func' => '_questions_groups_preview', |
|
112 | - 'capability' => 'ee_read_question_groups', |
|
113 | - ], |
|
114 | - |
|
115 | - 'update_question' => [ |
|
116 | - 'func' => '_insert_or_update_question', |
|
117 | - 'args' => ['new_question' => false], |
|
118 | - 'capability' => 'ee_edit_question', |
|
119 | - 'obj_id' => $qst_id, |
|
120 | - 'noheader' => true, |
|
121 | - ], |
|
122 | - ]; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - protected function _set_page_config() |
|
127 | - { |
|
128 | - $this->_page_config = [ |
|
129 | - 'default' => [ |
|
130 | - 'nav' => [ |
|
131 | - 'label' => esc_html__('Questions', 'event_espresso'), |
|
132 | - 'order' => 10, |
|
133 | - ], |
|
134 | - 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
135 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
136 | - 'help_tabs' => [ |
|
137 | - 'registration_form_questions_overview_help_tab' => [ |
|
138 | - 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
139 | - 'filename' => 'registration_form_questions_overview', |
|
140 | - ], |
|
141 | - 'registration_form_questions_overview_table_column_headings_help_tab' => [ |
|
142 | - 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
143 | - 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
144 | - ], |
|
145 | - 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => [ |
|
146 | - 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
147 | - 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
148 | - ], |
|
149 | - ], |
|
150 | - 'require_nonce' => false, |
|
151 | - 'qtips' => [ |
|
152 | - 'EE_Registration_Form_Tips', |
|
153 | - ]/**/ |
|
154 | - ], |
|
155 | - |
|
156 | - 'question_groups' => [ |
|
157 | - 'nav' => [ |
|
158 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
159 | - 'order' => 20, |
|
160 | - ], |
|
161 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
162 | - 'help_tabs' => [ |
|
163 | - 'registration_form_question_groups_help_tab' => [ |
|
164 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
165 | - 'filename' => 'registration_form_question_groups', |
|
166 | - ], |
|
167 | - ], |
|
168 | - 'require_nonce' => false, |
|
169 | - ], |
|
170 | - |
|
171 | - 'edit_question' => [ |
|
172 | - 'nav' => [ |
|
173 | - 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
174 | - 'order' => 15, |
|
175 | - 'persistent' => false, |
|
176 | - 'url' => isset($this->_req_data['question_id']) |
|
177 | - ? add_query_arg( |
|
178 | - ['question_id' => $this->_req_data['question_id']], |
|
179 | - $this->_current_page_view_url |
|
180 | - ) |
|
181 | - : $this->_admin_base_url, |
|
182 | - ], |
|
183 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
184 | - 'help_tabs' => [ |
|
185 | - 'registration_form_edit_question_group_help_tab' => [ |
|
186 | - 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
187 | - 'filename' => 'registration_form_edit_question', |
|
188 | - ], |
|
189 | - ], |
|
190 | - 'require_nonce' => false, |
|
191 | - ], |
|
192 | - ]; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - protected function _add_screen_options() |
|
197 | - { |
|
198 | - // todo |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - protected function _add_screen_options_default() |
|
203 | - { |
|
204 | - $page_title = $this->_admin_page_title; |
|
205 | - $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
206 | - $this->_per_page_screen_option(); |
|
207 | - $this->_admin_page_title = $page_title; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - protected function _add_screen_options_question_groups() |
|
212 | - { |
|
213 | - $page_title = $this->_admin_page_title; |
|
214 | - $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
215 | - $this->_per_page_screen_option(); |
|
216 | - $this->_admin_page_title = $page_title; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - // none of the below group are currently used for Event Categories |
|
221 | - protected function _add_feature_pointers() |
|
222 | - { |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - public function load_scripts_styles() |
|
227 | - { |
|
228 | - wp_register_style( |
|
229 | - 'espresso_registration', |
|
230 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', |
|
231 | - [], |
|
232 | - EVENT_ESPRESSO_VERSION |
|
233 | - ); |
|
234 | - wp_enqueue_style('espresso_registration'); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - public function admin_init() |
|
239 | - { |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - public function admin_notices() |
|
244 | - { |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - public function admin_footer_scripts() |
|
249 | - { |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - public function load_scripts_styles_default() |
|
254 | - { |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * @throws EE_Error |
|
260 | - */ |
|
261 | - public function load_scripts_styles_add_question() |
|
262 | - { |
|
263 | - $this->load_scripts_styles_question_details(); |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @throws EE_Error |
|
269 | - */ |
|
270 | - public function load_scripts_styles_edit_question() |
|
271 | - { |
|
272 | - $this->load_scripts_styles_question_details(); |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Loads the JS required for adding or editing a question |
|
278 | - * |
|
279 | - * @throws EE_Error |
|
280 | - * @throws EE_Error |
|
281 | - */ |
|
282 | - protected function load_scripts_styles_question_details() |
|
283 | - { |
|
284 | - $this->load_scripts_styles_forms(); |
|
285 | - wp_register_script( |
|
286 | - 'espresso_registration_form_single', |
|
287 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', |
|
288 | - ['jquery-ui-sortable'], |
|
289 | - EVENT_ESPRESSO_VERSION, |
|
290 | - true |
|
291 | - ); |
|
292 | - wp_enqueue_script('espresso_registration_form_single'); |
|
293 | - wp_localize_script( |
|
294 | - 'espresso_registration_form_single', |
|
295 | - 'ee_question_data', |
|
296 | - [ |
|
297 | - 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
298 | - 'question_type_with_options' => EEM_Question::instance()->question_types_with_options(), |
|
299 | - ] |
|
300 | - ); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - public function recaptcha_info_help_tab() |
|
305 | - { |
|
306 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
307 | - EEH_Template::display_template($template, []); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - public function load_scripts_styles_forms() |
|
312 | - { |
|
313 | - // styles |
|
314 | - wp_enqueue_style('espresso-ui-theme'); |
|
315 | - // scripts |
|
316 | - wp_enqueue_script('ee_admin_js'); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - protected function _set_list_table_views_default() |
|
321 | - { |
|
322 | - $this->_views = [ |
|
323 | - 'all' => [ |
|
324 | - 'slug' => 'all', |
|
325 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
326 | - 'count' => 0, |
|
327 | - ], |
|
328 | - ]; |
|
329 | - |
|
330 | - if ( |
|
331 | - EE_Registry::instance()->CAP->current_user_can( |
|
332 | - 'ee_delete_questions', |
|
333 | - 'espresso_registration_form_trash_questions' |
|
334 | - ) |
|
335 | - ) { |
|
336 | - $this->_views['trash'] = [ |
|
337 | - 'slug' => 'trash', |
|
338 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
339 | - 'count' => 0, |
|
340 | - ]; |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * This just previews the question groups tab that comes in caffeinated. |
|
347 | - * |
|
348 | - * @return void html |
|
349 | - * @throws EE_Error |
|
350 | - */ |
|
351 | - protected function _questions_groups_preview() |
|
352 | - { |
|
353 | - $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
354 | - $this->_template_args['preview_img'] = |
|
355 | - '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' |
|
356 | - . esc_attr__( |
|
357 | - 'Preview Question Groups Overview List Table screenshot', |
|
358 | - 'event_espresso' |
|
359 | - ) . '" />'; |
|
360 | - $this->_template_args['preview_text'] = '<strong>' |
|
361 | - . esc_html__( |
|
362 | - 'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
363 | - 'event_espresso' |
|
364 | - ) . '</strong>'; |
|
365 | - $this->display_admin_caf_preview_page('question_groups_tab'); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Extracts the question field's values from the POST request to update or insert them |
|
371 | - * |
|
372 | - * @param EEM_Base $model |
|
373 | - * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
374 | - * @throws EE_Error |
|
375 | - */ |
|
376 | - protected function _set_column_values_for(EEM_Base $model) |
|
377 | - { |
|
378 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
379 | - $set_column_values = []; |
|
380 | - |
|
381 | - // some initial checks for proper values. |
|
382 | - // if QST_admin_only, then no matter what QST_required is we disable. |
|
383 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
384 | - $this->_req_data['QST_required'] = 0; |
|
385 | - } |
|
386 | - // if the question shouldn't have a max length, don't let them set one |
|
387 | - if ( |
|
388 | - ! isset( |
|
389 | - $this->_req_data['QST_type'], |
|
390 | - $this->_req_data['QST_max'] |
|
391 | - ) |
|
392 | - || ! in_array( |
|
393 | - $this->_req_data['QST_type'], |
|
394 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
395 | - true |
|
396 | - ) |
|
397 | - ) { |
|
398 | - // they're not allowed to set the max |
|
399 | - $this->_req_data['QST_max'] = null; |
|
400 | - } |
|
401 | - foreach ($model->field_settings() as $fieldName => $settings) { |
|
402 | - // basically if QSG_identifier is empty or not set |
|
403 | - if ( |
|
404 | - $fieldName === 'QSG_identifier' |
|
405 | - && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier'])) |
|
406 | - ) { |
|
407 | - $QSG_name = isset($this->_req_data['QSG_name']) |
|
408 | - ? $this->_req_data['QSG_name'] |
|
409 | - : ''; |
|
410 | - $set_column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
411 | - } elseif ( |
|
412 | - $fieldName === 'QST_admin_label' |
|
413 | - && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label'])) |
|
414 | - ) { |
|
415 | - // the admin label is blank, use a slug version of the question text |
|
416 | - $QST_text = |
|
417 | - isset($this->_req_data['QST_display_text']) |
|
418 | - ? $this->_req_data['QST_display_text'] |
|
419 | - : ''; |
|
420 | - $set_column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
421 | - } elseif ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
422 | - $set_column_values[ $fieldName ] = 0; |
|
423 | - } elseif ($fieldName === 'QST_max') { |
|
424 | - $qst_system = EEM_Question::instance()->get_var( |
|
425 | - [ |
|
426 | - [ |
|
427 | - 'QST_ID' => isset($this->_req_data['QST_ID']) |
|
428 | - ? $this->_req_data['QST_ID'] |
|
429 | - : 0, |
|
430 | - ], |
|
431 | - ], |
|
432 | - 'QST_system' |
|
433 | - ); |
|
434 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
435 | - if ( |
|
436 | - empty($this->_req_data['QST_max']) || $this->_req_data['QST_max'] > $max_max |
|
437 | - ) { |
|
438 | - $set_column_values[ $fieldName ] = $max_max; |
|
439 | - } |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - // only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
444 | - if ( |
|
445 | - ! isset($set_column_values[ $fieldName ]) && isset($this->_req_data[ $fieldName ]) |
|
446 | - ) { |
|
447 | - $set_column_values[ $fieldName ] = $this->_req_data[ $fieldName ]; |
|
448 | - } |
|
449 | - } |
|
450 | - return $set_column_values;// validation fo this data to be performed by the model before insertion. |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - *_questions_overview_list_table |
|
456 | - * |
|
457 | - * @throws EE_Error |
|
458 | - */ |
|
459 | - protected function _questions_overview_list_table() |
|
460 | - { |
|
461 | - $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
462 | - $this->display_admin_list_table_page_with_sidebar(); |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * _edit_question |
|
468 | - * |
|
469 | - * @throws EE_Error |
|
470 | - * @throws ReflectionException |
|
471 | - */ |
|
472 | - protected function _edit_question() |
|
473 | - { |
|
474 | - $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) |
|
475 | - ? absint($this->_req_data['QST_ID']) |
|
476 | - : false; |
|
477 | - |
|
478 | - switch ($this->_req_action) { |
|
479 | - case 'add_question': |
|
480 | - $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
481 | - break; |
|
482 | - case 'edit_question': |
|
483 | - $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
484 | - break; |
|
485 | - default: |
|
486 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
487 | - } |
|
488 | - |
|
489 | - // add PRC_ID to title if editing |
|
490 | - $this->_admin_page_title = |
|
491 | - $ID |
|
492 | - ? $this->_admin_page_title . ' # ' . $ID |
|
493 | - : $this->_admin_page_title; |
|
494 | - if ($ID) { |
|
495 | - $question = $this->_question_model->get_one_by_ID($ID); |
|
496 | - $additional_hidden_fields = ['QST_ID' => ['type' => 'hidden', 'value' => $ID]]; |
|
497 | - $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
498 | - } else { |
|
499 | - $question = EE_Question::new_instance(); |
|
500 | - $question->set_order_to_latest(); |
|
501 | - $this->_set_add_edit_form_tags('insert_question'); |
|
502 | - } |
|
503 | - if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
504 | - $question_types = array_intersect_key( |
|
505 | - EEM_Question::instance()->allowed_question_types(), |
|
506 | - array_flip( |
|
507 | - [ |
|
508 | - EEM_Question::QST_type_text, |
|
509 | - EEM_Question::QST_type_us_phone, |
|
510 | - ] |
|
511 | - ) |
|
512 | - ); |
|
513 | - } else { |
|
514 | - $question_types = $question->has_answers() |
|
515 | - ? $this->_question_model->question_types_in_same_category($question->type()) |
|
516 | - : $this->_question_model->allowed_question_types(); |
|
517 | - } |
|
518 | - $this->_template_args['QST_ID'] = $ID; |
|
519 | - $this->_template_args['question'] = $question; |
|
520 | - $this->_template_args['question_types'] = $question_types; |
|
521 | - $this->_template_args['max_max'] = |
|
522 | - EEM_Question::instance()->absolute_max_for_system_question( |
|
523 | - $question->system_ID() |
|
524 | - ); |
|
525 | - $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
526 | - $this->_set_publish_post_box_vars('id', $ID); |
|
527 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
528 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
529 | - $this->_template_args, |
|
530 | - true |
|
531 | - ); |
|
532 | - |
|
533 | - // the details template wrapper |
|
534 | - $this->display_admin_page_with_sidebar(); |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * @return string |
|
540 | - * @throws EE_Error |
|
541 | - * @throws ReflectionException |
|
542 | - */ |
|
543 | - protected function _get_question_type_descriptions() |
|
544 | - { |
|
545 | - EE_Registry::instance()->load_helper('HTML'); |
|
546 | - $descriptions = ''; |
|
547 | - $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
548 | - foreach ($question_type_descriptions as $type => $question_type_description) { |
|
549 | - if ($type == 'HTML_TEXTAREA') { |
|
550 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
551 | - $question_type_description .= sprintf( |
|
552 | - esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
553 | - '<br/>', |
|
554 | - $html->get_list_of_allowed_tags() |
|
555 | - ); |
|
556 | - } |
|
557 | - $descriptions .= EEH_HTML::p( |
|
558 | - $question_type_description, |
|
559 | - 'question_type_description-' . $type, |
|
560 | - 'question_type_description description', |
|
561 | - 'display:none;' |
|
562 | - ); |
|
563 | - } |
|
564 | - return $descriptions; |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * @param bool|true $new_question |
|
570 | - * @throws EE_Error |
|
571 | - * @throws ReflectionException |
|
572 | - */ |
|
573 | - protected function _insert_or_update_question($new_question = true) |
|
574 | - { |
|
575 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
576 | - $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
577 | - if ($new_question) { |
|
578 | - $question = EE_Question::new_instance($set_column_values); |
|
579 | - $action_desc = 'added'; |
|
580 | - } else { |
|
581 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
582 | - foreach ($set_column_values as $field => $new_value) { |
|
583 | - $question->set($field, $new_value); |
|
584 | - } |
|
585 | - $action_desc = 'updated'; |
|
586 | - } |
|
587 | - $success = $question->save(); |
|
588 | - $ID = $question->ID(); |
|
589 | - if ($ID && $question->should_have_question_options()) { |
|
590 | - // save the related options |
|
591 | - // trash removed options, save old ones |
|
592 | - // get list of all options |
|
593 | - $options = $question->options(); |
|
594 | - if (! empty($options)) { |
|
595 | - foreach ($options as $option_ID => $option) { |
|
596 | - $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
597 | - if ($option_req_index !== false) { |
|
598 | - $option->save($this->_req_data['question_options'][ $option_req_index ]); |
|
599 | - } else { |
|
600 | - // not found, remove it |
|
601 | - $option->delete(); |
|
602 | - } |
|
603 | - } |
|
604 | - } |
|
605 | - // save new related options |
|
606 | - foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
607 | - // skip $index that is from our sample |
|
608 | - if ($index === 'xxcountxx') { |
|
609 | - continue; |
|
610 | - } |
|
611 | - // note we allow saving blank options. |
|
612 | - if (empty($option_req_data['QSO_ID'])) { |
|
613 | - // no ID! save it! |
|
614 | - $new_option = EE_Question_Option::new_instance( |
|
615 | - [ |
|
616 | - 'QSO_value' => $option_req_data['QSO_value'], |
|
617 | - 'QSO_desc' => $option_req_data['QSO_desc'], |
|
618 | - 'QSO_order' => $option_req_data['QSO_order'], |
|
619 | - 'QST_ID' => $question->ID(), |
|
620 | - ] |
|
621 | - ); |
|
622 | - $new_option->save(); |
|
623 | - } |
|
624 | - } |
|
625 | - } |
|
626 | - $query_args = ['action' => 'edit_question', 'QST_ID' => $ID]; |
|
627 | - if ($success !== 0) { |
|
628 | - $msg = $new_question |
|
629 | - ? sprintf( |
|
630 | - esc_html__('The %s has been created', 'event_espresso'), |
|
631 | - $this->_question_model->item_name() |
|
632 | - ) |
|
633 | - : sprintf( |
|
634 | - esc_html__('The %s has been updated', 'event_espresso'), |
|
635 | - $this->_question_model->item_name() |
|
636 | - ); |
|
637 | - EE_Error::add_success($msg); |
|
638 | - } |
|
639 | - |
|
640 | - $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
646 | - * by ID |
|
647 | - * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
648 | - * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
649 | - * |
|
650 | - * @param int $ID of the question option to find |
|
651 | - * @return int index in question_options array if successful, FALSE if unsuccessful |
|
652 | - */ |
|
653 | - protected function _get_option_req_data_index($ID) |
|
654 | - { |
|
655 | - $req_data_for_question_options = $this->_req_data['question_options']; |
|
656 | - foreach ($req_data_for_question_options as $num => $option_data) { |
|
657 | - if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
658 | - return $num; |
|
659 | - } |
|
660 | - } |
|
661 | - return false; |
|
662 | - } |
|
663 | - |
|
664 | - |
|
665 | - |
|
666 | - |
|
667 | - /***********/ |
|
668 | - /* QUERIES */ |
|
669 | - /** |
|
670 | - * For internal use in getting all the query parameters |
|
671 | - * (because it's pretty well the same between question, question groups, |
|
672 | - * and for both when searching for trashed and untrashed ones) |
|
673 | - * |
|
674 | - * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
675 | - * @param int $per_page |
|
676 | - * @param int $current_page |
|
677 | - * @return array model query params, @see |
|
678 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
679 | - */ |
|
680 | - protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
681 | - { |
|
682 | - $query_params = []; |
|
683 | - $offset = ($current_page - 1) * $per_page; |
|
684 | - $query_params['limit'] = [$offset, $per_page]; |
|
685 | - $order = |
|
686 | - (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
687 | - ? $this->_req_data['order'] |
|
688 | - : 'ASC'; |
|
689 | - $orderby_field = |
|
690 | - $model instanceof EEM_Question |
|
691 | - ? 'QST_ID' |
|
692 | - : 'QSG_order'; |
|
693 | - $field_to_order_by = |
|
694 | - empty($this->_req_data['orderby']) |
|
695 | - ? $orderby_field |
|
696 | - : $this->_req_data['orderby']; |
|
697 | - $query_params['order_by'] = [$field_to_order_by => $order]; |
|
698 | - $search_string = |
|
699 | - array_key_exists('s', $this->_req_data) |
|
700 | - ? $this->_req_data['s'] |
|
701 | - : null; |
|
702 | - if (! empty($search_string)) { |
|
703 | - if ($model instanceof EEM_Question_Group) { |
|
704 | - $query_params[0] = [ |
|
705 | - 'OR' => [ |
|
706 | - 'QSG_name' => ['LIKE', "%$search_string%"], |
|
707 | - 'QSG_desc' => ['LIKE', "%$search_string%"], |
|
708 | - ], |
|
709 | - ]; |
|
710 | - } else { |
|
711 | - $query_params[0] = [ |
|
712 | - 'QST_display_text' => ['LIKE', "%$search_string%"], |
|
713 | - ]; |
|
714 | - } |
|
715 | - } |
|
716 | - |
|
717 | - // capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
718 | - /*if ( $model instanceof EEM_Question_Group ) { |
|
18 | + /** |
|
19 | + * holds the specific question object for the question details screen |
|
20 | + * |
|
21 | + * @var EE_Question $_question |
|
22 | + */ |
|
23 | + protected $_question; |
|
24 | + |
|
25 | + /** |
|
26 | + * holds the specific question group object for the question group details screen |
|
27 | + * |
|
28 | + * @var EE_Question_Group $_question_group |
|
29 | + */ |
|
30 | + protected $_question_group; |
|
31 | + |
|
32 | + /** |
|
33 | + *_question_model EEM_Question model instance (for queries) |
|
34 | + * |
|
35 | + * @var EEM_Question $_question_model ; |
|
36 | + */ |
|
37 | + protected $_question_model; |
|
38 | + |
|
39 | + /** |
|
40 | + * _question_group_model EEM_Question_group instance (for queries) |
|
41 | + * |
|
42 | + * @var EEM_Question_Group $_question_group_model |
|
43 | + */ |
|
44 | + protected $_question_group_model; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @Constructor |
|
49 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
50 | + * @throws EE_Error |
|
51 | + * @throws ReflectionException |
|
52 | + */ |
|
53 | + public function __construct($routing = true) |
|
54 | + { |
|
55 | + require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
56 | + require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
57 | + $this->_question_model = EEM_Question::instance(); |
|
58 | + $this->_question_group_model = EEM_Question_Group::instance(); |
|
59 | + parent::__construct($routing); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + protected function _init_page_props() |
|
64 | + { |
|
65 | + $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
66 | + $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
67 | + $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
68 | + $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + protected function _ajax_hooks() |
|
73 | + { |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + protected function _define_page_props() |
|
78 | + { |
|
79 | + $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
80 | + $this->_labels = [ |
|
81 | + 'buttons' => [ |
|
82 | + 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
83 | + ], |
|
84 | + ]; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + *_set_page_routes |
|
90 | + */ |
|
91 | + protected function _set_page_routes() |
|
92 | + { |
|
93 | + $qst_id = |
|
94 | + ! empty($this->_req_data['QST_ID']) |
|
95 | + ? $this->_req_data['QST_ID'] |
|
96 | + : 0; |
|
97 | + $this->_page_routes = [ |
|
98 | + 'default' => [ |
|
99 | + 'func' => '_questions_overview_list_table', |
|
100 | + 'capability' => 'ee_read_questions', |
|
101 | + ], |
|
102 | + |
|
103 | + 'edit_question' => [ |
|
104 | + 'func' => '_edit_question', |
|
105 | + 'capability' => 'ee_edit_question', |
|
106 | + 'obj_id' => $qst_id, |
|
107 | + 'args' => ['edit'], |
|
108 | + ], |
|
109 | + |
|
110 | + 'question_groups' => [ |
|
111 | + 'func' => '_questions_groups_preview', |
|
112 | + 'capability' => 'ee_read_question_groups', |
|
113 | + ], |
|
114 | + |
|
115 | + 'update_question' => [ |
|
116 | + 'func' => '_insert_or_update_question', |
|
117 | + 'args' => ['new_question' => false], |
|
118 | + 'capability' => 'ee_edit_question', |
|
119 | + 'obj_id' => $qst_id, |
|
120 | + 'noheader' => true, |
|
121 | + ], |
|
122 | + ]; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + protected function _set_page_config() |
|
127 | + { |
|
128 | + $this->_page_config = [ |
|
129 | + 'default' => [ |
|
130 | + 'nav' => [ |
|
131 | + 'label' => esc_html__('Questions', 'event_espresso'), |
|
132 | + 'order' => 10, |
|
133 | + ], |
|
134 | + 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
135 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
136 | + 'help_tabs' => [ |
|
137 | + 'registration_form_questions_overview_help_tab' => [ |
|
138 | + 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
139 | + 'filename' => 'registration_form_questions_overview', |
|
140 | + ], |
|
141 | + 'registration_form_questions_overview_table_column_headings_help_tab' => [ |
|
142 | + 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
143 | + 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
144 | + ], |
|
145 | + 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => [ |
|
146 | + 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
147 | + 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
148 | + ], |
|
149 | + ], |
|
150 | + 'require_nonce' => false, |
|
151 | + 'qtips' => [ |
|
152 | + 'EE_Registration_Form_Tips', |
|
153 | + ]/**/ |
|
154 | + ], |
|
155 | + |
|
156 | + 'question_groups' => [ |
|
157 | + 'nav' => [ |
|
158 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
159 | + 'order' => 20, |
|
160 | + ], |
|
161 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
162 | + 'help_tabs' => [ |
|
163 | + 'registration_form_question_groups_help_tab' => [ |
|
164 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
165 | + 'filename' => 'registration_form_question_groups', |
|
166 | + ], |
|
167 | + ], |
|
168 | + 'require_nonce' => false, |
|
169 | + ], |
|
170 | + |
|
171 | + 'edit_question' => [ |
|
172 | + 'nav' => [ |
|
173 | + 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
174 | + 'order' => 15, |
|
175 | + 'persistent' => false, |
|
176 | + 'url' => isset($this->_req_data['question_id']) |
|
177 | + ? add_query_arg( |
|
178 | + ['question_id' => $this->_req_data['question_id']], |
|
179 | + $this->_current_page_view_url |
|
180 | + ) |
|
181 | + : $this->_admin_base_url, |
|
182 | + ], |
|
183 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
184 | + 'help_tabs' => [ |
|
185 | + 'registration_form_edit_question_group_help_tab' => [ |
|
186 | + 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
187 | + 'filename' => 'registration_form_edit_question', |
|
188 | + ], |
|
189 | + ], |
|
190 | + 'require_nonce' => false, |
|
191 | + ], |
|
192 | + ]; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + protected function _add_screen_options() |
|
197 | + { |
|
198 | + // todo |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + protected function _add_screen_options_default() |
|
203 | + { |
|
204 | + $page_title = $this->_admin_page_title; |
|
205 | + $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
206 | + $this->_per_page_screen_option(); |
|
207 | + $this->_admin_page_title = $page_title; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + protected function _add_screen_options_question_groups() |
|
212 | + { |
|
213 | + $page_title = $this->_admin_page_title; |
|
214 | + $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
215 | + $this->_per_page_screen_option(); |
|
216 | + $this->_admin_page_title = $page_title; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + // none of the below group are currently used for Event Categories |
|
221 | + protected function _add_feature_pointers() |
|
222 | + { |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + public function load_scripts_styles() |
|
227 | + { |
|
228 | + wp_register_style( |
|
229 | + 'espresso_registration', |
|
230 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', |
|
231 | + [], |
|
232 | + EVENT_ESPRESSO_VERSION |
|
233 | + ); |
|
234 | + wp_enqueue_style('espresso_registration'); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + public function admin_init() |
|
239 | + { |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + public function admin_notices() |
|
244 | + { |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + public function admin_footer_scripts() |
|
249 | + { |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + public function load_scripts_styles_default() |
|
254 | + { |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * @throws EE_Error |
|
260 | + */ |
|
261 | + public function load_scripts_styles_add_question() |
|
262 | + { |
|
263 | + $this->load_scripts_styles_question_details(); |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @throws EE_Error |
|
269 | + */ |
|
270 | + public function load_scripts_styles_edit_question() |
|
271 | + { |
|
272 | + $this->load_scripts_styles_question_details(); |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Loads the JS required for adding or editing a question |
|
278 | + * |
|
279 | + * @throws EE_Error |
|
280 | + * @throws EE_Error |
|
281 | + */ |
|
282 | + protected function load_scripts_styles_question_details() |
|
283 | + { |
|
284 | + $this->load_scripts_styles_forms(); |
|
285 | + wp_register_script( |
|
286 | + 'espresso_registration_form_single', |
|
287 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', |
|
288 | + ['jquery-ui-sortable'], |
|
289 | + EVENT_ESPRESSO_VERSION, |
|
290 | + true |
|
291 | + ); |
|
292 | + wp_enqueue_script('espresso_registration_form_single'); |
|
293 | + wp_localize_script( |
|
294 | + 'espresso_registration_form_single', |
|
295 | + 'ee_question_data', |
|
296 | + [ |
|
297 | + 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
298 | + 'question_type_with_options' => EEM_Question::instance()->question_types_with_options(), |
|
299 | + ] |
|
300 | + ); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + public function recaptcha_info_help_tab() |
|
305 | + { |
|
306 | + $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
307 | + EEH_Template::display_template($template, []); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + public function load_scripts_styles_forms() |
|
312 | + { |
|
313 | + // styles |
|
314 | + wp_enqueue_style('espresso-ui-theme'); |
|
315 | + // scripts |
|
316 | + wp_enqueue_script('ee_admin_js'); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + protected function _set_list_table_views_default() |
|
321 | + { |
|
322 | + $this->_views = [ |
|
323 | + 'all' => [ |
|
324 | + 'slug' => 'all', |
|
325 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
326 | + 'count' => 0, |
|
327 | + ], |
|
328 | + ]; |
|
329 | + |
|
330 | + if ( |
|
331 | + EE_Registry::instance()->CAP->current_user_can( |
|
332 | + 'ee_delete_questions', |
|
333 | + 'espresso_registration_form_trash_questions' |
|
334 | + ) |
|
335 | + ) { |
|
336 | + $this->_views['trash'] = [ |
|
337 | + 'slug' => 'trash', |
|
338 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
339 | + 'count' => 0, |
|
340 | + ]; |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * This just previews the question groups tab that comes in caffeinated. |
|
347 | + * |
|
348 | + * @return void html |
|
349 | + * @throws EE_Error |
|
350 | + */ |
|
351 | + protected function _questions_groups_preview() |
|
352 | + { |
|
353 | + $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
354 | + $this->_template_args['preview_img'] = |
|
355 | + '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' |
|
356 | + . esc_attr__( |
|
357 | + 'Preview Question Groups Overview List Table screenshot', |
|
358 | + 'event_espresso' |
|
359 | + ) . '" />'; |
|
360 | + $this->_template_args['preview_text'] = '<strong>' |
|
361 | + . esc_html__( |
|
362 | + 'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
363 | + 'event_espresso' |
|
364 | + ) . '</strong>'; |
|
365 | + $this->display_admin_caf_preview_page('question_groups_tab'); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Extracts the question field's values from the POST request to update or insert them |
|
371 | + * |
|
372 | + * @param EEM_Base $model |
|
373 | + * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
374 | + * @throws EE_Error |
|
375 | + */ |
|
376 | + protected function _set_column_values_for(EEM_Base $model) |
|
377 | + { |
|
378 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
379 | + $set_column_values = []; |
|
380 | + |
|
381 | + // some initial checks for proper values. |
|
382 | + // if QST_admin_only, then no matter what QST_required is we disable. |
|
383 | + if (! empty($this->_req_data['QST_admin_only'])) { |
|
384 | + $this->_req_data['QST_required'] = 0; |
|
385 | + } |
|
386 | + // if the question shouldn't have a max length, don't let them set one |
|
387 | + if ( |
|
388 | + ! isset( |
|
389 | + $this->_req_data['QST_type'], |
|
390 | + $this->_req_data['QST_max'] |
|
391 | + ) |
|
392 | + || ! in_array( |
|
393 | + $this->_req_data['QST_type'], |
|
394 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
395 | + true |
|
396 | + ) |
|
397 | + ) { |
|
398 | + // they're not allowed to set the max |
|
399 | + $this->_req_data['QST_max'] = null; |
|
400 | + } |
|
401 | + foreach ($model->field_settings() as $fieldName => $settings) { |
|
402 | + // basically if QSG_identifier is empty or not set |
|
403 | + if ( |
|
404 | + $fieldName === 'QSG_identifier' |
|
405 | + && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier'])) |
|
406 | + ) { |
|
407 | + $QSG_name = isset($this->_req_data['QSG_name']) |
|
408 | + ? $this->_req_data['QSG_name'] |
|
409 | + : ''; |
|
410 | + $set_column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
411 | + } elseif ( |
|
412 | + $fieldName === 'QST_admin_label' |
|
413 | + && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label'])) |
|
414 | + ) { |
|
415 | + // the admin label is blank, use a slug version of the question text |
|
416 | + $QST_text = |
|
417 | + isset($this->_req_data['QST_display_text']) |
|
418 | + ? $this->_req_data['QST_display_text'] |
|
419 | + : ''; |
|
420 | + $set_column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
421 | + } elseif ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
422 | + $set_column_values[ $fieldName ] = 0; |
|
423 | + } elseif ($fieldName === 'QST_max') { |
|
424 | + $qst_system = EEM_Question::instance()->get_var( |
|
425 | + [ |
|
426 | + [ |
|
427 | + 'QST_ID' => isset($this->_req_data['QST_ID']) |
|
428 | + ? $this->_req_data['QST_ID'] |
|
429 | + : 0, |
|
430 | + ], |
|
431 | + ], |
|
432 | + 'QST_system' |
|
433 | + ); |
|
434 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
435 | + if ( |
|
436 | + empty($this->_req_data['QST_max']) || $this->_req_data['QST_max'] > $max_max |
|
437 | + ) { |
|
438 | + $set_column_values[ $fieldName ] = $max_max; |
|
439 | + } |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + // only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
444 | + if ( |
|
445 | + ! isset($set_column_values[ $fieldName ]) && isset($this->_req_data[ $fieldName ]) |
|
446 | + ) { |
|
447 | + $set_column_values[ $fieldName ] = $this->_req_data[ $fieldName ]; |
|
448 | + } |
|
449 | + } |
|
450 | + return $set_column_values;// validation fo this data to be performed by the model before insertion. |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + *_questions_overview_list_table |
|
456 | + * |
|
457 | + * @throws EE_Error |
|
458 | + */ |
|
459 | + protected function _questions_overview_list_table() |
|
460 | + { |
|
461 | + $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
462 | + $this->display_admin_list_table_page_with_sidebar(); |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * _edit_question |
|
468 | + * |
|
469 | + * @throws EE_Error |
|
470 | + * @throws ReflectionException |
|
471 | + */ |
|
472 | + protected function _edit_question() |
|
473 | + { |
|
474 | + $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) |
|
475 | + ? absint($this->_req_data['QST_ID']) |
|
476 | + : false; |
|
477 | + |
|
478 | + switch ($this->_req_action) { |
|
479 | + case 'add_question': |
|
480 | + $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
481 | + break; |
|
482 | + case 'edit_question': |
|
483 | + $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
484 | + break; |
|
485 | + default: |
|
486 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
487 | + } |
|
488 | + |
|
489 | + // add PRC_ID to title if editing |
|
490 | + $this->_admin_page_title = |
|
491 | + $ID |
|
492 | + ? $this->_admin_page_title . ' # ' . $ID |
|
493 | + : $this->_admin_page_title; |
|
494 | + if ($ID) { |
|
495 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
496 | + $additional_hidden_fields = ['QST_ID' => ['type' => 'hidden', 'value' => $ID]]; |
|
497 | + $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
498 | + } else { |
|
499 | + $question = EE_Question::new_instance(); |
|
500 | + $question->set_order_to_latest(); |
|
501 | + $this->_set_add_edit_form_tags('insert_question'); |
|
502 | + } |
|
503 | + if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
504 | + $question_types = array_intersect_key( |
|
505 | + EEM_Question::instance()->allowed_question_types(), |
|
506 | + array_flip( |
|
507 | + [ |
|
508 | + EEM_Question::QST_type_text, |
|
509 | + EEM_Question::QST_type_us_phone, |
|
510 | + ] |
|
511 | + ) |
|
512 | + ); |
|
513 | + } else { |
|
514 | + $question_types = $question->has_answers() |
|
515 | + ? $this->_question_model->question_types_in_same_category($question->type()) |
|
516 | + : $this->_question_model->allowed_question_types(); |
|
517 | + } |
|
518 | + $this->_template_args['QST_ID'] = $ID; |
|
519 | + $this->_template_args['question'] = $question; |
|
520 | + $this->_template_args['question_types'] = $question_types; |
|
521 | + $this->_template_args['max_max'] = |
|
522 | + EEM_Question::instance()->absolute_max_for_system_question( |
|
523 | + $question->system_ID() |
|
524 | + ); |
|
525 | + $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
526 | + $this->_set_publish_post_box_vars('id', $ID); |
|
527 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
528 | + REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
529 | + $this->_template_args, |
|
530 | + true |
|
531 | + ); |
|
532 | + |
|
533 | + // the details template wrapper |
|
534 | + $this->display_admin_page_with_sidebar(); |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * @return string |
|
540 | + * @throws EE_Error |
|
541 | + * @throws ReflectionException |
|
542 | + */ |
|
543 | + protected function _get_question_type_descriptions() |
|
544 | + { |
|
545 | + EE_Registry::instance()->load_helper('HTML'); |
|
546 | + $descriptions = ''; |
|
547 | + $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
548 | + foreach ($question_type_descriptions as $type => $question_type_description) { |
|
549 | + if ($type == 'HTML_TEXTAREA') { |
|
550 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
551 | + $question_type_description .= sprintf( |
|
552 | + esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
553 | + '<br/>', |
|
554 | + $html->get_list_of_allowed_tags() |
|
555 | + ); |
|
556 | + } |
|
557 | + $descriptions .= EEH_HTML::p( |
|
558 | + $question_type_description, |
|
559 | + 'question_type_description-' . $type, |
|
560 | + 'question_type_description description', |
|
561 | + 'display:none;' |
|
562 | + ); |
|
563 | + } |
|
564 | + return $descriptions; |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * @param bool|true $new_question |
|
570 | + * @throws EE_Error |
|
571 | + * @throws ReflectionException |
|
572 | + */ |
|
573 | + protected function _insert_or_update_question($new_question = true) |
|
574 | + { |
|
575 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
576 | + $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
577 | + if ($new_question) { |
|
578 | + $question = EE_Question::new_instance($set_column_values); |
|
579 | + $action_desc = 'added'; |
|
580 | + } else { |
|
581 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
582 | + foreach ($set_column_values as $field => $new_value) { |
|
583 | + $question->set($field, $new_value); |
|
584 | + } |
|
585 | + $action_desc = 'updated'; |
|
586 | + } |
|
587 | + $success = $question->save(); |
|
588 | + $ID = $question->ID(); |
|
589 | + if ($ID && $question->should_have_question_options()) { |
|
590 | + // save the related options |
|
591 | + // trash removed options, save old ones |
|
592 | + // get list of all options |
|
593 | + $options = $question->options(); |
|
594 | + if (! empty($options)) { |
|
595 | + foreach ($options as $option_ID => $option) { |
|
596 | + $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
597 | + if ($option_req_index !== false) { |
|
598 | + $option->save($this->_req_data['question_options'][ $option_req_index ]); |
|
599 | + } else { |
|
600 | + // not found, remove it |
|
601 | + $option->delete(); |
|
602 | + } |
|
603 | + } |
|
604 | + } |
|
605 | + // save new related options |
|
606 | + foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
607 | + // skip $index that is from our sample |
|
608 | + if ($index === 'xxcountxx') { |
|
609 | + continue; |
|
610 | + } |
|
611 | + // note we allow saving blank options. |
|
612 | + if (empty($option_req_data['QSO_ID'])) { |
|
613 | + // no ID! save it! |
|
614 | + $new_option = EE_Question_Option::new_instance( |
|
615 | + [ |
|
616 | + 'QSO_value' => $option_req_data['QSO_value'], |
|
617 | + 'QSO_desc' => $option_req_data['QSO_desc'], |
|
618 | + 'QSO_order' => $option_req_data['QSO_order'], |
|
619 | + 'QST_ID' => $question->ID(), |
|
620 | + ] |
|
621 | + ); |
|
622 | + $new_option->save(); |
|
623 | + } |
|
624 | + } |
|
625 | + } |
|
626 | + $query_args = ['action' => 'edit_question', 'QST_ID' => $ID]; |
|
627 | + if ($success !== 0) { |
|
628 | + $msg = $new_question |
|
629 | + ? sprintf( |
|
630 | + esc_html__('The %s has been created', 'event_espresso'), |
|
631 | + $this->_question_model->item_name() |
|
632 | + ) |
|
633 | + : sprintf( |
|
634 | + esc_html__('The %s has been updated', 'event_espresso'), |
|
635 | + $this->_question_model->item_name() |
|
636 | + ); |
|
637 | + EE_Error::add_success($msg); |
|
638 | + } |
|
639 | + |
|
640 | + $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
646 | + * by ID |
|
647 | + * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
648 | + * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
649 | + * |
|
650 | + * @param int $ID of the question option to find |
|
651 | + * @return int index in question_options array if successful, FALSE if unsuccessful |
|
652 | + */ |
|
653 | + protected function _get_option_req_data_index($ID) |
|
654 | + { |
|
655 | + $req_data_for_question_options = $this->_req_data['question_options']; |
|
656 | + foreach ($req_data_for_question_options as $num => $option_data) { |
|
657 | + if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
658 | + return $num; |
|
659 | + } |
|
660 | + } |
|
661 | + return false; |
|
662 | + } |
|
663 | + |
|
664 | + |
|
665 | + |
|
666 | + |
|
667 | + /***********/ |
|
668 | + /* QUERIES */ |
|
669 | + /** |
|
670 | + * For internal use in getting all the query parameters |
|
671 | + * (because it's pretty well the same between question, question groups, |
|
672 | + * and for both when searching for trashed and untrashed ones) |
|
673 | + * |
|
674 | + * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
675 | + * @param int $per_page |
|
676 | + * @param int $current_page |
|
677 | + * @return array model query params, @see |
|
678 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
679 | + */ |
|
680 | + protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
681 | + { |
|
682 | + $query_params = []; |
|
683 | + $offset = ($current_page - 1) * $per_page; |
|
684 | + $query_params['limit'] = [$offset, $per_page]; |
|
685 | + $order = |
|
686 | + (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
687 | + ? $this->_req_data['order'] |
|
688 | + : 'ASC'; |
|
689 | + $orderby_field = |
|
690 | + $model instanceof EEM_Question |
|
691 | + ? 'QST_ID' |
|
692 | + : 'QSG_order'; |
|
693 | + $field_to_order_by = |
|
694 | + empty($this->_req_data['orderby']) |
|
695 | + ? $orderby_field |
|
696 | + : $this->_req_data['orderby']; |
|
697 | + $query_params['order_by'] = [$field_to_order_by => $order]; |
|
698 | + $search_string = |
|
699 | + array_key_exists('s', $this->_req_data) |
|
700 | + ? $this->_req_data['s'] |
|
701 | + : null; |
|
702 | + if (! empty($search_string)) { |
|
703 | + if ($model instanceof EEM_Question_Group) { |
|
704 | + $query_params[0] = [ |
|
705 | + 'OR' => [ |
|
706 | + 'QSG_name' => ['LIKE', "%$search_string%"], |
|
707 | + 'QSG_desc' => ['LIKE', "%$search_string%"], |
|
708 | + ], |
|
709 | + ]; |
|
710 | + } else { |
|
711 | + $query_params[0] = [ |
|
712 | + 'QST_display_text' => ['LIKE', "%$search_string%"], |
|
713 | + ]; |
|
714 | + } |
|
715 | + } |
|
716 | + |
|
717 | + // capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
718 | + /*if ( $model instanceof EEM_Question_Group ) { |
|
719 | 719 | if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) { |
720 | 720 | $query_params[0] = array( |
721 | 721 | 'AND' => array( |
@@ -745,67 +745,67 @@ discard block |
||
745 | 745 | } |
746 | 746 | }/**/ |
747 | 747 | |
748 | - return $query_params; |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - /** |
|
753 | - * @param int $per_page |
|
754 | - * @param int $current_page |
|
755 | - * @param bool|false $count |
|
756 | - * @return EE_Base_Class[]|EE_Question_Group[]|EE_Soft_Delete_Base_Class[]|int |
|
757 | - * @throws EE_Error |
|
758 | - */ |
|
759 | - public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
760 | - { |
|
761 | - $QST = EEM_Question::instance(); |
|
762 | - $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
763 | - if ($count) { |
|
764 | - $where = |
|
765 | - isset($query_params[0]) |
|
766 | - ? [$query_params[0]] |
|
767 | - : []; |
|
768 | - $results = $QST->count($where); |
|
769 | - } else { |
|
770 | - $results = $QST->get_all($query_params); |
|
771 | - } |
|
772 | - return $results; |
|
773 | - } |
|
774 | - |
|
775 | - |
|
776 | - /** |
|
777 | - * @param $per_page |
|
778 | - * @param int $current_page |
|
779 | - * @param bool|false $count |
|
780 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
781 | - * @throws EE_Error |
|
782 | - */ |
|
783 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
784 | - { |
|
785 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
786 | - $where = |
|
787 | - isset($query_params[0]) |
|
788 | - ? [$query_params[0]] |
|
789 | - : []; |
|
790 | - return $count |
|
791 | - ? EEM_Question::instance()->count_deleted($where) |
|
792 | - : EEM_Question::instance()->get_all_deleted($query_params); |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * @param $per_page |
|
798 | - * @param int $current_page |
|
799 | - * @param bool|false $count |
|
800 | - * @return EE_Base_Class[]|EE_Question_Group[]|EE_Soft_Delete_Base_Class[] |
|
801 | - * @throws EE_Error |
|
802 | - */ |
|
803 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
804 | - { |
|
805 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
806 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
807 | - return $questionGroupModel->get_all( |
|
808 | - $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
809 | - ); |
|
810 | - } |
|
748 | + return $query_params; |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + /** |
|
753 | + * @param int $per_page |
|
754 | + * @param int $current_page |
|
755 | + * @param bool|false $count |
|
756 | + * @return EE_Base_Class[]|EE_Question_Group[]|EE_Soft_Delete_Base_Class[]|int |
|
757 | + * @throws EE_Error |
|
758 | + */ |
|
759 | + public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
760 | + { |
|
761 | + $QST = EEM_Question::instance(); |
|
762 | + $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
763 | + if ($count) { |
|
764 | + $where = |
|
765 | + isset($query_params[0]) |
|
766 | + ? [$query_params[0]] |
|
767 | + : []; |
|
768 | + $results = $QST->count($where); |
|
769 | + } else { |
|
770 | + $results = $QST->get_all($query_params); |
|
771 | + } |
|
772 | + return $results; |
|
773 | + } |
|
774 | + |
|
775 | + |
|
776 | + /** |
|
777 | + * @param $per_page |
|
778 | + * @param int $current_page |
|
779 | + * @param bool|false $count |
|
780 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
781 | + * @throws EE_Error |
|
782 | + */ |
|
783 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
784 | + { |
|
785 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
786 | + $where = |
|
787 | + isset($query_params[0]) |
|
788 | + ? [$query_params[0]] |
|
789 | + : []; |
|
790 | + return $count |
|
791 | + ? EEM_Question::instance()->count_deleted($where) |
|
792 | + : EEM_Question::instance()->get_all_deleted($query_params); |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * @param $per_page |
|
798 | + * @param int $current_page |
|
799 | + * @param bool|false $count |
|
800 | + * @return EE_Base_Class[]|EE_Question_Group[]|EE_Soft_Delete_Base_Class[] |
|
801 | + * @throws EE_Error |
|
802 | + */ |
|
803 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
804 | + { |
|
805 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
806 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
807 | + return $questionGroupModel->get_all( |
|
808 | + $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
809 | + ); |
|
810 | + } |
|
811 | 811 | } |
@@ -94,16 +94,16 @@ |
||
94 | 94 | ? $this->_extra_data['template']['question_list'] |
95 | 95 | : $template; |
96 | 96 | $ans_result = ''; |
97 | - $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
98 | - ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
97 | + $answers = ! empty($this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs']) |
|
98 | + ? $this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs'] |
|
99 | 99 | : []; |
100 | 100 | $questions = ! empty($this->_extra_data['data']->questions) |
101 | 101 | ? $this->_extra_data['data']->questions |
102 | 102 | : []; |
103 | 103 | foreach ($answers as $answer) { |
104 | 104 | // first see if the question is in our $questions array. If not then try to get from answer object |
105 | - $question = isset($questions[ $answer->ID() ]) |
|
106 | - ? $questions[ $answer->ID() ] |
|
105 | + $question = isset($questions[$answer->ID()]) |
|
106 | + ? $questions[$answer->ID()] |
|
107 | 107 | : null; |
108 | 108 | $question = ! $question instanceof EE_Question |
109 | 109 | ? $answer->question() |
@@ -15,109 +15,109 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Question_List_Shortcodes extends EE_Shortcodes |
17 | 17 | { |
18 | - public function __construct() |
|
19 | - { |
|
20 | - parent::__construct(); |
|
21 | - } |
|
18 | + public function __construct() |
|
19 | + { |
|
20 | + parent::__construct(); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - protected function _init_props() |
|
25 | - { |
|
26 | - $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
27 | - $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
28 | - $this->_shortcodes = [ |
|
29 | - '[QUESTION_LIST]' => esc_html__( |
|
30 | - 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
31 | - 'event_espresso' |
|
32 | - ), |
|
33 | - ]; |
|
34 | - } |
|
24 | + protected function _init_props() |
|
25 | + { |
|
26 | + $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
27 | + $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
28 | + $this->_shortcodes = [ |
|
29 | + '[QUESTION_LIST]' => esc_html__( |
|
30 | + 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
31 | + 'event_espresso' |
|
32 | + ), |
|
33 | + ]; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @throws EE_Error |
|
39 | - * @throws ReflectionException |
|
40 | - */ |
|
41 | - protected function _parser($shortcode) |
|
42 | - { |
|
43 | - switch ($shortcode) { |
|
44 | - case '[QUESTION_LIST]': |
|
45 | - return $this->_get_question_list(); |
|
46 | - } |
|
47 | - return ''; |
|
48 | - } |
|
37 | + /** |
|
38 | + * @throws EE_Error |
|
39 | + * @throws ReflectionException |
|
40 | + */ |
|
41 | + protected function _parser($shortcode) |
|
42 | + { |
|
43 | + switch ($shortcode) { |
|
44 | + case '[QUESTION_LIST]': |
|
45 | + return $this->_get_question_list(); |
|
46 | + } |
|
47 | + return ''; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @throws EE_Error |
|
53 | - * @throws ReflectionException |
|
54 | - */ |
|
55 | - protected function _get_question_list() |
|
56 | - { |
|
57 | - $this->_validate_list_requirements(); |
|
51 | + /** |
|
52 | + * @throws EE_Error |
|
53 | + * @throws ReflectionException |
|
54 | + */ |
|
55 | + protected function _get_question_list() |
|
56 | + { |
|
57 | + $this->_validate_list_requirements(); |
|
58 | 58 | |
59 | - // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
60 | - if ($this->_data['data'] instanceof EE_Registration) { |
|
61 | - return $this->_get_question_answer_list_for_attendee(); |
|
62 | - } |
|
63 | - // for when [QUESTION_LIST] is used in the main content field. |
|
64 | - if ( |
|
65 | - $this->_data['data'] instanceof EE_Messages_Addressee |
|
66 | - && $this->_data['data']->reg_obj instanceof EE_Registration |
|
67 | - ) { |
|
68 | - return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
69 | - } |
|
70 | - return ''; |
|
71 | - } |
|
59 | + // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
60 | + if ($this->_data['data'] instanceof EE_Registration) { |
|
61 | + return $this->_get_question_answer_list_for_attendee(); |
|
62 | + } |
|
63 | + // for when [QUESTION_LIST] is used in the main content field. |
|
64 | + if ( |
|
65 | + $this->_data['data'] instanceof EE_Messages_Addressee |
|
66 | + && $this->_data['data']->reg_obj instanceof EE_Registration |
|
67 | + ) { |
|
68 | + return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
69 | + } |
|
70 | + return ''; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
76 | - * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
77 | - * |
|
78 | - * @param null $reg_obj |
|
79 | - * @return string parsed template. |
|
80 | - * @throws EE_Error |
|
81 | - * @throws ReflectionException |
|
82 | - */ |
|
83 | - private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
84 | - { |
|
85 | - $valid_shortcodes = ['question']; |
|
86 | - $reg_obj = $reg_obj instanceof EE_Registration |
|
87 | - ? $reg_obj |
|
88 | - : $this->_data['data']; |
|
89 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
90 | - ? $this->_data['template']['question_list'] |
|
91 | - : ''; |
|
92 | - $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
93 | - ? $this->_extra_data['template']['question_list'] |
|
94 | - : $template; |
|
95 | - $ans_result = ''; |
|
96 | - $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
97 | - ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
98 | - : []; |
|
99 | - $questions = ! empty($this->_extra_data['data']->questions) |
|
100 | - ? $this->_extra_data['data']->questions |
|
101 | - : []; |
|
102 | - foreach ($answers as $answer) { |
|
103 | - // first see if the question is in our $questions array. If not then try to get from answer object |
|
104 | - $question = isset($questions[ $answer->ID() ]) |
|
105 | - ? $questions[ $answer->ID() ] |
|
106 | - : null; |
|
107 | - $question = ! $question instanceof EE_Question |
|
108 | - ? $answer->question() |
|
109 | - : $question; |
|
110 | - if ($question instanceof EE_Question and $question->admin_only()) { |
|
111 | - continue; |
|
112 | - } |
|
113 | - $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
114 | - $template, |
|
115 | - $answer, |
|
116 | - $valid_shortcodes, |
|
117 | - $this->_extra_data |
|
118 | - ); |
|
119 | - } |
|
74 | + /** |
|
75 | + * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
76 | + * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
77 | + * |
|
78 | + * @param null $reg_obj |
|
79 | + * @return string parsed template. |
|
80 | + * @throws EE_Error |
|
81 | + * @throws ReflectionException |
|
82 | + */ |
|
83 | + private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
84 | + { |
|
85 | + $valid_shortcodes = ['question']; |
|
86 | + $reg_obj = $reg_obj instanceof EE_Registration |
|
87 | + ? $reg_obj |
|
88 | + : $this->_data['data']; |
|
89 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
90 | + ? $this->_data['template']['question_list'] |
|
91 | + : ''; |
|
92 | + $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
93 | + ? $this->_extra_data['template']['question_list'] |
|
94 | + : $template; |
|
95 | + $ans_result = ''; |
|
96 | + $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
97 | + ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
98 | + : []; |
|
99 | + $questions = ! empty($this->_extra_data['data']->questions) |
|
100 | + ? $this->_extra_data['data']->questions |
|
101 | + : []; |
|
102 | + foreach ($answers as $answer) { |
|
103 | + // first see if the question is in our $questions array. If not then try to get from answer object |
|
104 | + $question = isset($questions[ $answer->ID() ]) |
|
105 | + ? $questions[ $answer->ID() ] |
|
106 | + : null; |
|
107 | + $question = ! $question instanceof EE_Question |
|
108 | + ? $answer->question() |
|
109 | + : $question; |
|
110 | + if ($question instanceof EE_Question and $question->admin_only()) { |
|
111 | + continue; |
|
112 | + } |
|
113 | + $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
114 | + $template, |
|
115 | + $answer, |
|
116 | + $valid_shortcodes, |
|
117 | + $this->_extra_data |
|
118 | + ); |
|
119 | + } |
|
120 | 120 | |
121 | - return $ans_result; |
|
122 | - } |
|
121 | + return $ans_result; |
|
122 | + } |
|
123 | 123 | } |
@@ -4,10 +4,10 @@ discard block |
||
4 | 4 | </p> |
5 | 5 | <p> |
6 | 6 | <?php printf( |
7 | - esc_html__('See %1$shere%2$s for list of currencies supported by Paypal Pro.', 'event_espresso'), |
|
8 | - "<a href='https://www.paypal.com/multicurrency' target='_blank' rel='noopener noreferrer'>", |
|
9 | - "</a>" |
|
10 | - ); ?> |
|
7 | + esc_html__('See %1$shere%2$s for list of currencies supported by Paypal Pro.', 'event_espresso'), |
|
8 | + "<a href='https://www.paypal.com/multicurrency' target='_blank' rel='noopener noreferrer'>", |
|
9 | + "</a>" |
|
10 | + ); ?> |
|
11 | 11 | </p> |
12 | 12 | <p><strong><?php esc_html_e('PayPal Pro Settings', 'event_espresso'); ?></strong></p> |
13 | 13 | <ul> |
@@ -18,48 +18,48 @@ discard block |
||
18 | 18 | <li> |
19 | 19 | <strong><?php esc_html_e('PayPal API Username', 'event_espresso'); ?></strong><br/> |
20 | 20 | <?php |
21 | - printf( |
|
22 | - esc_html__( |
|
23 | - 'Enter your API Username for PayPal. Learn how to find your %1$sAPI Username%2$s.', |
|
24 | - 'event_espresso' |
|
25 | - ), |
|
26 | - '<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">', |
|
27 | - '</a>' |
|
28 | - ); |
|
29 | - ?> |
|
21 | + printf( |
|
22 | + esc_html__( |
|
23 | + 'Enter your API Username for PayPal. Learn how to find your %1$sAPI Username%2$s.', |
|
24 | + 'event_espresso' |
|
25 | + ), |
|
26 | + '<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">', |
|
27 | + '</a>' |
|
28 | + ); |
|
29 | + ?> |
|
30 | 30 | </li> |
31 | 31 | <li> |
32 | 32 | <strong><?php esc_html_e('PayPal API Password', 'event_espresso'); ?></strong><br/> |
33 | 33 | <?php |
34 | - printf( |
|
35 | - esc_html__( |
|
36 | - 'Enter your API Password for PayPal. Learn how to find your %1$sAPI Password%2$s.', |
|
37 | - 'event_espresso' |
|
38 | - ), |
|
39 | - '<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">', |
|
40 | - '</a>' |
|
41 | - ); |
|
42 | - ?> |
|
34 | + printf( |
|
35 | + esc_html__( |
|
36 | + 'Enter your API Password for PayPal. Learn how to find your %1$sAPI Password%2$s.', |
|
37 | + 'event_espresso' |
|
38 | + ), |
|
39 | + '<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">', |
|
40 | + '</a>' |
|
41 | + ); |
|
42 | + ?> |
|
43 | 43 | </li> |
44 | 44 | <li> |
45 | 45 | <strong><?php esc_html_e('PayPal API Signature', 'event_espresso'); ?></strong><br/> |
46 | 46 | <?php |
47 | - printf( |
|
48 | - esc_html__( |
|
49 | - 'Enter your API Signature for PayPal. Learn how to find your %1$sAPI Signature%2$s.', |
|
50 | - 'event_espresso' |
|
51 | - ), |
|
52 | - '<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">', |
|
53 | - '</a>' |
|
54 | - ); |
|
55 | - ?> |
|
47 | + printf( |
|
48 | + esc_html__( |
|
49 | + 'Enter your API Signature for PayPal. Learn how to find your %1$sAPI Signature%2$s.', |
|
50 | + 'event_espresso' |
|
51 | + ), |
|
52 | + '<a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/merchant/wppro/WPProIntegrationSteps-outside#SectionB" target="_blank" rel="noopener noreferrer">', |
|
53 | + '</a>' |
|
54 | + ); |
|
55 | + ?> |
|
56 | 56 | </li> |
57 | 57 | <li> |
58 | 58 | <strong><?php esc_html_e('Country Currency', 'event_espresso'); ?></strong><br/> |
59 | 59 | <?php esc_html_e( |
60 | - 'Select the currency for your country. Payments will be accepted in this currency.', |
|
61 | - 'event_espresso' |
|
62 | - ); ?> |
|
60 | + 'Select the currency for your country. Payments will be accepted in this currency.', |
|
61 | + 'event_espresso' |
|
62 | + ); ?> |
|
63 | 63 | </li> |
64 | 64 | <li> |
65 | 65 | <strong><?php esc_html_e('Accepted Card Types', 'event_espresso'); ?></strong><br/> |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | <li> |
69 | 69 | <strong><?php esc_html_e('Use the Debugging Feature and the PayPal Sandbox', 'event_espresso'); ?></strong><br/> |
70 | 70 | <?php esc_html_e( |
71 | - 'Specify if you want to test the payment gateway by submitting a test transaction. If this option is enabled, be sure to enter your PayPal sandbox credentials in the fields above. Be sure to turn this setting off when you are done testing.', |
|
72 | - 'event_espresso' |
|
73 | - ); ?> |
|
71 | + 'Specify if you want to test the payment gateway by submitting a test transaction. If this option is enabled, be sure to enter your PayPal sandbox credentials in the fields above. Be sure to turn this setting off when you are done testing.', |
|
72 | + 'event_espresso' |
|
73 | + ); ?> |
|
74 | 74 | </li> |
75 | 75 | <li> |
76 | 76 | <strong><?php esc_html_e('Button Image URL', 'event_espresso'); ?></strong><br/> |
@@ -6,15 +6,15 @@ discard block |
||
6 | 6 | </p> |
7 | 7 | <p> |
8 | 8 | <?php |
9 | - printf( |
|
10 | - esc_html__( |
|
11 | - 'See %1$shere%2$s for list of currencies supported by Authorize.net AIM.', |
|
12 | - 'event_espresso' |
|
13 | - ), |
|
14 | - "<a href='https://support.authorize.net/s/article/Which-Currencies-Does-Authorize-Net-Support/' target='_blank' rel='noopener noreferrer'>", |
|
15 | - "</a>" |
|
16 | - ); |
|
17 | - ?> |
|
9 | + printf( |
|
10 | + esc_html__( |
|
11 | + 'See %1$shere%2$s for list of currencies supported by Authorize.net AIM.', |
|
12 | + 'event_espresso' |
|
13 | + ), |
|
14 | + "<a href='https://support.authorize.net/s/article/Which-Currencies-Does-Authorize-Net-Support/' target='_blank' rel='noopener noreferrer'>", |
|
15 | + "</a>" |
|
16 | + ); |
|
17 | + ?> |
|
18 | 18 | </p> |
19 | 19 | <p> |
20 | 20 | <strong><?php esc_html_e('Authorize.net AIM Settings', 'event_espresso'); ?></strong> |
@@ -24,70 +24,70 @@ discard block |
||
24 | 24 | <strong><?php esc_html_e('Authorize.net API Login ID', 'event_espresso'); ?></strong> |
25 | 25 | <br/> |
26 | 26 | <?php |
27 | - printf( |
|
28 | - esc_html__( |
|
29 | - 'Enter your API Login ID for Authorize.net. Learn how to find your %1$sAPI Login%2$s ID.', |
|
30 | - 'event_espresso' |
|
31 | - ), |
|
32 | - '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
33 | - '</a>' |
|
34 | - ); |
|
35 | - ?> |
|
27 | + printf( |
|
28 | + esc_html__( |
|
29 | + 'Enter your API Login ID for Authorize.net. Learn how to find your %1$sAPI Login%2$s ID.', |
|
30 | + 'event_espresso' |
|
31 | + ), |
|
32 | + '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
33 | + '</a>' |
|
34 | + ); |
|
35 | + ?> |
|
36 | 36 | </li> |
37 | 37 | <li> |
38 | 38 | <strong><?php esc_html_e('Authorize.net Transaction Key', 'event_espresso'); ?></strong> |
39 | 39 | <br/> |
40 | 40 | <?php |
41 | - printf( |
|
42 | - esc_html__( |
|
43 | - 'Enter your Transaction Key for Authorize.net. Learn how to find your %1$sTransaction Key%2$s.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
47 | - '</a>' |
|
48 | - ); |
|
49 | - ?> |
|
41 | + printf( |
|
42 | + esc_html__( |
|
43 | + 'Enter your Transaction Key for Authorize.net. Learn how to find your %1$sTransaction Key%2$s.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
47 | + '</a>' |
|
48 | + ); |
|
49 | + ?> |
|
50 | 50 | </li> |
51 | 51 | <li> |
52 | 52 | <strong> |
53 | 53 | <?php esc_html_e( |
54 | - 'Is this an account on the Authorize.net development server?', |
|
55 | - 'event_espresso' |
|
56 | - ); ?> |
|
54 | + 'Is this an account on the Authorize.net development server?', |
|
55 | + 'event_espresso' |
|
56 | + ); ?> |
|
57 | 57 | </strong> |
58 | 58 | <br/> |
59 | 59 | <?php esc_html_e( |
60 | - 'Specify whether this is a live/production account or a test account on the Authorize.net development server.', |
|
61 | - 'event_espresso' |
|
62 | - ); ?> |
|
60 | + 'Specify whether this is a live/production account or a test account on the Authorize.net development server.', |
|
61 | + 'event_espresso' |
|
62 | + ); ?> |
|
63 | 63 | </li> |
64 | 64 | <li> |
65 | 65 | <strong><?php esc_html_e('Do you want to submit a test transaction?', 'event_espresso'); ?></strong> |
66 | 66 | <br/> |
67 | 67 | <?php esc_html_e( |
68 | - 'Specify if you want to test the Authorize.net AIM payment gateway by submitting a test transaction. Be sure to turn this setting off when you are done testing.', |
|
69 | - 'event_espresso' |
|
70 | - ); ?> |
|
68 | + 'Specify if you want to test the Authorize.net AIM payment gateway by submitting a test transaction. Be sure to turn this setting off when you are done testing.', |
|
69 | + 'event_espresso' |
|
70 | + ); ?> |
|
71 | 71 | </li> |
72 | 72 | <li> |
73 | 73 | <strong><?php esc_html_e('Excluded and Required Payment Form Fields', 'event_espresso'); ?></strong> |
74 | 74 | <br/> |
75 | 75 | <?php esc_html_e( |
76 | - 'By logging into Authorize.net, you can change which payment fields are required by Authorize.net when processing payments. These settings affect both the Advanced Integration Method (AIM, this) and the Simple Integration Method (SIM, different). The payment method settings "Excluded Payment Form Fields" and "Required Payment Form Fields" allow you to change the billing form in Event Espresso to reflect your payment form settings in Authorize.net.', |
|
77 | - 'event_espresso' |
|
78 | - ); ?> |
|
76 | + 'By logging into Authorize.net, you can change which payment fields are required by Authorize.net when processing payments. These settings affect both the Advanced Integration Method (AIM, this) and the Simple Integration Method (SIM, different). The payment method settings "Excluded Payment Form Fields" and "Required Payment Form Fields" allow you to change the billing form in Event Espresso to reflect your payment form settings in Authorize.net.', |
|
77 | + 'event_espresso' |
|
78 | + ); ?> |
|
79 | 79 | <br> |
80 | 80 | <?php printf( |
81 | - esc_html__( |
|
82 | - 'To change your payment form settings in Authorize.net, %1$slog in to authorize.net%2$s, go to %3$sAccount then Payment Form%2$s, then %4$sForm Fields%2$s. It will look similar to %5$sthis%2$s. If you make a field required in Authorize.net, you should also make it required in Event Espresso. If it isn\'t required in Authorize.net, and you want to simplify the billing form in Event Espresso, you can exclude it from the Event Espresso Form too.', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - '<a href="http://authorize.net" target="_blank" rel="noopener noreferrer">', |
|
86 | - '</a>', |
|
87 | - '<a href="https://monosnap.com/file/nebVteOkEXcdDIos88SojStWOifP23" target="_blank" rel="noopener noreferrer">', |
|
88 | - '<a href="https://monosnap.com/file/WyxGJtev87TcDmdGBEZ2oi1xaBIQAm" target="_blank" rel="noopener noreferrer">', |
|
89 | - '<a href="https://monosnap.com/image/DbCJNfEesWXeSNUs1wLIpGYODFw52m" target="_blank" rel="noopener noreferrer">' |
|
90 | - ); ?> |
|
81 | + esc_html__( |
|
82 | + 'To change your payment form settings in Authorize.net, %1$slog in to authorize.net%2$s, go to %3$sAccount then Payment Form%2$s, then %4$sForm Fields%2$s. It will look similar to %5$sthis%2$s. If you make a field required in Authorize.net, you should also make it required in Event Espresso. If it isn\'t required in Authorize.net, and you want to simplify the billing form in Event Espresso, you can exclude it from the Event Espresso Form too.', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + '<a href="http://authorize.net" target="_blank" rel="noopener noreferrer">', |
|
86 | + '</a>', |
|
87 | + '<a href="https://monosnap.com/file/nebVteOkEXcdDIos88SojStWOifP23" target="_blank" rel="noopener noreferrer">', |
|
88 | + '<a href="https://monosnap.com/file/WyxGJtev87TcDmdGBEZ2oi1xaBIQAm" target="_blank" rel="noopener noreferrer">', |
|
89 | + '<a href="https://monosnap.com/image/DbCJNfEesWXeSNUs1wLIpGYODFw52m" target="_blank" rel="noopener noreferrer">' |
|
90 | + ); ?> |
|
91 | 91 | </li> |
92 | 92 | <li> |
93 | 93 | <strong><?php esc_html_e('Button Image URL', 'event_espresso'); ?></strong> |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | <li> |
98 | 98 | <strong><?php esc_html_e('Note About Special Characters', 'event_espresso'); ?></strong> |
99 | 99 | <?php |
100 | - esc_html_e( |
|
101 | - 'If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.', |
|
102 | - 'event_espresso' |
|
103 | - ); |
|
104 | - ?> |
|
100 | + esc_html_e( |
|
101 | + 'If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.', |
|
102 | + 'event_espresso' |
|
103 | + ); |
|
104 | + ?> |
|
105 | 105 | </li> |
106 | 106 | </ul> |
107 | 107 | \ No newline at end of file |
@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | use EventEspresso\core\services\database\TableAnalysis; |
13 | 13 | |
14 | 14 | // defined some new constants related to caffeinated folder |
15 | -define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/'); |
|
16 | -define('EE_CAF_CORE', EE_CAFF_PATH . 'core/'); |
|
17 | -define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries/'); |
|
18 | -define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods/'); |
|
15 | +define('EE_CAF_URL', EE_PLUGIN_DIR_URL.'caffeinated/'); |
|
16 | +define('EE_CAF_CORE', EE_CAFF_PATH.'core/'); |
|
17 | +define('EE_CAF_LIBRARIES', EE_CAF_CORE.'libraries/'); |
|
18 | +define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH.'payment_methods/'); |
|
19 | 19 | |
20 | 20 | |
21 | 21 | /** |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | add_filter('FHEE__EE_Registry__load_helper__helper_paths', [$this, 'caf_helper_paths'], 10); |
66 | 66 | add_filter( |
67 | 67 | 'AHEE__EE_System__load_core_configuration__complete', |
68 | - function () { |
|
68 | + function() { |
|
69 | 69 | EE_Register_Payment_Method::register( |
70 | 70 | 'caffeinated_payment_methods', |
71 | 71 | [ |
72 | - 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
72 | + 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS.'*', GLOB_ONLYDIR), |
|
73 | 73 | ] |
74 | 74 | ); |
75 | 75 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function caf_helper_paths($paths) |
126 | 126 | { |
127 | - $paths[] = EE_CAF_CORE . 'helpers/'; |
|
127 | + $paths[] = EE_CAF_CORE.'helpers/'; |
|
128 | 128 | return $paths; |
129 | 129 | } |
130 | 130 | |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | global $wpdb; |
146 | 146 | // use same method of getting creator id as the version introducing the change |
147 | 147 | $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
148 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
149 | - $price_table = $wpdb->prefix . "esp_price"; |
|
148 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
149 | + $price_table = $wpdb->prefix."esp_price"; |
|
150 | 150 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
151 | 151 | $SQL = |
152 | - 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
152 | + 'SELECT COUNT(PRT_ID) FROM '.$price_type_table.' WHERE PBT_ID=4'; // include trashed price types |
|
153 | 153 | $tax_price_type_count = $wpdb->get_var($SQL); |
154 | 154 | if ($tax_price_type_count <= 1) { |
155 | 155 | $wpdb->insert( |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | 'PRT_wp_user' => $default_creator_id, |
164 | 164 | ], |
165 | 165 | [ |
166 | - '%s',// PRT_name |
|
167 | - '%d',// PBT_id |
|
168 | - '%d',// PRT_is_percent |
|
169 | - '%d',// PRT_order |
|
170 | - '%d',// PRT_deleted |
|
166 | + '%s', // PRT_name |
|
167 | + '%d', // PBT_id |
|
168 | + '%d', // PRT_is_percent |
|
169 | + '%d', // PRT_order |
|
170 | + '%d', // PRT_deleted |
|
171 | 171 | '%d', // PRT_wp_user |
172 | 172 | ] |
173 | 173 | ); |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | 'PRT_wp_user' => $default_creator_id, |
184 | 184 | ], |
185 | 185 | [ |
186 | - '%s',// PRT_name |
|
187 | - '%d',// PBT_id |
|
188 | - '%d',// PRT_is_percent |
|
189 | - '%d',// PRT_order |
|
190 | - '%d',// PRT_deleted |
|
186 | + '%s', // PRT_name |
|
187 | + '%d', // PBT_id |
|
188 | + '%d', // PRT_is_percent |
|
189 | + '%d', // PRT_order |
|
190 | + '%d', // PRT_deleted |
|
191 | 191 | '%d' // PRT_wp_user |
192 | 192 | ] |
193 | 193 | ); |
@@ -207,15 +207,15 @@ discard block |
||
207 | 207 | 'PRC_wp_user' => $default_creator_id, |
208 | 208 | ], |
209 | 209 | [ |
210 | - '%d',// PRT_id |
|
211 | - '%f',// PRC_amount |
|
212 | - '%s',// PRC_name |
|
213 | - '%s',// PRC_desc |
|
214 | - '%d',// PRC_is_default |
|
215 | - '%d',// PRC_overrides |
|
216 | - '%d',// PRC_deleted |
|
217 | - '%d',// PRC_order |
|
218 | - '%d',// PRC_parent |
|
210 | + '%d', // PRT_id |
|
211 | + '%f', // PRC_amount |
|
212 | + '%s', // PRC_name |
|
213 | + '%s', // PRC_desc |
|
214 | + '%d', // PRC_is_default |
|
215 | + '%d', // PRC_overrides |
|
216 | + '%d', // PRC_deleted |
|
217 | + '%d', // PRC_order |
|
218 | + '%d', // PRC_parent |
|
219 | 219 | '%d' // PRC_wp_user |
220 | 220 | ] |
221 | 221 | ); |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function caffeinated_modules_to_register($modules_to_register = []) |
236 | 236 | { |
237 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
238 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules/*', GLOB_ONLYDIR); |
|
237 | + if (is_readable(EE_CAFF_PATH.'modules')) { |
|
238 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH.'modules/*', GLOB_ONLYDIR); |
|
239 | 239 | if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
240 | 240 | $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
241 | 241 | } |
@@ -27,323 +27,323 @@ |
||
27 | 27 | */ |
28 | 28 | class EE_Brewing_Regular extends EE_BASE implements InterminableInterface |
29 | 29 | { |
30 | - /** |
|
31 | - * @var TableAnalysis $table_analysis |
|
32 | - */ |
|
33 | - protected $_table_analysis; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * EE_Brewing_Regular constructor. |
|
38 | - * |
|
39 | - * @param TableAnalysis $table_analysis |
|
40 | - */ |
|
41 | - public function __construct(TableAnalysis $table_analysis) |
|
42 | - { |
|
43 | - $this->_table_analysis = $table_analysis; |
|
44 | - if (defined('EE_CAFF_PATH')) { |
|
45 | - $this->setInitializationHooks(); |
|
46 | - $this->setApiRegistrationHooks(); |
|
47 | - $this->setSwitchHooks(); |
|
48 | - $this->setDefaultFilterHooks(); |
|
49 | - // caffeinated constructed |
|
50 | - do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Various hooks used for extending features via registration of modules or extensions. |
|
57 | - */ |
|
58 | - private function setApiRegistrationHooks() |
|
59 | - { |
|
60 | - add_filter( |
|
61 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
62 | - [$this, 'caffeinated_modules_to_register'] |
|
63 | - ); |
|
64 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', [$this, 'caf_helper_paths'], 10); |
|
65 | - add_filter( |
|
66 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
67 | - function () { |
|
68 | - EE_Register_Payment_Method::register( |
|
69 | - 'caffeinated_payment_methods', |
|
70 | - [ |
|
71 | - 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
72 | - ] |
|
73 | - ); |
|
74 | - } |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Various hooks used for modifying initialization or activation processes. |
|
81 | - */ |
|
82 | - private function setInitializationHooks() |
|
83 | - { |
|
84 | - // activation |
|
85 | - add_action('AHEE__EEH_Activation__initialize_db_content', [$this, 'initialize_caf_db_content']); |
|
86 | - // load caff init |
|
87 | - add_action('AHEE__EE_System__set_hooks_for_core', [$this, 'caffeinated_init']); |
|
88 | - // load caff scripts |
|
89 | - add_action('wp_enqueue_scripts', [$this, 'enqueue_caffeinated_scripts'], 10); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Various hooks used for switch (on/off) type filters. |
|
95 | - */ |
|
96 | - private function setSwitchHooks() |
|
97 | - { |
|
98 | - // remove the "powered by" credit link from receipts and invoices |
|
99 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
100 | - // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
101 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Various filters for affecting default configuration values in the caffeinated |
|
107 | - * context. |
|
108 | - */ |
|
109 | - private function setDefaultFilterHooks() |
|
110 | - { |
|
111 | - add_filter( |
|
112 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
113 | - '__return_true' |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
120 | - * |
|
121 | - * @param array $paths original helper paths array |
|
122 | - * @return array new array of paths |
|
123 | - */ |
|
124 | - public function caf_helper_paths($paths) |
|
125 | - { |
|
126 | - $paths[] = EE_CAF_CORE . 'helpers/'; |
|
127 | - return $paths; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
133 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
134 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
135 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
136 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
137 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
138 | - * Right now, we ASSUME the only price types in the system are default ones |
|
139 | - * |
|
140 | - * @global wpdb $wpdb |
|
141 | - */ |
|
142 | - public function initialize_caf_db_content() |
|
143 | - { |
|
144 | - global $wpdb; |
|
145 | - // use same method of getting creator id as the version introducing the change |
|
146 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
147 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
148 | - $price_table = $wpdb->prefix . "esp_price"; |
|
149 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
150 | - $SQL = |
|
151 | - 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
152 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
153 | - if ($tax_price_type_count <= 1) { |
|
154 | - $wpdb->insert( |
|
155 | - $price_type_table, |
|
156 | - [ |
|
157 | - 'PRT_name' => esc_html__("Regional Tax", "event_espresso"), |
|
158 | - 'PBT_ID' => 4, |
|
159 | - 'PRT_is_percent' => true, |
|
160 | - 'PRT_order' => 60, |
|
161 | - 'PRT_deleted' => false, |
|
162 | - 'PRT_wp_user' => $default_creator_id, |
|
163 | - ], |
|
164 | - [ |
|
165 | - '%s',// PRT_name |
|
166 | - '%d',// PBT_id |
|
167 | - '%d',// PRT_is_percent |
|
168 | - '%d',// PRT_order |
|
169 | - '%d',// PRT_deleted |
|
170 | - '%d', // PRT_wp_user |
|
171 | - ] |
|
172 | - ); |
|
173 | - // federal tax |
|
174 | - $result = $wpdb->insert( |
|
175 | - $price_type_table, |
|
176 | - [ |
|
177 | - 'PRT_name' => esc_html__("Federal Tax", "event_espresso"), |
|
178 | - 'PBT_ID' => 4, |
|
179 | - 'PRT_is_percent' => true, |
|
180 | - 'PRT_order' => 70, |
|
181 | - 'PRT_deleted' => false, |
|
182 | - 'PRT_wp_user' => $default_creator_id, |
|
183 | - ], |
|
184 | - [ |
|
185 | - '%s',// PRT_name |
|
186 | - '%d',// PBT_id |
|
187 | - '%d',// PRT_is_percent |
|
188 | - '%d',// PRT_order |
|
189 | - '%d',// PRT_deleted |
|
190 | - '%d' // PRT_wp_user |
|
191 | - ] |
|
192 | - ); |
|
193 | - if ($result) { |
|
194 | - $wpdb->insert( |
|
195 | - $price_table, |
|
196 | - [ |
|
197 | - 'PRT_ID' => $wpdb->insert_id, |
|
198 | - 'PRC_amount' => 15.00, |
|
199 | - 'PRC_name' => esc_html__("Sales Tax", "event_espresso"), |
|
200 | - 'PRC_desc' => '', |
|
201 | - 'PRC_is_default' => true, |
|
202 | - 'PRC_overrides' => null, |
|
203 | - 'PRC_deleted' => false, |
|
204 | - 'PRC_order' => 50, |
|
205 | - 'PRC_parent' => null, |
|
206 | - 'PRC_wp_user' => $default_creator_id, |
|
207 | - ], |
|
208 | - [ |
|
209 | - '%d',// PRT_id |
|
210 | - '%f',// PRC_amount |
|
211 | - '%s',// PRC_name |
|
212 | - '%s',// PRC_desc |
|
213 | - '%d',// PRC_is_default |
|
214 | - '%d',// PRC_overrides |
|
215 | - '%d',// PRC_deleted |
|
216 | - '%d',// PRC_order |
|
217 | - '%d',// PRC_parent |
|
218 | - '%d' // PRC_wp_user |
|
219 | - ] |
|
220 | - ); |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * caffeinated_modules_to_register |
|
229 | - * |
|
230 | - * @access public |
|
231 | - * @param array $modules_to_register |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - public function caffeinated_modules_to_register($modules_to_register = []) |
|
235 | - { |
|
236 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
237 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules/*', GLOB_ONLYDIR); |
|
238 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
239 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
240 | - } |
|
241 | - } |
|
242 | - return $modules_to_register; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @throws EE_Error |
|
248 | - * @throws InvalidArgumentException |
|
249 | - * @throws ReflectionException |
|
250 | - * @throws InvalidDataTypeException |
|
251 | - * @throws InvalidInterfaceException |
|
252 | - */ |
|
253 | - public function caffeinated_init() |
|
254 | - { |
|
255 | - // Custom Post Type hooks |
|
256 | - add_filter( |
|
257 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
258 | - [$this, 'filter_taxonomies'] |
|
259 | - ); |
|
260 | - add_filter( |
|
261 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
262 | - [$this, 'filter_cpts'] |
|
263 | - ); |
|
264 | - add_filter( |
|
265 | - 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
266 | - [$this, 'nav_metabox_items'] |
|
267 | - ); |
|
268 | - EE_Registry::instance()->load_file( |
|
269 | - EE_CAFF_PATH, |
|
270 | - 'EE_Caf_Messages', |
|
271 | - 'class', |
|
272 | - [], |
|
273 | - false |
|
274 | - ); |
|
275 | - // caffeinated_init__complete hook |
|
276 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - public function enqueue_caffeinated_scripts() |
|
281 | - { |
|
282 | - // sound of crickets... |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * callbacks below here |
|
288 | - * |
|
289 | - * @param array $taxonomy_array |
|
290 | - * @return array |
|
291 | - */ |
|
292 | - public function filter_taxonomies(array $taxonomy_array) |
|
293 | - { |
|
294 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
295 | - return $taxonomy_array; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @param array $cpt_array |
|
301 | - * @return mixed |
|
302 | - */ |
|
303 | - public function filter_cpts(array $cpt_array) |
|
304 | - { |
|
305 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
306 | - return $cpt_array; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @param array $menuitems |
|
312 | - * @return array |
|
313 | - */ |
|
314 | - public function nav_metabox_items(array $menuitems) |
|
315 | - { |
|
316 | - $menuitems[] = [ |
|
317 | - 'title' => esc_html__('Venue List', 'event_espresso'), |
|
318 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
319 | - 'description' => esc_html__('Archive page for all venues.', 'event_espresso'), |
|
320 | - ]; |
|
321 | - return $menuitems; |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * Gets the injected table analyzer, or throws an exception |
|
327 | - * |
|
328 | - * @return TableAnalysis |
|
329 | - * @throws \EE_Error |
|
330 | - */ |
|
331 | - protected function _get_table_analysis() |
|
332 | - { |
|
333 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
334 | - return $this->_table_analysis; |
|
335 | - } else { |
|
336 | - throw new \EE_Error( |
|
337 | - sprintf( |
|
338 | - esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
339 | - get_class($this) |
|
340 | - ) |
|
341 | - ); |
|
342 | - } |
|
343 | - } |
|
30 | + /** |
|
31 | + * @var TableAnalysis $table_analysis |
|
32 | + */ |
|
33 | + protected $_table_analysis; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * EE_Brewing_Regular constructor. |
|
38 | + * |
|
39 | + * @param TableAnalysis $table_analysis |
|
40 | + */ |
|
41 | + public function __construct(TableAnalysis $table_analysis) |
|
42 | + { |
|
43 | + $this->_table_analysis = $table_analysis; |
|
44 | + if (defined('EE_CAFF_PATH')) { |
|
45 | + $this->setInitializationHooks(); |
|
46 | + $this->setApiRegistrationHooks(); |
|
47 | + $this->setSwitchHooks(); |
|
48 | + $this->setDefaultFilterHooks(); |
|
49 | + // caffeinated constructed |
|
50 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Various hooks used for extending features via registration of modules or extensions. |
|
57 | + */ |
|
58 | + private function setApiRegistrationHooks() |
|
59 | + { |
|
60 | + add_filter( |
|
61 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
62 | + [$this, 'caffeinated_modules_to_register'] |
|
63 | + ); |
|
64 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', [$this, 'caf_helper_paths'], 10); |
|
65 | + add_filter( |
|
66 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
67 | + function () { |
|
68 | + EE_Register_Payment_Method::register( |
|
69 | + 'caffeinated_payment_methods', |
|
70 | + [ |
|
71 | + 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
72 | + ] |
|
73 | + ); |
|
74 | + } |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Various hooks used for modifying initialization or activation processes. |
|
81 | + */ |
|
82 | + private function setInitializationHooks() |
|
83 | + { |
|
84 | + // activation |
|
85 | + add_action('AHEE__EEH_Activation__initialize_db_content', [$this, 'initialize_caf_db_content']); |
|
86 | + // load caff init |
|
87 | + add_action('AHEE__EE_System__set_hooks_for_core', [$this, 'caffeinated_init']); |
|
88 | + // load caff scripts |
|
89 | + add_action('wp_enqueue_scripts', [$this, 'enqueue_caffeinated_scripts'], 10); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Various hooks used for switch (on/off) type filters. |
|
95 | + */ |
|
96 | + private function setSwitchHooks() |
|
97 | + { |
|
98 | + // remove the "powered by" credit link from receipts and invoices |
|
99 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
100 | + // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
101 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Various filters for affecting default configuration values in the caffeinated |
|
107 | + * context. |
|
108 | + */ |
|
109 | + private function setDefaultFilterHooks() |
|
110 | + { |
|
111 | + add_filter( |
|
112 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
113 | + '__return_true' |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
120 | + * |
|
121 | + * @param array $paths original helper paths array |
|
122 | + * @return array new array of paths |
|
123 | + */ |
|
124 | + public function caf_helper_paths($paths) |
|
125 | + { |
|
126 | + $paths[] = EE_CAF_CORE . 'helpers/'; |
|
127 | + return $paths; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
133 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
134 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
135 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
136 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
137 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
138 | + * Right now, we ASSUME the only price types in the system are default ones |
|
139 | + * |
|
140 | + * @global wpdb $wpdb |
|
141 | + */ |
|
142 | + public function initialize_caf_db_content() |
|
143 | + { |
|
144 | + global $wpdb; |
|
145 | + // use same method of getting creator id as the version introducing the change |
|
146 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
147 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
148 | + $price_table = $wpdb->prefix . "esp_price"; |
|
149 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
150 | + $SQL = |
|
151 | + 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
152 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
153 | + if ($tax_price_type_count <= 1) { |
|
154 | + $wpdb->insert( |
|
155 | + $price_type_table, |
|
156 | + [ |
|
157 | + 'PRT_name' => esc_html__("Regional Tax", "event_espresso"), |
|
158 | + 'PBT_ID' => 4, |
|
159 | + 'PRT_is_percent' => true, |
|
160 | + 'PRT_order' => 60, |
|
161 | + 'PRT_deleted' => false, |
|
162 | + 'PRT_wp_user' => $default_creator_id, |
|
163 | + ], |
|
164 | + [ |
|
165 | + '%s',// PRT_name |
|
166 | + '%d',// PBT_id |
|
167 | + '%d',// PRT_is_percent |
|
168 | + '%d',// PRT_order |
|
169 | + '%d',// PRT_deleted |
|
170 | + '%d', // PRT_wp_user |
|
171 | + ] |
|
172 | + ); |
|
173 | + // federal tax |
|
174 | + $result = $wpdb->insert( |
|
175 | + $price_type_table, |
|
176 | + [ |
|
177 | + 'PRT_name' => esc_html__("Federal Tax", "event_espresso"), |
|
178 | + 'PBT_ID' => 4, |
|
179 | + 'PRT_is_percent' => true, |
|
180 | + 'PRT_order' => 70, |
|
181 | + 'PRT_deleted' => false, |
|
182 | + 'PRT_wp_user' => $default_creator_id, |
|
183 | + ], |
|
184 | + [ |
|
185 | + '%s',// PRT_name |
|
186 | + '%d',// PBT_id |
|
187 | + '%d',// PRT_is_percent |
|
188 | + '%d',// PRT_order |
|
189 | + '%d',// PRT_deleted |
|
190 | + '%d' // PRT_wp_user |
|
191 | + ] |
|
192 | + ); |
|
193 | + if ($result) { |
|
194 | + $wpdb->insert( |
|
195 | + $price_table, |
|
196 | + [ |
|
197 | + 'PRT_ID' => $wpdb->insert_id, |
|
198 | + 'PRC_amount' => 15.00, |
|
199 | + 'PRC_name' => esc_html__("Sales Tax", "event_espresso"), |
|
200 | + 'PRC_desc' => '', |
|
201 | + 'PRC_is_default' => true, |
|
202 | + 'PRC_overrides' => null, |
|
203 | + 'PRC_deleted' => false, |
|
204 | + 'PRC_order' => 50, |
|
205 | + 'PRC_parent' => null, |
|
206 | + 'PRC_wp_user' => $default_creator_id, |
|
207 | + ], |
|
208 | + [ |
|
209 | + '%d',// PRT_id |
|
210 | + '%f',// PRC_amount |
|
211 | + '%s',// PRC_name |
|
212 | + '%s',// PRC_desc |
|
213 | + '%d',// PRC_is_default |
|
214 | + '%d',// PRC_overrides |
|
215 | + '%d',// PRC_deleted |
|
216 | + '%d',// PRC_order |
|
217 | + '%d',// PRC_parent |
|
218 | + '%d' // PRC_wp_user |
|
219 | + ] |
|
220 | + ); |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * caffeinated_modules_to_register |
|
229 | + * |
|
230 | + * @access public |
|
231 | + * @param array $modules_to_register |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + public function caffeinated_modules_to_register($modules_to_register = []) |
|
235 | + { |
|
236 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
237 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules/*', GLOB_ONLYDIR); |
|
238 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
239 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
240 | + } |
|
241 | + } |
|
242 | + return $modules_to_register; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @throws EE_Error |
|
248 | + * @throws InvalidArgumentException |
|
249 | + * @throws ReflectionException |
|
250 | + * @throws InvalidDataTypeException |
|
251 | + * @throws InvalidInterfaceException |
|
252 | + */ |
|
253 | + public function caffeinated_init() |
|
254 | + { |
|
255 | + // Custom Post Type hooks |
|
256 | + add_filter( |
|
257 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
258 | + [$this, 'filter_taxonomies'] |
|
259 | + ); |
|
260 | + add_filter( |
|
261 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
262 | + [$this, 'filter_cpts'] |
|
263 | + ); |
|
264 | + add_filter( |
|
265 | + 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
266 | + [$this, 'nav_metabox_items'] |
|
267 | + ); |
|
268 | + EE_Registry::instance()->load_file( |
|
269 | + EE_CAFF_PATH, |
|
270 | + 'EE_Caf_Messages', |
|
271 | + 'class', |
|
272 | + [], |
|
273 | + false |
|
274 | + ); |
|
275 | + // caffeinated_init__complete hook |
|
276 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + public function enqueue_caffeinated_scripts() |
|
281 | + { |
|
282 | + // sound of crickets... |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * callbacks below here |
|
288 | + * |
|
289 | + * @param array $taxonomy_array |
|
290 | + * @return array |
|
291 | + */ |
|
292 | + public function filter_taxonomies(array $taxonomy_array) |
|
293 | + { |
|
294 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
295 | + return $taxonomy_array; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @param array $cpt_array |
|
301 | + * @return mixed |
|
302 | + */ |
|
303 | + public function filter_cpts(array $cpt_array) |
|
304 | + { |
|
305 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
306 | + return $cpt_array; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @param array $menuitems |
|
312 | + * @return array |
|
313 | + */ |
|
314 | + public function nav_metabox_items(array $menuitems) |
|
315 | + { |
|
316 | + $menuitems[] = [ |
|
317 | + 'title' => esc_html__('Venue List', 'event_espresso'), |
|
318 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
319 | + 'description' => esc_html__('Archive page for all venues.', 'event_espresso'), |
|
320 | + ]; |
|
321 | + return $menuitems; |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * Gets the injected table analyzer, or throws an exception |
|
327 | + * |
|
328 | + * @return TableAnalysis |
|
329 | + * @throws \EE_Error |
|
330 | + */ |
|
331 | + protected function _get_table_analysis() |
|
332 | + { |
|
333 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
334 | + return $this->_table_analysis; |
|
335 | + } else { |
|
336 | + throw new \EE_Error( |
|
337 | + sprintf( |
|
338 | + esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
339 | + get_class($this) |
|
340 | + ) |
|
341 | + ); |
|
342 | + } |
|
343 | + } |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
347 | 347 | $brewing = new EE_Brewing_Regular( |
348 | - EE_Registry::instance()->create('TableAnalysis', [], true) |
|
348 | + EE_Registry::instance()->create('TableAnalysis', [], true) |
|
349 | 349 | ); |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | // load messenger |
157 | 157 | $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
158 | 158 | $messenger = str_replace(' ', '_', $messenger); |
159 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
159 | + $messenger = 'EE_'.$messenger.'_messenger'; |
|
160 | 160 | |
161 | - if (! class_exists($messenger)) { |
|
161 | + if ( ! class_exists($messenger)) { |
|
162 | 162 | throw new EE_Error( |
163 | 163 | sprintf( |
164 | 164 | esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | // load message type |
173 | 173 | $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
174 | 174 | $message_type = str_replace(' ', '_', $message_type); |
175 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
175 | + $message_type = 'EE_'.$message_type.'_message_type'; |
|
176 | 176 | |
177 | - if (! class_exists($message_type)) { |
|
177 | + if ( ! class_exists($message_type)) { |
|
178 | 178 | throw new EE_Error( |
179 | 179 | sprintf( |
180 | 180 | esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | |
207 | 207 | // we only want the valid shortcodes for the given context! |
208 | 208 | $context = $this->_context; |
209 | - $mt_codes = $mt_codes[ $context ]; |
|
209 | + $mt_codes = $mt_codes[$context]; |
|
210 | 210 | |
211 | 211 | // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
212 | 212 | // into a single array (so we can get the appropriate shortcode objects for the groups) |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | if (empty($config) || ! isset($config['shortcodes'])) { |
218 | 218 | continue; |
219 | 219 | } //Nothing to see here. |
220 | - $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
220 | + $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes); |
|
221 | 221 | $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
222 | 222 | } |
223 | 223 | |
@@ -230,11 +230,11 @@ discard block |
||
230 | 230 | foreach ($shortcode_groups as $group) { |
231 | 231 | $ref = ucwords(str_replace('_', ' ', $group)); |
232 | 232 | $ref = str_replace(' ', '_', $ref); |
233 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
233 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
234 | 234 | if (class_exists($classname)) { |
235 | 235 | $a = new ReflectionClass($classname); |
236 | 236 | $obj = $a->newInstance(); |
237 | - $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
237 | + $codes_from_objs[$group] = $obj->get_shortcodes(); |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
243 | 243 | $final_mt_codes = []; |
244 | 244 | foreach ($mt_codes as $group) { |
245 | - $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
245 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | $mt_codes = $final_mt_codes; |
@@ -260,44 +260,44 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | // If we have an override then we use it to indicate the codes we want. |
263 | - if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
264 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
265 | - $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
263 | + if (isset($this->_valid_shortcodes_modifier[$context][$field])) { |
|
264 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
265 | + $this->_valid_shortcodes_modifier[$context][$field], |
|
266 | 266 | $codes_from_objs |
267 | 267 | ); |
268 | - } elseif (isset($groups_per_field[ $field ])) { |
|
268 | + } elseif (isset($groups_per_field[$field])) { |
|
269 | 269 | // we have specific shortcodes for a field so we need to use them |
270 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
271 | - $groups_per_field[ $field ], |
|
270 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
271 | + $groups_per_field[$field], |
|
272 | 272 | $codes_from_objs |
273 | 273 | ); |
274 | 274 | } elseif (empty($config)) { |
275 | 275 | // no config so we're assuming we're just going to use the shortcodes from the message type context |
276 | - $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
276 | + $this->_validators[$field]['shortcodes'] = $mt_codes; |
|
277 | 277 | } elseif (isset($config['specific_shortcodes'])) { |
278 | 278 | // we have specific shortcodes so we need to use them |
279 | - $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
279 | + $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes']; |
|
280 | 280 | } else { |
281 | 281 | // otherwise the shortcodes are what is set by the messenger for that field |
282 | 282 | foreach ($config['shortcodes'] as $group) { |
283 | - $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes']) |
|
284 | - ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ]) |
|
285 | - : $codes_from_objs[ $group ]; |
|
283 | + $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes']) |
|
284 | + ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group]) |
|
285 | + : $codes_from_objs[$group]; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
289 | 289 | // now let's just make sure that any excluded specific shortcodes are removed. |
290 | 290 | $specific_excludes = $this->get_specific_shortcode_excludes(); |
291 | - if (isset($specific_excludes[ $field ])) { |
|
292 | - foreach ($specific_excludes[ $field ] as $sex) { |
|
293 | - if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) { |
|
294 | - unset($this->_validators[ $field ]['shortcodes'][ $sex ]); |
|
291 | + if (isset($specific_excludes[$field])) { |
|
292 | + foreach ($specific_excludes[$field] as $sex) { |
|
293 | + if (isset($this->_validators[$field]['shortcodes'][$sex])) { |
|
294 | + unset($this->_validators[$field]['shortcodes'][$sex]); |
|
295 | 295 | } |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | 299 | // hey! don't forget to include the type if present! |
300 | - $this->_validators[ $field ]['type'] = |
|
300 | + $this->_validators[$field]['type'] = |
|
301 | 301 | isset($config['type']) |
302 | 302 | ? $config['type'] |
303 | 303 | : null; |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | { |
328 | 328 | // specific validator filter |
329 | 329 | $shortcode_excludes = apply_filters( |
330 | - 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
330 | + 'FHEE__'.get_class($this).'__get_specific_shortcode_excludes;', |
|
331 | 331 | $this->_specific_shortcode_excludes, |
332 | 332 | $this->_context |
333 | 333 | ); |
@@ -354,21 +354,21 @@ discard block |
||
354 | 354 | $template_fields = $this->_messenger->get_template_fields(); |
355 | 355 | // loop through the fields and check! |
356 | 356 | foreach ($this->_fields as $field => $value) { |
357 | - $this->_errors[ $field ] = []; |
|
357 | + $this->_errors[$field] = []; |
|
358 | 358 | $err_msg = ''; |
359 | 359 | $field_label = ''; |
360 | 360 | // if field is not present in the _validators array then we continue |
361 | - if (! isset($this->_validators[ $field ])) { |
|
362 | - unset($this->_errors[ $field ]); |
|
361 | + if ( ! isset($this->_validators[$field])) { |
|
362 | + unset($this->_errors[$field]); |
|
363 | 363 | continue; |
364 | 364 | } |
365 | 365 | |
366 | 366 | // get the translated field label! |
367 | 367 | // first check if it's in the main fields list |
368 | - if (isset($template_fields[ $field ])) { |
|
368 | + if (isset($template_fields[$field])) { |
|
369 | 369 | // most likely the field is found in the 'extra' array. |
370 | - $field_label = ! empty($template_fields[ $field ]) |
|
371 | - ? $template_fields[ $field ]['label'] |
|
370 | + $field_label = ! empty($template_fields[$field]) |
|
371 | + ? $template_fields[$field]['label'] |
|
372 | 372 | : $field; |
373 | 373 | } |
374 | 374 | |
@@ -392,20 +392,20 @@ discard block |
||
392 | 392 | |
393 | 393 | // field is present. Let's validate shortcodes first (but only if shortcodes present). |
394 | 394 | if ( |
395 | - isset($this->_validators[ $field ]['shortcodes']) |
|
396 | - && ! empty($this->_validators[ $field ]['shortcodes']) |
|
395 | + isset($this->_validators[$field]['shortcodes']) |
|
396 | + && ! empty($this->_validators[$field]['shortcodes']) |
|
397 | 397 | ) { |
398 | - $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']); |
|
398 | + $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']); |
|
399 | 399 | // if true then that means there is a returned error message |
400 | 400 | // that we'll need to add to the _errors array for this field. |
401 | 401 | if ($invalid_shortcodes) { |
402 | - $v_s = array_keys($this->_validators[ $field ]['shortcodes']); |
|
402 | + $v_s = array_keys($this->_validators[$field]['shortcodes']); |
|
403 | 403 | $err_msg = sprintf( |
404 | 404 | esc_html__( |
405 | 405 | '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
406 | 406 | 'event_espresso' |
407 | 407 | ), |
408 | - '<strong>' . $field_label . '</strong>', |
|
408 | + '<strong>'.$field_label.'</strong>', |
|
409 | 409 | $invalid_shortcodes, |
410 | 410 | '<p>', |
411 | 411 | '</p >' |
@@ -420,10 +420,10 @@ discard block |
||
420 | 420 | } |
421 | 421 | |
422 | 422 | // if there's a "type" to be validated then let's do that too. |
423 | - if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) { |
|
424 | - switch ($this->_validators[ $field ]['type']) { |
|
423 | + if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) { |
|
424 | + switch ($this->_validators[$field]['type']) { |
|
425 | 425 | case 'number': |
426 | - if (! is_numeric($value)) { |
|
426 | + if ( ! is_numeric($value)) { |
|
427 | 427 | $err_msg .= sprintf( |
428 | 428 | esc_html__( |
429 | 429 | '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | break; |
439 | 439 | case 'email': |
440 | 440 | $valid_email = $this->_validate_email($value); |
441 | - if (! $valid_email) { |
|
441 | + if ( ! $valid_email) { |
|
442 | 442 | $err_msg .= htmlentities( |
443 | 443 | sprintf( |
444 | 444 | esc_html__( |
@@ -456,18 +456,18 @@ discard block |
||
456 | 456 | } |
457 | 457 | |
458 | 458 | // if $err_msg isn't empty let's setup the _errors array for this field. |
459 | - if (! empty($err_msg)) { |
|
460 | - $this->_errors[ $field ]['msg'] = $err_msg; |
|
459 | + if ( ! empty($err_msg)) { |
|
460 | + $this->_errors[$field]['msg'] = $err_msg; |
|
461 | 461 | } else { |
462 | - unset($this->_errors[ $field ]); |
|
462 | + unset($this->_errors[$field]); |
|
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | 466 | // if we have ANY errors, then we want to make sure we return the values |
467 | 467 | // for ALL the fields so the user doesn't have to retype them all. |
468 | - if (! empty($this->_errors)) { |
|
468 | + if ( ! empty($this->_errors)) { |
|
469 | 469 | foreach ($this->_fields as $field => $value) { |
470 | - $this->_errors[ $field ]['value'] = stripslashes($value); |
|
470 | + $this->_errors[$field]['value'] = stripslashes($value); |
|
471 | 471 | } |
472 | 472 | } |
473 | 473 | |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | { |
491 | 491 | $shortcodes = []; |
492 | 492 | foreach ($groups as $group) { |
493 | - $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]); |
|
493 | + $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]); |
|
494 | 494 | } |
495 | 495 | return $shortcodes; |
496 | 496 | } |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
521 | 521 | $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
522 | 522 | // does this exist in the $valid_shortcodes? If so then unset. |
523 | - if (isset($valid_shortcodes[ $dynamic_sc ])) { |
|
524 | - unset($diff[ $ind ]); |
|
523 | + if (isset($valid_shortcodes[$dynamic_sc])) { |
|
524 | + unset($diff[$ind]); |
|
525 | 525 | } |
526 | 526 | } |
527 | 527 | } |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | |
533 | 533 | // made it here? then let's assemble the error message |
534 | 534 | $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
535 | - return '<strong>' . $invalid_shortcodes . '</strong>'; |
|
535 | + return '<strong>'.$invalid_shortcodes.'</strong>'; |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | // its possible that this message is being "turned off" for a particular context |
569 | 569 | |
570 | 570 | |
571 | - if (! empty($or_val) && empty($value)) { |
|
571 | + if ( ! empty($or_val) && empty($value)) { |
|
572 | 572 | return $validate; |
573 | 573 | } |
574 | 574 | |
@@ -627,8 +627,8 @@ discard block |
||
627 | 627 | '_MSGTYP' => '_message_type', |
628 | 628 | ]; |
629 | 629 | |
630 | - if (isset($expected_properties_map[ $property ])) { |
|
631 | - return $this->{$expected_properties_map[ $property ]}; |
|
630 | + if (isset($expected_properties_map[$property])) { |
|
631 | + return $this->{$expected_properties_map[$property]}; |
|
632 | 632 | } |
633 | 633 | |
634 | 634 | throw new Exception( |
@@ -15,626 +15,626 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class EE_Messages_Validator extends EE_Base |
17 | 17 | { |
18 | - /** |
|
19 | - * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
20 | - * These are used for retrieving objects etc. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_m_name; |
|
25 | - |
|
26 | - protected $_mt_name; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * This will hold any error messages from the validation process. |
|
31 | - * The _errors property holds an associative array of error messages |
|
32 | - * listing the field as the key and the message as the value. |
|
33 | - * |
|
34 | - * @var array() |
|
35 | - */ |
|
36 | - private $_errors = []; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * holds an array of fields being validated |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - protected $_fields; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * this will hold the incoming context |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_context; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * this holds an array of fields and the relevant validation information |
|
57 | - * that the incoming fields data get validated against. |
|
58 | - * This gets setup in the _set_props() method. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - protected $_validators; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * holds the messenger object |
|
67 | - * |
|
68 | - * @var object |
|
69 | - */ |
|
70 | - protected $_messenger; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * holds the message type object |
|
75 | - * |
|
76 | - * @var object |
|
77 | - */ |
|
78 | - protected $_message_type; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
83 | - * |
|
84 | - * @var array |
|
85 | - */ |
|
86 | - protected $_valid_shortcodes_modifier; |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * There may be times where a message type wants to include a shortcode group but exclude specific |
|
91 | - * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
92 | - * they will not be allowed. |
|
93 | - * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
94 | - * |
|
95 | - * @var array |
|
96 | - */ |
|
97 | - protected $_specific_shortcode_excludes = []; |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Runs the validator using the incoming fields array as the fields/values to check. |
|
102 | - * |
|
103 | - * @param array $fields The fields sent by the EEM object. |
|
104 | - * @param $context |
|
105 | - * @throws EE_Error |
|
106 | - * @throws ReflectionException |
|
107 | - */ |
|
108 | - public function __construct($fields, $context) |
|
109 | - { |
|
110 | - // check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
111 | - if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
112 | - throw new EE_Error( |
|
113 | - esc_html__( |
|
114 | - 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
115 | - 'event_espresso' |
|
116 | - ) |
|
117 | - ); |
|
118 | - } |
|
119 | - $this->_fields = $fields; |
|
120 | - $this->_context = $context; |
|
121 | - |
|
122 | - // load messenger and message_type objects and the related shortcode objects. |
|
123 | - $this->_load_objects(); |
|
124 | - |
|
125 | - |
|
126 | - // modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
127 | - $this->_modify_validator(); |
|
128 | - |
|
129 | - |
|
130 | - // let's set validators property |
|
131 | - $this->_set_validators(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Child classes instantiate this and use it to modify the _validator_config array property |
|
137 | - * for the messenger using messengers set_validate_config() method. |
|
138 | - * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
139 | - * that aren't handled by the defaults setup in the messenger. |
|
140 | - * |
|
141 | - * @abstract |
|
142 | - * @return void |
|
143 | - */ |
|
144 | - abstract protected function _modify_validator(); |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * loads all objects used by validator |
|
149 | - * |
|
150 | - * @throws EE_Error |
|
151 | - */ |
|
152 | - private function _load_objects() |
|
153 | - { |
|
154 | - // load messenger |
|
155 | - $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
156 | - $messenger = str_replace(' ', '_', $messenger); |
|
157 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
158 | - |
|
159 | - if (! class_exists($messenger)) { |
|
160 | - throw new EE_Error( |
|
161 | - sprintf( |
|
162 | - esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
163 | - $this->_m_name |
|
164 | - ) |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - $this->_messenger = new $messenger(); |
|
169 | - |
|
170 | - // load message type |
|
171 | - $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
172 | - $message_type = str_replace(' ', '_', $message_type); |
|
173 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
174 | - |
|
175 | - if (! class_exists($message_type)) { |
|
176 | - throw new EE_Error( |
|
177 | - sprintf( |
|
178 | - esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
|
179 | - $this->_mt_name |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - |
|
184 | - $this->_message_type = new $message_type(); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * used to set the $_validators property |
|
190 | - * |
|
191 | - * @return void |
|
192 | - * @throws ReflectionException |
|
193 | - */ |
|
194 | - private function _set_validators() |
|
195 | - { |
|
196 | - // let's get all valid shortcodes from mt and message type |
|
197 | - // (messenger will have its set in the _validator_config property for the messenger) |
|
198 | - $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
199 | - |
|
200 | - |
|
201 | - // get messenger validator_config |
|
202 | - $msgr_validator = $this->_messenger->get_validator_config(); |
|
203 | - |
|
204 | - |
|
205 | - // we only want the valid shortcodes for the given context! |
|
206 | - $context = $this->_context; |
|
207 | - $mt_codes = $mt_codes[ $context ]; |
|
208 | - |
|
209 | - // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
210 | - // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
211 | - $shortcode_groups = $mt_codes; |
|
212 | - $groups_per_field = []; |
|
213 | - |
|
214 | - foreach ($msgr_validator as $field => $config) { |
|
215 | - if (empty($config) || ! isset($config['shortcodes'])) { |
|
216 | - continue; |
|
217 | - } //Nothing to see here. |
|
218 | - $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
219 | - $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
220 | - } |
|
221 | - |
|
222 | - $shortcode_groups = array_unique($shortcode_groups); |
|
223 | - |
|
224 | - // okay now we've got our groups. |
|
225 | - // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
226 | - $codes_from_objs = []; |
|
227 | - |
|
228 | - foreach ($shortcode_groups as $group) { |
|
229 | - $ref = ucwords(str_replace('_', ' ', $group)); |
|
230 | - $ref = str_replace(' ', '_', $ref); |
|
231 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
232 | - if (class_exists($classname)) { |
|
233 | - $a = new ReflectionClass($classname); |
|
234 | - $obj = $a->newInstance(); |
|
235 | - $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
241 | - $final_mt_codes = []; |
|
242 | - foreach ($mt_codes as $group) { |
|
243 | - $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
244 | - } |
|
245 | - |
|
246 | - $mt_codes = $final_mt_codes; |
|
247 | - |
|
248 | - |
|
249 | - // k now in this next loop we're going to loop through $msgr_validator again |
|
250 | - // and setup the _validators property from the data we've setup so far. |
|
251 | - foreach ($msgr_validator as $field => $config) { |
|
252 | - // if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
253 | - $required = isset($config['required']) |
|
254 | - ? array_intersect($config['required'], array_keys($mt_codes)) |
|
255 | - : true; |
|
256 | - if (empty($required)) { |
|
257 | - continue; |
|
258 | - } |
|
259 | - |
|
260 | - // If we have an override then we use it to indicate the codes we want. |
|
261 | - if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
262 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
263 | - $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
264 | - $codes_from_objs |
|
265 | - ); |
|
266 | - } elseif (isset($groups_per_field[ $field ])) { |
|
267 | - // we have specific shortcodes for a field so we need to use them |
|
268 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
269 | - $groups_per_field[ $field ], |
|
270 | - $codes_from_objs |
|
271 | - ); |
|
272 | - } elseif (empty($config)) { |
|
273 | - // no config so we're assuming we're just going to use the shortcodes from the message type context |
|
274 | - $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
275 | - } elseif (isset($config['specific_shortcodes'])) { |
|
276 | - // we have specific shortcodes so we need to use them |
|
277 | - $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
278 | - } else { |
|
279 | - // otherwise the shortcodes are what is set by the messenger for that field |
|
280 | - foreach ($config['shortcodes'] as $group) { |
|
281 | - $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes']) |
|
282 | - ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ]) |
|
283 | - : $codes_from_objs[ $group ]; |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - // now let's just make sure that any excluded specific shortcodes are removed. |
|
288 | - $specific_excludes = $this->get_specific_shortcode_excludes(); |
|
289 | - if (isset($specific_excludes[ $field ])) { |
|
290 | - foreach ($specific_excludes[ $field ] as $sex) { |
|
291 | - if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) { |
|
292 | - unset($this->_validators[ $field ]['shortcodes'][ $sex ]); |
|
293 | - } |
|
294 | - } |
|
295 | - } |
|
296 | - |
|
297 | - // hey! don't forget to include the type if present! |
|
298 | - $this->_validators[ $field ]['type'] = |
|
299 | - isset($config['type']) |
|
300 | - ? $config['type'] |
|
301 | - : null; |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * This just returns the validators property that contains information |
|
308 | - * about the various shortcodes and their availability with each field |
|
309 | - * |
|
310 | - * @return array |
|
311 | - */ |
|
312 | - public function get_validators() |
|
313 | - { |
|
314 | - return $this->_validators; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * This simply returns the specific shortcode_excludes property that is set. |
|
320 | - * |
|
321 | - * @return array |
|
322 | - * @since 4.5.0 |
|
323 | - */ |
|
324 | - public function get_specific_shortcode_excludes() |
|
325 | - { |
|
326 | - // specific validator filter |
|
327 | - $shortcode_excludes = apply_filters( |
|
328 | - 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
329 | - $this->_specific_shortcode_excludes, |
|
330 | - $this->_context |
|
331 | - ); |
|
332 | - // global filter |
|
333 | - return apply_filters( |
|
334 | - 'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes', |
|
335 | - $shortcode_excludes, |
|
336 | - $this->_context, |
|
337 | - $this |
|
338 | - ); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * This is the main method that handles validation |
|
344 | - * What it does is loop through the _fields (the ones that get validated) |
|
345 | - * and checks them against the shortcodes array for the field and the 'type' indicated by the |
|
346 | - * |
|
347 | - * @return array|bool if errors present we return the array otherwise true |
|
348 | - */ |
|
349 | - public function validate() |
|
350 | - { |
|
351 | - // some defaults |
|
352 | - $template_fields = $this->_messenger->get_template_fields(); |
|
353 | - // loop through the fields and check! |
|
354 | - foreach ($this->_fields as $field => $value) { |
|
355 | - $this->_errors[ $field ] = []; |
|
356 | - $err_msg = ''; |
|
357 | - $field_label = ''; |
|
358 | - // if field is not present in the _validators array then we continue |
|
359 | - if (! isset($this->_validators[ $field ])) { |
|
360 | - unset($this->_errors[ $field ]); |
|
361 | - continue; |
|
362 | - } |
|
363 | - |
|
364 | - // get the translated field label! |
|
365 | - // first check if it's in the main fields list |
|
366 | - if (isset($template_fields[ $field ])) { |
|
367 | - // most likely the field is found in the 'extra' array. |
|
368 | - $field_label = ! empty($template_fields[ $field ]) |
|
369 | - ? $template_fields[ $field ]['label'] |
|
370 | - : $field; |
|
371 | - } |
|
372 | - |
|
373 | - // if field label is empty OR is equal to the current field |
|
374 | - // then we need to loop through the 'extra' fields in the template_fields config (if present) |
|
375 | - if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) { |
|
376 | - foreach ($template_fields['extra'] as $main_field => $secondary_field) { |
|
377 | - foreach ($secondary_field as $name => $values) { |
|
378 | - if ($name === $field) { |
|
379 | - $field_label = $values['label']; |
|
380 | - } |
|
381 | - |
|
382 | - // if we've got a 'main' secondary field, let's see if that matches what field we're on |
|
383 | - // which means it contains the label for this field. |
|
384 | - if ($name === 'main' && $main_field === $field_label) { |
|
385 | - $field_label = $values['label']; |
|
386 | - } |
|
387 | - } |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - // field is present. Let's validate shortcodes first (but only if shortcodes present). |
|
392 | - if ( |
|
393 | - isset($this->_validators[ $field ]['shortcodes']) |
|
394 | - && ! empty($this->_validators[ $field ]['shortcodes']) |
|
395 | - ) { |
|
396 | - $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']); |
|
397 | - // if true then that means there is a returned error message |
|
398 | - // that we'll need to add to the _errors array for this field. |
|
399 | - if ($invalid_shortcodes) { |
|
400 | - $v_s = array_keys($this->_validators[ $field ]['shortcodes']); |
|
401 | - $err_msg = sprintf( |
|
402 | - esc_html__( |
|
403 | - '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
|
404 | - 'event_espresso' |
|
405 | - ), |
|
406 | - '<strong>' . $field_label . '</strong>', |
|
407 | - $invalid_shortcodes, |
|
408 | - '<p>', |
|
409 | - '</p >' |
|
410 | - ); |
|
411 | - $err_msg .= sprintf( |
|
412 | - esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'), |
|
413 | - implode(', ', $v_s), |
|
414 | - '<strong>', |
|
415 | - '</strong>' |
|
416 | - ); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - // if there's a "type" to be validated then let's do that too. |
|
421 | - if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) { |
|
422 | - switch ($this->_validators[ $field ]['type']) { |
|
423 | - case 'number': |
|
424 | - if (! is_numeric($value)) { |
|
425 | - $err_msg .= sprintf( |
|
426 | - esc_html__( |
|
427 | - '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
|
428 | - 'event_espresso' |
|
429 | - ), |
|
430 | - $field_label, |
|
431 | - $value, |
|
432 | - '<p>', |
|
433 | - '</p >' |
|
434 | - ); |
|
435 | - } |
|
436 | - break; |
|
437 | - case 'email': |
|
438 | - $valid_email = $this->_validate_email($value); |
|
439 | - if (! $valid_email) { |
|
440 | - $err_msg .= htmlentities( |
|
441 | - sprintf( |
|
442 | - esc_html__( |
|
443 | - 'The %1$s field has at least one string that is not a valid email address record. Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.', |
|
444 | - 'event_espresso' |
|
445 | - ), |
|
446 | - $field_label |
|
447 | - ) |
|
448 | - ); |
|
449 | - } |
|
450 | - break; |
|
451 | - default: |
|
452 | - break; |
|
453 | - } |
|
454 | - } |
|
455 | - |
|
456 | - // if $err_msg isn't empty let's setup the _errors array for this field. |
|
457 | - if (! empty($err_msg)) { |
|
458 | - $this->_errors[ $field ]['msg'] = $err_msg; |
|
459 | - } else { |
|
460 | - unset($this->_errors[ $field ]); |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - // if we have ANY errors, then we want to make sure we return the values |
|
465 | - // for ALL the fields so the user doesn't have to retype them all. |
|
466 | - if (! empty($this->_errors)) { |
|
467 | - foreach ($this->_fields as $field => $value) { |
|
468 | - $this->_errors[ $field ]['value'] = stripslashes($value); |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - // return any errors or just TRUE if everything validates |
|
473 | - return empty($this->_errors) |
|
474 | - ? true |
|
475 | - : $this->_errors; |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Reassembles and returns an array of valid shortcodes |
|
481 | - * given the array of groups and array of shortcodes indexed by group. |
|
482 | - * |
|
483 | - * @param array $groups array of shortcode groups that we want shortcodes for |
|
484 | - * @param array $codes_from_objs All the codes available. |
|
485 | - * @return array an array of actual shortcodes (that will be used for validation). |
|
486 | - */ |
|
487 | - private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs) |
|
488 | - { |
|
489 | - $shortcodes = []; |
|
490 | - foreach ($groups as $group) { |
|
491 | - $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]); |
|
492 | - } |
|
493 | - return $shortcodes; |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * Validates a string against a list of accepted shortcodes |
|
499 | - * This function takes in an array of shortcodes |
|
500 | - * and makes sure that the given string ONLY contains shortcodes in that array. |
|
501 | - * |
|
502 | - * @param string $value string to evaluate |
|
503 | - * @param array $valid_shortcodes array of shortcodes that are acceptable. |
|
504 | - * @return bool|string return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
505 | - */ |
|
506 | - protected function _invalid_shortcodes($value, $valid_shortcodes) |
|
507 | - { |
|
508 | - // first we need to go through the string and get the shortcodes in the string |
|
509 | - preg_match_all('/(\[.+?\])/', $value, $matches); |
|
510 | - $incoming_shortcodes = (array) $matches[0]; |
|
511 | - |
|
512 | - // get a diff of the shortcodes in the string vs the valid shortcodes |
|
513 | - $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
|
514 | - |
|
515 | - // we need to account for custom codes so let's loop through the diff and remove any of those type of codes |
|
516 | - foreach ($diff as $ind => $code) { |
|
517 | - if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) { |
|
518 | - // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
|
519 | - $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
|
520 | - // does this exist in the $valid_shortcodes? If so then unset. |
|
521 | - if (isset($valid_shortcodes[ $dynamic_sc ])) { |
|
522 | - unset($diff[ $ind ]); |
|
523 | - } |
|
524 | - } |
|
525 | - } |
|
526 | - |
|
527 | - if (empty($diff)) { |
|
528 | - return false; |
|
529 | - } //there is no diff, we have no invalid shortcodes, so return |
|
530 | - |
|
531 | - // made it here? then let's assemble the error message |
|
532 | - $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
|
533 | - return '<strong>' . $invalid_shortcodes . '</strong>'; |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * Validates an incoming string and makes sure we have valid emails in the string. |
|
539 | - * |
|
540 | - * @param string $value incoming value to validate |
|
541 | - * @return bool true if the string validates, false if it doesn't |
|
542 | - */ |
|
543 | - protected function _validate_email($value) |
|
544 | - { |
|
545 | - $validate = true; |
|
546 | - $or_val = $value; |
|
547 | - |
|
548 | - // empty strings will validate because this is how a message template |
|
549 | - // for a particular context can be "turned off" (if there is no email then no message) |
|
550 | - if (empty($value)) { |
|
551 | - return $validate; |
|
552 | - } |
|
553 | - |
|
554 | - // first determine if there ARE any shortcodes. |
|
555 | - // If there are shortcodes and then later we find that there were no other valid emails |
|
556 | - // but the field isn't empty... |
|
557 | - // that means we've got extra commas that were left after stripping out shortcodes so probably still valid. |
|
558 | - $has_shortcodes = preg_match('/(\[.+?\])/', $value); |
|
559 | - |
|
560 | - // first we need to strip out all the shortcodes! |
|
561 | - $value = preg_replace('/(\[.+?\])/', '', $value); |
|
562 | - |
|
563 | - // if original value is not empty and new value is, then we've parsed out a shortcode |
|
564 | - // and we now have an empty string which DOES validate. |
|
565 | - // We also validate complete empty field for email because |
|
566 | - // its possible that this message is being "turned off" for a particular context |
|
567 | - |
|
568 | - |
|
569 | - if (! empty($or_val) && empty($value)) { |
|
570 | - return $validate; |
|
571 | - } |
|
572 | - |
|
573 | - // trim any commas from beginning and end of string ( after whitespace trimmed ); |
|
574 | - $value = trim(trim($value), ','); |
|
575 | - |
|
576 | - |
|
577 | - // next we need to split up the string if its comma delimited. |
|
578 | - $emails = explode(',', $value); |
|
579 | - $empty = false; // used to indicate that there is an empty comma. |
|
580 | - // now let's loop through the emails and do our checks |
|
581 | - foreach ($emails as $email) { |
|
582 | - if (empty($email)) { |
|
583 | - $empty = true; |
|
584 | - continue; |
|
585 | - } |
|
586 | - |
|
587 | - // trim whitespace |
|
588 | - $email = trim($email); |
|
589 | - // either its of type "[email protected]", or its of type "fname lname <[email protected]>" |
|
590 | - if (is_email($email)) { |
|
591 | - continue; |
|
592 | - } |
|
593 | - $matches = []; |
|
594 | - $validate = (bool) preg_match('/(.*)<(.+)>/', $email, $matches); |
|
595 | - if ($validate && is_email($matches[2])) { |
|
596 | - continue; |
|
597 | - } |
|
598 | - return false; |
|
599 | - } |
|
600 | - |
|
601 | - return $empty && ! $has_shortcodes |
|
602 | - ? false |
|
603 | - : $validate; |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * Magic getter |
|
609 | - * Using this to provide back compat with add-ons referencing deprecated properties. |
|
610 | - * |
|
611 | - * @param string $property Property being requested |
|
612 | - * @return mixed |
|
613 | - * @throws Exception |
|
614 | - */ |
|
615 | - public function __get($property) |
|
616 | - { |
|
617 | - $expected_properties_map = [ |
|
618 | - /** |
|
619 | - * @deprecated 4.9.0 |
|
620 | - */ |
|
621 | - '_MSGR' => '_messenger', |
|
622 | - /** |
|
623 | - * @deprecated 4.9.0 |
|
624 | - */ |
|
625 | - '_MSGTYP' => '_message_type', |
|
626 | - ]; |
|
627 | - |
|
628 | - if (isset($expected_properties_map[ $property ])) { |
|
629 | - return $this->{$expected_properties_map[ $property ]}; |
|
630 | - } |
|
631 | - |
|
632 | - throw new Exception( |
|
633 | - sprintf( |
|
634 | - esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'), |
|
635 | - $property, |
|
636 | - get_class($this) |
|
637 | - ) |
|
638 | - ); |
|
639 | - } |
|
18 | + /** |
|
19 | + * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
20 | + * These are used for retrieving objects etc. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_m_name; |
|
25 | + |
|
26 | + protected $_mt_name; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * This will hold any error messages from the validation process. |
|
31 | + * The _errors property holds an associative array of error messages |
|
32 | + * listing the field as the key and the message as the value. |
|
33 | + * |
|
34 | + * @var array() |
|
35 | + */ |
|
36 | + private $_errors = []; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * holds an array of fields being validated |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + protected $_fields; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * this will hold the incoming context |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_context; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * this holds an array of fields and the relevant validation information |
|
57 | + * that the incoming fields data get validated against. |
|
58 | + * This gets setup in the _set_props() method. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + protected $_validators; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * holds the messenger object |
|
67 | + * |
|
68 | + * @var object |
|
69 | + */ |
|
70 | + protected $_messenger; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * holds the message type object |
|
75 | + * |
|
76 | + * @var object |
|
77 | + */ |
|
78 | + protected $_message_type; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
83 | + * |
|
84 | + * @var array |
|
85 | + */ |
|
86 | + protected $_valid_shortcodes_modifier; |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * There may be times where a message type wants to include a shortcode group but exclude specific |
|
91 | + * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
92 | + * they will not be allowed. |
|
93 | + * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
94 | + * |
|
95 | + * @var array |
|
96 | + */ |
|
97 | + protected $_specific_shortcode_excludes = []; |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Runs the validator using the incoming fields array as the fields/values to check. |
|
102 | + * |
|
103 | + * @param array $fields The fields sent by the EEM object. |
|
104 | + * @param $context |
|
105 | + * @throws EE_Error |
|
106 | + * @throws ReflectionException |
|
107 | + */ |
|
108 | + public function __construct($fields, $context) |
|
109 | + { |
|
110 | + // check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
111 | + if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
112 | + throw new EE_Error( |
|
113 | + esc_html__( |
|
114 | + 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
115 | + 'event_espresso' |
|
116 | + ) |
|
117 | + ); |
|
118 | + } |
|
119 | + $this->_fields = $fields; |
|
120 | + $this->_context = $context; |
|
121 | + |
|
122 | + // load messenger and message_type objects and the related shortcode objects. |
|
123 | + $this->_load_objects(); |
|
124 | + |
|
125 | + |
|
126 | + // modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
127 | + $this->_modify_validator(); |
|
128 | + |
|
129 | + |
|
130 | + // let's set validators property |
|
131 | + $this->_set_validators(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Child classes instantiate this and use it to modify the _validator_config array property |
|
137 | + * for the messenger using messengers set_validate_config() method. |
|
138 | + * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
139 | + * that aren't handled by the defaults setup in the messenger. |
|
140 | + * |
|
141 | + * @abstract |
|
142 | + * @return void |
|
143 | + */ |
|
144 | + abstract protected function _modify_validator(); |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * loads all objects used by validator |
|
149 | + * |
|
150 | + * @throws EE_Error |
|
151 | + */ |
|
152 | + private function _load_objects() |
|
153 | + { |
|
154 | + // load messenger |
|
155 | + $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
156 | + $messenger = str_replace(' ', '_', $messenger); |
|
157 | + $messenger = 'EE_' . $messenger . '_messenger'; |
|
158 | + |
|
159 | + if (! class_exists($messenger)) { |
|
160 | + throw new EE_Error( |
|
161 | + sprintf( |
|
162 | + esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
163 | + $this->_m_name |
|
164 | + ) |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + $this->_messenger = new $messenger(); |
|
169 | + |
|
170 | + // load message type |
|
171 | + $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
172 | + $message_type = str_replace(' ', '_', $message_type); |
|
173 | + $message_type = 'EE_' . $message_type . '_message_type'; |
|
174 | + |
|
175 | + if (! class_exists($message_type)) { |
|
176 | + throw new EE_Error( |
|
177 | + sprintf( |
|
178 | + esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
|
179 | + $this->_mt_name |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + |
|
184 | + $this->_message_type = new $message_type(); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * used to set the $_validators property |
|
190 | + * |
|
191 | + * @return void |
|
192 | + * @throws ReflectionException |
|
193 | + */ |
|
194 | + private function _set_validators() |
|
195 | + { |
|
196 | + // let's get all valid shortcodes from mt and message type |
|
197 | + // (messenger will have its set in the _validator_config property for the messenger) |
|
198 | + $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
199 | + |
|
200 | + |
|
201 | + // get messenger validator_config |
|
202 | + $msgr_validator = $this->_messenger->get_validator_config(); |
|
203 | + |
|
204 | + |
|
205 | + // we only want the valid shortcodes for the given context! |
|
206 | + $context = $this->_context; |
|
207 | + $mt_codes = $mt_codes[ $context ]; |
|
208 | + |
|
209 | + // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
210 | + // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
211 | + $shortcode_groups = $mt_codes; |
|
212 | + $groups_per_field = []; |
|
213 | + |
|
214 | + foreach ($msgr_validator as $field => $config) { |
|
215 | + if (empty($config) || ! isset($config['shortcodes'])) { |
|
216 | + continue; |
|
217 | + } //Nothing to see here. |
|
218 | + $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
219 | + $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
220 | + } |
|
221 | + |
|
222 | + $shortcode_groups = array_unique($shortcode_groups); |
|
223 | + |
|
224 | + // okay now we've got our groups. |
|
225 | + // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
226 | + $codes_from_objs = []; |
|
227 | + |
|
228 | + foreach ($shortcode_groups as $group) { |
|
229 | + $ref = ucwords(str_replace('_', ' ', $group)); |
|
230 | + $ref = str_replace(' ', '_', $ref); |
|
231 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
232 | + if (class_exists($classname)) { |
|
233 | + $a = new ReflectionClass($classname); |
|
234 | + $obj = $a->newInstance(); |
|
235 | + $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
241 | + $final_mt_codes = []; |
|
242 | + foreach ($mt_codes as $group) { |
|
243 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
244 | + } |
|
245 | + |
|
246 | + $mt_codes = $final_mt_codes; |
|
247 | + |
|
248 | + |
|
249 | + // k now in this next loop we're going to loop through $msgr_validator again |
|
250 | + // and setup the _validators property from the data we've setup so far. |
|
251 | + foreach ($msgr_validator as $field => $config) { |
|
252 | + // if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
253 | + $required = isset($config['required']) |
|
254 | + ? array_intersect($config['required'], array_keys($mt_codes)) |
|
255 | + : true; |
|
256 | + if (empty($required)) { |
|
257 | + continue; |
|
258 | + } |
|
259 | + |
|
260 | + // If we have an override then we use it to indicate the codes we want. |
|
261 | + if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
262 | + $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
263 | + $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
264 | + $codes_from_objs |
|
265 | + ); |
|
266 | + } elseif (isset($groups_per_field[ $field ])) { |
|
267 | + // we have specific shortcodes for a field so we need to use them |
|
268 | + $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
269 | + $groups_per_field[ $field ], |
|
270 | + $codes_from_objs |
|
271 | + ); |
|
272 | + } elseif (empty($config)) { |
|
273 | + // no config so we're assuming we're just going to use the shortcodes from the message type context |
|
274 | + $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
275 | + } elseif (isset($config['specific_shortcodes'])) { |
|
276 | + // we have specific shortcodes so we need to use them |
|
277 | + $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
278 | + } else { |
|
279 | + // otherwise the shortcodes are what is set by the messenger for that field |
|
280 | + foreach ($config['shortcodes'] as $group) { |
|
281 | + $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes']) |
|
282 | + ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ]) |
|
283 | + : $codes_from_objs[ $group ]; |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + // now let's just make sure that any excluded specific shortcodes are removed. |
|
288 | + $specific_excludes = $this->get_specific_shortcode_excludes(); |
|
289 | + if (isset($specific_excludes[ $field ])) { |
|
290 | + foreach ($specific_excludes[ $field ] as $sex) { |
|
291 | + if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) { |
|
292 | + unset($this->_validators[ $field ]['shortcodes'][ $sex ]); |
|
293 | + } |
|
294 | + } |
|
295 | + } |
|
296 | + |
|
297 | + // hey! don't forget to include the type if present! |
|
298 | + $this->_validators[ $field ]['type'] = |
|
299 | + isset($config['type']) |
|
300 | + ? $config['type'] |
|
301 | + : null; |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * This just returns the validators property that contains information |
|
308 | + * about the various shortcodes and their availability with each field |
|
309 | + * |
|
310 | + * @return array |
|
311 | + */ |
|
312 | + public function get_validators() |
|
313 | + { |
|
314 | + return $this->_validators; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * This simply returns the specific shortcode_excludes property that is set. |
|
320 | + * |
|
321 | + * @return array |
|
322 | + * @since 4.5.0 |
|
323 | + */ |
|
324 | + public function get_specific_shortcode_excludes() |
|
325 | + { |
|
326 | + // specific validator filter |
|
327 | + $shortcode_excludes = apply_filters( |
|
328 | + 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
329 | + $this->_specific_shortcode_excludes, |
|
330 | + $this->_context |
|
331 | + ); |
|
332 | + // global filter |
|
333 | + return apply_filters( |
|
334 | + 'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes', |
|
335 | + $shortcode_excludes, |
|
336 | + $this->_context, |
|
337 | + $this |
|
338 | + ); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * This is the main method that handles validation |
|
344 | + * What it does is loop through the _fields (the ones that get validated) |
|
345 | + * and checks them against the shortcodes array for the field and the 'type' indicated by the |
|
346 | + * |
|
347 | + * @return array|bool if errors present we return the array otherwise true |
|
348 | + */ |
|
349 | + public function validate() |
|
350 | + { |
|
351 | + // some defaults |
|
352 | + $template_fields = $this->_messenger->get_template_fields(); |
|
353 | + // loop through the fields and check! |
|
354 | + foreach ($this->_fields as $field => $value) { |
|
355 | + $this->_errors[ $field ] = []; |
|
356 | + $err_msg = ''; |
|
357 | + $field_label = ''; |
|
358 | + // if field is not present in the _validators array then we continue |
|
359 | + if (! isset($this->_validators[ $field ])) { |
|
360 | + unset($this->_errors[ $field ]); |
|
361 | + continue; |
|
362 | + } |
|
363 | + |
|
364 | + // get the translated field label! |
|
365 | + // first check if it's in the main fields list |
|
366 | + if (isset($template_fields[ $field ])) { |
|
367 | + // most likely the field is found in the 'extra' array. |
|
368 | + $field_label = ! empty($template_fields[ $field ]) |
|
369 | + ? $template_fields[ $field ]['label'] |
|
370 | + : $field; |
|
371 | + } |
|
372 | + |
|
373 | + // if field label is empty OR is equal to the current field |
|
374 | + // then we need to loop through the 'extra' fields in the template_fields config (if present) |
|
375 | + if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) { |
|
376 | + foreach ($template_fields['extra'] as $main_field => $secondary_field) { |
|
377 | + foreach ($secondary_field as $name => $values) { |
|
378 | + if ($name === $field) { |
|
379 | + $field_label = $values['label']; |
|
380 | + } |
|
381 | + |
|
382 | + // if we've got a 'main' secondary field, let's see if that matches what field we're on |
|
383 | + // which means it contains the label for this field. |
|
384 | + if ($name === 'main' && $main_field === $field_label) { |
|
385 | + $field_label = $values['label']; |
|
386 | + } |
|
387 | + } |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + // field is present. Let's validate shortcodes first (but only if shortcodes present). |
|
392 | + if ( |
|
393 | + isset($this->_validators[ $field ]['shortcodes']) |
|
394 | + && ! empty($this->_validators[ $field ]['shortcodes']) |
|
395 | + ) { |
|
396 | + $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']); |
|
397 | + // if true then that means there is a returned error message |
|
398 | + // that we'll need to add to the _errors array for this field. |
|
399 | + if ($invalid_shortcodes) { |
|
400 | + $v_s = array_keys($this->_validators[ $field ]['shortcodes']); |
|
401 | + $err_msg = sprintf( |
|
402 | + esc_html__( |
|
403 | + '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
|
404 | + 'event_espresso' |
|
405 | + ), |
|
406 | + '<strong>' . $field_label . '</strong>', |
|
407 | + $invalid_shortcodes, |
|
408 | + '<p>', |
|
409 | + '</p >' |
|
410 | + ); |
|
411 | + $err_msg .= sprintf( |
|
412 | + esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'), |
|
413 | + implode(', ', $v_s), |
|
414 | + '<strong>', |
|
415 | + '</strong>' |
|
416 | + ); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + // if there's a "type" to be validated then let's do that too. |
|
421 | + if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) { |
|
422 | + switch ($this->_validators[ $field ]['type']) { |
|
423 | + case 'number': |
|
424 | + if (! is_numeric($value)) { |
|
425 | + $err_msg .= sprintf( |
|
426 | + esc_html__( |
|
427 | + '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
|
428 | + 'event_espresso' |
|
429 | + ), |
|
430 | + $field_label, |
|
431 | + $value, |
|
432 | + '<p>', |
|
433 | + '</p >' |
|
434 | + ); |
|
435 | + } |
|
436 | + break; |
|
437 | + case 'email': |
|
438 | + $valid_email = $this->_validate_email($value); |
|
439 | + if (! $valid_email) { |
|
440 | + $err_msg .= htmlentities( |
|
441 | + sprintf( |
|
442 | + esc_html__( |
|
443 | + 'The %1$s field has at least one string that is not a valid email address record. Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.', |
|
444 | + 'event_espresso' |
|
445 | + ), |
|
446 | + $field_label |
|
447 | + ) |
|
448 | + ); |
|
449 | + } |
|
450 | + break; |
|
451 | + default: |
|
452 | + break; |
|
453 | + } |
|
454 | + } |
|
455 | + |
|
456 | + // if $err_msg isn't empty let's setup the _errors array for this field. |
|
457 | + if (! empty($err_msg)) { |
|
458 | + $this->_errors[ $field ]['msg'] = $err_msg; |
|
459 | + } else { |
|
460 | + unset($this->_errors[ $field ]); |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + // if we have ANY errors, then we want to make sure we return the values |
|
465 | + // for ALL the fields so the user doesn't have to retype them all. |
|
466 | + if (! empty($this->_errors)) { |
|
467 | + foreach ($this->_fields as $field => $value) { |
|
468 | + $this->_errors[ $field ]['value'] = stripslashes($value); |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + // return any errors or just TRUE if everything validates |
|
473 | + return empty($this->_errors) |
|
474 | + ? true |
|
475 | + : $this->_errors; |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Reassembles and returns an array of valid shortcodes |
|
481 | + * given the array of groups and array of shortcodes indexed by group. |
|
482 | + * |
|
483 | + * @param array $groups array of shortcode groups that we want shortcodes for |
|
484 | + * @param array $codes_from_objs All the codes available. |
|
485 | + * @return array an array of actual shortcodes (that will be used for validation). |
|
486 | + */ |
|
487 | + private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs) |
|
488 | + { |
|
489 | + $shortcodes = []; |
|
490 | + foreach ($groups as $group) { |
|
491 | + $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]); |
|
492 | + } |
|
493 | + return $shortcodes; |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * Validates a string against a list of accepted shortcodes |
|
499 | + * This function takes in an array of shortcodes |
|
500 | + * and makes sure that the given string ONLY contains shortcodes in that array. |
|
501 | + * |
|
502 | + * @param string $value string to evaluate |
|
503 | + * @param array $valid_shortcodes array of shortcodes that are acceptable. |
|
504 | + * @return bool|string return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
505 | + */ |
|
506 | + protected function _invalid_shortcodes($value, $valid_shortcodes) |
|
507 | + { |
|
508 | + // first we need to go through the string and get the shortcodes in the string |
|
509 | + preg_match_all('/(\[.+?\])/', $value, $matches); |
|
510 | + $incoming_shortcodes = (array) $matches[0]; |
|
511 | + |
|
512 | + // get a diff of the shortcodes in the string vs the valid shortcodes |
|
513 | + $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
|
514 | + |
|
515 | + // we need to account for custom codes so let's loop through the diff and remove any of those type of codes |
|
516 | + foreach ($diff as $ind => $code) { |
|
517 | + if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) { |
|
518 | + // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
|
519 | + $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
|
520 | + // does this exist in the $valid_shortcodes? If so then unset. |
|
521 | + if (isset($valid_shortcodes[ $dynamic_sc ])) { |
|
522 | + unset($diff[ $ind ]); |
|
523 | + } |
|
524 | + } |
|
525 | + } |
|
526 | + |
|
527 | + if (empty($diff)) { |
|
528 | + return false; |
|
529 | + } //there is no diff, we have no invalid shortcodes, so return |
|
530 | + |
|
531 | + // made it here? then let's assemble the error message |
|
532 | + $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
|
533 | + return '<strong>' . $invalid_shortcodes . '</strong>'; |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * Validates an incoming string and makes sure we have valid emails in the string. |
|
539 | + * |
|
540 | + * @param string $value incoming value to validate |
|
541 | + * @return bool true if the string validates, false if it doesn't |
|
542 | + */ |
|
543 | + protected function _validate_email($value) |
|
544 | + { |
|
545 | + $validate = true; |
|
546 | + $or_val = $value; |
|
547 | + |
|
548 | + // empty strings will validate because this is how a message template |
|
549 | + // for a particular context can be "turned off" (if there is no email then no message) |
|
550 | + if (empty($value)) { |
|
551 | + return $validate; |
|
552 | + } |
|
553 | + |
|
554 | + // first determine if there ARE any shortcodes. |
|
555 | + // If there are shortcodes and then later we find that there were no other valid emails |
|
556 | + // but the field isn't empty... |
|
557 | + // that means we've got extra commas that were left after stripping out shortcodes so probably still valid. |
|
558 | + $has_shortcodes = preg_match('/(\[.+?\])/', $value); |
|
559 | + |
|
560 | + // first we need to strip out all the shortcodes! |
|
561 | + $value = preg_replace('/(\[.+?\])/', '', $value); |
|
562 | + |
|
563 | + // if original value is not empty and new value is, then we've parsed out a shortcode |
|
564 | + // and we now have an empty string which DOES validate. |
|
565 | + // We also validate complete empty field for email because |
|
566 | + // its possible that this message is being "turned off" for a particular context |
|
567 | + |
|
568 | + |
|
569 | + if (! empty($or_val) && empty($value)) { |
|
570 | + return $validate; |
|
571 | + } |
|
572 | + |
|
573 | + // trim any commas from beginning and end of string ( after whitespace trimmed ); |
|
574 | + $value = trim(trim($value), ','); |
|
575 | + |
|
576 | + |
|
577 | + // next we need to split up the string if its comma delimited. |
|
578 | + $emails = explode(',', $value); |
|
579 | + $empty = false; // used to indicate that there is an empty comma. |
|
580 | + // now let's loop through the emails and do our checks |
|
581 | + foreach ($emails as $email) { |
|
582 | + if (empty($email)) { |
|
583 | + $empty = true; |
|
584 | + continue; |
|
585 | + } |
|
586 | + |
|
587 | + // trim whitespace |
|
588 | + $email = trim($email); |
|
589 | + // either its of type "[email protected]", or its of type "fname lname <[email protected]>" |
|
590 | + if (is_email($email)) { |
|
591 | + continue; |
|
592 | + } |
|
593 | + $matches = []; |
|
594 | + $validate = (bool) preg_match('/(.*)<(.+)>/', $email, $matches); |
|
595 | + if ($validate && is_email($matches[2])) { |
|
596 | + continue; |
|
597 | + } |
|
598 | + return false; |
|
599 | + } |
|
600 | + |
|
601 | + return $empty && ! $has_shortcodes |
|
602 | + ? false |
|
603 | + : $validate; |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * Magic getter |
|
609 | + * Using this to provide back compat with add-ons referencing deprecated properties. |
|
610 | + * |
|
611 | + * @param string $property Property being requested |
|
612 | + * @return mixed |
|
613 | + * @throws Exception |
|
614 | + */ |
|
615 | + public function __get($property) |
|
616 | + { |
|
617 | + $expected_properties_map = [ |
|
618 | + /** |
|
619 | + * @deprecated 4.9.0 |
|
620 | + */ |
|
621 | + '_MSGR' => '_messenger', |
|
622 | + /** |
|
623 | + * @deprecated 4.9.0 |
|
624 | + */ |
|
625 | + '_MSGTYP' => '_message_type', |
|
626 | + ]; |
|
627 | + |
|
628 | + if (isset($expected_properties_map[ $property ])) { |
|
629 | + return $this->{$expected_properties_map[ $property ]}; |
|
630 | + } |
|
631 | + |
|
632 | + throw new Exception( |
|
633 | + sprintf( |
|
634 | + esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'), |
|
635 | + $property, |
|
636 | + get_class($this) |
|
637 | + ) |
|
638 | + ); |
|
639 | + } |
|
640 | 640 | } |