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