@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param WP $WP |
43 | 43 | * @return void |
44 | 44 | */ |
45 | - public abstract function run( WP $WP ); |
|
45 | + public abstract function run(WP $WP); |
|
46 | 46 | |
47 | 47 | |
48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param array $attributes |
55 | 55 | * @return mixed |
56 | 56 | */ |
57 | - public abstract function process_shortcode( $attributes = array() ); |
|
57 | + public abstract function process_shortcode($attributes = array()); |
|
58 | 58 | |
59 | 59 | |
60 | 60 | |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | * @param string $shortcode_class |
66 | 66 | * @return \EES_Shortcode |
67 | 67 | */ |
68 | - final public static function instance( $shortcode_class = NULL ) { |
|
69 | - $shortcode_class = ! empty( $shortcode_class ) ? $shortcode_class : get_called_class(); |
|
70 | - if ( $shortcode_class == 'EES_Shortcode' || empty( $shortcode_class )) { |
|
68 | + final public static function instance($shortcode_class = NULL) { |
|
69 | + $shortcode_class = ! empty($shortcode_class) ? $shortcode_class : get_called_class(); |
|
70 | + if ($shortcode_class == 'EES_Shortcode' || empty($shortcode_class)) { |
|
71 | 71 | return NULL; |
72 | 72 | } |
73 | - $shortcode = str_replace( 'EES_', '', strtoupper( $shortcode_class )); |
|
74 | - $shortcode_obj = isset( EE_Registry::instance()->shortcodes->{$shortcode} ) ? EE_Registry::instance()->shortcodes->{$shortcode} : NULL; |
|
73 | + $shortcode = str_replace('EES_', '', strtoupper($shortcode_class)); |
|
74 | + $shortcode_obj = isset(EE_Registry::instance()->shortcodes->{$shortcode} ) ? EE_Registry::instance()->shortcodes->{$shortcode} : NULL; |
|
75 | 75 | return $shortcode_obj instanceof $shortcode_class || $shortcode_class == 'self' ? $shortcode_obj : new $shortcode_class(); |
76 | 76 | } |
77 | 77 | |
@@ -86,23 +86,23 @@ discard block |
||
86 | 86 | * @param $attributes |
87 | 87 | * @return mixed |
88 | 88 | */ |
89 | - final public static function fallback_shortcode_processor( $attributes ) { |
|
90 | - if ( EE_Maintenance_Mode::disable_frontend_for_maintenance() ) { |
|
89 | + final public static function fallback_shortcode_processor($attributes) { |
|
90 | + if (EE_Maintenance_Mode::disable_frontend_for_maintenance()) { |
|
91 | 91 | return null; |
92 | 92 | } |
93 | 93 | // what shortcode was actually parsed ? |
94 | 94 | $shortcode_class = get_called_class(); |
95 | 95 | // notify rest of system that fallback processor was triggered |
96 | - add_filter( 'FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true' ); |
|
96 | + add_filter('FHEE__fallback_shortcode_processor__'.$shortcode_class, '__return_true'); |
|
97 | 97 | // get instance of actual shortcode |
98 | - $shortcode_obj = self::instance( $shortcode_class ); |
|
98 | + $shortcode_obj = self::instance($shortcode_class); |
|
99 | 99 | // verify class |
100 | - if ( $shortcode_obj instanceof EES_Shortcode ) { |
|
100 | + if ($shortcode_obj instanceof EES_Shortcode) { |
|
101 | 101 | global $wp; |
102 | - $shortcode_obj->run( $wp ); |
|
102 | + $shortcode_obj->run($wp); |
|
103 | 103 | // set attributes and run the shortcode |
104 | - $shortcode_obj->_attributes = (array)$attributes; |
|
105 | - return $shortcode_obj->process_shortcode( $shortcode_obj->_attributes ); |
|
104 | + $shortcode_obj->_attributes = (array) $attributes; |
|
105 | + return $shortcode_obj->process_shortcode($shortcode_obj->_attributes); |
|
106 | 106 | } else { |
107 | 107 | return NULL; |
108 | 108 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param $attributes |
119 | 119 | * @return string |
120 | 120 | */ |
121 | - final public static function invalid_shortcode_processor( $attributes ) { |
|
121 | + final public static function invalid_shortcode_processor($attributes) { |
|
122 | 122 | return ''; |
123 | 123 | } |
124 | 124 | |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | */ |
133 | 133 | final public function __construct() { |
134 | 134 | // get classname, remove EES_prefix, and convert to UPPERCASE |
135 | - $shortcode = strtoupper( str_replace( 'EES_', '', get_class( $this ))); |
|
135 | + $shortcode = strtoupper(str_replace('EES_', '', get_class($this))); |
|
136 | 136 | // assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier |
137 | - add_shortcode( $shortcode, array( $this, 'process_shortcode' )); |
|
137 | + add_shortcode($shortcode, array($this, 'process_shortcode')); |
|
138 | 138 | // make sure system knows this is an EE page |
139 | - EE_Registry::instance()->REQ->set_espresso_page( TRUE ); |
|
139 | + EE_Registry::instance()->REQ->set_espresso_page(TRUE); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |
@@ -77,7 +77,7 @@ |
||
77 | 77 | } |
78 | 78 | foreach( $model->field_settings() as $field_name => $field_obj ){ |
79 | 79 | if( $model_version_info->field_has_rendered_format( $field_obj ) |
80 | - && isset( $entity[ $field_name ] ) |
|
80 | + && isset( $entity[ $field_name ] ) |
|
81 | 81 | && is_array( $entity[ $field_name ] ) |
82 | 82 | && isset( $entity[ $field_name ][ 'raw' ] ) |
83 | 83 | ) { |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
4 | - exit( 'No direct script access allowed' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -21,16 +21,16 @@ discard block |
||
21 | 21 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
22 | 22 | * @return boolean |
23 | 23 | */ |
24 | - public static function current_user_has_partial_access_to( $model, $model_context = \EEM_Base::caps_read ) { |
|
25 | - if( apply_filters( 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', false, $model, $model ) ) { |
|
24 | + public static function current_user_has_partial_access_to($model, $model_context = \EEM_Base::caps_read) { |
|
25 | + if (apply_filters('FHEE__Capabilities__current_user_has_partial_access_to__override_begin', false, $model, $model)) { |
|
26 | 26 | return true; |
27 | 27 | } |
28 | - foreach( $model->caps_missing( $model_context ) as $capability_name => $restriction_obj ) { |
|
29 | - if( $restriction_obj instanceof \EE_Return_None_Where_Conditions ){ |
|
28 | + foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) { |
|
29 | + if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) { |
|
30 | 30 | return false; |
31 | 31 | } |
32 | 32 | } |
33 | - if( apply_filters( 'FHEE__Capabilities__current_user_has_partial_access_to__override_end', false, $model, $model ) ) { |
|
33 | + if (apply_filters('FHEE__Capabilities__current_user_has_partial_access_to__override_end', false, $model, $model)) { |
|
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | return true; |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @param string $request_type one of the constants on WP_JSON_Server |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - public static function get_missing_permissions( $model, $request_type = \EEM_Base::caps_read ) { |
|
47 | - return $model->caps_missing( $request_type ); |
|
46 | + public static function get_missing_permissions($model, $request_type = \EEM_Base::caps_read) { |
|
47 | + return $model->caps_missing($request_type); |
|
48 | 48 | } |
49 | 49 | /** |
50 | 50 | * Gets a string of all the capabilities the current user is missing that affected |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - public static function get_missing_permissions_string( $model, $model_context = \EEM_Base::caps_read ) { |
|
58 | - return implode(',', array_keys( self::get_missing_permissions( $model, $model_context ) ) ); |
|
57 | + public static function get_missing_permissions_string($model, $model_context = \EEM_Base::caps_read) { |
|
58 | + return implode(',', array_keys(self::get_missing_permissions($model, $model_context))); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -66,27 +66,27 @@ discard block |
||
66 | 66 | * @param Model_Version_Info $model_version_info |
67 | 67 | * @return array ready for converting into json |
68 | 68 | */ |
69 | - public static function filter_out_inaccessible_entity_fields( $entity, $model, $request_type, $model_version_info ) { |
|
69 | + public static function filter_out_inaccessible_entity_fields($entity, $model, $request_type, $model_version_info) { |
|
70 | 70 | //we only care to do this for frontend reads and when the user can't edit the item |
71 | - if( $request_type !== \EEM_Base::caps_read || |
|
72 | - $model->exists( array( |
|
73 | - array( $model->primary_key_name() => $entity[ $model->primary_key_name() ] ), |
|
71 | + if ($request_type !== \EEM_Base::caps_read || |
|
72 | + $model->exists(array( |
|
73 | + array($model->primary_key_name() => $entity[$model->primary_key_name()]), |
|
74 | 74 | 'default_where_conditions' => 'none', |
75 | - 'caps' => \EEM_Base::caps_edit ) ) ) { |
|
75 | + 'caps' => \EEM_Base::caps_edit ))) { |
|
76 | 76 | return $entity; |
77 | 77 | } |
78 | - foreach( $model->field_settings() as $field_name => $field_obj ){ |
|
79 | - if( $model_version_info->field_has_rendered_format( $field_obj ) |
|
80 | - && isset( $entity[ $field_name ] ) |
|
81 | - && is_array( $entity[ $field_name ] ) |
|
82 | - && isset( $entity[ $field_name ][ 'raw' ] ) |
|
78 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
79 | + if ($model_version_info->field_has_rendered_format($field_obj) |
|
80 | + && isset($entity[$field_name]) |
|
81 | + && is_array($entity[$field_name]) |
|
82 | + && isset($entity[$field_name]['raw']) |
|
83 | 83 | ) { |
84 | - unset( $entity[ $field_name ][ 'raw' ] ); |
|
84 | + unset($entity[$field_name]['raw']); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | //theoretically we may want to filter out specific fields for specific models |
88 | 88 | |
89 | - return apply_filters( 'FHEE__Capabilities__filter_out_inaccessible_entity_fields', $entity, $model, $request_type ); |
|
89 | + return apply_filters('FHEE__Capabilities__filter_out_inaccessible_entity_fields', $entity, $model, $request_type); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | * @param \EE_Request $request |
71 | 71 | * @param \EE_Response $response |
72 | 72 | */ |
73 | - protected function __construct( EE_Request $request, EE_Response $response ) { |
|
73 | + protected function __construct(EE_Request $request, EE_Response $response) { |
|
74 | 74 | $this->_request = $request; |
75 | 75 | $this->_response = $response; |
76 | - add_action( 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', array( $this, 'initialize' ) ); |
|
77 | - do_action( 'EE_Dependency_Map____construct' ); |
|
76 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
77 | + do_action('EE_Dependency_Map____construct'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | |
@@ -95,10 +95,10 @@ discard block |
||
95 | 95 | * @param \EE_Response $response |
96 | 96 | * @return \EE_Dependency_Map instance |
97 | 97 | */ |
98 | - public static function instance( EE_Request $request = null, EE_Response $response = null ) { |
|
98 | + public static function instance(EE_Request $request = null, EE_Response $response = null) { |
|
99 | 99 | // check if class object is instantiated, and instantiated properly |
100 | - if ( ! self::$_instance instanceof EE_Dependency_Map ) { |
|
101 | - self::$_instance = new EE_Dependency_Map( $request, $response ); |
|
100 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
101 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
102 | 102 | } |
103 | 103 | return self::$_instance; |
104 | 104 | } |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * @param array $dependencies |
111 | 111 | * @return boolean |
112 | 112 | */ |
113 | - public static function register_dependencies( $class, $dependencies ) { |
|
114 | - if ( ! isset( self::$_instance->_dependency_map[ $class ] ) ) { |
|
115 | - self::$_instance->_dependency_map[ $class ] = (array)$dependencies; |
|
113 | + public static function register_dependencies($class, $dependencies) { |
|
114 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
115 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
116 | 116 | return true; |
117 | 117 | } |
118 | 118 | return false; |
@@ -126,18 +126,18 @@ discard block |
||
126 | 126 | * @return bool |
127 | 127 | * @throws \EE_Error |
128 | 128 | */ |
129 | - public static function register_class_loader( $class_name, $loader = 'load_core' ) { |
|
129 | + public static function register_class_loader($class_name, $loader = 'load_core') { |
|
130 | 130 | // check that loader method starts with "load_" and exists in EE_Registry |
131 | - if ( strpos( $loader, 'load_' ) !== 0 || ! method_exists( 'EE_Registry', $loader ) ) { |
|
131 | + if (strpos($loader, 'load_') !== 0 || ! method_exists('EE_Registry', $loader)) { |
|
132 | 132 | throw new EE_Error( |
133 | 133 | sprintf( |
134 | - __( '"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso' ), |
|
134 | + __('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
135 | 135 | $loader |
136 | 136 | ) |
137 | 137 | ); |
138 | 138 | } |
139 | - if ( ! isset( self::$_instance->_class_loaders[ $class_name ] ) ) { |
|
140 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
139 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
140 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
141 | 141 | return true; |
142 | 142 | } |
143 | 143 | return false; |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | * @param string $class_name |
161 | 161 | * @return boolean |
162 | 162 | */ |
163 | - public function has( $class_name = '' ) { |
|
164 | - return isset( $this->_dependency_map[ $class_name ] ) ? true : false; |
|
163 | + public function has($class_name = '') { |
|
164 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @param string $dependency |
174 | 174 | * @return bool |
175 | 175 | */ |
176 | - public function has_dependency_for_class( $class_name = '', $dependency = '' ) { |
|
177 | - return isset( $this->_dependency_map[ $class_name ], $this->_dependency_map[ $class_name ][ $dependency ] ) |
|
176 | + public function has_dependency_for_class($class_name = '', $dependency = '') { |
|
177 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
178 | 178 | ? true |
179 | 179 | : false; |
180 | 180 | } |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * @param string $dependency |
189 | 189 | * @return int |
190 | 190 | */ |
191 | - public function loading_strategy_for_class_dependency( $class_name = '', $dependency = '' ) { |
|
192 | - return $this->has_dependency_for_class( $class_name, $dependency ) |
|
193 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
191 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') { |
|
192 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
193 | + ? $this->_dependency_map[$class_name][$dependency] |
|
194 | 194 | : EE_Dependency_Map::not_registered; |
195 | 195 | } |
196 | 196 | |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | * @param string $class_name |
201 | 201 | * @return string | Closure |
202 | 202 | */ |
203 | - public function class_loader( $class_name ) { |
|
204 | - return isset( $this->_class_loaders[ $class_name ] ) ? $this->_class_loaders[ $class_name ] : ''; |
|
203 | + public function class_loader($class_name) { |
|
204 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | |
@@ -339,17 +339,17 @@ discard block |
||
339 | 339 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
340 | 340 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
341 | 341 | 'EE_Messages_Generator' => function() { |
342 | - return EE_Registry::instance()->load_lib( 'Messages_Generator', array(), false, false ); |
|
342 | + return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
343 | 343 | }, |
344 | - 'EE_Messages_Template_Defaults' => function( $arguments = array() ) { |
|
345 | - return EE_Registry::instance()->load_lib( 'Messages_Template_Defaults', $arguments, false, false ); |
|
344 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
345 | + return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
346 | 346 | }, |
347 | 347 | //load_model |
348 | 348 | 'EEM_Message_Template_Group' => 'load_model', |
349 | 349 | 'EEM_Message_Template' => 'load_model', |
350 | 350 | //load_helper |
351 | 351 | 'EEH_Parse_Shortcodes' => function() { |
352 | - if ( EE_Registry::instance()->load_helper( 'Parse_Shortcodes' ) ) { |
|
352 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
353 | 353 | return new EEH_Parse_Shortcodes(); |
354 | 354 | } |
355 | 355 | return null; |
@@ -316,7 +316,7 @@ |
||
316 | 316 | ); |
317 | 317 | // verify that post_shortcodes is set |
318 | 318 | \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
319 | - && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
319 | + && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
320 | 320 | ? \EE_Config::instance()->core->post_shortcodes |
321 | 321 | : array(); |
322 | 322 | // cycle thru post_shortcodes |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\admin; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -28,31 +28,31 @@ discard block |
||
28 | 28 | public static function set_hooks_admin() { |
29 | 29 | add_action( |
30 | 30 | 'save_post', |
31 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
31 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save'), |
|
32 | 32 | 100, |
33 | 33 | 2 |
34 | 34 | ); |
35 | 35 | add_action( |
36 | 36 | 'delete_post', |
37 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
37 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete'), |
|
38 | 38 | 100, |
39 | 39 | 1 |
40 | 40 | ); |
41 | 41 | add_action( |
42 | 42 | 'add_option_page_for_posts', |
43 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
43 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set'), |
|
44 | 44 | 100, |
45 | 45 | 2 |
46 | 46 | ); |
47 | 47 | add_action( |
48 | 48 | 'update_option', |
49 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
49 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change'), |
|
50 | 50 | 100, |
51 | 51 | 3 |
52 | 52 | ); |
53 | 53 | add_action( |
54 | 54 | 'delete_option', |
55 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
55 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete'), |
|
56 | 56 | 100, |
57 | 57 | 1 |
58 | 58 | ); |
@@ -72,61 +72,61 @@ discard block |
||
72 | 72 | * @param \WP_Post $post |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public static function parse_post_content_on_save( $post_ID, $post ) { |
|
75 | + public static function parse_post_content_on_save($post_ID, $post) { |
|
76 | 76 | // if the post is trashed, then let's remove our post shortcode tracking |
77 | - if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
78 | - PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
77 | + if ($post instanceof \WP_Post && $post->post_status === 'trash') { |
|
78 | + PostShortcodeTracking::unset_post_shortcodes_on_delete($post_ID); |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | // default post types |
82 | - $post_types = array( 'post' => 0, 'page' => 1 ); |
|
82 | + $post_types = array('post' => 0, 'page' => 1); |
|
83 | 83 | // add CPTs |
84 | 84 | $CPTs = \EE_Register_CPTs::get_CPTs(); |
85 | - $post_types = array_merge( $post_types, $CPTs ); |
|
85 | + $post_types = array_merge($post_types, $CPTs); |
|
86 | 86 | // for default or CPT posts... |
87 | - if ( isset( $post_types[ $post->post_type ] ) ) { |
|
87 | + if (isset($post_types[$post->post_type])) { |
|
88 | 88 | // post on frontpage ? |
89 | 89 | $page_for_posts = \EE_Config::get_page_for_posts(); |
90 | - if ( $post->post_name === $page_for_posts ) { |
|
91 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
90 | + if ($post->post_name === $page_for_posts) { |
|
91 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page($page_for_posts); |
|
92 | 92 | return; |
93 | 93 | } |
94 | 94 | // array of shortcodes indexed by post name |
95 | - \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
95 | + \EE_Registry::CFG()->core->post_shortcodes = isset(\EE_Registry::CFG()->core->post_shortcodes) |
|
96 | 96 | ? \EE_Registry::CFG()->core->post_shortcodes |
97 | 97 | : array(); |
98 | 98 | // whether to proceed with update |
99 | 99 | $update_post_shortcodes = false; |
100 | 100 | // empty both arrays |
101 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
101 | + \EE_Registry::CFG()->core->post_shortcodes[$post->post_name] = array(); |
|
102 | 102 | // check that posts page is already being tracked |
103 | - if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
103 | + if ( ! isset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts])) { |
|
104 | 104 | // if not, then ensure that it is properly added |
105 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
105 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts] = array(); |
|
106 | 106 | } |
107 | 107 | // loop thru shortcodes |
108 | - foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
108 | + foreach (\EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir) { |
|
109 | 109 | // convert to UPPERCASE to get actual shortcode |
110 | - $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
110 | + $EES_Shortcode = strtoupper($EES_Shortcode); |
|
111 | 111 | // is the shortcode in the post_content ? |
112 | - if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
112 | + if (strpos($post->post_content, $EES_Shortcode) !== false) { |
|
113 | 113 | // map shortcode to post names and post IDs |
114 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
114 | + \EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode] = $post_ID; |
|
115 | 115 | // and add this shortcode to the tracking for the blog page |
116 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
116 | + PostShortcodeTracking::set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID); |
|
117 | 117 | $update_post_shortcodes = true; |
118 | 118 | } else { |
119 | 119 | // shortcode is not present in post content, so check if we were tracking it previously |
120 | 120 | // stop tracking if shortcode is not used in this specific post |
121 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
122 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
121 | + if (isset(\EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode])) { |
|
122 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode]); |
|
123 | 123 | $update_post_shortcodes = true; |
124 | 124 | } |
125 | 125 | // make sure that something is set for the shortcode posts (even though we may remove this) |
126 | 126 | $shortcode_posts = isset( |
127 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
127 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] |
|
128 | 128 | ) |
129 | - ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
129 | + ? \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] |
|
130 | 130 | : array(); |
131 | 131 | // and stop tracking for this shortcode on the blog page if it is not used |
132 | 132 | $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | : $update_post_shortcodes; |
141 | 141 | } |
142 | 142 | } |
143 | - if ( $update_post_shortcodes ) { |
|
144 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
143 | + if ($update_post_shortcodes) { |
|
144 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
@@ -158,15 +158,15 @@ discard block |
||
158 | 158 | * @param string $page_for_posts |
159 | 159 | * @return void |
160 | 160 | */ |
161 | - protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) { |
|
162 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
161 | + protected static function set_post_shortcodes_for_posts_page($page_for_posts) { |
|
162 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts] = array(); |
|
163 | 163 | // loop thru shortcodes |
164 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
165 | - foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
166 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
164 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
165 | + foreach ($post_shortcodes as $EES_Shortcode => $post_ID) { |
|
166 | + PostShortcodeTracking::set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID); |
|
167 | 167 | } |
168 | 168 | } |
169 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
169 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | |
@@ -181,24 +181,24 @@ discard block |
||
181 | 181 | * @param $EES_Shortcode |
182 | 182 | * @param $post_ID |
183 | 183 | */ |
184 | - protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) { |
|
184 | + protected static function set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID) { |
|
185 | 185 | // critical page shortcodes that we do NOT want added to the Posts page (blog) |
186 | 186 | $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
187 | 187 | // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
188 | - if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
188 | + if (in_array($EES_Shortcode, $critical_shortcodes)) { |
|
189 | 189 | return; |
190 | 190 | } |
191 | 191 | // add shortcode to "Posts page" tracking |
192 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
192 | + if (isset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode])) { |
|
193 | 193 | // make sure tracking is in form of an array |
194 | - if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
195 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
196 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true |
|
194 | + if ( ! is_array(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode])) { |
|
195 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] = array( |
|
196 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] => true |
|
197 | 197 | ); |
198 | 198 | } |
199 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
199 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] += array($post_ID => true); |
|
200 | 200 | } else { |
201 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
201 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] = array($post_ID => true); |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
@@ -211,16 +211,16 @@ discard block |
||
211 | 211 | * @param int $ID |
212 | 212 | * @return void |
213 | 213 | */ |
214 | - public static function unset_post_shortcodes_on_delete( $ID ) { |
|
214 | + public static function unset_post_shortcodes_on_delete($ID) { |
|
215 | 215 | $update_post_shortcodes = false; |
216 | 216 | // post on frontpage ? |
217 | 217 | $page_for_posts = \EE_Config::get_page_for_posts(); |
218 | 218 | // looking for any references to this post |
219 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
219 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
220 | 220 | // is this the "Posts Page" (blog) ? |
221 | - if ( $post_name === $page_for_posts ) { |
|
221 | + if ($post_name === $page_for_posts) { |
|
222 | 222 | // loop thru shortcodes registered for the posts page |
223 | - foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
223 | + foreach ($post_shortcodes as $shortcode_class => $shortcode_posts) { |
|
224 | 224 | $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
225 | 225 | $ID, |
226 | 226 | $shortcode_class, |
@@ -233,17 +233,17 @@ discard block |
||
233 | 233 | } |
234 | 234 | } else { |
235 | 235 | // loop thru shortcodes registered for each page |
236 | - foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
236 | + foreach ($post_shortcodes as $shortcode_class => $post_ID) { |
|
237 | 237 | // if this is page is being deleted, then don't track any post shortcodes for it |
238 | - if ( $post_ID === $ID ) { |
|
239 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
238 | + if ($post_ID === $ID) { |
|
239 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$post_name]); |
|
240 | 240 | $update_post_shortcodes = true; |
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
244 | 244 | } |
245 | - if ( $update_post_shortcodes ) { |
|
246 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
245 | + if ($update_post_shortcodes) { |
|
246 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
@@ -268,20 +268,20 @@ discard block |
||
268 | 268 | $update_post_shortcodes = false |
269 | 269 | ) { |
270 | 270 | // make sure that an array of post IDs is being tracked for each shortcode |
271 | - if ( ! is_array( $shortcode_posts ) ) { |
|
272 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
271 | + if ( ! is_array($shortcode_posts)) { |
|
272 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class] = array( |
|
273 | 273 | $shortcode_posts => true |
274 | 274 | ); |
275 | 275 | $update_post_shortcodes = true; |
276 | 276 | } |
277 | 277 | // now if the ID of the post being deleted is in the $shortcode_posts array |
278 | - if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
279 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
278 | + if (is_array($shortcode_posts) && isset($shortcode_posts[$ID])) { |
|
279 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class][$ID]); |
|
280 | 280 | $update_post_shortcodes = true; |
281 | 281 | } |
282 | 282 | // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
283 | - if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
284 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
283 | + if (empty(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class])) { |
|
284 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class]); |
|
285 | 285 | $update_post_shortcodes = true; |
286 | 286 | } |
287 | 287 | return $update_post_shortcodes; |
@@ -296,9 +296,9 @@ discard block |
||
296 | 296 | * @param $page_for_posts |
297 | 297 | * @return void |
298 | 298 | */ |
299 | - public static function update_post_shortcodes( $page_for_posts = '' ) { |
|
299 | + public static function update_post_shortcodes($page_for_posts = '') { |
|
300 | 300 | // make sure page_for_posts is set |
301 | - $page_for_posts = ! empty( $page_for_posts ) |
|
301 | + $page_for_posts = ! empty($page_for_posts) |
|
302 | 302 | ? $page_for_posts |
303 | 303 | : \EE_Config::get_page_for_posts(); |
304 | 304 | // allow others to mess stuff up :D |
@@ -314,45 +314,45 @@ discard block |
||
314 | 314 | $page_for_posts |
315 | 315 | ); |
316 | 316 | // verify that post_shortcodes is set |
317 | - \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
318 | - && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
317 | + \EE_Config::instance()->core->post_shortcodes = isset(\EE_Config::instance()->core->post_shortcodes) |
|
318 | + && is_array(\EE_Config::instance()->core->post_shortcodes) |
|
319 | 319 | ? \EE_Config::instance()->core->post_shortcodes |
320 | 320 | : array(); |
321 | 321 | // cycle thru post_shortcodes |
322 | - foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
322 | + foreach (\EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes) { |
|
323 | 323 | // are there any shortcodes to track ? |
324 | - if ( ! empty( $shortcodes ) ) { |
|
324 | + if ( ! empty($shortcodes)) { |
|
325 | 325 | // loop thru list of tracked shortcodes |
326 | - foreach ( $shortcodes as $shortcode => $post_id ) { |
|
326 | + foreach ($shortcodes as $shortcode => $post_id) { |
|
327 | 327 | // if shortcode is for a critical page, |
328 | 328 | // BUT this is NOT the corresponding critical page for that shortcode |
329 | - if ( $post_name === $page_for_posts ) { |
|
329 | + if ($post_name === $page_for_posts) { |
|
330 | 330 | continue; |
331 | 331 | } |
332 | 332 | // skip the posts page, because we want all shortcodes registered for it |
333 | - if ( $post_name === $page_for_posts ) { |
|
333 | + if ($post_name === $page_for_posts) { |
|
334 | 334 | continue; |
335 | 335 | } |
336 | 336 | // make sure post still exists |
337 | - $post = get_post( $post_id ); |
|
337 | + $post = get_post($post_id); |
|
338 | 338 | // check that the post name matches what we have saved |
339 | - if ( $post && $post->post_name === $post_name ) { |
|
339 | + if ($post && $post->post_name === $post_name) { |
|
340 | 340 | // if so, then break before hitting the unset below |
341 | 341 | continue; |
342 | 342 | } |
343 | 343 | // we don't like missing posts around here >:( |
344 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
344 | + unset(\EE_Config::instance()->core->post_shortcodes[$post_name]); |
|
345 | 345 | } |
346 | 346 | } else { |
347 | 347 | // you got no shortcodes to keep track of ! |
348 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
348 | + unset(\EE_Config::instance()->core->post_shortcodes[$post_name]); |
|
349 | 349 | } |
350 | 350 | } |
351 | 351 | // critical page shortcodes that we do NOT want added to the Posts page (blog) |
352 | 352 | $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
353 | - $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
354 | - foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
355 | - unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
353 | + $critical_shortcodes = array_flip($critical_shortcodes); |
|
354 | + foreach ($critical_shortcodes as $critical_shortcode) { |
|
355 | + unset(\EE_Config::instance()->core->post_shortcodes[$page_for_posts][$critical_shortcode]); |
|
356 | 356 | } |
357 | 357 | //only show errors |
358 | 358 | \EE_Config::instance()->update_espresso_config(); |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | * @param string $value |
373 | 373 | * @return void |
374 | 374 | */ |
375 | - public static function reset_page_for_posts_on_initial_set( $option, $value ) { |
|
376 | - PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
375 | + public static function reset_page_for_posts_on_initial_set($option, $value) { |
|
376 | + PostShortcodeTracking::reset_page_for_posts_on_change($option, '', $value); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | |
@@ -390,13 +390,13 @@ discard block |
||
390 | 390 | * @param string $value |
391 | 391 | * @return void |
392 | 392 | */ |
393 | - public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) { |
|
394 | - if ( $option === 'page_for_posts' ) { |
|
393 | + public static function reset_page_for_posts_on_change($option, $old_value = '', $value = '') { |
|
394 | + if ($option === 'page_for_posts') { |
|
395 | 395 | global $wpdb; |
396 | 396 | $table = $wpdb->posts; |
397 | 397 | $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
398 | - $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
399 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
398 | + $new_page_for_posts = $value ? $wpdb->get_var($wpdb->prepare($SQL, $value)) : 'posts'; |
|
399 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page($new_page_for_posts); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
@@ -412,9 +412,9 @@ discard block |
||
412 | 412 | * @param string $option |
413 | 413 | * @return void |
414 | 414 | */ |
415 | - public static function reset_page_for_posts_on_delete( $option ) { |
|
416 | - if ( $option === 'page_for_posts' ) { |
|
417 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
415 | + public static function reset_page_for_posts_on_delete($option) { |
|
416 | + if ($option === 'page_for_posts') { |
|
417 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page('posts'); |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 |
@@ -256,7 +256,7 @@ |
||
256 | 256 | * @param int $ID |
257 | 257 | * @param $shortcode_class |
258 | 258 | * @param $shortcode_posts |
259 | - * @param $page_for_posts |
|
259 | + * @param string $page_for_posts |
|
260 | 260 | * @param bool $update_post_shortcodes |
261 | 261 | * @return bool |
262 | 262 | */ |
@@ -577,7 +577,7 @@ |
||
577 | 577 | * @param \EEM_Base $model |
578 | 578 | * @param array $wpdb_row |
579 | 579 | * @param \WP_REST_Request $rest_request |
580 | - * @return array the _calculations item in the entity |
|
580 | + * @return \stdClass the _calculations item in the entity |
|
581 | 581 | */ |
582 | 582 | protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
583 | 583 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | use EventEspresso\core\libraries\rest_api\Rest_Exception; |
7 | 7 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
8 | 8 | |
9 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
10 | - exit( 'No direct script access allowed' ); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -46,22 +46,22 @@ discard block |
||
46 | 46 | * @param \WP_REST_Request $request |
47 | 47 | * @return \WP_REST_Response|\WP_Error |
48 | 48 | */ |
49 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
49 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
50 | 50 | $controller = new Read(); |
51 | - try{ |
|
51 | + try { |
|
52 | 52 | $matches = $controller->parse_route( |
53 | 53 | $request->get_route(), |
54 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
55 | - array( 'version', 'model' ) |
|
54 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
55 | + array('version', 'model') |
|
56 | 56 | ); |
57 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
58 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
59 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
57 | + $controller->set_requested_version($matches['version']); |
|
58 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
59 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
60 | 60 | return $controller->send_response( |
61 | 61 | new \WP_Error( |
62 | 62 | 'endpoint_parsing_error', |
63 | 63 | sprintf( |
64 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
64 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
65 | 65 | $model_name_singular |
66 | 66 | ) |
67 | 67 | ) |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | } |
70 | 70 | return $controller->send_response( |
71 | 71 | $controller->get_entities_from_model( |
72 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
72 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
73 | 73 | $request |
74 | 74 | ) |
75 | 75 | ); |
76 | - } catch( \Exception $e ) { |
|
77 | - return $controller->send_response( $e ); |
|
76 | + } catch (\Exception $e) { |
|
77 | + return $controller->send_response($e); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -84,21 +84,21 @@ discard block |
||
84 | 84 | * @param \WP_REST_Request $request |
85 | 85 | * @return \WP_REST_Response|\WP_Error |
86 | 86 | */ |
87 | - public static function handle_request_get_one( \WP_REST_Request $request ) { |
|
87 | + public static function handle_request_get_one(\WP_REST_Request $request) { |
|
88 | 88 | $controller = new Read(); |
89 | - try{ |
|
89 | + try { |
|
90 | 90 | $matches = $controller->parse_route( |
91 | 91 | $request->get_route(), |
92 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
93 | - array( 'version', 'model', 'id' ) ); |
|
94 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
95 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
96 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
92 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
93 | + array('version', 'model', 'id') ); |
|
94 | + $controller->set_requested_version($matches['version']); |
|
95 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
96 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
97 | 97 | return $controller->send_response( |
98 | 98 | new \WP_Error( |
99 | 99 | 'endpoint_parsing_error', |
100 | 100 | sprintf( |
101 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
101 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
102 | 102 | $model_name_singular |
103 | 103 | ) |
104 | 104 | ) |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | } |
107 | 107 | return $controller->send_response( |
108 | 108 | $controller->get_entity_from_model( |
109 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
109 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
110 | 110 | $request |
111 | 111 | ) |
112 | 112 | ); |
113 | - } catch( \Exception $e ) { |
|
114 | - return $controller->send_response( $e ); |
|
113 | + } catch (\Exception $e) { |
|
114 | + return $controller->send_response($e); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -123,40 +123,40 @@ discard block |
||
123 | 123 | * @param \WP_REST_Request $request |
124 | 124 | * @return \WP_REST_Response|\WP_Error |
125 | 125 | */ |
126 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
126 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
127 | 127 | $controller = new Read(); |
128 | - try{ |
|
128 | + try { |
|
129 | 129 | $matches = $controller->parse_route( |
130 | 130 | $request->get_route(), |
131 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
132 | - array( 'version', 'model', 'id', 'related_model' ) |
|
131 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
132 | + array('version', 'model', 'id', 'related_model') |
|
133 | 133 | ); |
134 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
135 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
136 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
134 | + $controller->set_requested_version($matches['version']); |
|
135 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
136 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
137 | 137 | return $controller->send_response( |
138 | 138 | new \WP_Error( |
139 | 139 | 'endpoint_parsing_error', |
140 | 140 | sprintf( |
141 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
141 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
142 | 142 | $main_model_name_singular |
143 | 143 | ) |
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | } |
147 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
147 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
148 | 148 | //assume the related model name is plural and try to find the model's name |
149 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
150 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
149 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
150 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
151 | 151 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
152 | - $related_model_name_singular = \EEH_Inflector::humanize( $matches[ 'related_model' ] ); |
|
152 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
153 | 153 | } |
154 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
154 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
155 | 155 | return $controller->send_response( |
156 | 156 | new \WP_Error( |
157 | 157 | 'endpoint_parsing_error', |
158 | 158 | sprintf( |
159 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
159 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
160 | 160 | $related_model_name_singular |
161 | 161 | ) |
162 | 162 | ) |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | |
166 | 166 | return $controller->send_response( |
167 | 167 | $controller->get_entities_from_relation( |
168 | - $request->get_param( 'id' ), |
|
169 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
168 | + $request->get_param('id'), |
|
169 | + $main_model->related_settings_for($related_model_name_singular), |
|
170 | 170 | $request |
171 | 171 | ) |
172 | 172 | ); |
173 | - } catch( \Exception $e ) { |
|
174 | - return $controller->send_response( $e ); |
|
173 | + } catch (\Exception $e) { |
|
174 | + return $controller->send_response($e); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
@@ -184,28 +184,28 @@ discard block |
||
184 | 184 | * @param \WP_REST_Request $request |
185 | 185 | * @return array |
186 | 186 | */ |
187 | - public function get_entities_from_model( $model, $request) { |
|
188 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
189 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
190 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
187 | + public function get_entities_from_model($model, $request) { |
|
188 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
189 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
190 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
191 | 191 | return new \WP_Error( |
192 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
192 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
193 | 193 | sprintf( |
194 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
194 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
195 | 195 | $model_name_plural, |
196 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
196 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
197 | 197 | ), |
198 | - array( 'status' => 403 ) |
|
198 | + array('status' => 403) |
|
199 | 199 | ); |
200 | 200 | } |
201 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
202 | - $this->_set_headers_from_query_params( $model, $query_params ); |
|
201 | + if ( ! $request->get_header('no_rest_headers')) { |
|
202 | + $this->_set_headers_from_query_params($model, $query_params); |
|
203 | 203 | } |
204 | 204 | /** @type array $results */ |
205 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
205 | + $results = $model->get_all_wpdb_results($query_params); |
|
206 | 206 | $nice_results = array( ); |
207 | - foreach ( $results as $result ) { |
|
208 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
207 | + foreach ($results as $result) { |
|
208 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
209 | 209 | $model, |
210 | 210 | $result, |
211 | 211 | $request |
@@ -226,64 +226,64 @@ discard block |
||
226 | 226 | * @param \WP_REST_Request $request |
227 | 227 | * @return array |
228 | 228 | */ |
229 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
230 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
229 | + public function get_entities_from_relation($id, $relation, $request) { |
|
230 | + $context = $this->validate_context($request->get_param('caps')); |
|
231 | 231 | $model = $relation->get_this_model(); |
232 | 232 | $related_model = $relation->get_other_model(); |
233 | 233 | //check if they can access the 1st model object |
234 | - $query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 ); |
|
235 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
234 | + $query_params = array(array($model->primary_key_name() => $id), 'limit' => 1); |
|
235 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
236 | 236 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
237 | 237 | } |
238 | 238 | $restricted_query_params = $query_params; |
239 | - $restricted_query_params[ 'caps' ] = $context; |
|
240 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
241 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
239 | + $restricted_query_params['caps'] = $context; |
|
240 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
241 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
242 | 242 | |
243 | - if( |
|
243 | + if ( |
|
244 | 244 | ! ( |
245 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
246 | - && $model->exists( $restricted_query_params ) |
|
245 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
246 | + && $model->exists($restricted_query_params) |
|
247 | 247 | ) |
248 | - ){ |
|
249 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
250 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
251 | - }else{ |
|
252 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
248 | + ) { |
|
249 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
250 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
251 | + } else { |
|
252 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
253 | 253 | } |
254 | 254 | return new \WP_Error( |
255 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
255 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
256 | 256 | sprintf( |
257 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
257 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
258 | 258 | $related_model_name_maybe_plural, |
259 | 259 | $relation->get_this_model()->get_this_model_name(), |
260 | 260 | implode( |
261 | 261 | ',', |
262 | 262 | array_keys( |
263 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
263 | + Capabilities::get_missing_permissions($related_model, $context) |
|
264 | 264 | ) |
265 | 265 | ) |
266 | 266 | ), |
267 | - array( 'status' => 403 ) |
|
267 | + array('status' => 403) |
|
268 | 268 | ); |
269 | 269 | } |
270 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
271 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id; |
|
272 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
273 | - $query_params[ 'caps' ] = $context; |
|
274 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
275 | - $this->_set_headers_from_query_params( $relation->get_other_model(), $query_params ); |
|
270 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
271 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id; |
|
272 | + $query_params['default_where_conditions'] = 'none'; |
|
273 | + $query_params['caps'] = $context; |
|
274 | + if ( ! $request->get_header('no_rest_headers')) { |
|
275 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
276 | 276 | } |
277 | 277 | /** @type array $results */ |
278 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
278 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
279 | 279 | $nice_results = array(); |
280 | - foreach( $results as $result ) { |
|
280 | + foreach ($results as $result) { |
|
281 | 281 | $nice_result = $this->create_entity_from_wpdb_result( |
282 | 282 | $relation->get_other_model(), |
283 | 283 | $result, |
284 | 284 | $request |
285 | 285 | ); |
286 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
286 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
287 | 287 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
288 | 288 | //if there are conflicts we prefer the properties from the main model |
289 | 289 | $join_model_result = $this->create_entity_from_wpdb_result( |
@@ -291,18 +291,18 @@ discard block |
||
291 | 291 | $result, |
292 | 292 | $request |
293 | 293 | ); |
294 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
294 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
295 | 295 | //but keep the meta stuff from the main model |
296 | - if( isset( $nice_result['meta'] ) ){ |
|
296 | + if (isset($nice_result['meta'])) { |
|
297 | 297 | $joined_result['meta'] = $nice_result['meta']; |
298 | 298 | } |
299 | 299 | $nice_result = $joined_result; |
300 | 300 | } |
301 | 301 | $nice_results[] = $nice_result; |
302 | 302 | } |
303 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
304 | - return array_shift( $nice_results ); |
|
305 | - }else{ |
|
303 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
304 | + return array_shift($nice_results); |
|
305 | + } else { |
|
306 | 306 | return $nice_results; |
307 | 307 | } |
308 | 308 | } |
@@ -315,30 +315,30 @@ discard block |
||
315 | 315 | * @param array $query_params |
316 | 316 | * @return void |
317 | 317 | */ |
318 | - protected function _set_headers_from_query_params( $model, $query_params ) { |
|
319 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
320 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) ); |
|
318 | + protected function _set_headers_from_query_params($model, $query_params) { |
|
319 | + $this->_set_debug_info('model query params', $query_params); |
|
320 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
321 | 321 | //normally the limit to a 2-part array, where the 2nd item is the limit |
322 | - if( ! isset( $query_params[ 'limit' ] ) ) { |
|
323 | - $query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
322 | + if ( ! isset($query_params['limit'])) { |
|
323 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
324 | 324 | } |
325 | - if( is_array( $query_params[ 'limit' ] ) ) { |
|
326 | - $limit_parts = $query_params[ 'limit' ]; |
|
325 | + if (is_array($query_params['limit'])) { |
|
326 | + $limit_parts = $query_params['limit']; |
|
327 | 327 | } else { |
328 | - $limit_parts = explode(',', $query_params[ 'limit' ] ); |
|
329 | - if( count( $limit_parts ) == 1 ){ |
|
330 | - $limit_parts = array(0, $limit_parts[ 0 ] ); |
|
328 | + $limit_parts = explode(',', $query_params['limit']); |
|
329 | + if (count($limit_parts) == 1) { |
|
330 | + $limit_parts = array(0, $limit_parts[0]); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | //remove the group by and having parts of the query, as those will |
334 | 334 | //make the sql query return an array of values, instead of just a single value |
335 | - unset( $query_params[ 'group_by' ], $query_params[ 'having' ], $query_params[ 'limit' ] ); |
|
336 | - $count = $model->count( $query_params, null, true ); |
|
335 | + unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
336 | + $count = $model->count($query_params, null, true); |
|
337 | 337 | |
338 | - $pages = $count / $limit_parts[ 1 ]; |
|
339 | - $this->_set_response_header( 'Total', $count, false ); |
|
340 | - $this->_set_response_header( 'PageSize', $limit_parts[ 1 ], false ); |
|
341 | - $this->_set_response_header( 'TotalPages', ceil( $pages ), false ); |
|
338 | + $pages = $count / $limit_parts[1]; |
|
339 | + $this->_set_response_header('Total', $count, false); |
|
340 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
341 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | |
@@ -351,47 +351,47 @@ discard block |
||
351 | 351 | * @param string $deprecated no longer used |
352 | 352 | * @return array ready for being converted into json for sending to client |
353 | 353 | */ |
354 | - public function create_entity_from_wpdb_result( $model, $db_row, $rest_request, $deprecated = null ) { |
|
355 | - if( ! $rest_request instanceof \WP_REST_Request ) { |
|
354 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) { |
|
355 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
356 | 356 | //ok so this was called in the old style, where the 3rd arg was |
357 | 357 | //$include, and the 4th arg was $context |
358 | 358 | //now setup the request just to avoid fatal errors, although we won't be able |
359 | 359 | //to truly make use of it because it's kinda devoid of info |
360 | 360 | $rest_request = new \WP_REST_Request(); |
361 | - $rest_request->set_param( 'include', $rest_request ); |
|
362 | - $rest_request->set_param( 'caps', $deprecated ); |
|
361 | + $rest_request->set_param('include', $rest_request); |
|
362 | + $rest_request->set_param('caps', $deprecated); |
|
363 | 363 | } |
364 | - if( $rest_request->get_param( 'caps' ) == null ) { |
|
365 | - $rest_request->set_param( 'caps', \EEM_Base::caps_read ); |
|
364 | + if ($rest_request->get_param('caps') == null) { |
|
365 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
366 | 366 | } |
367 | - $entity_array = $this->_create_bare_entity_from_wpdb_results( $model, $db_row ); |
|
368 | - $entity_array = $this->_add_extra_fields( $model, $db_row, $entity_array ); |
|
369 | - $entity_array[ '_links' ] = $this->_get_entity_links( $model, $db_row, $entity_array ); |
|
370 | - $entity_array[ '_calculated_fields'] = $this->_get_entity_calculations( $model, $db_row, $rest_request ); |
|
371 | - $entity_array = $this->_include_requested_models( $model, $rest_request, $entity_array ); |
|
367 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
368 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
369 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
370 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
371 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array); |
|
372 | 372 | $entity_array = apply_filters( |
373 | 373 | 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
374 | 374 | $entity_array, |
375 | 375 | $model, |
376 | - $rest_request->get_param( 'caps' ), |
|
376 | + $rest_request->get_param('caps'), |
|
377 | 377 | $rest_request, |
378 | 378 | $this |
379 | 379 | ); |
380 | 380 | $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
381 | 381 | $entity_array, |
382 | 382 | $model, |
383 | - $rest_request->get_param( 'caps' ), |
|
383 | + $rest_request->get_param('caps'), |
|
384 | 384 | $this->get_model_version_info() |
385 | 385 | ); |
386 | 386 | $this->_set_debug_info( |
387 | 387 | 'inaccessible fields', |
388 | - array_keys( array_diff_key( $entity_array, $result_without_inaccessible_fields ) ) |
|
388 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
389 | 389 | ); |
390 | 390 | return apply_filters( |
391 | 391 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
392 | 392 | $result_without_inaccessible_fields, |
393 | 393 | $model, |
394 | - $rest_request->get_param( 'caps' ) |
|
394 | + $rest_request->get_param('caps') |
|
395 | 395 | ); |
396 | 396 | } |
397 | 397 | |
@@ -403,38 +403,38 @@ discard block |
||
403 | 403 | * @param array $db_row |
404 | 404 | * @return array entity mostly ready for converting to JSON and sending in the response |
405 | 405 | */ |
406 | - protected function _create_bare_entity_from_wpdb_results( \EEM_Base $model, $db_row ) { |
|
407 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
408 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
409 | - foreach( $result as $field_name => $raw_field_value ) { |
|
406 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) { |
|
407 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
408 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
409 | + foreach ($result as $field_name => $raw_field_value) { |
|
410 | 410 | $field_obj = $model->field_settings_for($field_name); |
411 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
412 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
413 | - unset( $result[ $field_name ] ); |
|
414 | - }elseif( |
|
415 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
416 | - ){ |
|
417 | - $result[ $field_name ] = array( |
|
418 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
419 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
411 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
412 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
413 | + unset($result[$field_name]); |
|
414 | + }elseif ( |
|
415 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
416 | + ) { |
|
417 | + $result[$field_name] = array( |
|
418 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
419 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
420 | 420 | ); |
421 | - }elseif( |
|
422 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
423 | - ){ |
|
424 | - $result[ $field_name ] = array( |
|
425 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
426 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
421 | + }elseif ( |
|
422 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
423 | + ) { |
|
424 | + $result[$field_name] = array( |
|
425 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
426 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
427 | 427 | ); |
428 | - } elseif ( $field_obj instanceof \EE_Datetime_Field ) { |
|
429 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
428 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
429 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
430 | 430 | $field_obj, |
431 | 431 | $field_value, |
432 | 432 | $this->get_model_version_info()->requested_version() |
433 | 433 | ); |
434 | 434 | } else { |
435 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
435 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
436 | 436 | $field_obj, |
437 | - $field_obj->prepare_for_get( $field_value ), |
|
437 | + $field_obj->prepare_for_get($field_value), |
|
438 | 438 | $this->get_model_version_info()->requested_version() |
439 | 439 | ); |
440 | 440 | } |
@@ -449,9 +449,9 @@ discard block |
||
449 | 449 | * @param array $entity_array |
450 | 450 | * @return array modified entity |
451 | 451 | */ |
452 | - protected function _add_extra_fields( \EEM_Base $model, $db_row, $entity_array ) { |
|
453 | - if( $model instanceof \EEM_CPT_Base ) { |
|
454 | - $entity_array[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
452 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) { |
|
453 | + if ($model instanceof \EEM_CPT_Base) { |
|
454 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
455 | 455 | } |
456 | 456 | return $entity_array; |
457 | 457 | } |
@@ -465,20 +465,20 @@ discard block |
||
465 | 465 | * @param array $entity_array |
466 | 466 | * @return array the _links item in the entity |
467 | 467 | */ |
468 | - protected function _get_entity_links( $model, $db_row, $entity_array ) { |
|
468 | + protected function _get_entity_links($model, $db_row, $entity_array) { |
|
469 | 469 | //add basic links |
470 | 470 | $links = array( |
471 | 471 | 'self' => array( |
472 | 472 | array( |
473 | 473 | 'href' => $this->get_versioned_link_to( |
474 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] |
|
474 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()] |
|
475 | 475 | ) |
476 | 476 | ) |
477 | 477 | ), |
478 | 478 | 'collection' => array( |
479 | 479 | array( |
480 | 480 | 'href' => $this->get_versioned_link_to( |
481 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
481 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
482 | 482 | ) |
483 | 483 | ) |
484 | 484 | ), |
@@ -486,24 +486,24 @@ discard block |
||
486 | 486 | |
487 | 487 | //add link to the wp core endpoint, if wp api is active |
488 | 488 | global $wp_rest_server; |
489 | - if( $model instanceof \EEM_CPT_Base && |
|
489 | + if ($model instanceof \EEM_CPT_Base && |
|
490 | 490 | $wp_rest_server instanceof \WP_REST_Server && |
491 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) ) { |
|
492 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post' ] = array( |
|
491 | + $wp_rest_server->get_route_options('/wp/v2/posts')) { |
|
492 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.'self_wp_post'] = array( |
|
493 | 493 | array( |
494 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
494 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
495 | 495 | 'single' => true |
496 | 496 | ) |
497 | 497 | ); |
498 | 498 | } |
499 | 499 | |
500 | 500 | //add links to related models |
501 | - foreach( $this->get_model_version_info()->relation_settings( $model ) as $relation_name => $relation_obj ) { |
|
502 | - $related_model_part = Read::get_related_entity_name( $relation_name, $relation_obj ); |
|
503 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array( |
|
501 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
502 | + $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
503 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
504 | 504 | array( |
505 | 505 | 'href' => $this->get_versioned_link_to( |
506 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] . '/' . $related_model_part |
|
506 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()].'/'.$related_model_part |
|
507 | 507 | ), |
508 | 508 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
509 | 509 | ) |
@@ -519,51 +519,51 @@ discard block |
||
519 | 519 | * @param array $entity_array |
520 | 520 | * @return array the modified entity |
521 | 521 | */ |
522 | - protected function _include_requested_models( \EEM_Base $model, \WP_REST_Request $rest_request, $entity_array ) { |
|
523 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'include' ), '' ); |
|
524 | - $includes_for_this_model = $this->_remove_model_names_from_array( $includes_for_this_model ); |
|
522 | + protected function _include_requested_models(\EEM_Base $model, \WP_REST_Request $rest_request, $entity_array) { |
|
523 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
524 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
525 | 525 | //if they passed in * or didn't specify any includes, return everything |
526 | - if( ! in_array( '*', $includes_for_this_model ) |
|
527 | - && ! empty( $includes_for_this_model ) ) { |
|
528 | - if( $model->has_primary_key_field() ) { |
|
526 | + if ( ! in_array('*', $includes_for_this_model) |
|
527 | + && ! empty($includes_for_this_model)) { |
|
528 | + if ($model->has_primary_key_field()) { |
|
529 | 529 | //always include the primary key. ya just gotta know that at least |
530 | 530 | $includes_for_this_model[] = $model->primary_key_name(); |
531 | 531 | } |
532 | - if( $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'calculate' ), '' ) ) { |
|
532 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
533 | 533 | $includes_for_this_model[] = '_calculated_fields'; |
534 | 534 | } |
535 | - $entity_array = array_intersect_key( $entity_array, array_flip( $includes_for_this_model ) ); |
|
535 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
536 | 536 | } |
537 | - $relation_settings = $this->get_model_version_info()->relation_settings( $model ); |
|
538 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
537 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
538 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
539 | 539 | $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
540 | - $rest_request->get_param( 'include' ), |
|
540 | + $rest_request->get_param('include'), |
|
541 | 541 | $relation_name |
542 | 542 | ); |
543 | 543 | $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
544 | - $rest_request->get_param( 'calculate' ), |
|
544 | + $rest_request->get_param('calculate'), |
|
545 | 545 | $relation_name |
546 | 546 | ); |
547 | 547 | //did they specify they wanted to include a related model, or |
548 | 548 | //specific fields from a related model? |
549 | 549 | //or did they specify to calculate a field from a related model? |
550 | - if( $related_fields_to_include || $related_fields_to_calculate ) { |
|
550 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
551 | 551 | //if so, we should include at least some part of the related model |
552 | 552 | $pretend_related_request = new \WP_REST_Request(); |
553 | 553 | $pretend_related_request->set_query_params( |
554 | 554 | array( |
555 | - 'caps' => $rest_request->get_param( 'caps' ), |
|
555 | + 'caps' => $rest_request->get_param('caps'), |
|
556 | 556 | 'include' => $related_fields_to_include, |
557 | 557 | 'calculate' => $related_fields_to_calculate, |
558 | 558 | ) |
559 | 559 | ); |
560 | - $pretend_related_request->add_header( 'no_rest_headers', true ); |
|
560 | + $pretend_related_request->add_header('no_rest_headers', true); |
|
561 | 561 | $related_results = $this->get_entities_from_relation( |
562 | - $entity_array[ $model->primary_key_name() ], |
|
562 | + $entity_array[$model->primary_key_name()], |
|
563 | 563 | $relation_obj, |
564 | 564 | $pretend_related_request |
565 | 565 | ); |
566 | - $entity_array[ Read::get_related_entity_name( $relation_name, $relation_obj ) ] = $related_results instanceof \WP_Error |
|
566 | + $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results instanceof \WP_Error |
|
567 | 567 | ? null |
568 | 568 | : $related_results; |
569 | 569 | } |
@@ -577,8 +577,8 @@ discard block |
||
577 | 577 | * @param array $arr |
578 | 578 | * @return array |
579 | 579 | */ |
580 | - private function _remove_model_names_from_array( $arr ) { |
|
581 | - return array_diff( $arr, array_keys( \EE_Registry::instance()->non_abstract_db_models ) ); |
|
580 | + private function _remove_model_names_from_array($arr) { |
|
581 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
582 | 582 | } |
583 | 583 | /** |
584 | 584 | * Gets the calculated fields for the response |
@@ -588,15 +588,15 @@ discard block |
||
588 | 588 | * @param \WP_REST_Request $rest_request |
589 | 589 | * @return array the _calculations item in the entity |
590 | 590 | */ |
591 | - protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
|
591 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) { |
|
592 | 592 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
593 | - $rest_request->get_param( 'calculate' ), |
|
593 | + $rest_request->get_param('calculate'), |
|
594 | 594 | '' |
595 | 595 | ); |
596 | 596 | //note: setting calculate=* doesn't do anything |
597 | 597 | $calculated_fields_to_return = new \stdClass(); |
598 | - foreach( $calculated_fields as $field_to_calculate ) { |
|
599 | - try{ |
|
598 | + foreach ($calculated_fields as $field_to_calculate) { |
|
599 | + try { |
|
600 | 600 | $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
601 | 601 | null, |
602 | 602 | $this->_fields_calculator->retrieve_calculated_field_value( |
@@ -608,10 +608,10 @@ discard block |
||
608 | 608 | ), |
609 | 609 | $this->get_model_version_info()->requested_version() |
610 | 610 | ); |
611 | - } catch( Rest_Exception $e ) { |
|
611 | + } catch (Rest_Exception $e) { |
|
612 | 612 | //if we don't have permission to read it, just leave it out. but let devs know about the problem |
613 | 613 | $this->_set_response_header( |
614 | - 'Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']', |
|
614 | + 'Notices-Field-Calculation-Errors['.$e->get_string_code().']['.$model->get_this_model_name().']['.$field_to_calculate.']', |
|
615 | 615 | $e->getMessage(), |
616 | 616 | true |
617 | 617 | ); |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
626 | 626 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
627 | 627 | */ |
628 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
628 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
629 | 629 | return rest_url( |
630 | 630 | \EED_Core_Rest_Api::ee_api_namespace |
631 | 631 | . $this->get_model_version_info()->requested_version() |
@@ -641,11 +641,11 @@ discard block |
||
641 | 641 | * @param \EE_Model_Relation_Base $relation_obj |
642 | 642 | * @return string |
643 | 643 | */ |
644 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
645 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
646 | - return strtolower( $relation_name ); |
|
647 | - }else{ |
|
648 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
644 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
645 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
646 | + return strtolower($relation_name); |
|
647 | + } else { |
|
648 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
649 | 649 | } |
650 | 650 | } |
651 | 651 | |
@@ -658,43 +658,43 @@ discard block |
||
658 | 658 | * @param \WP_REST_Request $request |
659 | 659 | * @return array |
660 | 660 | */ |
661 | - public function get_entity_from_model( $model, $request ) { |
|
662 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
663 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
661 | + public function get_entity_from_model($model, $request) { |
|
662 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
663 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
664 | 664 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
665 | 665 | } |
666 | 666 | $restricted_query_params = $query_params; |
667 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
668 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
669 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
670 | - if ( ! empty ( $model_rows ) ) { |
|
667 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
668 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
669 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
670 | + if ( ! empty ($model_rows)) { |
|
671 | 671 | return $this->create_entity_from_wpdb_result( |
672 | 672 | $model, |
673 | - array_shift( $model_rows ), |
|
673 | + array_shift($model_rows), |
|
674 | 674 | $request ); |
675 | 675 | } else { |
676 | 676 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
677 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
678 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
679 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
677 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
678 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
679 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
680 | 680 | //you got shafted- it existed but we didn't want to tell you! |
681 | 681 | return new \WP_Error( |
682 | 682 | 'rest_user_cannot_read', |
683 | 683 | sprintf( |
684 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
685 | - strtolower( $model->get_this_model_name() ), |
|
684 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
685 | + strtolower($model->get_this_model_name()), |
|
686 | 686 | Capabilities::get_missing_permissions_string( |
687 | 687 | $model, |
688 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
688 | + $this->validate_context($request->get_param('caps')) ) |
|
689 | 689 | ), |
690 | - array( 'status' => 403 ) |
|
690 | + array('status' => 403) |
|
691 | 691 | ); |
692 | 692 | } else { |
693 | 693 | //it's not you. It just doesn't exist |
694 | 694 | return new \WP_Error( |
695 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
696 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
697 | - array( 'status' => 404 ) |
|
695 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
696 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
697 | + array('status' => 404) |
|
698 | 698 | ); |
699 | 699 | } |
700 | 700 | } |
@@ -707,14 +707,14 @@ discard block |
||
707 | 707 | * @param string $context |
708 | 708 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
709 | 709 | */ |
710 | - public function validate_context( $context ) { |
|
711 | - if( ! $context ) { |
|
710 | + public function validate_context($context) { |
|
711 | + if ( ! $context) { |
|
712 | 712 | $context = \EEM_Base::caps_read; |
713 | 713 | } |
714 | 714 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
715 | - if( in_array( $context, $valid_contexts ) ){ |
|
715 | + if (in_array($context, $valid_contexts)) { |
|
716 | 716 | return $context; |
717 | - }else{ |
|
717 | + } else { |
|
718 | 718 | return \EEM_Base::caps_read; |
719 | 719 | } |
720 | 720 | } |
@@ -733,77 +733,77 @@ discard block |
||
733 | 733 | * that absolutely no results should be returned |
734 | 734 | * @throws \EE_Error |
735 | 735 | */ |
736 | - public function create_model_query_params( $model, $query_parameters ) { |
|
736 | + public function create_model_query_params($model, $query_parameters) { |
|
737 | 737 | $model_query_params = array( ); |
738 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
739 | - $model_query_params[ 0 ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
740 | - $query_parameters[ 'where' ], |
|
738 | + if (isset($query_parameters['where'])) { |
|
739 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
740 | + $query_parameters['where'], |
|
741 | 741 | $model, |
742 | 742 | $this->get_model_version_info()->requested_version() |
743 | 743 | ); |
744 | 744 | } |
745 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
746 | - $order_by = $query_parameters[ 'order_by' ]; |
|
747 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
748 | - $order_by = $query_parameters[ 'orderby' ]; |
|
749 | - }else{ |
|
745 | + if (isset($query_parameters['order_by'])) { |
|
746 | + $order_by = $query_parameters['order_by']; |
|
747 | + } elseif (isset($query_parameters['orderby'])) { |
|
748 | + $order_by = $query_parameters['orderby']; |
|
749 | + } else { |
|
750 | 750 | $order_by = null; |
751 | 751 | } |
752 | - if( $order_by !== null ){ |
|
753 | - $model_query_params[ 'order_by' ] = $order_by; |
|
752 | + if ($order_by !== null) { |
|
753 | + $model_query_params['order_by'] = $order_by; |
|
754 | 754 | } |
755 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
756 | - $group_by = $query_parameters[ 'group_by' ]; |
|
757 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
758 | - $group_by = $query_parameters[ 'groupby' ]; |
|
759 | - }else{ |
|
760 | - $group_by = array_keys( $model->get_combined_primary_key_fields() ); |
|
755 | + if (isset($query_parameters['group_by'])) { |
|
756 | + $group_by = $query_parameters['group_by']; |
|
757 | + } elseif (isset($query_parameters['groupby'])) { |
|
758 | + $group_by = $query_parameters['groupby']; |
|
759 | + } else { |
|
760 | + $group_by = array_keys($model->get_combined_primary_key_fields()); |
|
761 | 761 | } |
762 | - if( $group_by !== null ){ |
|
763 | - $model_query_params[ 'group_by' ] = $group_by; |
|
762 | + if ($group_by !== null) { |
|
763 | + $model_query_params['group_by'] = $group_by; |
|
764 | 764 | } |
765 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
766 | - $model_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
767 | - $query_parameters[ 'having' ], |
|
765 | + if (isset($query_parameters['having'])) { |
|
766 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
767 | + $query_parameters['having'], |
|
768 | 768 | $model, |
769 | 769 | $this->get_model_version_info()->requested_version() |
770 | 770 | ); |
771 | 771 | } |
772 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
773 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
772 | + if (isset($query_parameters['order'])) { |
|
773 | + $model_query_params['order'] = $query_parameters['order']; |
|
774 | 774 | } |
775 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
776 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
775 | + if (isset($query_parameters['mine'])) { |
|
776 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
777 | 777 | } |
778 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
778 | + if (isset($query_parameters['limit'])) { |
|
779 | 779 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
780 | - if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
|
781 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
782 | - }else { |
|
783 | - $limit_array = $query_parameters[ 'limit' ]; |
|
780 | + if ( ! is_array($query_parameters['limit'])) { |
|
781 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
782 | + } else { |
|
783 | + $limit_array = $query_parameters['limit']; |
|
784 | 784 | } |
785 | 785 | $sanitized_limit = array(); |
786 | - foreach( $limit_array as $key => $limit_part ) { |
|
787 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
786 | + foreach ($limit_array as $key => $limit_part) { |
|
787 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
788 | 788 | throw new \EE_Error( |
789 | 789 | sprintf( |
790 | - __( 'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso' ), |
|
791 | - json_encode( $query_parameters[ 'limit' ] ) |
|
790 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso'), |
|
791 | + json_encode($query_parameters['limit']) |
|
792 | 792 | ) |
793 | 793 | ); |
794 | 794 | } |
795 | - $sanitized_limit[] = (int)$limit_part; |
|
795 | + $sanitized_limit[] = (int) $limit_part; |
|
796 | 796 | } |
797 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
798 | - }else{ |
|
799 | - $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
797 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
798 | + } else { |
|
799 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
800 | 800 | } |
801 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
802 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
803 | - }else{ |
|
804 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
801 | + if (isset($query_parameters['caps'])) { |
|
802 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
803 | + } else { |
|
804 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
805 | 805 | } |
806 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
806 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | |
@@ -815,13 +815,13 @@ discard block |
||
815 | 815 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
816 | 816 | * @return array |
817 | 817 | */ |
818 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
818 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
819 | 819 | $model_ready_query_params = array(); |
820 | - foreach( $query_params as $key => $value ) { |
|
821 | - if( is_array( $value ) ) { |
|
822 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
823 | - }else{ |
|
824 | - $model_ready_query_params[ $key ] = $value; |
|
820 | + foreach ($query_params as $key => $value) { |
|
821 | + if (is_array($value)) { |
|
822 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
823 | + } else { |
|
824 | + $model_ready_query_params[$key] = $value; |
|
825 | 825 | } |
826 | 826 | } |
827 | 827 | return $model_ready_query_params; |
@@ -835,13 +835,13 @@ discard block |
||
835 | 835 | * @param $query_params |
836 | 836 | * @return array |
837 | 837 | */ |
838 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
838 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
839 | 839 | $model_ready_query_params = array(); |
840 | - foreach( $query_params as $key => $value ) { |
|
841 | - if( is_array( $value ) ) { |
|
842 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
840 | + foreach ($query_params as $key => $value) { |
|
841 | + if (is_array($value)) { |
|
842 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
843 | 843 | } else { |
844 | - $model_ready_query_params[ $key ] = $value; |
|
844 | + $model_ready_query_params[$key] = $value; |
|
845 | 845 | } |
846 | 846 | } |
847 | 847 | return $model_ready_query_params; |
@@ -856,33 +856,33 @@ discard block |
||
856 | 856 | * we only return strings starting with that and a period; if no prefix was specified |
857 | 857 | * we return all items containing NO periods |
858 | 858 | */ |
859 | - public function explode_and_get_items_prefixed_with( $string_to_explode, $prefix ) { |
|
860 | - if( is_string( $string_to_explode ) ) { |
|
861 | - $exploded_contents = explode( ',', $string_to_explode ); |
|
862 | - } else if( is_array( $string_to_explode ) ) { |
|
859 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) { |
|
860 | + if (is_string($string_to_explode)) { |
|
861 | + $exploded_contents = explode(',', $string_to_explode); |
|
862 | + } else if (is_array($string_to_explode)) { |
|
863 | 863 | $exploded_contents = $string_to_explode; |
864 | 864 | } else { |
865 | 865 | $exploded_contents = array(); |
866 | 866 | } |
867 | 867 | //if the string was empty, we want an empty array |
868 | - $exploded_contents = array_filter( $exploded_contents ); |
|
868 | + $exploded_contents = array_filter($exploded_contents); |
|
869 | 869 | $contents_with_prefix = array(); |
870 | - foreach( $exploded_contents as $item ) { |
|
871 | - $item = trim( $item ); |
|
870 | + foreach ($exploded_contents as $item) { |
|
871 | + $item = trim($item); |
|
872 | 872 | //if no prefix was provided, so we look for items with no "." in them |
873 | - if( ! $prefix ) { |
|
873 | + if ( ! $prefix) { |
|
874 | 874 | //does this item have a period? |
875 | - if( strpos( $item, '.' ) === false ) { |
|
875 | + if (strpos($item, '.') === false) { |
|
876 | 876 | //if not, then its what we're looking for |
877 | 877 | $contents_with_prefix[] = $item; |
878 | 878 | } |
879 | - } else if( strpos( $item, $prefix . '.' ) === 0 ) { |
|
879 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
880 | 880 | //this item has the prefix and a period, grab it |
881 | 881 | $contents_with_prefix[] = substr( |
882 | 882 | $item, |
883 | - strpos( $item, $prefix . '.' ) + strlen( $prefix . '.' ) |
|
883 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
884 | 884 | ); |
885 | - } else if( $item === $prefix ) { |
|
885 | + } else if ($item === $prefix) { |
|
886 | 886 | //this item is JUST the prefix |
887 | 887 | //so let's grab everything after, which is a blank string |
888 | 888 | $contents_with_prefix[] = ''; |
@@ -905,33 +905,33 @@ discard block |
||
905 | 905 | * the fields for that model, with the model's name removed from each. |
906 | 906 | * If $include_string was blank or '*' returns an empty array |
907 | 907 | */ |
908 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
909 | - if( is_array( $include_string ) ) { |
|
910 | - $include_string = implode( ',', $include_string ); |
|
908 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
909 | + if (is_array($include_string)) { |
|
910 | + $include_string = implode(',', $include_string); |
|
911 | 911 | } |
912 | - if( $include_string === '*' || $include_string === '' ) { |
|
912 | + if ($include_string === '*' || $include_string === '') { |
|
913 | 913 | return array(); |
914 | 914 | } |
915 | - $includes = explode( ',', $include_string ); |
|
915 | + $includes = explode(',', $include_string); |
|
916 | 916 | $extracted_fields_to_include = array(); |
917 | - if( $model_name ){ |
|
918 | - foreach( $includes as $field_to_include ) { |
|
919 | - $field_to_include = trim( $field_to_include ); |
|
920 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
917 | + if ($model_name) { |
|
918 | + foreach ($includes as $field_to_include) { |
|
919 | + $field_to_include = trim($field_to_include); |
|
920 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
921 | 921 | //found the model name at the exact start |
922 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
922 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
923 | 923 | $extracted_fields_to_include[] = $field_sans_model_name; |
924 | - }elseif( $field_to_include == $model_name ){ |
|
924 | + }elseif ($field_to_include == $model_name) { |
|
925 | 925 | $extracted_fields_to_include[] = '*'; |
926 | 926 | } |
927 | 927 | } |
928 | - }else{ |
|
928 | + } else { |
|
929 | 929 | //look for ones with no period |
930 | - foreach( $includes as $field_to_include ) { |
|
931 | - $field_to_include = trim( $field_to_include ); |
|
930 | + foreach ($includes as $field_to_include) { |
|
931 | + $field_to_include = trim($field_to_include); |
|
932 | 932 | if ( |
933 | - strpos( $field_to_include, '.' ) === false |
|
934 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
933 | + strpos($field_to_include, '.') === false |
|
934 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
935 | 935 | ) { |
936 | 936 | $extracted_fields_to_include[] = $field_to_include; |
937 | 937 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | ){ |
249 | 249 | if( $relation instanceof \EE_Belongs_To_Relation ) { |
250 | 250 | $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
251 | - }else{ |
|
251 | + } else{ |
|
252 | 252 | $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
253 | 253 | } |
254 | 254 | return new \WP_Error( |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | } |
303 | 303 | if( $relation instanceof \EE_Belongs_To_Relation ){ |
304 | 304 | return array_shift( $nice_results ); |
305 | - }else{ |
|
305 | + } else{ |
|
306 | 306 | return $nice_results; |
307 | 307 | } |
308 | 308 | } |
@@ -411,14 +411,14 @@ discard block |
||
411 | 411 | $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
412 | 412 | if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
413 | 413 | unset( $result[ $field_name ] ); |
414 | - }elseif( |
|
414 | + } elseif( |
|
415 | 415 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
416 | 416 | ){ |
417 | 417 | $result[ $field_name ] = array( |
418 | 418 | 'raw' => $field_obj->prepare_for_get( $field_value ), |
419 | 419 | 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
420 | 420 | ); |
421 | - }elseif( |
|
421 | + } elseif( |
|
422 | 422 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
423 | 423 | ){ |
424 | 424 | $result[ $field_name ] = array( |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | public static function get_related_entity_name( $relation_name, $relation_obj ){ |
645 | 645 | if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
646 | 646 | return strtolower( $relation_name ); |
647 | - }else{ |
|
647 | + } else{ |
|
648 | 648 | return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
649 | 649 | } |
650 | 650 | } |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
715 | 715 | if( in_array( $context, $valid_contexts ) ){ |
716 | 716 | return $context; |
717 | - }else{ |
|
717 | + } else{ |
|
718 | 718 | return \EEM_Base::caps_read; |
719 | 719 | } |
720 | 720 | } |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | $order_by = $query_parameters[ 'order_by' ]; |
747 | 747 | } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
748 | 748 | $order_by = $query_parameters[ 'orderby' ]; |
749 | - }else{ |
|
749 | + } else{ |
|
750 | 750 | $order_by = null; |
751 | 751 | } |
752 | 752 | if( $order_by !== null ){ |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | $group_by = $query_parameters[ 'group_by' ]; |
757 | 757 | } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
758 | 758 | $group_by = $query_parameters[ 'groupby' ]; |
759 | - }else{ |
|
759 | + } else{ |
|
760 | 760 | $group_by = array_keys( $model->get_combined_primary_key_fields() ); |
761 | 761 | } |
762 | 762 | if( $group_by !== null ){ |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
780 | 780 | if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
781 | 781 | $limit_array = explode(',', (string)$query_parameters['limit']); |
782 | - }else { |
|
782 | + } else { |
|
783 | 783 | $limit_array = $query_parameters[ 'limit' ]; |
784 | 784 | } |
785 | 785 | $sanitized_limit = array(); |
@@ -795,12 +795,12 @@ discard block |
||
795 | 795 | $sanitized_limit[] = (int)$limit_part; |
796 | 796 | } |
797 | 797 | $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
798 | - }else{ |
|
798 | + } else{ |
|
799 | 799 | $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
800 | 800 | } |
801 | 801 | if( isset( $query_parameters[ 'caps' ] ) ) { |
802 | 802 | $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
803 | - }else{ |
|
803 | + } else{ |
|
804 | 804 | $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
805 | 805 | } |
806 | 806 | return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
@@ -820,7 +820,7 @@ discard block |
||
820 | 820 | foreach( $query_params as $key => $value ) { |
821 | 821 | if( is_array( $value ) ) { |
822 | 822 | $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
823 | - }else{ |
|
823 | + } else{ |
|
824 | 824 | $model_ready_query_params[ $key ] = $value; |
825 | 825 | } |
826 | 826 | } |
@@ -921,11 +921,11 @@ discard block |
||
921 | 921 | //found the model name at the exact start |
922 | 922 | $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
923 | 923 | $extracted_fields_to_include[] = $field_sans_model_name; |
924 | - }elseif( $field_to_include == $model_name ){ |
|
924 | + } elseif( $field_to_include == $model_name ){ |
|
925 | 925 | $extracted_fields_to_include[] = '*'; |
926 | 926 | } |
927 | 927 | } |
928 | - }else{ |
|
928 | + } else{ |
|
929 | 929 | //look for ones with no period |
930 | 930 | foreach( $includes as $field_to_include ) { |
931 | 931 | $field_to_include = trim( $field_to_include ); |
@@ -40,8 +40,11 @@ discard block |
||
40 | 40 | <?php echo do_shortcode( $venue_description ); ?> |
41 | 41 | </p> |
42 | 42 | <?php endif; ?> |
43 | - <?php else : ?> |
|
44 | - <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); ?> |
|
43 | + <?php else { |
|
44 | + : ?> |
|
45 | + <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); |
|
46 | +} |
|
47 | +?> |
|
45 | 48 | <?php if ( $venue_excerpt ) : ?> |
46 | 49 | <p> |
47 | 50 | <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
@@ -53,12 +56,15 @@ discard block |
||
53 | 56 | <!-- .espresso-venue-dv --> |
54 | 57 | <?php |
55 | 58 | do_action( 'AHEE_event_details_after_venue_details', $post ); |
56 | -else : |
|
59 | +else { |
|
60 | + : |
|
57 | 61 | if ( espresso_venue_is_password_protected() ) : |
58 | 62 | ?> |
59 | 63 | <div class="espresso-venue-dv espresso-password-protected-venue-dv" > |
60 | 64 | <h3 class="event-venues-h3 ee-event-h3"> |
61 | - <?php _e( 'Location', 'event_espresso' );?> |
|
65 | + <?php _e( 'Location', 'event_espresso' ); |
|
66 | +} |
|
67 | +?> |
|
62 | 68 | </h3> |
63 | 69 | <?php echo espresso_password_protected_venue_form(); ?> |
64 | 70 | </div> |
@@ -1,69 +1,69 @@ |
||
1 | 1 | <?php |
2 | 2 | //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>'; |
3 | 3 | if ( |
4 | - ( is_single() && espresso_display_venue_in_event_details() ) |
|
5 | - || ( is_archive() && espresso_display_venue_in_event_list() ) |
|
4 | + (is_single() && espresso_display_venue_in_event_details()) |
|
5 | + || (is_archive() && espresso_display_venue_in_event_list()) |
|
6 | 6 | ) : |
7 | 7 | global $post; |
8 | - do_action( 'AHEE_event_details_before_venue_details', $post ); |
|
9 | - $venue_name = espresso_venue_name( 0, 'details', FALSE ); |
|
10 | - if ( empty( $venue_name ) && espresso_is_venue_private() ) { |
|
11 | - do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
8 | + do_action('AHEE_event_details_before_venue_details', $post); |
|
9 | + $venue_name = espresso_venue_name(0, 'details', FALSE); |
|
10 | + if (empty($venue_name) && espresso_is_venue_private()) { |
|
11 | + do_action('AHEE_event_details_after_venue_details', $post); |
|
12 | 12 | return ''; |
13 | 13 | } |
14 | 14 | ?> |
15 | 15 | |
16 | 16 | <div class="espresso-venue-dv<?php echo espresso_is_venue_private() ? ' espresso-private-venue-dv' : ''; ?>"> |
17 | 17 | <h3 class="event-venues-h3 ee-event-h3"> |
18 | - <?php _e( 'Location', 'event_espresso' ); ?> |
|
18 | + <?php _e('Location', 'event_espresso'); ?> |
|
19 | 19 | </h3> |
20 | - <h4><strong><?php _e( 'Venue:', 'event_espresso' ); ?></strong> <strong> <?php echo $venue_name; ?></strong></h4> |
|
20 | + <h4><strong><?php _e('Venue:', 'event_espresso'); ?></strong> <strong> <?php echo $venue_name; ?></strong></h4> |
|
21 | 21 | <p><span class="smaller-text tags-links"><?php echo espresso_venue_categories(); ?></span></p> |
22 | -<?php if ( $venue_phone = espresso_venue_phone( $post->ID, FALSE )) : ?> |
|
22 | +<?php if ($venue_phone = espresso_venue_phone($post->ID, FALSE)) : ?> |
|
23 | 23 | <p> |
24 | - <span class="small-text"><strong><?php _e( 'Venue Phone:', 'event_espresso' ); ?></strong></span> <?php echo $venue_phone; ?> |
|
24 | + <span class="small-text"><strong><?php _e('Venue Phone:', 'event_espresso'); ?></strong></span> <?php echo $venue_phone; ?> |
|
25 | 25 | </p> |
26 | -<?php endif; ?> |
|
27 | -<?php if ( $venue_website = espresso_venue_website( $post->ID, FALSE )) : ?> |
|
26 | +<?php endif; ?> |
|
27 | +<?php if ($venue_website = espresso_venue_website($post->ID, FALSE)) : ?> |
|
28 | 28 | <p> |
29 | - <span class="small-text"><strong><?php _e( 'Venue Website:', 'event_espresso' ); ?></strong></span> <?php echo $venue_website; ?> |
|
29 | + <span class="small-text"><strong><?php _e('Venue Website:', 'event_espresso'); ?></strong></span> <?php echo $venue_website; ?> |
|
30 | 30 | </p> |
31 | 31 | <?php endif; ?> |
32 | -<?php if ( espresso_venue_has_address( $post->ID )) : ?> |
|
33 | - <strong><span class="dashicons dashicons-location-alt"></span><?php _e( 'Address:', 'event_espresso' ); ?></strong> |
|
34 | - <?php espresso_venue_address( 'inline' ); ?> |
|
35 | - <?php espresso_venue_gmap( $post->ID ); ?> |
|
32 | +<?php if (espresso_venue_has_address($post->ID)) : ?> |
|
33 | + <strong><span class="dashicons dashicons-location-alt"></span><?php _e('Address:', 'event_espresso'); ?></strong> |
|
34 | + <?php espresso_venue_address('inline'); ?> |
|
35 | + <?php espresso_venue_gmap($post->ID); ?> |
|
36 | 36 | <div class="clear"><br/></div> |
37 | -<?php endif; ?> |
|
37 | +<?php endif; ?> |
|
38 | 38 | |
39 | - <?php $VNU_ID = espresso_venue_id( $post->ID ); ?> |
|
40 | - <?php if ( is_single() ) : ?> |
|
41 | - <?php $venue_description = espresso_venue_description( $VNU_ID, FALSE ); ?> |
|
42 | - <?php if ( $venue_description ) : ?> |
|
39 | + <?php $VNU_ID = espresso_venue_id($post->ID); ?> |
|
40 | + <?php if (is_single()) : ?> |
|
41 | + <?php $venue_description = espresso_venue_description($VNU_ID, FALSE); ?> |
|
42 | + <?php if ($venue_description) : ?> |
|
43 | 43 | <p> |
44 | - <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
45 | - <?php echo do_shortcode( $venue_description ); ?> |
|
44 | + <strong><?php _e('Description:', 'event_espresso'); ?></strong><br/> |
|
45 | + <?php echo do_shortcode($venue_description); ?> |
|
46 | 46 | </p> |
47 | - <?php endif; ?> |
|
47 | + <?php endif; ?> |
|
48 | 48 | <?php else : ?> |
49 | - <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); ?> |
|
50 | - <?php if ( $venue_excerpt ) : ?> |
|
49 | + <?php $venue_excerpt = espresso_venue_excerpt($VNU_ID, FALSE); ?> |
|
50 | + <?php if ($venue_excerpt) : ?> |
|
51 | 51 | <p> |
52 | - <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
52 | + <strong><?php _e('Description:', 'event_espresso'); ?></strong><br/> |
|
53 | 53 | <?php echo $venue_excerpt; ?> |
54 | 54 | </p> |
55 | - <?php endif; ?> |
|
56 | - <?php endif; ?> |
|
55 | + <?php endif; ?> |
|
56 | + <?php endif; ?> |
|
57 | 57 | </div> |
58 | 58 | <!-- .espresso-venue-dv --> |
59 | 59 | <?php |
60 | -do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
60 | +do_action('AHEE_event_details_after_venue_details', $post); |
|
61 | 61 | else : |
62 | - if ( espresso_venue_is_password_protected() ) : |
|
62 | + if (espresso_venue_is_password_protected()) : |
|
63 | 63 | ?> |
64 | 64 | <div class="espresso-venue-dv espresso-password-protected-venue-dv" > |
65 | 65 | <h3 class="event-venues-h3 ee-event-h3"> |
66 | - <?php _e( 'Location', 'event_espresso' );?> |
|
66 | + <?php _e('Location', 'event_espresso'); ?> |
|
67 | 67 | </h3> |
68 | 68 | <?php echo espresso_password_protected_venue_form(); ?> |
69 | 69 | </div> |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -24,18 +24,18 @@ discard block |
||
24 | 24 | * |
25 | 25 | * ------------------------------------------------------------------------ |
26 | 26 | */ |
27 | -class EE_Year_Input extends EE_Select_Input{ |
|
27 | +class EE_Year_Input extends EE_Select_Input { |
|
28 | 28 | |
29 | - function __construct( $input_settings = array(), $four_digit_year = true, $years_behind = 100, $years_ahead = 0 ){ |
|
30 | - if($four_digit_year){ |
|
29 | + function __construct($input_settings = array(), $four_digit_year = true, $years_behind = 100, $years_ahead = 0) { |
|
30 | + if ($four_digit_year) { |
|
31 | 31 | $current_year_int = intval(date('Y')); |
32 | - }else{ |
|
32 | + } else { |
|
33 | 33 | $current_year_int = intval(date('y')); |
34 | 34 | } |
35 | 35 | $answer_options = array(); |
36 | - for( $start = $current_year_int - $years_behind; $start <= ($current_year_int + $years_ahead); $start++){ |
|
36 | + for ($start = $current_year_int - $years_behind; $start <= ($current_year_int + $years_ahead); $start++) { |
|
37 | 37 | $answer_options[$start] = $start; |
38 | 38 | } |
39 | - parent::__construct( $answer_options, $input_settings ); |
|
39 | + parent::__construct($answer_options, $input_settings); |
|
40 | 40 | } |
41 | 41 | } |
@@ -1,6 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
2 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | +} |
|
4 | 5 | |
5 | 6 | /** |
6 | 7 | * Event Espresso |
@@ -29,7 +30,7 @@ discard block |
||
29 | 30 | function __construct( $input_settings = array(), $four_digit_year = true, $years_behind = 100, $years_ahead = 0 ){ |
30 | 31 | if($four_digit_year){ |
31 | 32 | $current_year_int = intval(date('Y')); |
32 | - }else{ |
|
33 | + } else{ |
|
33 | 34 | $current_year_int = intval(date('y')); |
34 | 35 | } |
35 | 36 | $answer_options = array(); |
@@ -10,21 +10,21 @@ discard block |
||
10 | 10 | * @since 4.6 |
11 | 11 | * |
12 | 12 | */ |
13 | -class EE_Full_HTML_Validation_Strategy extends EE_Validation_Strategy_Base{ |
|
13 | +class EE_Full_HTML_Validation_Strategy extends EE_Validation_Strategy_Base { |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * @param null $validation_error_message |
17 | 17 | */ |
18 | - public function __construct( $validation_error_message = NULL ) { |
|
19 | - if ( ! $validation_error_message ) { |
|
18 | + public function __construct($validation_error_message = NULL) { |
|
19 | + if ( ! $validation_error_message) { |
|
20 | 20 | global $allowedposttags; |
21 | 21 | $validation_error_message = sprintf( |
22 | - __( 'Only the following HTML tags are allowed:%1$s%2$s', "event_espresso" ), |
|
22 | + __('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"), |
|
23 | 23 | '<br />', |
24 | - implode( ",", array_keys( $allowedposttags ) ) |
|
24 | + implode(",", array_keys($allowedposttags)) |
|
25 | 25 | ); |
26 | 26 | } |
27 | - parent::__construct( $validation_error_message ); |
|
27 | + parent::__construct($validation_error_message); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function get_list_of_allowed_tags() { |
40 | 40 | global $allowedposttags; |
41 | - ksort( $allowedposttags ); |
|
42 | - return implode( ', ', array_keys( $allowedposttags ) ); |
|
41 | + ksort($allowedposttags); |
|
42 | + return implode(', ', array_keys($allowedposttags)); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function validate($normalized_value) { |
52 | 52 | global $allowedposttags; |
53 | - parent::validate( $normalized_value ); |
|
54 | - $normalized_value_sans_tags = wp_kses( "$normalized_value", $allowedposttags ); |
|
55 | - if ( strlen( $normalized_value ) > strlen( $normalized_value_sans_tags ) ) { |
|
56 | - throw new EE_Validation_Error( $this->get_validation_error_message(), 'complex_html_tags' ); |
|
53 | + parent::validate($normalized_value); |
|
54 | + $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedposttags); |
|
55 | + if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
56 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | } |
60 | 60 | \ No newline at end of file |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | protected function _set_tips_array() { |
19 | 19 | $this->_qtipsa = array( |
20 | 20 | 0 => array( |
21 | - 'content_id' => 'message_status-' . EEM_Message::status_sent, |
|
22 | - 'target' => '.msg-status-' . EEM_Message::status_sent, |
|
23 | - 'content' => $this->_message_status_legend( EEM_Message::status_sent ), |
|
21 | + 'content_id' => 'message_status-'.EEM_Message::status_sent, |
|
22 | + 'target' => '.msg-status-'.EEM_Message::status_sent, |
|
23 | + 'content' => $this->_message_status_legend(EEM_Message::status_sent), |
|
24 | 24 | 'options' => array( |
25 | 25 | 'position' => array( |
26 | 26 | 'target' => 'mouse', |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | ) |
29 | 29 | ), |
30 | 30 | 1 => array( |
31 | - 'content_id' => 'message_status-' . EEM_Message::status_idle, |
|
32 | - 'target' => '.msg-status-' . EEM_Message::status_idle, |
|
33 | - 'content' => $this->_message_status_legend( EEM_Message::status_idle ), |
|
31 | + 'content_id' => 'message_status-'.EEM_Message::status_idle, |
|
32 | + 'target' => '.msg-status-'.EEM_Message::status_idle, |
|
33 | + 'content' => $this->_message_status_legend(EEM_Message::status_idle), |
|
34 | 34 | 'options' => array( |
35 | 35 | 'position' => array( |
36 | 36 | 'target' => 'mouse', |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | ) |
39 | 39 | ), |
40 | 40 | 2 => array( |
41 | - 'content_id' => 'message_status-' . EEM_Message::status_failed, |
|
42 | - 'target' => '.msg-status-' . EEM_Message::status_failed, |
|
43 | - 'content' => $this->_message_status_legend( EEM_Message::status_failed ), |
|
41 | + 'content_id' => 'message_status-'.EEM_Message::status_failed, |
|
42 | + 'target' => '.msg-status-'.EEM_Message::status_failed, |
|
43 | + 'content' => $this->_message_status_legend(EEM_Message::status_failed), |
|
44 | 44 | 'options' => array( |
45 | 45 | 'position' => array( |
46 | 46 | 'target' => 'mouse', |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | ) |
49 | 49 | ), |
50 | 50 | 3 => array( |
51 | - 'content_id' => 'message_status-' . EEM_Message::status_resend, |
|
52 | - 'target' => '.msg-status-' . EEM_Message::status_resend, |
|
53 | - 'content' => $this->_message_status_legend( EEM_Message::status_resend ), |
|
51 | + 'content_id' => 'message_status-'.EEM_Message::status_resend, |
|
52 | + 'target' => '.msg-status-'.EEM_Message::status_resend, |
|
53 | + 'content' => $this->_message_status_legend(EEM_Message::status_resend), |
|
54 | 54 | 'options' => array( |
55 | 55 | 'position' => array( |
56 | 56 | 'target' => 'mouse', |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | ) |
59 | 59 | ), |
60 | 60 | 4 => array( |
61 | - 'content_id' => 'message_status-' . EEM_Message::status_incomplete, |
|
62 | - 'target' => '.msg-status-' . EEM_Message::status_incomplete, |
|
63 | - 'content' => $this->_message_status_legend( EEM_Message::status_incomplete ), |
|
61 | + 'content_id' => 'message_status-'.EEM_Message::status_incomplete, |
|
62 | + 'target' => '.msg-status-'.EEM_Message::status_incomplete, |
|
63 | + 'content' => $this->_message_status_legend(EEM_Message::status_incomplete), |
|
64 | 64 | 'options' => array( |
65 | 65 | 'position' => array( |
66 | 66 | 'target' => 'mouse', |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | ) |
69 | 69 | ), |
70 | 70 | 5 => array( |
71 | - 'content_id' => 'message_status-' . EEM_Message::status_retry, |
|
72 | - 'target' => '.msg-status-' . EEM_Message::status_retry, |
|
73 | - 'content' => $this->_message_status_legend( EEM_Message::status_retry ), |
|
71 | + 'content_id' => 'message_status-'.EEM_Message::status_retry, |
|
72 | + 'target' => '.msg-status-'.EEM_Message::status_retry, |
|
73 | + 'content' => $this->_message_status_legend(EEM_Message::status_retry), |
|
74 | 74 | 'options' => array( |
75 | 75 | 'position' => array( |
76 | 76 | 'target' => 'mouse', |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | ) |
79 | 79 | ), |
80 | 80 | 6 => array( |
81 | - 'content_id' => 'message_status-' . EEM_Message::status_debug_only, |
|
82 | - 'target' => '.msg-status-' . EEM_Message::status_debug_only, |
|
83 | - 'content' => $this->_message_status_legend( EEM_Message::status_debug_only ), |
|
81 | + 'content_id' => 'message_status-'.EEM_Message::status_debug_only, |
|
82 | + 'target' => '.msg-status-'.EEM_Message::status_debug_only, |
|
83 | + 'content' => $this->_message_status_legend(EEM_Message::status_debug_only), |
|
84 | 84 | 'options' => array( |
85 | 85 | 'position' => array( |
86 | 86 | 'target' => 'mouse', |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param EEM_Message constant $status What status is set (by class) |
100 | 100 | * @return string The status legend with the related status highlighted |
101 | 101 | */ |
102 | - private function _message_status_legend( $status ) { |
|
102 | + private function _message_status_legend($status) { |
|
103 | 103 | |
104 | 104 | $status_array = array( |
105 | 105 | 'sent_status' => EEM_Message::status_sent, |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | 'retry_status' => EEM_Message::status_retry, |
111 | 111 | ); |
112 | 112 | |
113 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
113 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
114 | 114 | $status_array['debug_only_status'] = EEM_Message::status_debug_only; |
115 | 115 | } |
116 | 116 | |
117 | - return EEH_Template::status_legend( $status_array, $status ); |
|
117 | + return EEH_Template::status_legend($status_array, $status); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | \ No newline at end of file |