/** * Converts an underscored or CamelCase word into a English * sentence. * * The titleize static function converts text like "WelcomePage", * "welcome_page" or "welcome page" to this "Welcome * Page". * If second parameter is set to 'first' it will only * capitalize the first character of the title. * * @access public * @static * @param string $word Word to format as tile * @param string $uppercase If set to 'first' it will only uppercase the * first character. Otherwise it will uppercase all * the words in the title. * @return string Text formatted as title */ static function titleize($word, $uppercase = '') { $uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords'; return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); }
/** * * Gets all the related entities (or if its a belongs-to relation just the one) * to the item with the given id * * @param \WP_REST_Request $request * @return \WP_REST_Response|\WP_Error */ public static function handle_request_get_related(\WP_REST_Request $request) { $controller = new Read(); try { $matches = $controller->parse_route($request->get_route(), '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', array('version', 'model', 'id', 'related_model')); $controller->set_requested_version($matches['version']); $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); if (!$controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { return $controller->send_response(new \WP_Error('endpoint_parsing_error', sprintf(__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), $main_model_name_singular))); } $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); //assume the related model name is plural and try to find the model's name $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); if (!$controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { //so the word didn't singularize well. Maybe that's just because it's a singular word? $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); } if (!$controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { return $controller->send_response(new \WP_Error('endpoint_parsing_error', sprintf(__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), $related_model_name_singular))); } return $controller->send_response($controller->get_entities_from_relation($request->get_param('id'), $main_model->related_settings_for($related_model_name_singular), $request)); } catch (\Exception $e) { return $controller->send_response($e); } }
/** * Array of headers derived from EE sucess, attention, and error messages * @return array */ protected function _get_headers_from_ee_notices() { $headers = array(); $notices = \EE_Error::get_raw_notices(); foreach ($notices as $notice_type => $sub_notices) { if (!is_array($sub_notices)) { continue; } foreach ($sub_notices as $notice_code => $sub_notice) { $headers['X-EE4-Notices-' . \EEH_Inflector::humanize($notice_type) . '[' . $notice_code . ']'] = strip_tags($sub_notice); } } return apply_filters('FHEE__EventEspresso\\core\\libraries\\rest_api\\controllers\\Base___get_headers_from_ee_notices__return', $headers, $this->_requested_version, $notices); }