@@ -17,270 +17,270 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string $iframe_name |
|
| 22 | - */ |
|
| 23 | - private $iframe_name; |
|
| 20 | + /** |
|
| 21 | + * @var string $iframe_name |
|
| 22 | + */ |
|
| 23 | + private $iframe_name; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var string $route_name |
|
| 27 | - */ |
|
| 28 | - private $route_name; |
|
| 25 | + /** |
|
| 26 | + * @var string $route_name |
|
| 27 | + */ |
|
| 28 | + private $route_name; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var string $slug |
|
| 32 | - */ |
|
| 33 | - private $slug; |
|
| 30 | + /** |
|
| 31 | + * @var string $slug |
|
| 32 | + */ |
|
| 33 | + private $slug; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var boolean $append_filterable_content |
|
| 37 | - */ |
|
| 38 | - private $append_filterable_content; |
|
| 35 | + /** |
|
| 36 | + * @var boolean $append_filterable_content |
|
| 37 | + */ |
|
| 38 | + private $append_filterable_content; |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * IframeEmbedButton constructor. |
|
| 43 | - * |
|
| 44 | - * @param string $iframe_name i18n name for the iframe. This will be used in HTML |
|
| 45 | - * @param string $route_name the name of the registered route |
|
| 46 | - * @param string $slug URL slug used for the thing the iframe button is being embedded in. |
|
| 47 | - * will most likely be "event" since that's the only usage atm |
|
| 48 | - */ |
|
| 49 | - public function __construct($iframe_name, $route_name, $slug = 'event') |
|
| 50 | - { |
|
| 51 | - $this->iframe_name = $iframe_name; |
|
| 52 | - $this->route_name = $route_name; |
|
| 53 | - $this->slug = $slug; |
|
| 54 | - } |
|
| 41 | + /** |
|
| 42 | + * IframeEmbedButton constructor. |
|
| 43 | + * |
|
| 44 | + * @param string $iframe_name i18n name for the iframe. This will be used in HTML |
|
| 45 | + * @param string $route_name the name of the registered route |
|
| 46 | + * @param string $slug URL slug used for the thing the iframe button is being embedded in. |
|
| 47 | + * will most likely be "event" since that's the only usage atm |
|
| 48 | + */ |
|
| 49 | + public function __construct($iframe_name, $route_name, $slug = 'event') |
|
| 50 | + { |
|
| 51 | + $this->iframe_name = $iframe_name; |
|
| 52 | + $this->route_name = $route_name; |
|
| 53 | + $this->slug = $slug; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Adds an iframe embed code button to the Event editor. |
|
| 59 | - */ |
|
| 60 | - public function addEventEditorIframeEmbedButtonFilter() |
|
| 61 | - { |
|
| 62 | - // add button for iframe code to event editor. |
|
| 63 | - add_filter( |
|
| 64 | - 'get_sample_permalink_html', |
|
| 65 | - array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'), |
|
| 66 | - 10, |
|
| 67 | - 2 |
|
| 68 | - ); |
|
| 69 | - add_action( |
|
| 70 | - 'admin_enqueue_scripts', |
|
| 71 | - array($this, 'embedButtonAssets'), |
|
| 72 | - 10 |
|
| 73 | - ); |
|
| 74 | - } |
|
| 57 | + /** |
|
| 58 | + * Adds an iframe embed code button to the Event editor. |
|
| 59 | + */ |
|
| 60 | + public function addEventEditorIframeEmbedButtonFilter() |
|
| 61 | + { |
|
| 62 | + // add button for iframe code to event editor. |
|
| 63 | + add_filter( |
|
| 64 | + 'get_sample_permalink_html', |
|
| 65 | + array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'), |
|
| 66 | + 10, |
|
| 67 | + 2 |
|
| 68 | + ); |
|
| 69 | + add_action( |
|
| 70 | + 'admin_enqueue_scripts', |
|
| 71 | + array($this, 'embedButtonAssets'), |
|
| 72 | + 10 |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @param $permalink_string |
|
| 79 | - * @param $id |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function appendIframeEmbedButtonToSamplePermalinkHtml($permalink_string, $id) |
|
| 83 | - { |
|
| 84 | - return $this->eventEditorIframeEmbedButton( |
|
| 85 | - $permalink_string, |
|
| 86 | - $id |
|
| 87 | - ); |
|
| 88 | - } |
|
| 77 | + /** |
|
| 78 | + * @param $permalink_string |
|
| 79 | + * @param $id |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function appendIframeEmbedButtonToSamplePermalinkHtml($permalink_string, $id) |
|
| 83 | + { |
|
| 84 | + return $this->eventEditorIframeEmbedButton( |
|
| 85 | + $permalink_string, |
|
| 86 | + $id |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * iframe embed code button to the Event editor. |
|
| 93 | - * |
|
| 94 | - * @param string $permalink_string |
|
| 95 | - * @param int $id |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - public function eventEditorIframeEmbedButton( |
|
| 99 | - $permalink_string, |
|
| 100 | - $id |
|
| 101 | - ) { |
|
| 102 | - // make sure this is ONLY when editing and the event id has been set. |
|
| 103 | - if (! empty($id)) { |
|
| 104 | - $post = get_post($id); |
|
| 105 | - // if NOT event then let's get out. |
|
| 106 | - if ($post->post_type !== 'espresso_events') { |
|
| 107 | - return $permalink_string; |
|
| 108 | - } |
|
| 109 | - $permalink_string .= $this->embedButtonHtml([$this->slug => $id]); |
|
| 110 | - } |
|
| 111 | - return $permalink_string; |
|
| 112 | - } |
|
| 91 | + /** |
|
| 92 | + * iframe embed code button to the Event editor. |
|
| 93 | + * |
|
| 94 | + * @param string $permalink_string |
|
| 95 | + * @param int $id |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + public function eventEditorIframeEmbedButton( |
|
| 99 | + $permalink_string, |
|
| 100 | + $id |
|
| 101 | + ) { |
|
| 102 | + // make sure this is ONLY when editing and the event id has been set. |
|
| 103 | + if (! empty($id)) { |
|
| 104 | + $post = get_post($id); |
|
| 105 | + // if NOT event then let's get out. |
|
| 106 | + if ($post->post_type !== 'espresso_events') { |
|
| 107 | + return $permalink_string; |
|
| 108 | + } |
|
| 109 | + $permalink_string .= $this->embedButtonHtml([$this->slug => $id]); |
|
| 110 | + } |
|
| 111 | + return $permalink_string; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
|
| 117 | - * |
|
| 118 | - * @param string $action name of the WP do_action() to hook into |
|
| 119 | - */ |
|
| 120 | - public function addActionIframeEmbedButton($action) |
|
| 121 | - { |
|
| 122 | - // add button for iframe code to event editor. |
|
| 123 | - add_action( |
|
| 124 | - $action, |
|
| 125 | - array($this, 'addActionIframeEmbedButtonCallback'), |
|
| 126 | - 10, |
|
| 127 | - 2 |
|
| 128 | - ); |
|
| 129 | - } |
|
| 115 | + /** |
|
| 116 | + * Adds an iframe embed code button via a WP do_action() as determined by the first parameter |
|
| 117 | + * |
|
| 118 | + * @param string $action name of the WP do_action() to hook into |
|
| 119 | + */ |
|
| 120 | + public function addActionIframeEmbedButton($action) |
|
| 121 | + { |
|
| 122 | + // add button for iframe code to event editor. |
|
| 123 | + add_action( |
|
| 124 | + $action, |
|
| 125 | + array($this, 'addActionIframeEmbedButtonCallback'), |
|
| 126 | + 10, |
|
| 127 | + 2 |
|
| 128 | + ); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * @return void |
|
| 134 | - */ |
|
| 135 | - public function addActionIframeEmbedButtonCallback() |
|
| 136 | - { |
|
| 137 | - echo $this->embedButtonHtml(); // already escaped |
|
| 138 | - } |
|
| 132 | + /** |
|
| 133 | + * @return void |
|
| 134 | + */ |
|
| 135 | + public function addActionIframeEmbedButtonCallback() |
|
| 136 | + { |
|
| 137 | + echo $this->embedButtonHtml(); // already escaped |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter |
|
| 143 | - * |
|
| 144 | - * @param string $filter name of the WP apply_filters() to hook into |
|
| 145 | - * @param bool $append if true, will add iframe embed button to end of content, |
|
| 146 | - * else if false, will add to the beginning of the content |
|
| 147 | - */ |
|
| 148 | - public function addFilterIframeEmbedButton($filter, $append = true) |
|
| 149 | - { |
|
| 150 | - $this->append_filterable_content = $append; |
|
| 151 | - // add button for iframe code to event editor. |
|
| 152 | - add_filter( |
|
| 153 | - $filter, |
|
| 154 | - array($this, 'addFilterIframeEmbedButtonCallback'), |
|
| 155 | - 10 |
|
| 156 | - ); |
|
| 157 | - } |
|
| 141 | + /** |
|
| 142 | + * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter |
|
| 143 | + * |
|
| 144 | + * @param string $filter name of the WP apply_filters() to hook into |
|
| 145 | + * @param bool $append if true, will add iframe embed button to end of content, |
|
| 146 | + * else if false, will add to the beginning of the content |
|
| 147 | + */ |
|
| 148 | + public function addFilterIframeEmbedButton($filter, $append = true) |
|
| 149 | + { |
|
| 150 | + $this->append_filterable_content = $append; |
|
| 151 | + // add button for iframe code to event editor. |
|
| 152 | + add_filter( |
|
| 153 | + $filter, |
|
| 154 | + array($this, 'addFilterIframeEmbedButtonCallback'), |
|
| 155 | + 10 |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * @param array|string $filterable_content |
|
| 162 | - * @return array|string |
|
| 163 | - */ |
|
| 164 | - public function addFilterIframeEmbedButtonCallback($filterable_content) |
|
| 165 | - { |
|
| 166 | - $embedButtonHtml = $this->embedButtonHtml(); |
|
| 167 | - if (is_array($filterable_content)) { |
|
| 168 | - $filterable_content = $this->append_filterable_content |
|
| 169 | - ? $filterable_content + array($this->route_name => $embedButtonHtml) |
|
| 170 | - : array($this->route_name => $embedButtonHtml) + $filterable_content; |
|
| 171 | - } else { |
|
| 172 | - $filterable_content = $this->append_filterable_content |
|
| 173 | - ? $filterable_content . $embedButtonHtml |
|
| 174 | - : $embedButtonHtml . $filterable_content; |
|
| 175 | - } |
|
| 176 | - return $filterable_content; |
|
| 177 | - } |
|
| 160 | + /** |
|
| 161 | + * @param array|string $filterable_content |
|
| 162 | + * @return array|string |
|
| 163 | + */ |
|
| 164 | + public function addFilterIframeEmbedButtonCallback($filterable_content) |
|
| 165 | + { |
|
| 166 | + $embedButtonHtml = $this->embedButtonHtml(); |
|
| 167 | + if (is_array($filterable_content)) { |
|
| 168 | + $filterable_content = $this->append_filterable_content |
|
| 169 | + ? $filterable_content + array($this->route_name => $embedButtonHtml) |
|
| 170 | + : array($this->route_name => $embedButtonHtml) + $filterable_content; |
|
| 171 | + } else { |
|
| 172 | + $filterable_content = $this->append_filterable_content |
|
| 173 | + ? $filterable_content . $embedButtonHtml |
|
| 174 | + : $embedButtonHtml . $filterable_content; |
|
| 175 | + } |
|
| 176 | + return $filterable_content; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * iframe_embed_html |
|
| 182 | - * |
|
| 183 | - * @param array $query_args |
|
| 184 | - * @param string $button_class |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function embedButtonHtml($query_args = array(), $button_class = '') |
|
| 188 | - { |
|
| 189 | - // incoming args will replace the defaults listed here in the second array (union preserves first array) |
|
| 190 | - $query_args = (array) $query_args + array($this->route_name => 'iframe'); |
|
| 191 | - $query_args = (array) apply_filters( |
|
| 192 | - 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
|
| 193 | - $query_args |
|
| 194 | - ); |
|
| 195 | - // add this route to our localized vars |
|
| 196 | - $iframe_module_routes = EE_Registry::$i18n_js_strings['iframe_module_routes'] ?? []; |
|
| 197 | - $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
| 198 | - EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
|
| 199 | - return EEH_HTML::div( |
|
| 200 | - EEH_HTML::link( |
|
| 201 | - '#', |
|
| 202 | - sprintf(esc_html__('Embed %1$s', 'event_espresso'), $this->iframe_name), |
|
| 203 | - sprintf( |
|
| 204 | - esc_html__( |
|
| 205 | - 'click here to generate code for embedding %1$s iframe into another site.', |
|
| 206 | - 'event_espresso' |
|
| 207 | - ), |
|
| 208 | - EEH_Inflector::add_indefinite_article($this->iframe_name) |
|
| 209 | - ), |
|
| 210 | - esc_attr($this->route_name) . '-iframe-embed-trigger-js', |
|
| 211 | - 'iframe-embed-trigger-js button button--small button--secondary ' . esc_attr($button_class), |
|
| 212 | - '', |
|
| 213 | - ' data-iframe_embed_button="#' . esc_attr($this->route_name) . '-iframe-js" tabindex="-1"' |
|
| 214 | - ) |
|
| 215 | - . EEH_HTML::div( |
|
| 216 | - EEH_HTML::div( |
|
| 217 | - '<iframe src="' |
|
| 218 | - . esc_url_raw(add_query_arg($query_args, site_url())) |
|
| 219 | - . '" width="100%" height="100%"></iframe>', |
|
| 220 | - '', |
|
| 221 | - '', |
|
| 222 | - 'width:100%; height: 500px;' |
|
| 223 | - ), |
|
| 224 | - esc_attr($this->route_name) . '-iframe-js', |
|
| 225 | - 'iframe-embed-wrapper-js', |
|
| 226 | - 'display:none;' |
|
| 227 | - ), |
|
| 228 | - '', |
|
| 229 | - 'ee-admin-button-row' |
|
| 230 | - ); |
|
| 231 | - } |
|
| 180 | + /** |
|
| 181 | + * iframe_embed_html |
|
| 182 | + * |
|
| 183 | + * @param array $query_args |
|
| 184 | + * @param string $button_class |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function embedButtonHtml($query_args = array(), $button_class = '') |
|
| 188 | + { |
|
| 189 | + // incoming args will replace the defaults listed here in the second array (union preserves first array) |
|
| 190 | + $query_args = (array) $query_args + array($this->route_name => 'iframe'); |
|
| 191 | + $query_args = (array) apply_filters( |
|
| 192 | + 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args', |
|
| 193 | + $query_args |
|
| 194 | + ); |
|
| 195 | + // add this route to our localized vars |
|
| 196 | + $iframe_module_routes = EE_Registry::$i18n_js_strings['iframe_module_routes'] ?? []; |
|
| 197 | + $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
| 198 | + EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
|
| 199 | + return EEH_HTML::div( |
|
| 200 | + EEH_HTML::link( |
|
| 201 | + '#', |
|
| 202 | + sprintf(esc_html__('Embed %1$s', 'event_espresso'), $this->iframe_name), |
|
| 203 | + sprintf( |
|
| 204 | + esc_html__( |
|
| 205 | + 'click here to generate code for embedding %1$s iframe into another site.', |
|
| 206 | + 'event_espresso' |
|
| 207 | + ), |
|
| 208 | + EEH_Inflector::add_indefinite_article($this->iframe_name) |
|
| 209 | + ), |
|
| 210 | + esc_attr($this->route_name) . '-iframe-embed-trigger-js', |
|
| 211 | + 'iframe-embed-trigger-js button button--small button--secondary ' . esc_attr($button_class), |
|
| 212 | + '', |
|
| 213 | + ' data-iframe_embed_button="#' . esc_attr($this->route_name) . '-iframe-js" tabindex="-1"' |
|
| 214 | + ) |
|
| 215 | + . EEH_HTML::div( |
|
| 216 | + EEH_HTML::div( |
|
| 217 | + '<iframe src="' |
|
| 218 | + . esc_url_raw(add_query_arg($query_args, site_url())) |
|
| 219 | + . '" width="100%" height="100%"></iframe>', |
|
| 220 | + '', |
|
| 221 | + '', |
|
| 222 | + 'width:100%; height: 500px;' |
|
| 223 | + ), |
|
| 224 | + esc_attr($this->route_name) . '-iframe-js', |
|
| 225 | + 'iframe-embed-wrapper-js', |
|
| 226 | + 'display:none;' |
|
| 227 | + ), |
|
| 228 | + '', |
|
| 229 | + 'ee-admin-button-row' |
|
| 230 | + ); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * enqueue iframe button js |
|
| 236 | - */ |
|
| 237 | - public function embedButtonAssets() |
|
| 238 | - { |
|
| 239 | - EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__( |
|
| 240 | - 'copy and paste the following into any other site\'s content to display this event:', |
|
| 241 | - 'event_espresso' |
|
| 242 | - ); |
|
| 243 | - EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__( |
|
| 244 | - 'click anywhere outside of this window to close it.', |
|
| 245 | - 'event_espresso' |
|
| 246 | - ); |
|
| 247 | - wp_register_script( |
|
| 248 | - 'iframe_embed_button', |
|
| 249 | - plugin_dir_url(__FILE__) . 'iframe-embed-button.js', |
|
| 250 | - array('ee-dialog'), |
|
| 251 | - EVENT_ESPRESSO_VERSION, |
|
| 252 | - true |
|
| 253 | - ); |
|
| 254 | - wp_enqueue_script('iframe_embed_button'); |
|
| 255 | - } |
|
| 234 | + /** |
|
| 235 | + * enqueue iframe button js |
|
| 236 | + */ |
|
| 237 | + public function embedButtonAssets() |
|
| 238 | + { |
|
| 239 | + EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__( |
|
| 240 | + 'copy and paste the following into any other site\'s content to display this event:', |
|
| 241 | + 'event_espresso' |
|
| 242 | + ); |
|
| 243 | + EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__( |
|
| 244 | + 'click anywhere outside of this window to close it.', |
|
| 245 | + 'event_espresso' |
|
| 246 | + ); |
|
| 247 | + wp_register_script( |
|
| 248 | + 'iframe_embed_button', |
|
| 249 | + plugin_dir_url(__FILE__) . 'iframe-embed-button.js', |
|
| 250 | + array('ee-dialog'), |
|
| 251 | + EVENT_ESPRESSO_VERSION, |
|
| 252 | + true |
|
| 253 | + ); |
|
| 254 | + wp_enqueue_script('iframe_embed_button'); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * generates embed button sections for admin pages |
|
| 260 | - * |
|
| 261 | - * @param array $embed_buttons |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - public function addIframeEmbedButtonsSection(array $embed_buttons) |
|
| 265 | - { |
|
| 266 | - $embed_buttons = (array) apply_filters( |
|
| 267 | - 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
|
| 268 | - $embed_buttons |
|
| 269 | - ); |
|
| 270 | - if (empty($embed_buttons)) { |
|
| 271 | - return ''; |
|
| 272 | - } |
|
| 273 | - // add button for iframe code to event editor. |
|
| 274 | - $html = EEH_HTML::br(2); |
|
| 275 | - $html .= EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso')); |
|
| 276 | - $html .= EEH_HTML::p( |
|
| 277 | - esc_html__( |
|
| 278 | - 'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
|
| 279 | - 'event_espresso' |
|
| 280 | - ) |
|
| 281 | - ); |
|
| 282 | - $html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
| 283 | - $html .= EEH_HTML::br(2); |
|
| 284 | - return $html; |
|
| 285 | - } |
|
| 258 | + /** |
|
| 259 | + * generates embed button sections for admin pages |
|
| 260 | + * |
|
| 261 | + * @param array $embed_buttons |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + public function addIframeEmbedButtonsSection(array $embed_buttons) |
|
| 265 | + { |
|
| 266 | + $embed_buttons = (array) apply_filters( |
|
| 267 | + 'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons', |
|
| 268 | + $embed_buttons |
|
| 269 | + ); |
|
| 270 | + if (empty($embed_buttons)) { |
|
| 271 | + return ''; |
|
| 272 | + } |
|
| 273 | + // add button for iframe code to event editor. |
|
| 274 | + $html = EEH_HTML::br(2); |
|
| 275 | + $html .= EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso')); |
|
| 276 | + $html .= EEH_HTML::p( |
|
| 277 | + esc_html__( |
|
| 278 | + 'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.', |
|
| 279 | + 'event_espresso' |
|
| 280 | + ) |
|
| 281 | + ); |
|
| 282 | + $html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
| 283 | + $html .= EEH_HTML::br(2); |
|
| 284 | + return $html; |
|
| 285 | + } |
|
| 286 | 286 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $id |
| 101 | 101 | ) { |
| 102 | 102 | // make sure this is ONLY when editing and the event id has been set. |
| 103 | - if (! empty($id)) { |
|
| 103 | + if ( ! empty($id)) { |
|
| 104 | 104 | $post = get_post($id); |
| 105 | 105 | // if NOT event then let's get out. |
| 106 | 106 | if ($post->post_type !== 'espresso_events') { |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | : array($this->route_name => $embedButtonHtml) + $filterable_content; |
| 171 | 171 | } else { |
| 172 | 172 | $filterable_content = $this->append_filterable_content |
| 173 | - ? $filterable_content . $embedButtonHtml |
|
| 174 | - : $embedButtonHtml . $filterable_content; |
|
| 173 | + ? $filterable_content.$embedButtonHtml |
|
| 174 | + : $embedButtonHtml.$filterable_content; |
|
| 175 | 175 | } |
| 176 | 176 | return $filterable_content; |
| 177 | 177 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | ); |
| 195 | 195 | // add this route to our localized vars |
| 196 | 196 | $iframe_module_routes = EE_Registry::$i18n_js_strings['iframe_module_routes'] ?? []; |
| 197 | - $iframe_module_routes[ $this->route_name ] = $this->route_name; |
|
| 197 | + $iframe_module_routes[$this->route_name] = $this->route_name; |
|
| 198 | 198 | EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes; |
| 199 | 199 | return EEH_HTML::div( |
| 200 | 200 | EEH_HTML::link( |
@@ -207,10 +207,10 @@ discard block |
||
| 207 | 207 | ), |
| 208 | 208 | EEH_Inflector::add_indefinite_article($this->iframe_name) |
| 209 | 209 | ), |
| 210 | - esc_attr($this->route_name) . '-iframe-embed-trigger-js', |
|
| 211 | - 'iframe-embed-trigger-js button button--small button--secondary ' . esc_attr($button_class), |
|
| 210 | + esc_attr($this->route_name).'-iframe-embed-trigger-js', |
|
| 211 | + 'iframe-embed-trigger-js button button--small button--secondary '.esc_attr($button_class), |
|
| 212 | 212 | '', |
| 213 | - ' data-iframe_embed_button="#' . esc_attr($this->route_name) . '-iframe-js" tabindex="-1"' |
|
| 213 | + ' data-iframe_embed_button="#'.esc_attr($this->route_name).'-iframe-js" tabindex="-1"' |
|
| 214 | 214 | ) |
| 215 | 215 | . EEH_HTML::div( |
| 216 | 216 | EEH_HTML::div( |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | '', |
| 222 | 222 | 'width:100%; height: 500px;' |
| 223 | 223 | ), |
| 224 | - esc_attr($this->route_name) . '-iframe-js', |
|
| 224 | + esc_attr($this->route_name).'-iframe-js', |
|
| 225 | 225 | 'iframe-embed-wrapper-js', |
| 226 | 226 | 'display:none;' |
| 227 | 227 | ), |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | ); |
| 247 | 247 | wp_register_script( |
| 248 | 248 | 'iframe_embed_button', |
| 249 | - plugin_dir_url(__FILE__) . 'iframe-embed-button.js', |
|
| 249 | + plugin_dir_url(__FILE__).'iframe-embed-button.js', |
|
| 250 | 250 | array('ee-dialog'), |
| 251 | 251 | EVENT_ESPRESSO_VERSION, |
| 252 | 252 | true |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | 'event_espresso' |
| 280 | 280 | ) |
| 281 | 281 | ); |
| 282 | - $html .= ' ' . implode(' ', $embed_buttons) . ' '; |
|
| 282 | + $html .= ' '.implode(' ', $embed_buttons).' '; |
|
| 283 | 283 | $html .= EEH_HTML::br(2); |
| 284 | 284 | return $html; |
| 285 | 285 | } |
@@ -15,244 +15,244 @@ |
||
| 15 | 15 | class EspressoLegacyAdminAssetManager extends AssetManager |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - const JS_HANDLE_EE_ADMIN = 'ee_admin_js'; |
|
| 18 | + const JS_HANDLE_EE_ADMIN = 'ee_admin_js'; |
|
| 19 | 19 | |
| 20 | - const JS_HANDLE_EE_AJAX_TABLE_SORTING = 'espresso_ajax_table_sorting'; |
|
| 20 | + const JS_HANDLE_EE_AJAX_TABLE_SORTING = 'espresso_ajax_table_sorting'; |
|
| 21 | 21 | |
| 22 | - const JS_HANDLE_EE_DATEPICKER = 'ee-datepicker'; |
|
| 22 | + const JS_HANDLE_EE_DATEPICKER = 'ee-datepicker'; |
|
| 23 | 23 | |
| 24 | - const JS_HANDLE_EE_DIALOG = 'ee-dialog'; |
|
| 24 | + const JS_HANDLE_EE_DIALOG = 'ee-dialog'; |
|
| 25 | 25 | |
| 26 | - const JS_HANDLE_EE_HELP_TOUR = 'ee-help-tour'; |
|
| 26 | + const JS_HANDLE_EE_HELP_TOUR = 'ee-help-tour'; |
|
| 27 | 27 | |
| 28 | - const JS_HANDLE_EE_INJECT_WP = 'ee-inject-wp'; |
|
| 28 | + const JS_HANDLE_EE_INJECT_WP = 'ee-inject-wp'; |
|
| 29 | 29 | |
| 30 | - const JS_HANDLE_GOOGLE_CHARTS = 'google-charts'; |
|
| 30 | + const JS_HANDLE_GOOGLE_CHARTS = 'google-charts'; |
|
| 31 | 31 | |
| 32 | - const JS_HANDLE_MOMENT = 'ee-moment'; |
|
| 32 | + const JS_HANDLE_MOMENT = 'ee-moment'; |
|
| 33 | 33 | |
| 34 | - const JS_HANDLE_MOMENT_CORE = 'ee-moment-core'; |
|
| 34 | + const JS_HANDLE_MOMENT_CORE = 'ee-moment-core'; |
|
| 35 | 35 | |
| 36 | - const JS_HANDLE_PARSE_URI = 'ee-parse-uri'; |
|
| 36 | + const JS_HANDLE_PARSE_URI = 'ee-parse-uri'; |
|
| 37 | 37 | |
| 38 | - const JS_HANDLE_EE_TEXT_LINKS = 'ee-text-links'; |
|
| 38 | + const JS_HANDLE_EE_TEXT_LINKS = 'ee-text-links'; |
|
| 39 | 39 | |
| 40 | - const JS_HANDLE_EE_SERIALIZE_FULL_ARRAY = 'ee-serialize-full-array'; |
|
| 41 | - |
|
| 42 | - const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
| 40 | + const JS_HANDLE_EE_SERIALIZE_FULL_ARRAY = 'ee-serialize-full-array'; |
|
| 41 | + |
|
| 42 | + const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
| 43 | 43 | |
| 44 | - const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
| 45 | - |
|
| 46 | - const CSS_HANDLE_EE_ADMIN = 'ee-admin-css'; |
|
| 47 | - |
|
| 48 | - const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
| 49 | - |
|
| 50 | - const CSS_HANDLE_EE_TEXT_LINKS = 'ee-text-links'; |
|
| 51 | - |
|
| 52 | - const CSS_HANDLE_EE_UI_THEME = 'espresso-ui-theme'; |
|
| 53 | - |
|
| 54 | - const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @inheritDoc |
|
| 59 | - */ |
|
| 60 | - public function addAssets() |
|
| 61 | - { |
|
| 62 | - $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
| 63 | - $this->registerJavascript($joyride); |
|
| 64 | - $this->registerStyleSheets($joyride); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Register javascript assets |
|
| 70 | - * |
|
| 71 | - * @param bool $joyride |
|
| 72 | - */ |
|
| 73 | - private function registerJavascript($joyride = false) |
|
| 74 | - { |
|
| 75 | - $this->addJavascript( |
|
| 76 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 77 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 78 | - [ |
|
| 79 | - JqueryAssetManager::JS_HANDLE_JQUERY, |
|
| 80 | - JqueryAssetManager::JS_HANDLE_JQUERY_UI_DRAGGABLE, |
|
| 81 | - ] |
|
| 82 | - ); |
|
| 83 | - $this->addJavascript( |
|
| 84 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 85 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 86 | - [ |
|
| 87 | - CoreAssetManager::JS_HANDLE_CORE, |
|
| 88 | - EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 89 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 90 | - ] |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - // script for sorting tables |
|
| 94 | - $this->addJavascript( |
|
| 95 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_AJAX_TABLE_SORTING, |
|
| 96 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 97 | - [ |
|
| 98 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 99 | - JqueryAssetManager::JS_HANDLE_JQUERY_UI_SORTABLE, |
|
| 100 | - ] |
|
| 101 | - ); |
|
| 102 | - |
|
| 103 | - // script for parsing uri's |
|
| 104 | - $this->addJavascript( |
|
| 105 | - EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 106 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js' |
|
| 107 | - ); |
|
| 108 | - |
|
| 109 | - // and parsing associative serialized form elements |
|
| 110 | - $this->addJavascript( |
|
| 111 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_SERIALIZE_FULL_ARRAY, |
|
| 112 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 113 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 114 | - |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - // helpers scripts |
|
| 118 | - $this->addJavascript( |
|
| 119 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_TEXT_LINKS, |
|
| 120 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 121 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 122 | - ); |
|
| 123 | - |
|
| 124 | - $this->addJavascript( |
|
| 125 | - EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE, |
|
| 126 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js' |
|
| 127 | - ); |
|
| 128 | - |
|
| 129 | - $this->addJavascript( |
|
| 130 | - EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 131 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 132 | - [EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE] |
|
| 133 | - ); |
|
| 134 | - |
|
| 135 | - $this->addJavascript( |
|
| 136 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DATEPICKER, |
|
| 137 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 138 | - [ |
|
| 139 | - JqueryAssetManager::JS_HANDLE_JQUERY_UI_TIMEPICKER_ADDON, |
|
| 140 | - EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 141 | - ] |
|
| 142 | - ); |
|
| 143 | - |
|
| 144 | - // google charts |
|
| 145 | - $this->addJavascript( |
|
| 146 | - EspressoLegacyAdminAssetManager::JS_HANDLE_GOOGLE_CHARTS, |
|
| 147 | - 'https://www.gstatic.com/charts/loader.js' |
|
| 148 | - ); |
|
| 149 | - |
|
| 150 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 151 | - // Note: the intention of this script is to only do TARGETED injections. |
|
| 152 | - //ie: only injecting on certain script calls. |
|
| 153 | - $this->addJavascript( |
|
| 154 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_INJECT_WP, |
|
| 155 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 156 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 157 | - ); |
|
| 158 | - |
|
| 159 | - $this->loadQtipJs(); |
|
| 160 | - |
|
| 161 | - // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
| 162 | - // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 163 | - if (! $joyride) { |
|
| 164 | - return; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $this->addJavascript( |
|
| 168 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 169 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 170 | - [], |
|
| 171 | - true, |
|
| 172 | - '2.1' |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - // wanna go for a joyride? |
|
| 176 | - $this->addJavascript( |
|
| 177 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 178 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 179 | - [ |
|
| 180 | - JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
| 181 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 182 | - ], |
|
| 183 | - true, |
|
| 184 | - '2.1' |
|
| 185 | - )->setEnqueueImmediately(); |
|
| 186 | - |
|
| 187 | - $this->addJavascript( |
|
| 188 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_HELP_TOUR, |
|
| 189 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 190 | - [ |
|
| 191 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 192 | - ], |
|
| 193 | - true, |
|
| 194 | - '2.1' |
|
| 195 | - )->setEnqueueImmediately(); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Register CSS assets. |
|
| 201 | - * |
|
| 202 | - * @param bool $joyride |
|
| 203 | - */ |
|
| 204 | - private function registerStyleSheets($joyride = false) |
|
| 205 | - { |
|
| 206 | - |
|
| 207 | - $this->addStylesheet( |
|
| 208 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_UI_THEME, |
|
| 209 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 210 | - ); |
|
| 211 | - |
|
| 212 | - $this->addStylesheet( |
|
| 213 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_TEXT_LINKS, |
|
| 214 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css' |
|
| 215 | - ); |
|
| 216 | - |
|
| 217 | - $this->addStylesheet( |
|
| 218 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN, |
|
| 219 | - EE_ADMIN_URL . 'assets/ee-admin-page.css' |
|
| 220 | - )->setEnqueueImmediately(); |
|
| 221 | - |
|
| 222 | - if (! $joyride) { |
|
| 223 | - return; |
|
| 224 | - } |
|
| 225 | - // joyride style |
|
| 226 | - $this->addStylesheet( |
|
| 227 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
| 228 | - EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
| 229 | - [], |
|
| 230 | - 'all', |
|
| 231 | - '2.1' |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - $this->addStylesheet( |
|
| 235 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
| 236 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 237 | - [EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE], |
|
| 238 | - 'all', |
|
| 239 | - EVENT_ESPRESSO_VERSION |
|
| 240 | - )->setEnqueueImmediately(); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * registers assets for cleaning your ears |
|
| 246 | - */ |
|
| 247 | - public function loadQtipJs() |
|
| 248 | - { |
|
| 249 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 250 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 251 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 252 | - $qtip_loader = EEH_Qtip_Loader::instance(); |
|
| 253 | - if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
| 254 | - $qtip_loader->register_and_enqueue(); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 44 | + const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
| 45 | + |
|
| 46 | + const CSS_HANDLE_EE_ADMIN = 'ee-admin-css'; |
|
| 47 | + |
|
| 48 | + const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
| 49 | + |
|
| 50 | + const CSS_HANDLE_EE_TEXT_LINKS = 'ee-text-links'; |
|
| 51 | + |
|
| 52 | + const CSS_HANDLE_EE_UI_THEME = 'espresso-ui-theme'; |
|
| 53 | + |
|
| 54 | + const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @inheritDoc |
|
| 59 | + */ |
|
| 60 | + public function addAssets() |
|
| 61 | + { |
|
| 62 | + $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
| 63 | + $this->registerJavascript($joyride); |
|
| 64 | + $this->registerStyleSheets($joyride); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Register javascript assets |
|
| 70 | + * |
|
| 71 | + * @param bool $joyride |
|
| 72 | + */ |
|
| 73 | + private function registerJavascript($joyride = false) |
|
| 74 | + { |
|
| 75 | + $this->addJavascript( |
|
| 76 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 77 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 78 | + [ |
|
| 79 | + JqueryAssetManager::JS_HANDLE_JQUERY, |
|
| 80 | + JqueryAssetManager::JS_HANDLE_JQUERY_UI_DRAGGABLE, |
|
| 81 | + ] |
|
| 82 | + ); |
|
| 83 | + $this->addJavascript( |
|
| 84 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 85 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 86 | + [ |
|
| 87 | + CoreAssetManager::JS_HANDLE_CORE, |
|
| 88 | + EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 89 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
|
| 90 | + ] |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + // script for sorting tables |
|
| 94 | + $this->addJavascript( |
|
| 95 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_AJAX_TABLE_SORTING, |
|
| 96 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 97 | + [ |
|
| 98 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 99 | + JqueryAssetManager::JS_HANDLE_JQUERY_UI_SORTABLE, |
|
| 100 | + ] |
|
| 101 | + ); |
|
| 102 | + |
|
| 103 | + // script for parsing uri's |
|
| 104 | + $this->addJavascript( |
|
| 105 | + EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
|
| 106 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js' |
|
| 107 | + ); |
|
| 108 | + |
|
| 109 | + // and parsing associative serialized form elements |
|
| 110 | + $this->addJavascript( |
|
| 111 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_SERIALIZE_FULL_ARRAY, |
|
| 112 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 113 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 114 | + |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + // helpers scripts |
|
| 118 | + $this->addJavascript( |
|
| 119 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_TEXT_LINKS, |
|
| 120 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 121 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 122 | + ); |
|
| 123 | + |
|
| 124 | + $this->addJavascript( |
|
| 125 | + EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE, |
|
| 126 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js' |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + $this->addJavascript( |
|
| 130 | + EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 131 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 132 | + [EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE] |
|
| 133 | + ); |
|
| 134 | + |
|
| 135 | + $this->addJavascript( |
|
| 136 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DATEPICKER, |
|
| 137 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 138 | + [ |
|
| 139 | + JqueryAssetManager::JS_HANDLE_JQUERY_UI_TIMEPICKER_ADDON, |
|
| 140 | + EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
|
| 141 | + ] |
|
| 142 | + ); |
|
| 143 | + |
|
| 144 | + // google charts |
|
| 145 | + $this->addJavascript( |
|
| 146 | + EspressoLegacyAdminAssetManager::JS_HANDLE_GOOGLE_CHARTS, |
|
| 147 | + 'https://www.gstatic.com/charts/loader.js' |
|
| 148 | + ); |
|
| 149 | + |
|
| 150 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 151 | + // Note: the intention of this script is to only do TARGETED injections. |
|
| 152 | + //ie: only injecting on certain script calls. |
|
| 153 | + $this->addJavascript( |
|
| 154 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_INJECT_WP, |
|
| 155 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 156 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
| 157 | + ); |
|
| 158 | + |
|
| 159 | + $this->loadQtipJs(); |
|
| 160 | + |
|
| 161 | + // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
| 162 | + // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 163 | + if (! $joyride) { |
|
| 164 | + return; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $this->addJavascript( |
|
| 168 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 169 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 170 | + [], |
|
| 171 | + true, |
|
| 172 | + '2.1' |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + // wanna go for a joyride? |
|
| 176 | + $this->addJavascript( |
|
| 177 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 178 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 179 | + [ |
|
| 180 | + JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
| 181 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
| 182 | + ], |
|
| 183 | + true, |
|
| 184 | + '2.1' |
|
| 185 | + )->setEnqueueImmediately(); |
|
| 186 | + |
|
| 187 | + $this->addJavascript( |
|
| 188 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_HELP_TOUR, |
|
| 189 | + EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 190 | + [ |
|
| 191 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
| 192 | + ], |
|
| 193 | + true, |
|
| 194 | + '2.1' |
|
| 195 | + )->setEnqueueImmediately(); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Register CSS assets. |
|
| 201 | + * |
|
| 202 | + * @param bool $joyride |
|
| 203 | + */ |
|
| 204 | + private function registerStyleSheets($joyride = false) |
|
| 205 | + { |
|
| 206 | + |
|
| 207 | + $this->addStylesheet( |
|
| 208 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_UI_THEME, |
|
| 209 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 210 | + ); |
|
| 211 | + |
|
| 212 | + $this->addStylesheet( |
|
| 213 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_TEXT_LINKS, |
|
| 214 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css' |
|
| 215 | + ); |
|
| 216 | + |
|
| 217 | + $this->addStylesheet( |
|
| 218 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN, |
|
| 219 | + EE_ADMIN_URL . 'assets/ee-admin-page.css' |
|
| 220 | + )->setEnqueueImmediately(); |
|
| 221 | + |
|
| 222 | + if (! $joyride) { |
|
| 223 | + return; |
|
| 224 | + } |
|
| 225 | + // joyride style |
|
| 226 | + $this->addStylesheet( |
|
| 227 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
| 228 | + EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
| 229 | + [], |
|
| 230 | + 'all', |
|
| 231 | + '2.1' |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + $this->addStylesheet( |
|
| 235 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
| 236 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 237 | + [EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE], |
|
| 238 | + 'all', |
|
| 239 | + EVENT_ESPRESSO_VERSION |
|
| 240 | + )->setEnqueueImmediately(); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * registers assets for cleaning your ears |
|
| 246 | + */ |
|
| 247 | + public function loadQtipJs() |
|
| 248 | + { |
|
| 249 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 250 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 251 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 252 | + $qtip_loader = EEH_Qtip_Loader::instance(); |
|
| 253 | + if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
| 254 | + $qtip_loader->register_and_enqueue(); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | 258 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | $this->addJavascript( |
| 76 | 76 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DIALOG, |
| 77 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 77 | + EE_ADMIN_URL.'assets/ee-dialog-helper.js', |
|
| 78 | 78 | [ |
| 79 | 79 | JqueryAssetManager::JS_HANDLE_JQUERY, |
| 80 | 80 | JqueryAssetManager::JS_HANDLE_JQUERY_UI_DRAGGABLE, |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | ); |
| 83 | 83 | $this->addJavascript( |
| 84 | 84 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
| 85 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 85 | + EE_ADMIN_URL.'assets/ee-admin-page.js', |
|
| 86 | 86 | [ |
| 87 | 87 | CoreAssetManager::JS_HANDLE_CORE, |
| 88 | 88 | EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | // script for sorting tables |
| 94 | 94 | $this->addJavascript( |
| 95 | 95 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_AJAX_TABLE_SORTING, |
| 96 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 96 | + EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js', |
|
| 97 | 97 | [ |
| 98 | 98 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
| 99 | 99 | JqueryAssetManager::JS_HANDLE_JQUERY_UI_SORTABLE, |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | // script for parsing uri's |
| 104 | 104 | $this->addJavascript( |
| 105 | 105 | EspressoLegacyAdminAssetManager::JS_HANDLE_PARSE_URI, |
| 106 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js' |
|
| 106 | + EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js' |
|
| 107 | 107 | ); |
| 108 | 108 | |
| 109 | 109 | // and parsing associative serialized form elements |
| 110 | 110 | $this->addJavascript( |
| 111 | 111 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_SERIALIZE_FULL_ARRAY, |
| 112 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 112 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', |
|
| 113 | 113 | [JqueryAssetManager::JS_HANDLE_JQUERY] |
| 114 | 114 | |
| 115 | 115 | ); |
@@ -117,24 +117,24 @@ discard block |
||
| 117 | 117 | // helpers scripts |
| 118 | 118 | $this->addJavascript( |
| 119 | 119 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_TEXT_LINKS, |
| 120 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 120 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', |
|
| 121 | 121 | [JqueryAssetManager::JS_HANDLE_JQUERY] |
| 122 | 122 | ); |
| 123 | 123 | |
| 124 | 124 | $this->addJavascript( |
| 125 | 125 | EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE, |
| 126 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js' |
|
| 126 | + EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js' |
|
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | 129 | $this->addJavascript( |
| 130 | 130 | EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
| 131 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 131 | + EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', |
|
| 132 | 132 | [EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT_CORE] |
| 133 | 133 | ); |
| 134 | 134 | |
| 135 | 135 | $this->addJavascript( |
| 136 | 136 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_DATEPICKER, |
| 137 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 137 | + EE_ADMIN_URL.'assets/ee-datepicker.js', |
|
| 138 | 138 | [ |
| 139 | 139 | JqueryAssetManager::JS_HANDLE_JQUERY_UI_TIMEPICKER_ADDON, |
| 140 | 140 | EspressoLegacyAdminAssetManager::JS_HANDLE_MOMENT, |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | //ie: only injecting on certain script calls. |
| 153 | 153 | $this->addJavascript( |
| 154 | 154 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_INJECT_WP, |
| 155 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 155 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
| 156 | 156 | [JqueryAssetManager::JS_HANDLE_JQUERY] |
| 157 | 157 | ); |
| 158 | 158 | |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
| 162 | 162 | // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
| 163 | - if (! $joyride) { |
|
| 163 | + if ( ! $joyride) { |
|
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $this->addJavascript( |
| 168 | 168 | EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
| 169 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 169 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
| 170 | 170 | [], |
| 171 | 171 | true, |
| 172 | 172 | '2.1' |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | // wanna go for a joyride? |
| 176 | 176 | $this->addJavascript( |
| 177 | 177 | EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
| 178 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 178 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
| 179 | 179 | [ |
| 180 | 180 | JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE, |
| 181 | 181 | EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | $this->addJavascript( |
| 188 | 188 | EspressoLegacyAdminAssetManager::JS_HANDLE_EE_HELP_TOUR, |
| 189 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 189 | + EE_ADMIN_URL.'assets/ee-help-tour.js', |
|
| 190 | 190 | [ |
| 191 | 191 | EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
| 192 | 192 | ], |
@@ -206,26 +206,26 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | $this->addStylesheet( |
| 208 | 208 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_UI_THEME, |
| 209 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 209 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css' |
|
| 210 | 210 | ); |
| 211 | 211 | |
| 212 | 212 | $this->addStylesheet( |
| 213 | 213 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_TEXT_LINKS, |
| 214 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css' |
|
| 214 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css' |
|
| 215 | 215 | ); |
| 216 | 216 | |
| 217 | 217 | $this->addStylesheet( |
| 218 | 218 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN, |
| 219 | - EE_ADMIN_URL . 'assets/ee-admin-page.css' |
|
| 219 | + EE_ADMIN_URL.'assets/ee-admin-page.css' |
|
| 220 | 220 | )->setEnqueueImmediately(); |
| 221 | 221 | |
| 222 | - if (! $joyride) { |
|
| 222 | + if ( ! $joyride) { |
|
| 223 | 223 | return; |
| 224 | 224 | } |
| 225 | 225 | // joyride style |
| 226 | 226 | $this->addStylesheet( |
| 227 | 227 | EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
| 228 | - EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
| 228 | + EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', |
|
| 229 | 229 | [], |
| 230 | 230 | 'all', |
| 231 | 231 | '2.1' |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | |
| 234 | 234 | $this->addStylesheet( |
| 235 | 235 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
| 236 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 236 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
| 237 | 237 | [EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE], |
| 238 | 238 | 'all', |
| 239 | 239 | EVENT_ESPRESSO_VERSION |
@@ -15,1256 +15,1256 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Holds a collection of EE_Message_Template_Pack objects. |
|
| 20 | - * @type EE_Messages_Template_Pack_Collection |
|
| 21 | - */ |
|
| 22 | - protected static $_template_pack_collection; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @throws EE_Error |
|
| 27 | - */ |
|
| 28 | - private static function _set_autoloader() |
|
| 29 | - { |
|
| 30 | - EED_Messages::set_autoloaders(); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * generate_new_templates |
|
| 36 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 37 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 38 | - * for the event. |
|
| 39 | - * |
|
| 40 | - * @access protected |
|
| 41 | - * @param string $messenger the messenger we are generating templates for |
|
| 42 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 43 | - * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID |
|
| 44 | - * to use as the base for the new generated template. |
|
| 45 | - * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID |
|
| 46 | - * for event specific template generation. |
|
| 47 | - * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array |
|
| 48 | - * for templates that are generated. If this is an empty array then it means no templates were |
|
| 49 | - * generated which usually means there was an error. Anything in the array with an empty value for |
|
| 50 | - * `MTP_context` means that it was not a new generated template but just reactivated (which only |
|
| 51 | - * happens for global templates that already exist in the database. |
|
| 52 | - * @throws EE_Error |
|
| 53 | - * @throws ReflectionException |
|
| 54 | - */ |
|
| 55 | - public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 56 | - { |
|
| 57 | - // make sure message_type is an array. |
|
| 58 | - $message_types = (array) $message_types; |
|
| 59 | - $templates = array(); |
|
| 60 | - |
|
| 61 | - if (empty($messenger)) { |
|
| 62 | - throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso')); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
|
| 66 | - if (empty($message_types)) { |
|
| 67 | - throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso')); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - EEH_MSG_Template::_set_autoloader(); |
|
| 71 | - foreach ($message_types as $message_type) { |
|
| 72 | - // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
|
| 73 | - if ($global && empty($GRP_ID)) { |
|
| 74 | - $GRP_ID = EEM_Message_Template_Group::instance()->get_one( |
|
| 75 | - array( |
|
| 76 | - array( |
|
| 77 | - 'MTP_messenger' => $messenger, |
|
| 78 | - 'MTP_message_type' => $message_type, |
|
| 79 | - 'MTP_is_global' => true, |
|
| 80 | - ), |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; |
|
| 84 | - } |
|
| 85 | - // if this is global template generation. |
|
| 86 | - // First let's determine if we already HAVE global templates for this messenger and message_type combination. |
|
| 87 | - // If we do then NO generation!! |
|
| 88 | - if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { |
|
| 89 | - $templates[] = array( |
|
| 90 | - 'GRP_ID' => $GRP_ID, |
|
| 91 | - 'MTP_context' => '', |
|
| 92 | - ); |
|
| 93 | - // we already have generated templates for this so let's go to the next message type. |
|
| 94 | - continue; |
|
| 95 | - } |
|
| 96 | - $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 97 | - |
|
| 98 | - if (! $new_message_template_group) { |
|
| 99 | - continue; |
|
| 100 | - } |
|
| 101 | - $templates[] = $new_message_template_group; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return $templates; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * The purpose of this method is to determine if there are already generated templates in the database for the |
|
| 110 | - * given variables. |
|
| 111 | - * |
|
| 112 | - * @param string $messenger messenger |
|
| 113 | - * @param string $message_type message type |
|
| 114 | - * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global |
|
| 115 | - * template check) |
|
| 116 | - * @return bool true = generated, false = hasn't been generated. |
|
| 117 | - * @throws EE_Error |
|
| 118 | - */ |
|
| 119 | - public static function already_generated($messenger, $message_type, $GRP_ID = 0) |
|
| 120 | - { |
|
| 121 | - EEH_MSG_Template::_set_autoloader(); |
|
| 122 | - // what method we use depends on whether we have an GRP_ID or not |
|
| 123 | - $count = empty($GRP_ID) |
|
| 124 | - ? EEM_Message_Template::instance()->count( |
|
| 125 | - array( |
|
| 126 | - array( |
|
| 127 | - 'Message_Template_Group.MTP_messenger' => $messenger, |
|
| 128 | - 'Message_Template_Group.MTP_message_type' => $message_type, |
|
| 129 | - 'Message_Template_Group.MTP_is_global' => true |
|
| 130 | - ) |
|
| 131 | - ) |
|
| 132 | - ) |
|
| 133 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
| 134 | - |
|
| 135 | - return $count > 0; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Updates all message templates matching the incoming messengers and message types to active status. |
|
| 141 | - * |
|
| 142 | - * @static |
|
| 143 | - * @param array $messenger_names Messenger slug |
|
| 144 | - * @param array $message_type_names Message type slug |
|
| 145 | - * @return int count of updated records. |
|
| 146 | - * @throws EE_Error |
|
| 147 | - */ |
|
| 148 | - public static function update_to_active($messenger_names, $message_type_names) |
|
| 149 | - { |
|
| 150 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
| 151 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
| 152 | - return EEM_Message_Template_Group::instance()->update( |
|
| 153 | - array( 'MTP_is_active' => 1 ), |
|
| 154 | - array( |
|
| 155 | - array( |
|
| 156 | - 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
| 157 | - 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
| 158 | - ) |
|
| 159 | - ) |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Updates all message template groups matching the incoming arguments to inactive status. |
|
| 166 | - * |
|
| 167 | - * @static |
|
| 168 | - * @param array $messenger_names The messenger slugs. |
|
| 169 | - * If empty then all templates matching the message types are marked inactive. |
|
| 170 | - * Otherwise only templates matching the messengers and message types. |
|
| 171 | - * @param array $message_type_names The message type slugs. |
|
| 172 | - * If empty then all templates matching the messengers are marked inactive. |
|
| 173 | - * Otherwise only templates matching the messengers and message types. |
|
| 174 | - * |
|
| 175 | - * @return int count of updated records. |
|
| 176 | - * @throws EE_Error |
|
| 177 | - */ |
|
| 178 | - public static function update_to_inactive($messenger_names = array(), $message_type_names = array()) |
|
| 179 | - { |
|
| 180 | - return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for( |
|
| 181 | - $messenger_names, |
|
| 182 | - $message_type_names |
|
| 183 | - ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * The purpose of this function is to return all installed message objects |
|
| 189 | - * (messengers and message type regardless of whether they are ACTIVE or not) |
|
| 190 | - * |
|
| 191 | - * @param string $type |
|
| 192 | - * @return array array consisting of installed messenger objects and installed message type objects. |
|
| 193 | - * @throws EE_Error |
|
| 194 | - * @throws ReflectionException |
|
| 195 | - * @deprecated 4.9.0 |
|
| 196 | - * @static |
|
| 197 | - */ |
|
| 198 | - public static function get_installed_message_objects($type = 'all') |
|
| 199 | - { |
|
| 200 | - self::_set_autoloader(); |
|
| 201 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 202 | - return array( |
|
| 203 | - 'messenger' => $message_resource_manager->installed_messengers(), |
|
| 204 | - 'message_type' => $message_resource_manager->installed_message_types() |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * This will return an array of shortcodes => labels from the |
|
| 211 | - * messenger and message_type objects associated with this |
|
| 212 | - * template. |
|
| 213 | - * |
|
| 214 | - * @param string $message_type |
|
| 215 | - * @param string $messenger |
|
| 216 | - * @param array $fields What fields we're returning valid shortcodes for. |
|
| 217 | - * If empty then we assume all fields are to be returned. Optional. |
|
| 218 | - * @param string $context What context we're going to return shortcodes for. Optional. |
|
| 219 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field, |
|
| 220 | - * but instead an array of the unique shortcodes for all the given ( |
|
| 221 | - * or all) fields. Optional. |
|
| 222 | - * @return array an array of shortcodes in the format |
|
| 223 | - * array( '[shortcode] => 'label') |
|
| 224 | - * OR |
|
| 225 | - * FALSE if no shortcodes found. |
|
| 226 | - * @throws ReflectionException |
|
| 227 | - * @throws EE_Error*@since 4.3.0 |
|
| 228 | - * |
|
| 229 | - */ |
|
| 230 | - public static function get_shortcodes( |
|
| 231 | - $message_type, |
|
| 232 | - $messenger, |
|
| 233 | - $fields = array(), |
|
| 234 | - $context = 'admin', |
|
| 235 | - $merged = false |
|
| 236 | - ) { |
|
| 237 | - $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
| 238 | - $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
| 239 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 240 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 241 | - // convert slug to object |
|
| 242 | - $messenger = $message_resource_manager->get_messenger($messenger); |
|
| 243 | - |
|
| 244 | - // if messenger isn't a EE_messenger resource then bail. |
|
| 245 | - if (! $messenger instanceof EE_messenger) { |
|
| 246 | - return array(); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // validate class for getting our list of shortcodes |
|
| 250 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 251 | - if (! class_exists($classname)) { |
|
| 252 | - $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
| 253 | - $msg[] = sprintf( |
|
| 254 | - esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
|
| 255 | - $classname |
|
| 256 | - ); |
|
| 257 | - throw new EE_Error(implode('||', $msg)); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** @type EE_Messages_Validator $_VLD */ |
|
| 261 | - $_VLD = new $classname(array(), $context); |
|
| 262 | - $valid_shortcodes = $_VLD->get_validators(); |
|
| 263 | - |
|
| 264 | - // let's make sure we're only getting the shortcode part of the validators |
|
| 265 | - $shortcodes = array(); |
|
| 266 | - foreach ($valid_shortcodes as $field => $validators) { |
|
| 267 | - $shortcodes[ $field ] = $validators['shortcodes']; |
|
| 268 | - } |
|
| 269 | - $valid_shortcodes = $shortcodes; |
|
| 270 | - |
|
| 271 | - // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
|
| 272 | - if (! empty($fields)) { |
|
| 273 | - $specified_shortcodes = array(); |
|
| 274 | - foreach ($fields as $field) { |
|
| 275 | - if (isset($valid_shortcodes[ $field ])) { |
|
| 276 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - $valid_shortcodes = $specified_shortcodes; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // if not merged then let's replace the fields with the localized fields |
|
| 283 | - if (! $merged) { |
|
| 284 | - // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
|
| 285 | - $field_settings = $messenger->get_template_fields(); |
|
| 286 | - $localized = array(); |
|
| 287 | - foreach ($valid_shortcodes as $field => $shortcodes) { |
|
| 288 | - // get localized field label |
|
| 289 | - if (isset($field_settings[ $field ])) { |
|
| 290 | - // possible that this is used as a main field. |
|
| 291 | - if (empty($field_settings[ $field ])) { |
|
| 292 | - if (isset($field_settings['extra'][ $field ])) { |
|
| 293 | - $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
| 294 | - } else { |
|
| 295 | - $_field = $field; |
|
| 296 | - } |
|
| 297 | - } else { |
|
| 298 | - $_field = $field_settings[ $field ]['label']; |
|
| 299 | - } |
|
| 300 | - } elseif (isset($field_settings['extra'])) { |
|
| 301 | - // loop through extra "main fields" and see if any of their children have our field |
|
| 302 | - foreach ($field_settings['extra'] as $fields) { |
|
| 303 | - if (isset($fields[ $field ])) { |
|
| 304 | - $_field = $fields[ $field ]['label']; |
|
| 305 | - } else { |
|
| 306 | - $_field = $field; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - } else { |
|
| 310 | - $_field = $field; |
|
| 311 | - } |
|
| 312 | - if (isset($_field)) { |
|
| 313 | - $localized[ (string) $_field ] = $shortcodes; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - $valid_shortcodes = $localized; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
|
| 320 | - if ($merged) { |
|
| 321 | - $merged_codes = array(); |
|
| 322 | - foreach ($valid_shortcodes as $shortcode) { |
|
| 323 | - foreach ($shortcode as $code => $label) { |
|
| 324 | - if (isset($merged_codes[ $code ])) { |
|
| 325 | - continue; |
|
| 326 | - } else { |
|
| 327 | - $merged_codes[ $code ] = $label; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - $valid_shortcodes = $merged_codes; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - return $valid_shortcodes; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Get Messenger object. |
|
| 340 | - * |
|
| 341 | - * @param string $messenger messenger slug for the messenger object we want to retrieve. |
|
| 342 | - * @return EE_messenger |
|
| 343 | - * @throws ReflectionException |
|
| 344 | - * @throws EE_Error*@since 4.3.0 |
|
| 345 | - * @deprecated 4.9.0 |
|
| 346 | - */ |
|
| 347 | - public static function messenger_obj($messenger) |
|
| 348 | - { |
|
| 349 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 350 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 351 | - return $Message_Resource_Manager->get_messenger($messenger); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * get Message type object |
|
| 357 | - * |
|
| 358 | - * @param string $message_type the slug for the message type object to retrieve |
|
| 359 | - * @return EE_message_type |
|
| 360 | - * @throws ReflectionException |
|
| 361 | - * @throws EE_Error*@since 4.3.0 |
|
| 362 | - * @deprecated 4.9.0 |
|
| 363 | - */ |
|
| 364 | - public static function message_type_obj($message_type) |
|
| 365 | - { |
|
| 366 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 367 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 368 | - return $Message_Resource_Manager->get_message_type($message_type); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Given a message_type slug, will return whether that message type is active in the system or not. |
|
| 374 | - * |
|
| 375 | - * @since 4.3.0 |
|
| 376 | - * @param string $message_type message type to check for. |
|
| 377 | - * @return boolean |
|
| 378 | - * @throws EE_Error |
|
| 379 | - * @throws ReflectionException |
|
| 380 | - */ |
|
| 381 | - public static function is_mt_active($message_type) |
|
| 382 | - { |
|
| 383 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 384 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 385 | - $active_mts = $Message_Resource_Manager->list_of_active_message_types(); |
|
| 386 | - return in_array($message_type, $active_mts); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Given a messenger slug, will return whether that messenger is active in the system or not. |
|
| 392 | - * |
|
| 393 | - * @since 4.3.0 |
|
| 394 | - * |
|
| 395 | - * @param string $messenger slug for messenger to check. |
|
| 396 | - * @return boolean |
|
| 397 | - * @throws EE_Error |
|
| 398 | - * @throws ReflectionException |
|
| 399 | - */ |
|
| 400 | - public static function is_messenger_active($messenger) |
|
| 401 | - { |
|
| 402 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 403 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 404 | - $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger); |
|
| 405 | - return $active_messenger instanceof EE_messenger; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Used to return active messengers array stored in the wp options table. |
|
| 411 | - * If no value is present in the option then an empty array is returned. |
|
| 412 | - * |
|
| 413 | - * @deprecated 4.9 |
|
| 414 | - * @since 4.3.1 |
|
| 415 | - * |
|
| 416 | - * @return array |
|
| 417 | - * @throws EE_Error |
|
| 418 | - * @throws ReflectionException |
|
| 419 | - */ |
|
| 420 | - public static function get_active_messengers_in_db() |
|
| 421 | - { |
|
| 422 | - EE_Error::doing_it_wrong( |
|
| 423 | - __METHOD__, |
|
| 424 | - esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), |
|
| 425 | - '4.9.0' |
|
| 426 | - ); |
|
| 427 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 428 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 429 | - return $Message_Resource_Manager->get_active_messengers_option(); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Used to update the active messengers array stored in the wp options table. |
|
| 435 | - * |
|
| 436 | - * @since 4.3.1 |
|
| 437 | - * @deprecated 4.9.0 |
|
| 438 | - * |
|
| 439 | - * @param array $data_to_save Incoming data to save. |
|
| 440 | - * |
|
| 441 | - * @return bool FALSE if not updated, TRUE if updated. |
|
| 442 | - * @throws EE_Error |
|
| 443 | - * @throws ReflectionException |
|
| 444 | - */ |
|
| 445 | - public static function update_active_messengers_in_db($data_to_save) |
|
| 446 | - { |
|
| 447 | - EE_Error::doing_it_wrong( |
|
| 448 | - __METHOD__, |
|
| 449 | - esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), |
|
| 450 | - '4.9.0' |
|
| 451 | - ); |
|
| 452 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 453 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 454 | - return $Message_Resource_Manager->update_active_messengers_option($data_to_save); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * This does some validation of incoming params, determines what type of url is being prepped and returns the |
|
| 460 | - * appropriate url trigger |
|
| 461 | - * |
|
| 462 | - * @param EE_message_type $message_type |
|
| 463 | - * @param EE_Message $message |
|
| 464 | - * @param EE_Registration | null $registration The registration object must be included if this |
|
| 465 | - * is going to be a registration trigger url. |
|
| 466 | - * @param string $sending_messenger The (optional) sending messenger for the url. |
|
| 467 | - * |
|
| 468 | - * @return string |
|
| 469 | - * @throws EE_Error |
|
| 470 | - */ |
|
| 471 | - public static function get_url_trigger( |
|
| 472 | - EE_message_type $message_type, |
|
| 473 | - EE_Message $message, |
|
| 474 | - $registration = null, |
|
| 475 | - $sending_messenger = '' |
|
| 476 | - ) { |
|
| 477 | - // first determine if the url can be to the EE_Message object. |
|
| 478 | - if (! $message_type->always_generate()) { |
|
| 479 | - return EEH_MSG_Template::generate_browser_trigger($message); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - // if $registration object is not valid then exit early because there's nothing that can be generated. |
|
| 483 | - if (! $registration instanceof EE_Registration) { |
|
| 484 | - throw new EE_Error( |
|
| 485 | - esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
|
| 486 | - ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // validate given context |
|
| 490 | - $contexts = $message_type->get_contexts(); |
|
| 491 | - if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
| 492 | - throw new EE_Error( |
|
| 493 | - sprintf( |
|
| 494 | - esc_html__('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 495 | - $message->context(), |
|
| 496 | - get_class($message_type) |
|
| 497 | - ) |
|
| 498 | - ); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
|
| 502 | - if (! empty($sending_messenger)) { |
|
| 503 | - $with_messengers = $message_type->with_messengers(); |
|
| 504 | - if ( |
|
| 505 | - ! isset($with_messengers[ $message->messenger() ]) |
|
| 506 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) |
|
| 507 | - ) { |
|
| 508 | - throw new EE_Error( |
|
| 509 | - sprintf( |
|
| 510 | - esc_html__( |
|
| 511 | - 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
| 512 | - 'event_espresso' |
|
| 513 | - ), |
|
| 514 | - $sending_messenger, |
|
| 515 | - get_class($message_type) |
|
| 516 | - ) |
|
| 517 | - ); |
|
| 518 | - } |
|
| 519 | - } else { |
|
| 520 | - $sending_messenger = $message->messenger(); |
|
| 521 | - } |
|
| 522 | - return EEH_MSG_Template::generate_url_trigger( |
|
| 523 | - $sending_messenger, |
|
| 524 | - $message->messenger(), |
|
| 525 | - $message->context(), |
|
| 526 | - $message->message_type(), |
|
| 527 | - $registration, |
|
| 528 | - $message->GRP_ID() |
|
| 529 | - ); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * This returns the url for triggering a in browser view of a specific EE_Message object. |
|
| 535 | - * @param EE_Message $message |
|
| 536 | - * @return string. |
|
| 537 | - */ |
|
| 538 | - public static function generate_browser_trigger(EE_Message $message) |
|
| 539 | - { |
|
| 540 | - $query_args = array( |
|
| 541 | - 'ee' => 'msg_browser_trigger', |
|
| 542 | - 'token' => $message->MSG_token() |
|
| 543 | - ); |
|
| 544 | - return apply_filters( |
|
| 545 | - 'FHEE__EEH_MSG_Template__generate_browser_trigger', |
|
| 546 | - add_query_arg($query_args, site_url()), |
|
| 547 | - $message |
|
| 548 | - ); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * This returns the url for triggering an in browser view of the error saved on the incoming message object. |
|
| 558 | - * @param EE_Message $message |
|
| 559 | - * @return string |
|
| 560 | - */ |
|
| 561 | - public static function generate_error_display_trigger(EE_Message $message) |
|
| 562 | - { |
|
| 563 | - return apply_filters( |
|
| 564 | - 'FHEE__EEH_MSG_Template__generate_error_display_trigger', |
|
| 565 | - add_query_arg( |
|
| 566 | - array( |
|
| 567 | - 'ee' => 'msg_browser_error_trigger', |
|
| 568 | - 'token' => $message->MSG_token() |
|
| 569 | - ), |
|
| 570 | - site_url() |
|
| 571 | - ), |
|
| 572 | - $message |
|
| 573 | - ); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * This generates a url trigger for the msg_url_trigger route using the given arguments |
|
| 579 | - * |
|
| 580 | - * @param string $sending_messenger The sending messenger slug. |
|
| 581 | - * @param string $generating_messenger The generating messenger slug. |
|
| 582 | - * @param string $context The context for the template. |
|
| 583 | - * @param string $message_type The message type slug |
|
| 584 | - * @param EE_Registration $registration |
|
| 585 | - * @param integer $message_template_group id The EE_Message_Template_Group ID for the template. |
|
| 586 | - * @param integer $data_id The id to the EE_Base_Class for getting the data used by the |
|
| 587 | - * trigger. |
|
| 588 | - * @return string The generated url. |
|
| 589 | - * @throws EE_Error |
|
| 590 | - */ |
|
| 591 | - public static function generate_url_trigger( |
|
| 592 | - $sending_messenger, |
|
| 593 | - $generating_messenger, |
|
| 594 | - $context, |
|
| 595 | - $message_type, |
|
| 596 | - EE_Registration $registration, |
|
| 597 | - $message_template_group, |
|
| 598 | - $data_id = 0 |
|
| 599 | - ) { |
|
| 600 | - $query_args = array( |
|
| 601 | - 'ee' => 'msg_url_trigger', |
|
| 602 | - 'snd_msgr' => $sending_messenger, |
|
| 603 | - 'gen_msgr' => $generating_messenger, |
|
| 604 | - 'message_type' => $message_type, |
|
| 605 | - 'context' => $context, |
|
| 606 | - 'token' => $registration->reg_url_link(), |
|
| 607 | - 'GRP_ID' => $message_template_group, |
|
| 608 | - 'id' => $data_id |
|
| 609 | - ); |
|
| 610 | - $url = add_query_arg($query_args, get_home_url()); |
|
| 611 | - |
|
| 612 | - // made it here so now we can just get the url and filter it. Filtered globally and by message type. |
|
| 613 | - return apply_filters( |
|
| 614 | - 'FHEE__EEH_MSG_Template__generate_url_trigger', |
|
| 615 | - $url, |
|
| 616 | - $sending_messenger, |
|
| 617 | - $generating_messenger, |
|
| 618 | - $context, |
|
| 619 | - $message_type, |
|
| 620 | - $registration, |
|
| 621 | - $message_template_group, |
|
| 622 | - $data_id |
|
| 623 | - ); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Return the specific css for the action icon given. |
|
| 631 | - * |
|
| 632 | - * @param string $type What action to return. |
|
| 633 | - * @return string[] |
|
| 634 | - * @since 4.9.0 |
|
| 635 | - */ |
|
| 636 | - public static function get_message_action_icon($type) |
|
| 637 | - { |
|
| 638 | - $action_icons = self::get_message_action_icons(); |
|
| 639 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : []; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * This is used for retrieving the css classes used for the icons representing message actions. |
|
| 645 | - * |
|
| 646 | - * @since 4.9.0 |
|
| 647 | - * |
|
| 648 | - * @return array |
|
| 649 | - */ |
|
| 650 | - public static function get_message_action_icons() |
|
| 651 | - { |
|
| 652 | - return apply_filters( |
|
| 653 | - 'FHEE__EEH_MSG_Template__message_action_icons', |
|
| 654 | - array( |
|
| 655 | - 'view' => array( |
|
| 656 | - 'label' => esc_html__('View Message', 'event_espresso'), |
|
| 657 | - 'css_class' => 'dashicons dashicons-welcome-view-site', |
|
| 658 | - ), |
|
| 659 | - 'error' => array( |
|
| 660 | - 'label' => esc_html__('View Error Message', 'event_espresso'), |
|
| 661 | - 'css_class' => 'dashicons dashicons-info', |
|
| 662 | - ), |
|
| 663 | - 'see_notifications_for' => array( |
|
| 664 | - 'label' => esc_html__('View Related Messages', 'event_espresso'), |
|
| 665 | - 'css_class' => 'dashicons dashicons-megaphone', |
|
| 666 | - ), |
|
| 667 | - 'generate_now' => array( |
|
| 668 | - 'label' => esc_html__('Generate the message now.', 'event_espresso'), |
|
| 669 | - 'css_class' => 'dashicons dashicons-admin-tools', |
|
| 670 | - ), |
|
| 671 | - 'send_now' => array( |
|
| 672 | - 'label' => esc_html__('Send Immediately', 'event_espresso'), |
|
| 673 | - 'css_class' => 'dashicons dashicons-controls-forward', |
|
| 674 | - ), |
|
| 675 | - 'queue_for_resending' => array( |
|
| 676 | - 'label' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 677 | - 'css_class' => 'dashicons dashicons-controls-repeat', |
|
| 678 | - ), |
|
| 679 | - 'view_transaction' => array( |
|
| 680 | - 'label' => esc_html__('View related Transaction', 'event_espresso'), |
|
| 681 | - 'css_class' => 'dashicons dashicons-cart', |
|
| 682 | - ) |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * This returns the url for a given action related to EE_Message. |
|
| 690 | - * |
|
| 691 | - * @param string $type What type of action to return the url for. |
|
| 692 | - * @param EE_Message $message Required for generating the correct url for some types. |
|
| 693 | - * @param array $query_params Any additional query params to be included with the generated url. |
|
| 694 | - * |
|
| 695 | - * @return string |
|
| 696 | - * @throws EE_Error |
|
| 697 | - * @throws ReflectionException |
|
| 698 | - * @since 4.9.0 |
|
| 699 | - * |
|
| 700 | - */ |
|
| 701 | - public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
|
| 702 | - { |
|
| 703 | - $action_urls = self::get_message_action_urls($message, $query_params); |
|
| 704 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * This returns all the current urls for EE_Message actions. |
|
| 710 | - * |
|
| 711 | - * @since 4.9.0 |
|
| 712 | - * |
|
| 713 | - * @param EE_Message $message The EE_Message object required to generate correct urls for some types. |
|
| 714 | - * @param array $query_params Any additional query_params to be included with the generated url. |
|
| 715 | - * |
|
| 716 | - * @return array |
|
| 717 | - * @throws EE_Error |
|
| 718 | - * @throws ReflectionException |
|
| 719 | - */ |
|
| 720 | - public static function get_message_action_urls(EE_Message $message = null, $query_params = array()) |
|
| 721 | - { |
|
| 722 | - EE_Registry::instance()->load_helper('URL'); |
|
| 723 | - // if $message is not an instance of EE_Message then let's just do a dummy. |
|
| 724 | - $message = empty($message) ? EE_Message_Factory::create() : $message; |
|
| 725 | - $action_urls = apply_filters( |
|
| 726 | - 'FHEE__EEH_MSG_Template__get_message_action_url', |
|
| 727 | - array( |
|
| 728 | - 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
|
| 729 | - 'error' => EEH_MSG_Template::generate_error_display_trigger($message), |
|
| 730 | - 'see_notifications_for' => EEH_URL::add_query_args_and_nonce( |
|
| 731 | - array_merge( |
|
| 732 | - array( |
|
| 733 | - 'page' => 'espresso_messages', |
|
| 734 | - 'action' => 'default', |
|
| 735 | - 'filterby' => 1, |
|
| 736 | - ), |
|
| 737 | - $query_params |
|
| 738 | - ), |
|
| 739 | - admin_url('admin.php') |
|
| 740 | - ), |
|
| 741 | - 'generate_now' => EEH_URL::add_query_args_and_nonce( |
|
| 742 | - array( |
|
| 743 | - 'page' => 'espresso_messages', |
|
| 744 | - 'action' => 'generate_now', |
|
| 745 | - 'MSG_ID' => $message->ID() |
|
| 746 | - ), |
|
| 747 | - admin_url('admin.php') |
|
| 748 | - ), |
|
| 749 | - 'send_now' => EEH_URL::add_query_args_and_nonce( |
|
| 750 | - array( |
|
| 751 | - 'page' => 'espresso_messages', |
|
| 752 | - 'action' => 'send_now', |
|
| 753 | - 'MSG_ID' => $message->ID() |
|
| 754 | - ), |
|
| 755 | - admin_url('admin.php') |
|
| 756 | - ), |
|
| 757 | - 'queue_for_resending' => EEH_URL::add_query_args_and_nonce( |
|
| 758 | - array( |
|
| 759 | - 'page' => 'espresso_messages', |
|
| 760 | - 'action' => 'queue_for_resending', |
|
| 761 | - 'MSG_ID' => $message->ID() |
|
| 762 | - ), |
|
| 763 | - admin_url('admin.php') |
|
| 764 | - ), |
|
| 765 | - ) |
|
| 766 | - ); |
|
| 767 | - if ( |
|
| 768 | - $message->TXN_ID() > 0 |
|
| 769 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 770 | - 'ee_read_transaction', |
|
| 771 | - 'espresso_transactions_default', |
|
| 772 | - $message->TXN_ID() |
|
| 773 | - ) |
|
| 774 | - ) { |
|
| 775 | - $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce( |
|
| 776 | - array( |
|
| 777 | - 'page' => 'espresso_transactions', |
|
| 778 | - 'action' => 'view_transaction', |
|
| 779 | - 'TXN_ID' => $message->TXN_ID() |
|
| 780 | - ), |
|
| 781 | - admin_url('admin.php') |
|
| 782 | - ); |
|
| 783 | - } else { |
|
| 784 | - $action_urls['view_transaction'] = ''; |
|
| 785 | - } |
|
| 786 | - return $action_urls; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * This returns a generated link html including the icon used for the action link for EE_Message actions. |
|
| 792 | - * |
|
| 793 | - * @param string $type What type of action the link is for (if invalid type is passed in then an |
|
| 794 | - * empty string is returned) |
|
| 795 | - * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly) |
|
| 796 | - * @param array $query_params Any extra query params to include in the generated link. |
|
| 797 | - * |
|
| 798 | - * @return string |
|
| 799 | - * @throws EE_Error |
|
| 800 | - * @throws ReflectionException |
|
| 801 | - * @since 4.9.0 |
|
| 802 | - * |
|
| 803 | - */ |
|
| 804 | - public static function get_message_action_link($type, EE_Message $message = null, $query_params = array()) |
|
| 805 | - { |
|
| 806 | - $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
|
| 807 | - $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
|
| 808 | - $label = $icon_css['label'] ?? null; |
|
| 809 | - $label = $label ? 'aria-label="' . $label . '"' : ''; |
|
| 810 | - $class = $label ? ' ee-aria-tooltip' : ''; |
|
| 811 | - |
|
| 812 | - if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
|
| 813 | - return ''; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - $icon_css['css_class'] .= esc_attr( |
|
| 817 | - apply_filters( |
|
| 818 | - 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
|
| 819 | - ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
| 820 | - $type, |
|
| 821 | - $message, |
|
| 822 | - $query_params |
|
| 823 | - ) |
|
| 824 | - ); |
|
| 825 | - |
|
| 826 | - return ' |
|
| 18 | + /** |
|
| 19 | + * Holds a collection of EE_Message_Template_Pack objects. |
|
| 20 | + * @type EE_Messages_Template_Pack_Collection |
|
| 21 | + */ |
|
| 22 | + protected static $_template_pack_collection; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @throws EE_Error |
|
| 27 | + */ |
|
| 28 | + private static function _set_autoloader() |
|
| 29 | + { |
|
| 30 | + EED_Messages::set_autoloaders(); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * generate_new_templates |
|
| 36 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 37 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 38 | + * for the event. |
|
| 39 | + * |
|
| 40 | + * @access protected |
|
| 41 | + * @param string $messenger the messenger we are generating templates for |
|
| 42 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 43 | + * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID |
|
| 44 | + * to use as the base for the new generated template. |
|
| 45 | + * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID |
|
| 46 | + * for event specific template generation. |
|
| 47 | + * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array |
|
| 48 | + * for templates that are generated. If this is an empty array then it means no templates were |
|
| 49 | + * generated which usually means there was an error. Anything in the array with an empty value for |
|
| 50 | + * `MTP_context` means that it was not a new generated template but just reactivated (which only |
|
| 51 | + * happens for global templates that already exist in the database. |
|
| 52 | + * @throws EE_Error |
|
| 53 | + * @throws ReflectionException |
|
| 54 | + */ |
|
| 55 | + public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 56 | + { |
|
| 57 | + // make sure message_type is an array. |
|
| 58 | + $message_types = (array) $message_types; |
|
| 59 | + $templates = array(); |
|
| 60 | + |
|
| 61 | + if (empty($messenger)) { |
|
| 62 | + throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso')); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
|
| 66 | + if (empty($message_types)) { |
|
| 67 | + throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso')); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + EEH_MSG_Template::_set_autoloader(); |
|
| 71 | + foreach ($message_types as $message_type) { |
|
| 72 | + // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
|
| 73 | + if ($global && empty($GRP_ID)) { |
|
| 74 | + $GRP_ID = EEM_Message_Template_Group::instance()->get_one( |
|
| 75 | + array( |
|
| 76 | + array( |
|
| 77 | + 'MTP_messenger' => $messenger, |
|
| 78 | + 'MTP_message_type' => $message_type, |
|
| 79 | + 'MTP_is_global' => true, |
|
| 80 | + ), |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; |
|
| 84 | + } |
|
| 85 | + // if this is global template generation. |
|
| 86 | + // First let's determine if we already HAVE global templates for this messenger and message_type combination. |
|
| 87 | + // If we do then NO generation!! |
|
| 88 | + if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { |
|
| 89 | + $templates[] = array( |
|
| 90 | + 'GRP_ID' => $GRP_ID, |
|
| 91 | + 'MTP_context' => '', |
|
| 92 | + ); |
|
| 93 | + // we already have generated templates for this so let's go to the next message type. |
|
| 94 | + continue; |
|
| 95 | + } |
|
| 96 | + $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 97 | + |
|
| 98 | + if (! $new_message_template_group) { |
|
| 99 | + continue; |
|
| 100 | + } |
|
| 101 | + $templates[] = $new_message_template_group; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return $templates; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * The purpose of this method is to determine if there are already generated templates in the database for the |
|
| 110 | + * given variables. |
|
| 111 | + * |
|
| 112 | + * @param string $messenger messenger |
|
| 113 | + * @param string $message_type message type |
|
| 114 | + * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global |
|
| 115 | + * template check) |
|
| 116 | + * @return bool true = generated, false = hasn't been generated. |
|
| 117 | + * @throws EE_Error |
|
| 118 | + */ |
|
| 119 | + public static function already_generated($messenger, $message_type, $GRP_ID = 0) |
|
| 120 | + { |
|
| 121 | + EEH_MSG_Template::_set_autoloader(); |
|
| 122 | + // what method we use depends on whether we have an GRP_ID or not |
|
| 123 | + $count = empty($GRP_ID) |
|
| 124 | + ? EEM_Message_Template::instance()->count( |
|
| 125 | + array( |
|
| 126 | + array( |
|
| 127 | + 'Message_Template_Group.MTP_messenger' => $messenger, |
|
| 128 | + 'Message_Template_Group.MTP_message_type' => $message_type, |
|
| 129 | + 'Message_Template_Group.MTP_is_global' => true |
|
| 130 | + ) |
|
| 131 | + ) |
|
| 132 | + ) |
|
| 133 | + : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
| 134 | + |
|
| 135 | + return $count > 0; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Updates all message templates matching the incoming messengers and message types to active status. |
|
| 141 | + * |
|
| 142 | + * @static |
|
| 143 | + * @param array $messenger_names Messenger slug |
|
| 144 | + * @param array $message_type_names Message type slug |
|
| 145 | + * @return int count of updated records. |
|
| 146 | + * @throws EE_Error |
|
| 147 | + */ |
|
| 148 | + public static function update_to_active($messenger_names, $message_type_names) |
|
| 149 | + { |
|
| 150 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
| 151 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
| 152 | + return EEM_Message_Template_Group::instance()->update( |
|
| 153 | + array( 'MTP_is_active' => 1 ), |
|
| 154 | + array( |
|
| 155 | + array( |
|
| 156 | + 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
| 157 | + 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
| 158 | + ) |
|
| 159 | + ) |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Updates all message template groups matching the incoming arguments to inactive status. |
|
| 166 | + * |
|
| 167 | + * @static |
|
| 168 | + * @param array $messenger_names The messenger slugs. |
|
| 169 | + * If empty then all templates matching the message types are marked inactive. |
|
| 170 | + * Otherwise only templates matching the messengers and message types. |
|
| 171 | + * @param array $message_type_names The message type slugs. |
|
| 172 | + * If empty then all templates matching the messengers are marked inactive. |
|
| 173 | + * Otherwise only templates matching the messengers and message types. |
|
| 174 | + * |
|
| 175 | + * @return int count of updated records. |
|
| 176 | + * @throws EE_Error |
|
| 177 | + */ |
|
| 178 | + public static function update_to_inactive($messenger_names = array(), $message_type_names = array()) |
|
| 179 | + { |
|
| 180 | + return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for( |
|
| 181 | + $messenger_names, |
|
| 182 | + $message_type_names |
|
| 183 | + ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * The purpose of this function is to return all installed message objects |
|
| 189 | + * (messengers and message type regardless of whether they are ACTIVE or not) |
|
| 190 | + * |
|
| 191 | + * @param string $type |
|
| 192 | + * @return array array consisting of installed messenger objects and installed message type objects. |
|
| 193 | + * @throws EE_Error |
|
| 194 | + * @throws ReflectionException |
|
| 195 | + * @deprecated 4.9.0 |
|
| 196 | + * @static |
|
| 197 | + */ |
|
| 198 | + public static function get_installed_message_objects($type = 'all') |
|
| 199 | + { |
|
| 200 | + self::_set_autoloader(); |
|
| 201 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 202 | + return array( |
|
| 203 | + 'messenger' => $message_resource_manager->installed_messengers(), |
|
| 204 | + 'message_type' => $message_resource_manager->installed_message_types() |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * This will return an array of shortcodes => labels from the |
|
| 211 | + * messenger and message_type objects associated with this |
|
| 212 | + * template. |
|
| 213 | + * |
|
| 214 | + * @param string $message_type |
|
| 215 | + * @param string $messenger |
|
| 216 | + * @param array $fields What fields we're returning valid shortcodes for. |
|
| 217 | + * If empty then we assume all fields are to be returned. Optional. |
|
| 218 | + * @param string $context What context we're going to return shortcodes for. Optional. |
|
| 219 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field, |
|
| 220 | + * but instead an array of the unique shortcodes for all the given ( |
|
| 221 | + * or all) fields. Optional. |
|
| 222 | + * @return array an array of shortcodes in the format |
|
| 223 | + * array( '[shortcode] => 'label') |
|
| 224 | + * OR |
|
| 225 | + * FALSE if no shortcodes found. |
|
| 226 | + * @throws ReflectionException |
|
| 227 | + * @throws EE_Error*@since 4.3.0 |
|
| 228 | + * |
|
| 229 | + */ |
|
| 230 | + public static function get_shortcodes( |
|
| 231 | + $message_type, |
|
| 232 | + $messenger, |
|
| 233 | + $fields = array(), |
|
| 234 | + $context = 'admin', |
|
| 235 | + $merged = false |
|
| 236 | + ) { |
|
| 237 | + $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
| 238 | + $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
| 239 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 240 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 241 | + // convert slug to object |
|
| 242 | + $messenger = $message_resource_manager->get_messenger($messenger); |
|
| 243 | + |
|
| 244 | + // if messenger isn't a EE_messenger resource then bail. |
|
| 245 | + if (! $messenger instanceof EE_messenger) { |
|
| 246 | + return array(); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // validate class for getting our list of shortcodes |
|
| 250 | + $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 251 | + if (! class_exists($classname)) { |
|
| 252 | + $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
| 253 | + $msg[] = sprintf( |
|
| 254 | + esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
|
| 255 | + $classname |
|
| 256 | + ); |
|
| 257 | + throw new EE_Error(implode('||', $msg)); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** @type EE_Messages_Validator $_VLD */ |
|
| 261 | + $_VLD = new $classname(array(), $context); |
|
| 262 | + $valid_shortcodes = $_VLD->get_validators(); |
|
| 263 | + |
|
| 264 | + // let's make sure we're only getting the shortcode part of the validators |
|
| 265 | + $shortcodes = array(); |
|
| 266 | + foreach ($valid_shortcodes as $field => $validators) { |
|
| 267 | + $shortcodes[ $field ] = $validators['shortcodes']; |
|
| 268 | + } |
|
| 269 | + $valid_shortcodes = $shortcodes; |
|
| 270 | + |
|
| 271 | + // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
|
| 272 | + if (! empty($fields)) { |
|
| 273 | + $specified_shortcodes = array(); |
|
| 274 | + foreach ($fields as $field) { |
|
| 275 | + if (isset($valid_shortcodes[ $field ])) { |
|
| 276 | + $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + $valid_shortcodes = $specified_shortcodes; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // if not merged then let's replace the fields with the localized fields |
|
| 283 | + if (! $merged) { |
|
| 284 | + // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
|
| 285 | + $field_settings = $messenger->get_template_fields(); |
|
| 286 | + $localized = array(); |
|
| 287 | + foreach ($valid_shortcodes as $field => $shortcodes) { |
|
| 288 | + // get localized field label |
|
| 289 | + if (isset($field_settings[ $field ])) { |
|
| 290 | + // possible that this is used as a main field. |
|
| 291 | + if (empty($field_settings[ $field ])) { |
|
| 292 | + if (isset($field_settings['extra'][ $field ])) { |
|
| 293 | + $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
| 294 | + } else { |
|
| 295 | + $_field = $field; |
|
| 296 | + } |
|
| 297 | + } else { |
|
| 298 | + $_field = $field_settings[ $field ]['label']; |
|
| 299 | + } |
|
| 300 | + } elseif (isset($field_settings['extra'])) { |
|
| 301 | + // loop through extra "main fields" and see if any of their children have our field |
|
| 302 | + foreach ($field_settings['extra'] as $fields) { |
|
| 303 | + if (isset($fields[ $field ])) { |
|
| 304 | + $_field = $fields[ $field ]['label']; |
|
| 305 | + } else { |
|
| 306 | + $_field = $field; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + } else { |
|
| 310 | + $_field = $field; |
|
| 311 | + } |
|
| 312 | + if (isset($_field)) { |
|
| 313 | + $localized[ (string) $_field ] = $shortcodes; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + $valid_shortcodes = $localized; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
|
| 320 | + if ($merged) { |
|
| 321 | + $merged_codes = array(); |
|
| 322 | + foreach ($valid_shortcodes as $shortcode) { |
|
| 323 | + foreach ($shortcode as $code => $label) { |
|
| 324 | + if (isset($merged_codes[ $code ])) { |
|
| 325 | + continue; |
|
| 326 | + } else { |
|
| 327 | + $merged_codes[ $code ] = $label; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + $valid_shortcodes = $merged_codes; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + return $valid_shortcodes; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Get Messenger object. |
|
| 340 | + * |
|
| 341 | + * @param string $messenger messenger slug for the messenger object we want to retrieve. |
|
| 342 | + * @return EE_messenger |
|
| 343 | + * @throws ReflectionException |
|
| 344 | + * @throws EE_Error*@since 4.3.0 |
|
| 345 | + * @deprecated 4.9.0 |
|
| 346 | + */ |
|
| 347 | + public static function messenger_obj($messenger) |
|
| 348 | + { |
|
| 349 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 350 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 351 | + return $Message_Resource_Manager->get_messenger($messenger); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * get Message type object |
|
| 357 | + * |
|
| 358 | + * @param string $message_type the slug for the message type object to retrieve |
|
| 359 | + * @return EE_message_type |
|
| 360 | + * @throws ReflectionException |
|
| 361 | + * @throws EE_Error*@since 4.3.0 |
|
| 362 | + * @deprecated 4.9.0 |
|
| 363 | + */ |
|
| 364 | + public static function message_type_obj($message_type) |
|
| 365 | + { |
|
| 366 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 367 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 368 | + return $Message_Resource_Manager->get_message_type($message_type); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Given a message_type slug, will return whether that message type is active in the system or not. |
|
| 374 | + * |
|
| 375 | + * @since 4.3.0 |
|
| 376 | + * @param string $message_type message type to check for. |
|
| 377 | + * @return boolean |
|
| 378 | + * @throws EE_Error |
|
| 379 | + * @throws ReflectionException |
|
| 380 | + */ |
|
| 381 | + public static function is_mt_active($message_type) |
|
| 382 | + { |
|
| 383 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 384 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 385 | + $active_mts = $Message_Resource_Manager->list_of_active_message_types(); |
|
| 386 | + return in_array($message_type, $active_mts); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Given a messenger slug, will return whether that messenger is active in the system or not. |
|
| 392 | + * |
|
| 393 | + * @since 4.3.0 |
|
| 394 | + * |
|
| 395 | + * @param string $messenger slug for messenger to check. |
|
| 396 | + * @return boolean |
|
| 397 | + * @throws EE_Error |
|
| 398 | + * @throws ReflectionException |
|
| 399 | + */ |
|
| 400 | + public static function is_messenger_active($messenger) |
|
| 401 | + { |
|
| 402 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 403 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 404 | + $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger); |
|
| 405 | + return $active_messenger instanceof EE_messenger; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Used to return active messengers array stored in the wp options table. |
|
| 411 | + * If no value is present in the option then an empty array is returned. |
|
| 412 | + * |
|
| 413 | + * @deprecated 4.9 |
|
| 414 | + * @since 4.3.1 |
|
| 415 | + * |
|
| 416 | + * @return array |
|
| 417 | + * @throws EE_Error |
|
| 418 | + * @throws ReflectionException |
|
| 419 | + */ |
|
| 420 | + public static function get_active_messengers_in_db() |
|
| 421 | + { |
|
| 422 | + EE_Error::doing_it_wrong( |
|
| 423 | + __METHOD__, |
|
| 424 | + esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), |
|
| 425 | + '4.9.0' |
|
| 426 | + ); |
|
| 427 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 428 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 429 | + return $Message_Resource_Manager->get_active_messengers_option(); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Used to update the active messengers array stored in the wp options table. |
|
| 435 | + * |
|
| 436 | + * @since 4.3.1 |
|
| 437 | + * @deprecated 4.9.0 |
|
| 438 | + * |
|
| 439 | + * @param array $data_to_save Incoming data to save. |
|
| 440 | + * |
|
| 441 | + * @return bool FALSE if not updated, TRUE if updated. |
|
| 442 | + * @throws EE_Error |
|
| 443 | + * @throws ReflectionException |
|
| 444 | + */ |
|
| 445 | + public static function update_active_messengers_in_db($data_to_save) |
|
| 446 | + { |
|
| 447 | + EE_Error::doing_it_wrong( |
|
| 448 | + __METHOD__, |
|
| 449 | + esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), |
|
| 450 | + '4.9.0' |
|
| 451 | + ); |
|
| 452 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 453 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 454 | + return $Message_Resource_Manager->update_active_messengers_option($data_to_save); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * This does some validation of incoming params, determines what type of url is being prepped and returns the |
|
| 460 | + * appropriate url trigger |
|
| 461 | + * |
|
| 462 | + * @param EE_message_type $message_type |
|
| 463 | + * @param EE_Message $message |
|
| 464 | + * @param EE_Registration | null $registration The registration object must be included if this |
|
| 465 | + * is going to be a registration trigger url. |
|
| 466 | + * @param string $sending_messenger The (optional) sending messenger for the url. |
|
| 467 | + * |
|
| 468 | + * @return string |
|
| 469 | + * @throws EE_Error |
|
| 470 | + */ |
|
| 471 | + public static function get_url_trigger( |
|
| 472 | + EE_message_type $message_type, |
|
| 473 | + EE_Message $message, |
|
| 474 | + $registration = null, |
|
| 475 | + $sending_messenger = '' |
|
| 476 | + ) { |
|
| 477 | + // first determine if the url can be to the EE_Message object. |
|
| 478 | + if (! $message_type->always_generate()) { |
|
| 479 | + return EEH_MSG_Template::generate_browser_trigger($message); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + // if $registration object is not valid then exit early because there's nothing that can be generated. |
|
| 483 | + if (! $registration instanceof EE_Registration) { |
|
| 484 | + throw new EE_Error( |
|
| 485 | + esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
|
| 486 | + ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // validate given context |
|
| 490 | + $contexts = $message_type->get_contexts(); |
|
| 491 | + if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
| 492 | + throw new EE_Error( |
|
| 493 | + sprintf( |
|
| 494 | + esc_html__('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 495 | + $message->context(), |
|
| 496 | + get_class($message_type) |
|
| 497 | + ) |
|
| 498 | + ); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
|
| 502 | + if (! empty($sending_messenger)) { |
|
| 503 | + $with_messengers = $message_type->with_messengers(); |
|
| 504 | + if ( |
|
| 505 | + ! isset($with_messengers[ $message->messenger() ]) |
|
| 506 | + || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) |
|
| 507 | + ) { |
|
| 508 | + throw new EE_Error( |
|
| 509 | + sprintf( |
|
| 510 | + esc_html__( |
|
| 511 | + 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
| 512 | + 'event_espresso' |
|
| 513 | + ), |
|
| 514 | + $sending_messenger, |
|
| 515 | + get_class($message_type) |
|
| 516 | + ) |
|
| 517 | + ); |
|
| 518 | + } |
|
| 519 | + } else { |
|
| 520 | + $sending_messenger = $message->messenger(); |
|
| 521 | + } |
|
| 522 | + return EEH_MSG_Template::generate_url_trigger( |
|
| 523 | + $sending_messenger, |
|
| 524 | + $message->messenger(), |
|
| 525 | + $message->context(), |
|
| 526 | + $message->message_type(), |
|
| 527 | + $registration, |
|
| 528 | + $message->GRP_ID() |
|
| 529 | + ); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * This returns the url for triggering a in browser view of a specific EE_Message object. |
|
| 535 | + * @param EE_Message $message |
|
| 536 | + * @return string. |
|
| 537 | + */ |
|
| 538 | + public static function generate_browser_trigger(EE_Message $message) |
|
| 539 | + { |
|
| 540 | + $query_args = array( |
|
| 541 | + 'ee' => 'msg_browser_trigger', |
|
| 542 | + 'token' => $message->MSG_token() |
|
| 543 | + ); |
|
| 544 | + return apply_filters( |
|
| 545 | + 'FHEE__EEH_MSG_Template__generate_browser_trigger', |
|
| 546 | + add_query_arg($query_args, site_url()), |
|
| 547 | + $message |
|
| 548 | + ); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * This returns the url for triggering an in browser view of the error saved on the incoming message object. |
|
| 558 | + * @param EE_Message $message |
|
| 559 | + * @return string |
|
| 560 | + */ |
|
| 561 | + public static function generate_error_display_trigger(EE_Message $message) |
|
| 562 | + { |
|
| 563 | + return apply_filters( |
|
| 564 | + 'FHEE__EEH_MSG_Template__generate_error_display_trigger', |
|
| 565 | + add_query_arg( |
|
| 566 | + array( |
|
| 567 | + 'ee' => 'msg_browser_error_trigger', |
|
| 568 | + 'token' => $message->MSG_token() |
|
| 569 | + ), |
|
| 570 | + site_url() |
|
| 571 | + ), |
|
| 572 | + $message |
|
| 573 | + ); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * This generates a url trigger for the msg_url_trigger route using the given arguments |
|
| 579 | + * |
|
| 580 | + * @param string $sending_messenger The sending messenger slug. |
|
| 581 | + * @param string $generating_messenger The generating messenger slug. |
|
| 582 | + * @param string $context The context for the template. |
|
| 583 | + * @param string $message_type The message type slug |
|
| 584 | + * @param EE_Registration $registration |
|
| 585 | + * @param integer $message_template_group id The EE_Message_Template_Group ID for the template. |
|
| 586 | + * @param integer $data_id The id to the EE_Base_Class for getting the data used by the |
|
| 587 | + * trigger. |
|
| 588 | + * @return string The generated url. |
|
| 589 | + * @throws EE_Error |
|
| 590 | + */ |
|
| 591 | + public static function generate_url_trigger( |
|
| 592 | + $sending_messenger, |
|
| 593 | + $generating_messenger, |
|
| 594 | + $context, |
|
| 595 | + $message_type, |
|
| 596 | + EE_Registration $registration, |
|
| 597 | + $message_template_group, |
|
| 598 | + $data_id = 0 |
|
| 599 | + ) { |
|
| 600 | + $query_args = array( |
|
| 601 | + 'ee' => 'msg_url_trigger', |
|
| 602 | + 'snd_msgr' => $sending_messenger, |
|
| 603 | + 'gen_msgr' => $generating_messenger, |
|
| 604 | + 'message_type' => $message_type, |
|
| 605 | + 'context' => $context, |
|
| 606 | + 'token' => $registration->reg_url_link(), |
|
| 607 | + 'GRP_ID' => $message_template_group, |
|
| 608 | + 'id' => $data_id |
|
| 609 | + ); |
|
| 610 | + $url = add_query_arg($query_args, get_home_url()); |
|
| 611 | + |
|
| 612 | + // made it here so now we can just get the url and filter it. Filtered globally and by message type. |
|
| 613 | + return apply_filters( |
|
| 614 | + 'FHEE__EEH_MSG_Template__generate_url_trigger', |
|
| 615 | + $url, |
|
| 616 | + $sending_messenger, |
|
| 617 | + $generating_messenger, |
|
| 618 | + $context, |
|
| 619 | + $message_type, |
|
| 620 | + $registration, |
|
| 621 | + $message_template_group, |
|
| 622 | + $data_id |
|
| 623 | + ); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Return the specific css for the action icon given. |
|
| 631 | + * |
|
| 632 | + * @param string $type What action to return. |
|
| 633 | + * @return string[] |
|
| 634 | + * @since 4.9.0 |
|
| 635 | + */ |
|
| 636 | + public static function get_message_action_icon($type) |
|
| 637 | + { |
|
| 638 | + $action_icons = self::get_message_action_icons(); |
|
| 639 | + return isset($action_icons[ $type ]) ? $action_icons[ $type ] : []; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * This is used for retrieving the css classes used for the icons representing message actions. |
|
| 645 | + * |
|
| 646 | + * @since 4.9.0 |
|
| 647 | + * |
|
| 648 | + * @return array |
|
| 649 | + */ |
|
| 650 | + public static function get_message_action_icons() |
|
| 651 | + { |
|
| 652 | + return apply_filters( |
|
| 653 | + 'FHEE__EEH_MSG_Template__message_action_icons', |
|
| 654 | + array( |
|
| 655 | + 'view' => array( |
|
| 656 | + 'label' => esc_html__('View Message', 'event_espresso'), |
|
| 657 | + 'css_class' => 'dashicons dashicons-welcome-view-site', |
|
| 658 | + ), |
|
| 659 | + 'error' => array( |
|
| 660 | + 'label' => esc_html__('View Error Message', 'event_espresso'), |
|
| 661 | + 'css_class' => 'dashicons dashicons-info', |
|
| 662 | + ), |
|
| 663 | + 'see_notifications_for' => array( |
|
| 664 | + 'label' => esc_html__('View Related Messages', 'event_espresso'), |
|
| 665 | + 'css_class' => 'dashicons dashicons-megaphone', |
|
| 666 | + ), |
|
| 667 | + 'generate_now' => array( |
|
| 668 | + 'label' => esc_html__('Generate the message now.', 'event_espresso'), |
|
| 669 | + 'css_class' => 'dashicons dashicons-admin-tools', |
|
| 670 | + ), |
|
| 671 | + 'send_now' => array( |
|
| 672 | + 'label' => esc_html__('Send Immediately', 'event_espresso'), |
|
| 673 | + 'css_class' => 'dashicons dashicons-controls-forward', |
|
| 674 | + ), |
|
| 675 | + 'queue_for_resending' => array( |
|
| 676 | + 'label' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 677 | + 'css_class' => 'dashicons dashicons-controls-repeat', |
|
| 678 | + ), |
|
| 679 | + 'view_transaction' => array( |
|
| 680 | + 'label' => esc_html__('View related Transaction', 'event_espresso'), |
|
| 681 | + 'css_class' => 'dashicons dashicons-cart', |
|
| 682 | + ) |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * This returns the url for a given action related to EE_Message. |
|
| 690 | + * |
|
| 691 | + * @param string $type What type of action to return the url for. |
|
| 692 | + * @param EE_Message $message Required for generating the correct url for some types. |
|
| 693 | + * @param array $query_params Any additional query params to be included with the generated url. |
|
| 694 | + * |
|
| 695 | + * @return string |
|
| 696 | + * @throws EE_Error |
|
| 697 | + * @throws ReflectionException |
|
| 698 | + * @since 4.9.0 |
|
| 699 | + * |
|
| 700 | + */ |
|
| 701 | + public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
|
| 702 | + { |
|
| 703 | + $action_urls = self::get_message_action_urls($message, $query_params); |
|
| 704 | + return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * This returns all the current urls for EE_Message actions. |
|
| 710 | + * |
|
| 711 | + * @since 4.9.0 |
|
| 712 | + * |
|
| 713 | + * @param EE_Message $message The EE_Message object required to generate correct urls for some types. |
|
| 714 | + * @param array $query_params Any additional query_params to be included with the generated url. |
|
| 715 | + * |
|
| 716 | + * @return array |
|
| 717 | + * @throws EE_Error |
|
| 718 | + * @throws ReflectionException |
|
| 719 | + */ |
|
| 720 | + public static function get_message_action_urls(EE_Message $message = null, $query_params = array()) |
|
| 721 | + { |
|
| 722 | + EE_Registry::instance()->load_helper('URL'); |
|
| 723 | + // if $message is not an instance of EE_Message then let's just do a dummy. |
|
| 724 | + $message = empty($message) ? EE_Message_Factory::create() : $message; |
|
| 725 | + $action_urls = apply_filters( |
|
| 726 | + 'FHEE__EEH_MSG_Template__get_message_action_url', |
|
| 727 | + array( |
|
| 728 | + 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
|
| 729 | + 'error' => EEH_MSG_Template::generate_error_display_trigger($message), |
|
| 730 | + 'see_notifications_for' => EEH_URL::add_query_args_and_nonce( |
|
| 731 | + array_merge( |
|
| 732 | + array( |
|
| 733 | + 'page' => 'espresso_messages', |
|
| 734 | + 'action' => 'default', |
|
| 735 | + 'filterby' => 1, |
|
| 736 | + ), |
|
| 737 | + $query_params |
|
| 738 | + ), |
|
| 739 | + admin_url('admin.php') |
|
| 740 | + ), |
|
| 741 | + 'generate_now' => EEH_URL::add_query_args_and_nonce( |
|
| 742 | + array( |
|
| 743 | + 'page' => 'espresso_messages', |
|
| 744 | + 'action' => 'generate_now', |
|
| 745 | + 'MSG_ID' => $message->ID() |
|
| 746 | + ), |
|
| 747 | + admin_url('admin.php') |
|
| 748 | + ), |
|
| 749 | + 'send_now' => EEH_URL::add_query_args_and_nonce( |
|
| 750 | + array( |
|
| 751 | + 'page' => 'espresso_messages', |
|
| 752 | + 'action' => 'send_now', |
|
| 753 | + 'MSG_ID' => $message->ID() |
|
| 754 | + ), |
|
| 755 | + admin_url('admin.php') |
|
| 756 | + ), |
|
| 757 | + 'queue_for_resending' => EEH_URL::add_query_args_and_nonce( |
|
| 758 | + array( |
|
| 759 | + 'page' => 'espresso_messages', |
|
| 760 | + 'action' => 'queue_for_resending', |
|
| 761 | + 'MSG_ID' => $message->ID() |
|
| 762 | + ), |
|
| 763 | + admin_url('admin.php') |
|
| 764 | + ), |
|
| 765 | + ) |
|
| 766 | + ); |
|
| 767 | + if ( |
|
| 768 | + $message->TXN_ID() > 0 |
|
| 769 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 770 | + 'ee_read_transaction', |
|
| 771 | + 'espresso_transactions_default', |
|
| 772 | + $message->TXN_ID() |
|
| 773 | + ) |
|
| 774 | + ) { |
|
| 775 | + $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce( |
|
| 776 | + array( |
|
| 777 | + 'page' => 'espresso_transactions', |
|
| 778 | + 'action' => 'view_transaction', |
|
| 779 | + 'TXN_ID' => $message->TXN_ID() |
|
| 780 | + ), |
|
| 781 | + admin_url('admin.php') |
|
| 782 | + ); |
|
| 783 | + } else { |
|
| 784 | + $action_urls['view_transaction'] = ''; |
|
| 785 | + } |
|
| 786 | + return $action_urls; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * This returns a generated link html including the icon used for the action link for EE_Message actions. |
|
| 792 | + * |
|
| 793 | + * @param string $type What type of action the link is for (if invalid type is passed in then an |
|
| 794 | + * empty string is returned) |
|
| 795 | + * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly) |
|
| 796 | + * @param array $query_params Any extra query params to include in the generated link. |
|
| 797 | + * |
|
| 798 | + * @return string |
|
| 799 | + * @throws EE_Error |
|
| 800 | + * @throws ReflectionException |
|
| 801 | + * @since 4.9.0 |
|
| 802 | + * |
|
| 803 | + */ |
|
| 804 | + public static function get_message_action_link($type, EE_Message $message = null, $query_params = array()) |
|
| 805 | + { |
|
| 806 | + $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
|
| 807 | + $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
|
| 808 | + $label = $icon_css['label'] ?? null; |
|
| 809 | + $label = $label ? 'aria-label="' . $label . '"' : ''; |
|
| 810 | + $class = $label ? ' ee-aria-tooltip' : ''; |
|
| 811 | + |
|
| 812 | + if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
|
| 813 | + return ''; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + $icon_css['css_class'] .= esc_attr( |
|
| 817 | + apply_filters( |
|
| 818 | + 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
|
| 819 | + ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
| 820 | + $type, |
|
| 821 | + $message, |
|
| 822 | + $query_params |
|
| 823 | + ) |
|
| 824 | + ); |
|
| 825 | + |
|
| 826 | + return ' |
|
| 827 | 827 | <a href="' . $url . '" ' . $label . ' class="button button--small button--icon-only' . $class . '"> |
| 828 | 828 | <span class="' . esc_attr($icon_css['css_class']) . '"></span> |
| 829 | 829 | </a>'; |
| 830 | - } |
|
| 831 | - |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered). |
|
| 838 | - * |
|
| 839 | - * @since 4.9.0 |
|
| 840 | - * @return array |
|
| 841 | - */ |
|
| 842 | - public static function reg_status_to_message_type_array() |
|
| 843 | - { |
|
| 844 | - return (array) apply_filters( |
|
| 845 | - 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array', |
|
| 846 | - array( |
|
| 847 | - EEM_Registration::status_id_approved => 'registration', |
|
| 848 | - EEM_Registration::status_id_pending_payment => 'pending_approval', |
|
| 849 | - EEM_Registration::status_id_not_approved => 'not_approved_registration', |
|
| 850 | - EEM_Registration::status_id_cancelled => 'cancelled_registration', |
|
| 851 | - EEM_Registration::status_id_declined => 'declined_registration' |
|
| 852 | - ) |
|
| 853 | - ); |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * This returns the corresponding registration message type slug to the given reg status. If there isn't a |
|
| 861 | - * match, then returns an empty string. |
|
| 862 | - * |
|
| 863 | - * @since 4.9.0 |
|
| 864 | - * @param $reg_status |
|
| 865 | - * @return string |
|
| 866 | - */ |
|
| 867 | - public static function convert_reg_status_to_message_type($reg_status) |
|
| 868 | - { |
|
| 869 | - $reg_status_array = self::reg_status_to_message_type_array(); |
|
| 870 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered). |
|
| 876 | - * |
|
| 877 | - * @since 4.9.0 |
|
| 878 | - * @return array |
|
| 879 | - */ |
|
| 880 | - public static function payment_status_to_message_type_array() |
|
| 881 | - { |
|
| 882 | - return (array) apply_filters( |
|
| 883 | - 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array', |
|
| 884 | - array( |
|
| 885 | - EEM_Payment::status_id_approved => 'payment', |
|
| 886 | - EEM_Payment::status_id_pending => 'payment_pending', |
|
| 887 | - EEM_Payment::status_id_cancelled => 'payment_cancelled', |
|
| 888 | - EEM_Payment::status_id_declined => 'payment_declined', |
|
| 889 | - EEM_Payment::status_id_failed => 'payment_failed' |
|
| 890 | - ) |
|
| 891 | - ); |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then |
|
| 899 | - * an empty string is returned |
|
| 900 | - * |
|
| 901 | - * @since 4.9.0 |
|
| 902 | - * @param $payment_status |
|
| 903 | - * @return string |
|
| 904 | - */ |
|
| 905 | - public static function convert_payment_status_to_message_type($payment_status) |
|
| 906 | - { |
|
| 907 | - $payment_status_array = self::payment_status_to_message_type_array(); |
|
| 908 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * This is used to retrieve the template pack for the given name. |
|
| 914 | - * |
|
| 915 | - * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack. |
|
| 916 | - * |
|
| 917 | - * @return EE_Messages_Template_Pack |
|
| 918 | - */ |
|
| 919 | - public static function get_template_pack($template_pack_name) |
|
| 920 | - { |
|
| 921 | - if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 922 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - // first see if in collection already |
|
| 926 | - $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name); |
|
| 927 | - |
|
| 928 | - if ($template_pack instanceof EE_Messages_Template_Pack) { |
|
| 929 | - return $template_pack; |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - // nope...let's get it. |
|
| 933 | - // not set yet so let's attempt to get it. |
|
| 934 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 935 | - ' ', |
|
| 936 | - '_', |
|
| 937 | - ucwords( |
|
| 938 | - str_replace('_', ' ', $template_pack_name) |
|
| 939 | - ) |
|
| 940 | - ); |
|
| 941 | - if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 942 | - return self::get_template_pack('default'); |
|
| 943 | - } else { |
|
| 944 | - $template_pack = new $pack_class_name(); |
|
| 945 | - self::$_template_pack_collection->add($template_pack); |
|
| 946 | - return $template_pack; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Globs template packs installed in core and returns the template pack collection with all installed template packs |
|
| 955 | - * in it. |
|
| 956 | - * |
|
| 957 | - * @since 4.9.0 |
|
| 958 | - * |
|
| 959 | - * @return EE_Messages_Template_Pack_Collection |
|
| 960 | - */ |
|
| 961 | - public static function get_template_pack_collection() |
|
| 962 | - { |
|
| 963 | - $new_collection = false; |
|
| 964 | - if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 965 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 966 | - $new_collection = true; |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - // glob the defaults directory for messages |
|
| 970 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
| 971 | - foreach ($templates as $template_path) { |
|
| 972 | - // grab folder name |
|
| 973 | - $template = basename($template_path); |
|
| 974 | - |
|
| 975 | - if (! $new_collection) { |
|
| 976 | - // already have it? |
|
| 977 | - if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
|
| 978 | - continue; |
|
| 979 | - } |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - // setup classname. |
|
| 983 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 984 | - ' ', |
|
| 985 | - '_', |
|
| 986 | - ucwords( |
|
| 987 | - str_replace( |
|
| 988 | - '_', |
|
| 989 | - ' ', |
|
| 990 | - $template |
|
| 991 | - ) |
|
| 992 | - ) |
|
| 993 | - ); |
|
| 994 | - if (! class_exists($template_pack_class_name)) { |
|
| 995 | - continue; |
|
| 996 | - } |
|
| 997 | - self::$_template_pack_collection->add(new $template_pack_class_name()); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - /** |
|
| 1001 | - * Filter for plugins to add in any additional template packs |
|
| 1002 | - * Note the filter name here is for backward compat, this used to be found in EED_Messages. |
|
| 1003 | - */ |
|
| 1004 | - $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
|
| 1005 | - foreach ((array) $additional_template_packs as $template_pack) { |
|
| 1006 | - if ( |
|
| 1007 | - self::$_template_pack_collection->get_by_name( |
|
| 1008 | - $template_pack->dbref |
|
| 1009 | - ) instanceof EE_Messages_Template_Pack |
|
| 1010 | - ) { |
|
| 1011 | - continue; |
|
| 1012 | - } |
|
| 1013 | - self::$_template_pack_collection->add($template_pack); |
|
| 1014 | - } |
|
| 1015 | - return self::$_template_pack_collection; |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - |
|
| 1019 | - /** |
|
| 1020 | - * This is a wrapper for the protected _create_new_templates function |
|
| 1021 | - * |
|
| 1022 | - * @param string $messenger_name |
|
| 1023 | - * @param string $message_type_name message type that the templates are being created for |
|
| 1024 | - * @param int $GRP_ID |
|
| 1025 | - * @param bool $global |
|
| 1026 | - * @return array |
|
| 1027 | - * @throws EE_Error |
|
| 1028 | - * @throws ReflectionException |
|
| 1029 | - */ |
|
| 1030 | - public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false) |
|
| 1031 | - { |
|
| 1032 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1033 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1034 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1035 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1036 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1037 | - return array(); |
|
| 1038 | - } |
|
| 1039 | - // whew made it this far! Okay, let's go ahead and create the templates then |
|
| 1040 | - return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * @param EE_messenger $messenger |
|
| 1046 | - * @param EE_message_type $message_type |
|
| 1047 | - * @param $GRP_ID |
|
| 1048 | - * @param $global |
|
| 1049 | - * @return array|mixed |
|
| 1050 | - * @throws EE_Error |
|
| 1051 | - * @throws ReflectionException |
|
| 1052 | - */ |
|
| 1053 | - protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
|
| 1054 | - { |
|
| 1055 | - // if we're creating a custom template then we don't need to use the defaults class |
|
| 1056 | - if (! $global) { |
|
| 1057 | - return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
|
| 1058 | - } |
|
| 1059 | - /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
|
| 1060 | - $Message_Template_Defaults = EE_Registry::factory( |
|
| 1061 | - 'EE_Messages_Template_Defaults', |
|
| 1062 | - array( $messenger, $message_type, $GRP_ID ) |
|
| 1063 | - ); |
|
| 1064 | - // generate templates |
|
| 1065 | - $success = $Message_Template_Defaults->create_new_templates(); |
|
| 1066 | - |
|
| 1067 | - // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
|
| 1068 | - // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
|
| 1069 | - // attempts. |
|
| 1070 | - if (! $success) { |
|
| 1071 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1072 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1073 | - $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * $success is in an array in the following format |
|
| 1078 | - * array( |
|
| 1079 | - * 'GRP_ID' => $new_grp_id, |
|
| 1080 | - * 'MTP_context' => $first_context_in_new_templates, |
|
| 1081 | - * ) |
|
| 1082 | - */ |
|
| 1083 | - return $success; |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * This creates a custom template using the incoming GRP_ID |
|
| 1089 | - * |
|
| 1090 | - * @param EE_messenger $messenger |
|
| 1091 | - * @param EE_message_type $message_type |
|
| 1092 | - * @param int $GRP_ID GRP_ID for the template_group being used as the base |
|
| 1093 | - * @return array $success This will be an array in the format: |
|
| 1094 | - * array( |
|
| 1095 | - * 'GRP_ID' => $new_grp_id, |
|
| 1096 | - * 'MTP_context' => $first_context_in_created_template |
|
| 1097 | - * ) |
|
| 1098 | - * @throws EE_Error |
|
| 1099 | - * @throws ReflectionException |
|
| 1100 | - * @access private |
|
| 1101 | - */ |
|
| 1102 | - private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
|
| 1103 | - { |
|
| 1104 | - // defaults |
|
| 1105 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
| 1106 | - // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
|
| 1107 | - $Message_Template_Group = empty($GRP_ID) |
|
| 1108 | - ? EEM_Message_Template_Group::instance()->get_one( |
|
| 1109 | - array( |
|
| 1110 | - array( |
|
| 1111 | - 'MTP_messenger' => $messenger->name, |
|
| 1112 | - 'MTP_message_type' => $message_type->name, |
|
| 1113 | - 'MTP_is_global' => true |
|
| 1114 | - ) |
|
| 1115 | - ) |
|
| 1116 | - ) |
|
| 1117 | - : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1118 | - // if we don't have a mtg at this point then we need to bail. |
|
| 1119 | - if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1120 | - EE_Error::add_error( |
|
| 1121 | - sprintf( |
|
| 1122 | - esc_html__( |
|
| 1123 | - 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.', |
|
| 1124 | - 'event_espresso' |
|
| 1125 | - ), |
|
| 1126 | - $GRP_ID |
|
| 1127 | - ), |
|
| 1128 | - __FILE__, |
|
| 1129 | - __FUNCTION__, |
|
| 1130 | - __LINE__ |
|
| 1131 | - ); |
|
| 1132 | - return $success; |
|
| 1133 | - } |
|
| 1134 | - // let's get all the related message_template objects for this group. |
|
| 1135 | - $message_templates = $Message_Template_Group->message_templates(); |
|
| 1136 | - // now we have what we need to setup the new template |
|
| 1137 | - $new_mtg = clone $Message_Template_Group; |
|
| 1138 | - $new_mtg->set('GRP_ID', 0); |
|
| 1139 | - $new_mtg->set('MTP_is_global', false); |
|
| 1140 | - |
|
| 1141 | - /** @var RequestInterface $request */ |
|
| 1142 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1143 | - $template_name = $request->isAjax() && $request->requestParamIsSet('templateName') |
|
| 1144 | - ? $request->getRequestParam('templateName') |
|
| 1145 | - : esc_html__('New Custom Template', 'event_espresso'); |
|
| 1146 | - $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription') |
|
| 1147 | - ? $request->getRequestParam('templateDescription') |
|
| 1148 | - : sprintf( |
|
| 1149 | - esc_html__( |
|
| 1150 | - 'This is a custom template that was created for the %s messenger and %s message type.', |
|
| 1151 | - 'event_espresso' |
|
| 1152 | - ), |
|
| 1153 | - $new_mtg->messenger_obj()->label['singular'], |
|
| 1154 | - $new_mtg->message_type_obj()->label['singular'] |
|
| 1155 | - ); |
|
| 1156 | - $new_mtg->set('MTP_name', $template_name); |
|
| 1157 | - $new_mtg->set('MTP_description', $template_description); |
|
| 1158 | - // remove ALL relations on this template group so they don't get saved! |
|
| 1159 | - $new_mtg->_remove_relations('Message_Template'); |
|
| 1160 | - $new_mtg->save(); |
|
| 1161 | - $success['GRP_ID'] = $new_mtg->ID(); |
|
| 1162 | - $success['template_name'] = $template_name; |
|
| 1163 | - // add new message templates and add relation to. |
|
| 1164 | - foreach ($message_templates as $message_template) { |
|
| 1165 | - if (! $message_template instanceof EE_Message_Template) { |
|
| 1166 | - continue; |
|
| 1167 | - } |
|
| 1168 | - $new_message_template = clone $message_template; |
|
| 1169 | - $new_message_template->set('MTP_ID', 0); |
|
| 1170 | - $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation |
|
| 1171 | - $new_message_template->save(); |
|
| 1172 | - if (empty($success['MTP_context'])) { |
|
| 1173 | - $success['MTP_context'] = $new_message_template->get('MTP_context'); |
|
| 1174 | - } |
|
| 1175 | - } |
|
| 1176 | - return $success; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - /** |
|
| 1181 | - * message_type_has_active_templates_for_messenger |
|
| 1182 | - * |
|
| 1183 | - * @param EE_messenger $messenger |
|
| 1184 | - * @param EE_message_type $message_type |
|
| 1185 | - * @param bool $global |
|
| 1186 | - * @return bool |
|
| 1187 | - * @throws EE_Error |
|
| 1188 | - */ |
|
| 1189 | - public static function message_type_has_active_templates_for_messenger( |
|
| 1190 | - EE_messenger $messenger, |
|
| 1191 | - EE_message_type $message_type, |
|
| 1192 | - $global = false |
|
| 1193 | - ) { |
|
| 1194 | - // is given message_type valid for given messenger (if this is not a global save) |
|
| 1195 | - if ($global) { |
|
| 1196 | - return true; |
|
| 1197 | - } |
|
| 1198 | - $active_templates = EEM_Message_Template_Group::instance()->count( |
|
| 1199 | - array( |
|
| 1200 | - array( |
|
| 1201 | - 'MTP_is_active' => true, |
|
| 1202 | - 'MTP_messenger' => $messenger->name, |
|
| 1203 | - 'MTP_message_type' => $message_type->name |
|
| 1204 | - ) |
|
| 1205 | - ) |
|
| 1206 | - ); |
|
| 1207 | - if ($active_templates > 0) { |
|
| 1208 | - return true; |
|
| 1209 | - } |
|
| 1210 | - EE_Error::add_error( |
|
| 1211 | - sprintf( |
|
| 1212 | - esc_html__( |
|
| 1213 | - 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.', |
|
| 1214 | - 'event_espresso' |
|
| 1215 | - ), |
|
| 1216 | - $message_type->name, |
|
| 1217 | - $messenger->name |
|
| 1218 | - ), |
|
| 1219 | - __FILE__, |
|
| 1220 | - __FUNCTION__, |
|
| 1221 | - __LINE__ |
|
| 1222 | - ); |
|
| 1223 | - return false; |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - |
|
| 1227 | - /** |
|
| 1228 | - * get_fields |
|
| 1229 | - * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). |
|
| 1230 | - * |
|
| 1231 | - * @param string $messenger_name name of EE_messenger |
|
| 1232 | - * @param string $message_type_name name of EE_message_type |
|
| 1233 | - * @return array |
|
| 1234 | - * @throws EE_Error |
|
| 1235 | - * @throws ReflectionException |
|
| 1236 | - */ |
|
| 1237 | - public static function get_fields($messenger_name, $message_type_name) |
|
| 1238 | - { |
|
| 1239 | - $template_fields = array(); |
|
| 1240 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1241 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1242 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1243 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1244 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1245 | - return array(); |
|
| 1246 | - } |
|
| 1247 | - |
|
| 1248 | - $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
| 1249 | - |
|
| 1250 | - // okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
|
| 1251 | - foreach ($message_type->get_contexts() as $context => $details) { |
|
| 1252 | - foreach ($messenger->get_template_fields() as $field => $value) { |
|
| 1253 | - if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
| 1254 | - continue; |
|
| 1255 | - } |
|
| 1256 | - $template_fields[ $context ][ $field ] = $value; |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - if (empty($template_fields)) { |
|
| 1260 | - EE_Error::add_error( |
|
| 1261 | - esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), |
|
| 1262 | - __FILE__, |
|
| 1263 | - __FUNCTION__, |
|
| 1264 | - __LINE__ |
|
| 1265 | - ); |
|
| 1266 | - return array(); |
|
| 1267 | - } |
|
| 1268 | - return $template_fields; |
|
| 1269 | - } |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + /** |
|
| 837 | + * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered). |
|
| 838 | + * |
|
| 839 | + * @since 4.9.0 |
|
| 840 | + * @return array |
|
| 841 | + */ |
|
| 842 | + public static function reg_status_to_message_type_array() |
|
| 843 | + { |
|
| 844 | + return (array) apply_filters( |
|
| 845 | + 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array', |
|
| 846 | + array( |
|
| 847 | + EEM_Registration::status_id_approved => 'registration', |
|
| 848 | + EEM_Registration::status_id_pending_payment => 'pending_approval', |
|
| 849 | + EEM_Registration::status_id_not_approved => 'not_approved_registration', |
|
| 850 | + EEM_Registration::status_id_cancelled => 'cancelled_registration', |
|
| 851 | + EEM_Registration::status_id_declined => 'declined_registration' |
|
| 852 | + ) |
|
| 853 | + ); |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * This returns the corresponding registration message type slug to the given reg status. If there isn't a |
|
| 861 | + * match, then returns an empty string. |
|
| 862 | + * |
|
| 863 | + * @since 4.9.0 |
|
| 864 | + * @param $reg_status |
|
| 865 | + * @return string |
|
| 866 | + */ |
|
| 867 | + public static function convert_reg_status_to_message_type($reg_status) |
|
| 868 | + { |
|
| 869 | + $reg_status_array = self::reg_status_to_message_type_array(); |
|
| 870 | + return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered). |
|
| 876 | + * |
|
| 877 | + * @since 4.9.0 |
|
| 878 | + * @return array |
|
| 879 | + */ |
|
| 880 | + public static function payment_status_to_message_type_array() |
|
| 881 | + { |
|
| 882 | + return (array) apply_filters( |
|
| 883 | + 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array', |
|
| 884 | + array( |
|
| 885 | + EEM_Payment::status_id_approved => 'payment', |
|
| 886 | + EEM_Payment::status_id_pending => 'payment_pending', |
|
| 887 | + EEM_Payment::status_id_cancelled => 'payment_cancelled', |
|
| 888 | + EEM_Payment::status_id_declined => 'payment_declined', |
|
| 889 | + EEM_Payment::status_id_failed => 'payment_failed' |
|
| 890 | + ) |
|
| 891 | + ); |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then |
|
| 899 | + * an empty string is returned |
|
| 900 | + * |
|
| 901 | + * @since 4.9.0 |
|
| 902 | + * @param $payment_status |
|
| 903 | + * @return string |
|
| 904 | + */ |
|
| 905 | + public static function convert_payment_status_to_message_type($payment_status) |
|
| 906 | + { |
|
| 907 | + $payment_status_array = self::payment_status_to_message_type_array(); |
|
| 908 | + return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * This is used to retrieve the template pack for the given name. |
|
| 914 | + * |
|
| 915 | + * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack. |
|
| 916 | + * |
|
| 917 | + * @return EE_Messages_Template_Pack |
|
| 918 | + */ |
|
| 919 | + public static function get_template_pack($template_pack_name) |
|
| 920 | + { |
|
| 921 | + if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 922 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + // first see if in collection already |
|
| 926 | + $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name); |
|
| 927 | + |
|
| 928 | + if ($template_pack instanceof EE_Messages_Template_Pack) { |
|
| 929 | + return $template_pack; |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + // nope...let's get it. |
|
| 933 | + // not set yet so let's attempt to get it. |
|
| 934 | + $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 935 | + ' ', |
|
| 936 | + '_', |
|
| 937 | + ucwords( |
|
| 938 | + str_replace('_', ' ', $template_pack_name) |
|
| 939 | + ) |
|
| 940 | + ); |
|
| 941 | + if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 942 | + return self::get_template_pack('default'); |
|
| 943 | + } else { |
|
| 944 | + $template_pack = new $pack_class_name(); |
|
| 945 | + self::$_template_pack_collection->add($template_pack); |
|
| 946 | + return $template_pack; |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Globs template packs installed in core and returns the template pack collection with all installed template packs |
|
| 955 | + * in it. |
|
| 956 | + * |
|
| 957 | + * @since 4.9.0 |
|
| 958 | + * |
|
| 959 | + * @return EE_Messages_Template_Pack_Collection |
|
| 960 | + */ |
|
| 961 | + public static function get_template_pack_collection() |
|
| 962 | + { |
|
| 963 | + $new_collection = false; |
|
| 964 | + if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 965 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 966 | + $new_collection = true; |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + // glob the defaults directory for messages |
|
| 970 | + $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
| 971 | + foreach ($templates as $template_path) { |
|
| 972 | + // grab folder name |
|
| 973 | + $template = basename($template_path); |
|
| 974 | + |
|
| 975 | + if (! $new_collection) { |
|
| 976 | + // already have it? |
|
| 977 | + if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
|
| 978 | + continue; |
|
| 979 | + } |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + // setup classname. |
|
| 983 | + $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 984 | + ' ', |
|
| 985 | + '_', |
|
| 986 | + ucwords( |
|
| 987 | + str_replace( |
|
| 988 | + '_', |
|
| 989 | + ' ', |
|
| 990 | + $template |
|
| 991 | + ) |
|
| 992 | + ) |
|
| 993 | + ); |
|
| 994 | + if (! class_exists($template_pack_class_name)) { |
|
| 995 | + continue; |
|
| 996 | + } |
|
| 997 | + self::$_template_pack_collection->add(new $template_pack_class_name()); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + /** |
|
| 1001 | + * Filter for plugins to add in any additional template packs |
|
| 1002 | + * Note the filter name here is for backward compat, this used to be found in EED_Messages. |
|
| 1003 | + */ |
|
| 1004 | + $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
|
| 1005 | + foreach ((array) $additional_template_packs as $template_pack) { |
|
| 1006 | + if ( |
|
| 1007 | + self::$_template_pack_collection->get_by_name( |
|
| 1008 | + $template_pack->dbref |
|
| 1009 | + ) instanceof EE_Messages_Template_Pack |
|
| 1010 | + ) { |
|
| 1011 | + continue; |
|
| 1012 | + } |
|
| 1013 | + self::$_template_pack_collection->add($template_pack); |
|
| 1014 | + } |
|
| 1015 | + return self::$_template_pack_collection; |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + |
|
| 1019 | + /** |
|
| 1020 | + * This is a wrapper for the protected _create_new_templates function |
|
| 1021 | + * |
|
| 1022 | + * @param string $messenger_name |
|
| 1023 | + * @param string $message_type_name message type that the templates are being created for |
|
| 1024 | + * @param int $GRP_ID |
|
| 1025 | + * @param bool $global |
|
| 1026 | + * @return array |
|
| 1027 | + * @throws EE_Error |
|
| 1028 | + * @throws ReflectionException |
|
| 1029 | + */ |
|
| 1030 | + public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false) |
|
| 1031 | + { |
|
| 1032 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1033 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1034 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1035 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1036 | + if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1037 | + return array(); |
|
| 1038 | + } |
|
| 1039 | + // whew made it this far! Okay, let's go ahead and create the templates then |
|
| 1040 | + return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * @param EE_messenger $messenger |
|
| 1046 | + * @param EE_message_type $message_type |
|
| 1047 | + * @param $GRP_ID |
|
| 1048 | + * @param $global |
|
| 1049 | + * @return array|mixed |
|
| 1050 | + * @throws EE_Error |
|
| 1051 | + * @throws ReflectionException |
|
| 1052 | + */ |
|
| 1053 | + protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
|
| 1054 | + { |
|
| 1055 | + // if we're creating a custom template then we don't need to use the defaults class |
|
| 1056 | + if (! $global) { |
|
| 1057 | + return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
|
| 1058 | + } |
|
| 1059 | + /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
|
| 1060 | + $Message_Template_Defaults = EE_Registry::factory( |
|
| 1061 | + 'EE_Messages_Template_Defaults', |
|
| 1062 | + array( $messenger, $message_type, $GRP_ID ) |
|
| 1063 | + ); |
|
| 1064 | + // generate templates |
|
| 1065 | + $success = $Message_Template_Defaults->create_new_templates(); |
|
| 1066 | + |
|
| 1067 | + // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
|
| 1068 | + // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
|
| 1069 | + // attempts. |
|
| 1070 | + if (! $success) { |
|
| 1071 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1072 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1073 | + $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * $success is in an array in the following format |
|
| 1078 | + * array( |
|
| 1079 | + * 'GRP_ID' => $new_grp_id, |
|
| 1080 | + * 'MTP_context' => $first_context_in_new_templates, |
|
| 1081 | + * ) |
|
| 1082 | + */ |
|
| 1083 | + return $success; |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * This creates a custom template using the incoming GRP_ID |
|
| 1089 | + * |
|
| 1090 | + * @param EE_messenger $messenger |
|
| 1091 | + * @param EE_message_type $message_type |
|
| 1092 | + * @param int $GRP_ID GRP_ID for the template_group being used as the base |
|
| 1093 | + * @return array $success This will be an array in the format: |
|
| 1094 | + * array( |
|
| 1095 | + * 'GRP_ID' => $new_grp_id, |
|
| 1096 | + * 'MTP_context' => $first_context_in_created_template |
|
| 1097 | + * ) |
|
| 1098 | + * @throws EE_Error |
|
| 1099 | + * @throws ReflectionException |
|
| 1100 | + * @access private |
|
| 1101 | + */ |
|
| 1102 | + private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
|
| 1103 | + { |
|
| 1104 | + // defaults |
|
| 1105 | + $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
| 1106 | + // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
|
| 1107 | + $Message_Template_Group = empty($GRP_ID) |
|
| 1108 | + ? EEM_Message_Template_Group::instance()->get_one( |
|
| 1109 | + array( |
|
| 1110 | + array( |
|
| 1111 | + 'MTP_messenger' => $messenger->name, |
|
| 1112 | + 'MTP_message_type' => $message_type->name, |
|
| 1113 | + 'MTP_is_global' => true |
|
| 1114 | + ) |
|
| 1115 | + ) |
|
| 1116 | + ) |
|
| 1117 | + : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1118 | + // if we don't have a mtg at this point then we need to bail. |
|
| 1119 | + if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1120 | + EE_Error::add_error( |
|
| 1121 | + sprintf( |
|
| 1122 | + esc_html__( |
|
| 1123 | + 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.', |
|
| 1124 | + 'event_espresso' |
|
| 1125 | + ), |
|
| 1126 | + $GRP_ID |
|
| 1127 | + ), |
|
| 1128 | + __FILE__, |
|
| 1129 | + __FUNCTION__, |
|
| 1130 | + __LINE__ |
|
| 1131 | + ); |
|
| 1132 | + return $success; |
|
| 1133 | + } |
|
| 1134 | + // let's get all the related message_template objects for this group. |
|
| 1135 | + $message_templates = $Message_Template_Group->message_templates(); |
|
| 1136 | + // now we have what we need to setup the new template |
|
| 1137 | + $new_mtg = clone $Message_Template_Group; |
|
| 1138 | + $new_mtg->set('GRP_ID', 0); |
|
| 1139 | + $new_mtg->set('MTP_is_global', false); |
|
| 1140 | + |
|
| 1141 | + /** @var RequestInterface $request */ |
|
| 1142 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1143 | + $template_name = $request->isAjax() && $request->requestParamIsSet('templateName') |
|
| 1144 | + ? $request->getRequestParam('templateName') |
|
| 1145 | + : esc_html__('New Custom Template', 'event_espresso'); |
|
| 1146 | + $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription') |
|
| 1147 | + ? $request->getRequestParam('templateDescription') |
|
| 1148 | + : sprintf( |
|
| 1149 | + esc_html__( |
|
| 1150 | + 'This is a custom template that was created for the %s messenger and %s message type.', |
|
| 1151 | + 'event_espresso' |
|
| 1152 | + ), |
|
| 1153 | + $new_mtg->messenger_obj()->label['singular'], |
|
| 1154 | + $new_mtg->message_type_obj()->label['singular'] |
|
| 1155 | + ); |
|
| 1156 | + $new_mtg->set('MTP_name', $template_name); |
|
| 1157 | + $new_mtg->set('MTP_description', $template_description); |
|
| 1158 | + // remove ALL relations on this template group so they don't get saved! |
|
| 1159 | + $new_mtg->_remove_relations('Message_Template'); |
|
| 1160 | + $new_mtg->save(); |
|
| 1161 | + $success['GRP_ID'] = $new_mtg->ID(); |
|
| 1162 | + $success['template_name'] = $template_name; |
|
| 1163 | + // add new message templates and add relation to. |
|
| 1164 | + foreach ($message_templates as $message_template) { |
|
| 1165 | + if (! $message_template instanceof EE_Message_Template) { |
|
| 1166 | + continue; |
|
| 1167 | + } |
|
| 1168 | + $new_message_template = clone $message_template; |
|
| 1169 | + $new_message_template->set('MTP_ID', 0); |
|
| 1170 | + $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation |
|
| 1171 | + $new_message_template->save(); |
|
| 1172 | + if (empty($success['MTP_context'])) { |
|
| 1173 | + $success['MTP_context'] = $new_message_template->get('MTP_context'); |
|
| 1174 | + } |
|
| 1175 | + } |
|
| 1176 | + return $success; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + /** |
|
| 1181 | + * message_type_has_active_templates_for_messenger |
|
| 1182 | + * |
|
| 1183 | + * @param EE_messenger $messenger |
|
| 1184 | + * @param EE_message_type $message_type |
|
| 1185 | + * @param bool $global |
|
| 1186 | + * @return bool |
|
| 1187 | + * @throws EE_Error |
|
| 1188 | + */ |
|
| 1189 | + public static function message_type_has_active_templates_for_messenger( |
|
| 1190 | + EE_messenger $messenger, |
|
| 1191 | + EE_message_type $message_type, |
|
| 1192 | + $global = false |
|
| 1193 | + ) { |
|
| 1194 | + // is given message_type valid for given messenger (if this is not a global save) |
|
| 1195 | + if ($global) { |
|
| 1196 | + return true; |
|
| 1197 | + } |
|
| 1198 | + $active_templates = EEM_Message_Template_Group::instance()->count( |
|
| 1199 | + array( |
|
| 1200 | + array( |
|
| 1201 | + 'MTP_is_active' => true, |
|
| 1202 | + 'MTP_messenger' => $messenger->name, |
|
| 1203 | + 'MTP_message_type' => $message_type->name |
|
| 1204 | + ) |
|
| 1205 | + ) |
|
| 1206 | + ); |
|
| 1207 | + if ($active_templates > 0) { |
|
| 1208 | + return true; |
|
| 1209 | + } |
|
| 1210 | + EE_Error::add_error( |
|
| 1211 | + sprintf( |
|
| 1212 | + esc_html__( |
|
| 1213 | + 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.', |
|
| 1214 | + 'event_espresso' |
|
| 1215 | + ), |
|
| 1216 | + $message_type->name, |
|
| 1217 | + $messenger->name |
|
| 1218 | + ), |
|
| 1219 | + __FILE__, |
|
| 1220 | + __FUNCTION__, |
|
| 1221 | + __LINE__ |
|
| 1222 | + ); |
|
| 1223 | + return false; |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * get_fields |
|
| 1229 | + * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). |
|
| 1230 | + * |
|
| 1231 | + * @param string $messenger_name name of EE_messenger |
|
| 1232 | + * @param string $message_type_name name of EE_message_type |
|
| 1233 | + * @return array |
|
| 1234 | + * @throws EE_Error |
|
| 1235 | + * @throws ReflectionException |
|
| 1236 | + */ |
|
| 1237 | + public static function get_fields($messenger_name, $message_type_name) |
|
| 1238 | + { |
|
| 1239 | + $template_fields = array(); |
|
| 1240 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1241 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1242 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1243 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1244 | + if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1245 | + return array(); |
|
| 1246 | + } |
|
| 1247 | + |
|
| 1248 | + $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
| 1249 | + |
|
| 1250 | + // okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
|
| 1251 | + foreach ($message_type->get_contexts() as $context => $details) { |
|
| 1252 | + foreach ($messenger->get_template_fields() as $field => $value) { |
|
| 1253 | + if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
| 1254 | + continue; |
|
| 1255 | + } |
|
| 1256 | + $template_fields[ $context ][ $field ] = $value; |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + if (empty($template_fields)) { |
|
| 1260 | + EE_Error::add_error( |
|
| 1261 | + esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), |
|
| 1262 | + __FILE__, |
|
| 1263 | + __FUNCTION__, |
|
| 1264 | + __LINE__ |
|
| 1265 | + ); |
|
| 1266 | + return array(); |
|
| 1267 | + } |
|
| 1268 | + return $template_fields; |
|
| 1269 | + } |
|
| 1270 | 1270 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
| 97 | 97 | |
| 98 | - if (! $new_message_template_group) { |
|
| 98 | + if ( ! $new_message_template_group) { |
|
| 99 | 99 | continue; |
| 100 | 100 | } |
| 101 | 101 | $templates[] = $new_message_template_group; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | ) |
| 131 | 131 | ) |
| 132 | 132 | ) |
| 133 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
| 133 | + : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID))); |
|
| 134 | 134 | |
| 135 | 135 | return $count > 0; |
| 136 | 136 | } |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public static function update_to_active($messenger_names, $message_type_names) |
| 149 | 149 | { |
| 150 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
| 151 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
| 150 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names); |
|
| 151 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names); |
|
| 152 | 152 | return EEM_Message_Template_Group::instance()->update( |
| 153 | - array( 'MTP_is_active' => 1 ), |
|
| 153 | + array('MTP_is_active' => 1), |
|
| 154 | 154 | array( |
| 155 | 155 | array( |
| 156 | - 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
| 157 | - 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
| 156 | + 'MTP_messenger' => array('IN', $messenger_names), |
|
| 157 | + 'MTP_message_type' => array('IN', $message_type_names) |
|
| 158 | 158 | ) |
| 159 | 159 | ) |
| 160 | 160 | ); |
@@ -242,13 +242,13 @@ discard block |
||
| 242 | 242 | $messenger = $message_resource_manager->get_messenger($messenger); |
| 243 | 243 | |
| 244 | 244 | // if messenger isn't a EE_messenger resource then bail. |
| 245 | - if (! $messenger instanceof EE_messenger) { |
|
| 245 | + if ( ! $messenger instanceof EE_messenger) { |
|
| 246 | 246 | return array(); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | // validate class for getting our list of shortcodes |
| 250 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 251 | - if (! class_exists($classname)) { |
|
| 250 | + $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator'; |
|
| 251 | + if ( ! class_exists($classname)) { |
|
| 252 | 252 | $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
| 253 | 253 | $msg[] = sprintf( |
| 254 | 254 | esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
@@ -264,44 +264,44 @@ discard block |
||
| 264 | 264 | // let's make sure we're only getting the shortcode part of the validators |
| 265 | 265 | $shortcodes = array(); |
| 266 | 266 | foreach ($valid_shortcodes as $field => $validators) { |
| 267 | - $shortcodes[ $field ] = $validators['shortcodes']; |
|
| 267 | + $shortcodes[$field] = $validators['shortcodes']; |
|
| 268 | 268 | } |
| 269 | 269 | $valid_shortcodes = $shortcodes; |
| 270 | 270 | |
| 271 | 271 | // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
| 272 | - if (! empty($fields)) { |
|
| 272 | + if ( ! empty($fields)) { |
|
| 273 | 273 | $specified_shortcodes = array(); |
| 274 | 274 | foreach ($fields as $field) { |
| 275 | - if (isset($valid_shortcodes[ $field ])) { |
|
| 276 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
| 275 | + if (isset($valid_shortcodes[$field])) { |
|
| 276 | + $specified_shortcodes[$field] = $valid_shortcodes[$field]; |
|
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | $valid_shortcodes = $specified_shortcodes; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // if not merged then let's replace the fields with the localized fields |
| 283 | - if (! $merged) { |
|
| 283 | + if ( ! $merged) { |
|
| 284 | 284 | // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
| 285 | 285 | $field_settings = $messenger->get_template_fields(); |
| 286 | 286 | $localized = array(); |
| 287 | 287 | foreach ($valid_shortcodes as $field => $shortcodes) { |
| 288 | 288 | // get localized field label |
| 289 | - if (isset($field_settings[ $field ])) { |
|
| 289 | + if (isset($field_settings[$field])) { |
|
| 290 | 290 | // possible that this is used as a main field. |
| 291 | - if (empty($field_settings[ $field ])) { |
|
| 292 | - if (isset($field_settings['extra'][ $field ])) { |
|
| 293 | - $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
| 291 | + if (empty($field_settings[$field])) { |
|
| 292 | + if (isset($field_settings['extra'][$field])) { |
|
| 293 | + $_field = $field_settings['extra'][$field]['main']['label']; |
|
| 294 | 294 | } else { |
| 295 | 295 | $_field = $field; |
| 296 | 296 | } |
| 297 | 297 | } else { |
| 298 | - $_field = $field_settings[ $field ]['label']; |
|
| 298 | + $_field = $field_settings[$field]['label']; |
|
| 299 | 299 | } |
| 300 | 300 | } elseif (isset($field_settings['extra'])) { |
| 301 | 301 | // loop through extra "main fields" and see if any of their children have our field |
| 302 | 302 | foreach ($field_settings['extra'] as $fields) { |
| 303 | - if (isset($fields[ $field ])) { |
|
| 304 | - $_field = $fields[ $field ]['label']; |
|
| 303 | + if (isset($fields[$field])) { |
|
| 304 | + $_field = $fields[$field]['label']; |
|
| 305 | 305 | } else { |
| 306 | 306 | $_field = $field; |
| 307 | 307 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | $_field = $field; |
| 311 | 311 | } |
| 312 | 312 | if (isset($_field)) { |
| 313 | - $localized[ (string) $_field ] = $shortcodes; |
|
| 313 | + $localized[(string) $_field] = $shortcodes; |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | $valid_shortcodes = $localized; |
@@ -321,10 +321,10 @@ discard block |
||
| 321 | 321 | $merged_codes = array(); |
| 322 | 322 | foreach ($valid_shortcodes as $shortcode) { |
| 323 | 323 | foreach ($shortcode as $code => $label) { |
| 324 | - if (isset($merged_codes[ $code ])) { |
|
| 324 | + if (isset($merged_codes[$code])) { |
|
| 325 | 325 | continue; |
| 326 | 326 | } else { |
| 327 | - $merged_codes[ $code ] = $label; |
|
| 327 | + $merged_codes[$code] = $label; |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | } |
@@ -475,12 +475,12 @@ discard block |
||
| 475 | 475 | $sending_messenger = '' |
| 476 | 476 | ) { |
| 477 | 477 | // first determine if the url can be to the EE_Message object. |
| 478 | - if (! $message_type->always_generate()) { |
|
| 478 | + if ( ! $message_type->always_generate()) { |
|
| 479 | 479 | return EEH_MSG_Template::generate_browser_trigger($message); |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | // if $registration object is not valid then exit early because there's nothing that can be generated. |
| 483 | - if (! $registration instanceof EE_Registration) { |
|
| 483 | + if ( ! $registration instanceof EE_Registration) { |
|
| 484 | 484 | throw new EE_Error( |
| 485 | 485 | esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
| 486 | 486 | ); |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | |
| 489 | 489 | // validate given context |
| 490 | 490 | $contexts = $message_type->get_contexts(); |
| 491 | - if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
| 491 | + if ($message->context() !== '' && ! isset($contexts[$message->context()])) { |
|
| 492 | 492 | throw new EE_Error( |
| 493 | 493 | sprintf( |
| 494 | 494 | esc_html__('The context %s is not a valid context for %s.', 'event_espresso'), |
@@ -499,11 +499,11 @@ discard block |
||
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
| 502 | - if (! empty($sending_messenger)) { |
|
| 502 | + if ( ! empty($sending_messenger)) { |
|
| 503 | 503 | $with_messengers = $message_type->with_messengers(); |
| 504 | 504 | if ( |
| 505 | - ! isset($with_messengers[ $message->messenger() ]) |
|
| 506 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) |
|
| 505 | + ! isset($with_messengers[$message->messenger()]) |
|
| 506 | + || ! in_array($sending_messenger, $with_messengers[$message->messenger()]) |
|
| 507 | 507 | ) { |
| 508 | 508 | throw new EE_Error( |
| 509 | 509 | sprintf( |
@@ -636,7 +636,7 @@ discard block |
||
| 636 | 636 | public static function get_message_action_icon($type) |
| 637 | 637 | { |
| 638 | 638 | $action_icons = self::get_message_action_icons(); |
| 639 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : []; |
|
| 639 | + return isset($action_icons[$type]) ? $action_icons[$type] : []; |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
| 702 | 702 | { |
| 703 | 703 | $action_urls = self::get_message_action_urls($message, $query_params); |
| 704 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
| 704 | + return isset($action_urls[$type]) ? $action_urls[$type] : ''; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | EE_Registry::instance()->load_helper('URL'); |
| 723 | 723 | // if $message is not an instance of EE_Message then let's just do a dummy. |
| 724 | 724 | $message = empty($message) ? EE_Message_Factory::create() : $message; |
| 725 | - $action_urls = apply_filters( |
|
| 725 | + $action_urls = apply_filters( |
|
| 726 | 726 | 'FHEE__EEH_MSG_Template__get_message_action_url', |
| 727 | 727 | array( |
| 728 | 728 | 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
| 807 | 807 | $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
| 808 | 808 | $label = $icon_css['label'] ?? null; |
| 809 | - $label = $label ? 'aria-label="' . $label . '"' : ''; |
|
| 809 | + $label = $label ? 'aria-label="'.$label.'"' : ''; |
|
| 810 | 810 | $class = $label ? ' ee-aria-tooltip' : ''; |
| 811 | 811 | |
| 812 | 812 | if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | $icon_css['css_class'] .= esc_attr( |
| 817 | 817 | apply_filters( |
| 818 | 818 | 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
| 819 | - ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
| 819 | + ' js-ee-message-action-link ee-message-action-link-'.$type, |
|
| 820 | 820 | $type, |
| 821 | 821 | $message, |
| 822 | 822 | $query_params |
@@ -824,8 +824,8 @@ discard block |
||
| 824 | 824 | ); |
| 825 | 825 | |
| 826 | 826 | return ' |
| 827 | - <a href="' . $url . '" ' . $label . ' class="button button--small button--icon-only' . $class . '"> |
|
| 828 | - <span class="' . esc_attr($icon_css['css_class']) . '"></span> |
|
| 827 | + <a href="' . $url.'" '.$label.' class="button button--small button--icon-only'.$class.'"> |
|
| 828 | + <span class="' . esc_attr($icon_css['css_class']).'"></span> |
|
| 829 | 829 | </a>'; |
| 830 | 830 | } |
| 831 | 831 | |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | public static function convert_reg_status_to_message_type($reg_status) |
| 868 | 868 | { |
| 869 | 869 | $reg_status_array = self::reg_status_to_message_type_array(); |
| 870 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
| 870 | + return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : ''; |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | public static function convert_payment_status_to_message_type($payment_status) |
| 906 | 906 | { |
| 907 | 907 | $payment_status_array = self::payment_status_to_message_type_array(); |
| 908 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
| 908 | + return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : ''; |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | */ |
| 919 | 919 | public static function get_template_pack($template_pack_name) |
| 920 | 920 | { |
| 921 | - if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 921 | + if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 922 | 922 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
| 923 | 923 | } |
| 924 | 924 | |
@@ -931,14 +931,14 @@ discard block |
||
| 931 | 931 | |
| 932 | 932 | // nope...let's get it. |
| 933 | 933 | // not set yet so let's attempt to get it. |
| 934 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 934 | + $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
| 935 | 935 | ' ', |
| 936 | 936 | '_', |
| 937 | 937 | ucwords( |
| 938 | 938 | str_replace('_', ' ', $template_pack_name) |
| 939 | 939 | ) |
| 940 | 940 | ); |
| 941 | - if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 941 | + if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 942 | 942 | return self::get_template_pack('default'); |
| 943 | 943 | } else { |
| 944 | 944 | $template_pack = new $pack_class_name(); |
@@ -961,18 +961,18 @@ discard block |
||
| 961 | 961 | public static function get_template_pack_collection() |
| 962 | 962 | { |
| 963 | 963 | $new_collection = false; |
| 964 | - if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 964 | + if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 965 | 965 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
| 966 | 966 | $new_collection = true; |
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | // glob the defaults directory for messages |
| 970 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
| 970 | + $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR); |
|
| 971 | 971 | foreach ($templates as $template_path) { |
| 972 | 972 | // grab folder name |
| 973 | 973 | $template = basename($template_path); |
| 974 | 974 | |
| 975 | - if (! $new_collection) { |
|
| 975 | + if ( ! $new_collection) { |
|
| 976 | 976 | // already have it? |
| 977 | 977 | if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
| 978 | 978 | continue; |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | // setup classname. |
| 983 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 983 | + $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
| 984 | 984 | ' ', |
| 985 | 985 | '_', |
| 986 | 986 | ucwords( |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | ) |
| 992 | 992 | ) |
| 993 | 993 | ); |
| 994 | - if (! class_exists($template_pack_class_name)) { |
|
| 994 | + if ( ! class_exists($template_pack_class_name)) { |
|
| 995 | 995 | continue; |
| 996 | 996 | } |
| 997 | 997 | self::$_template_pack_collection->add(new $template_pack_class_name()); |
@@ -1033,7 +1033,7 @@ discard block |
||
| 1033 | 1033 | $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 1034 | 1034 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
| 1035 | 1035 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
| 1036 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1036 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1037 | 1037 | return array(); |
| 1038 | 1038 | } |
| 1039 | 1039 | // whew made it this far! Okay, let's go ahead and create the templates then |
@@ -1053,13 +1053,13 @@ discard block |
||
| 1053 | 1053 | protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
| 1054 | 1054 | { |
| 1055 | 1055 | // if we're creating a custom template then we don't need to use the defaults class |
| 1056 | - if (! $global) { |
|
| 1056 | + if ( ! $global) { |
|
| 1057 | 1057 | return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
| 1058 | 1058 | } |
| 1059 | 1059 | /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
| 1060 | 1060 | $Message_Template_Defaults = EE_Registry::factory( |
| 1061 | 1061 | 'EE_Messages_Template_Defaults', |
| 1062 | - array( $messenger, $message_type, $GRP_ID ) |
|
| 1062 | + array($messenger, $message_type, $GRP_ID) |
|
| 1063 | 1063 | ); |
| 1064 | 1064 | // generate templates |
| 1065 | 1065 | $success = $Message_Template_Defaults->create_new_templates(); |
@@ -1067,7 +1067,7 @@ discard block |
||
| 1067 | 1067 | // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
| 1068 | 1068 | // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
| 1069 | 1069 | // attempts. |
| 1070 | - if (! $success) { |
|
| 1070 | + if ( ! $success) { |
|
| 1071 | 1071 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
| 1072 | 1072 | $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 1073 | 1073 | $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
| 1103 | 1103 | { |
| 1104 | 1104 | // defaults |
| 1105 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
| 1105 | + $success = array('GRP_ID' => null, 'MTP_context' => ''); |
|
| 1106 | 1106 | // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
| 1107 | 1107 | $Message_Template_Group = empty($GRP_ID) |
| 1108 | 1108 | ? EEM_Message_Template_Group::instance()->get_one( |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | ) |
| 1117 | 1117 | : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
| 1118 | 1118 | // if we don't have a mtg at this point then we need to bail. |
| 1119 | - if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1119 | + if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1120 | 1120 | EE_Error::add_error( |
| 1121 | 1121 | sprintf( |
| 1122 | 1122 | esc_html__( |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | $success['template_name'] = $template_name; |
| 1163 | 1163 | // add new message templates and add relation to. |
| 1164 | 1164 | foreach ($message_templates as $message_template) { |
| 1165 | - if (! $message_template instanceof EE_Message_Template) { |
|
| 1165 | + if ( ! $message_template instanceof EE_Message_Template) { |
|
| 1166 | 1166 | continue; |
| 1167 | 1167 | } |
| 1168 | 1168 | $new_message_template = clone $message_template; |
@@ -1241,7 +1241,7 @@ discard block |
||
| 1241 | 1241 | $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 1242 | 1242 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
| 1243 | 1243 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
| 1244 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1244 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1245 | 1245 | return array(); |
| 1246 | 1246 | } |
| 1247 | 1247 | |
@@ -1253,7 +1253,7 @@ discard block |
||
| 1253 | 1253 | if (in_array($field, $excluded_fields_for_messenger, true)) { |
| 1254 | 1254 | continue; |
| 1255 | 1255 | } |
| 1256 | - $template_fields[ $context ][ $field ] = $value; |
|
| 1256 | + $template_fields[$context][$field] = $value; |
|
| 1257 | 1257 | } |
| 1258 | 1258 | } |
| 1259 | 1259 | if (empty($template_fields)) { |
@@ -19,4244 +19,4244 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var EE_Admin_Config |
|
| 24 | - */ |
|
| 25 | - protected $admin_config; |
|
| 22 | + /** |
|
| 23 | + * @var EE_Admin_Config |
|
| 24 | + */ |
|
| 25 | + protected $admin_config; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var LoaderInterface |
|
| 29 | - */ |
|
| 30 | - protected $loader; |
|
| 27 | + /** |
|
| 28 | + * @var LoaderInterface |
|
| 29 | + */ |
|
| 30 | + protected $loader; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var RequestInterface |
|
| 34 | - */ |
|
| 35 | - protected $request; |
|
| 32 | + /** |
|
| 33 | + * @var RequestInterface |
|
| 34 | + */ |
|
| 35 | + protected $request; |
|
| 36 | 36 | |
| 37 | - // set in _init_page_props() |
|
| 38 | - public $page_slug; |
|
| 37 | + // set in _init_page_props() |
|
| 38 | + public $page_slug; |
|
| 39 | 39 | |
| 40 | - public $page_label; |
|
| 40 | + public $page_label; |
|
| 41 | 41 | |
| 42 | - public $page_folder; |
|
| 42 | + public $page_folder; |
|
| 43 | 43 | |
| 44 | - // set in define_page_props() |
|
| 45 | - protected $_admin_base_url; |
|
| 44 | + // set in define_page_props() |
|
| 45 | + protected $_admin_base_url; |
|
| 46 | 46 | |
| 47 | - protected $_admin_base_path; |
|
| 47 | + protected $_admin_base_path; |
|
| 48 | 48 | |
| 49 | - protected $_admin_page_title; |
|
| 49 | + protected $_admin_page_title; |
|
| 50 | 50 | |
| 51 | - protected $_labels; |
|
| 51 | + protected $_labels; |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - // set early within EE_Admin_Init |
|
| 55 | - protected $_wp_page_slug; |
|
| 54 | + // set early within EE_Admin_Init |
|
| 55 | + protected $_wp_page_slug; |
|
| 56 | 56 | |
| 57 | - // nav tabs |
|
| 58 | - protected $_nav_tabs; |
|
| 57 | + // nav tabs |
|
| 58 | + protected $_nav_tabs; |
|
| 59 | 59 | |
| 60 | - protected $_default_nav_tab_name; |
|
| 60 | + protected $_default_nav_tab_name; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @var array $_help_tour |
|
| 64 | - */ |
|
| 65 | - protected $_help_tour = []; |
|
| 62 | + /** |
|
| 63 | + * @var array $_help_tour |
|
| 64 | + */ |
|
| 65 | + protected $_help_tour = []; |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | - // template variables (used by templates) |
|
| 69 | - protected $_template_path; |
|
| 68 | + // template variables (used by templates) |
|
| 69 | + protected $_template_path; |
|
| 70 | 70 | |
| 71 | - protected $_column_template_path; |
|
| 71 | + protected $_column_template_path; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @var array $_template_args |
|
| 75 | - */ |
|
| 76 | - protected $_template_args = []; |
|
| 73 | + /** |
|
| 74 | + * @var array $_template_args |
|
| 75 | + */ |
|
| 76 | + protected $_template_args = []; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * this will hold the list table object for a given view. |
|
| 80 | - * |
|
| 81 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 82 | - */ |
|
| 83 | - protected $_list_table_object; |
|
| 78 | + /** |
|
| 79 | + * this will hold the list table object for a given view. |
|
| 80 | + * |
|
| 81 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 82 | + */ |
|
| 83 | + protected $_list_table_object; |
|
| 84 | 84 | |
| 85 | - // boolean |
|
| 86 | - protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states. |
|
| 85 | + // boolean |
|
| 86 | + protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states. |
|
| 87 | 87 | |
| 88 | - protected $_routing; |
|
| 88 | + protected $_routing; |
|
| 89 | 89 | |
| 90 | - // list table args |
|
| 91 | - protected $_view; |
|
| 90 | + // list table args |
|
| 91 | + protected $_view; |
|
| 92 | 92 | |
| 93 | - protected $_views; |
|
| 93 | + protected $_views; |
|
| 94 | 94 | |
| 95 | 95 | |
| 96 | - // action => method pairs used for routing incoming requests |
|
| 97 | - protected $_page_routes; |
|
| 96 | + // action => method pairs used for routing incoming requests |
|
| 97 | + protected $_page_routes; |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @var array $_page_config |
|
| 101 | - */ |
|
| 102 | - protected $_page_config; |
|
| 99 | + /** |
|
| 100 | + * @var array $_page_config |
|
| 101 | + */ |
|
| 102 | + protected $_page_config; |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * the current page route and route config |
|
| 106 | - * |
|
| 107 | - * @var string $_route |
|
| 108 | - */ |
|
| 109 | - protected $_route; |
|
| 104 | + /** |
|
| 105 | + * the current page route and route config |
|
| 106 | + * |
|
| 107 | + * @var string $_route |
|
| 108 | + */ |
|
| 109 | + protected $_route; |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @var string $_cpt_route |
|
| 113 | - */ |
|
| 114 | - protected $_cpt_route; |
|
| 111 | + /** |
|
| 112 | + * @var string $_cpt_route |
|
| 113 | + */ |
|
| 114 | + protected $_cpt_route; |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * @var array $_route_config |
|
| 118 | - */ |
|
| 119 | - protected $_route_config; |
|
| 116 | + /** |
|
| 117 | + * @var array $_route_config |
|
| 118 | + */ |
|
| 119 | + protected $_route_config; |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 123 | - * actions. |
|
| 124 | - * |
|
| 125 | - * @since 4.6.x |
|
| 126 | - * @var array. |
|
| 127 | - */ |
|
| 128 | - protected $_default_route_query_args; |
|
| 121 | + /** |
|
| 122 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 123 | + * actions. |
|
| 124 | + * |
|
| 125 | + * @since 4.6.x |
|
| 126 | + * @var array. |
|
| 127 | + */ |
|
| 128 | + protected $_default_route_query_args; |
|
| 129 | 129 | |
| 130 | - // set via request page and action args. |
|
| 131 | - protected $_current_page; |
|
| 132 | - |
|
| 133 | - protected $_current_view; |
|
| 130 | + // set via request page and action args. |
|
| 131 | + protected $_current_page; |
|
| 132 | + |
|
| 133 | + protected $_current_view; |
|
| 134 | 134 | |
| 135 | - protected $_current_page_view_url; |
|
| 135 | + protected $_current_page_view_url; |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * unprocessed value for the 'action' request param (default '') |
|
| 139 | - * |
|
| 140 | - * @var string |
|
| 141 | - */ |
|
| 142 | - protected $raw_req_action = ''; |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * unprocessed value for the 'page' request param (default '') |
|
| 146 | - * |
|
| 147 | - * @var string |
|
| 148 | - */ |
|
| 149 | - protected $raw_req_page = ''; |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * sanitized request action (and nonce) |
|
| 153 | - * |
|
| 154 | - * @var string |
|
| 155 | - */ |
|
| 156 | - protected $_req_action = ''; |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * sanitized request action nonce |
|
| 160 | - * |
|
| 161 | - * @var string |
|
| 162 | - */ |
|
| 163 | - protected $_req_nonce = ''; |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @var string |
|
| 167 | - */ |
|
| 168 | - protected $_search_btn_label = ''; |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @var string |
|
| 172 | - */ |
|
| 173 | - protected $_search_box_callback = ''; |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @var WP_Screen |
|
| 177 | - */ |
|
| 178 | - protected $_current_screen; |
|
| 179 | - |
|
| 180 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 181 | - protected $_hook_obj; |
|
| 182 | - |
|
| 183 | - // for holding incoming request data |
|
| 184 | - protected $_req_data = []; |
|
| 185 | - |
|
| 186 | - // yes / no array for admin form fields |
|
| 187 | - protected $_yes_no_values = []; |
|
| 188 | - |
|
| 189 | - // some default things shared by all child classes |
|
| 190 | - protected $_default_espresso_metaboxes; |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * @var EE_Registry |
|
| 194 | - */ |
|
| 195 | - protected $EE; |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 200 | - * |
|
| 201 | - * @var boolean |
|
| 202 | - */ |
|
| 203 | - protected $_is_caf = false; |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * whether or not initializePage() has run |
|
| 207 | - * |
|
| 208 | - * @var boolean |
|
| 209 | - */ |
|
| 210 | - protected $initialized = false; |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @var FeatureFlags |
|
| 214 | - */ |
|
| 215 | - protected $feature; |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * @Constructor |
|
| 220 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 221 | - * @throws InvalidArgumentException |
|
| 222 | - * @throws InvalidDataTypeException |
|
| 223 | - * @throws InvalidInterfaceException |
|
| 224 | - * @throws ReflectionException |
|
| 225 | - */ |
|
| 226 | - public function __construct($routing = true) |
|
| 227 | - { |
|
| 228 | - $this->loader = LoaderFactory::getLoader(); |
|
| 229 | - $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 230 | - $this->feature = $this->loader->getShared(FeatureFlags::class); |
|
| 231 | - $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 232 | - // routing enabled? |
|
| 233 | - $this->_routing = $routing; |
|
| 234 | - |
|
| 235 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 236 | - $this->_is_caf = true; |
|
| 237 | - } |
|
| 238 | - $this->_yes_no_values = [ |
|
| 239 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 240 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 241 | - ]; |
|
| 242 | - // set the _req_data property. |
|
| 243 | - $this->_req_data = $this->request->requestParams(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * @return EE_Admin_Config |
|
| 249 | - */ |
|
| 250 | - public function adminConfig(): EE_Admin_Config |
|
| 251 | - { |
|
| 252 | - return $this->admin_config; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @return FeatureFlags |
|
| 258 | - */ |
|
| 259 | - public function feature(): FeatureFlags |
|
| 260 | - { |
|
| 261 | - return $this->feature; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * This logic used to be in the constructor, but that caused a chicken <--> egg scenario |
|
| 267 | - * for child classes that needed to set properties prior to these methods getting called, |
|
| 268 | - * but also needed the parent class to have its construction completed as well. |
|
| 269 | - * Bottom line is that constructors should ONLY be used for setting initial properties |
|
| 270 | - * and any complex initialization logic should only run after instantiation is complete. |
|
| 271 | - * |
|
| 272 | - * This method gets called immediately after construction from within |
|
| 273 | - * EE_Admin_Page_Init::_initialize_admin_page() |
|
| 274 | - * |
|
| 275 | - * @throws EE_Error |
|
| 276 | - * @throws InvalidArgumentException |
|
| 277 | - * @throws InvalidDataTypeException |
|
| 278 | - * @throws InvalidInterfaceException |
|
| 279 | - * @throws ReflectionException |
|
| 280 | - * @since $VID:$ |
|
| 281 | - */ |
|
| 282 | - public function initializePage() |
|
| 283 | - { |
|
| 284 | - if ($this->initialized) { |
|
| 285 | - return; |
|
| 286 | - } |
|
| 287 | - // set initial page props (child method) |
|
| 288 | - $this->_init_page_props(); |
|
| 289 | - // set global defaults |
|
| 290 | - $this->_set_defaults(); |
|
| 291 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 292 | - $this->_global_ajax_hooks(); |
|
| 293 | - $this->_ajax_hooks(); |
|
| 294 | - // other_page_hooks have to be early too. |
|
| 295 | - $this->_do_other_page_hooks(); |
|
| 296 | - // set up page dependencies |
|
| 297 | - $this->_before_page_setup(); |
|
| 298 | - $this->_page_setup(); |
|
| 299 | - $this->initialized = true; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * _init_page_props |
|
| 305 | - * Child classes use to set at least the following properties: |
|
| 306 | - * $page_slug. |
|
| 307 | - * $page_label. |
|
| 308 | - * |
|
| 309 | - * @abstract |
|
| 310 | - * @return void |
|
| 311 | - */ |
|
| 312 | - abstract protected function _init_page_props(); |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * _ajax_hooks |
|
| 317 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 318 | - * Note: within the ajax callback methods. |
|
| 319 | - * |
|
| 320 | - * @abstract |
|
| 321 | - * @return void |
|
| 322 | - */ |
|
| 323 | - abstract protected function _ajax_hooks(); |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * _define_page_props |
|
| 328 | - * child classes define page properties in here. Must include at least: |
|
| 329 | - * $_admin_base_url = base_url for all admin pages |
|
| 330 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 331 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 332 | - * array( |
|
| 333 | - * 'buttons' => array( |
|
| 334 | - * 'add' => esc_html__('label for add new button'), |
|
| 335 | - * 'edit' => esc_html__('label for edit button'), |
|
| 336 | - * 'delete' => esc_html__('label for delete button') |
|
| 337 | - * ) |
|
| 338 | - * ) |
|
| 339 | - * |
|
| 340 | - * @abstract |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - abstract protected function _define_page_props(); |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * _set_page_routes |
|
| 348 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 349 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 350 | - * have a 'default' route. Here's the format |
|
| 351 | - * $this->_page_routes = array( |
|
| 352 | - * 'default' => array( |
|
| 353 | - * 'func' => '_default_method_handling_route', |
|
| 354 | - * 'args' => array('array','of','args'), |
|
| 355 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 356 | - * ajax request, backend processing) |
|
| 357 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 358 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 359 | - * headers sent route. |
|
| 360 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 361 | - * this route. |
|
| 362 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 363 | - * checks). |
|
| 364 | - * ), |
|
| 365 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 366 | - * handling method. |
|
| 367 | - * ) |
|
| 368 | - * ) |
|
| 369 | - * |
|
| 370 | - * @abstract |
|
| 371 | - * @return void |
|
| 372 | - */ |
|
| 373 | - abstract protected function _set_page_routes(); |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * _set_page_config |
|
| 378 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 379 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 380 | - * $this->_page_config = array( |
|
| 381 | - * 'default' => array( |
|
| 382 | - * 'labels' => array( |
|
| 383 | - * 'buttons' => array( |
|
| 384 | - * 'add' => esc_html__('label for adding item'), |
|
| 385 | - * 'edit' => esc_html__('label for editing item'), |
|
| 386 | - * 'delete' => esc_html__('label for deleting item') |
|
| 387 | - * ), |
|
| 388 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 389 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 390 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 391 | - * _define_page_props() method |
|
| 392 | - * 'nav' => array( |
|
| 393 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 394 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 395 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 396 | - * 'order' => 10, //required to indicate tab position. |
|
| 397 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 398 | - * displayed then add this parameter. |
|
| 399 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 400 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 401 | - * metaboxes set for eventespresso admin pages. |
|
| 402 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 403 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 404 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 405 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 406 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 407 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 408 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 409 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 410 | - * want to display. |
|
| 411 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 412 | - * 'tab_id' => array( |
|
| 413 | - * 'title' => 'tab_title', |
|
| 414 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 415 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 416 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 417 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 418 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 419 | - * attempt to use the callback which should match the name of a method in the class |
|
| 420 | - * ), |
|
| 421 | - * 'tab2_id' => array( |
|
| 422 | - * 'title' => 'tab2 title', |
|
| 423 | - * 'filename' => 'file_name_2' |
|
| 424 | - * 'callback' => 'callback_method_for_content', |
|
| 425 | - * ), |
|
| 426 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 427 | - * help tab area on an admin page. @return void |
|
| 428 | - * |
|
| 429 | - * @link |
|
| 430 | - * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 431 | - * 'help_tour' => array( |
|
| 432 | - * 'name_of_help_tour_class', //all help tours should be a child class of EE_Help_Tour and located |
|
| 433 | - * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 434 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 435 | - * ), |
|
| 436 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default |
|
| 437 | - * is true if it isn't present). To remove the requirement for a nonce check when this route is |
|
| 438 | - * visited just set |
|
| 439 | - * 'require_nonce' to FALSE |
|
| 440 | - * ) |
|
| 441 | - * ) |
|
| 442 | - * |
|
| 443 | - * @abstract |
|
| 444 | - */ |
|
| 445 | - abstract protected function _set_page_config(); |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** end sample help_tour methods **/ |
|
| 452 | - /** |
|
| 453 | - * _add_screen_options |
|
| 454 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 455 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 456 | - * to a particular view. |
|
| 457 | - * |
|
| 458 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 459 | - * see also WP_Screen object documents... |
|
| 460 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 461 | - * @abstract |
|
| 462 | - * @return void |
|
| 463 | - */ |
|
| 464 | - abstract protected function _add_screen_options(); |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * _add_feature_pointers |
|
| 469 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 470 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 471 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 472 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 473 | - * extended) also see: |
|
| 474 | - * |
|
| 475 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 476 | - * @abstract |
|
| 477 | - * @return void |
|
| 478 | - */ |
|
| 479 | - abstract protected function _add_feature_pointers(); |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * load_scripts_styles |
|
| 484 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 485 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 486 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 487 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 488 | - * |
|
| 489 | - * @abstract |
|
| 490 | - * @return void |
|
| 491 | - */ |
|
| 492 | - abstract public function load_scripts_styles(); |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * admin_init |
|
| 497 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 498 | - * all pages/views loaded by child class. |
|
| 499 | - * |
|
| 500 | - * @abstract |
|
| 501 | - * @return void |
|
| 502 | - */ |
|
| 503 | - abstract public function admin_init(); |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * admin_notices |
|
| 508 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 509 | - * all pages/views loaded by child class. |
|
| 510 | - * |
|
| 511 | - * @abstract |
|
| 512 | - * @return void |
|
| 513 | - */ |
|
| 514 | - abstract public function admin_notices(); |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * admin_footer_scripts |
|
| 519 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 520 | - * will apply to all pages/views loaded by child class. |
|
| 521 | - * |
|
| 522 | - * @return void |
|
| 523 | - */ |
|
| 524 | - abstract public function admin_footer_scripts(); |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * admin_footer |
|
| 529 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 530 | - * apply to all pages/views loaded by child class. |
|
| 531 | - * |
|
| 532 | - * @return void |
|
| 533 | - */ |
|
| 534 | - public function admin_footer() |
|
| 535 | - { |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * _global_ajax_hooks |
|
| 541 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 542 | - * Note: within the ajax callback methods. |
|
| 543 | - * |
|
| 544 | - * @abstract |
|
| 545 | - * @return void |
|
| 546 | - */ |
|
| 547 | - protected function _global_ajax_hooks() |
|
| 548 | - { |
|
| 549 | - // for lazy loading of metabox content |
|
| 550 | - add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 551 | - |
|
| 552 | - add_action( |
|
| 553 | - 'wp_ajax_espresso_hide_status_change_notice', |
|
| 554 | - [$this, 'hideStatusChangeNotice'] |
|
| 555 | - ); |
|
| 556 | - add_action( |
|
| 557 | - 'wp_ajax_nopriv_espresso_hide_status_change_notice', |
|
| 558 | - [$this, 'hideStatusChangeNotice'] |
|
| 559 | - ); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - public function ajax_metabox_content() |
|
| 564 | - { |
|
| 565 | - $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 566 | - $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 567 | - EE_Admin_Page::cached_rss_display($content_id, $content_url); |
|
| 568 | - wp_die(); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - public function hideStatusChangeNotice() |
|
| 573 | - { |
|
| 574 | - $response = []; |
|
| 575 | - try { |
|
| 576 | - /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
|
| 577 | - $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
|
| 578 | - $response['success'] = $status_change_notice->dismiss() > -1; |
|
| 579 | - } catch (Exception $exception) { |
|
| 580 | - $response['errors'] = $exception->getMessage(); |
|
| 581 | - } |
|
| 582 | - echo wp_json_encode($response); |
|
| 583 | - exit(); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 589 | - * |
|
| 590 | - * @return void |
|
| 591 | - */ |
|
| 592 | - protected function _before_page_setup() |
|
| 593 | - { |
|
| 594 | - // default is to do nothing |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * Makes sure any things that need to be loaded early get handled. |
|
| 600 | - * We also escape early here if the page requested doesn't match the object. |
|
| 601 | - * |
|
| 602 | - * @final |
|
| 603 | - * @return void |
|
| 604 | - * @throws EE_Error |
|
| 605 | - * @throws InvalidArgumentException |
|
| 606 | - * @throws ReflectionException |
|
| 607 | - * @throws InvalidDataTypeException |
|
| 608 | - * @throws InvalidInterfaceException |
|
| 609 | - */ |
|
| 610 | - final protected function _page_setup() |
|
| 611 | - { |
|
| 612 | - // requires? |
|
| 613 | - // admin_init stuff - global - we're setting this REALLY early |
|
| 614 | - // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 615 | - // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 616 | - add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 617 | - // next verify if we need to load anything... |
|
| 618 | - $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 619 | - $this->page_folder = strtolower( |
|
| 620 | - str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
| 621 | - ); |
|
| 622 | - global $ee_menu_slugs; |
|
| 623 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 624 | - if ( |
|
| 625 | - ! $this->request->isAjax() |
|
| 626 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 627 | - ) { |
|
| 628 | - return; |
|
| 629 | - } |
|
| 630 | - // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 631 | - // we need to copy the action from the second to the first |
|
| 632 | - $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 633 | - $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 634 | - $action = $action !== '-1' ? $action : $action2; |
|
| 635 | - $req_action = $action !== '-1' ? $action : 'default'; |
|
| 636 | - |
|
| 637 | - // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 638 | - // then let's use the route as the action. |
|
| 639 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 640 | - $route = $this->request->getRequestParam('route'); |
|
| 641 | - $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 642 | - ? $route |
|
| 643 | - : $req_action; |
|
| 644 | - |
|
| 645 | - $this->_current_view = $this->_req_action; |
|
| 646 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 647 | - $this->_define_page_props(); |
|
| 648 | - $this->_current_page_view_url = add_query_arg( |
|
| 649 | - ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 650 | - $this->_admin_base_url |
|
| 651 | - ); |
|
| 652 | - // default things |
|
| 653 | - $this->_default_espresso_metaboxes = [ |
|
| 654 | - '_espresso_news_post_box', |
|
| 655 | - '_espresso_links_post_box', |
|
| 656 | - '_espresso_ratings_request', |
|
| 657 | - '_espresso_sponsors_post_box', |
|
| 658 | - ]; |
|
| 659 | - // set page configs |
|
| 660 | - $this->_set_page_routes(); |
|
| 661 | - $this->_set_page_config(); |
|
| 662 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 663 | - if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 664 | - $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 665 | - if ($wp_referer) { |
|
| 666 | - $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - // for caffeinated and other extended functionality. |
|
| 670 | - // If there is a _extend_page_config method |
|
| 671 | - // then let's run that to modify the all the various page configuration arrays |
|
| 672 | - if (method_exists($this, '_extend_page_config')) { |
|
| 673 | - $this->_extend_page_config(); |
|
| 674 | - } |
|
| 675 | - // for CPT and other extended functionality. |
|
| 676 | - // If there is an _extend_page_config_for_cpt |
|
| 677 | - // then let's run that to modify all the various page configuration arrays. |
|
| 678 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 679 | - $this->_extend_page_config_for_cpt(); |
|
| 680 | - } |
|
| 681 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 682 | - $this->_page_routes = apply_filters( |
|
| 683 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 684 | - $this->_page_routes, |
|
| 685 | - $this |
|
| 686 | - ); |
|
| 687 | - $this->_page_config = apply_filters( |
|
| 688 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 689 | - $this->_page_config, |
|
| 690 | - $this |
|
| 691 | - ); |
|
| 692 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 693 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 694 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 695 | - add_action( |
|
| 696 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 697 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 698 | - 10, |
|
| 699 | - 2 |
|
| 700 | - ); |
|
| 701 | - } |
|
| 702 | - // next route only if routing enabled |
|
| 703 | - if ($this->_routing && ! $this->request->isAjax()) { |
|
| 704 | - $this->_verify_routes(); |
|
| 705 | - // next let's just check user_access and kill if no access |
|
| 706 | - $this->check_user_access(); |
|
| 707 | - if ($this->_is_UI_request) { |
|
| 708 | - // admin_init stuff - global, all views for this page class, specific view |
|
| 709 | - add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 710 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 711 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 712 | - } |
|
| 713 | - } else { |
|
| 714 | - // hijack regular WP loading and route admin request immediately |
|
| 715 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 716 | - $this->route_admin_request(); |
|
| 717 | - } |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 724 | - * |
|
| 725 | - * @return void |
|
| 726 | - * @throws EE_Error |
|
| 727 | - */ |
|
| 728 | - private function _do_other_page_hooks() |
|
| 729 | - { |
|
| 730 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 731 | - foreach ($registered_pages as $page) { |
|
| 732 | - // now let's setup the file name and class that should be present |
|
| 733 | - $classname = str_replace('.class.php', '', $page); |
|
| 734 | - // autoloaders should take care of loading file |
|
| 735 | - if (! class_exists($classname)) { |
|
| 736 | - $error_msg[] = sprintf( |
|
| 737 | - esc_html__( |
|
| 738 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 739 | - 'event_espresso' |
|
| 740 | - ), |
|
| 741 | - $page |
|
| 742 | - ); |
|
| 743 | - $error_msg[] = $error_msg[0] |
|
| 744 | - . "\r\n" |
|
| 745 | - . sprintf( |
|
| 746 | - esc_html__( |
|
| 747 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 748 | - 'event_espresso' |
|
| 749 | - ), |
|
| 750 | - $page, |
|
| 751 | - '<br />', |
|
| 752 | - '<strong>' . $classname . '</strong>' |
|
| 753 | - ); |
|
| 754 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 755 | - } |
|
| 756 | - // notice we are passing the instance of this class to the hook object. |
|
| 757 | - $this->loader->getShared($classname, [$this]); |
|
| 758 | - } |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * @throws ReflectionException |
|
| 764 | - * @throws EE_Error |
|
| 765 | - */ |
|
| 766 | - public function load_page_dependencies() |
|
| 767 | - { |
|
| 768 | - try { |
|
| 769 | - $this->_load_page_dependencies(); |
|
| 770 | - } catch (EE_Error $e) { |
|
| 771 | - $e->get_error(); |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * load_page_dependencies |
|
| 778 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 779 | - * |
|
| 780 | - * @return void |
|
| 781 | - * @throws DomainException |
|
| 782 | - * @throws EE_Error |
|
| 783 | - * @throws InvalidArgumentException |
|
| 784 | - * @throws InvalidDataTypeException |
|
| 785 | - * @throws InvalidInterfaceException |
|
| 786 | - */ |
|
| 787 | - protected function _load_page_dependencies() |
|
| 788 | - { |
|
| 789 | - // let's set the current_screen and screen options to override what WP set |
|
| 790 | - $this->_current_screen = get_current_screen(); |
|
| 791 | - // load admin_notices - global, page class, and view specific |
|
| 792 | - add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 793 | - add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 794 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 795 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 796 | - } |
|
| 797 | - // load network admin_notices - global, page class, and view specific |
|
| 798 | - add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 799 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 800 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 801 | - } |
|
| 802 | - // this will save any per_page screen options if they are present |
|
| 803 | - $this->_set_per_page_screen_options(); |
|
| 804 | - // setup list table properties |
|
| 805 | - $this->_set_list_table(); |
|
| 806 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 807 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 808 | - $this->_add_registered_meta_boxes(); |
|
| 809 | - $this->_add_screen_columns(); |
|
| 810 | - // add screen options - global, page child class, and view specific |
|
| 811 | - $this->_add_global_screen_options(); |
|
| 812 | - $this->_add_screen_options(); |
|
| 813 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 814 | - if (method_exists($this, $add_screen_options)) { |
|
| 815 | - $this->{$add_screen_options}(); |
|
| 816 | - } |
|
| 817 | - // add help tab(s) and tours- set via page_config and qtips. |
|
| 818 | - // $this->_add_help_tour(); |
|
| 819 | - $this->_add_help_tabs(); |
|
| 820 | - $this->_add_qtips(); |
|
| 821 | - // add feature_pointers - global, page child class, and view specific |
|
| 822 | - $this->_add_feature_pointers(); |
|
| 823 | - $this->_add_global_feature_pointers(); |
|
| 824 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 825 | - if (method_exists($this, $add_feature_pointer)) { |
|
| 826 | - $this->{$add_feature_pointer}(); |
|
| 827 | - } |
|
| 828 | - // enqueue scripts/styles - global, page class, and view specific |
|
| 829 | - add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 830 | - add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 831 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 832 | - add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 833 | - } |
|
| 834 | - add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 835 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 836 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 837 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 838 | - // is a good use case. Notice the late priority we're giving these |
|
| 839 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 840 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 841 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 842 | - add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 843 | - } |
|
| 844 | - // admin footer scripts |
|
| 845 | - add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 846 | - add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 847 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 848 | - add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 849 | - } |
|
| 850 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 851 | - // targeted hook |
|
| 852 | - do_action( |
|
| 853 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 854 | - ); |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * _set_defaults |
|
| 860 | - * This sets some global defaults for class properties. |
|
| 861 | - */ |
|
| 862 | - private function _set_defaults() |
|
| 863 | - { |
|
| 864 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 865 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 866 | - $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 867 | - $this->_page_config = $this->_default_route_query_args = []; |
|
| 868 | - $this->_default_nav_tab_name = 'overview'; |
|
| 869 | - // init template args |
|
| 870 | - $this->_template_args = [ |
|
| 871 | - 'admin_page_header' => '', |
|
| 872 | - 'admin_page_content' => '', |
|
| 873 | - 'post_body_content' => '', |
|
| 874 | - 'before_list_table' => '', |
|
| 875 | - 'after_list_table' => '', |
|
| 876 | - ]; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * route_admin_request |
|
| 882 | - * |
|
| 883 | - * @return void |
|
| 884 | - * @throws InvalidArgumentException |
|
| 885 | - * @throws InvalidInterfaceException |
|
| 886 | - * @throws InvalidDataTypeException |
|
| 887 | - * @throws EE_Error |
|
| 888 | - * @throws ReflectionException |
|
| 889 | - * @see _route_admin_request() |
|
| 890 | - */ |
|
| 891 | - public function route_admin_request() |
|
| 892 | - { |
|
| 893 | - try { |
|
| 894 | - $this->_route_admin_request(); |
|
| 895 | - } catch (EE_Error $e) { |
|
| 896 | - $e->get_error(); |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - |
|
| 901 | - public function set_wp_page_slug($wp_page_slug) |
|
| 902 | - { |
|
| 903 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 904 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 905 | - if (is_network_admin()) { |
|
| 906 | - $this->_wp_page_slug .= '-network'; |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - |
|
| 911 | - /** |
|
| 912 | - * _verify_routes |
|
| 913 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 914 | - * we know if we need to drop out. |
|
| 915 | - * |
|
| 916 | - * @return bool |
|
| 917 | - * @throws EE_Error |
|
| 918 | - */ |
|
| 919 | - protected function _verify_routes() |
|
| 920 | - { |
|
| 921 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 922 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 923 | - return false; |
|
| 924 | - } |
|
| 925 | - $this->_route = false; |
|
| 926 | - // check that the page_routes array is not empty |
|
| 927 | - if (empty($this->_page_routes)) { |
|
| 928 | - // user error msg |
|
| 929 | - $error_msg = sprintf( |
|
| 930 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 931 | - $this->_admin_page_title |
|
| 932 | - ); |
|
| 933 | - // developer error msg |
|
| 934 | - $error_msg .= '||' . $error_msg |
|
| 935 | - . esc_html__( |
|
| 936 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 937 | - 'event_espresso' |
|
| 938 | - ); |
|
| 939 | - throw new EE_Error($error_msg); |
|
| 940 | - } |
|
| 941 | - // and that the requested page route exists |
|
| 942 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 943 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 944 | - $this->_route_config = $this->_page_config[ $this->_req_action ] ?? []; |
|
| 945 | - } else { |
|
| 946 | - // user error msg |
|
| 947 | - $error_msg = sprintf( |
|
| 948 | - esc_html__( |
|
| 949 | - 'The requested page route does not exist for the %s admin page.', |
|
| 950 | - 'event_espresso' |
|
| 951 | - ), |
|
| 952 | - $this->_admin_page_title |
|
| 953 | - ); |
|
| 954 | - // developer error msg |
|
| 955 | - $error_msg .= '||' . $error_msg |
|
| 956 | - . sprintf( |
|
| 957 | - esc_html__( |
|
| 958 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 959 | - 'event_espresso' |
|
| 960 | - ), |
|
| 961 | - $this->_req_action |
|
| 962 | - ); |
|
| 963 | - throw new EE_Error($error_msg); |
|
| 964 | - } |
|
| 965 | - // and that a default route exists |
|
| 966 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 967 | - // user error msg |
|
| 968 | - $error_msg = sprintf( |
|
| 969 | - esc_html__( |
|
| 970 | - 'A default page route has not been set for the % admin page.', |
|
| 971 | - 'event_espresso' |
|
| 972 | - ), |
|
| 973 | - $this->_admin_page_title |
|
| 974 | - ); |
|
| 975 | - // developer error msg |
|
| 976 | - $error_msg .= '||' . $error_msg |
|
| 977 | - . esc_html__( |
|
| 978 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 979 | - 'event_espresso' |
|
| 980 | - ); |
|
| 981 | - throw new EE_Error($error_msg); |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - // first lets' catch if the UI request has EVER been set. |
|
| 985 | - if ($this->_is_UI_request === null) { |
|
| 986 | - // lets set if this is a UI request or not. |
|
| 987 | - $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 988 | - // wait a minute... we might have a noheader in the route array |
|
| 989 | - $this->_is_UI_request = ! ( |
|
| 990 | - is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 991 | - ) |
|
| 992 | - ? $this->_is_UI_request |
|
| 993 | - : false; |
|
| 994 | - } |
|
| 995 | - $this->_set_current_labels(); |
|
| 996 | - return true; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - |
|
| 1000 | - /** |
|
| 1001 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 1002 | - * |
|
| 1003 | - * @param string $route the route name we're verifying |
|
| 1004 | - * @return bool we'll throw an exception if this isn't a valid route. |
|
| 1005 | - * @throws EE_Error |
|
| 1006 | - */ |
|
| 1007 | - protected function _verify_route($route) |
|
| 1008 | - { |
|
| 1009 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 1010 | - return true; |
|
| 1011 | - } |
|
| 1012 | - // user error msg |
|
| 1013 | - $error_msg = sprintf( |
|
| 1014 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 1015 | - $this->_admin_page_title |
|
| 1016 | - ); |
|
| 1017 | - // developer error msg |
|
| 1018 | - $error_msg .= '||' . $error_msg |
|
| 1019 | - . sprintf( |
|
| 1020 | - esc_html__( |
|
| 1021 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 1022 | - 'event_espresso' |
|
| 1023 | - ), |
|
| 1024 | - $route |
|
| 1025 | - ); |
|
| 1026 | - throw new EE_Error($error_msg); |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * perform nonce verification |
|
| 1032 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 1033 | - * using this method (and save retyping!) |
|
| 1034 | - * |
|
| 1035 | - * @param string $nonce The nonce sent |
|
| 1036 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 1037 | - * @return void |
|
| 1038 | - * @throws EE_Error |
|
| 1039 | - * @throws InvalidArgumentException |
|
| 1040 | - * @throws InvalidDataTypeException |
|
| 1041 | - * @throws InvalidInterfaceException |
|
| 1042 | - */ |
|
| 1043 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 1044 | - { |
|
| 1045 | - // verify nonce against expected value |
|
| 1046 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1047 | - // these are not the droids you are looking for !!! |
|
| 1048 | - $msg = sprintf( |
|
| 1049 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 1050 | - '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 1051 | - '</a>' |
|
| 1052 | - ); |
|
| 1053 | - if (WP_DEBUG) { |
|
| 1054 | - $msg .= "\n "; |
|
| 1055 | - $msg .= sprintf( |
|
| 1056 | - esc_html__( |
|
| 1057 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 1058 | - 'event_espresso' |
|
| 1059 | - ), |
|
| 1060 | - __CLASS__ |
|
| 1061 | - ); |
|
| 1062 | - } |
|
| 1063 | - if (! $this->request->isAjax()) { |
|
| 1064 | - wp_die($msg); |
|
| 1065 | - } |
|
| 1066 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1067 | - $this->_return_json(); |
|
| 1068 | - } |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - |
|
| 1072 | - /** |
|
| 1073 | - * _route_admin_request() |
|
| 1074 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if there are |
|
| 1075 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 1076 | - * in the page routes and then will try to load the corresponding method. |
|
| 1077 | - * |
|
| 1078 | - * @return void |
|
| 1079 | - * @throws EE_Error |
|
| 1080 | - * @throws InvalidArgumentException |
|
| 1081 | - * @throws InvalidDataTypeException |
|
| 1082 | - * @throws InvalidInterfaceException |
|
| 1083 | - * @throws ReflectionException |
|
| 1084 | - */ |
|
| 1085 | - protected function _route_admin_request() |
|
| 1086 | - { |
|
| 1087 | - if (! $this->_is_UI_request) { |
|
| 1088 | - $this->_verify_routes(); |
|
| 1089 | - } |
|
| 1090 | - $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 1091 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1092 | - // set nonce from post data |
|
| 1093 | - $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 1094 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1095 | - } |
|
| 1096 | - // set the nav_tabs array but ONLY if this is UI_request |
|
| 1097 | - if ($this->_is_UI_request) { |
|
| 1098 | - $this->_set_nav_tabs(); |
|
| 1099 | - } |
|
| 1100 | - // grab callback function |
|
| 1101 | - $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route; |
|
| 1102 | - // check if callback has args |
|
| 1103 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 1104 | - $error_msg = ''; |
|
| 1105 | - // action right before calling route |
|
| 1106 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1107 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1108 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1109 | - } |
|
| 1110 | - // right before calling the route, let's clean the _wp_http_referer |
|
| 1111 | - $this->request->setServerParam( |
|
| 1112 | - 'REQUEST_URI', |
|
| 1113 | - remove_query_arg( |
|
| 1114 | - '_wp_http_referer', |
|
| 1115 | - wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1116 | - ) |
|
| 1117 | - ); |
|
| 1118 | - if (! empty($func)) { |
|
| 1119 | - if (is_array($func)) { |
|
| 1120 | - [$class, $method] = $func; |
|
| 1121 | - } elseif (strpos($func, '::') !== false) { |
|
| 1122 | - [$class, $method] = explode('::', $func); |
|
| 1123 | - } else { |
|
| 1124 | - $class = $this; |
|
| 1125 | - $method = $func; |
|
| 1126 | - } |
|
| 1127 | - if (! (is_object($class) && $class === $this)) { |
|
| 1128 | - // send along this admin page object for access by addons. |
|
| 1129 | - $args['admin_page_object'] = $this; |
|
| 1130 | - } |
|
| 1131 | - if ( |
|
| 1132 | - // is it a method on a class that doesn't work? |
|
| 1133 | - ( |
|
| 1134 | - ( |
|
| 1135 | - method_exists($class, $method) |
|
| 1136 | - && call_user_func_array([$class, $method], $args) === false |
|
| 1137 | - ) |
|
| 1138 | - && ( |
|
| 1139 | - // is it a standalone function that doesn't work? |
|
| 1140 | - function_exists($method) |
|
| 1141 | - && call_user_func_array( |
|
| 1142 | - $func, |
|
| 1143 | - array_merge(['admin_page_object' => $this], $args) |
|
| 1144 | - ) === false |
|
| 1145 | - ) |
|
| 1146 | - ) |
|
| 1147 | - || ( |
|
| 1148 | - // is it neither a class method NOR a standalone function? |
|
| 1149 | - ! method_exists($class, $method) |
|
| 1150 | - && ! function_exists($method) |
|
| 1151 | - ) |
|
| 1152 | - ) { |
|
| 1153 | - // user error msg |
|
| 1154 | - $error_msg = esc_html__( |
|
| 1155 | - 'An error occurred. The requested page route could not be found.', |
|
| 1156 | - 'event_espresso' |
|
| 1157 | - ); |
|
| 1158 | - // developer error msg |
|
| 1159 | - $error_msg .= '||'; |
|
| 1160 | - $error_msg .= sprintf( |
|
| 1161 | - esc_html__( |
|
| 1162 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1163 | - 'event_espresso' |
|
| 1164 | - ), |
|
| 1165 | - $method |
|
| 1166 | - ); |
|
| 1167 | - } |
|
| 1168 | - if (! empty($error_msg)) { |
|
| 1169 | - throw new EE_Error($error_msg); |
|
| 1170 | - } |
|
| 1171 | - } |
|
| 1172 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1173 | - // then we need to reset the routing properties to the new route. |
|
| 1174 | - // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1175 | - if ( |
|
| 1176 | - $this->_is_UI_request === false |
|
| 1177 | - && is_array($this->_route) |
|
| 1178 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1179 | - ) { |
|
| 1180 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1181 | - } |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1187 | - * route redirects to a headers route in its route config. |
|
| 1188 | - * |
|
| 1189 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1190 | - * @return void |
|
| 1191 | - * @throws ReflectionException |
|
| 1192 | - * @throws InvalidArgumentException |
|
| 1193 | - * @throws InvalidInterfaceException |
|
| 1194 | - * @throws InvalidDataTypeException |
|
| 1195 | - * @throws EE_Error |
|
| 1196 | - * @since 4.3.0 |
|
| 1197 | - */ |
|
| 1198 | - protected function _reset_routing_properties($new_route) |
|
| 1199 | - { |
|
| 1200 | - $this->_is_UI_request = true; |
|
| 1201 | - // now we set the current route to whatever the headers_sent_route is set at |
|
| 1202 | - $this->request->setRequestParam('action', $new_route); |
|
| 1203 | - // rerun page setup |
|
| 1204 | - $this->_page_setup(); |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * _add_query_arg |
|
| 1210 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1211 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1212 | - * |
|
| 1213 | - * @param array $args |
|
| 1214 | - * @param string $url |
|
| 1215 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1216 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1217 | - * Example usage: If the current page is: |
|
| 1218 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1219 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1220 | - * &_wpnonce=5467821 |
|
| 1221 | - * and you call: |
|
| 1222 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1223 | - * array( |
|
| 1224 | - * 'action' => 'resend_something', |
|
| 1225 | - * 'page=>espresso_registrations' |
|
| 1226 | - * ), |
|
| 1227 | - * $some_url, |
|
| 1228 | - * true |
|
| 1229 | - * ); |
|
| 1230 | - * It will produce a url in this structure: |
|
| 1231 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1232 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1233 | - * month_range]=March%202015 |
|
| 1234 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1235 | - * @return string |
|
| 1236 | - */ |
|
| 1237 | - public static function add_query_args_and_nonce( |
|
| 1238 | - $args = [], |
|
| 1239 | - $url = '', |
|
| 1240 | - $sticky = false, |
|
| 1241 | - $exclude_nonce = false |
|
| 1242 | - ) { |
|
| 1243 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1244 | - if ($sticky) { |
|
| 1245 | - /** @var RequestInterface $request */ |
|
| 1246 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1247 | - $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']); |
|
| 1248 | - foreach ($request->requestParams() as $key => $value) { |
|
| 1249 | - // do not add nonces |
|
| 1250 | - if (strpos($key, 'nonce') !== false) { |
|
| 1251 | - continue; |
|
| 1252 | - } |
|
| 1253 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1254 | - } |
|
| 1255 | - } |
|
| 1256 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1257 | - } |
|
| 1258 | - |
|
| 1259 | - |
|
| 1260 | - /** |
|
| 1261 | - * This returns a generated link that will load the related help tab. |
|
| 1262 | - * |
|
| 1263 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1264 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1265 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1266 | - * @return string generated link |
|
| 1267 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1268 | - */ |
|
| 1269 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1270 | - { |
|
| 1271 | - return EEH_Template::get_help_tab_link( |
|
| 1272 | - $help_tab_id, |
|
| 1273 | - $this->page_slug, |
|
| 1274 | - $this->_req_action, |
|
| 1275 | - $icon_style, |
|
| 1276 | - $help_text |
|
| 1277 | - ); |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * _add_help_tabs |
|
| 1283 | - * Note child classes define their help tabs within the page_config array. |
|
| 1284 | - * |
|
| 1285 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1286 | - * @return void |
|
| 1287 | - * @throws DomainException |
|
| 1288 | - * @throws EE_Error |
|
| 1289 | - * @throws ReflectionException |
|
| 1290 | - */ |
|
| 1291 | - protected function _add_help_tabs() |
|
| 1292 | - { |
|
| 1293 | - $tour_buttons = ''; |
|
| 1294 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1295 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1296 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1297 | - // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1298 | - // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1299 | - // $tb = array(); |
|
| 1300 | - // $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1301 | - // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1302 | - // // if this is the end tour then we don't need to setup a button |
|
| 1303 | - // if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1304 | - // continue; |
|
| 1305 | - // } |
|
| 1306 | - // $tb[] = '<button id="trigger-tour-' |
|
| 1307 | - // . $tour->get_slug() |
|
| 1308 | - // . '" class="button--primary trigger-ee-help-tour">' |
|
| 1309 | - // . $tour->get_label() |
|
| 1310 | - // . '</button>'; |
|
| 1311 | - // } |
|
| 1312 | - // $tour_buttons .= implode('<br />', $tb); |
|
| 1313 | - // $tour_buttons .= '</div></div>'; |
|
| 1314 | - // } |
|
| 1315 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1316 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1317 | - // check that the callback given is valid |
|
| 1318 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1319 | - throw new EE_Error( |
|
| 1320 | - sprintf( |
|
| 1321 | - esc_html__( |
|
| 1322 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1323 | - 'event_espresso' |
|
| 1324 | - ), |
|
| 1325 | - $config['help_sidebar'], |
|
| 1326 | - get_class($this) |
|
| 1327 | - ) |
|
| 1328 | - ); |
|
| 1329 | - } |
|
| 1330 | - $content = apply_filters( |
|
| 1331 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1332 | - $this->{$config['help_sidebar']}() |
|
| 1333 | - ); |
|
| 1334 | - $content .= $tour_buttons; // add help tour buttons. |
|
| 1335 | - // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1336 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1337 | - } |
|
| 1338 | - // if there ARE tour buttons... |
|
| 1339 | - if (! empty($tour_buttons)) { |
|
| 1340 | - // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar. |
|
| 1341 | - if (! isset($config['help_sidebar'])) { |
|
| 1342 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1343 | - } |
|
| 1344 | - // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1345 | - if (! isset($config['help_tabs'])) { |
|
| 1346 | - $_ht['id'] = $this->page_slug; |
|
| 1347 | - $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1348 | - $_ht['content'] = '<p>' |
|
| 1349 | - . esc_html__( |
|
| 1350 | - 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1351 | - 'event_espresso' |
|
| 1352 | - ) . '</p>'; |
|
| 1353 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1356 | - if (! isset($config['help_tabs'])) { |
|
| 1357 | - return; |
|
| 1358 | - } //no help tabs for this route |
|
| 1359 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1360 | - // we're here so there ARE help tabs! |
|
| 1361 | - // make sure we've got what we need |
|
| 1362 | - if (! isset($cfg['title'])) { |
|
| 1363 | - throw new EE_Error( |
|
| 1364 | - esc_html__( |
|
| 1365 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1366 | - 'event_espresso' |
|
| 1367 | - ) |
|
| 1368 | - ); |
|
| 1369 | - } |
|
| 1370 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1371 | - throw new EE_Error( |
|
| 1372 | - esc_html__( |
|
| 1373 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1374 | - 'event_espresso' |
|
| 1375 | - ) |
|
| 1376 | - ); |
|
| 1377 | - } |
|
| 1378 | - // first priority goes to content. |
|
| 1379 | - if (! empty($cfg['content'])) { |
|
| 1380 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1381 | - // second priority goes to filename |
|
| 1382 | - } elseif (! empty($cfg['filename'])) { |
|
| 1383 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1384 | - // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1385 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1386 | - . basename($this->_get_dir()) |
|
| 1387 | - . '/help_tabs/' |
|
| 1388 | - . $cfg['filename'] |
|
| 1389 | - . '.help_tab.php' : $file_path; |
|
| 1390 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1391 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1392 | - EE_Error::add_error( |
|
| 1393 | - sprintf( |
|
| 1394 | - esc_html__( |
|
| 1395 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1396 | - 'event_espresso' |
|
| 1397 | - ), |
|
| 1398 | - $tab_id, |
|
| 1399 | - key($config), |
|
| 1400 | - $file_path |
|
| 1401 | - ), |
|
| 1402 | - __FILE__, |
|
| 1403 | - __FUNCTION__, |
|
| 1404 | - __LINE__ |
|
| 1405 | - ); |
|
| 1406 | - return; |
|
| 1407 | - } |
|
| 1408 | - $template_args['admin_page_obj'] = $this; |
|
| 1409 | - $content = EEH_Template::display_template( |
|
| 1410 | - $file_path, |
|
| 1411 | - $template_args, |
|
| 1412 | - true |
|
| 1413 | - ); |
|
| 1414 | - } else { |
|
| 1415 | - $content = ''; |
|
| 1416 | - } |
|
| 1417 | - // check if callback is valid |
|
| 1418 | - if ( |
|
| 1419 | - empty($content) |
|
| 1420 | - && ( |
|
| 1421 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1422 | - ) |
|
| 1423 | - ) { |
|
| 1424 | - EE_Error::add_error( |
|
| 1425 | - sprintf( |
|
| 1426 | - esc_html__( |
|
| 1427 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1428 | - 'event_espresso' |
|
| 1429 | - ), |
|
| 1430 | - $cfg['title'] |
|
| 1431 | - ), |
|
| 1432 | - __FILE__, |
|
| 1433 | - __FUNCTION__, |
|
| 1434 | - __LINE__ |
|
| 1435 | - ); |
|
| 1436 | - return; |
|
| 1437 | - } |
|
| 1438 | - // setup config array for help tab method |
|
| 1439 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1440 | - $_ht = [ |
|
| 1441 | - 'id' => $id, |
|
| 1442 | - 'title' => $cfg['title'], |
|
| 1443 | - 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1444 | - 'content' => $content, |
|
| 1445 | - ]; |
|
| 1446 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1447 | - } |
|
| 1448 | - } |
|
| 1449 | - } |
|
| 1450 | - |
|
| 1451 | - |
|
| 1452 | - /** |
|
| 1453 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1454 | - * an array with properties for setting up usage of the joyride plugin |
|
| 1455 | - * |
|
| 1456 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1457 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1458 | - * _set_page_config() comments |
|
| 1459 | - * @return void |
|
| 1460 | - * @throws InvalidArgumentException |
|
| 1461 | - * @throws InvalidDataTypeException |
|
| 1462 | - * @throws InvalidInterfaceException |
|
| 1463 | - * @throws ReflectionException |
|
| 1464 | - */ |
|
| 1465 | - protected function _add_help_tour() |
|
| 1466 | - { |
|
| 1467 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1468 | - // $tours = array(); |
|
| 1469 | - // $this->_help_tour = array(); |
|
| 1470 | - // // exit early if help tours are turned off globally |
|
| 1471 | - // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1472 | - // || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1473 | - // ) { |
|
| 1474 | - // return; |
|
| 1475 | - // } |
|
| 1476 | - // // loop through _page_config to find any help_tour defined |
|
| 1477 | - // foreach ($this->_page_config as $route => $config) { |
|
| 1478 | - // // we're only going to set things up for this route |
|
| 1479 | - // if ($route !== $this->_req_action) { |
|
| 1480 | - // continue; |
|
| 1481 | - // } |
|
| 1482 | - // if (isset($config['help_tour'])) { |
|
| 1483 | - // foreach ($config['help_tour'] as $tour) { |
|
| 1484 | - // $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1485 | - // // let's see if we can get that file... |
|
| 1486 | - // // if not its possible this is a decaf route not set in caffeinated |
|
| 1487 | - // // so lets try and get the caffeinated equivalent |
|
| 1488 | - // $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1489 | - // . basename($this->_get_dir()) |
|
| 1490 | - // . '/help_tours/' |
|
| 1491 | - // . $tour |
|
| 1492 | - // . '.class.php' : $file_path; |
|
| 1493 | - // // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1494 | - // if (! is_readable($file_path)) { |
|
| 1495 | - // EE_Error::add_error( |
|
| 1496 | - // sprintf( |
|
| 1497 | - // esc_html__( |
|
| 1498 | - // 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1499 | - // 'event_espresso' |
|
| 1500 | - // ), |
|
| 1501 | - // $file_path, |
|
| 1502 | - // $tour |
|
| 1503 | - // ), |
|
| 1504 | - // __FILE__, |
|
| 1505 | - // __FUNCTION__, |
|
| 1506 | - // __LINE__ |
|
| 1507 | - // ); |
|
| 1508 | - // return; |
|
| 1509 | - // } |
|
| 1510 | - // require_once $file_path; |
|
| 1511 | - // if (! class_exists($tour)) { |
|
| 1512 | - // $error_msg[] = sprintf( |
|
| 1513 | - // esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1514 | - // $tour |
|
| 1515 | - // ); |
|
| 1516 | - // $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1517 | - // . sprintf( |
|
| 1518 | - // esc_html__( |
|
| 1519 | - // 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1520 | - // 'event_espresso' |
|
| 1521 | - // ), |
|
| 1522 | - // $tour, |
|
| 1523 | - // '<br />', |
|
| 1524 | - // $tour, |
|
| 1525 | - // $this->_req_action, |
|
| 1526 | - // get_class($this) |
|
| 1527 | - // ); |
|
| 1528 | - // throw new EE_Error(implode('||', $error_msg)); |
|
| 1529 | - // } |
|
| 1530 | - // $tour_obj = new $tour($this->_is_caf); |
|
| 1531 | - // $tours[] = $tour_obj; |
|
| 1532 | - // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1533 | - // } |
|
| 1534 | - // // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1535 | - // $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1536 | - // $tours[] = $end_stop_tour; |
|
| 1537 | - // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1538 | - // } |
|
| 1539 | - // } |
|
| 1540 | - // |
|
| 1541 | - // if (! empty($tours)) { |
|
| 1542 | - // $this->_help_tour['tours'] = $tours; |
|
| 1543 | - // } |
|
| 1544 | - // // that's it! Now that the $_help_tours property is set (or not) |
|
| 1545 | - // // the scripts and html should be taken care of automatically. |
|
| 1546 | - // |
|
| 1547 | - // /** |
|
| 1548 | - // * Allow extending the help tours variable. |
|
| 1549 | - // * |
|
| 1550 | - // * @param Array $_help_tour The array containing all help tour information to be displayed. |
|
| 1551 | - // */ |
|
| 1552 | - // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1558 | - * |
|
| 1559 | - * @return void |
|
| 1560 | - * @throws ReflectionException |
|
| 1561 | - * @throws EE_Error |
|
| 1562 | - */ |
|
| 1563 | - protected function _add_qtips() |
|
| 1564 | - { |
|
| 1565 | - if (isset($this->_route_config['qtips'])) { |
|
| 1566 | - $qtips = (array) $this->_route_config['qtips']; |
|
| 1567 | - // load qtip loader |
|
| 1568 | - $path = [ |
|
| 1569 | - $this->_get_dir() . '/qtips/', |
|
| 1570 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1571 | - ]; |
|
| 1572 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1573 | - } |
|
| 1574 | - } |
|
| 1575 | - |
|
| 1576 | - |
|
| 1577 | - /** |
|
| 1578 | - * _set_nav_tabs |
|
| 1579 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1580 | - * wish to add additional tabs or modify accordingly. |
|
| 1581 | - * |
|
| 1582 | - * @return void |
|
| 1583 | - * @throws InvalidArgumentException |
|
| 1584 | - * @throws InvalidInterfaceException |
|
| 1585 | - * @throws InvalidDataTypeException |
|
| 1586 | - */ |
|
| 1587 | - protected function _set_nav_tabs() |
|
| 1588 | - { |
|
| 1589 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1590 | - $i = 0; |
|
| 1591 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1592 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1593 | - continue; |
|
| 1594 | - } |
|
| 1595 | - // no nav tab for this config |
|
| 1596 | - // check for persistent flag |
|
| 1597 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1598 | - // nav tab is only to appear when route requested. |
|
| 1599 | - continue; |
|
| 1600 | - } |
|
| 1601 | - if (! $this->check_user_access($slug, true)) { |
|
| 1602 | - // no nav tab because current user does not have access. |
|
| 1603 | - continue; |
|
| 1604 | - } |
|
| 1605 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1606 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1607 | - 'url' => isset($config['nav']['url']) |
|
| 1608 | - ? $config['nav']['url'] |
|
| 1609 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1610 | - ['action' => $slug], |
|
| 1611 | - $this->_admin_base_url |
|
| 1612 | - ), |
|
| 1613 | - 'link_text' => isset($config['nav']['label']) |
|
| 1614 | - ? $config['nav']['label'] |
|
| 1615 | - : ucwords( |
|
| 1616 | - str_replace('_', ' ', $slug) |
|
| 1617 | - ), |
|
| 1618 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1619 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1620 | - ]; |
|
| 1621 | - $i++; |
|
| 1622 | - } |
|
| 1623 | - // if $this->_nav_tabs is empty then lets set the default |
|
| 1624 | - if (empty($this->_nav_tabs)) { |
|
| 1625 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1626 | - 'url' => $this->_admin_base_url, |
|
| 1627 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1628 | - 'css_class' => 'nav-tab-active', |
|
| 1629 | - 'order' => 10, |
|
| 1630 | - ]; |
|
| 1631 | - } |
|
| 1632 | - // now let's sort the tabs according to order |
|
| 1633 | - usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1634 | - } |
|
| 1635 | - |
|
| 1636 | - |
|
| 1637 | - /** |
|
| 1638 | - * _set_current_labels |
|
| 1639 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1640 | - * property array |
|
| 1641 | - * |
|
| 1642 | - * @return void |
|
| 1643 | - */ |
|
| 1644 | - private function _set_current_labels() |
|
| 1645 | - { |
|
| 1646 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1647 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1648 | - if (is_array($text)) { |
|
| 1649 | - foreach ($text as $sublabel => $subtext) { |
|
| 1650 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1651 | - } |
|
| 1652 | - } else { |
|
| 1653 | - $this->_labels[ $label ] = $text; |
|
| 1654 | - } |
|
| 1655 | - } |
|
| 1656 | - } |
|
| 1657 | - } |
|
| 1658 | - |
|
| 1659 | - |
|
| 1660 | - /** |
|
| 1661 | - * verifies user access for this admin page |
|
| 1662 | - * |
|
| 1663 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1664 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1665 | - * return false if verify fail. |
|
| 1666 | - * @return bool |
|
| 1667 | - * @throws InvalidArgumentException |
|
| 1668 | - * @throws InvalidDataTypeException |
|
| 1669 | - * @throws InvalidInterfaceException |
|
| 1670 | - */ |
|
| 1671 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1672 | - { |
|
| 1673 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1674 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1675 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1676 | - && is_array( |
|
| 1677 | - $this->_page_routes[ $route_to_check ] |
|
| 1678 | - ) |
|
| 1679 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1680 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1681 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1682 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1683 | - : $this->_route['capability']; |
|
| 1684 | - } else { |
|
| 1685 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1686 | - } |
|
| 1687 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1688 | - if ( |
|
| 1689 | - ! $this->request->isAjax() |
|
| 1690 | - && ( |
|
| 1691 | - ! function_exists('is_admin') |
|
| 1692 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1693 | - $capability, |
|
| 1694 | - $this->page_slug |
|
| 1695 | - . '_' |
|
| 1696 | - . $route_to_check, |
|
| 1697 | - $id |
|
| 1698 | - ) |
|
| 1699 | - ) |
|
| 1700 | - ) { |
|
| 1701 | - if ($verify_only) { |
|
| 1702 | - return false; |
|
| 1703 | - } |
|
| 1704 | - if (is_user_logged_in()) { |
|
| 1705 | - wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1706 | - } else { |
|
| 1707 | - return false; |
|
| 1708 | - } |
|
| 1709 | - } |
|
| 1710 | - return true; |
|
| 1711 | - } |
|
| 1712 | - |
|
| 1713 | - |
|
| 1714 | - protected function addMetaBox( |
|
| 1715 | - $box_id, |
|
| 1716 | - $title, |
|
| 1717 | - $callback, |
|
| 1718 | - $screen, |
|
| 1719 | - $context = 'normal', |
|
| 1720 | - $priority = 'default', |
|
| 1721 | - $callback_args = null |
|
| 1722 | - ) { |
|
| 1723 | - add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args); |
|
| 1724 | - add_filter( |
|
| 1725 | - "postbox_classes_{$this->_wp_page_slug}_{$box_id}", |
|
| 1726 | - function ($classes) { |
|
| 1727 | - array_push($classes, 'ee-admin-container'); |
|
| 1728 | - return $classes; |
|
| 1729 | - } |
|
| 1730 | - ); |
|
| 1731 | - } |
|
| 1732 | - |
|
| 1733 | - |
|
| 1734 | - /** |
|
| 1735 | - * admin_init_global |
|
| 1736 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1737 | - * This method executes for ALL EE Admin pages. |
|
| 1738 | - * |
|
| 1739 | - * @return void |
|
| 1740 | - */ |
|
| 1741 | - public function admin_init_global() |
|
| 1742 | - { |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - |
|
| 1746 | - /** |
|
| 1747 | - * wp_loaded_global |
|
| 1748 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1749 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1750 | - * |
|
| 1751 | - * @return void |
|
| 1752 | - */ |
|
| 1753 | - public function wp_loaded() |
|
| 1754 | - { |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - |
|
| 1758 | - /** |
|
| 1759 | - * admin_notices |
|
| 1760 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1761 | - * ALL EE_Admin pages. |
|
| 1762 | - * |
|
| 1763 | - * @return void |
|
| 1764 | - */ |
|
| 1765 | - public function admin_notices_global() |
|
| 1766 | - { |
|
| 1767 | - $this->_display_no_javascript_warning(); |
|
| 1768 | - $this->_display_espresso_notices(); |
|
| 1769 | - } |
|
| 1770 | - |
|
| 1771 | - |
|
| 1772 | - public function network_admin_notices_global() |
|
| 1773 | - { |
|
| 1774 | - $this->_display_no_javascript_warning(); |
|
| 1775 | - $this->_display_espresso_notices(); |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - |
|
| 1779 | - /** |
|
| 1780 | - * admin_footer_scripts_global |
|
| 1781 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1782 | - * will apply on ALL EE_Admin pages. |
|
| 1783 | - * |
|
| 1784 | - * @return void |
|
| 1785 | - */ |
|
| 1786 | - public function admin_footer_scripts_global() |
|
| 1787 | - { |
|
| 1788 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1789 | - $this->_add_admin_page_overlay(); |
|
| 1790 | - // if metaboxes are present we need to add the nonce field |
|
| 1791 | - if ( |
|
| 1792 | - isset($this->_route_config['metaboxes']) |
|
| 1793 | - || isset($this->_route_config['list_table']) |
|
| 1794 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1795 | - ) { |
|
| 1796 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1797 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1798 | - } |
|
| 1799 | - } |
|
| 1800 | - |
|
| 1801 | - |
|
| 1802 | - /** |
|
| 1803 | - * admin_footer_global |
|
| 1804 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. |
|
| 1805 | - * This particular method will apply on ALL EE_Admin Pages. |
|
| 1806 | - * |
|
| 1807 | - * @return void |
|
| 1808 | - */ |
|
| 1809 | - public function admin_footer_global() |
|
| 1810 | - { |
|
| 1811 | - // dialog container for dialog helper |
|
| 1812 | - echo ' |
|
| 137 | + /** |
|
| 138 | + * unprocessed value for the 'action' request param (default '') |
|
| 139 | + * |
|
| 140 | + * @var string |
|
| 141 | + */ |
|
| 142 | + protected $raw_req_action = ''; |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * unprocessed value for the 'page' request param (default '') |
|
| 146 | + * |
|
| 147 | + * @var string |
|
| 148 | + */ |
|
| 149 | + protected $raw_req_page = ''; |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * sanitized request action (and nonce) |
|
| 153 | + * |
|
| 154 | + * @var string |
|
| 155 | + */ |
|
| 156 | + protected $_req_action = ''; |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * sanitized request action nonce |
|
| 160 | + * |
|
| 161 | + * @var string |
|
| 162 | + */ |
|
| 163 | + protected $_req_nonce = ''; |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @var string |
|
| 167 | + */ |
|
| 168 | + protected $_search_btn_label = ''; |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @var string |
|
| 172 | + */ |
|
| 173 | + protected $_search_box_callback = ''; |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @var WP_Screen |
|
| 177 | + */ |
|
| 178 | + protected $_current_screen; |
|
| 179 | + |
|
| 180 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 181 | + protected $_hook_obj; |
|
| 182 | + |
|
| 183 | + // for holding incoming request data |
|
| 184 | + protected $_req_data = []; |
|
| 185 | + |
|
| 186 | + // yes / no array for admin form fields |
|
| 187 | + protected $_yes_no_values = []; |
|
| 188 | + |
|
| 189 | + // some default things shared by all child classes |
|
| 190 | + protected $_default_espresso_metaboxes; |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @var EE_Registry |
|
| 194 | + */ |
|
| 195 | + protected $EE; |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 200 | + * |
|
| 201 | + * @var boolean |
|
| 202 | + */ |
|
| 203 | + protected $_is_caf = false; |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * whether or not initializePage() has run |
|
| 207 | + * |
|
| 208 | + * @var boolean |
|
| 209 | + */ |
|
| 210 | + protected $initialized = false; |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @var FeatureFlags |
|
| 214 | + */ |
|
| 215 | + protected $feature; |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * @Constructor |
|
| 220 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 221 | + * @throws InvalidArgumentException |
|
| 222 | + * @throws InvalidDataTypeException |
|
| 223 | + * @throws InvalidInterfaceException |
|
| 224 | + * @throws ReflectionException |
|
| 225 | + */ |
|
| 226 | + public function __construct($routing = true) |
|
| 227 | + { |
|
| 228 | + $this->loader = LoaderFactory::getLoader(); |
|
| 229 | + $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 230 | + $this->feature = $this->loader->getShared(FeatureFlags::class); |
|
| 231 | + $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 232 | + // routing enabled? |
|
| 233 | + $this->_routing = $routing; |
|
| 234 | + |
|
| 235 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 236 | + $this->_is_caf = true; |
|
| 237 | + } |
|
| 238 | + $this->_yes_no_values = [ |
|
| 239 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 240 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 241 | + ]; |
|
| 242 | + // set the _req_data property. |
|
| 243 | + $this->_req_data = $this->request->requestParams(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * @return EE_Admin_Config |
|
| 249 | + */ |
|
| 250 | + public function adminConfig(): EE_Admin_Config |
|
| 251 | + { |
|
| 252 | + return $this->admin_config; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @return FeatureFlags |
|
| 258 | + */ |
|
| 259 | + public function feature(): FeatureFlags |
|
| 260 | + { |
|
| 261 | + return $this->feature; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * This logic used to be in the constructor, but that caused a chicken <--> egg scenario |
|
| 267 | + * for child classes that needed to set properties prior to these methods getting called, |
|
| 268 | + * but also needed the parent class to have its construction completed as well. |
|
| 269 | + * Bottom line is that constructors should ONLY be used for setting initial properties |
|
| 270 | + * and any complex initialization logic should only run after instantiation is complete. |
|
| 271 | + * |
|
| 272 | + * This method gets called immediately after construction from within |
|
| 273 | + * EE_Admin_Page_Init::_initialize_admin_page() |
|
| 274 | + * |
|
| 275 | + * @throws EE_Error |
|
| 276 | + * @throws InvalidArgumentException |
|
| 277 | + * @throws InvalidDataTypeException |
|
| 278 | + * @throws InvalidInterfaceException |
|
| 279 | + * @throws ReflectionException |
|
| 280 | + * @since $VID:$ |
|
| 281 | + */ |
|
| 282 | + public function initializePage() |
|
| 283 | + { |
|
| 284 | + if ($this->initialized) { |
|
| 285 | + return; |
|
| 286 | + } |
|
| 287 | + // set initial page props (child method) |
|
| 288 | + $this->_init_page_props(); |
|
| 289 | + // set global defaults |
|
| 290 | + $this->_set_defaults(); |
|
| 291 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 292 | + $this->_global_ajax_hooks(); |
|
| 293 | + $this->_ajax_hooks(); |
|
| 294 | + // other_page_hooks have to be early too. |
|
| 295 | + $this->_do_other_page_hooks(); |
|
| 296 | + // set up page dependencies |
|
| 297 | + $this->_before_page_setup(); |
|
| 298 | + $this->_page_setup(); |
|
| 299 | + $this->initialized = true; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * _init_page_props |
|
| 305 | + * Child classes use to set at least the following properties: |
|
| 306 | + * $page_slug. |
|
| 307 | + * $page_label. |
|
| 308 | + * |
|
| 309 | + * @abstract |
|
| 310 | + * @return void |
|
| 311 | + */ |
|
| 312 | + abstract protected function _init_page_props(); |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * _ajax_hooks |
|
| 317 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 318 | + * Note: within the ajax callback methods. |
|
| 319 | + * |
|
| 320 | + * @abstract |
|
| 321 | + * @return void |
|
| 322 | + */ |
|
| 323 | + abstract protected function _ajax_hooks(); |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * _define_page_props |
|
| 328 | + * child classes define page properties in here. Must include at least: |
|
| 329 | + * $_admin_base_url = base_url for all admin pages |
|
| 330 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 331 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 332 | + * array( |
|
| 333 | + * 'buttons' => array( |
|
| 334 | + * 'add' => esc_html__('label for add new button'), |
|
| 335 | + * 'edit' => esc_html__('label for edit button'), |
|
| 336 | + * 'delete' => esc_html__('label for delete button') |
|
| 337 | + * ) |
|
| 338 | + * ) |
|
| 339 | + * |
|
| 340 | + * @abstract |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + abstract protected function _define_page_props(); |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * _set_page_routes |
|
| 348 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 349 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 350 | + * have a 'default' route. Here's the format |
|
| 351 | + * $this->_page_routes = array( |
|
| 352 | + * 'default' => array( |
|
| 353 | + * 'func' => '_default_method_handling_route', |
|
| 354 | + * 'args' => array('array','of','args'), |
|
| 355 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 356 | + * ajax request, backend processing) |
|
| 357 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 358 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 359 | + * headers sent route. |
|
| 360 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 361 | + * this route. |
|
| 362 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 363 | + * checks). |
|
| 364 | + * ), |
|
| 365 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 366 | + * handling method. |
|
| 367 | + * ) |
|
| 368 | + * ) |
|
| 369 | + * |
|
| 370 | + * @abstract |
|
| 371 | + * @return void |
|
| 372 | + */ |
|
| 373 | + abstract protected function _set_page_routes(); |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * _set_page_config |
|
| 378 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 379 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 380 | + * $this->_page_config = array( |
|
| 381 | + * 'default' => array( |
|
| 382 | + * 'labels' => array( |
|
| 383 | + * 'buttons' => array( |
|
| 384 | + * 'add' => esc_html__('label for adding item'), |
|
| 385 | + * 'edit' => esc_html__('label for editing item'), |
|
| 386 | + * 'delete' => esc_html__('label for deleting item') |
|
| 387 | + * ), |
|
| 388 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 389 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 390 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 391 | + * _define_page_props() method |
|
| 392 | + * 'nav' => array( |
|
| 393 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 394 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 395 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 396 | + * 'order' => 10, //required to indicate tab position. |
|
| 397 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 398 | + * displayed then add this parameter. |
|
| 399 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 400 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 401 | + * metaboxes set for eventespresso admin pages. |
|
| 402 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 403 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 404 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 405 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 406 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 407 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 408 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 409 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 410 | + * want to display. |
|
| 411 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 412 | + * 'tab_id' => array( |
|
| 413 | + * 'title' => 'tab_title', |
|
| 414 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 415 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 416 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 417 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 418 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 419 | + * attempt to use the callback which should match the name of a method in the class |
|
| 420 | + * ), |
|
| 421 | + * 'tab2_id' => array( |
|
| 422 | + * 'title' => 'tab2 title', |
|
| 423 | + * 'filename' => 'file_name_2' |
|
| 424 | + * 'callback' => 'callback_method_for_content', |
|
| 425 | + * ), |
|
| 426 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 427 | + * help tab area on an admin page. @return void |
|
| 428 | + * |
|
| 429 | + * @link |
|
| 430 | + * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 431 | + * 'help_tour' => array( |
|
| 432 | + * 'name_of_help_tour_class', //all help tours should be a child class of EE_Help_Tour and located |
|
| 433 | + * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 434 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 435 | + * ), |
|
| 436 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default |
|
| 437 | + * is true if it isn't present). To remove the requirement for a nonce check when this route is |
|
| 438 | + * visited just set |
|
| 439 | + * 'require_nonce' to FALSE |
|
| 440 | + * ) |
|
| 441 | + * ) |
|
| 442 | + * |
|
| 443 | + * @abstract |
|
| 444 | + */ |
|
| 445 | + abstract protected function _set_page_config(); |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** end sample help_tour methods **/ |
|
| 452 | + /** |
|
| 453 | + * _add_screen_options |
|
| 454 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 455 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 456 | + * to a particular view. |
|
| 457 | + * |
|
| 458 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 459 | + * see also WP_Screen object documents... |
|
| 460 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 461 | + * @abstract |
|
| 462 | + * @return void |
|
| 463 | + */ |
|
| 464 | + abstract protected function _add_screen_options(); |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * _add_feature_pointers |
|
| 469 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 470 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 471 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 472 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 473 | + * extended) also see: |
|
| 474 | + * |
|
| 475 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 476 | + * @abstract |
|
| 477 | + * @return void |
|
| 478 | + */ |
|
| 479 | + abstract protected function _add_feature_pointers(); |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * load_scripts_styles |
|
| 484 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 485 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 486 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 487 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 488 | + * |
|
| 489 | + * @abstract |
|
| 490 | + * @return void |
|
| 491 | + */ |
|
| 492 | + abstract public function load_scripts_styles(); |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * admin_init |
|
| 497 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 498 | + * all pages/views loaded by child class. |
|
| 499 | + * |
|
| 500 | + * @abstract |
|
| 501 | + * @return void |
|
| 502 | + */ |
|
| 503 | + abstract public function admin_init(); |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * admin_notices |
|
| 508 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 509 | + * all pages/views loaded by child class. |
|
| 510 | + * |
|
| 511 | + * @abstract |
|
| 512 | + * @return void |
|
| 513 | + */ |
|
| 514 | + abstract public function admin_notices(); |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * admin_footer_scripts |
|
| 519 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 520 | + * will apply to all pages/views loaded by child class. |
|
| 521 | + * |
|
| 522 | + * @return void |
|
| 523 | + */ |
|
| 524 | + abstract public function admin_footer_scripts(); |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * admin_footer |
|
| 529 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 530 | + * apply to all pages/views loaded by child class. |
|
| 531 | + * |
|
| 532 | + * @return void |
|
| 533 | + */ |
|
| 534 | + public function admin_footer() |
|
| 535 | + { |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * _global_ajax_hooks |
|
| 541 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 542 | + * Note: within the ajax callback methods. |
|
| 543 | + * |
|
| 544 | + * @abstract |
|
| 545 | + * @return void |
|
| 546 | + */ |
|
| 547 | + protected function _global_ajax_hooks() |
|
| 548 | + { |
|
| 549 | + // for lazy loading of metabox content |
|
| 550 | + add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 551 | + |
|
| 552 | + add_action( |
|
| 553 | + 'wp_ajax_espresso_hide_status_change_notice', |
|
| 554 | + [$this, 'hideStatusChangeNotice'] |
|
| 555 | + ); |
|
| 556 | + add_action( |
|
| 557 | + 'wp_ajax_nopriv_espresso_hide_status_change_notice', |
|
| 558 | + [$this, 'hideStatusChangeNotice'] |
|
| 559 | + ); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + public function ajax_metabox_content() |
|
| 564 | + { |
|
| 565 | + $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 566 | + $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 567 | + EE_Admin_Page::cached_rss_display($content_id, $content_url); |
|
| 568 | + wp_die(); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + public function hideStatusChangeNotice() |
|
| 573 | + { |
|
| 574 | + $response = []; |
|
| 575 | + try { |
|
| 576 | + /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
|
| 577 | + $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
|
| 578 | + $response['success'] = $status_change_notice->dismiss() > -1; |
|
| 579 | + } catch (Exception $exception) { |
|
| 580 | + $response['errors'] = $exception->getMessage(); |
|
| 581 | + } |
|
| 582 | + echo wp_json_encode($response); |
|
| 583 | + exit(); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 589 | + * |
|
| 590 | + * @return void |
|
| 591 | + */ |
|
| 592 | + protected function _before_page_setup() |
|
| 593 | + { |
|
| 594 | + // default is to do nothing |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * Makes sure any things that need to be loaded early get handled. |
|
| 600 | + * We also escape early here if the page requested doesn't match the object. |
|
| 601 | + * |
|
| 602 | + * @final |
|
| 603 | + * @return void |
|
| 604 | + * @throws EE_Error |
|
| 605 | + * @throws InvalidArgumentException |
|
| 606 | + * @throws ReflectionException |
|
| 607 | + * @throws InvalidDataTypeException |
|
| 608 | + * @throws InvalidInterfaceException |
|
| 609 | + */ |
|
| 610 | + final protected function _page_setup() |
|
| 611 | + { |
|
| 612 | + // requires? |
|
| 613 | + // admin_init stuff - global - we're setting this REALLY early |
|
| 614 | + // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 615 | + // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 616 | + add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 617 | + // next verify if we need to load anything... |
|
| 618 | + $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 619 | + $this->page_folder = strtolower( |
|
| 620 | + str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
| 621 | + ); |
|
| 622 | + global $ee_menu_slugs; |
|
| 623 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 624 | + if ( |
|
| 625 | + ! $this->request->isAjax() |
|
| 626 | + && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 627 | + ) { |
|
| 628 | + return; |
|
| 629 | + } |
|
| 630 | + // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 631 | + // we need to copy the action from the second to the first |
|
| 632 | + $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 633 | + $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 634 | + $action = $action !== '-1' ? $action : $action2; |
|
| 635 | + $req_action = $action !== '-1' ? $action : 'default'; |
|
| 636 | + |
|
| 637 | + // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 638 | + // then let's use the route as the action. |
|
| 639 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 640 | + $route = $this->request->getRequestParam('route'); |
|
| 641 | + $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 642 | + ? $route |
|
| 643 | + : $req_action; |
|
| 644 | + |
|
| 645 | + $this->_current_view = $this->_req_action; |
|
| 646 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 647 | + $this->_define_page_props(); |
|
| 648 | + $this->_current_page_view_url = add_query_arg( |
|
| 649 | + ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 650 | + $this->_admin_base_url |
|
| 651 | + ); |
|
| 652 | + // default things |
|
| 653 | + $this->_default_espresso_metaboxes = [ |
|
| 654 | + '_espresso_news_post_box', |
|
| 655 | + '_espresso_links_post_box', |
|
| 656 | + '_espresso_ratings_request', |
|
| 657 | + '_espresso_sponsors_post_box', |
|
| 658 | + ]; |
|
| 659 | + // set page configs |
|
| 660 | + $this->_set_page_routes(); |
|
| 661 | + $this->_set_page_config(); |
|
| 662 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 663 | + if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 664 | + $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 665 | + if ($wp_referer) { |
|
| 666 | + $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + // for caffeinated and other extended functionality. |
|
| 670 | + // If there is a _extend_page_config method |
|
| 671 | + // then let's run that to modify the all the various page configuration arrays |
|
| 672 | + if (method_exists($this, '_extend_page_config')) { |
|
| 673 | + $this->_extend_page_config(); |
|
| 674 | + } |
|
| 675 | + // for CPT and other extended functionality. |
|
| 676 | + // If there is an _extend_page_config_for_cpt |
|
| 677 | + // then let's run that to modify all the various page configuration arrays. |
|
| 678 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 679 | + $this->_extend_page_config_for_cpt(); |
|
| 680 | + } |
|
| 681 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 682 | + $this->_page_routes = apply_filters( |
|
| 683 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 684 | + $this->_page_routes, |
|
| 685 | + $this |
|
| 686 | + ); |
|
| 687 | + $this->_page_config = apply_filters( |
|
| 688 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 689 | + $this->_page_config, |
|
| 690 | + $this |
|
| 691 | + ); |
|
| 692 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 693 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 694 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 695 | + add_action( |
|
| 696 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 697 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 698 | + 10, |
|
| 699 | + 2 |
|
| 700 | + ); |
|
| 701 | + } |
|
| 702 | + // next route only if routing enabled |
|
| 703 | + if ($this->_routing && ! $this->request->isAjax()) { |
|
| 704 | + $this->_verify_routes(); |
|
| 705 | + // next let's just check user_access and kill if no access |
|
| 706 | + $this->check_user_access(); |
|
| 707 | + if ($this->_is_UI_request) { |
|
| 708 | + // admin_init stuff - global, all views for this page class, specific view |
|
| 709 | + add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 710 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 711 | + add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 712 | + } |
|
| 713 | + } else { |
|
| 714 | + // hijack regular WP loading and route admin request immediately |
|
| 715 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 716 | + $this->route_admin_request(); |
|
| 717 | + } |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 724 | + * |
|
| 725 | + * @return void |
|
| 726 | + * @throws EE_Error |
|
| 727 | + */ |
|
| 728 | + private function _do_other_page_hooks() |
|
| 729 | + { |
|
| 730 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 731 | + foreach ($registered_pages as $page) { |
|
| 732 | + // now let's setup the file name and class that should be present |
|
| 733 | + $classname = str_replace('.class.php', '', $page); |
|
| 734 | + // autoloaders should take care of loading file |
|
| 735 | + if (! class_exists($classname)) { |
|
| 736 | + $error_msg[] = sprintf( |
|
| 737 | + esc_html__( |
|
| 738 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 739 | + 'event_espresso' |
|
| 740 | + ), |
|
| 741 | + $page |
|
| 742 | + ); |
|
| 743 | + $error_msg[] = $error_msg[0] |
|
| 744 | + . "\r\n" |
|
| 745 | + . sprintf( |
|
| 746 | + esc_html__( |
|
| 747 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 748 | + 'event_espresso' |
|
| 749 | + ), |
|
| 750 | + $page, |
|
| 751 | + '<br />', |
|
| 752 | + '<strong>' . $classname . '</strong>' |
|
| 753 | + ); |
|
| 754 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 755 | + } |
|
| 756 | + // notice we are passing the instance of this class to the hook object. |
|
| 757 | + $this->loader->getShared($classname, [$this]); |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * @throws ReflectionException |
|
| 764 | + * @throws EE_Error |
|
| 765 | + */ |
|
| 766 | + public function load_page_dependencies() |
|
| 767 | + { |
|
| 768 | + try { |
|
| 769 | + $this->_load_page_dependencies(); |
|
| 770 | + } catch (EE_Error $e) { |
|
| 771 | + $e->get_error(); |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * load_page_dependencies |
|
| 778 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 779 | + * |
|
| 780 | + * @return void |
|
| 781 | + * @throws DomainException |
|
| 782 | + * @throws EE_Error |
|
| 783 | + * @throws InvalidArgumentException |
|
| 784 | + * @throws InvalidDataTypeException |
|
| 785 | + * @throws InvalidInterfaceException |
|
| 786 | + */ |
|
| 787 | + protected function _load_page_dependencies() |
|
| 788 | + { |
|
| 789 | + // let's set the current_screen and screen options to override what WP set |
|
| 790 | + $this->_current_screen = get_current_screen(); |
|
| 791 | + // load admin_notices - global, page class, and view specific |
|
| 792 | + add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 793 | + add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 794 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 795 | + add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 796 | + } |
|
| 797 | + // load network admin_notices - global, page class, and view specific |
|
| 798 | + add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 799 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 800 | + add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 801 | + } |
|
| 802 | + // this will save any per_page screen options if they are present |
|
| 803 | + $this->_set_per_page_screen_options(); |
|
| 804 | + // setup list table properties |
|
| 805 | + $this->_set_list_table(); |
|
| 806 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 807 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 808 | + $this->_add_registered_meta_boxes(); |
|
| 809 | + $this->_add_screen_columns(); |
|
| 810 | + // add screen options - global, page child class, and view specific |
|
| 811 | + $this->_add_global_screen_options(); |
|
| 812 | + $this->_add_screen_options(); |
|
| 813 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 814 | + if (method_exists($this, $add_screen_options)) { |
|
| 815 | + $this->{$add_screen_options}(); |
|
| 816 | + } |
|
| 817 | + // add help tab(s) and tours- set via page_config and qtips. |
|
| 818 | + // $this->_add_help_tour(); |
|
| 819 | + $this->_add_help_tabs(); |
|
| 820 | + $this->_add_qtips(); |
|
| 821 | + // add feature_pointers - global, page child class, and view specific |
|
| 822 | + $this->_add_feature_pointers(); |
|
| 823 | + $this->_add_global_feature_pointers(); |
|
| 824 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 825 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 826 | + $this->{$add_feature_pointer}(); |
|
| 827 | + } |
|
| 828 | + // enqueue scripts/styles - global, page class, and view specific |
|
| 829 | + add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 830 | + add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 831 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 832 | + add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 833 | + } |
|
| 834 | + add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 835 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 836 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 837 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 838 | + // is a good use case. Notice the late priority we're giving these |
|
| 839 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 840 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 841 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 842 | + add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 843 | + } |
|
| 844 | + // admin footer scripts |
|
| 845 | + add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 846 | + add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 847 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 848 | + add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 849 | + } |
|
| 850 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 851 | + // targeted hook |
|
| 852 | + do_action( |
|
| 853 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 854 | + ); |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * _set_defaults |
|
| 860 | + * This sets some global defaults for class properties. |
|
| 861 | + */ |
|
| 862 | + private function _set_defaults() |
|
| 863 | + { |
|
| 864 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 865 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 866 | + $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 867 | + $this->_page_config = $this->_default_route_query_args = []; |
|
| 868 | + $this->_default_nav_tab_name = 'overview'; |
|
| 869 | + // init template args |
|
| 870 | + $this->_template_args = [ |
|
| 871 | + 'admin_page_header' => '', |
|
| 872 | + 'admin_page_content' => '', |
|
| 873 | + 'post_body_content' => '', |
|
| 874 | + 'before_list_table' => '', |
|
| 875 | + 'after_list_table' => '', |
|
| 876 | + ]; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * route_admin_request |
|
| 882 | + * |
|
| 883 | + * @return void |
|
| 884 | + * @throws InvalidArgumentException |
|
| 885 | + * @throws InvalidInterfaceException |
|
| 886 | + * @throws InvalidDataTypeException |
|
| 887 | + * @throws EE_Error |
|
| 888 | + * @throws ReflectionException |
|
| 889 | + * @see _route_admin_request() |
|
| 890 | + */ |
|
| 891 | + public function route_admin_request() |
|
| 892 | + { |
|
| 893 | + try { |
|
| 894 | + $this->_route_admin_request(); |
|
| 895 | + } catch (EE_Error $e) { |
|
| 896 | + $e->get_error(); |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + |
|
| 901 | + public function set_wp_page_slug($wp_page_slug) |
|
| 902 | + { |
|
| 903 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 904 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 905 | + if (is_network_admin()) { |
|
| 906 | + $this->_wp_page_slug .= '-network'; |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + |
|
| 911 | + /** |
|
| 912 | + * _verify_routes |
|
| 913 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 914 | + * we know if we need to drop out. |
|
| 915 | + * |
|
| 916 | + * @return bool |
|
| 917 | + * @throws EE_Error |
|
| 918 | + */ |
|
| 919 | + protected function _verify_routes() |
|
| 920 | + { |
|
| 921 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 922 | + if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 923 | + return false; |
|
| 924 | + } |
|
| 925 | + $this->_route = false; |
|
| 926 | + // check that the page_routes array is not empty |
|
| 927 | + if (empty($this->_page_routes)) { |
|
| 928 | + // user error msg |
|
| 929 | + $error_msg = sprintf( |
|
| 930 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 931 | + $this->_admin_page_title |
|
| 932 | + ); |
|
| 933 | + // developer error msg |
|
| 934 | + $error_msg .= '||' . $error_msg |
|
| 935 | + . esc_html__( |
|
| 936 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 937 | + 'event_espresso' |
|
| 938 | + ); |
|
| 939 | + throw new EE_Error($error_msg); |
|
| 940 | + } |
|
| 941 | + // and that the requested page route exists |
|
| 942 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 943 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 944 | + $this->_route_config = $this->_page_config[ $this->_req_action ] ?? []; |
|
| 945 | + } else { |
|
| 946 | + // user error msg |
|
| 947 | + $error_msg = sprintf( |
|
| 948 | + esc_html__( |
|
| 949 | + 'The requested page route does not exist for the %s admin page.', |
|
| 950 | + 'event_espresso' |
|
| 951 | + ), |
|
| 952 | + $this->_admin_page_title |
|
| 953 | + ); |
|
| 954 | + // developer error msg |
|
| 955 | + $error_msg .= '||' . $error_msg |
|
| 956 | + . sprintf( |
|
| 957 | + esc_html__( |
|
| 958 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 959 | + 'event_espresso' |
|
| 960 | + ), |
|
| 961 | + $this->_req_action |
|
| 962 | + ); |
|
| 963 | + throw new EE_Error($error_msg); |
|
| 964 | + } |
|
| 965 | + // and that a default route exists |
|
| 966 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 967 | + // user error msg |
|
| 968 | + $error_msg = sprintf( |
|
| 969 | + esc_html__( |
|
| 970 | + 'A default page route has not been set for the % admin page.', |
|
| 971 | + 'event_espresso' |
|
| 972 | + ), |
|
| 973 | + $this->_admin_page_title |
|
| 974 | + ); |
|
| 975 | + // developer error msg |
|
| 976 | + $error_msg .= '||' . $error_msg |
|
| 977 | + . esc_html__( |
|
| 978 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 979 | + 'event_espresso' |
|
| 980 | + ); |
|
| 981 | + throw new EE_Error($error_msg); |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + // first lets' catch if the UI request has EVER been set. |
|
| 985 | + if ($this->_is_UI_request === null) { |
|
| 986 | + // lets set if this is a UI request or not. |
|
| 987 | + $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 988 | + // wait a minute... we might have a noheader in the route array |
|
| 989 | + $this->_is_UI_request = ! ( |
|
| 990 | + is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 991 | + ) |
|
| 992 | + ? $this->_is_UI_request |
|
| 993 | + : false; |
|
| 994 | + } |
|
| 995 | + $this->_set_current_labels(); |
|
| 996 | + return true; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + |
|
| 1000 | + /** |
|
| 1001 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 1002 | + * |
|
| 1003 | + * @param string $route the route name we're verifying |
|
| 1004 | + * @return bool we'll throw an exception if this isn't a valid route. |
|
| 1005 | + * @throws EE_Error |
|
| 1006 | + */ |
|
| 1007 | + protected function _verify_route($route) |
|
| 1008 | + { |
|
| 1009 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 1010 | + return true; |
|
| 1011 | + } |
|
| 1012 | + // user error msg |
|
| 1013 | + $error_msg = sprintf( |
|
| 1014 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 1015 | + $this->_admin_page_title |
|
| 1016 | + ); |
|
| 1017 | + // developer error msg |
|
| 1018 | + $error_msg .= '||' . $error_msg |
|
| 1019 | + . sprintf( |
|
| 1020 | + esc_html__( |
|
| 1021 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 1022 | + 'event_espresso' |
|
| 1023 | + ), |
|
| 1024 | + $route |
|
| 1025 | + ); |
|
| 1026 | + throw new EE_Error($error_msg); |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * perform nonce verification |
|
| 1032 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 1033 | + * using this method (and save retyping!) |
|
| 1034 | + * |
|
| 1035 | + * @param string $nonce The nonce sent |
|
| 1036 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 1037 | + * @return void |
|
| 1038 | + * @throws EE_Error |
|
| 1039 | + * @throws InvalidArgumentException |
|
| 1040 | + * @throws InvalidDataTypeException |
|
| 1041 | + * @throws InvalidInterfaceException |
|
| 1042 | + */ |
|
| 1043 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 1044 | + { |
|
| 1045 | + // verify nonce against expected value |
|
| 1046 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1047 | + // these are not the droids you are looking for !!! |
|
| 1048 | + $msg = sprintf( |
|
| 1049 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 1050 | + '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 1051 | + '</a>' |
|
| 1052 | + ); |
|
| 1053 | + if (WP_DEBUG) { |
|
| 1054 | + $msg .= "\n "; |
|
| 1055 | + $msg .= sprintf( |
|
| 1056 | + esc_html__( |
|
| 1057 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 1058 | + 'event_espresso' |
|
| 1059 | + ), |
|
| 1060 | + __CLASS__ |
|
| 1061 | + ); |
|
| 1062 | + } |
|
| 1063 | + if (! $this->request->isAjax()) { |
|
| 1064 | + wp_die($msg); |
|
| 1065 | + } |
|
| 1066 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1067 | + $this->_return_json(); |
|
| 1068 | + } |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + |
|
| 1072 | + /** |
|
| 1073 | + * _route_admin_request() |
|
| 1074 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if there are |
|
| 1075 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 1076 | + * in the page routes and then will try to load the corresponding method. |
|
| 1077 | + * |
|
| 1078 | + * @return void |
|
| 1079 | + * @throws EE_Error |
|
| 1080 | + * @throws InvalidArgumentException |
|
| 1081 | + * @throws InvalidDataTypeException |
|
| 1082 | + * @throws InvalidInterfaceException |
|
| 1083 | + * @throws ReflectionException |
|
| 1084 | + */ |
|
| 1085 | + protected function _route_admin_request() |
|
| 1086 | + { |
|
| 1087 | + if (! $this->_is_UI_request) { |
|
| 1088 | + $this->_verify_routes(); |
|
| 1089 | + } |
|
| 1090 | + $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 1091 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1092 | + // set nonce from post data |
|
| 1093 | + $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 1094 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1095 | + } |
|
| 1096 | + // set the nav_tabs array but ONLY if this is UI_request |
|
| 1097 | + if ($this->_is_UI_request) { |
|
| 1098 | + $this->_set_nav_tabs(); |
|
| 1099 | + } |
|
| 1100 | + // grab callback function |
|
| 1101 | + $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route; |
|
| 1102 | + // check if callback has args |
|
| 1103 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 1104 | + $error_msg = ''; |
|
| 1105 | + // action right before calling route |
|
| 1106 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1107 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1108 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1109 | + } |
|
| 1110 | + // right before calling the route, let's clean the _wp_http_referer |
|
| 1111 | + $this->request->setServerParam( |
|
| 1112 | + 'REQUEST_URI', |
|
| 1113 | + remove_query_arg( |
|
| 1114 | + '_wp_http_referer', |
|
| 1115 | + wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1116 | + ) |
|
| 1117 | + ); |
|
| 1118 | + if (! empty($func)) { |
|
| 1119 | + if (is_array($func)) { |
|
| 1120 | + [$class, $method] = $func; |
|
| 1121 | + } elseif (strpos($func, '::') !== false) { |
|
| 1122 | + [$class, $method] = explode('::', $func); |
|
| 1123 | + } else { |
|
| 1124 | + $class = $this; |
|
| 1125 | + $method = $func; |
|
| 1126 | + } |
|
| 1127 | + if (! (is_object($class) && $class === $this)) { |
|
| 1128 | + // send along this admin page object for access by addons. |
|
| 1129 | + $args['admin_page_object'] = $this; |
|
| 1130 | + } |
|
| 1131 | + if ( |
|
| 1132 | + // is it a method on a class that doesn't work? |
|
| 1133 | + ( |
|
| 1134 | + ( |
|
| 1135 | + method_exists($class, $method) |
|
| 1136 | + && call_user_func_array([$class, $method], $args) === false |
|
| 1137 | + ) |
|
| 1138 | + && ( |
|
| 1139 | + // is it a standalone function that doesn't work? |
|
| 1140 | + function_exists($method) |
|
| 1141 | + && call_user_func_array( |
|
| 1142 | + $func, |
|
| 1143 | + array_merge(['admin_page_object' => $this], $args) |
|
| 1144 | + ) === false |
|
| 1145 | + ) |
|
| 1146 | + ) |
|
| 1147 | + || ( |
|
| 1148 | + // is it neither a class method NOR a standalone function? |
|
| 1149 | + ! method_exists($class, $method) |
|
| 1150 | + && ! function_exists($method) |
|
| 1151 | + ) |
|
| 1152 | + ) { |
|
| 1153 | + // user error msg |
|
| 1154 | + $error_msg = esc_html__( |
|
| 1155 | + 'An error occurred. The requested page route could not be found.', |
|
| 1156 | + 'event_espresso' |
|
| 1157 | + ); |
|
| 1158 | + // developer error msg |
|
| 1159 | + $error_msg .= '||'; |
|
| 1160 | + $error_msg .= sprintf( |
|
| 1161 | + esc_html__( |
|
| 1162 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1163 | + 'event_espresso' |
|
| 1164 | + ), |
|
| 1165 | + $method |
|
| 1166 | + ); |
|
| 1167 | + } |
|
| 1168 | + if (! empty($error_msg)) { |
|
| 1169 | + throw new EE_Error($error_msg); |
|
| 1170 | + } |
|
| 1171 | + } |
|
| 1172 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1173 | + // then we need to reset the routing properties to the new route. |
|
| 1174 | + // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1175 | + if ( |
|
| 1176 | + $this->_is_UI_request === false |
|
| 1177 | + && is_array($this->_route) |
|
| 1178 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1179 | + ) { |
|
| 1180 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1181 | + } |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1187 | + * route redirects to a headers route in its route config. |
|
| 1188 | + * |
|
| 1189 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1190 | + * @return void |
|
| 1191 | + * @throws ReflectionException |
|
| 1192 | + * @throws InvalidArgumentException |
|
| 1193 | + * @throws InvalidInterfaceException |
|
| 1194 | + * @throws InvalidDataTypeException |
|
| 1195 | + * @throws EE_Error |
|
| 1196 | + * @since 4.3.0 |
|
| 1197 | + */ |
|
| 1198 | + protected function _reset_routing_properties($new_route) |
|
| 1199 | + { |
|
| 1200 | + $this->_is_UI_request = true; |
|
| 1201 | + // now we set the current route to whatever the headers_sent_route is set at |
|
| 1202 | + $this->request->setRequestParam('action', $new_route); |
|
| 1203 | + // rerun page setup |
|
| 1204 | + $this->_page_setup(); |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * _add_query_arg |
|
| 1210 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1211 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1212 | + * |
|
| 1213 | + * @param array $args |
|
| 1214 | + * @param string $url |
|
| 1215 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1216 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1217 | + * Example usage: If the current page is: |
|
| 1218 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1219 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1220 | + * &_wpnonce=5467821 |
|
| 1221 | + * and you call: |
|
| 1222 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1223 | + * array( |
|
| 1224 | + * 'action' => 'resend_something', |
|
| 1225 | + * 'page=>espresso_registrations' |
|
| 1226 | + * ), |
|
| 1227 | + * $some_url, |
|
| 1228 | + * true |
|
| 1229 | + * ); |
|
| 1230 | + * It will produce a url in this structure: |
|
| 1231 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1232 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1233 | + * month_range]=March%202015 |
|
| 1234 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1235 | + * @return string |
|
| 1236 | + */ |
|
| 1237 | + public static function add_query_args_and_nonce( |
|
| 1238 | + $args = [], |
|
| 1239 | + $url = '', |
|
| 1240 | + $sticky = false, |
|
| 1241 | + $exclude_nonce = false |
|
| 1242 | + ) { |
|
| 1243 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1244 | + if ($sticky) { |
|
| 1245 | + /** @var RequestInterface $request */ |
|
| 1246 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1247 | + $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']); |
|
| 1248 | + foreach ($request->requestParams() as $key => $value) { |
|
| 1249 | + // do not add nonces |
|
| 1250 | + if (strpos($key, 'nonce') !== false) { |
|
| 1251 | + continue; |
|
| 1252 | + } |
|
| 1253 | + $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1254 | + } |
|
| 1255 | + } |
|
| 1256 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + |
|
| 1260 | + /** |
|
| 1261 | + * This returns a generated link that will load the related help tab. |
|
| 1262 | + * |
|
| 1263 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1264 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1265 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1266 | + * @return string generated link |
|
| 1267 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1268 | + */ |
|
| 1269 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1270 | + { |
|
| 1271 | + return EEH_Template::get_help_tab_link( |
|
| 1272 | + $help_tab_id, |
|
| 1273 | + $this->page_slug, |
|
| 1274 | + $this->_req_action, |
|
| 1275 | + $icon_style, |
|
| 1276 | + $help_text |
|
| 1277 | + ); |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * _add_help_tabs |
|
| 1283 | + * Note child classes define their help tabs within the page_config array. |
|
| 1284 | + * |
|
| 1285 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1286 | + * @return void |
|
| 1287 | + * @throws DomainException |
|
| 1288 | + * @throws EE_Error |
|
| 1289 | + * @throws ReflectionException |
|
| 1290 | + */ |
|
| 1291 | + protected function _add_help_tabs() |
|
| 1292 | + { |
|
| 1293 | + $tour_buttons = ''; |
|
| 1294 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1295 | + $config = $this->_page_config[ $this->_req_action ]; |
|
| 1296 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1297 | + // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1298 | + // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1299 | + // $tb = array(); |
|
| 1300 | + // $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1301 | + // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1302 | + // // if this is the end tour then we don't need to setup a button |
|
| 1303 | + // if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1304 | + // continue; |
|
| 1305 | + // } |
|
| 1306 | + // $tb[] = '<button id="trigger-tour-' |
|
| 1307 | + // . $tour->get_slug() |
|
| 1308 | + // . '" class="button--primary trigger-ee-help-tour">' |
|
| 1309 | + // . $tour->get_label() |
|
| 1310 | + // . '</button>'; |
|
| 1311 | + // } |
|
| 1312 | + // $tour_buttons .= implode('<br />', $tb); |
|
| 1313 | + // $tour_buttons .= '</div></div>'; |
|
| 1314 | + // } |
|
| 1315 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1316 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1317 | + // check that the callback given is valid |
|
| 1318 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1319 | + throw new EE_Error( |
|
| 1320 | + sprintf( |
|
| 1321 | + esc_html__( |
|
| 1322 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1323 | + 'event_espresso' |
|
| 1324 | + ), |
|
| 1325 | + $config['help_sidebar'], |
|
| 1326 | + get_class($this) |
|
| 1327 | + ) |
|
| 1328 | + ); |
|
| 1329 | + } |
|
| 1330 | + $content = apply_filters( |
|
| 1331 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1332 | + $this->{$config['help_sidebar']}() |
|
| 1333 | + ); |
|
| 1334 | + $content .= $tour_buttons; // add help tour buttons. |
|
| 1335 | + // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1336 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1337 | + } |
|
| 1338 | + // if there ARE tour buttons... |
|
| 1339 | + if (! empty($tour_buttons)) { |
|
| 1340 | + // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar. |
|
| 1341 | + if (! isset($config['help_sidebar'])) { |
|
| 1342 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1343 | + } |
|
| 1344 | + // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1345 | + if (! isset($config['help_tabs'])) { |
|
| 1346 | + $_ht['id'] = $this->page_slug; |
|
| 1347 | + $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1348 | + $_ht['content'] = '<p>' |
|
| 1349 | + . esc_html__( |
|
| 1350 | + 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1351 | + 'event_espresso' |
|
| 1352 | + ) . '</p>'; |
|
| 1353 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | + if (! isset($config['help_tabs'])) { |
|
| 1357 | + return; |
|
| 1358 | + } //no help tabs for this route |
|
| 1359 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1360 | + // we're here so there ARE help tabs! |
|
| 1361 | + // make sure we've got what we need |
|
| 1362 | + if (! isset($cfg['title'])) { |
|
| 1363 | + throw new EE_Error( |
|
| 1364 | + esc_html__( |
|
| 1365 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1366 | + 'event_espresso' |
|
| 1367 | + ) |
|
| 1368 | + ); |
|
| 1369 | + } |
|
| 1370 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1371 | + throw new EE_Error( |
|
| 1372 | + esc_html__( |
|
| 1373 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1374 | + 'event_espresso' |
|
| 1375 | + ) |
|
| 1376 | + ); |
|
| 1377 | + } |
|
| 1378 | + // first priority goes to content. |
|
| 1379 | + if (! empty($cfg['content'])) { |
|
| 1380 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1381 | + // second priority goes to filename |
|
| 1382 | + } elseif (! empty($cfg['filename'])) { |
|
| 1383 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1384 | + // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1385 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1386 | + . basename($this->_get_dir()) |
|
| 1387 | + . '/help_tabs/' |
|
| 1388 | + . $cfg['filename'] |
|
| 1389 | + . '.help_tab.php' : $file_path; |
|
| 1390 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1391 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1392 | + EE_Error::add_error( |
|
| 1393 | + sprintf( |
|
| 1394 | + esc_html__( |
|
| 1395 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1396 | + 'event_espresso' |
|
| 1397 | + ), |
|
| 1398 | + $tab_id, |
|
| 1399 | + key($config), |
|
| 1400 | + $file_path |
|
| 1401 | + ), |
|
| 1402 | + __FILE__, |
|
| 1403 | + __FUNCTION__, |
|
| 1404 | + __LINE__ |
|
| 1405 | + ); |
|
| 1406 | + return; |
|
| 1407 | + } |
|
| 1408 | + $template_args['admin_page_obj'] = $this; |
|
| 1409 | + $content = EEH_Template::display_template( |
|
| 1410 | + $file_path, |
|
| 1411 | + $template_args, |
|
| 1412 | + true |
|
| 1413 | + ); |
|
| 1414 | + } else { |
|
| 1415 | + $content = ''; |
|
| 1416 | + } |
|
| 1417 | + // check if callback is valid |
|
| 1418 | + if ( |
|
| 1419 | + empty($content) |
|
| 1420 | + && ( |
|
| 1421 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1422 | + ) |
|
| 1423 | + ) { |
|
| 1424 | + EE_Error::add_error( |
|
| 1425 | + sprintf( |
|
| 1426 | + esc_html__( |
|
| 1427 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1428 | + 'event_espresso' |
|
| 1429 | + ), |
|
| 1430 | + $cfg['title'] |
|
| 1431 | + ), |
|
| 1432 | + __FILE__, |
|
| 1433 | + __FUNCTION__, |
|
| 1434 | + __LINE__ |
|
| 1435 | + ); |
|
| 1436 | + return; |
|
| 1437 | + } |
|
| 1438 | + // setup config array for help tab method |
|
| 1439 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1440 | + $_ht = [ |
|
| 1441 | + 'id' => $id, |
|
| 1442 | + 'title' => $cfg['title'], |
|
| 1443 | + 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1444 | + 'content' => $content, |
|
| 1445 | + ]; |
|
| 1446 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1447 | + } |
|
| 1448 | + } |
|
| 1449 | + } |
|
| 1450 | + |
|
| 1451 | + |
|
| 1452 | + /** |
|
| 1453 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1454 | + * an array with properties for setting up usage of the joyride plugin |
|
| 1455 | + * |
|
| 1456 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1457 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1458 | + * _set_page_config() comments |
|
| 1459 | + * @return void |
|
| 1460 | + * @throws InvalidArgumentException |
|
| 1461 | + * @throws InvalidDataTypeException |
|
| 1462 | + * @throws InvalidInterfaceException |
|
| 1463 | + * @throws ReflectionException |
|
| 1464 | + */ |
|
| 1465 | + protected function _add_help_tour() |
|
| 1466 | + { |
|
| 1467 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1468 | + // $tours = array(); |
|
| 1469 | + // $this->_help_tour = array(); |
|
| 1470 | + // // exit early if help tours are turned off globally |
|
| 1471 | + // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1472 | + // || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1473 | + // ) { |
|
| 1474 | + // return; |
|
| 1475 | + // } |
|
| 1476 | + // // loop through _page_config to find any help_tour defined |
|
| 1477 | + // foreach ($this->_page_config as $route => $config) { |
|
| 1478 | + // // we're only going to set things up for this route |
|
| 1479 | + // if ($route !== $this->_req_action) { |
|
| 1480 | + // continue; |
|
| 1481 | + // } |
|
| 1482 | + // if (isset($config['help_tour'])) { |
|
| 1483 | + // foreach ($config['help_tour'] as $tour) { |
|
| 1484 | + // $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1485 | + // // let's see if we can get that file... |
|
| 1486 | + // // if not its possible this is a decaf route not set in caffeinated |
|
| 1487 | + // // so lets try and get the caffeinated equivalent |
|
| 1488 | + // $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1489 | + // . basename($this->_get_dir()) |
|
| 1490 | + // . '/help_tours/' |
|
| 1491 | + // . $tour |
|
| 1492 | + // . '.class.php' : $file_path; |
|
| 1493 | + // // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1494 | + // if (! is_readable($file_path)) { |
|
| 1495 | + // EE_Error::add_error( |
|
| 1496 | + // sprintf( |
|
| 1497 | + // esc_html__( |
|
| 1498 | + // 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1499 | + // 'event_espresso' |
|
| 1500 | + // ), |
|
| 1501 | + // $file_path, |
|
| 1502 | + // $tour |
|
| 1503 | + // ), |
|
| 1504 | + // __FILE__, |
|
| 1505 | + // __FUNCTION__, |
|
| 1506 | + // __LINE__ |
|
| 1507 | + // ); |
|
| 1508 | + // return; |
|
| 1509 | + // } |
|
| 1510 | + // require_once $file_path; |
|
| 1511 | + // if (! class_exists($tour)) { |
|
| 1512 | + // $error_msg[] = sprintf( |
|
| 1513 | + // esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1514 | + // $tour |
|
| 1515 | + // ); |
|
| 1516 | + // $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1517 | + // . sprintf( |
|
| 1518 | + // esc_html__( |
|
| 1519 | + // 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1520 | + // 'event_espresso' |
|
| 1521 | + // ), |
|
| 1522 | + // $tour, |
|
| 1523 | + // '<br />', |
|
| 1524 | + // $tour, |
|
| 1525 | + // $this->_req_action, |
|
| 1526 | + // get_class($this) |
|
| 1527 | + // ); |
|
| 1528 | + // throw new EE_Error(implode('||', $error_msg)); |
|
| 1529 | + // } |
|
| 1530 | + // $tour_obj = new $tour($this->_is_caf); |
|
| 1531 | + // $tours[] = $tour_obj; |
|
| 1532 | + // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1533 | + // } |
|
| 1534 | + // // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1535 | + // $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1536 | + // $tours[] = $end_stop_tour; |
|
| 1537 | + // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1538 | + // } |
|
| 1539 | + // } |
|
| 1540 | + // |
|
| 1541 | + // if (! empty($tours)) { |
|
| 1542 | + // $this->_help_tour['tours'] = $tours; |
|
| 1543 | + // } |
|
| 1544 | + // // that's it! Now that the $_help_tours property is set (or not) |
|
| 1545 | + // // the scripts and html should be taken care of automatically. |
|
| 1546 | + // |
|
| 1547 | + // /** |
|
| 1548 | + // * Allow extending the help tours variable. |
|
| 1549 | + // * |
|
| 1550 | + // * @param Array $_help_tour The array containing all help tour information to be displayed. |
|
| 1551 | + // */ |
|
| 1552 | + // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour); |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1558 | + * |
|
| 1559 | + * @return void |
|
| 1560 | + * @throws ReflectionException |
|
| 1561 | + * @throws EE_Error |
|
| 1562 | + */ |
|
| 1563 | + protected function _add_qtips() |
|
| 1564 | + { |
|
| 1565 | + if (isset($this->_route_config['qtips'])) { |
|
| 1566 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1567 | + // load qtip loader |
|
| 1568 | + $path = [ |
|
| 1569 | + $this->_get_dir() . '/qtips/', |
|
| 1570 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1571 | + ]; |
|
| 1572 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1573 | + } |
|
| 1574 | + } |
|
| 1575 | + |
|
| 1576 | + |
|
| 1577 | + /** |
|
| 1578 | + * _set_nav_tabs |
|
| 1579 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1580 | + * wish to add additional tabs or modify accordingly. |
|
| 1581 | + * |
|
| 1582 | + * @return void |
|
| 1583 | + * @throws InvalidArgumentException |
|
| 1584 | + * @throws InvalidInterfaceException |
|
| 1585 | + * @throws InvalidDataTypeException |
|
| 1586 | + */ |
|
| 1587 | + protected function _set_nav_tabs() |
|
| 1588 | + { |
|
| 1589 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1590 | + $i = 0; |
|
| 1591 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1592 | + if (! is_array($config) || empty($config['nav'])) { |
|
| 1593 | + continue; |
|
| 1594 | + } |
|
| 1595 | + // no nav tab for this config |
|
| 1596 | + // check for persistent flag |
|
| 1597 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1598 | + // nav tab is only to appear when route requested. |
|
| 1599 | + continue; |
|
| 1600 | + } |
|
| 1601 | + if (! $this->check_user_access($slug, true)) { |
|
| 1602 | + // no nav tab because current user does not have access. |
|
| 1603 | + continue; |
|
| 1604 | + } |
|
| 1605 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1606 | + $this->_nav_tabs[ $slug ] = [ |
|
| 1607 | + 'url' => isset($config['nav']['url']) |
|
| 1608 | + ? $config['nav']['url'] |
|
| 1609 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1610 | + ['action' => $slug], |
|
| 1611 | + $this->_admin_base_url |
|
| 1612 | + ), |
|
| 1613 | + 'link_text' => isset($config['nav']['label']) |
|
| 1614 | + ? $config['nav']['label'] |
|
| 1615 | + : ucwords( |
|
| 1616 | + str_replace('_', ' ', $slug) |
|
| 1617 | + ), |
|
| 1618 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1619 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1620 | + ]; |
|
| 1621 | + $i++; |
|
| 1622 | + } |
|
| 1623 | + // if $this->_nav_tabs is empty then lets set the default |
|
| 1624 | + if (empty($this->_nav_tabs)) { |
|
| 1625 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1626 | + 'url' => $this->_admin_base_url, |
|
| 1627 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1628 | + 'css_class' => 'nav-tab-active', |
|
| 1629 | + 'order' => 10, |
|
| 1630 | + ]; |
|
| 1631 | + } |
|
| 1632 | + // now let's sort the tabs according to order |
|
| 1633 | + usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1634 | + } |
|
| 1635 | + |
|
| 1636 | + |
|
| 1637 | + /** |
|
| 1638 | + * _set_current_labels |
|
| 1639 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1640 | + * property array |
|
| 1641 | + * |
|
| 1642 | + * @return void |
|
| 1643 | + */ |
|
| 1644 | + private function _set_current_labels() |
|
| 1645 | + { |
|
| 1646 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1647 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1648 | + if (is_array($text)) { |
|
| 1649 | + foreach ($text as $sublabel => $subtext) { |
|
| 1650 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1651 | + } |
|
| 1652 | + } else { |
|
| 1653 | + $this->_labels[ $label ] = $text; |
|
| 1654 | + } |
|
| 1655 | + } |
|
| 1656 | + } |
|
| 1657 | + } |
|
| 1658 | + |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * verifies user access for this admin page |
|
| 1662 | + * |
|
| 1663 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1664 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1665 | + * return false if verify fail. |
|
| 1666 | + * @return bool |
|
| 1667 | + * @throws InvalidArgumentException |
|
| 1668 | + * @throws InvalidDataTypeException |
|
| 1669 | + * @throws InvalidInterfaceException |
|
| 1670 | + */ |
|
| 1671 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1672 | + { |
|
| 1673 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1674 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1675 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1676 | + && is_array( |
|
| 1677 | + $this->_page_routes[ $route_to_check ] |
|
| 1678 | + ) |
|
| 1679 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1680 | + ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1681 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1682 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1683 | + : $this->_route['capability']; |
|
| 1684 | + } else { |
|
| 1685 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1686 | + } |
|
| 1687 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1688 | + if ( |
|
| 1689 | + ! $this->request->isAjax() |
|
| 1690 | + && ( |
|
| 1691 | + ! function_exists('is_admin') |
|
| 1692 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1693 | + $capability, |
|
| 1694 | + $this->page_slug |
|
| 1695 | + . '_' |
|
| 1696 | + . $route_to_check, |
|
| 1697 | + $id |
|
| 1698 | + ) |
|
| 1699 | + ) |
|
| 1700 | + ) { |
|
| 1701 | + if ($verify_only) { |
|
| 1702 | + return false; |
|
| 1703 | + } |
|
| 1704 | + if (is_user_logged_in()) { |
|
| 1705 | + wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1706 | + } else { |
|
| 1707 | + return false; |
|
| 1708 | + } |
|
| 1709 | + } |
|
| 1710 | + return true; |
|
| 1711 | + } |
|
| 1712 | + |
|
| 1713 | + |
|
| 1714 | + protected function addMetaBox( |
|
| 1715 | + $box_id, |
|
| 1716 | + $title, |
|
| 1717 | + $callback, |
|
| 1718 | + $screen, |
|
| 1719 | + $context = 'normal', |
|
| 1720 | + $priority = 'default', |
|
| 1721 | + $callback_args = null |
|
| 1722 | + ) { |
|
| 1723 | + add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args); |
|
| 1724 | + add_filter( |
|
| 1725 | + "postbox_classes_{$this->_wp_page_slug}_{$box_id}", |
|
| 1726 | + function ($classes) { |
|
| 1727 | + array_push($classes, 'ee-admin-container'); |
|
| 1728 | + return $classes; |
|
| 1729 | + } |
|
| 1730 | + ); |
|
| 1731 | + } |
|
| 1732 | + |
|
| 1733 | + |
|
| 1734 | + /** |
|
| 1735 | + * admin_init_global |
|
| 1736 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1737 | + * This method executes for ALL EE Admin pages. |
|
| 1738 | + * |
|
| 1739 | + * @return void |
|
| 1740 | + */ |
|
| 1741 | + public function admin_init_global() |
|
| 1742 | + { |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + |
|
| 1746 | + /** |
|
| 1747 | + * wp_loaded_global |
|
| 1748 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1749 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1750 | + * |
|
| 1751 | + * @return void |
|
| 1752 | + */ |
|
| 1753 | + public function wp_loaded() |
|
| 1754 | + { |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + |
|
| 1758 | + /** |
|
| 1759 | + * admin_notices |
|
| 1760 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1761 | + * ALL EE_Admin pages. |
|
| 1762 | + * |
|
| 1763 | + * @return void |
|
| 1764 | + */ |
|
| 1765 | + public function admin_notices_global() |
|
| 1766 | + { |
|
| 1767 | + $this->_display_no_javascript_warning(); |
|
| 1768 | + $this->_display_espresso_notices(); |
|
| 1769 | + } |
|
| 1770 | + |
|
| 1771 | + |
|
| 1772 | + public function network_admin_notices_global() |
|
| 1773 | + { |
|
| 1774 | + $this->_display_no_javascript_warning(); |
|
| 1775 | + $this->_display_espresso_notices(); |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + |
|
| 1779 | + /** |
|
| 1780 | + * admin_footer_scripts_global |
|
| 1781 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1782 | + * will apply on ALL EE_Admin pages. |
|
| 1783 | + * |
|
| 1784 | + * @return void |
|
| 1785 | + */ |
|
| 1786 | + public function admin_footer_scripts_global() |
|
| 1787 | + { |
|
| 1788 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1789 | + $this->_add_admin_page_overlay(); |
|
| 1790 | + // if metaboxes are present we need to add the nonce field |
|
| 1791 | + if ( |
|
| 1792 | + isset($this->_route_config['metaboxes']) |
|
| 1793 | + || isset($this->_route_config['list_table']) |
|
| 1794 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1795 | + ) { |
|
| 1796 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1797 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1798 | + } |
|
| 1799 | + } |
|
| 1800 | + |
|
| 1801 | + |
|
| 1802 | + /** |
|
| 1803 | + * admin_footer_global |
|
| 1804 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. |
|
| 1805 | + * This particular method will apply on ALL EE_Admin Pages. |
|
| 1806 | + * |
|
| 1807 | + * @return void |
|
| 1808 | + */ |
|
| 1809 | + public function admin_footer_global() |
|
| 1810 | + { |
|
| 1811 | + // dialog container for dialog helper |
|
| 1812 | + echo ' |
|
| 1813 | 1813 | <div class="ee-admin-dialog-container auto-hide hidden"> |
| 1814 | 1814 | <div class="ee-notices"></div> |
| 1815 | 1815 | <div class="ee-admin-dialog-container-inner-content"></div> |
| 1816 | 1816 | </div> |
| 1817 | 1817 | '; |
| 1818 | 1818 | |
| 1819 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1820 | - // help tour stuff? |
|
| 1821 | - // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1822 | - // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1823 | - // } |
|
| 1824 | - // current set timezone for timezone js |
|
| 1825 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1831 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1832 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1833 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1834 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1835 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1836 | - * for the |
|
| 1837 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1838 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1839 | - * 'help_trigger_id' => array( |
|
| 1840 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1841 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1842 | - * ) |
|
| 1843 | - * ); |
|
| 1844 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1845 | - * |
|
| 1846 | - * @param array $help_array |
|
| 1847 | - * @param bool $display |
|
| 1848 | - * @return string content |
|
| 1849 | - * @throws DomainException |
|
| 1850 | - * @throws EE_Error |
|
| 1851 | - */ |
|
| 1852 | - protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1853 | - { |
|
| 1854 | - $content = ''; |
|
| 1855 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1856 | - // loop through the array and setup content |
|
| 1857 | - foreach ($help_array as $trigger => $help) { |
|
| 1858 | - // make sure the array is setup properly |
|
| 1859 | - if (! isset($help['title'], $help['content'])) { |
|
| 1860 | - throw new EE_Error( |
|
| 1861 | - esc_html__( |
|
| 1862 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1863 | - 'event_espresso' |
|
| 1864 | - ) |
|
| 1865 | - ); |
|
| 1866 | - } |
|
| 1867 | - // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1868 | - $template_args = [ |
|
| 1869 | - 'help_popup_id' => $trigger, |
|
| 1870 | - 'help_popup_title' => $help['title'], |
|
| 1871 | - 'help_popup_content' => $help['content'], |
|
| 1872 | - ]; |
|
| 1873 | - $content .= EEH_Template::display_template( |
|
| 1874 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1875 | - $template_args, |
|
| 1876 | - true |
|
| 1877 | - ); |
|
| 1878 | - } |
|
| 1879 | - if ($display) { |
|
| 1880 | - echo $content; // already escaped |
|
| 1881 | - return ''; |
|
| 1882 | - } |
|
| 1883 | - return $content; |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - |
|
| 1887 | - /** |
|
| 1888 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1889 | - * |
|
| 1890 | - * @return array properly formatted array for help popup content |
|
| 1891 | - * @throws EE_Error |
|
| 1892 | - */ |
|
| 1893 | - private function _get_help_content() |
|
| 1894 | - { |
|
| 1895 | - // what is the method we're looking for? |
|
| 1896 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1897 | - // if method doesn't exist let's get out. |
|
| 1898 | - if (! method_exists($this, $method_name)) { |
|
| 1899 | - return []; |
|
| 1900 | - } |
|
| 1901 | - // k we're good to go let's retrieve the help array |
|
| 1902 | - $help_array = $this->{$method_name}(); |
|
| 1903 | - // make sure we've got an array! |
|
| 1904 | - if (! is_array($help_array)) { |
|
| 1905 | - throw new EE_Error( |
|
| 1906 | - esc_html__( |
|
| 1907 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1908 | - 'event_espresso' |
|
| 1909 | - ) |
|
| 1910 | - ); |
|
| 1911 | - } |
|
| 1912 | - return $help_array; |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - |
|
| 1916 | - /** |
|
| 1917 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1918 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1919 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1920 | - * |
|
| 1921 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1922 | - * @param boolean $display if false then we return the trigger string |
|
| 1923 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1924 | - * @return string |
|
| 1925 | - * @throws DomainException |
|
| 1926 | - * @throws EE_Error |
|
| 1927 | - */ |
|
| 1928 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1929 | - { |
|
| 1930 | - if ($this->request->isAjax()) { |
|
| 1931 | - return ''; |
|
| 1932 | - } |
|
| 1933 | - // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1934 | - $help_array = $this->_get_help_content(); |
|
| 1935 | - $help_content = ''; |
|
| 1936 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1937 | - $help_array[ $trigger_id ] = [ |
|
| 1938 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1939 | - 'content' => esc_html__( |
|
| 1940 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1941 | - 'event_espresso' |
|
| 1942 | - ), |
|
| 1943 | - ]; |
|
| 1944 | - $help_content = $this->_set_help_popup_content($help_array); |
|
| 1945 | - } |
|
| 1946 | - // let's setup the trigger |
|
| 1947 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1948 | - . esc_attr($dimensions[0]) |
|
| 1949 | - . '&width=' |
|
| 1950 | - . esc_attr($dimensions[1]) |
|
| 1951 | - . '&inlineId=' |
|
| 1952 | - . esc_attr($trigger_id) |
|
| 1953 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1954 | - $content .= $help_content; |
|
| 1955 | - if ($display) { |
|
| 1956 | - echo $content; // already escaped |
|
| 1957 | - return ''; |
|
| 1958 | - } |
|
| 1959 | - return $content; |
|
| 1960 | - } |
|
| 1961 | - |
|
| 1962 | - |
|
| 1963 | - /** |
|
| 1964 | - * _add_global_screen_options |
|
| 1965 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1966 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1967 | - * |
|
| 1968 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1969 | - * see also WP_Screen object documents... |
|
| 1970 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1971 | - * @abstract |
|
| 1972 | - * @return void |
|
| 1973 | - */ |
|
| 1974 | - private function _add_global_screen_options() |
|
| 1975 | - { |
|
| 1976 | - } |
|
| 1977 | - |
|
| 1978 | - |
|
| 1979 | - /** |
|
| 1980 | - * _add_global_feature_pointers |
|
| 1981 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1982 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1983 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1984 | - * |
|
| 1985 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1986 | - * extended) also see: |
|
| 1987 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1988 | - * @abstract |
|
| 1989 | - * @return void |
|
| 1990 | - */ |
|
| 1991 | - private function _add_global_feature_pointers() |
|
| 1992 | - { |
|
| 1993 | - } |
|
| 1994 | - |
|
| 1995 | - |
|
| 1996 | - /** |
|
| 1997 | - * load_global_scripts_styles |
|
| 1998 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1999 | - * |
|
| 2000 | - * @return void |
|
| 2001 | - */ |
|
| 2002 | - public function load_global_scripts_styles() |
|
| 2003 | - { |
|
| 2004 | - // add debugging styles |
|
| 2005 | - if (WP_DEBUG) { |
|
| 2006 | - add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 2007 | - } |
|
| 2008 | - // taking care of metaboxes |
|
| 2009 | - if ( |
|
| 2010 | - empty($this->_cpt_route) |
|
| 2011 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2012 | - ) { |
|
| 2013 | - wp_enqueue_script('dashboard'); |
|
| 2014 | - } |
|
| 2015 | - |
|
| 2016 | - wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN); |
|
| 2017 | - // LOCALIZED DATA |
|
| 2018 | - // localize script for ajax lazy loading |
|
| 2019 | - wp_localize_script( |
|
| 2020 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 2021 | - 'eeLazyLoadingContainers', |
|
| 2022 | - apply_filters( |
|
| 2023 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2024 | - ['espresso_news_post_box_content'] |
|
| 2025 | - ) |
|
| 2026 | - ); |
|
| 2027 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 2028 | - // /** |
|
| 2029 | - // * help tour stuff |
|
| 2030 | - // */ |
|
| 2031 | - // if (! empty($this->_help_tour)) { |
|
| 2032 | - // // register the js for kicking things off |
|
| 2033 | - // wp_enqueue_script( |
|
| 2034 | - // 'ee-help-tour', |
|
| 2035 | - // EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2036 | - // array('jquery-joyride'), |
|
| 2037 | - // EVENT_ESPRESSO_VERSION, |
|
| 2038 | - // true |
|
| 2039 | - // ); |
|
| 2040 | - // $tours = array(); |
|
| 2041 | - // // setup tours for the js tour object |
|
| 2042 | - // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2043 | - // if ($tour instanceof EE_Help_Tour) { |
|
| 2044 | - // $tours[] = array( |
|
| 2045 | - // 'id' => $tour->get_slug(), |
|
| 2046 | - // 'options' => $tour->get_options(), |
|
| 2047 | - // ); |
|
| 2048 | - // } |
|
| 2049 | - // } |
|
| 2050 | - // wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2051 | - // // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2052 | - // } |
|
| 2053 | - |
|
| 2054 | - add_filter( |
|
| 2055 | - 'admin_body_class', |
|
| 2056 | - function ($classes) { |
|
| 2057 | - if (strpos($classes, 'espresso-admin') === false) { |
|
| 2058 | - $classes .= ' espresso-admin'; |
|
| 2059 | - } |
|
| 2060 | - return $classes; |
|
| 2061 | - } |
|
| 2062 | - ); |
|
| 2063 | - } |
|
| 2064 | - |
|
| 2065 | - |
|
| 2066 | - /** |
|
| 2067 | - * admin_footer_scripts_eei18n_js_strings |
|
| 2068 | - * |
|
| 2069 | - * @return void |
|
| 2070 | - */ |
|
| 2071 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 2072 | - { |
|
| 2073 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2074 | - EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 2075 | - __( |
|
| 2076 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2077 | - 'event_espresso' |
|
| 2078 | - ) |
|
| 2079 | - ); |
|
| 2080 | - EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 2081 | - EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 2082 | - EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 2083 | - EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 2084 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 2085 | - EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 2086 | - EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 2087 | - EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 2088 | - EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 2089 | - EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 2090 | - EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 2091 | - EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 2092 | - EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 2093 | - EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 2094 | - EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 2095 | - EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 2096 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 2097 | - EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 2098 | - EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 2099 | - EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 2100 | - EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 2101 | - EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 2102 | - EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 2103 | - EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 2104 | - EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 2105 | - EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 2106 | - EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 2107 | - EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 2108 | - EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 2109 | - EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 2110 | - EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 2111 | - EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 2112 | - EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 2113 | - EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 2114 | - EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 2115 | - EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 2116 | - EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 2117 | - EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 2118 | - } |
|
| 2119 | - |
|
| 2120 | - |
|
| 2121 | - /** |
|
| 2122 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2123 | - * |
|
| 2124 | - * @return void |
|
| 2125 | - */ |
|
| 2126 | - public function add_xdebug_style() |
|
| 2127 | - { |
|
| 2128 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2129 | - } |
|
| 2130 | - |
|
| 2131 | - |
|
| 2132 | - /************************/ |
|
| 2133 | - /** LIST TABLE METHODS **/ |
|
| 2134 | - /************************/ |
|
| 2135 | - /** |
|
| 2136 | - * this sets up the list table if the current view requires it. |
|
| 2137 | - * |
|
| 2138 | - * @return void |
|
| 2139 | - * @throws EE_Error |
|
| 2140 | - * @throws InvalidArgumentException |
|
| 2141 | - * @throws InvalidDataTypeException |
|
| 2142 | - * @throws InvalidInterfaceException |
|
| 2143 | - */ |
|
| 2144 | - protected function _set_list_table() |
|
| 2145 | - { |
|
| 2146 | - // first is this a list_table view? |
|
| 2147 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2148 | - return; |
|
| 2149 | - } //not a list_table view so get out. |
|
| 2150 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2151 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2152 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2153 | - // user error msg |
|
| 2154 | - $error_msg = esc_html__( |
|
| 2155 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2156 | - 'event_espresso' |
|
| 2157 | - ); |
|
| 2158 | - // developer error msg |
|
| 2159 | - $error_msg .= '||' |
|
| 2160 | - . sprintf( |
|
| 2161 | - esc_html__( |
|
| 2162 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2163 | - 'event_espresso' |
|
| 2164 | - ), |
|
| 2165 | - $this->_req_action, |
|
| 2166 | - $list_table_view |
|
| 2167 | - ); |
|
| 2168 | - throw new EE_Error($error_msg); |
|
| 2169 | - } |
|
| 2170 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2171 | - $this->_views = apply_filters( |
|
| 2172 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2173 | - $this->_views |
|
| 2174 | - ); |
|
| 2175 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2176 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2177 | - $this->_set_list_table_view(); |
|
| 2178 | - $this->_set_list_table_object(); |
|
| 2179 | - } |
|
| 2180 | - |
|
| 2181 | - |
|
| 2182 | - /** |
|
| 2183 | - * set current view for List Table |
|
| 2184 | - * |
|
| 2185 | - * @return void |
|
| 2186 | - */ |
|
| 2187 | - protected function _set_list_table_view() |
|
| 2188 | - { |
|
| 2189 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2190 | - $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 2191 | - $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 2192 | - ? $status |
|
| 2193 | - : $this->_view; |
|
| 2194 | - } |
|
| 2195 | - |
|
| 2196 | - |
|
| 2197 | - /** |
|
| 2198 | - * _set_list_table_object |
|
| 2199 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2200 | - * |
|
| 2201 | - * @throws InvalidInterfaceException |
|
| 2202 | - * @throws InvalidArgumentException |
|
| 2203 | - * @throws InvalidDataTypeException |
|
| 2204 | - * @throws EE_Error |
|
| 2205 | - * @throws InvalidInterfaceException |
|
| 2206 | - */ |
|
| 2207 | - protected function _set_list_table_object() |
|
| 2208 | - { |
|
| 2209 | - if (isset($this->_route_config['list_table'])) { |
|
| 2210 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2211 | - throw new EE_Error( |
|
| 2212 | - sprintf( |
|
| 2213 | - esc_html__( |
|
| 2214 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2215 | - 'event_espresso' |
|
| 2216 | - ), |
|
| 2217 | - $this->_route_config['list_table'], |
|
| 2218 | - get_class($this) |
|
| 2219 | - ) |
|
| 2220 | - ); |
|
| 2221 | - } |
|
| 2222 | - $this->_list_table_object = $this->loader->getShared( |
|
| 2223 | - $this->_route_config['list_table'], |
|
| 2224 | - [$this] |
|
| 2225 | - ); |
|
| 2226 | - } |
|
| 2227 | - } |
|
| 2228 | - |
|
| 2229 | - |
|
| 2230 | - /** |
|
| 2231 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2232 | - * |
|
| 2233 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2234 | - * urls. The array should be indexed by the view it is being |
|
| 2235 | - * added to. |
|
| 2236 | - * @return array |
|
| 2237 | - */ |
|
| 2238 | - public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2239 | - { |
|
| 2240 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2241 | - if (empty($this->_views)) { |
|
| 2242 | - $this->_views = []; |
|
| 2243 | - } |
|
| 2244 | - // cycle thru views |
|
| 2245 | - foreach ($this->_views as $key => $view) { |
|
| 2246 | - $query_args = []; |
|
| 2247 | - // check for current view |
|
| 2248 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2249 | - $query_args['action'] = $this->_req_action; |
|
| 2250 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2251 | - $query_args['status'] = $view['slug']; |
|
| 2252 | - // merge any other arguments sent in. |
|
| 2253 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2254 | - foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) { |
|
| 2255 | - $query_args[] = $extra_query_arg; |
|
| 2256 | - } |
|
| 2257 | - } |
|
| 2258 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2259 | - } |
|
| 2260 | - return $this->_views; |
|
| 2261 | - } |
|
| 2262 | - |
|
| 2263 | - |
|
| 2264 | - /** |
|
| 2265 | - * _entries_per_page_dropdown |
|
| 2266 | - * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2267 | - * |
|
| 2268 | - * @param int $max_entries total number of rows in the table |
|
| 2269 | - * @return string |
|
| 2270 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2271 | - * WP does it. |
|
| 2272 | - */ |
|
| 2273 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2274 | - { |
|
| 2275 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2276 | - $values = [10, 25, 50, 100]; |
|
| 2277 | - $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2278 | - if ($max_entries) { |
|
| 2279 | - $values[] = $max_entries; |
|
| 2280 | - sort($values); |
|
| 2281 | - } |
|
| 2282 | - $entries_per_page_dropdown = ' |
|
| 1819 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1820 | + // help tour stuff? |
|
| 1821 | + // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1822 | + // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1823 | + // } |
|
| 1824 | + // current set timezone for timezone js |
|
| 1825 | + echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1831 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1832 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1833 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1834 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1835 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1836 | + * for the |
|
| 1837 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1838 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1839 | + * 'help_trigger_id' => array( |
|
| 1840 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1841 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1842 | + * ) |
|
| 1843 | + * ); |
|
| 1844 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1845 | + * |
|
| 1846 | + * @param array $help_array |
|
| 1847 | + * @param bool $display |
|
| 1848 | + * @return string content |
|
| 1849 | + * @throws DomainException |
|
| 1850 | + * @throws EE_Error |
|
| 1851 | + */ |
|
| 1852 | + protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1853 | + { |
|
| 1854 | + $content = ''; |
|
| 1855 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1856 | + // loop through the array and setup content |
|
| 1857 | + foreach ($help_array as $trigger => $help) { |
|
| 1858 | + // make sure the array is setup properly |
|
| 1859 | + if (! isset($help['title'], $help['content'])) { |
|
| 1860 | + throw new EE_Error( |
|
| 1861 | + esc_html__( |
|
| 1862 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1863 | + 'event_espresso' |
|
| 1864 | + ) |
|
| 1865 | + ); |
|
| 1866 | + } |
|
| 1867 | + // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1868 | + $template_args = [ |
|
| 1869 | + 'help_popup_id' => $trigger, |
|
| 1870 | + 'help_popup_title' => $help['title'], |
|
| 1871 | + 'help_popup_content' => $help['content'], |
|
| 1872 | + ]; |
|
| 1873 | + $content .= EEH_Template::display_template( |
|
| 1874 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1875 | + $template_args, |
|
| 1876 | + true |
|
| 1877 | + ); |
|
| 1878 | + } |
|
| 1879 | + if ($display) { |
|
| 1880 | + echo $content; // already escaped |
|
| 1881 | + return ''; |
|
| 1882 | + } |
|
| 1883 | + return $content; |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + |
|
| 1887 | + /** |
|
| 1888 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1889 | + * |
|
| 1890 | + * @return array properly formatted array for help popup content |
|
| 1891 | + * @throws EE_Error |
|
| 1892 | + */ |
|
| 1893 | + private function _get_help_content() |
|
| 1894 | + { |
|
| 1895 | + // what is the method we're looking for? |
|
| 1896 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1897 | + // if method doesn't exist let's get out. |
|
| 1898 | + if (! method_exists($this, $method_name)) { |
|
| 1899 | + return []; |
|
| 1900 | + } |
|
| 1901 | + // k we're good to go let's retrieve the help array |
|
| 1902 | + $help_array = $this->{$method_name}(); |
|
| 1903 | + // make sure we've got an array! |
|
| 1904 | + if (! is_array($help_array)) { |
|
| 1905 | + throw new EE_Error( |
|
| 1906 | + esc_html__( |
|
| 1907 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1908 | + 'event_espresso' |
|
| 1909 | + ) |
|
| 1910 | + ); |
|
| 1911 | + } |
|
| 1912 | + return $help_array; |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + |
|
| 1916 | + /** |
|
| 1917 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1918 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1919 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1920 | + * |
|
| 1921 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1922 | + * @param boolean $display if false then we return the trigger string |
|
| 1923 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1924 | + * @return string |
|
| 1925 | + * @throws DomainException |
|
| 1926 | + * @throws EE_Error |
|
| 1927 | + */ |
|
| 1928 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1929 | + { |
|
| 1930 | + if ($this->request->isAjax()) { |
|
| 1931 | + return ''; |
|
| 1932 | + } |
|
| 1933 | + // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1934 | + $help_array = $this->_get_help_content(); |
|
| 1935 | + $help_content = ''; |
|
| 1936 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1937 | + $help_array[ $trigger_id ] = [ |
|
| 1938 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1939 | + 'content' => esc_html__( |
|
| 1940 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1941 | + 'event_espresso' |
|
| 1942 | + ), |
|
| 1943 | + ]; |
|
| 1944 | + $help_content = $this->_set_help_popup_content($help_array); |
|
| 1945 | + } |
|
| 1946 | + // let's setup the trigger |
|
| 1947 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1948 | + . esc_attr($dimensions[0]) |
|
| 1949 | + . '&width=' |
|
| 1950 | + . esc_attr($dimensions[1]) |
|
| 1951 | + . '&inlineId=' |
|
| 1952 | + . esc_attr($trigger_id) |
|
| 1953 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1954 | + $content .= $help_content; |
|
| 1955 | + if ($display) { |
|
| 1956 | + echo $content; // already escaped |
|
| 1957 | + return ''; |
|
| 1958 | + } |
|
| 1959 | + return $content; |
|
| 1960 | + } |
|
| 1961 | + |
|
| 1962 | + |
|
| 1963 | + /** |
|
| 1964 | + * _add_global_screen_options |
|
| 1965 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1966 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1967 | + * |
|
| 1968 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1969 | + * see also WP_Screen object documents... |
|
| 1970 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1971 | + * @abstract |
|
| 1972 | + * @return void |
|
| 1973 | + */ |
|
| 1974 | + private function _add_global_screen_options() |
|
| 1975 | + { |
|
| 1976 | + } |
|
| 1977 | + |
|
| 1978 | + |
|
| 1979 | + /** |
|
| 1980 | + * _add_global_feature_pointers |
|
| 1981 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1982 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1983 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1984 | + * |
|
| 1985 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1986 | + * extended) also see: |
|
| 1987 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1988 | + * @abstract |
|
| 1989 | + * @return void |
|
| 1990 | + */ |
|
| 1991 | + private function _add_global_feature_pointers() |
|
| 1992 | + { |
|
| 1993 | + } |
|
| 1994 | + |
|
| 1995 | + |
|
| 1996 | + /** |
|
| 1997 | + * load_global_scripts_styles |
|
| 1998 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1999 | + * |
|
| 2000 | + * @return void |
|
| 2001 | + */ |
|
| 2002 | + public function load_global_scripts_styles() |
|
| 2003 | + { |
|
| 2004 | + // add debugging styles |
|
| 2005 | + if (WP_DEBUG) { |
|
| 2006 | + add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 2007 | + } |
|
| 2008 | + // taking care of metaboxes |
|
| 2009 | + if ( |
|
| 2010 | + empty($this->_cpt_route) |
|
| 2011 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2012 | + ) { |
|
| 2013 | + wp_enqueue_script('dashboard'); |
|
| 2014 | + } |
|
| 2015 | + |
|
| 2016 | + wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN); |
|
| 2017 | + // LOCALIZED DATA |
|
| 2018 | + // localize script for ajax lazy loading |
|
| 2019 | + wp_localize_script( |
|
| 2020 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 2021 | + 'eeLazyLoadingContainers', |
|
| 2022 | + apply_filters( |
|
| 2023 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2024 | + ['espresso_news_post_box_content'] |
|
| 2025 | + ) |
|
| 2026 | + ); |
|
| 2027 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 2028 | + // /** |
|
| 2029 | + // * help tour stuff |
|
| 2030 | + // */ |
|
| 2031 | + // if (! empty($this->_help_tour)) { |
|
| 2032 | + // // register the js for kicking things off |
|
| 2033 | + // wp_enqueue_script( |
|
| 2034 | + // 'ee-help-tour', |
|
| 2035 | + // EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2036 | + // array('jquery-joyride'), |
|
| 2037 | + // EVENT_ESPRESSO_VERSION, |
|
| 2038 | + // true |
|
| 2039 | + // ); |
|
| 2040 | + // $tours = array(); |
|
| 2041 | + // // setup tours for the js tour object |
|
| 2042 | + // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2043 | + // if ($tour instanceof EE_Help_Tour) { |
|
| 2044 | + // $tours[] = array( |
|
| 2045 | + // 'id' => $tour->get_slug(), |
|
| 2046 | + // 'options' => $tour->get_options(), |
|
| 2047 | + // ); |
|
| 2048 | + // } |
|
| 2049 | + // } |
|
| 2050 | + // wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2051 | + // // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2052 | + // } |
|
| 2053 | + |
|
| 2054 | + add_filter( |
|
| 2055 | + 'admin_body_class', |
|
| 2056 | + function ($classes) { |
|
| 2057 | + if (strpos($classes, 'espresso-admin') === false) { |
|
| 2058 | + $classes .= ' espresso-admin'; |
|
| 2059 | + } |
|
| 2060 | + return $classes; |
|
| 2061 | + } |
|
| 2062 | + ); |
|
| 2063 | + } |
|
| 2064 | + |
|
| 2065 | + |
|
| 2066 | + /** |
|
| 2067 | + * admin_footer_scripts_eei18n_js_strings |
|
| 2068 | + * |
|
| 2069 | + * @return void |
|
| 2070 | + */ |
|
| 2071 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 2072 | + { |
|
| 2073 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2074 | + EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 2075 | + __( |
|
| 2076 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2077 | + 'event_espresso' |
|
| 2078 | + ) |
|
| 2079 | + ); |
|
| 2080 | + EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 2081 | + EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 2082 | + EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 2083 | + EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 2084 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 2085 | + EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 2086 | + EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 2087 | + EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 2088 | + EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 2089 | + EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 2090 | + EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 2091 | + EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 2092 | + EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 2093 | + EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 2094 | + EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 2095 | + EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 2096 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 2097 | + EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 2098 | + EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 2099 | + EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 2100 | + EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 2101 | + EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 2102 | + EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 2103 | + EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 2104 | + EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 2105 | + EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 2106 | + EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 2107 | + EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 2108 | + EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 2109 | + EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 2110 | + EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 2111 | + EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 2112 | + EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 2113 | + EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 2114 | + EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 2115 | + EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 2116 | + EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 2117 | + EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 2118 | + } |
|
| 2119 | + |
|
| 2120 | + |
|
| 2121 | + /** |
|
| 2122 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2123 | + * |
|
| 2124 | + * @return void |
|
| 2125 | + */ |
|
| 2126 | + public function add_xdebug_style() |
|
| 2127 | + { |
|
| 2128 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2129 | + } |
|
| 2130 | + |
|
| 2131 | + |
|
| 2132 | + /************************/ |
|
| 2133 | + /** LIST TABLE METHODS **/ |
|
| 2134 | + /************************/ |
|
| 2135 | + /** |
|
| 2136 | + * this sets up the list table if the current view requires it. |
|
| 2137 | + * |
|
| 2138 | + * @return void |
|
| 2139 | + * @throws EE_Error |
|
| 2140 | + * @throws InvalidArgumentException |
|
| 2141 | + * @throws InvalidDataTypeException |
|
| 2142 | + * @throws InvalidInterfaceException |
|
| 2143 | + */ |
|
| 2144 | + protected function _set_list_table() |
|
| 2145 | + { |
|
| 2146 | + // first is this a list_table view? |
|
| 2147 | + if (! isset($this->_route_config['list_table'])) { |
|
| 2148 | + return; |
|
| 2149 | + } //not a list_table view so get out. |
|
| 2150 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2151 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2152 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2153 | + // user error msg |
|
| 2154 | + $error_msg = esc_html__( |
|
| 2155 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2156 | + 'event_espresso' |
|
| 2157 | + ); |
|
| 2158 | + // developer error msg |
|
| 2159 | + $error_msg .= '||' |
|
| 2160 | + . sprintf( |
|
| 2161 | + esc_html__( |
|
| 2162 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2163 | + 'event_espresso' |
|
| 2164 | + ), |
|
| 2165 | + $this->_req_action, |
|
| 2166 | + $list_table_view |
|
| 2167 | + ); |
|
| 2168 | + throw new EE_Error($error_msg); |
|
| 2169 | + } |
|
| 2170 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2171 | + $this->_views = apply_filters( |
|
| 2172 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2173 | + $this->_views |
|
| 2174 | + ); |
|
| 2175 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2176 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2177 | + $this->_set_list_table_view(); |
|
| 2178 | + $this->_set_list_table_object(); |
|
| 2179 | + } |
|
| 2180 | + |
|
| 2181 | + |
|
| 2182 | + /** |
|
| 2183 | + * set current view for List Table |
|
| 2184 | + * |
|
| 2185 | + * @return void |
|
| 2186 | + */ |
|
| 2187 | + protected function _set_list_table_view() |
|
| 2188 | + { |
|
| 2189 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2190 | + $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 2191 | + $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 2192 | + ? $status |
|
| 2193 | + : $this->_view; |
|
| 2194 | + } |
|
| 2195 | + |
|
| 2196 | + |
|
| 2197 | + /** |
|
| 2198 | + * _set_list_table_object |
|
| 2199 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2200 | + * |
|
| 2201 | + * @throws InvalidInterfaceException |
|
| 2202 | + * @throws InvalidArgumentException |
|
| 2203 | + * @throws InvalidDataTypeException |
|
| 2204 | + * @throws EE_Error |
|
| 2205 | + * @throws InvalidInterfaceException |
|
| 2206 | + */ |
|
| 2207 | + protected function _set_list_table_object() |
|
| 2208 | + { |
|
| 2209 | + if (isset($this->_route_config['list_table'])) { |
|
| 2210 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2211 | + throw new EE_Error( |
|
| 2212 | + sprintf( |
|
| 2213 | + esc_html__( |
|
| 2214 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2215 | + 'event_espresso' |
|
| 2216 | + ), |
|
| 2217 | + $this->_route_config['list_table'], |
|
| 2218 | + get_class($this) |
|
| 2219 | + ) |
|
| 2220 | + ); |
|
| 2221 | + } |
|
| 2222 | + $this->_list_table_object = $this->loader->getShared( |
|
| 2223 | + $this->_route_config['list_table'], |
|
| 2224 | + [$this] |
|
| 2225 | + ); |
|
| 2226 | + } |
|
| 2227 | + } |
|
| 2228 | + |
|
| 2229 | + |
|
| 2230 | + /** |
|
| 2231 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2232 | + * |
|
| 2233 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2234 | + * urls. The array should be indexed by the view it is being |
|
| 2235 | + * added to. |
|
| 2236 | + * @return array |
|
| 2237 | + */ |
|
| 2238 | + public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2239 | + { |
|
| 2240 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2241 | + if (empty($this->_views)) { |
|
| 2242 | + $this->_views = []; |
|
| 2243 | + } |
|
| 2244 | + // cycle thru views |
|
| 2245 | + foreach ($this->_views as $key => $view) { |
|
| 2246 | + $query_args = []; |
|
| 2247 | + // check for current view |
|
| 2248 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2249 | + $query_args['action'] = $this->_req_action; |
|
| 2250 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2251 | + $query_args['status'] = $view['slug']; |
|
| 2252 | + // merge any other arguments sent in. |
|
| 2253 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2254 | + foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) { |
|
| 2255 | + $query_args[] = $extra_query_arg; |
|
| 2256 | + } |
|
| 2257 | + } |
|
| 2258 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2259 | + } |
|
| 2260 | + return $this->_views; |
|
| 2261 | + } |
|
| 2262 | + |
|
| 2263 | + |
|
| 2264 | + /** |
|
| 2265 | + * _entries_per_page_dropdown |
|
| 2266 | + * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2267 | + * |
|
| 2268 | + * @param int $max_entries total number of rows in the table |
|
| 2269 | + * @return string |
|
| 2270 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2271 | + * WP does it. |
|
| 2272 | + */ |
|
| 2273 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2274 | + { |
|
| 2275 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2276 | + $values = [10, 25, 50, 100]; |
|
| 2277 | + $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2278 | + if ($max_entries) { |
|
| 2279 | + $values[] = $max_entries; |
|
| 2280 | + sort($values); |
|
| 2281 | + } |
|
| 2282 | + $entries_per_page_dropdown = ' |
|
| 2283 | 2283 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2284 | 2284 | <label class="hide-if-no-js"> |
| 2285 | 2285 | Show |
| 2286 | 2286 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2287 | - foreach ($values as $value) { |
|
| 2288 | - if ($value < $max_entries) { |
|
| 2289 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2290 | - $entries_per_page_dropdown .= ' |
|
| 2287 | + foreach ($values as $value) { |
|
| 2288 | + if ($value < $max_entries) { |
|
| 2289 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2290 | + $entries_per_page_dropdown .= ' |
|
| 2291 | 2291 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2292 | - } |
|
| 2293 | - } |
|
| 2294 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2295 | - $entries_per_page_dropdown .= ' |
|
| 2292 | + } |
|
| 2293 | + } |
|
| 2294 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2295 | + $entries_per_page_dropdown .= ' |
|
| 2296 | 2296 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2297 | - $entries_per_page_dropdown .= ' |
|
| 2297 | + $entries_per_page_dropdown .= ' |
|
| 2298 | 2298 | </select> |
| 2299 | 2299 | entries |
| 2300 | 2300 | </label> |
| 2301 | 2301 | <input id="entries-per-page-btn" class="button--secondary" type="submit" value="Go" > |
| 2302 | 2302 | </div> |
| 2303 | 2303 | '; |
| 2304 | - return $entries_per_page_dropdown; |
|
| 2305 | - } |
|
| 2306 | - |
|
| 2307 | - |
|
| 2308 | - /** |
|
| 2309 | - * _set_search_attributes |
|
| 2310 | - * |
|
| 2311 | - * @return void |
|
| 2312 | - */ |
|
| 2313 | - public function _set_search_attributes() |
|
| 2314 | - { |
|
| 2315 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2316 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2317 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2318 | - : $this->_search_btn_label |
|
| 2319 | - ); |
|
| 2320 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2321 | - } |
|
| 2322 | - |
|
| 2323 | - |
|
| 2324 | - |
|
| 2325 | - /*** END LIST TABLE METHODS **/ |
|
| 2326 | - |
|
| 2327 | - |
|
| 2328 | - /** |
|
| 2329 | - * _add_registered_metaboxes |
|
| 2330 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2331 | - * |
|
| 2332 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2333 | - * @return void |
|
| 2334 | - * @throws EE_Error |
|
| 2335 | - */ |
|
| 2336 | - private function _add_registered_meta_boxes() |
|
| 2337 | - { |
|
| 2338 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2339 | - // we only add meta boxes if the page_route calls for it |
|
| 2340 | - if ( |
|
| 2341 | - is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2342 | - && is_array( |
|
| 2343 | - $this->_route_config['metaboxes'] |
|
| 2344 | - ) |
|
| 2345 | - ) { |
|
| 2346 | - // this simply loops through the callbacks provided |
|
| 2347 | - // and checks if there is a corresponding callback registered by the child |
|
| 2348 | - // if there is then we go ahead and process the metabox loader. |
|
| 2349 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2350 | - // first check for Closures |
|
| 2351 | - if ($metabox_callback instanceof Closure) { |
|
| 2352 | - $result = $metabox_callback(); |
|
| 2353 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2354 | - $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2355 | - } else { |
|
| 2356 | - $result = $this->{$metabox_callback}(); |
|
| 2357 | - } |
|
| 2358 | - if ($result === false) { |
|
| 2359 | - // user error msg |
|
| 2360 | - $error_msg = esc_html__( |
|
| 2361 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2362 | - 'event_espresso' |
|
| 2363 | - ); |
|
| 2364 | - // developer error msg |
|
| 2365 | - $error_msg .= '||' |
|
| 2366 | - . sprintf( |
|
| 2367 | - esc_html__( |
|
| 2368 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2369 | - 'event_espresso' |
|
| 2370 | - ), |
|
| 2371 | - $metabox_callback |
|
| 2372 | - ); |
|
| 2373 | - throw new EE_Error($error_msg); |
|
| 2374 | - } |
|
| 2375 | - } |
|
| 2376 | - } |
|
| 2377 | - } |
|
| 2378 | - |
|
| 2379 | - |
|
| 2380 | - /** |
|
| 2381 | - * _add_screen_columns |
|
| 2382 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2383 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2384 | - * |
|
| 2385 | - * @return void |
|
| 2386 | - */ |
|
| 2387 | - private function _add_screen_columns() |
|
| 2388 | - { |
|
| 2389 | - if ( |
|
| 2390 | - is_array($this->_route_config) |
|
| 2391 | - && isset($this->_route_config['columns']) |
|
| 2392 | - && is_array($this->_route_config['columns']) |
|
| 2393 | - && count($this->_route_config['columns']) === 2 |
|
| 2394 | - ) { |
|
| 2395 | - add_screen_option( |
|
| 2396 | - 'layout_columns', |
|
| 2397 | - [ |
|
| 2398 | - 'max' => (int) $this->_route_config['columns'][0], |
|
| 2399 | - 'default' => (int) $this->_route_config['columns'][1], |
|
| 2400 | - ] |
|
| 2401 | - ); |
|
| 2402 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2403 | - $screen_id = $this->_current_screen->id; |
|
| 2404 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2405 | - $total_columns = ! empty($screen_columns) |
|
| 2406 | - ? $screen_columns |
|
| 2407 | - : $this->_route_config['columns'][1]; |
|
| 2408 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2409 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2410 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2411 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2412 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2413 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2414 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2415 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2416 | - } |
|
| 2417 | - } |
|
| 2418 | - |
|
| 2419 | - |
|
| 2420 | - |
|
| 2421 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2422 | - |
|
| 2423 | - |
|
| 2424 | - /** |
|
| 2425 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2426 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2427 | - * these get loaded on. |
|
| 2428 | - */ |
|
| 2429 | - private function _espresso_news_post_box() |
|
| 2430 | - { |
|
| 2431 | - $news_box_title = apply_filters( |
|
| 2432 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2433 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2434 | - ); |
|
| 2435 | - $this->addMetaBox( |
|
| 2436 | - 'espresso_news_post_box', |
|
| 2437 | - $news_box_title, |
|
| 2438 | - [ |
|
| 2439 | - $this, |
|
| 2440 | - 'espresso_news_post_box', |
|
| 2441 | - ], |
|
| 2442 | - $this->_wp_page_slug, |
|
| 2443 | - 'side' |
|
| 2444 | - ); |
|
| 2445 | - } |
|
| 2446 | - |
|
| 2447 | - |
|
| 2448 | - /** |
|
| 2449 | - * Code for setting up espresso ratings request metabox. |
|
| 2450 | - */ |
|
| 2451 | - protected function _espresso_ratings_request() |
|
| 2452 | - { |
|
| 2453 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2454 | - return; |
|
| 2455 | - } |
|
| 2456 | - $ratings_box_title = apply_filters( |
|
| 2457 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2458 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2459 | - ); |
|
| 2460 | - $this->addMetaBox( |
|
| 2461 | - 'espresso_ratings_request', |
|
| 2462 | - $ratings_box_title, |
|
| 2463 | - [ |
|
| 2464 | - $this, |
|
| 2465 | - 'espresso_ratings_request', |
|
| 2466 | - ], |
|
| 2467 | - $this->_wp_page_slug, |
|
| 2468 | - 'side' |
|
| 2469 | - ); |
|
| 2470 | - } |
|
| 2471 | - |
|
| 2472 | - |
|
| 2473 | - /** |
|
| 2474 | - * Code for setting up espresso ratings request metabox content. |
|
| 2475 | - * |
|
| 2476 | - * @throws DomainException |
|
| 2477 | - */ |
|
| 2478 | - public function espresso_ratings_request() |
|
| 2479 | - { |
|
| 2480 | - EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2481 | - } |
|
| 2482 | - |
|
| 2483 | - |
|
| 2484 | - public static function cached_rss_display($rss_id, $url) |
|
| 2485 | - { |
|
| 2486 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2487 | - . esc_html__('Loading…', 'event_espresso') |
|
| 2488 | - . '</p><p class="hide-if-js">' |
|
| 2489 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2490 | - . '</p>'; |
|
| 2491 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2492 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2493 | - $post = '</div>' . "\n"; |
|
| 2494 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2495 | - $output = get_transient($cache_key); |
|
| 2496 | - if ($output !== false) { |
|
| 2497 | - echo $pre . $output . $post; // already escaped |
|
| 2498 | - return true; |
|
| 2499 | - } |
|
| 2500 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2501 | - echo $pre . $loading . $post; // already escaped |
|
| 2502 | - return false; |
|
| 2503 | - } |
|
| 2504 | - ob_start(); |
|
| 2505 | - wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2506 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2507 | - return true; |
|
| 2508 | - } |
|
| 2509 | - |
|
| 2510 | - |
|
| 2511 | - public function espresso_news_post_box() |
|
| 2512 | - { |
|
| 2513 | - ?> |
|
| 2304 | + return $entries_per_page_dropdown; |
|
| 2305 | + } |
|
| 2306 | + |
|
| 2307 | + |
|
| 2308 | + /** |
|
| 2309 | + * _set_search_attributes |
|
| 2310 | + * |
|
| 2311 | + * @return void |
|
| 2312 | + */ |
|
| 2313 | + public function _set_search_attributes() |
|
| 2314 | + { |
|
| 2315 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2316 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2317 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2318 | + : $this->_search_btn_label |
|
| 2319 | + ); |
|
| 2320 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2321 | + } |
|
| 2322 | + |
|
| 2323 | + |
|
| 2324 | + |
|
| 2325 | + /*** END LIST TABLE METHODS **/ |
|
| 2326 | + |
|
| 2327 | + |
|
| 2328 | + /** |
|
| 2329 | + * _add_registered_metaboxes |
|
| 2330 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2331 | + * |
|
| 2332 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2333 | + * @return void |
|
| 2334 | + * @throws EE_Error |
|
| 2335 | + */ |
|
| 2336 | + private function _add_registered_meta_boxes() |
|
| 2337 | + { |
|
| 2338 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2339 | + // we only add meta boxes if the page_route calls for it |
|
| 2340 | + if ( |
|
| 2341 | + is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2342 | + && is_array( |
|
| 2343 | + $this->_route_config['metaboxes'] |
|
| 2344 | + ) |
|
| 2345 | + ) { |
|
| 2346 | + // this simply loops through the callbacks provided |
|
| 2347 | + // and checks if there is a corresponding callback registered by the child |
|
| 2348 | + // if there is then we go ahead and process the metabox loader. |
|
| 2349 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2350 | + // first check for Closures |
|
| 2351 | + if ($metabox_callback instanceof Closure) { |
|
| 2352 | + $result = $metabox_callback(); |
|
| 2353 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2354 | + $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2355 | + } else { |
|
| 2356 | + $result = $this->{$metabox_callback}(); |
|
| 2357 | + } |
|
| 2358 | + if ($result === false) { |
|
| 2359 | + // user error msg |
|
| 2360 | + $error_msg = esc_html__( |
|
| 2361 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2362 | + 'event_espresso' |
|
| 2363 | + ); |
|
| 2364 | + // developer error msg |
|
| 2365 | + $error_msg .= '||' |
|
| 2366 | + . sprintf( |
|
| 2367 | + esc_html__( |
|
| 2368 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2369 | + 'event_espresso' |
|
| 2370 | + ), |
|
| 2371 | + $metabox_callback |
|
| 2372 | + ); |
|
| 2373 | + throw new EE_Error($error_msg); |
|
| 2374 | + } |
|
| 2375 | + } |
|
| 2376 | + } |
|
| 2377 | + } |
|
| 2378 | + |
|
| 2379 | + |
|
| 2380 | + /** |
|
| 2381 | + * _add_screen_columns |
|
| 2382 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2383 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2384 | + * |
|
| 2385 | + * @return void |
|
| 2386 | + */ |
|
| 2387 | + private function _add_screen_columns() |
|
| 2388 | + { |
|
| 2389 | + if ( |
|
| 2390 | + is_array($this->_route_config) |
|
| 2391 | + && isset($this->_route_config['columns']) |
|
| 2392 | + && is_array($this->_route_config['columns']) |
|
| 2393 | + && count($this->_route_config['columns']) === 2 |
|
| 2394 | + ) { |
|
| 2395 | + add_screen_option( |
|
| 2396 | + 'layout_columns', |
|
| 2397 | + [ |
|
| 2398 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2399 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2400 | + ] |
|
| 2401 | + ); |
|
| 2402 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2403 | + $screen_id = $this->_current_screen->id; |
|
| 2404 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2405 | + $total_columns = ! empty($screen_columns) |
|
| 2406 | + ? $screen_columns |
|
| 2407 | + : $this->_route_config['columns'][1]; |
|
| 2408 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2409 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2410 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2411 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2412 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2413 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2414 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2415 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2416 | + } |
|
| 2417 | + } |
|
| 2418 | + |
|
| 2419 | + |
|
| 2420 | + |
|
| 2421 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2422 | + |
|
| 2423 | + |
|
| 2424 | + /** |
|
| 2425 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2426 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2427 | + * these get loaded on. |
|
| 2428 | + */ |
|
| 2429 | + private function _espresso_news_post_box() |
|
| 2430 | + { |
|
| 2431 | + $news_box_title = apply_filters( |
|
| 2432 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2433 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2434 | + ); |
|
| 2435 | + $this->addMetaBox( |
|
| 2436 | + 'espresso_news_post_box', |
|
| 2437 | + $news_box_title, |
|
| 2438 | + [ |
|
| 2439 | + $this, |
|
| 2440 | + 'espresso_news_post_box', |
|
| 2441 | + ], |
|
| 2442 | + $this->_wp_page_slug, |
|
| 2443 | + 'side' |
|
| 2444 | + ); |
|
| 2445 | + } |
|
| 2446 | + |
|
| 2447 | + |
|
| 2448 | + /** |
|
| 2449 | + * Code for setting up espresso ratings request metabox. |
|
| 2450 | + */ |
|
| 2451 | + protected function _espresso_ratings_request() |
|
| 2452 | + { |
|
| 2453 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2454 | + return; |
|
| 2455 | + } |
|
| 2456 | + $ratings_box_title = apply_filters( |
|
| 2457 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2458 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2459 | + ); |
|
| 2460 | + $this->addMetaBox( |
|
| 2461 | + 'espresso_ratings_request', |
|
| 2462 | + $ratings_box_title, |
|
| 2463 | + [ |
|
| 2464 | + $this, |
|
| 2465 | + 'espresso_ratings_request', |
|
| 2466 | + ], |
|
| 2467 | + $this->_wp_page_slug, |
|
| 2468 | + 'side' |
|
| 2469 | + ); |
|
| 2470 | + } |
|
| 2471 | + |
|
| 2472 | + |
|
| 2473 | + /** |
|
| 2474 | + * Code for setting up espresso ratings request metabox content. |
|
| 2475 | + * |
|
| 2476 | + * @throws DomainException |
|
| 2477 | + */ |
|
| 2478 | + public function espresso_ratings_request() |
|
| 2479 | + { |
|
| 2480 | + EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2481 | + } |
|
| 2482 | + |
|
| 2483 | + |
|
| 2484 | + public static function cached_rss_display($rss_id, $url) |
|
| 2485 | + { |
|
| 2486 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2487 | + . esc_html__('Loading…', 'event_espresso') |
|
| 2488 | + . '</p><p class="hide-if-js">' |
|
| 2489 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2490 | + . '</p>'; |
|
| 2491 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2492 | + $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2493 | + $post = '</div>' . "\n"; |
|
| 2494 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2495 | + $output = get_transient($cache_key); |
|
| 2496 | + if ($output !== false) { |
|
| 2497 | + echo $pre . $output . $post; // already escaped |
|
| 2498 | + return true; |
|
| 2499 | + } |
|
| 2500 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2501 | + echo $pre . $loading . $post; // already escaped |
|
| 2502 | + return false; |
|
| 2503 | + } |
|
| 2504 | + ob_start(); |
|
| 2505 | + wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2506 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2507 | + return true; |
|
| 2508 | + } |
|
| 2509 | + |
|
| 2510 | + |
|
| 2511 | + public function espresso_news_post_box() |
|
| 2512 | + { |
|
| 2513 | + ?> |
|
| 2514 | 2514 | <div class="padding"> |
| 2515 | 2515 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2516 | 2516 | <?php |
| 2517 | - // Get RSS Feed(s) |
|
| 2518 | - EE_Admin_Page::cached_rss_display( |
|
| 2519 | - 'espresso_news_post_box_content', |
|
| 2520 | - esc_url_raw( |
|
| 2521 | - apply_filters( |
|
| 2522 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2523 | - 'https://eventespresso.com/feed/' |
|
| 2524 | - ) |
|
| 2525 | - ) |
|
| 2526 | - ); |
|
| 2527 | - ?> |
|
| 2517 | + // Get RSS Feed(s) |
|
| 2518 | + EE_Admin_Page::cached_rss_display( |
|
| 2519 | + 'espresso_news_post_box_content', |
|
| 2520 | + esc_url_raw( |
|
| 2521 | + apply_filters( |
|
| 2522 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2523 | + 'https://eventespresso.com/feed/' |
|
| 2524 | + ) |
|
| 2525 | + ) |
|
| 2526 | + ); |
|
| 2527 | + ?> |
|
| 2528 | 2528 | </div> |
| 2529 | 2529 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2530 | 2530 | </div> |
| 2531 | 2531 | <?php |
| 2532 | - } |
|
| 2533 | - |
|
| 2534 | - |
|
| 2535 | - private function _espresso_links_post_box() |
|
| 2536 | - { |
|
| 2537 | - // Hiding until we actually have content to put in here... |
|
| 2538 | - // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2539 | - } |
|
| 2540 | - |
|
| 2541 | - |
|
| 2542 | - public function espresso_links_post_box() |
|
| 2543 | - { |
|
| 2544 | - // Hiding until we actually have content to put in here... |
|
| 2545 | - // EEH_Template::display_template( |
|
| 2546 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2547 | - // ); |
|
| 2548 | - } |
|
| 2549 | - |
|
| 2550 | - |
|
| 2551 | - protected function _espresso_sponsors_post_box() |
|
| 2552 | - { |
|
| 2553 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2554 | - $this->addMetaBox( |
|
| 2555 | - 'espresso_sponsors_post_box', |
|
| 2556 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2557 | - [$this, 'espresso_sponsors_post_box'], |
|
| 2558 | - $this->_wp_page_slug, |
|
| 2559 | - 'side' |
|
| 2560 | - ); |
|
| 2561 | - } |
|
| 2562 | - } |
|
| 2563 | - |
|
| 2564 | - |
|
| 2565 | - public function espresso_sponsors_post_box() |
|
| 2566 | - { |
|
| 2567 | - EEH_Template::display_template( |
|
| 2568 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2569 | - ); |
|
| 2570 | - } |
|
| 2571 | - |
|
| 2572 | - |
|
| 2573 | - private function _publish_post_box() |
|
| 2574 | - { |
|
| 2575 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2576 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2577 | - // then we'll use that for the metabox label. |
|
| 2578 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2579 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2580 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2581 | - : $this->_labels['publishbox']; |
|
| 2582 | - } else { |
|
| 2583 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2584 | - } |
|
| 2585 | - $box_label = apply_filters( |
|
| 2586 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2587 | - $box_label, |
|
| 2588 | - $this->_req_action, |
|
| 2589 | - $this |
|
| 2590 | - ); |
|
| 2591 | - $this->addMetaBox( |
|
| 2592 | - $meta_box_ref, |
|
| 2593 | - $box_label, |
|
| 2594 | - [$this, 'editor_overview'], |
|
| 2595 | - $this->_current_screen->id, |
|
| 2596 | - 'side', |
|
| 2597 | - 'high' |
|
| 2598 | - ); |
|
| 2599 | - } |
|
| 2600 | - |
|
| 2601 | - |
|
| 2602 | - public function editor_overview() |
|
| 2603 | - { |
|
| 2604 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2605 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2606 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2607 | - : ''; |
|
| 2608 | - echo EEH_Template::display_template( |
|
| 2609 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2610 | - $this->_template_args, |
|
| 2611 | - true |
|
| 2612 | - ); |
|
| 2613 | - } |
|
| 2614 | - |
|
| 2615 | - |
|
| 2616 | - /** end of globally available metaboxes section **/ |
|
| 2617 | - |
|
| 2618 | - |
|
| 2619 | - /** |
|
| 2620 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2621 | - * protected method. |
|
| 2622 | - * |
|
| 2623 | - * @param string $name |
|
| 2624 | - * @param int $id |
|
| 2625 | - * @param bool $delete |
|
| 2626 | - * @param string $save_close_redirect_URL |
|
| 2627 | - * @param bool $both_btns |
|
| 2628 | - * @throws EE_Error |
|
| 2629 | - * @throws InvalidArgumentException |
|
| 2630 | - * @throws InvalidDataTypeException |
|
| 2631 | - * @throws InvalidInterfaceException |
|
| 2632 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2633 | - * @since 4.6.0 |
|
| 2634 | - */ |
|
| 2635 | - public function set_publish_post_box_vars( |
|
| 2636 | - $name = '', |
|
| 2637 | - $id = 0, |
|
| 2638 | - $delete = false, |
|
| 2639 | - $save_close_redirect_URL = '', |
|
| 2640 | - $both_btns = true |
|
| 2641 | - ) { |
|
| 2642 | - $this->_set_publish_post_box_vars( |
|
| 2643 | - $name, |
|
| 2644 | - $id, |
|
| 2645 | - $delete, |
|
| 2646 | - $save_close_redirect_URL, |
|
| 2647 | - $both_btns |
|
| 2648 | - ); |
|
| 2649 | - } |
|
| 2650 | - |
|
| 2651 | - |
|
| 2652 | - /** |
|
| 2653 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2654 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2655 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2656 | - * values for the name and id arguments. |
|
| 2657 | - * |
|
| 2658 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2659 | - * @param int $id id attached to the item published |
|
| 2660 | - * @param string $delete page route callback for the delete action |
|
| 2661 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2662 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2663 | - * the Save button |
|
| 2664 | - * @throws EE_Error |
|
| 2665 | - * @throws InvalidArgumentException |
|
| 2666 | - * @throws InvalidDataTypeException |
|
| 2667 | - * @throws InvalidInterfaceException |
|
| 2668 | - * @todo Add in validation for name/id arguments. |
|
| 2669 | - */ |
|
| 2670 | - protected function _set_publish_post_box_vars( |
|
| 2671 | - $name = '', |
|
| 2672 | - $id = 0, |
|
| 2673 | - $delete = '', |
|
| 2674 | - $save_close_redirect_URL = '', |
|
| 2675 | - $both_btns = true |
|
| 2676 | - ) { |
|
| 2677 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2678 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2679 | - ? $save_close_redirect_URL |
|
| 2680 | - : $this->_admin_base_url; |
|
| 2681 | - // create the Save & Close and Save buttons |
|
| 2682 | - $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2683 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2684 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2685 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2686 | - : ''; |
|
| 2687 | - if ($delete && ! empty($id)) { |
|
| 2688 | - // make sure we have a default if just true is sent. |
|
| 2689 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2690 | - $delete_link_args = [$name => $id]; |
|
| 2691 | - $delete = $this->get_action_link_or_button( |
|
| 2692 | - $delete, |
|
| 2693 | - $delete, |
|
| 2694 | - $delete_link_args, |
|
| 2695 | - 'submitdelete deletion' |
|
| 2696 | - ); |
|
| 2697 | - } |
|
| 2698 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2699 | - if (! empty($name) && ! empty($id)) { |
|
| 2700 | - $hidden_field_arr[ $name ] = [ |
|
| 2701 | - 'type' => 'hidden', |
|
| 2702 | - 'value' => $id, |
|
| 2703 | - ]; |
|
| 2704 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2705 | - } else { |
|
| 2706 | - $hf = ''; |
|
| 2707 | - } |
|
| 2708 | - // add hidden field |
|
| 2709 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2710 | - ? $hf[ $name ]['field'] |
|
| 2711 | - : $hf; |
|
| 2712 | - } |
|
| 2713 | - |
|
| 2714 | - |
|
| 2715 | - /** |
|
| 2716 | - * displays an error message to ppl who have javascript disabled |
|
| 2717 | - * |
|
| 2718 | - * @return void |
|
| 2719 | - */ |
|
| 2720 | - private function _display_no_javascript_warning() |
|
| 2721 | - { |
|
| 2722 | - ?> |
|
| 2532 | + } |
|
| 2533 | + |
|
| 2534 | + |
|
| 2535 | + private function _espresso_links_post_box() |
|
| 2536 | + { |
|
| 2537 | + // Hiding until we actually have content to put in here... |
|
| 2538 | + // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2539 | + } |
|
| 2540 | + |
|
| 2541 | + |
|
| 2542 | + public function espresso_links_post_box() |
|
| 2543 | + { |
|
| 2544 | + // Hiding until we actually have content to put in here... |
|
| 2545 | + // EEH_Template::display_template( |
|
| 2546 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2547 | + // ); |
|
| 2548 | + } |
|
| 2549 | + |
|
| 2550 | + |
|
| 2551 | + protected function _espresso_sponsors_post_box() |
|
| 2552 | + { |
|
| 2553 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2554 | + $this->addMetaBox( |
|
| 2555 | + 'espresso_sponsors_post_box', |
|
| 2556 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2557 | + [$this, 'espresso_sponsors_post_box'], |
|
| 2558 | + $this->_wp_page_slug, |
|
| 2559 | + 'side' |
|
| 2560 | + ); |
|
| 2561 | + } |
|
| 2562 | + } |
|
| 2563 | + |
|
| 2564 | + |
|
| 2565 | + public function espresso_sponsors_post_box() |
|
| 2566 | + { |
|
| 2567 | + EEH_Template::display_template( |
|
| 2568 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2569 | + ); |
|
| 2570 | + } |
|
| 2571 | + |
|
| 2572 | + |
|
| 2573 | + private function _publish_post_box() |
|
| 2574 | + { |
|
| 2575 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2576 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2577 | + // then we'll use that for the metabox label. |
|
| 2578 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2579 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2580 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2581 | + : $this->_labels['publishbox']; |
|
| 2582 | + } else { |
|
| 2583 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2584 | + } |
|
| 2585 | + $box_label = apply_filters( |
|
| 2586 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2587 | + $box_label, |
|
| 2588 | + $this->_req_action, |
|
| 2589 | + $this |
|
| 2590 | + ); |
|
| 2591 | + $this->addMetaBox( |
|
| 2592 | + $meta_box_ref, |
|
| 2593 | + $box_label, |
|
| 2594 | + [$this, 'editor_overview'], |
|
| 2595 | + $this->_current_screen->id, |
|
| 2596 | + 'side', |
|
| 2597 | + 'high' |
|
| 2598 | + ); |
|
| 2599 | + } |
|
| 2600 | + |
|
| 2601 | + |
|
| 2602 | + public function editor_overview() |
|
| 2603 | + { |
|
| 2604 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2605 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2606 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2607 | + : ''; |
|
| 2608 | + echo EEH_Template::display_template( |
|
| 2609 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2610 | + $this->_template_args, |
|
| 2611 | + true |
|
| 2612 | + ); |
|
| 2613 | + } |
|
| 2614 | + |
|
| 2615 | + |
|
| 2616 | + /** end of globally available metaboxes section **/ |
|
| 2617 | + |
|
| 2618 | + |
|
| 2619 | + /** |
|
| 2620 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2621 | + * protected method. |
|
| 2622 | + * |
|
| 2623 | + * @param string $name |
|
| 2624 | + * @param int $id |
|
| 2625 | + * @param bool $delete |
|
| 2626 | + * @param string $save_close_redirect_URL |
|
| 2627 | + * @param bool $both_btns |
|
| 2628 | + * @throws EE_Error |
|
| 2629 | + * @throws InvalidArgumentException |
|
| 2630 | + * @throws InvalidDataTypeException |
|
| 2631 | + * @throws InvalidInterfaceException |
|
| 2632 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2633 | + * @since 4.6.0 |
|
| 2634 | + */ |
|
| 2635 | + public function set_publish_post_box_vars( |
|
| 2636 | + $name = '', |
|
| 2637 | + $id = 0, |
|
| 2638 | + $delete = false, |
|
| 2639 | + $save_close_redirect_URL = '', |
|
| 2640 | + $both_btns = true |
|
| 2641 | + ) { |
|
| 2642 | + $this->_set_publish_post_box_vars( |
|
| 2643 | + $name, |
|
| 2644 | + $id, |
|
| 2645 | + $delete, |
|
| 2646 | + $save_close_redirect_URL, |
|
| 2647 | + $both_btns |
|
| 2648 | + ); |
|
| 2649 | + } |
|
| 2650 | + |
|
| 2651 | + |
|
| 2652 | + /** |
|
| 2653 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2654 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2655 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2656 | + * values for the name and id arguments. |
|
| 2657 | + * |
|
| 2658 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2659 | + * @param int $id id attached to the item published |
|
| 2660 | + * @param string $delete page route callback for the delete action |
|
| 2661 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2662 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2663 | + * the Save button |
|
| 2664 | + * @throws EE_Error |
|
| 2665 | + * @throws InvalidArgumentException |
|
| 2666 | + * @throws InvalidDataTypeException |
|
| 2667 | + * @throws InvalidInterfaceException |
|
| 2668 | + * @todo Add in validation for name/id arguments. |
|
| 2669 | + */ |
|
| 2670 | + protected function _set_publish_post_box_vars( |
|
| 2671 | + $name = '', |
|
| 2672 | + $id = 0, |
|
| 2673 | + $delete = '', |
|
| 2674 | + $save_close_redirect_URL = '', |
|
| 2675 | + $both_btns = true |
|
| 2676 | + ) { |
|
| 2677 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2678 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2679 | + ? $save_close_redirect_URL |
|
| 2680 | + : $this->_admin_base_url; |
|
| 2681 | + // create the Save & Close and Save buttons |
|
| 2682 | + $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2683 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2684 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2685 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2686 | + : ''; |
|
| 2687 | + if ($delete && ! empty($id)) { |
|
| 2688 | + // make sure we have a default if just true is sent. |
|
| 2689 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2690 | + $delete_link_args = [$name => $id]; |
|
| 2691 | + $delete = $this->get_action_link_or_button( |
|
| 2692 | + $delete, |
|
| 2693 | + $delete, |
|
| 2694 | + $delete_link_args, |
|
| 2695 | + 'submitdelete deletion' |
|
| 2696 | + ); |
|
| 2697 | + } |
|
| 2698 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2699 | + if (! empty($name) && ! empty($id)) { |
|
| 2700 | + $hidden_field_arr[ $name ] = [ |
|
| 2701 | + 'type' => 'hidden', |
|
| 2702 | + 'value' => $id, |
|
| 2703 | + ]; |
|
| 2704 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2705 | + } else { |
|
| 2706 | + $hf = ''; |
|
| 2707 | + } |
|
| 2708 | + // add hidden field |
|
| 2709 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2710 | + ? $hf[ $name ]['field'] |
|
| 2711 | + : $hf; |
|
| 2712 | + } |
|
| 2713 | + |
|
| 2714 | + |
|
| 2715 | + /** |
|
| 2716 | + * displays an error message to ppl who have javascript disabled |
|
| 2717 | + * |
|
| 2718 | + * @return void |
|
| 2719 | + */ |
|
| 2720 | + private function _display_no_javascript_warning() |
|
| 2721 | + { |
|
| 2722 | + ?> |
|
| 2723 | 2723 | <noscript> |
| 2724 | 2724 | <div id="no-js-message" class="error"> |
| 2725 | 2725 | <p style="font-size:1.3em;"> |
| 2726 | 2726 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2727 | 2727 | <?php esc_html_e( |
| 2728 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2729 | - 'event_espresso' |
|
| 2730 | - ); ?> |
|
| 2728 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2729 | + 'event_espresso' |
|
| 2730 | + ); ?> |
|
| 2731 | 2731 | </p> |
| 2732 | 2732 | </div> |
| 2733 | 2733 | </noscript> |
| 2734 | 2734 | <?php |
| 2735 | - } |
|
| 2736 | - |
|
| 2737 | - |
|
| 2738 | - /** |
|
| 2739 | - * displays espresso success and/or error notices |
|
| 2740 | - * |
|
| 2741 | - * @return void |
|
| 2742 | - */ |
|
| 2743 | - protected function _display_espresso_notices() |
|
| 2744 | - { |
|
| 2745 | - $notices = $this->_get_transient(true); |
|
| 2746 | - echo stripslashes($notices); |
|
| 2747 | - } |
|
| 2748 | - |
|
| 2749 | - |
|
| 2750 | - /** |
|
| 2751 | - * spinny things pacify the masses |
|
| 2752 | - * |
|
| 2753 | - * @return void |
|
| 2754 | - */ |
|
| 2755 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2756 | - { |
|
| 2757 | - ?> |
|
| 2735 | + } |
|
| 2736 | + |
|
| 2737 | + |
|
| 2738 | + /** |
|
| 2739 | + * displays espresso success and/or error notices |
|
| 2740 | + * |
|
| 2741 | + * @return void |
|
| 2742 | + */ |
|
| 2743 | + protected function _display_espresso_notices() |
|
| 2744 | + { |
|
| 2745 | + $notices = $this->_get_transient(true); |
|
| 2746 | + echo stripslashes($notices); |
|
| 2747 | + } |
|
| 2748 | + |
|
| 2749 | + |
|
| 2750 | + /** |
|
| 2751 | + * spinny things pacify the masses |
|
| 2752 | + * |
|
| 2753 | + * @return void |
|
| 2754 | + */ |
|
| 2755 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2756 | + { |
|
| 2757 | + ?> |
|
| 2758 | 2758 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2759 | 2759 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
| 2760 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2760 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2761 | 2761 | </div> |
| 2762 | 2762 | <?php |
| 2763 | - } |
|
| 2763 | + } |
|
| 2764 | 2764 | |
| 2765 | 2765 | |
| 2766 | - /** |
|
| 2767 | - * add admin page overlay for modal boxes |
|
| 2768 | - * |
|
| 2769 | - * @return void |
|
| 2770 | - */ |
|
| 2771 | - protected function _add_admin_page_overlay() |
|
| 2772 | - { |
|
| 2773 | - ?> |
|
| 2766 | + /** |
|
| 2767 | + * add admin page overlay for modal boxes |
|
| 2768 | + * |
|
| 2769 | + * @return void |
|
| 2770 | + */ |
|
| 2771 | + protected function _add_admin_page_overlay() |
|
| 2772 | + { |
|
| 2773 | + ?> |
|
| 2774 | 2774 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2775 | 2775 | <?php |
| 2776 | - } |
|
| 2777 | - |
|
| 2778 | - |
|
| 2779 | - /** |
|
| 2780 | - * facade for $this->addMetaBox() |
|
| 2781 | - * |
|
| 2782 | - * @param string $action where the metabox get's displayed |
|
| 2783 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2784 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2785 | - * instead of the one created in here. |
|
| 2786 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2787 | - * @param string $column what metabox column |
|
| 2788 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2789 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2790 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2791 | - * @throws DomainException |
|
| 2792 | - */ |
|
| 2793 | - public function _add_admin_page_meta_box( |
|
| 2794 | - $action, |
|
| 2795 | - $title, |
|
| 2796 | - $callback, |
|
| 2797 | - $callback_args, |
|
| 2798 | - $column = 'normal', |
|
| 2799 | - $priority = 'high', |
|
| 2800 | - $create_func = true |
|
| 2801 | - ) { |
|
| 2802 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2803 | - // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2804 | - if (empty($callback_args) && $create_func) { |
|
| 2805 | - $callback_args = [ |
|
| 2806 | - 'template_path' => $this->_template_path, |
|
| 2807 | - 'template_args' => $this->_template_args, |
|
| 2808 | - ]; |
|
| 2809 | - } |
|
| 2810 | - // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2811 | - $call_back_func = $create_func |
|
| 2812 | - ? static function ($post, $metabox) { |
|
| 2813 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2814 | - echo EEH_Template::display_template( |
|
| 2815 | - $metabox['args']['template_path'], |
|
| 2816 | - $metabox['args']['template_args'], |
|
| 2817 | - true |
|
| 2818 | - ); |
|
| 2819 | - } |
|
| 2820 | - : $callback; |
|
| 2821 | - $this->addMetaBox( |
|
| 2822 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2823 | - $title, |
|
| 2824 | - $call_back_func, |
|
| 2825 | - $this->_wp_page_slug, |
|
| 2826 | - $column, |
|
| 2827 | - $priority, |
|
| 2828 | - $callback_args |
|
| 2829 | - ); |
|
| 2830 | - } |
|
| 2831 | - |
|
| 2832 | - |
|
| 2833 | - /** |
|
| 2834 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2835 | - * |
|
| 2836 | - * @throws DomainException |
|
| 2837 | - * @throws EE_Error |
|
| 2838 | - * @throws InvalidArgumentException |
|
| 2839 | - * @throws InvalidDataTypeException |
|
| 2840 | - * @throws InvalidInterfaceException |
|
| 2841 | - */ |
|
| 2842 | - public function display_admin_page_with_metabox_columns() |
|
| 2843 | - { |
|
| 2844 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2845 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2846 | - $this->_column_template_path, |
|
| 2847 | - $this->_template_args, |
|
| 2848 | - true |
|
| 2849 | - ); |
|
| 2850 | - // the final wrapper |
|
| 2851 | - $this->admin_page_wrapper(); |
|
| 2852 | - } |
|
| 2853 | - |
|
| 2854 | - |
|
| 2855 | - /** |
|
| 2856 | - * generates HTML wrapper for an admin details page |
|
| 2857 | - * |
|
| 2858 | - * @return void |
|
| 2859 | - * @throws DomainException |
|
| 2860 | - * @throws EE_Error |
|
| 2861 | - * @throws InvalidArgumentException |
|
| 2862 | - * @throws InvalidDataTypeException |
|
| 2863 | - * @throws InvalidInterfaceException |
|
| 2864 | - */ |
|
| 2865 | - public function display_admin_page_with_sidebar() |
|
| 2866 | - { |
|
| 2867 | - $this->_display_admin_page(true); |
|
| 2868 | - } |
|
| 2869 | - |
|
| 2870 | - |
|
| 2871 | - /** |
|
| 2872 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2873 | - * |
|
| 2874 | - * @return void |
|
| 2875 | - * @throws DomainException |
|
| 2876 | - * @throws EE_Error |
|
| 2877 | - * @throws InvalidArgumentException |
|
| 2878 | - * @throws InvalidDataTypeException |
|
| 2879 | - * @throws InvalidInterfaceException |
|
| 2880 | - */ |
|
| 2881 | - public function display_admin_page_with_no_sidebar() |
|
| 2882 | - { |
|
| 2883 | - $this->_display_admin_page(); |
|
| 2884 | - } |
|
| 2885 | - |
|
| 2886 | - |
|
| 2887 | - /** |
|
| 2888 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2889 | - * |
|
| 2890 | - * @return void |
|
| 2891 | - * @throws DomainException |
|
| 2892 | - * @throws EE_Error |
|
| 2893 | - * @throws InvalidArgumentException |
|
| 2894 | - * @throws InvalidDataTypeException |
|
| 2895 | - * @throws InvalidInterfaceException |
|
| 2896 | - */ |
|
| 2897 | - public function display_about_admin_page() |
|
| 2898 | - { |
|
| 2899 | - $this->_display_admin_page(false, true); |
|
| 2900 | - } |
|
| 2901 | - |
|
| 2902 | - |
|
| 2903 | - /** |
|
| 2904 | - * display_admin_page |
|
| 2905 | - * contains the code for actually displaying an admin page |
|
| 2906 | - * |
|
| 2907 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2908 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2909 | - * @return void |
|
| 2910 | - * @throws DomainException |
|
| 2911 | - * @throws EE_Error |
|
| 2912 | - * @throws InvalidArgumentException |
|
| 2913 | - * @throws InvalidDataTypeException |
|
| 2914 | - * @throws InvalidInterfaceException |
|
| 2915 | - */ |
|
| 2916 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2917 | - { |
|
| 2918 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2919 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2920 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2921 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2922 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2923 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2924 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2925 | - ? 'poststuff' |
|
| 2926 | - : 'espresso-default-admin'; |
|
| 2927 | - |
|
| 2928 | - $template_path = $sidebar |
|
| 2929 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2930 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2931 | - if ($this->request->isAjax()) { |
|
| 2932 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2933 | - } |
|
| 2934 | - $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2935 | - |
|
| 2936 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'] ?? ''; |
|
| 2937 | - $this->_template_args['before_admin_page_content'] = $this->_template_args['before_admin_page_content'] ?? ''; |
|
| 2938 | - $this->_template_args['after_admin_page_content'] = $this->_template_args['after_admin_page_content'] ?? ''; |
|
| 2939 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2940 | - $template_path, |
|
| 2941 | - $this->_template_args, |
|
| 2942 | - true |
|
| 2943 | - ); |
|
| 2944 | - // the final template wrapper |
|
| 2945 | - $this->admin_page_wrapper($about); |
|
| 2946 | - } |
|
| 2947 | - |
|
| 2948 | - |
|
| 2949 | - /** |
|
| 2950 | - * This is used to display caf preview pages. |
|
| 2951 | - * |
|
| 2952 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2953 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2954 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2955 | - * @return void |
|
| 2956 | - * @throws DomainException |
|
| 2957 | - * @throws EE_Error |
|
| 2958 | - * @throws InvalidArgumentException |
|
| 2959 | - * @throws InvalidDataTypeException |
|
| 2960 | - * @throws InvalidInterfaceException |
|
| 2961 | - * @since 4.3.2 |
|
| 2962 | - */ |
|
| 2963 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2964 | - { |
|
| 2965 | - // let's generate a default preview action button if there isn't one already present. |
|
| 2966 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2967 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2968 | - 'event_espresso' |
|
| 2969 | - ); |
|
| 2970 | - $buy_now_url = add_query_arg( |
|
| 2971 | - [ |
|
| 2972 | - 'ee_ver' => 'ee4', |
|
| 2973 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2974 | - 'utm_medium' => 'link', |
|
| 2975 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2976 | - 'utm_content' => 'buy_now_button', |
|
| 2977 | - ], |
|
| 2978 | - 'https://eventespresso.com/pricing/' |
|
| 2979 | - ); |
|
| 2980 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2981 | - ? $this->get_action_link_or_button( |
|
| 2982 | - '', |
|
| 2983 | - 'buy_now', |
|
| 2984 | - [], |
|
| 2985 | - 'button--primary button--big', |
|
| 2986 | - esc_url_raw($buy_now_url), |
|
| 2987 | - true |
|
| 2988 | - ) |
|
| 2989 | - : $this->_template_args['preview_action_button']; |
|
| 2990 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2991 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2992 | - $this->_template_args, |
|
| 2993 | - true |
|
| 2994 | - ); |
|
| 2995 | - $this->_display_admin_page($display_sidebar); |
|
| 2996 | - } |
|
| 2997 | - |
|
| 2998 | - |
|
| 2999 | - /** |
|
| 3000 | - * display_admin_list_table_page_with_sidebar |
|
| 3001 | - * generates HTML wrapper for an admin_page with list_table |
|
| 3002 | - * |
|
| 3003 | - * @return void |
|
| 3004 | - * @throws DomainException |
|
| 3005 | - * @throws EE_Error |
|
| 3006 | - * @throws InvalidArgumentException |
|
| 3007 | - * @throws InvalidDataTypeException |
|
| 3008 | - * @throws InvalidInterfaceException |
|
| 3009 | - */ |
|
| 3010 | - public function display_admin_list_table_page_with_sidebar() |
|
| 3011 | - { |
|
| 3012 | - $this->_display_admin_list_table_page(true); |
|
| 3013 | - } |
|
| 3014 | - |
|
| 3015 | - |
|
| 3016 | - /** |
|
| 3017 | - * display_admin_list_table_page_with_no_sidebar |
|
| 3018 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 3019 | - * |
|
| 3020 | - * @return void |
|
| 3021 | - * @throws DomainException |
|
| 3022 | - * @throws EE_Error |
|
| 3023 | - * @throws InvalidArgumentException |
|
| 3024 | - * @throws InvalidDataTypeException |
|
| 3025 | - * @throws InvalidInterfaceException |
|
| 3026 | - */ |
|
| 3027 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 3028 | - { |
|
| 3029 | - $this->_display_admin_list_table_page(); |
|
| 3030 | - } |
|
| 3031 | - |
|
| 3032 | - |
|
| 3033 | - /** |
|
| 3034 | - * generates html wrapper for an admin_list_table page |
|
| 3035 | - * |
|
| 3036 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3037 | - * @return void |
|
| 3038 | - * @throws DomainException |
|
| 3039 | - * @throws EE_Error |
|
| 3040 | - * @throws InvalidArgumentException |
|
| 3041 | - * @throws InvalidDataTypeException |
|
| 3042 | - * @throws InvalidInterfaceException |
|
| 3043 | - */ |
|
| 3044 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 3045 | - { |
|
| 3046 | - // setup search attributes |
|
| 3047 | - $this->_set_search_attributes(); |
|
| 3048 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3049 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3050 | - $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 3051 | - ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 3052 | - : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 3053 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3054 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 3055 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3056 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3057 | - if (! empty($ajax_sorting_callback)) { |
|
| 3058 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3059 | - $ajax_sorting_callback . '_nonce', |
|
| 3060 | - $ajax_sorting_callback . '_nonce', |
|
| 3061 | - false, |
|
| 3062 | - false |
|
| 3063 | - ); |
|
| 3064 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3065 | - . $this->page_slug |
|
| 3066 | - . '" />'; |
|
| 3067 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3068 | - . $ajax_sorting_callback |
|
| 3069 | - . '" />'; |
|
| 3070 | - } else { |
|
| 3071 | - $sortable_list_table_form_fields = ''; |
|
| 3072 | - } |
|
| 3073 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3074 | - $hidden_form_fields = |
|
| 3075 | - isset($this->_template_args['list_table_hidden_fields']) |
|
| 3076 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 3077 | - : ''; |
|
| 3078 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3079 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3080 | - . $nonce_ref |
|
| 3081 | - . '" value="' |
|
| 3082 | - . wp_create_nonce($nonce_ref) |
|
| 3083 | - . '">'; |
|
| 3084 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3085 | - // display message about search results? |
|
| 3086 | - $search = $this->request->getRequestParam('s'); |
|
| 3087 | - $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 3088 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3089 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3090 | - trim($search, '%') |
|
| 3091 | - ) . '</p>' |
|
| 3092 | - : ''; |
|
| 3093 | - // filter before_list_table template arg |
|
| 3094 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 3095 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3096 | - $this->_template_args['before_list_table'], |
|
| 3097 | - $this->page_slug, |
|
| 3098 | - $this->request->requestParams(), |
|
| 3099 | - $this->_req_action |
|
| 3100 | - ); |
|
| 3101 | - // convert to array and filter again |
|
| 3102 | - // arrays are easier to inject new items in a specific location, |
|
| 3103 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3104 | - $this->_template_args['before_list_table'] = implode( |
|
| 3105 | - " \n", |
|
| 3106 | - (array) apply_filters( |
|
| 3107 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3108 | - (array) $this->_template_args['before_list_table'], |
|
| 3109 | - $this->page_slug, |
|
| 3110 | - $this->request->requestParams(), |
|
| 3111 | - $this->_req_action |
|
| 3112 | - ) |
|
| 3113 | - ); |
|
| 3114 | - // filter after_list_table template arg |
|
| 3115 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 3116 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3117 | - $this->_template_args['after_list_table'], |
|
| 3118 | - $this->page_slug, |
|
| 3119 | - $this->request->requestParams(), |
|
| 3120 | - $this->_req_action |
|
| 3121 | - ); |
|
| 3122 | - // convert to array and filter again |
|
| 3123 | - // arrays are easier to inject new items in a specific location, |
|
| 3124 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3125 | - $this->_template_args['after_list_table'] = implode( |
|
| 3126 | - " \n", |
|
| 3127 | - (array) apply_filters( |
|
| 3128 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3129 | - (array) $this->_template_args['after_list_table'], |
|
| 3130 | - $this->page_slug, |
|
| 3131 | - $this->request->requestParams(), |
|
| 3132 | - $this->_req_action |
|
| 3133 | - ) |
|
| 3134 | - ); |
|
| 3135 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3136 | - $template_path, |
|
| 3137 | - $this->_template_args, |
|
| 3138 | - true |
|
| 3139 | - ); |
|
| 3140 | - // the final template wrapper |
|
| 3141 | - if ($sidebar) { |
|
| 3142 | - $this->display_admin_page_with_sidebar(); |
|
| 3143 | - } else { |
|
| 3144 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3145 | - } |
|
| 3146 | - } |
|
| 3147 | - |
|
| 3148 | - |
|
| 3149 | - /** |
|
| 3150 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3151 | - * html string for the legend. |
|
| 3152 | - * $items are expected in an array in the following format: |
|
| 3153 | - * $legend_items = array( |
|
| 3154 | - * 'item_id' => array( |
|
| 3155 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3156 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3157 | - * ) |
|
| 3158 | - * ); |
|
| 3159 | - * |
|
| 3160 | - * @param array $items see above for format of array |
|
| 3161 | - * @return string html string of legend |
|
| 3162 | - * @throws DomainException |
|
| 3163 | - */ |
|
| 3164 | - protected function _display_legend($items) |
|
| 3165 | - { |
|
| 3166 | - $this->_template_args['items'] = apply_filters( |
|
| 3167 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3168 | - (array) $items, |
|
| 3169 | - $this |
|
| 3170 | - ); |
|
| 3171 | - /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
|
| 3172 | - $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
|
| 3173 | - if (! $status_change_notice->isDismissed()) { |
|
| 3174 | - $this->_template_args['status_change_notice'] = EEH_Template::display_template( |
|
| 3175 | - EE_ADMIN_TEMPLATE . 'status_change_notice.template.php', |
|
| 3176 | - [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ], |
|
| 3177 | - true |
|
| 3178 | - ); |
|
| 3179 | - } |
|
| 3180 | - return EEH_Template::display_template( |
|
| 3181 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3182 | - $this->_template_args, |
|
| 3183 | - true |
|
| 3184 | - ); |
|
| 3185 | - } |
|
| 3186 | - |
|
| 3187 | - |
|
| 3188 | - /** |
|
| 3189 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3190 | - * The returned json object is created from an array in the following format: |
|
| 3191 | - * array( |
|
| 3192 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3193 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3194 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3195 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3196 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3197 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3198 | - * that might be included in here) |
|
| 3199 | - * ) |
|
| 3200 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3201 | - * |
|
| 3202 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3203 | - * instead of displayed. |
|
| 3204 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3205 | - * @return void |
|
| 3206 | - * @throws EE_Error |
|
| 3207 | - * @throws InvalidArgumentException |
|
| 3208 | - * @throws InvalidDataTypeException |
|
| 3209 | - * @throws InvalidInterfaceException |
|
| 3210 | - */ |
|
| 3211 | - protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 3212 | - { |
|
| 3213 | - // make sure any EE_Error notices have been handled. |
|
| 3214 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3215 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 3216 | - unset($this->_template_args['data']); |
|
| 3217 | - $json = [ |
|
| 3218 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3219 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3220 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3221 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3222 | - 'notices' => EE_Error::get_notices(), |
|
| 3223 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3224 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 3225 | - 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 3226 | - 'isEEajax' => true |
|
| 3227 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3228 | - ]; |
|
| 3229 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3230 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3231 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3232 | - } |
|
| 3233 | - echo wp_json_encode($json); |
|
| 3234 | - exit(); |
|
| 3235 | - } |
|
| 3236 | - |
|
| 3237 | - |
|
| 3238 | - /** |
|
| 3239 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3240 | - * |
|
| 3241 | - * @return void |
|
| 3242 | - * @throws EE_Error |
|
| 3243 | - * @throws InvalidArgumentException |
|
| 3244 | - * @throws InvalidDataTypeException |
|
| 3245 | - * @throws InvalidInterfaceException |
|
| 3246 | - */ |
|
| 3247 | - public function return_json() |
|
| 3248 | - { |
|
| 3249 | - if ($this->request->isAjax()) { |
|
| 3250 | - $this->_return_json(); |
|
| 3251 | - } else { |
|
| 3252 | - throw new EE_Error( |
|
| 3253 | - sprintf( |
|
| 3254 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3255 | - __FUNCTION__ |
|
| 3256 | - ) |
|
| 3257 | - ); |
|
| 3258 | - } |
|
| 3259 | - } |
|
| 3260 | - |
|
| 3261 | - |
|
| 3262 | - /** |
|
| 3263 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3264 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3265 | - * |
|
| 3266 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3267 | - */ |
|
| 3268 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3269 | - { |
|
| 3270 | - $this->_hook_obj = $hook_obj; |
|
| 3271 | - } |
|
| 3272 | - |
|
| 3273 | - |
|
| 3274 | - /** |
|
| 3275 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3276 | - * |
|
| 3277 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3278 | - * @return void |
|
| 3279 | - * @throws DomainException |
|
| 3280 | - * @throws EE_Error |
|
| 3281 | - * @throws InvalidArgumentException |
|
| 3282 | - * @throws InvalidDataTypeException |
|
| 3283 | - * @throws InvalidInterfaceException |
|
| 3284 | - */ |
|
| 3285 | - public function admin_page_wrapper($about = false) |
|
| 3286 | - { |
|
| 3287 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3288 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3289 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3290 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3291 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3292 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3293 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3294 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3295 | - : '' |
|
| 3296 | - ); |
|
| 3297 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3298 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3299 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3300 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3301 | - : '' |
|
| 3302 | - ); |
|
| 3303 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3304 | - // load settings page wrapper template |
|
| 3305 | - $template_path = ! $this->request->isAjax() |
|
| 3306 | - ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3307 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 3308 | - // about page? |
|
| 3309 | - $template_path = $about |
|
| 3310 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3311 | - : $template_path; |
|
| 3312 | - if ($this->request->isAjax()) { |
|
| 3313 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3314 | - $template_path, |
|
| 3315 | - $this->_template_args, |
|
| 3316 | - true |
|
| 3317 | - ); |
|
| 3318 | - $this->_return_json(); |
|
| 3319 | - } else { |
|
| 3320 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3321 | - } |
|
| 3322 | - } |
|
| 3323 | - |
|
| 3324 | - |
|
| 3325 | - /** |
|
| 3326 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3327 | - * |
|
| 3328 | - * @return string html |
|
| 3329 | - * @throws EE_Error |
|
| 3330 | - */ |
|
| 3331 | - protected function _get_main_nav_tabs() |
|
| 3332 | - { |
|
| 3333 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3334 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3335 | - // (rather than setting in the page_routes array) |
|
| 3336 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3337 | - } |
|
| 3338 | - |
|
| 3339 | - |
|
| 3340 | - /** |
|
| 3341 | - * sort nav tabs |
|
| 3342 | - * |
|
| 3343 | - * @param $a |
|
| 3344 | - * @param $b |
|
| 3345 | - * @return int |
|
| 3346 | - */ |
|
| 3347 | - private function _sort_nav_tabs($a, $b) |
|
| 3348 | - { |
|
| 3349 | - if ($a['order'] === $b['order']) { |
|
| 3350 | - return 0; |
|
| 3351 | - } |
|
| 3352 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3353 | - } |
|
| 3354 | - |
|
| 3355 | - |
|
| 3356 | - /** |
|
| 3357 | - * generates HTML for the forms used on admin pages |
|
| 3358 | - * |
|
| 3359 | - * @param array $input_vars - array of input field details |
|
| 3360 | - * @param string $generator indicates which generator to use: options are 'string' or 'array' |
|
| 3361 | - * @param bool $id |
|
| 3362 | - * @return array|string |
|
| 3363 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3364 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3365 | - */ |
|
| 3366 | - protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3367 | - { |
|
| 3368 | - return $generator === 'string' |
|
| 3369 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3370 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3371 | - } |
|
| 3372 | - |
|
| 3373 | - |
|
| 3374 | - /** |
|
| 3375 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3376 | - * |
|
| 3377 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3378 | - * Close" button. |
|
| 3379 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3380 | - * 'Save', [1] => 'save & close') |
|
| 3381 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3382 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3383 | - * default actions by submitting some other value. |
|
| 3384 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3385 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3386 | - * close (normal form handling). |
|
| 3387 | - */ |
|
| 3388 | - protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3389 | - { |
|
| 3390 | - // make sure $text and $actions are in an array |
|
| 3391 | - $text = (array) $text; |
|
| 3392 | - $actions = (array) $actions; |
|
| 3393 | - $referrer_url = empty($referrer) |
|
| 3394 | - ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3395 | - . $this->request->getServerParam('REQUEST_URI') |
|
| 3396 | - . '" />' |
|
| 3397 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3398 | - . $referrer |
|
| 3399 | - . '" />'; |
|
| 3400 | - $button_text = ! empty($text) |
|
| 3401 | - ? $text |
|
| 3402 | - : [ |
|
| 3403 | - esc_html__('Save', 'event_espresso'), |
|
| 3404 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3405 | - ]; |
|
| 3406 | - $default_names = ['save', 'save_and_close']; |
|
| 3407 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3408 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3409 | - foreach ($button_text as $key => $button) { |
|
| 3410 | - $ref = $default_names[ $key ]; |
|
| 3411 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button--primary ' |
|
| 3412 | - . $ref |
|
| 3413 | - . '" value="' |
|
| 3414 | - . $button |
|
| 3415 | - . '" name="' |
|
| 3416 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3417 | - . '" id="' |
|
| 3418 | - . $this->_current_view . '_' . $ref |
|
| 3419 | - . '" />'; |
|
| 3420 | - if (! $both) { |
|
| 3421 | - break; |
|
| 3422 | - } |
|
| 3423 | - } |
|
| 3424 | - } |
|
| 3425 | - |
|
| 3426 | - |
|
| 3427 | - /** |
|
| 3428 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3429 | - * |
|
| 3430 | - * @param string $route |
|
| 3431 | - * @param array $additional_hidden_fields |
|
| 3432 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3433 | - * @since 4.6.0 |
|
| 3434 | - */ |
|
| 3435 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3436 | - { |
|
| 3437 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3438 | - } |
|
| 3439 | - |
|
| 3440 | - |
|
| 3441 | - /** |
|
| 3442 | - * set form open and close tags on add/edit pages. |
|
| 3443 | - * |
|
| 3444 | - * @param string $route the route you want the form to direct to |
|
| 3445 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3446 | - * @return void |
|
| 3447 | - */ |
|
| 3448 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3449 | - { |
|
| 3450 | - if (empty($route)) { |
|
| 3451 | - $user_msg = esc_html__( |
|
| 3452 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3453 | - 'event_espresso' |
|
| 3454 | - ); |
|
| 3455 | - $dev_msg = $user_msg . "\n" |
|
| 3456 | - . sprintf( |
|
| 3457 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3458 | - __FUNCTION__, |
|
| 3459 | - __CLASS__ |
|
| 3460 | - ); |
|
| 3461 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3462 | - } |
|
| 3463 | - // open form |
|
| 3464 | - $action = $this->_admin_base_url; |
|
| 3465 | - $this->_template_args['before_admin_page_content'] = " |
|
| 2776 | + } |
|
| 2777 | + |
|
| 2778 | + |
|
| 2779 | + /** |
|
| 2780 | + * facade for $this->addMetaBox() |
|
| 2781 | + * |
|
| 2782 | + * @param string $action where the metabox get's displayed |
|
| 2783 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2784 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2785 | + * instead of the one created in here. |
|
| 2786 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2787 | + * @param string $column what metabox column |
|
| 2788 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2789 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2790 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2791 | + * @throws DomainException |
|
| 2792 | + */ |
|
| 2793 | + public function _add_admin_page_meta_box( |
|
| 2794 | + $action, |
|
| 2795 | + $title, |
|
| 2796 | + $callback, |
|
| 2797 | + $callback_args, |
|
| 2798 | + $column = 'normal', |
|
| 2799 | + $priority = 'high', |
|
| 2800 | + $create_func = true |
|
| 2801 | + ) { |
|
| 2802 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2803 | + // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2804 | + if (empty($callback_args) && $create_func) { |
|
| 2805 | + $callback_args = [ |
|
| 2806 | + 'template_path' => $this->_template_path, |
|
| 2807 | + 'template_args' => $this->_template_args, |
|
| 2808 | + ]; |
|
| 2809 | + } |
|
| 2810 | + // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2811 | + $call_back_func = $create_func |
|
| 2812 | + ? static function ($post, $metabox) { |
|
| 2813 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2814 | + echo EEH_Template::display_template( |
|
| 2815 | + $metabox['args']['template_path'], |
|
| 2816 | + $metabox['args']['template_args'], |
|
| 2817 | + true |
|
| 2818 | + ); |
|
| 2819 | + } |
|
| 2820 | + : $callback; |
|
| 2821 | + $this->addMetaBox( |
|
| 2822 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2823 | + $title, |
|
| 2824 | + $call_back_func, |
|
| 2825 | + $this->_wp_page_slug, |
|
| 2826 | + $column, |
|
| 2827 | + $priority, |
|
| 2828 | + $callback_args |
|
| 2829 | + ); |
|
| 2830 | + } |
|
| 2831 | + |
|
| 2832 | + |
|
| 2833 | + /** |
|
| 2834 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2835 | + * |
|
| 2836 | + * @throws DomainException |
|
| 2837 | + * @throws EE_Error |
|
| 2838 | + * @throws InvalidArgumentException |
|
| 2839 | + * @throws InvalidDataTypeException |
|
| 2840 | + * @throws InvalidInterfaceException |
|
| 2841 | + */ |
|
| 2842 | + public function display_admin_page_with_metabox_columns() |
|
| 2843 | + { |
|
| 2844 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2845 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2846 | + $this->_column_template_path, |
|
| 2847 | + $this->_template_args, |
|
| 2848 | + true |
|
| 2849 | + ); |
|
| 2850 | + // the final wrapper |
|
| 2851 | + $this->admin_page_wrapper(); |
|
| 2852 | + } |
|
| 2853 | + |
|
| 2854 | + |
|
| 2855 | + /** |
|
| 2856 | + * generates HTML wrapper for an admin details page |
|
| 2857 | + * |
|
| 2858 | + * @return void |
|
| 2859 | + * @throws DomainException |
|
| 2860 | + * @throws EE_Error |
|
| 2861 | + * @throws InvalidArgumentException |
|
| 2862 | + * @throws InvalidDataTypeException |
|
| 2863 | + * @throws InvalidInterfaceException |
|
| 2864 | + */ |
|
| 2865 | + public function display_admin_page_with_sidebar() |
|
| 2866 | + { |
|
| 2867 | + $this->_display_admin_page(true); |
|
| 2868 | + } |
|
| 2869 | + |
|
| 2870 | + |
|
| 2871 | + /** |
|
| 2872 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2873 | + * |
|
| 2874 | + * @return void |
|
| 2875 | + * @throws DomainException |
|
| 2876 | + * @throws EE_Error |
|
| 2877 | + * @throws InvalidArgumentException |
|
| 2878 | + * @throws InvalidDataTypeException |
|
| 2879 | + * @throws InvalidInterfaceException |
|
| 2880 | + */ |
|
| 2881 | + public function display_admin_page_with_no_sidebar() |
|
| 2882 | + { |
|
| 2883 | + $this->_display_admin_page(); |
|
| 2884 | + } |
|
| 2885 | + |
|
| 2886 | + |
|
| 2887 | + /** |
|
| 2888 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2889 | + * |
|
| 2890 | + * @return void |
|
| 2891 | + * @throws DomainException |
|
| 2892 | + * @throws EE_Error |
|
| 2893 | + * @throws InvalidArgumentException |
|
| 2894 | + * @throws InvalidDataTypeException |
|
| 2895 | + * @throws InvalidInterfaceException |
|
| 2896 | + */ |
|
| 2897 | + public function display_about_admin_page() |
|
| 2898 | + { |
|
| 2899 | + $this->_display_admin_page(false, true); |
|
| 2900 | + } |
|
| 2901 | + |
|
| 2902 | + |
|
| 2903 | + /** |
|
| 2904 | + * display_admin_page |
|
| 2905 | + * contains the code for actually displaying an admin page |
|
| 2906 | + * |
|
| 2907 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2908 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2909 | + * @return void |
|
| 2910 | + * @throws DomainException |
|
| 2911 | + * @throws EE_Error |
|
| 2912 | + * @throws InvalidArgumentException |
|
| 2913 | + * @throws InvalidDataTypeException |
|
| 2914 | + * @throws InvalidInterfaceException |
|
| 2915 | + */ |
|
| 2916 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2917 | + { |
|
| 2918 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2919 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2920 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2921 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2922 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2923 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2924 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2925 | + ? 'poststuff' |
|
| 2926 | + : 'espresso-default-admin'; |
|
| 2927 | + |
|
| 2928 | + $template_path = $sidebar |
|
| 2929 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2930 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2931 | + if ($this->request->isAjax()) { |
|
| 2932 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2933 | + } |
|
| 2934 | + $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2935 | + |
|
| 2936 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'] ?? ''; |
|
| 2937 | + $this->_template_args['before_admin_page_content'] = $this->_template_args['before_admin_page_content'] ?? ''; |
|
| 2938 | + $this->_template_args['after_admin_page_content'] = $this->_template_args['after_admin_page_content'] ?? ''; |
|
| 2939 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2940 | + $template_path, |
|
| 2941 | + $this->_template_args, |
|
| 2942 | + true |
|
| 2943 | + ); |
|
| 2944 | + // the final template wrapper |
|
| 2945 | + $this->admin_page_wrapper($about); |
|
| 2946 | + } |
|
| 2947 | + |
|
| 2948 | + |
|
| 2949 | + /** |
|
| 2950 | + * This is used to display caf preview pages. |
|
| 2951 | + * |
|
| 2952 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2953 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2954 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2955 | + * @return void |
|
| 2956 | + * @throws DomainException |
|
| 2957 | + * @throws EE_Error |
|
| 2958 | + * @throws InvalidArgumentException |
|
| 2959 | + * @throws InvalidDataTypeException |
|
| 2960 | + * @throws InvalidInterfaceException |
|
| 2961 | + * @since 4.3.2 |
|
| 2962 | + */ |
|
| 2963 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2964 | + { |
|
| 2965 | + // let's generate a default preview action button if there isn't one already present. |
|
| 2966 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2967 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2968 | + 'event_espresso' |
|
| 2969 | + ); |
|
| 2970 | + $buy_now_url = add_query_arg( |
|
| 2971 | + [ |
|
| 2972 | + 'ee_ver' => 'ee4', |
|
| 2973 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2974 | + 'utm_medium' => 'link', |
|
| 2975 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2976 | + 'utm_content' => 'buy_now_button', |
|
| 2977 | + ], |
|
| 2978 | + 'https://eventespresso.com/pricing/' |
|
| 2979 | + ); |
|
| 2980 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2981 | + ? $this->get_action_link_or_button( |
|
| 2982 | + '', |
|
| 2983 | + 'buy_now', |
|
| 2984 | + [], |
|
| 2985 | + 'button--primary button--big', |
|
| 2986 | + esc_url_raw($buy_now_url), |
|
| 2987 | + true |
|
| 2988 | + ) |
|
| 2989 | + : $this->_template_args['preview_action_button']; |
|
| 2990 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2991 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2992 | + $this->_template_args, |
|
| 2993 | + true |
|
| 2994 | + ); |
|
| 2995 | + $this->_display_admin_page($display_sidebar); |
|
| 2996 | + } |
|
| 2997 | + |
|
| 2998 | + |
|
| 2999 | + /** |
|
| 3000 | + * display_admin_list_table_page_with_sidebar |
|
| 3001 | + * generates HTML wrapper for an admin_page with list_table |
|
| 3002 | + * |
|
| 3003 | + * @return void |
|
| 3004 | + * @throws DomainException |
|
| 3005 | + * @throws EE_Error |
|
| 3006 | + * @throws InvalidArgumentException |
|
| 3007 | + * @throws InvalidDataTypeException |
|
| 3008 | + * @throws InvalidInterfaceException |
|
| 3009 | + */ |
|
| 3010 | + public function display_admin_list_table_page_with_sidebar() |
|
| 3011 | + { |
|
| 3012 | + $this->_display_admin_list_table_page(true); |
|
| 3013 | + } |
|
| 3014 | + |
|
| 3015 | + |
|
| 3016 | + /** |
|
| 3017 | + * display_admin_list_table_page_with_no_sidebar |
|
| 3018 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 3019 | + * |
|
| 3020 | + * @return void |
|
| 3021 | + * @throws DomainException |
|
| 3022 | + * @throws EE_Error |
|
| 3023 | + * @throws InvalidArgumentException |
|
| 3024 | + * @throws InvalidDataTypeException |
|
| 3025 | + * @throws InvalidInterfaceException |
|
| 3026 | + */ |
|
| 3027 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 3028 | + { |
|
| 3029 | + $this->_display_admin_list_table_page(); |
|
| 3030 | + } |
|
| 3031 | + |
|
| 3032 | + |
|
| 3033 | + /** |
|
| 3034 | + * generates html wrapper for an admin_list_table page |
|
| 3035 | + * |
|
| 3036 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3037 | + * @return void |
|
| 3038 | + * @throws DomainException |
|
| 3039 | + * @throws EE_Error |
|
| 3040 | + * @throws InvalidArgumentException |
|
| 3041 | + * @throws InvalidDataTypeException |
|
| 3042 | + * @throws InvalidInterfaceException |
|
| 3043 | + */ |
|
| 3044 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 3045 | + { |
|
| 3046 | + // setup search attributes |
|
| 3047 | + $this->_set_search_attributes(); |
|
| 3048 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3049 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3050 | + $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 3051 | + ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 3052 | + : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 3053 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3054 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 3055 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3056 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3057 | + if (! empty($ajax_sorting_callback)) { |
|
| 3058 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3059 | + $ajax_sorting_callback . '_nonce', |
|
| 3060 | + $ajax_sorting_callback . '_nonce', |
|
| 3061 | + false, |
|
| 3062 | + false |
|
| 3063 | + ); |
|
| 3064 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3065 | + . $this->page_slug |
|
| 3066 | + . '" />'; |
|
| 3067 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3068 | + . $ajax_sorting_callback |
|
| 3069 | + . '" />'; |
|
| 3070 | + } else { |
|
| 3071 | + $sortable_list_table_form_fields = ''; |
|
| 3072 | + } |
|
| 3073 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3074 | + $hidden_form_fields = |
|
| 3075 | + isset($this->_template_args['list_table_hidden_fields']) |
|
| 3076 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 3077 | + : ''; |
|
| 3078 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3079 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3080 | + . $nonce_ref |
|
| 3081 | + . '" value="' |
|
| 3082 | + . wp_create_nonce($nonce_ref) |
|
| 3083 | + . '">'; |
|
| 3084 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3085 | + // display message about search results? |
|
| 3086 | + $search = $this->request->getRequestParam('s'); |
|
| 3087 | + $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 3088 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 3089 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3090 | + trim($search, '%') |
|
| 3091 | + ) . '</p>' |
|
| 3092 | + : ''; |
|
| 3093 | + // filter before_list_table template arg |
|
| 3094 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 3095 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3096 | + $this->_template_args['before_list_table'], |
|
| 3097 | + $this->page_slug, |
|
| 3098 | + $this->request->requestParams(), |
|
| 3099 | + $this->_req_action |
|
| 3100 | + ); |
|
| 3101 | + // convert to array and filter again |
|
| 3102 | + // arrays are easier to inject new items in a specific location, |
|
| 3103 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3104 | + $this->_template_args['before_list_table'] = implode( |
|
| 3105 | + " \n", |
|
| 3106 | + (array) apply_filters( |
|
| 3107 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3108 | + (array) $this->_template_args['before_list_table'], |
|
| 3109 | + $this->page_slug, |
|
| 3110 | + $this->request->requestParams(), |
|
| 3111 | + $this->_req_action |
|
| 3112 | + ) |
|
| 3113 | + ); |
|
| 3114 | + // filter after_list_table template arg |
|
| 3115 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 3116 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3117 | + $this->_template_args['after_list_table'], |
|
| 3118 | + $this->page_slug, |
|
| 3119 | + $this->request->requestParams(), |
|
| 3120 | + $this->_req_action |
|
| 3121 | + ); |
|
| 3122 | + // convert to array and filter again |
|
| 3123 | + // arrays are easier to inject new items in a specific location, |
|
| 3124 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3125 | + $this->_template_args['after_list_table'] = implode( |
|
| 3126 | + " \n", |
|
| 3127 | + (array) apply_filters( |
|
| 3128 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3129 | + (array) $this->_template_args['after_list_table'], |
|
| 3130 | + $this->page_slug, |
|
| 3131 | + $this->request->requestParams(), |
|
| 3132 | + $this->_req_action |
|
| 3133 | + ) |
|
| 3134 | + ); |
|
| 3135 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3136 | + $template_path, |
|
| 3137 | + $this->_template_args, |
|
| 3138 | + true |
|
| 3139 | + ); |
|
| 3140 | + // the final template wrapper |
|
| 3141 | + if ($sidebar) { |
|
| 3142 | + $this->display_admin_page_with_sidebar(); |
|
| 3143 | + } else { |
|
| 3144 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3145 | + } |
|
| 3146 | + } |
|
| 3147 | + |
|
| 3148 | + |
|
| 3149 | + /** |
|
| 3150 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3151 | + * html string for the legend. |
|
| 3152 | + * $items are expected in an array in the following format: |
|
| 3153 | + * $legend_items = array( |
|
| 3154 | + * 'item_id' => array( |
|
| 3155 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3156 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3157 | + * ) |
|
| 3158 | + * ); |
|
| 3159 | + * |
|
| 3160 | + * @param array $items see above for format of array |
|
| 3161 | + * @return string html string of legend |
|
| 3162 | + * @throws DomainException |
|
| 3163 | + */ |
|
| 3164 | + protected function _display_legend($items) |
|
| 3165 | + { |
|
| 3166 | + $this->_template_args['items'] = apply_filters( |
|
| 3167 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3168 | + (array) $items, |
|
| 3169 | + $this |
|
| 3170 | + ); |
|
| 3171 | + /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
|
| 3172 | + $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
|
| 3173 | + if (! $status_change_notice->isDismissed()) { |
|
| 3174 | + $this->_template_args['status_change_notice'] = EEH_Template::display_template( |
|
| 3175 | + EE_ADMIN_TEMPLATE . 'status_change_notice.template.php', |
|
| 3176 | + [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ], |
|
| 3177 | + true |
|
| 3178 | + ); |
|
| 3179 | + } |
|
| 3180 | + return EEH_Template::display_template( |
|
| 3181 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3182 | + $this->_template_args, |
|
| 3183 | + true |
|
| 3184 | + ); |
|
| 3185 | + } |
|
| 3186 | + |
|
| 3187 | + |
|
| 3188 | + /** |
|
| 3189 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3190 | + * The returned json object is created from an array in the following format: |
|
| 3191 | + * array( |
|
| 3192 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3193 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3194 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3195 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3196 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3197 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3198 | + * that might be included in here) |
|
| 3199 | + * ) |
|
| 3200 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3201 | + * |
|
| 3202 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3203 | + * instead of displayed. |
|
| 3204 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3205 | + * @return void |
|
| 3206 | + * @throws EE_Error |
|
| 3207 | + * @throws InvalidArgumentException |
|
| 3208 | + * @throws InvalidDataTypeException |
|
| 3209 | + * @throws InvalidInterfaceException |
|
| 3210 | + */ |
|
| 3211 | + protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 3212 | + { |
|
| 3213 | + // make sure any EE_Error notices have been handled. |
|
| 3214 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3215 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 3216 | + unset($this->_template_args['data']); |
|
| 3217 | + $json = [ |
|
| 3218 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3219 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3220 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3221 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3222 | + 'notices' => EE_Error::get_notices(), |
|
| 3223 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3224 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 3225 | + 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 3226 | + 'isEEajax' => true |
|
| 3227 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3228 | + ]; |
|
| 3229 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3230 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3231 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3232 | + } |
|
| 3233 | + echo wp_json_encode($json); |
|
| 3234 | + exit(); |
|
| 3235 | + } |
|
| 3236 | + |
|
| 3237 | + |
|
| 3238 | + /** |
|
| 3239 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3240 | + * |
|
| 3241 | + * @return void |
|
| 3242 | + * @throws EE_Error |
|
| 3243 | + * @throws InvalidArgumentException |
|
| 3244 | + * @throws InvalidDataTypeException |
|
| 3245 | + * @throws InvalidInterfaceException |
|
| 3246 | + */ |
|
| 3247 | + public function return_json() |
|
| 3248 | + { |
|
| 3249 | + if ($this->request->isAjax()) { |
|
| 3250 | + $this->_return_json(); |
|
| 3251 | + } else { |
|
| 3252 | + throw new EE_Error( |
|
| 3253 | + sprintf( |
|
| 3254 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3255 | + __FUNCTION__ |
|
| 3256 | + ) |
|
| 3257 | + ); |
|
| 3258 | + } |
|
| 3259 | + } |
|
| 3260 | + |
|
| 3261 | + |
|
| 3262 | + /** |
|
| 3263 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3264 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3265 | + * |
|
| 3266 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3267 | + */ |
|
| 3268 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3269 | + { |
|
| 3270 | + $this->_hook_obj = $hook_obj; |
|
| 3271 | + } |
|
| 3272 | + |
|
| 3273 | + |
|
| 3274 | + /** |
|
| 3275 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3276 | + * |
|
| 3277 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3278 | + * @return void |
|
| 3279 | + * @throws DomainException |
|
| 3280 | + * @throws EE_Error |
|
| 3281 | + * @throws InvalidArgumentException |
|
| 3282 | + * @throws InvalidDataTypeException |
|
| 3283 | + * @throws InvalidInterfaceException |
|
| 3284 | + */ |
|
| 3285 | + public function admin_page_wrapper($about = false) |
|
| 3286 | + { |
|
| 3287 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3288 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3289 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3290 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3291 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3292 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3293 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3294 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3295 | + : '' |
|
| 3296 | + ); |
|
| 3297 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3298 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3299 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3300 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3301 | + : '' |
|
| 3302 | + ); |
|
| 3303 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3304 | + // load settings page wrapper template |
|
| 3305 | + $template_path = ! $this->request->isAjax() |
|
| 3306 | + ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3307 | + : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 3308 | + // about page? |
|
| 3309 | + $template_path = $about |
|
| 3310 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3311 | + : $template_path; |
|
| 3312 | + if ($this->request->isAjax()) { |
|
| 3313 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3314 | + $template_path, |
|
| 3315 | + $this->_template_args, |
|
| 3316 | + true |
|
| 3317 | + ); |
|
| 3318 | + $this->_return_json(); |
|
| 3319 | + } else { |
|
| 3320 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3321 | + } |
|
| 3322 | + } |
|
| 3323 | + |
|
| 3324 | + |
|
| 3325 | + /** |
|
| 3326 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3327 | + * |
|
| 3328 | + * @return string html |
|
| 3329 | + * @throws EE_Error |
|
| 3330 | + */ |
|
| 3331 | + protected function _get_main_nav_tabs() |
|
| 3332 | + { |
|
| 3333 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3334 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3335 | + // (rather than setting in the page_routes array) |
|
| 3336 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3337 | + } |
|
| 3338 | + |
|
| 3339 | + |
|
| 3340 | + /** |
|
| 3341 | + * sort nav tabs |
|
| 3342 | + * |
|
| 3343 | + * @param $a |
|
| 3344 | + * @param $b |
|
| 3345 | + * @return int |
|
| 3346 | + */ |
|
| 3347 | + private function _sort_nav_tabs($a, $b) |
|
| 3348 | + { |
|
| 3349 | + if ($a['order'] === $b['order']) { |
|
| 3350 | + return 0; |
|
| 3351 | + } |
|
| 3352 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3353 | + } |
|
| 3354 | + |
|
| 3355 | + |
|
| 3356 | + /** |
|
| 3357 | + * generates HTML for the forms used on admin pages |
|
| 3358 | + * |
|
| 3359 | + * @param array $input_vars - array of input field details |
|
| 3360 | + * @param string $generator indicates which generator to use: options are 'string' or 'array' |
|
| 3361 | + * @param bool $id |
|
| 3362 | + * @return array|string |
|
| 3363 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3364 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3365 | + */ |
|
| 3366 | + protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3367 | + { |
|
| 3368 | + return $generator === 'string' |
|
| 3369 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3370 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3371 | + } |
|
| 3372 | + |
|
| 3373 | + |
|
| 3374 | + /** |
|
| 3375 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3376 | + * |
|
| 3377 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3378 | + * Close" button. |
|
| 3379 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3380 | + * 'Save', [1] => 'save & close') |
|
| 3381 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3382 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3383 | + * default actions by submitting some other value. |
|
| 3384 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3385 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3386 | + * close (normal form handling). |
|
| 3387 | + */ |
|
| 3388 | + protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3389 | + { |
|
| 3390 | + // make sure $text and $actions are in an array |
|
| 3391 | + $text = (array) $text; |
|
| 3392 | + $actions = (array) $actions; |
|
| 3393 | + $referrer_url = empty($referrer) |
|
| 3394 | + ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3395 | + . $this->request->getServerParam('REQUEST_URI') |
|
| 3396 | + . '" />' |
|
| 3397 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3398 | + . $referrer |
|
| 3399 | + . '" />'; |
|
| 3400 | + $button_text = ! empty($text) |
|
| 3401 | + ? $text |
|
| 3402 | + : [ |
|
| 3403 | + esc_html__('Save', 'event_espresso'), |
|
| 3404 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3405 | + ]; |
|
| 3406 | + $default_names = ['save', 'save_and_close']; |
|
| 3407 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3408 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3409 | + foreach ($button_text as $key => $button) { |
|
| 3410 | + $ref = $default_names[ $key ]; |
|
| 3411 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button--primary ' |
|
| 3412 | + . $ref |
|
| 3413 | + . '" value="' |
|
| 3414 | + . $button |
|
| 3415 | + . '" name="' |
|
| 3416 | + . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3417 | + . '" id="' |
|
| 3418 | + . $this->_current_view . '_' . $ref |
|
| 3419 | + . '" />'; |
|
| 3420 | + if (! $both) { |
|
| 3421 | + break; |
|
| 3422 | + } |
|
| 3423 | + } |
|
| 3424 | + } |
|
| 3425 | + |
|
| 3426 | + |
|
| 3427 | + /** |
|
| 3428 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3429 | + * |
|
| 3430 | + * @param string $route |
|
| 3431 | + * @param array $additional_hidden_fields |
|
| 3432 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3433 | + * @since 4.6.0 |
|
| 3434 | + */ |
|
| 3435 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3436 | + { |
|
| 3437 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3438 | + } |
|
| 3439 | + |
|
| 3440 | + |
|
| 3441 | + /** |
|
| 3442 | + * set form open and close tags on add/edit pages. |
|
| 3443 | + * |
|
| 3444 | + * @param string $route the route you want the form to direct to |
|
| 3445 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3446 | + * @return void |
|
| 3447 | + */ |
|
| 3448 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3449 | + { |
|
| 3450 | + if (empty($route)) { |
|
| 3451 | + $user_msg = esc_html__( |
|
| 3452 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3453 | + 'event_espresso' |
|
| 3454 | + ); |
|
| 3455 | + $dev_msg = $user_msg . "\n" |
|
| 3456 | + . sprintf( |
|
| 3457 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3458 | + __FUNCTION__, |
|
| 3459 | + __CLASS__ |
|
| 3460 | + ); |
|
| 3461 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3462 | + } |
|
| 3463 | + // open form |
|
| 3464 | + $action = $this->_admin_base_url; |
|
| 3465 | + $this->_template_args['before_admin_page_content'] = " |
|
| 3466 | 3466 | <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' > |
| 3467 | 3467 | "; |
| 3468 | - // add nonce |
|
| 3469 | - $nonce = |
|
| 3470 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3471 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3472 | - // add REQUIRED form action |
|
| 3473 | - $hidden_fields = [ |
|
| 3474 | - 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3475 | - ]; |
|
| 3476 | - // merge arrays |
|
| 3477 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3478 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3479 | - : $hidden_fields; |
|
| 3480 | - // generate form fields |
|
| 3481 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3482 | - // add fields to form |
|
| 3483 | - foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3484 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3485 | - } |
|
| 3486 | - // close form |
|
| 3487 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3488 | - } |
|
| 3489 | - |
|
| 3490 | - |
|
| 3491 | - /** |
|
| 3492 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3493 | - * discovered it would be useful for external code to have access. |
|
| 3494 | - * |
|
| 3495 | - * @param bool $success |
|
| 3496 | - * @param string $what |
|
| 3497 | - * @param string $action_desc |
|
| 3498 | - * @param array $query_args |
|
| 3499 | - * @param bool $override_overwrite |
|
| 3500 | - * @throws EE_Error |
|
| 3501 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3502 | - * @since 4.5.0 |
|
| 3503 | - */ |
|
| 3504 | - public function redirect_after_action( |
|
| 3505 | - $success = false, |
|
| 3506 | - $what = 'item', |
|
| 3507 | - $action_desc = 'processed', |
|
| 3508 | - $query_args = [], |
|
| 3509 | - $override_overwrite = false |
|
| 3510 | - ) { |
|
| 3511 | - $this->_redirect_after_action( |
|
| 3512 | - $success, |
|
| 3513 | - $what, |
|
| 3514 | - $action_desc, |
|
| 3515 | - $query_args, |
|
| 3516 | - $override_overwrite |
|
| 3517 | - ); |
|
| 3518 | - } |
|
| 3519 | - |
|
| 3520 | - |
|
| 3521 | - /** |
|
| 3522 | - * Helper method for merging existing request data with the returned redirect url. |
|
| 3523 | - * |
|
| 3524 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3525 | - * filters are still applied. |
|
| 3526 | - * |
|
| 3527 | - * @param array $new_route_data |
|
| 3528 | - * @return array |
|
| 3529 | - */ |
|
| 3530 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3531 | - { |
|
| 3532 | - foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3533 | - // unset nonces |
|
| 3534 | - if (strpos($ref, 'nonce') !== false) { |
|
| 3535 | - $this->request->unSetRequestParam($ref); |
|
| 3536 | - continue; |
|
| 3537 | - } |
|
| 3538 | - // urlencode values. |
|
| 3539 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3540 | - $this->request->setRequestParam($ref, $value); |
|
| 3541 | - } |
|
| 3542 | - return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3543 | - } |
|
| 3544 | - |
|
| 3545 | - |
|
| 3546 | - /** |
|
| 3547 | - * _redirect_after_action |
|
| 3548 | - * |
|
| 3549 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3550 | - * @param string $what - what the action was performed on |
|
| 3551 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3552 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3553 | - * action is completed |
|
| 3554 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3555 | - * override this so that they show. |
|
| 3556 | - * @return void |
|
| 3557 | - * @throws EE_Error |
|
| 3558 | - * @throws InvalidArgumentException |
|
| 3559 | - * @throws InvalidDataTypeException |
|
| 3560 | - * @throws InvalidInterfaceException |
|
| 3561 | - */ |
|
| 3562 | - protected function _redirect_after_action( |
|
| 3563 | - $success = 0, |
|
| 3564 | - $what = 'item', |
|
| 3565 | - $action_desc = 'processed', |
|
| 3566 | - $query_args = [], |
|
| 3567 | - $override_overwrite = false |
|
| 3568 | - ) { |
|
| 3569 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3570 | - // class name for actions/filters. |
|
| 3571 | - $classname = get_class($this); |
|
| 3572 | - // set redirect url. |
|
| 3573 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3574 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3575 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3576 | - $notices = EE_Error::get_notices(false); |
|
| 3577 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3578 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3579 | - EE_Error::overwrite_success(); |
|
| 3580 | - } |
|
| 3581 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3582 | - // how many records affected ? more than one record ? or just one ? |
|
| 3583 | - if ($success > 1) { |
|
| 3584 | - // set plural msg |
|
| 3585 | - EE_Error::add_success( |
|
| 3586 | - sprintf( |
|
| 3587 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3588 | - $what, |
|
| 3589 | - $action_desc |
|
| 3590 | - ), |
|
| 3591 | - __FILE__, |
|
| 3592 | - __FUNCTION__, |
|
| 3593 | - __LINE__ |
|
| 3594 | - ); |
|
| 3595 | - } elseif ($success === 1) { |
|
| 3596 | - // set singular msg |
|
| 3597 | - EE_Error::add_success( |
|
| 3598 | - sprintf( |
|
| 3599 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3600 | - $what, |
|
| 3601 | - $action_desc |
|
| 3602 | - ), |
|
| 3603 | - __FILE__, |
|
| 3604 | - __FUNCTION__, |
|
| 3605 | - __LINE__ |
|
| 3606 | - ); |
|
| 3607 | - } |
|
| 3608 | - } |
|
| 3609 | - // check that $query_args isn't something crazy |
|
| 3610 | - if (! is_array($query_args)) { |
|
| 3611 | - $query_args = []; |
|
| 3612 | - } |
|
| 3613 | - /** |
|
| 3614 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3615 | - * redirections on save and close actions |
|
| 3616 | - * |
|
| 3617 | - * @param array $query_args The original query_args array coming into the |
|
| 3618 | - * method. |
|
| 3619 | - * @since 4.2.0 |
|
| 3620 | - */ |
|
| 3621 | - do_action( |
|
| 3622 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3623 | - $query_args |
|
| 3624 | - ); |
|
| 3625 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3626 | - |
|
| 3627 | - if ( |
|
| 3628 | - $this->request->requestParamIsSet('save_and_close') |
|
| 3629 | - && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3630 | - ) { |
|
| 3631 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3632 | - $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3633 | - // regenerate query args array from referrer URL |
|
| 3634 | - parse_str($parsed_url['query'], $query_args); |
|
| 3635 | - // correct page and action will be in the query args now |
|
| 3636 | - $redirect_url = admin_url('admin.php'); |
|
| 3637 | - } |
|
| 3638 | - // merge any default query_args set in _default_route_query_args property |
|
| 3639 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3640 | - $args_to_merge = []; |
|
| 3641 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3642 | - // is there a wp_referer array in our _default_route_query_args property? |
|
| 3643 | - if ($query_param === 'wp_referer') { |
|
| 3644 | - $query_value = (array) $query_value; |
|
| 3645 | - foreach ($query_value as $reference => $value) { |
|
| 3646 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3647 | - continue; |
|
| 3648 | - } |
|
| 3649 | - // finally we will override any arguments in the referer with |
|
| 3650 | - // what might be set on the _default_route_query_args array. |
|
| 3651 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3652 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3653 | - } else { |
|
| 3654 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3655 | - } |
|
| 3656 | - } |
|
| 3657 | - continue; |
|
| 3658 | - } |
|
| 3659 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3660 | - } |
|
| 3661 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3662 | - // redirect. |
|
| 3663 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3664 | - } |
|
| 3665 | - $this->_process_notices($query_args); |
|
| 3666 | - // generate redirect url |
|
| 3667 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3668 | - if (isset($query_args['action'])) { |
|
| 3669 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3670 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3671 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3672 | - } |
|
| 3673 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3674 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3675 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3676 | - $redirect_url = apply_filters( |
|
| 3677 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3678 | - EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3679 | - $query_args |
|
| 3680 | - ); |
|
| 3681 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3682 | - if ($this->request->isAjax()) { |
|
| 3683 | - $default_data = [ |
|
| 3684 | - 'close' => true, |
|
| 3685 | - 'redirect_url' => $redirect_url, |
|
| 3686 | - 'where' => 'main', |
|
| 3687 | - 'what' => 'append', |
|
| 3688 | - ]; |
|
| 3689 | - $this->_template_args['success'] = $success; |
|
| 3690 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3691 | - $default_data, |
|
| 3692 | - $this->_template_args['data'] |
|
| 3693 | - ) : $default_data; |
|
| 3694 | - $this->_return_json(); |
|
| 3695 | - } |
|
| 3696 | - wp_safe_redirect($redirect_url); |
|
| 3697 | - exit(); |
|
| 3698 | - } |
|
| 3699 | - |
|
| 3700 | - |
|
| 3701 | - /** |
|
| 3702 | - * process any notices before redirecting (or returning ajax request) |
|
| 3703 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3704 | - * |
|
| 3705 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3706 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3707 | - * page_routes haven't been defined yet. |
|
| 3708 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3709 | - * still save a transient for the notice. |
|
| 3710 | - * @return void |
|
| 3711 | - * @throws EE_Error |
|
| 3712 | - * @throws InvalidArgumentException |
|
| 3713 | - * @throws InvalidDataTypeException |
|
| 3714 | - * @throws InvalidInterfaceException |
|
| 3715 | - */ |
|
| 3716 | - protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3717 | - { |
|
| 3718 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3719 | - if ($this->request->isAjax()) { |
|
| 3720 | - $notices = EE_Error::get_notices(false); |
|
| 3721 | - if (empty($this->_template_args['success'])) { |
|
| 3722 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3723 | - } |
|
| 3724 | - if (empty($this->_template_args['errors'])) { |
|
| 3725 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3726 | - } |
|
| 3727 | - if (empty($this->_template_args['attention'])) { |
|
| 3728 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3729 | - } |
|
| 3730 | - } |
|
| 3731 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3732 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3733 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3734 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3735 | - $this->_add_transient( |
|
| 3736 | - $route, |
|
| 3737 | - $this->_template_args['notices'], |
|
| 3738 | - true, |
|
| 3739 | - $skip_route_verify |
|
| 3740 | - ); |
|
| 3741 | - } |
|
| 3742 | - } |
|
| 3743 | - |
|
| 3744 | - |
|
| 3745 | - /** |
|
| 3746 | - * get_action_link_or_button |
|
| 3747 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3748 | - * |
|
| 3749 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3750 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3751 | - * property. |
|
| 3752 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3753 | - * @param string $class Use this to give the class for the button. Defaults to 'button--primary' |
|
| 3754 | - * @param string $base_url If this is not provided |
|
| 3755 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3756 | - * Otherwise this value will be used. |
|
| 3757 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3758 | - * @return string |
|
| 3759 | - * @throws InvalidArgumentException |
|
| 3760 | - * @throws InvalidInterfaceException |
|
| 3761 | - * @throws InvalidDataTypeException |
|
| 3762 | - * @throws EE_Error |
|
| 3763 | - */ |
|
| 3764 | - public function get_action_link_or_button( |
|
| 3765 | - $action, |
|
| 3766 | - $type = 'add', |
|
| 3767 | - $extra_request = [], |
|
| 3768 | - $class = 'button--primary', |
|
| 3769 | - $base_url = '', |
|
| 3770 | - $exclude_nonce = false |
|
| 3771 | - ) { |
|
| 3772 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3773 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3774 | - throw new EE_Error( |
|
| 3775 | - sprintf( |
|
| 3776 | - esc_html__( |
|
| 3777 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3778 | - 'event_espresso' |
|
| 3779 | - ), |
|
| 3780 | - $action |
|
| 3781 | - ) |
|
| 3782 | - ); |
|
| 3783 | - } |
|
| 3784 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3785 | - throw new EE_Error( |
|
| 3786 | - sprintf( |
|
| 3787 | - esc_html__( |
|
| 3788 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3789 | - 'event_espresso' |
|
| 3790 | - ), |
|
| 3791 | - $type |
|
| 3792 | - ) |
|
| 3793 | - ); |
|
| 3794 | - } |
|
| 3795 | - // finally check user access for this button. |
|
| 3796 | - $has_access = $this->check_user_access($action, true); |
|
| 3797 | - if (! $has_access) { |
|
| 3798 | - return ''; |
|
| 3799 | - } |
|
| 3800 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3801 | - $query_args = [ |
|
| 3802 | - 'action' => $action, |
|
| 3803 | - ]; |
|
| 3804 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3805 | - if (! empty($extra_request)) { |
|
| 3806 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3807 | - } |
|
| 3808 | - $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3809 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3810 | - } |
|
| 3811 | - |
|
| 3812 | - |
|
| 3813 | - /** |
|
| 3814 | - * _per_page_screen_option |
|
| 3815 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3816 | - * |
|
| 3817 | - * @return void |
|
| 3818 | - * @throws InvalidArgumentException |
|
| 3819 | - * @throws InvalidInterfaceException |
|
| 3820 | - * @throws InvalidDataTypeException |
|
| 3821 | - */ |
|
| 3822 | - protected function _per_page_screen_option() |
|
| 3823 | - { |
|
| 3824 | - $option = 'per_page'; |
|
| 3825 | - $args = [ |
|
| 3826 | - 'label' => apply_filters( |
|
| 3827 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3828 | - $this->_admin_page_title, |
|
| 3829 | - $this |
|
| 3830 | - ), |
|
| 3831 | - 'default' => (int) apply_filters( |
|
| 3832 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3833 | - 20 |
|
| 3834 | - ), |
|
| 3835 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3836 | - ]; |
|
| 3837 | - // ONLY add the screen option if the user has access to it. |
|
| 3838 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3839 | - add_screen_option($option, $args); |
|
| 3840 | - } |
|
| 3841 | - } |
|
| 3842 | - |
|
| 3843 | - |
|
| 3844 | - /** |
|
| 3845 | - * set_per_page_screen_option |
|
| 3846 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3847 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3848 | - * admin_menu. |
|
| 3849 | - * |
|
| 3850 | - * @return void |
|
| 3851 | - */ |
|
| 3852 | - private function _set_per_page_screen_options() |
|
| 3853 | - { |
|
| 3854 | - if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3855 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3856 | - if (! $user = wp_get_current_user()) { |
|
| 3857 | - return; |
|
| 3858 | - } |
|
| 3859 | - $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3860 | - if (! $option) { |
|
| 3861 | - return; |
|
| 3862 | - } |
|
| 3863 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3864 | - $map_option = $option; |
|
| 3865 | - $option = str_replace('-', '_', $option); |
|
| 3866 | - switch ($map_option) { |
|
| 3867 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3868 | - $max_value = apply_filters( |
|
| 3869 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3870 | - 999, |
|
| 3871 | - $this->_current_page, |
|
| 3872 | - $this->_current_view |
|
| 3873 | - ); |
|
| 3874 | - if ($value < 1) { |
|
| 3875 | - return; |
|
| 3876 | - } |
|
| 3877 | - $value = min($value, $max_value); |
|
| 3878 | - break; |
|
| 3879 | - default: |
|
| 3880 | - $value = apply_filters( |
|
| 3881 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3882 | - false, |
|
| 3883 | - $option, |
|
| 3884 | - $value |
|
| 3885 | - ); |
|
| 3886 | - if (false === $value) { |
|
| 3887 | - return; |
|
| 3888 | - } |
|
| 3889 | - break; |
|
| 3890 | - } |
|
| 3891 | - update_user_meta($user->ID, $option, $value); |
|
| 3892 | - wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3893 | - exit; |
|
| 3894 | - } |
|
| 3895 | - } |
|
| 3896 | - |
|
| 3897 | - |
|
| 3898 | - /** |
|
| 3899 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3900 | - * |
|
| 3901 | - * @param array $data array that will be assigned to template args. |
|
| 3902 | - */ |
|
| 3903 | - public function set_template_args($data) |
|
| 3904 | - { |
|
| 3905 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3906 | - } |
|
| 3907 | - |
|
| 3908 | - |
|
| 3909 | - /** |
|
| 3910 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3911 | - * |
|
| 3912 | - * @param string $route the route that should receive the transient |
|
| 3913 | - * @param array $data the data that gets sent |
|
| 3914 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3915 | - * normal route transient. |
|
| 3916 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3917 | - * when we are adding a transient before page_routes have been defined. |
|
| 3918 | - * @return void |
|
| 3919 | - * @throws EE_Error |
|
| 3920 | - */ |
|
| 3921 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3922 | - { |
|
| 3923 | - $user_id = get_current_user_id(); |
|
| 3924 | - if (! $skip_route_verify) { |
|
| 3925 | - $this->_verify_route($route); |
|
| 3926 | - } |
|
| 3927 | - // now let's set the string for what kind of transient we're setting |
|
| 3928 | - $transient = $notices |
|
| 3929 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3930 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3931 | - $data = $notices ? ['notices' => $data] : $data; |
|
| 3932 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3933 | - $existing = is_multisite() && is_network_admin() |
|
| 3934 | - ? get_site_transient($transient) |
|
| 3935 | - : get_transient($transient); |
|
| 3936 | - if ($existing) { |
|
| 3937 | - $data = array_merge((array) $data, (array) $existing); |
|
| 3938 | - } |
|
| 3939 | - if (is_multisite() && is_network_admin()) { |
|
| 3940 | - set_site_transient($transient, $data, 8); |
|
| 3941 | - } else { |
|
| 3942 | - set_transient($transient, $data, 8); |
|
| 3943 | - } |
|
| 3944 | - } |
|
| 3945 | - |
|
| 3946 | - |
|
| 3947 | - /** |
|
| 3948 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3949 | - * |
|
| 3950 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3951 | - * @param string $route |
|
| 3952 | - * @return mixed data |
|
| 3953 | - */ |
|
| 3954 | - protected function _get_transient($notices = false, $route = '') |
|
| 3955 | - { |
|
| 3956 | - $user_id = get_current_user_id(); |
|
| 3957 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3958 | - $transient = $notices |
|
| 3959 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3960 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3961 | - $data = is_multisite() && is_network_admin() |
|
| 3962 | - ? get_site_transient($transient) |
|
| 3963 | - : get_transient($transient); |
|
| 3964 | - // delete transient after retrieval (just in case it hasn't expired); |
|
| 3965 | - if (is_multisite() && is_network_admin()) { |
|
| 3966 | - delete_site_transient($transient); |
|
| 3967 | - } else { |
|
| 3968 | - delete_transient($transient); |
|
| 3969 | - } |
|
| 3970 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3971 | - } |
|
| 3972 | - |
|
| 3973 | - |
|
| 3974 | - /** |
|
| 3975 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3976 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3977 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3978 | - * |
|
| 3979 | - * @return void |
|
| 3980 | - */ |
|
| 3981 | - protected function _transient_garbage_collection() |
|
| 3982 | - { |
|
| 3983 | - global $wpdb; |
|
| 3984 | - // retrieve all existing transients |
|
| 3985 | - $query = |
|
| 3986 | - "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3987 | - if ($results = $wpdb->get_results($query)) { |
|
| 3988 | - foreach ($results as $result) { |
|
| 3989 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3990 | - get_transient($transient); |
|
| 3991 | - if (is_multisite() && is_network_admin()) { |
|
| 3992 | - get_site_transient($transient); |
|
| 3993 | - } |
|
| 3994 | - } |
|
| 3995 | - } |
|
| 3996 | - } |
|
| 3997 | - |
|
| 3998 | - |
|
| 3999 | - /** |
|
| 4000 | - * get_view |
|
| 4001 | - * |
|
| 4002 | - * @return string content of _view property |
|
| 4003 | - */ |
|
| 4004 | - public function get_view() |
|
| 4005 | - { |
|
| 4006 | - return $this->_view; |
|
| 4007 | - } |
|
| 4008 | - |
|
| 4009 | - |
|
| 4010 | - /** |
|
| 4011 | - * getter for the protected $_views property |
|
| 4012 | - * |
|
| 4013 | - * @return array |
|
| 4014 | - */ |
|
| 4015 | - public function get_views() |
|
| 4016 | - { |
|
| 4017 | - return $this->_views; |
|
| 4018 | - } |
|
| 4019 | - |
|
| 4020 | - |
|
| 4021 | - /** |
|
| 4022 | - * get_current_page |
|
| 4023 | - * |
|
| 4024 | - * @return string _current_page property value |
|
| 4025 | - */ |
|
| 4026 | - public function get_current_page() |
|
| 4027 | - { |
|
| 4028 | - return $this->_current_page; |
|
| 4029 | - } |
|
| 4030 | - |
|
| 4031 | - |
|
| 4032 | - /** |
|
| 4033 | - * get_current_view |
|
| 4034 | - * |
|
| 4035 | - * @return string _current_view property value |
|
| 4036 | - */ |
|
| 4037 | - public function get_current_view() |
|
| 4038 | - { |
|
| 4039 | - return $this->_current_view; |
|
| 4040 | - } |
|
| 4041 | - |
|
| 4042 | - |
|
| 4043 | - /** |
|
| 4044 | - * get_current_screen |
|
| 4045 | - * |
|
| 4046 | - * @return object The current WP_Screen object |
|
| 4047 | - */ |
|
| 4048 | - public function get_current_screen() |
|
| 4049 | - { |
|
| 4050 | - return $this->_current_screen; |
|
| 4051 | - } |
|
| 4052 | - |
|
| 4053 | - |
|
| 4054 | - /** |
|
| 4055 | - * get_current_page_view_url |
|
| 4056 | - * |
|
| 4057 | - * @return string This returns the url for the current_page_view. |
|
| 4058 | - */ |
|
| 4059 | - public function get_current_page_view_url() |
|
| 4060 | - { |
|
| 4061 | - return $this->_current_page_view_url; |
|
| 4062 | - } |
|
| 4063 | - |
|
| 4064 | - |
|
| 4065 | - /** |
|
| 4066 | - * just returns the Request |
|
| 4067 | - * |
|
| 4068 | - * @return RequestInterface |
|
| 4069 | - */ |
|
| 4070 | - public function get_request() |
|
| 4071 | - { |
|
| 4072 | - return $this->request; |
|
| 4073 | - } |
|
| 4074 | - |
|
| 4075 | - |
|
| 4076 | - /** |
|
| 4077 | - * just returns the _req_data property |
|
| 4078 | - * |
|
| 4079 | - * @return array |
|
| 4080 | - */ |
|
| 4081 | - public function get_request_data() |
|
| 4082 | - { |
|
| 4083 | - return $this->request->requestParams(); |
|
| 4084 | - } |
|
| 4085 | - |
|
| 4086 | - |
|
| 4087 | - /** |
|
| 4088 | - * returns the _req_data protected property |
|
| 4089 | - * |
|
| 4090 | - * @return string |
|
| 4091 | - */ |
|
| 4092 | - public function get_req_action() |
|
| 4093 | - { |
|
| 4094 | - return $this->_req_action; |
|
| 4095 | - } |
|
| 4096 | - |
|
| 4097 | - |
|
| 4098 | - /** |
|
| 4099 | - * @return bool value of $_is_caf property |
|
| 4100 | - */ |
|
| 4101 | - public function is_caf() |
|
| 4102 | - { |
|
| 4103 | - return $this->_is_caf; |
|
| 4104 | - } |
|
| 4105 | - |
|
| 4106 | - |
|
| 4107 | - /** |
|
| 4108 | - * @return mixed |
|
| 4109 | - */ |
|
| 4110 | - public function default_espresso_metaboxes() |
|
| 4111 | - { |
|
| 4112 | - return $this->_default_espresso_metaboxes; |
|
| 4113 | - } |
|
| 4114 | - |
|
| 4115 | - |
|
| 4116 | - /** |
|
| 4117 | - * @return mixed |
|
| 4118 | - */ |
|
| 4119 | - public function admin_base_url() |
|
| 4120 | - { |
|
| 4121 | - return $this->_admin_base_url; |
|
| 4122 | - } |
|
| 4123 | - |
|
| 4124 | - |
|
| 4125 | - /** |
|
| 4126 | - * @return mixed |
|
| 4127 | - */ |
|
| 4128 | - public function wp_page_slug() |
|
| 4129 | - { |
|
| 4130 | - return $this->_wp_page_slug; |
|
| 4131 | - } |
|
| 4132 | - |
|
| 4133 | - |
|
| 4134 | - /** |
|
| 4135 | - * updates espresso configuration settings |
|
| 4136 | - * |
|
| 4137 | - * @param string $tab |
|
| 4138 | - * @param EE_Config_Base|EE_Config $config |
|
| 4139 | - * @param string $file file where error occurred |
|
| 4140 | - * @param string $func function where error occurred |
|
| 4141 | - * @param string $line line no where error occurred |
|
| 4142 | - * @return boolean |
|
| 4143 | - */ |
|
| 4144 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4145 | - { |
|
| 4146 | - // remove any options that are NOT going to be saved with the config settings. |
|
| 4147 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 4148 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4149 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4150 | - update_option('ee_ueip_has_notified', true); |
|
| 4151 | - } |
|
| 4152 | - // and save it (note we're also doing the network save here) |
|
| 4153 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4154 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4155 | - if ($config_saved && $net_saved) { |
|
| 4156 | - EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4157 | - return true; |
|
| 4158 | - } |
|
| 4159 | - EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4160 | - return false; |
|
| 4161 | - } |
|
| 4162 | - |
|
| 4163 | - |
|
| 4164 | - /** |
|
| 4165 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4166 | - * |
|
| 4167 | - * @return array |
|
| 4168 | - */ |
|
| 4169 | - public function get_yes_no_values() |
|
| 4170 | - { |
|
| 4171 | - return $this->_yes_no_values; |
|
| 4172 | - } |
|
| 4173 | - |
|
| 4174 | - |
|
| 4175 | - /** |
|
| 4176 | - * @return string |
|
| 4177 | - * @throws ReflectionException |
|
| 4178 | - * @since $VID:$ |
|
| 4179 | - */ |
|
| 4180 | - protected function _get_dir() |
|
| 4181 | - { |
|
| 4182 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 4183 | - return dirname($reflector->getFileName()); |
|
| 4184 | - } |
|
| 4185 | - |
|
| 4186 | - |
|
| 4187 | - /** |
|
| 4188 | - * A helper for getting a "next link". |
|
| 4189 | - * |
|
| 4190 | - * @param string $url The url to link to |
|
| 4191 | - * @param string $class The class to use. |
|
| 4192 | - * @return string |
|
| 4193 | - */ |
|
| 4194 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4195 | - { |
|
| 4196 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4197 | - } |
|
| 4198 | - |
|
| 4199 | - |
|
| 4200 | - /** |
|
| 4201 | - * A helper for getting a "previous link". |
|
| 4202 | - * |
|
| 4203 | - * @param string $url The url to link to |
|
| 4204 | - * @param string $class The class to use. |
|
| 4205 | - * @return string |
|
| 4206 | - */ |
|
| 4207 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4208 | - { |
|
| 4209 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4210 | - } |
|
| 4211 | - |
|
| 4212 | - |
|
| 4213 | - |
|
| 4214 | - |
|
| 4215 | - |
|
| 4216 | - |
|
| 4217 | - |
|
| 4218 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4219 | - |
|
| 4220 | - |
|
| 4221 | - /** |
|
| 4222 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4223 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4224 | - * _req_data array. |
|
| 4225 | - * |
|
| 4226 | - * @return bool success/fail |
|
| 4227 | - * @throws EE_Error |
|
| 4228 | - * @throws InvalidArgumentException |
|
| 4229 | - * @throws ReflectionException |
|
| 4230 | - * @throws InvalidDataTypeException |
|
| 4231 | - * @throws InvalidInterfaceException |
|
| 4232 | - */ |
|
| 4233 | - protected function _process_resend_registration() |
|
| 4234 | - { |
|
| 4235 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4236 | - do_action( |
|
| 4237 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4238 | - $this->_template_args['success'], |
|
| 4239 | - $this->request->requestParams() |
|
| 4240 | - ); |
|
| 4241 | - return $this->_template_args['success']; |
|
| 4242 | - } |
|
| 4243 | - |
|
| 4244 | - |
|
| 4245 | - /** |
|
| 4246 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4247 | - * |
|
| 4248 | - * @param EE_Payment $payment |
|
| 4249 | - * @return bool success/fail |
|
| 4250 | - */ |
|
| 4251 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 4252 | - { |
|
| 4253 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4254 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4255 | - $this->_template_args['success'] = apply_filters( |
|
| 4256 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4257 | - false, |
|
| 4258 | - $payment |
|
| 4259 | - ); |
|
| 4260 | - return $this->_template_args['success']; |
|
| 4261 | - } |
|
| 3468 | + // add nonce |
|
| 3469 | + $nonce = |
|
| 3470 | + wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3471 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3472 | + // add REQUIRED form action |
|
| 3473 | + $hidden_fields = [ |
|
| 3474 | + 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3475 | + ]; |
|
| 3476 | + // merge arrays |
|
| 3477 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3478 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3479 | + : $hidden_fields; |
|
| 3480 | + // generate form fields |
|
| 3481 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3482 | + // add fields to form |
|
| 3483 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3484 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3485 | + } |
|
| 3486 | + // close form |
|
| 3487 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3488 | + } |
|
| 3489 | + |
|
| 3490 | + |
|
| 3491 | + /** |
|
| 3492 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3493 | + * discovered it would be useful for external code to have access. |
|
| 3494 | + * |
|
| 3495 | + * @param bool $success |
|
| 3496 | + * @param string $what |
|
| 3497 | + * @param string $action_desc |
|
| 3498 | + * @param array $query_args |
|
| 3499 | + * @param bool $override_overwrite |
|
| 3500 | + * @throws EE_Error |
|
| 3501 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3502 | + * @since 4.5.0 |
|
| 3503 | + */ |
|
| 3504 | + public function redirect_after_action( |
|
| 3505 | + $success = false, |
|
| 3506 | + $what = 'item', |
|
| 3507 | + $action_desc = 'processed', |
|
| 3508 | + $query_args = [], |
|
| 3509 | + $override_overwrite = false |
|
| 3510 | + ) { |
|
| 3511 | + $this->_redirect_after_action( |
|
| 3512 | + $success, |
|
| 3513 | + $what, |
|
| 3514 | + $action_desc, |
|
| 3515 | + $query_args, |
|
| 3516 | + $override_overwrite |
|
| 3517 | + ); |
|
| 3518 | + } |
|
| 3519 | + |
|
| 3520 | + |
|
| 3521 | + /** |
|
| 3522 | + * Helper method for merging existing request data with the returned redirect url. |
|
| 3523 | + * |
|
| 3524 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3525 | + * filters are still applied. |
|
| 3526 | + * |
|
| 3527 | + * @param array $new_route_data |
|
| 3528 | + * @return array |
|
| 3529 | + */ |
|
| 3530 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3531 | + { |
|
| 3532 | + foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3533 | + // unset nonces |
|
| 3534 | + if (strpos($ref, 'nonce') !== false) { |
|
| 3535 | + $this->request->unSetRequestParam($ref); |
|
| 3536 | + continue; |
|
| 3537 | + } |
|
| 3538 | + // urlencode values. |
|
| 3539 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3540 | + $this->request->setRequestParam($ref, $value); |
|
| 3541 | + } |
|
| 3542 | + return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3543 | + } |
|
| 3544 | + |
|
| 3545 | + |
|
| 3546 | + /** |
|
| 3547 | + * _redirect_after_action |
|
| 3548 | + * |
|
| 3549 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3550 | + * @param string $what - what the action was performed on |
|
| 3551 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3552 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3553 | + * action is completed |
|
| 3554 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3555 | + * override this so that they show. |
|
| 3556 | + * @return void |
|
| 3557 | + * @throws EE_Error |
|
| 3558 | + * @throws InvalidArgumentException |
|
| 3559 | + * @throws InvalidDataTypeException |
|
| 3560 | + * @throws InvalidInterfaceException |
|
| 3561 | + */ |
|
| 3562 | + protected function _redirect_after_action( |
|
| 3563 | + $success = 0, |
|
| 3564 | + $what = 'item', |
|
| 3565 | + $action_desc = 'processed', |
|
| 3566 | + $query_args = [], |
|
| 3567 | + $override_overwrite = false |
|
| 3568 | + ) { |
|
| 3569 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3570 | + // class name for actions/filters. |
|
| 3571 | + $classname = get_class($this); |
|
| 3572 | + // set redirect url. |
|
| 3573 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3574 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3575 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3576 | + $notices = EE_Error::get_notices(false); |
|
| 3577 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3578 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3579 | + EE_Error::overwrite_success(); |
|
| 3580 | + } |
|
| 3581 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3582 | + // how many records affected ? more than one record ? or just one ? |
|
| 3583 | + if ($success > 1) { |
|
| 3584 | + // set plural msg |
|
| 3585 | + EE_Error::add_success( |
|
| 3586 | + sprintf( |
|
| 3587 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3588 | + $what, |
|
| 3589 | + $action_desc |
|
| 3590 | + ), |
|
| 3591 | + __FILE__, |
|
| 3592 | + __FUNCTION__, |
|
| 3593 | + __LINE__ |
|
| 3594 | + ); |
|
| 3595 | + } elseif ($success === 1) { |
|
| 3596 | + // set singular msg |
|
| 3597 | + EE_Error::add_success( |
|
| 3598 | + sprintf( |
|
| 3599 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3600 | + $what, |
|
| 3601 | + $action_desc |
|
| 3602 | + ), |
|
| 3603 | + __FILE__, |
|
| 3604 | + __FUNCTION__, |
|
| 3605 | + __LINE__ |
|
| 3606 | + ); |
|
| 3607 | + } |
|
| 3608 | + } |
|
| 3609 | + // check that $query_args isn't something crazy |
|
| 3610 | + if (! is_array($query_args)) { |
|
| 3611 | + $query_args = []; |
|
| 3612 | + } |
|
| 3613 | + /** |
|
| 3614 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3615 | + * redirections on save and close actions |
|
| 3616 | + * |
|
| 3617 | + * @param array $query_args The original query_args array coming into the |
|
| 3618 | + * method. |
|
| 3619 | + * @since 4.2.0 |
|
| 3620 | + */ |
|
| 3621 | + do_action( |
|
| 3622 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3623 | + $query_args |
|
| 3624 | + ); |
|
| 3625 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3626 | + |
|
| 3627 | + if ( |
|
| 3628 | + $this->request->requestParamIsSet('save_and_close') |
|
| 3629 | + && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3630 | + ) { |
|
| 3631 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3632 | + $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3633 | + // regenerate query args array from referrer URL |
|
| 3634 | + parse_str($parsed_url['query'], $query_args); |
|
| 3635 | + // correct page and action will be in the query args now |
|
| 3636 | + $redirect_url = admin_url('admin.php'); |
|
| 3637 | + } |
|
| 3638 | + // merge any default query_args set in _default_route_query_args property |
|
| 3639 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3640 | + $args_to_merge = []; |
|
| 3641 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3642 | + // is there a wp_referer array in our _default_route_query_args property? |
|
| 3643 | + if ($query_param === 'wp_referer') { |
|
| 3644 | + $query_value = (array) $query_value; |
|
| 3645 | + foreach ($query_value as $reference => $value) { |
|
| 3646 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3647 | + continue; |
|
| 3648 | + } |
|
| 3649 | + // finally we will override any arguments in the referer with |
|
| 3650 | + // what might be set on the _default_route_query_args array. |
|
| 3651 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3652 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3653 | + } else { |
|
| 3654 | + $args_to_merge[ $reference ] = urlencode($value); |
|
| 3655 | + } |
|
| 3656 | + } |
|
| 3657 | + continue; |
|
| 3658 | + } |
|
| 3659 | + $args_to_merge[ $query_param ] = $query_value; |
|
| 3660 | + } |
|
| 3661 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3662 | + // redirect. |
|
| 3663 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3664 | + } |
|
| 3665 | + $this->_process_notices($query_args); |
|
| 3666 | + // generate redirect url |
|
| 3667 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3668 | + if (isset($query_args['action'])) { |
|
| 3669 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3670 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3671 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3672 | + } |
|
| 3673 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3674 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3675 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3676 | + $redirect_url = apply_filters( |
|
| 3677 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3678 | + EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3679 | + $query_args |
|
| 3680 | + ); |
|
| 3681 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3682 | + if ($this->request->isAjax()) { |
|
| 3683 | + $default_data = [ |
|
| 3684 | + 'close' => true, |
|
| 3685 | + 'redirect_url' => $redirect_url, |
|
| 3686 | + 'where' => 'main', |
|
| 3687 | + 'what' => 'append', |
|
| 3688 | + ]; |
|
| 3689 | + $this->_template_args['success'] = $success; |
|
| 3690 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3691 | + $default_data, |
|
| 3692 | + $this->_template_args['data'] |
|
| 3693 | + ) : $default_data; |
|
| 3694 | + $this->_return_json(); |
|
| 3695 | + } |
|
| 3696 | + wp_safe_redirect($redirect_url); |
|
| 3697 | + exit(); |
|
| 3698 | + } |
|
| 3699 | + |
|
| 3700 | + |
|
| 3701 | + /** |
|
| 3702 | + * process any notices before redirecting (or returning ajax request) |
|
| 3703 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3704 | + * |
|
| 3705 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3706 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3707 | + * page_routes haven't been defined yet. |
|
| 3708 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3709 | + * still save a transient for the notice. |
|
| 3710 | + * @return void |
|
| 3711 | + * @throws EE_Error |
|
| 3712 | + * @throws InvalidArgumentException |
|
| 3713 | + * @throws InvalidDataTypeException |
|
| 3714 | + * @throws InvalidInterfaceException |
|
| 3715 | + */ |
|
| 3716 | + protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3717 | + { |
|
| 3718 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3719 | + if ($this->request->isAjax()) { |
|
| 3720 | + $notices = EE_Error::get_notices(false); |
|
| 3721 | + if (empty($this->_template_args['success'])) { |
|
| 3722 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3723 | + } |
|
| 3724 | + if (empty($this->_template_args['errors'])) { |
|
| 3725 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3726 | + } |
|
| 3727 | + if (empty($this->_template_args['attention'])) { |
|
| 3728 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3729 | + } |
|
| 3730 | + } |
|
| 3731 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3732 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3733 | + if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3734 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3735 | + $this->_add_transient( |
|
| 3736 | + $route, |
|
| 3737 | + $this->_template_args['notices'], |
|
| 3738 | + true, |
|
| 3739 | + $skip_route_verify |
|
| 3740 | + ); |
|
| 3741 | + } |
|
| 3742 | + } |
|
| 3743 | + |
|
| 3744 | + |
|
| 3745 | + /** |
|
| 3746 | + * get_action_link_or_button |
|
| 3747 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3748 | + * |
|
| 3749 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3750 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3751 | + * property. |
|
| 3752 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3753 | + * @param string $class Use this to give the class for the button. Defaults to 'button--primary' |
|
| 3754 | + * @param string $base_url If this is not provided |
|
| 3755 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3756 | + * Otherwise this value will be used. |
|
| 3757 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3758 | + * @return string |
|
| 3759 | + * @throws InvalidArgumentException |
|
| 3760 | + * @throws InvalidInterfaceException |
|
| 3761 | + * @throws InvalidDataTypeException |
|
| 3762 | + * @throws EE_Error |
|
| 3763 | + */ |
|
| 3764 | + public function get_action_link_or_button( |
|
| 3765 | + $action, |
|
| 3766 | + $type = 'add', |
|
| 3767 | + $extra_request = [], |
|
| 3768 | + $class = 'button--primary', |
|
| 3769 | + $base_url = '', |
|
| 3770 | + $exclude_nonce = false |
|
| 3771 | + ) { |
|
| 3772 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3773 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3774 | + throw new EE_Error( |
|
| 3775 | + sprintf( |
|
| 3776 | + esc_html__( |
|
| 3777 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3778 | + 'event_espresso' |
|
| 3779 | + ), |
|
| 3780 | + $action |
|
| 3781 | + ) |
|
| 3782 | + ); |
|
| 3783 | + } |
|
| 3784 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3785 | + throw new EE_Error( |
|
| 3786 | + sprintf( |
|
| 3787 | + esc_html__( |
|
| 3788 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3789 | + 'event_espresso' |
|
| 3790 | + ), |
|
| 3791 | + $type |
|
| 3792 | + ) |
|
| 3793 | + ); |
|
| 3794 | + } |
|
| 3795 | + // finally check user access for this button. |
|
| 3796 | + $has_access = $this->check_user_access($action, true); |
|
| 3797 | + if (! $has_access) { |
|
| 3798 | + return ''; |
|
| 3799 | + } |
|
| 3800 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3801 | + $query_args = [ |
|
| 3802 | + 'action' => $action, |
|
| 3803 | + ]; |
|
| 3804 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3805 | + if (! empty($extra_request)) { |
|
| 3806 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3807 | + } |
|
| 3808 | + $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3809 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3810 | + } |
|
| 3811 | + |
|
| 3812 | + |
|
| 3813 | + /** |
|
| 3814 | + * _per_page_screen_option |
|
| 3815 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3816 | + * |
|
| 3817 | + * @return void |
|
| 3818 | + * @throws InvalidArgumentException |
|
| 3819 | + * @throws InvalidInterfaceException |
|
| 3820 | + * @throws InvalidDataTypeException |
|
| 3821 | + */ |
|
| 3822 | + protected function _per_page_screen_option() |
|
| 3823 | + { |
|
| 3824 | + $option = 'per_page'; |
|
| 3825 | + $args = [ |
|
| 3826 | + 'label' => apply_filters( |
|
| 3827 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3828 | + $this->_admin_page_title, |
|
| 3829 | + $this |
|
| 3830 | + ), |
|
| 3831 | + 'default' => (int) apply_filters( |
|
| 3832 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3833 | + 20 |
|
| 3834 | + ), |
|
| 3835 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3836 | + ]; |
|
| 3837 | + // ONLY add the screen option if the user has access to it. |
|
| 3838 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3839 | + add_screen_option($option, $args); |
|
| 3840 | + } |
|
| 3841 | + } |
|
| 3842 | + |
|
| 3843 | + |
|
| 3844 | + /** |
|
| 3845 | + * set_per_page_screen_option |
|
| 3846 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3847 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3848 | + * admin_menu. |
|
| 3849 | + * |
|
| 3850 | + * @return void |
|
| 3851 | + */ |
|
| 3852 | + private function _set_per_page_screen_options() |
|
| 3853 | + { |
|
| 3854 | + if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3855 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3856 | + if (! $user = wp_get_current_user()) { |
|
| 3857 | + return; |
|
| 3858 | + } |
|
| 3859 | + $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3860 | + if (! $option) { |
|
| 3861 | + return; |
|
| 3862 | + } |
|
| 3863 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3864 | + $map_option = $option; |
|
| 3865 | + $option = str_replace('-', '_', $option); |
|
| 3866 | + switch ($map_option) { |
|
| 3867 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3868 | + $max_value = apply_filters( |
|
| 3869 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3870 | + 999, |
|
| 3871 | + $this->_current_page, |
|
| 3872 | + $this->_current_view |
|
| 3873 | + ); |
|
| 3874 | + if ($value < 1) { |
|
| 3875 | + return; |
|
| 3876 | + } |
|
| 3877 | + $value = min($value, $max_value); |
|
| 3878 | + break; |
|
| 3879 | + default: |
|
| 3880 | + $value = apply_filters( |
|
| 3881 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3882 | + false, |
|
| 3883 | + $option, |
|
| 3884 | + $value |
|
| 3885 | + ); |
|
| 3886 | + if (false === $value) { |
|
| 3887 | + return; |
|
| 3888 | + } |
|
| 3889 | + break; |
|
| 3890 | + } |
|
| 3891 | + update_user_meta($user->ID, $option, $value); |
|
| 3892 | + wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3893 | + exit; |
|
| 3894 | + } |
|
| 3895 | + } |
|
| 3896 | + |
|
| 3897 | + |
|
| 3898 | + /** |
|
| 3899 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3900 | + * |
|
| 3901 | + * @param array $data array that will be assigned to template args. |
|
| 3902 | + */ |
|
| 3903 | + public function set_template_args($data) |
|
| 3904 | + { |
|
| 3905 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3906 | + } |
|
| 3907 | + |
|
| 3908 | + |
|
| 3909 | + /** |
|
| 3910 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3911 | + * |
|
| 3912 | + * @param string $route the route that should receive the transient |
|
| 3913 | + * @param array $data the data that gets sent |
|
| 3914 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3915 | + * normal route transient. |
|
| 3916 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3917 | + * when we are adding a transient before page_routes have been defined. |
|
| 3918 | + * @return void |
|
| 3919 | + * @throws EE_Error |
|
| 3920 | + */ |
|
| 3921 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3922 | + { |
|
| 3923 | + $user_id = get_current_user_id(); |
|
| 3924 | + if (! $skip_route_verify) { |
|
| 3925 | + $this->_verify_route($route); |
|
| 3926 | + } |
|
| 3927 | + // now let's set the string for what kind of transient we're setting |
|
| 3928 | + $transient = $notices |
|
| 3929 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3930 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3931 | + $data = $notices ? ['notices' => $data] : $data; |
|
| 3932 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3933 | + $existing = is_multisite() && is_network_admin() |
|
| 3934 | + ? get_site_transient($transient) |
|
| 3935 | + : get_transient($transient); |
|
| 3936 | + if ($existing) { |
|
| 3937 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3938 | + } |
|
| 3939 | + if (is_multisite() && is_network_admin()) { |
|
| 3940 | + set_site_transient($transient, $data, 8); |
|
| 3941 | + } else { |
|
| 3942 | + set_transient($transient, $data, 8); |
|
| 3943 | + } |
|
| 3944 | + } |
|
| 3945 | + |
|
| 3946 | + |
|
| 3947 | + /** |
|
| 3948 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3949 | + * |
|
| 3950 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3951 | + * @param string $route |
|
| 3952 | + * @return mixed data |
|
| 3953 | + */ |
|
| 3954 | + protected function _get_transient($notices = false, $route = '') |
|
| 3955 | + { |
|
| 3956 | + $user_id = get_current_user_id(); |
|
| 3957 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3958 | + $transient = $notices |
|
| 3959 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3960 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3961 | + $data = is_multisite() && is_network_admin() |
|
| 3962 | + ? get_site_transient($transient) |
|
| 3963 | + : get_transient($transient); |
|
| 3964 | + // delete transient after retrieval (just in case it hasn't expired); |
|
| 3965 | + if (is_multisite() && is_network_admin()) { |
|
| 3966 | + delete_site_transient($transient); |
|
| 3967 | + } else { |
|
| 3968 | + delete_transient($transient); |
|
| 3969 | + } |
|
| 3970 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3971 | + } |
|
| 3972 | + |
|
| 3973 | + |
|
| 3974 | + /** |
|
| 3975 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3976 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3977 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3978 | + * |
|
| 3979 | + * @return void |
|
| 3980 | + */ |
|
| 3981 | + protected function _transient_garbage_collection() |
|
| 3982 | + { |
|
| 3983 | + global $wpdb; |
|
| 3984 | + // retrieve all existing transients |
|
| 3985 | + $query = |
|
| 3986 | + "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3987 | + if ($results = $wpdb->get_results($query)) { |
|
| 3988 | + foreach ($results as $result) { |
|
| 3989 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3990 | + get_transient($transient); |
|
| 3991 | + if (is_multisite() && is_network_admin()) { |
|
| 3992 | + get_site_transient($transient); |
|
| 3993 | + } |
|
| 3994 | + } |
|
| 3995 | + } |
|
| 3996 | + } |
|
| 3997 | + |
|
| 3998 | + |
|
| 3999 | + /** |
|
| 4000 | + * get_view |
|
| 4001 | + * |
|
| 4002 | + * @return string content of _view property |
|
| 4003 | + */ |
|
| 4004 | + public function get_view() |
|
| 4005 | + { |
|
| 4006 | + return $this->_view; |
|
| 4007 | + } |
|
| 4008 | + |
|
| 4009 | + |
|
| 4010 | + /** |
|
| 4011 | + * getter for the protected $_views property |
|
| 4012 | + * |
|
| 4013 | + * @return array |
|
| 4014 | + */ |
|
| 4015 | + public function get_views() |
|
| 4016 | + { |
|
| 4017 | + return $this->_views; |
|
| 4018 | + } |
|
| 4019 | + |
|
| 4020 | + |
|
| 4021 | + /** |
|
| 4022 | + * get_current_page |
|
| 4023 | + * |
|
| 4024 | + * @return string _current_page property value |
|
| 4025 | + */ |
|
| 4026 | + public function get_current_page() |
|
| 4027 | + { |
|
| 4028 | + return $this->_current_page; |
|
| 4029 | + } |
|
| 4030 | + |
|
| 4031 | + |
|
| 4032 | + /** |
|
| 4033 | + * get_current_view |
|
| 4034 | + * |
|
| 4035 | + * @return string _current_view property value |
|
| 4036 | + */ |
|
| 4037 | + public function get_current_view() |
|
| 4038 | + { |
|
| 4039 | + return $this->_current_view; |
|
| 4040 | + } |
|
| 4041 | + |
|
| 4042 | + |
|
| 4043 | + /** |
|
| 4044 | + * get_current_screen |
|
| 4045 | + * |
|
| 4046 | + * @return object The current WP_Screen object |
|
| 4047 | + */ |
|
| 4048 | + public function get_current_screen() |
|
| 4049 | + { |
|
| 4050 | + return $this->_current_screen; |
|
| 4051 | + } |
|
| 4052 | + |
|
| 4053 | + |
|
| 4054 | + /** |
|
| 4055 | + * get_current_page_view_url |
|
| 4056 | + * |
|
| 4057 | + * @return string This returns the url for the current_page_view. |
|
| 4058 | + */ |
|
| 4059 | + public function get_current_page_view_url() |
|
| 4060 | + { |
|
| 4061 | + return $this->_current_page_view_url; |
|
| 4062 | + } |
|
| 4063 | + |
|
| 4064 | + |
|
| 4065 | + /** |
|
| 4066 | + * just returns the Request |
|
| 4067 | + * |
|
| 4068 | + * @return RequestInterface |
|
| 4069 | + */ |
|
| 4070 | + public function get_request() |
|
| 4071 | + { |
|
| 4072 | + return $this->request; |
|
| 4073 | + } |
|
| 4074 | + |
|
| 4075 | + |
|
| 4076 | + /** |
|
| 4077 | + * just returns the _req_data property |
|
| 4078 | + * |
|
| 4079 | + * @return array |
|
| 4080 | + */ |
|
| 4081 | + public function get_request_data() |
|
| 4082 | + { |
|
| 4083 | + return $this->request->requestParams(); |
|
| 4084 | + } |
|
| 4085 | + |
|
| 4086 | + |
|
| 4087 | + /** |
|
| 4088 | + * returns the _req_data protected property |
|
| 4089 | + * |
|
| 4090 | + * @return string |
|
| 4091 | + */ |
|
| 4092 | + public function get_req_action() |
|
| 4093 | + { |
|
| 4094 | + return $this->_req_action; |
|
| 4095 | + } |
|
| 4096 | + |
|
| 4097 | + |
|
| 4098 | + /** |
|
| 4099 | + * @return bool value of $_is_caf property |
|
| 4100 | + */ |
|
| 4101 | + public function is_caf() |
|
| 4102 | + { |
|
| 4103 | + return $this->_is_caf; |
|
| 4104 | + } |
|
| 4105 | + |
|
| 4106 | + |
|
| 4107 | + /** |
|
| 4108 | + * @return mixed |
|
| 4109 | + */ |
|
| 4110 | + public function default_espresso_metaboxes() |
|
| 4111 | + { |
|
| 4112 | + return $this->_default_espresso_metaboxes; |
|
| 4113 | + } |
|
| 4114 | + |
|
| 4115 | + |
|
| 4116 | + /** |
|
| 4117 | + * @return mixed |
|
| 4118 | + */ |
|
| 4119 | + public function admin_base_url() |
|
| 4120 | + { |
|
| 4121 | + return $this->_admin_base_url; |
|
| 4122 | + } |
|
| 4123 | + |
|
| 4124 | + |
|
| 4125 | + /** |
|
| 4126 | + * @return mixed |
|
| 4127 | + */ |
|
| 4128 | + public function wp_page_slug() |
|
| 4129 | + { |
|
| 4130 | + return $this->_wp_page_slug; |
|
| 4131 | + } |
|
| 4132 | + |
|
| 4133 | + |
|
| 4134 | + /** |
|
| 4135 | + * updates espresso configuration settings |
|
| 4136 | + * |
|
| 4137 | + * @param string $tab |
|
| 4138 | + * @param EE_Config_Base|EE_Config $config |
|
| 4139 | + * @param string $file file where error occurred |
|
| 4140 | + * @param string $func function where error occurred |
|
| 4141 | + * @param string $line line no where error occurred |
|
| 4142 | + * @return boolean |
|
| 4143 | + */ |
|
| 4144 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4145 | + { |
|
| 4146 | + // remove any options that are NOT going to be saved with the config settings. |
|
| 4147 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 4148 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4149 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4150 | + update_option('ee_ueip_has_notified', true); |
|
| 4151 | + } |
|
| 4152 | + // and save it (note we're also doing the network save here) |
|
| 4153 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4154 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4155 | + if ($config_saved && $net_saved) { |
|
| 4156 | + EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4157 | + return true; |
|
| 4158 | + } |
|
| 4159 | + EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4160 | + return false; |
|
| 4161 | + } |
|
| 4162 | + |
|
| 4163 | + |
|
| 4164 | + /** |
|
| 4165 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4166 | + * |
|
| 4167 | + * @return array |
|
| 4168 | + */ |
|
| 4169 | + public function get_yes_no_values() |
|
| 4170 | + { |
|
| 4171 | + return $this->_yes_no_values; |
|
| 4172 | + } |
|
| 4173 | + |
|
| 4174 | + |
|
| 4175 | + /** |
|
| 4176 | + * @return string |
|
| 4177 | + * @throws ReflectionException |
|
| 4178 | + * @since $VID:$ |
|
| 4179 | + */ |
|
| 4180 | + protected function _get_dir() |
|
| 4181 | + { |
|
| 4182 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 4183 | + return dirname($reflector->getFileName()); |
|
| 4184 | + } |
|
| 4185 | + |
|
| 4186 | + |
|
| 4187 | + /** |
|
| 4188 | + * A helper for getting a "next link". |
|
| 4189 | + * |
|
| 4190 | + * @param string $url The url to link to |
|
| 4191 | + * @param string $class The class to use. |
|
| 4192 | + * @return string |
|
| 4193 | + */ |
|
| 4194 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4195 | + { |
|
| 4196 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4197 | + } |
|
| 4198 | + |
|
| 4199 | + |
|
| 4200 | + /** |
|
| 4201 | + * A helper for getting a "previous link". |
|
| 4202 | + * |
|
| 4203 | + * @param string $url The url to link to |
|
| 4204 | + * @param string $class The class to use. |
|
| 4205 | + * @return string |
|
| 4206 | + */ |
|
| 4207 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4208 | + { |
|
| 4209 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4210 | + } |
|
| 4211 | + |
|
| 4212 | + |
|
| 4213 | + |
|
| 4214 | + |
|
| 4215 | + |
|
| 4216 | + |
|
| 4217 | + |
|
| 4218 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4219 | + |
|
| 4220 | + |
|
| 4221 | + /** |
|
| 4222 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4223 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4224 | + * _req_data array. |
|
| 4225 | + * |
|
| 4226 | + * @return bool success/fail |
|
| 4227 | + * @throws EE_Error |
|
| 4228 | + * @throws InvalidArgumentException |
|
| 4229 | + * @throws ReflectionException |
|
| 4230 | + * @throws InvalidDataTypeException |
|
| 4231 | + * @throws InvalidInterfaceException |
|
| 4232 | + */ |
|
| 4233 | + protected function _process_resend_registration() |
|
| 4234 | + { |
|
| 4235 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4236 | + do_action( |
|
| 4237 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4238 | + $this->_template_args['success'], |
|
| 4239 | + $this->request->requestParams() |
|
| 4240 | + ); |
|
| 4241 | + return $this->_template_args['success']; |
|
| 4242 | + } |
|
| 4243 | + |
|
| 4244 | + |
|
| 4245 | + /** |
|
| 4246 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4247 | + * |
|
| 4248 | + * @param EE_Payment $payment |
|
| 4249 | + * @return bool success/fail |
|
| 4250 | + */ |
|
| 4251 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 4252 | + { |
|
| 4253 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4254 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4255 | + $this->_template_args['success'] = apply_filters( |
|
| 4256 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4257 | + false, |
|
| 4258 | + $payment |
|
| 4259 | + ); |
|
| 4260 | + return $this->_template_args['success']; |
|
| 4261 | + } |
|
| 4262 | 4262 | } |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | $ee_menu_slugs = (array) $ee_menu_slugs; |
| 624 | 624 | if ( |
| 625 | 625 | ! $this->request->isAjax() |
| 626 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 626 | + && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) |
|
| 627 | 627 | ) { |
| 628 | 628 | return; |
| 629 | 629 | } |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | : $req_action; |
| 644 | 644 | |
| 645 | 645 | $this->_current_view = $this->_req_action; |
| 646 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 646 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 647 | 647 | $this->_define_page_props(); |
| 648 | 648 | $this->_current_page_view_url = add_query_arg( |
| 649 | 649 | ['page' => $this->_current_page, 'action' => $this->_current_view], |
@@ -680,21 +680,21 @@ discard block |
||
| 680 | 680 | } |
| 681 | 681 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
| 682 | 682 | $this->_page_routes = apply_filters( |
| 683 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 683 | + 'FHEE__'.get_class($this).'__page_setup__page_routes', |
|
| 684 | 684 | $this->_page_routes, |
| 685 | 685 | $this |
| 686 | 686 | ); |
| 687 | 687 | $this->_page_config = apply_filters( |
| 688 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 688 | + 'FHEE__'.get_class($this).'__page_setup__page_config', |
|
| 689 | 689 | $this->_page_config, |
| 690 | 690 | $this |
| 691 | 691 | ); |
| 692 | 692 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
| 693 | 693 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 694 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 694 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 695 | 695 | add_action( |
| 696 | 696 | 'AHEE__EE_Admin_Page__route_admin_request', |
| 697 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 697 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view], |
|
| 698 | 698 | 10, |
| 699 | 699 | 2 |
| 700 | 700 | ); |
@@ -707,8 +707,8 @@ discard block |
||
| 707 | 707 | if ($this->_is_UI_request) { |
| 708 | 708 | // admin_init stuff - global, all views for this page class, specific view |
| 709 | 709 | add_action('admin_init', [$this, 'admin_init'], 10); |
| 710 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 711 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 710 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 711 | + add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15); |
|
| 712 | 712 | } |
| 713 | 713 | } else { |
| 714 | 714 | // hijack regular WP loading and route admin request immediately |
@@ -727,12 +727,12 @@ discard block |
||
| 727 | 727 | */ |
| 728 | 728 | private function _do_other_page_hooks() |
| 729 | 729 | { |
| 730 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 730 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []); |
|
| 731 | 731 | foreach ($registered_pages as $page) { |
| 732 | 732 | // now let's setup the file name and class that should be present |
| 733 | 733 | $classname = str_replace('.class.php', '', $page); |
| 734 | 734 | // autoloaders should take care of loading file |
| 735 | - if (! class_exists($classname)) { |
|
| 735 | + if ( ! class_exists($classname)) { |
|
| 736 | 736 | $error_msg[] = sprintf( |
| 737 | 737 | esc_html__( |
| 738 | 738 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | ), |
| 750 | 750 | $page, |
| 751 | 751 | '<br />', |
| 752 | - '<strong>' . $classname . '</strong>' |
|
| 752 | + '<strong>'.$classname.'</strong>' |
|
| 753 | 753 | ); |
| 754 | 754 | throw new EE_Error(implode('||', $error_msg)); |
| 755 | 755 | } |
@@ -791,13 +791,13 @@ discard block |
||
| 791 | 791 | // load admin_notices - global, page class, and view specific |
| 792 | 792 | add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
| 793 | 793 | add_action('admin_notices', [$this, 'admin_notices'], 10); |
| 794 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 795 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 794 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 795 | + add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15); |
|
| 796 | 796 | } |
| 797 | 797 | // load network admin_notices - global, page class, and view specific |
| 798 | 798 | add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
| 799 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 800 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 799 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 800 | + add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]); |
|
| 801 | 801 | } |
| 802 | 802 | // this will save any per_page screen options if they are present |
| 803 | 803 | $this->_set_per_page_screen_options(); |
@@ -919,7 +919,7 @@ discard block |
||
| 919 | 919 | protected function _verify_routes() |
| 920 | 920 | { |
| 921 | 921 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 922 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 922 | + if ( ! $this->_current_page && ! $this->request->isAjax()) { |
|
| 923 | 923 | return false; |
| 924 | 924 | } |
| 925 | 925 | $this->_route = false; |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | $this->_admin_page_title |
| 932 | 932 | ); |
| 933 | 933 | // developer error msg |
| 934 | - $error_msg .= '||' . $error_msg |
|
| 934 | + $error_msg .= '||'.$error_msg |
|
| 935 | 935 | . esc_html__( |
| 936 | 936 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
| 937 | 937 | 'event_espresso' |
@@ -940,8 +940,8 @@ discard block |
||
| 940 | 940 | } |
| 941 | 941 | // and that the requested page route exists |
| 942 | 942 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
| 943 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 944 | - $this->_route_config = $this->_page_config[ $this->_req_action ] ?? []; |
|
| 943 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 944 | + $this->_route_config = $this->_page_config[$this->_req_action] ?? []; |
|
| 945 | 945 | } else { |
| 946 | 946 | // user error msg |
| 947 | 947 | $error_msg = sprintf( |
@@ -952,7 +952,7 @@ discard block |
||
| 952 | 952 | $this->_admin_page_title |
| 953 | 953 | ); |
| 954 | 954 | // developer error msg |
| 955 | - $error_msg .= '||' . $error_msg |
|
| 955 | + $error_msg .= '||'.$error_msg |
|
| 956 | 956 | . sprintf( |
| 957 | 957 | esc_html__( |
| 958 | 958 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -963,7 +963,7 @@ discard block |
||
| 963 | 963 | throw new EE_Error($error_msg); |
| 964 | 964 | } |
| 965 | 965 | // and that a default route exists |
| 966 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 966 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 967 | 967 | // user error msg |
| 968 | 968 | $error_msg = sprintf( |
| 969 | 969 | esc_html__( |
@@ -973,7 +973,7 @@ discard block |
||
| 973 | 973 | $this->_admin_page_title |
| 974 | 974 | ); |
| 975 | 975 | // developer error msg |
| 976 | - $error_msg .= '||' . $error_msg |
|
| 976 | + $error_msg .= '||'.$error_msg |
|
| 977 | 977 | . esc_html__( |
| 978 | 978 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
| 979 | 979 | 'event_espresso' |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | $this->_admin_page_title |
| 1016 | 1016 | ); |
| 1017 | 1017 | // developer error msg |
| 1018 | - $error_msg .= '||' . $error_msg |
|
| 1018 | + $error_msg .= '||'.$error_msg |
|
| 1019 | 1019 | . sprintf( |
| 1020 | 1020 | esc_html__( |
| 1021 | 1021 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | protected function _verify_nonce($nonce, $nonce_ref) |
| 1044 | 1044 | { |
| 1045 | 1045 | // verify nonce against expected value |
| 1046 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1046 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1047 | 1047 | // these are not the droids you are looking for !!! |
| 1048 | 1048 | $msg = sprintf( |
| 1049 | 1049 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | __CLASS__ |
| 1061 | 1061 | ); |
| 1062 | 1062 | } |
| 1063 | - if (! $this->request->isAjax()) { |
|
| 1063 | + if ( ! $this->request->isAjax()) { |
|
| 1064 | 1064 | wp_die($msg); |
| 1065 | 1065 | } |
| 1066 | 1066 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | */ |
| 1085 | 1085 | protected function _route_admin_request() |
| 1086 | 1086 | { |
| 1087 | - if (! $this->_is_UI_request) { |
|
| 1087 | + if ( ! $this->_is_UI_request) { |
|
| 1088 | 1088 | $this->_verify_routes(); |
| 1089 | 1089 | } |
| 1090 | 1090 | $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
@@ -1104,7 +1104,7 @@ discard block |
||
| 1104 | 1104 | $error_msg = ''; |
| 1105 | 1105 | // action right before calling route |
| 1106 | 1106 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
| 1107 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1107 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1108 | 1108 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
| 1109 | 1109 | } |
| 1110 | 1110 | // right before calling the route, let's clean the _wp_http_referer |
@@ -1115,7 +1115,7 @@ discard block |
||
| 1115 | 1115 | wp_unslash($this->request->getServerParam('REQUEST_URI')) |
| 1116 | 1116 | ) |
| 1117 | 1117 | ); |
| 1118 | - if (! empty($func)) { |
|
| 1118 | + if ( ! empty($func)) { |
|
| 1119 | 1119 | if (is_array($func)) { |
| 1120 | 1120 | [$class, $method] = $func; |
| 1121 | 1121 | } elseif (strpos($func, '::') !== false) { |
@@ -1124,7 +1124,7 @@ discard block |
||
| 1124 | 1124 | $class = $this; |
| 1125 | 1125 | $method = $func; |
| 1126 | 1126 | } |
| 1127 | - if (! (is_object($class) && $class === $this)) { |
|
| 1127 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 1128 | 1128 | // send along this admin page object for access by addons. |
| 1129 | 1129 | $args['admin_page_object'] = $this; |
| 1130 | 1130 | } |
@@ -1165,7 +1165,7 @@ discard block |
||
| 1165 | 1165 | $method |
| 1166 | 1166 | ); |
| 1167 | 1167 | } |
| 1168 | - if (! empty($error_msg)) { |
|
| 1168 | + if ( ! empty($error_msg)) { |
|
| 1169 | 1169 | throw new EE_Error($error_msg); |
| 1170 | 1170 | } |
| 1171 | 1171 | } |
@@ -1250,7 +1250,7 @@ discard block |
||
| 1250 | 1250 | if (strpos($key, 'nonce') !== false) { |
| 1251 | 1251 | continue; |
| 1252 | 1252 | } |
| 1253 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1253 | + $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1254 | 1254 | } |
| 1255 | 1255 | } |
| 1256 | 1256 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1291,8 +1291,8 @@ discard block |
||
| 1291 | 1291 | protected function _add_help_tabs() |
| 1292 | 1292 | { |
| 1293 | 1293 | $tour_buttons = ''; |
| 1294 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1295 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1294 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1295 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1296 | 1296 | // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
| 1297 | 1297 | // is there a help tour for the current route? if there is let's setup the tour buttons |
| 1298 | 1298 | // if (isset($this->_help_tour[ $this->_req_action ])) { |
@@ -1315,7 +1315,7 @@ discard block |
||
| 1315 | 1315 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
| 1316 | 1316 | if (is_array($config) && isset($config['help_sidebar'])) { |
| 1317 | 1317 | // check that the callback given is valid |
| 1318 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1318 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1319 | 1319 | throw new EE_Error( |
| 1320 | 1320 | sprintf( |
| 1321 | 1321 | esc_html__( |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | ); |
| 1329 | 1329 | } |
| 1330 | 1330 | $content = apply_filters( |
| 1331 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1331 | + 'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', |
|
| 1332 | 1332 | $this->{$config['help_sidebar']}() |
| 1333 | 1333 | ); |
| 1334 | 1334 | $content .= $tour_buttons; // add help tour buttons. |
@@ -1336,30 +1336,30 @@ discard block |
||
| 1336 | 1336 | $this->_current_screen->set_help_sidebar($content); |
| 1337 | 1337 | } |
| 1338 | 1338 | // if there ARE tour buttons... |
| 1339 | - if (! empty($tour_buttons)) { |
|
| 1339 | + if ( ! empty($tour_buttons)) { |
|
| 1340 | 1340 | // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar. |
| 1341 | - if (! isset($config['help_sidebar'])) { |
|
| 1341 | + if ( ! isset($config['help_sidebar'])) { |
|
| 1342 | 1342 | $this->_current_screen->set_help_sidebar($tour_buttons); |
| 1343 | 1343 | } |
| 1344 | 1344 | // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
| 1345 | - if (! isset($config['help_tabs'])) { |
|
| 1345 | + if ( ! isset($config['help_tabs'])) { |
|
| 1346 | 1346 | $_ht['id'] = $this->page_slug; |
| 1347 | 1347 | $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
| 1348 | 1348 | $_ht['content'] = '<p>' |
| 1349 | 1349 | . esc_html__( |
| 1350 | 1350 | 'The buttons to the right allow you to start/restart any help tours available for this page', |
| 1351 | 1351 | 'event_espresso' |
| 1352 | - ) . '</p>'; |
|
| 1352 | + ).'</p>'; |
|
| 1353 | 1353 | $this->_current_screen->add_help_tab($_ht); |
| 1354 | 1354 | } |
| 1355 | 1355 | } |
| 1356 | - if (! isset($config['help_tabs'])) { |
|
| 1356 | + if ( ! isset($config['help_tabs'])) { |
|
| 1357 | 1357 | return; |
| 1358 | 1358 | } //no help tabs for this route |
| 1359 | 1359 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
| 1360 | 1360 | // we're here so there ARE help tabs! |
| 1361 | 1361 | // make sure we've got what we need |
| 1362 | - if (! isset($cfg['title'])) { |
|
| 1362 | + if ( ! isset($cfg['title'])) { |
|
| 1363 | 1363 | throw new EE_Error( |
| 1364 | 1364 | esc_html__( |
| 1365 | 1365 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1367,7 +1367,7 @@ discard block |
||
| 1367 | 1367 | ) |
| 1368 | 1368 | ); |
| 1369 | 1369 | } |
| 1370 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1370 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1371 | 1371 | throw new EE_Error( |
| 1372 | 1372 | esc_html__( |
| 1373 | 1373 | 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
@@ -1376,11 +1376,11 @@ discard block |
||
| 1376 | 1376 | ); |
| 1377 | 1377 | } |
| 1378 | 1378 | // first priority goes to content. |
| 1379 | - if (! empty($cfg['content'])) { |
|
| 1379 | + if ( ! empty($cfg['content'])) { |
|
| 1380 | 1380 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1381 | 1381 | // second priority goes to filename |
| 1382 | - } elseif (! empty($cfg['filename'])) { |
|
| 1383 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1382 | + } elseif ( ! empty($cfg['filename'])) { |
|
| 1383 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1384 | 1384 | // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
| 1385 | 1385 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
| 1386 | 1386 | . basename($this->_get_dir()) |
@@ -1388,7 +1388,7 @@ discard block |
||
| 1388 | 1388 | . $cfg['filename'] |
| 1389 | 1389 | . '.help_tab.php' : $file_path; |
| 1390 | 1390 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1391 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1391 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1392 | 1392 | EE_Error::add_error( |
| 1393 | 1393 | sprintf( |
| 1394 | 1394 | esc_html__( |
@@ -1436,7 +1436,7 @@ discard block |
||
| 1436 | 1436 | return; |
| 1437 | 1437 | } |
| 1438 | 1438 | // setup config array for help tab method |
| 1439 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1439 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1440 | 1440 | $_ht = [ |
| 1441 | 1441 | 'id' => $id, |
| 1442 | 1442 | 'title' => $cfg['title'], |
@@ -1566,8 +1566,8 @@ discard block |
||
| 1566 | 1566 | $qtips = (array) $this->_route_config['qtips']; |
| 1567 | 1567 | // load qtip loader |
| 1568 | 1568 | $path = [ |
| 1569 | - $this->_get_dir() . '/qtips/', |
|
| 1570 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1569 | + $this->_get_dir().'/qtips/', |
|
| 1570 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1571 | 1571 | ]; |
| 1572 | 1572 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1573 | 1573 | } |
@@ -1589,7 +1589,7 @@ discard block |
||
| 1589 | 1589 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1590 | 1590 | $i = 0; |
| 1591 | 1591 | foreach ($this->_page_config as $slug => $config) { |
| 1592 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1592 | + if ( ! is_array($config) || empty($config['nav'])) { |
|
| 1593 | 1593 | continue; |
| 1594 | 1594 | } |
| 1595 | 1595 | // no nav tab for this config |
@@ -1598,12 +1598,12 @@ discard block |
||
| 1598 | 1598 | // nav tab is only to appear when route requested. |
| 1599 | 1599 | continue; |
| 1600 | 1600 | } |
| 1601 | - if (! $this->check_user_access($slug, true)) { |
|
| 1601 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1602 | 1602 | // no nav tab because current user does not have access. |
| 1603 | 1603 | continue; |
| 1604 | 1604 | } |
| 1605 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1606 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1605 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1606 | + $this->_nav_tabs[$slug] = [ |
|
| 1607 | 1607 | 'url' => isset($config['nav']['url']) |
| 1608 | 1608 | ? $config['nav']['url'] |
| 1609 | 1609 | : EE_Admin_Page::add_query_args_and_nonce( |
@@ -1615,14 +1615,14 @@ discard block |
||
| 1615 | 1615 | : ucwords( |
| 1616 | 1616 | str_replace('_', ' ', $slug) |
| 1617 | 1617 | ), |
| 1618 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1618 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1619 | 1619 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1620 | 1620 | ]; |
| 1621 | 1621 | $i++; |
| 1622 | 1622 | } |
| 1623 | 1623 | // if $this->_nav_tabs is empty then lets set the default |
| 1624 | 1624 | if (empty($this->_nav_tabs)) { |
| 1625 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1625 | + $this->_nav_tabs[$this->_default_nav_tab_name] = [ |
|
| 1626 | 1626 | 'url' => $this->_admin_base_url, |
| 1627 | 1627 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
| 1628 | 1628 | 'css_class' => 'nav-tab-active', |
@@ -1647,10 +1647,10 @@ discard block |
||
| 1647 | 1647 | foreach ($this->_route_config['labels'] as $label => $text) { |
| 1648 | 1648 | if (is_array($text)) { |
| 1649 | 1649 | foreach ($text as $sublabel => $subtext) { |
| 1650 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1650 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1651 | 1651 | } |
| 1652 | 1652 | } else { |
| 1653 | - $this->_labels[ $label ] = $text; |
|
| 1653 | + $this->_labels[$label] = $text; |
|
| 1654 | 1654 | } |
| 1655 | 1655 | } |
| 1656 | 1656 | } |
@@ -1672,12 +1672,12 @@ discard block |
||
| 1672 | 1672 | { |
| 1673 | 1673 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1674 | 1674 | $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
| 1675 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1675 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1676 | 1676 | && is_array( |
| 1677 | - $this->_page_routes[ $route_to_check ] |
|
| 1677 | + $this->_page_routes[$route_to_check] |
|
| 1678 | 1678 | ) |
| 1679 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1680 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1679 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1680 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1681 | 1681 | if (empty($capability) && empty($route_to_check)) { |
| 1682 | 1682 | $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
| 1683 | 1683 | : $this->_route['capability']; |
@@ -1723,7 +1723,7 @@ discard block |
||
| 1723 | 1723 | add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args); |
| 1724 | 1724 | add_filter( |
| 1725 | 1725 | "postbox_classes_{$this->_wp_page_slug}_{$box_id}", |
| 1726 | - function ($classes) { |
|
| 1726 | + function($classes) { |
|
| 1727 | 1727 | array_push($classes, 'ee-admin-container'); |
| 1728 | 1728 | return $classes; |
| 1729 | 1729 | } |
@@ -1822,7 +1822,7 @@ discard block |
||
| 1822 | 1822 | // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
| 1823 | 1823 | // } |
| 1824 | 1824 | // current set timezone for timezone js |
| 1825 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1825 | + echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>'; |
|
| 1826 | 1826 | } |
| 1827 | 1827 | |
| 1828 | 1828 | |
@@ -1856,7 +1856,7 @@ discard block |
||
| 1856 | 1856 | // loop through the array and setup content |
| 1857 | 1857 | foreach ($help_array as $trigger => $help) { |
| 1858 | 1858 | // make sure the array is setup properly |
| 1859 | - if (! isset($help['title'], $help['content'])) { |
|
| 1859 | + if ( ! isset($help['title'], $help['content'])) { |
|
| 1860 | 1860 | throw new EE_Error( |
| 1861 | 1861 | esc_html__( |
| 1862 | 1862 | 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
@@ -1870,8 +1870,8 @@ discard block |
||
| 1870 | 1870 | 'help_popup_title' => $help['title'], |
| 1871 | 1871 | 'help_popup_content' => $help['content'], |
| 1872 | 1872 | ]; |
| 1873 | - $content .= EEH_Template::display_template( |
|
| 1874 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1873 | + $content .= EEH_Template::display_template( |
|
| 1874 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
| 1875 | 1875 | $template_args, |
| 1876 | 1876 | true |
| 1877 | 1877 | ); |
@@ -1893,15 +1893,15 @@ discard block |
||
| 1893 | 1893 | private function _get_help_content() |
| 1894 | 1894 | { |
| 1895 | 1895 | // what is the method we're looking for? |
| 1896 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1896 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1897 | 1897 | // if method doesn't exist let's get out. |
| 1898 | - if (! method_exists($this, $method_name)) { |
|
| 1898 | + if ( ! method_exists($this, $method_name)) { |
|
| 1899 | 1899 | return []; |
| 1900 | 1900 | } |
| 1901 | 1901 | // k we're good to go let's retrieve the help array |
| 1902 | 1902 | $help_array = $this->{$method_name}(); |
| 1903 | 1903 | // make sure we've got an array! |
| 1904 | - if (! is_array($help_array)) { |
|
| 1904 | + if ( ! is_array($help_array)) { |
|
| 1905 | 1905 | throw new EE_Error( |
| 1906 | 1906 | esc_html__( |
| 1907 | 1907 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1933,8 +1933,8 @@ discard block |
||
| 1933 | 1933 | // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
| 1934 | 1934 | $help_array = $this->_get_help_content(); |
| 1935 | 1935 | $help_content = ''; |
| 1936 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1937 | - $help_array[ $trigger_id ] = [ |
|
| 1936 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1937 | + $help_array[$trigger_id] = [ |
|
| 1938 | 1938 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
| 1939 | 1939 | 'content' => esc_html__( |
| 1940 | 1940 | 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
@@ -2053,7 +2053,7 @@ discard block |
||
| 2053 | 2053 | |
| 2054 | 2054 | add_filter( |
| 2055 | 2055 | 'admin_body_class', |
| 2056 | - function ($classes) { |
|
| 2056 | + function($classes) { |
|
| 2057 | 2057 | if (strpos($classes, 'espresso-admin') === false) { |
| 2058 | 2058 | $classes .= ' espresso-admin'; |
| 2059 | 2059 | } |
@@ -2144,12 +2144,12 @@ discard block |
||
| 2144 | 2144 | protected function _set_list_table() |
| 2145 | 2145 | { |
| 2146 | 2146 | // first is this a list_table view? |
| 2147 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2147 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 2148 | 2148 | return; |
| 2149 | 2149 | } //not a list_table view so get out. |
| 2150 | 2150 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
| 2151 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2152 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2151 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
| 2152 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2153 | 2153 | // user error msg |
| 2154 | 2154 | $error_msg = esc_html__( |
| 2155 | 2155 | 'An error occurred. The requested list table views could not be found.', |
@@ -2169,10 +2169,10 @@ discard block |
||
| 2169 | 2169 | } |
| 2170 | 2170 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 2171 | 2171 | $this->_views = apply_filters( |
| 2172 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2172 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
| 2173 | 2173 | $this->_views |
| 2174 | 2174 | ); |
| 2175 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2175 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 2176 | 2176 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 2177 | 2177 | $this->_set_list_table_view(); |
| 2178 | 2178 | $this->_set_list_table_object(); |
@@ -2207,7 +2207,7 @@ discard block |
||
| 2207 | 2207 | protected function _set_list_table_object() |
| 2208 | 2208 | { |
| 2209 | 2209 | if (isset($this->_route_config['list_table'])) { |
| 2210 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2210 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 2211 | 2211 | throw new EE_Error( |
| 2212 | 2212 | sprintf( |
| 2213 | 2213 | esc_html__( |
@@ -2245,17 +2245,17 @@ discard block |
||
| 2245 | 2245 | foreach ($this->_views as $key => $view) { |
| 2246 | 2246 | $query_args = []; |
| 2247 | 2247 | // check for current view |
| 2248 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2248 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2249 | 2249 | $query_args['action'] = $this->_req_action; |
| 2250 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2250 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2251 | 2251 | $query_args['status'] = $view['slug']; |
| 2252 | 2252 | // merge any other arguments sent in. |
| 2253 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2254 | - foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) { |
|
| 2253 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2254 | + foreach ($extra_query_args[$view['slug']] as $extra_query_arg) { |
|
| 2255 | 2255 | $query_args[] = $extra_query_arg; |
| 2256 | 2256 | } |
| 2257 | 2257 | } |
| 2258 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2258 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2259 | 2259 | } |
| 2260 | 2260 | return $this->_views; |
| 2261 | 2261 | } |
@@ -2286,14 +2286,14 @@ discard block |
||
| 2286 | 2286 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2287 | 2287 | foreach ($values as $value) { |
| 2288 | 2288 | if ($value < $max_entries) { |
| 2289 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2289 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2290 | 2290 | $entries_per_page_dropdown .= ' |
| 2291 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 2291 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 2292 | 2292 | } |
| 2293 | 2293 | } |
| 2294 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2294 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2295 | 2295 | $entries_per_page_dropdown .= ' |
| 2296 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 2296 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 2297 | 2297 | $entries_per_page_dropdown .= ' |
| 2298 | 2298 | </select> |
| 2299 | 2299 | entries |
@@ -2317,7 +2317,7 @@ discard block |
||
| 2317 | 2317 | empty($this->_search_btn_label) ? $this->page_label |
| 2318 | 2318 | : $this->_search_btn_label |
| 2319 | 2319 | ); |
| 2320 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2320 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 2321 | 2321 | } |
| 2322 | 2322 | |
| 2323 | 2323 | |
@@ -2405,7 +2405,7 @@ discard block |
||
| 2405 | 2405 | $total_columns = ! empty($screen_columns) |
| 2406 | 2406 | ? $screen_columns |
| 2407 | 2407 | : $this->_route_config['columns'][1]; |
| 2408 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2408 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 2409 | 2409 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2410 | 2410 | $this->_template_args['screen'] = $this->_current_screen; |
| 2411 | 2411 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2450,7 +2450,7 @@ discard block |
||
| 2450 | 2450 | */ |
| 2451 | 2451 | protected function _espresso_ratings_request() |
| 2452 | 2452 | { |
| 2453 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2453 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2454 | 2454 | return; |
| 2455 | 2455 | } |
| 2456 | 2456 | $ratings_box_title = apply_filters( |
@@ -2477,28 +2477,28 @@ discard block |
||
| 2477 | 2477 | */ |
| 2478 | 2478 | public function espresso_ratings_request() |
| 2479 | 2479 | { |
| 2480 | - EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2480 | + EEH_Template::display_template(EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php'); |
|
| 2481 | 2481 | } |
| 2482 | 2482 | |
| 2483 | 2483 | |
| 2484 | 2484 | public static function cached_rss_display($rss_id, $url) |
| 2485 | 2485 | { |
| 2486 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2486 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2487 | 2487 | . esc_html__('Loading…', 'event_espresso') |
| 2488 | 2488 | . '</p><p class="hide-if-js">' |
| 2489 | 2489 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
| 2490 | 2490 | . '</p>'; |
| 2491 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2492 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2493 | - $post = '</div>' . "\n"; |
|
| 2494 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2491 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 2492 | + $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>'; |
|
| 2493 | + $post = '</div>'."\n"; |
|
| 2494 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 2495 | 2495 | $output = get_transient($cache_key); |
| 2496 | 2496 | if ($output !== false) { |
| 2497 | - echo $pre . $output . $post; // already escaped |
|
| 2497 | + echo $pre.$output.$post; // already escaped |
|
| 2498 | 2498 | return true; |
| 2499 | 2499 | } |
| 2500 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2501 | - echo $pre . $loading . $post; // already escaped |
|
| 2500 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2501 | + echo $pre.$loading.$post; // already escaped |
|
| 2502 | 2502 | return false; |
| 2503 | 2503 | } |
| 2504 | 2504 | ob_start(); |
@@ -2565,19 +2565,19 @@ discard block |
||
| 2565 | 2565 | public function espresso_sponsors_post_box() |
| 2566 | 2566 | { |
| 2567 | 2567 | EEH_Template::display_template( |
| 2568 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2568 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2569 | 2569 | ); |
| 2570 | 2570 | } |
| 2571 | 2571 | |
| 2572 | 2572 | |
| 2573 | 2573 | private function _publish_post_box() |
| 2574 | 2574 | { |
| 2575 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2575 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2576 | 2576 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
| 2577 | 2577 | // then we'll use that for the metabox label. |
| 2578 | 2578 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2579 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2580 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2579 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2580 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2581 | 2581 | : $this->_labels['publishbox']; |
| 2582 | 2582 | } else { |
| 2583 | 2583 | $box_label = esc_html__('Publish', 'event_espresso'); |
@@ -2606,7 +2606,7 @@ discard block |
||
| 2606 | 2606 | ? $this->_template_args['publish_box_extra_content'] |
| 2607 | 2607 | : ''; |
| 2608 | 2608 | echo EEH_Template::display_template( |
| 2609 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2609 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
| 2610 | 2610 | $this->_template_args, |
| 2611 | 2611 | true |
| 2612 | 2612 | ); |
@@ -2696,18 +2696,18 @@ discard block |
||
| 2696 | 2696 | ); |
| 2697 | 2697 | } |
| 2698 | 2698 | $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
| 2699 | - if (! empty($name) && ! empty($id)) { |
|
| 2700 | - $hidden_field_arr[ $name ] = [ |
|
| 2699 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2700 | + $hidden_field_arr[$name] = [ |
|
| 2701 | 2701 | 'type' => 'hidden', |
| 2702 | 2702 | 'value' => $id, |
| 2703 | 2703 | ]; |
| 2704 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2704 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2705 | 2705 | } else { |
| 2706 | 2706 | $hf = ''; |
| 2707 | 2707 | } |
| 2708 | 2708 | // add hidden field |
| 2709 | 2709 | $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
| 2710 | - ? $hf[ $name ]['field'] |
|
| 2710 | + ? $hf[$name]['field'] |
|
| 2711 | 2711 | : $hf; |
| 2712 | 2712 | } |
| 2713 | 2713 | |
@@ -2809,7 +2809,7 @@ discard block |
||
| 2809 | 2809 | } |
| 2810 | 2810 | // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
| 2811 | 2811 | $call_back_func = $create_func |
| 2812 | - ? static function ($post, $metabox) { |
|
| 2812 | + ? static function($post, $metabox) { |
|
| 2813 | 2813 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2814 | 2814 | echo EEH_Template::display_template( |
| 2815 | 2815 | $metabox['args']['template_path'], |
@@ -2819,7 +2819,7 @@ discard block |
||
| 2819 | 2819 | } |
| 2820 | 2820 | : $callback; |
| 2821 | 2821 | $this->addMetaBox( |
| 2822 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2822 | + str_replace('_', '-', $action).'-mbox', |
|
| 2823 | 2823 | $title, |
| 2824 | 2824 | $call_back_func, |
| 2825 | 2825 | $this->_wp_page_slug, |
@@ -2927,9 +2927,9 @@ discard block |
||
| 2927 | 2927 | |
| 2928 | 2928 | $template_path = $sidebar |
| 2929 | 2929 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
| 2930 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2930 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2931 | 2931 | if ($this->request->isAjax()) { |
| 2932 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2932 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2933 | 2933 | } |
| 2934 | 2934 | $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
| 2935 | 2935 | |
@@ -2963,11 +2963,11 @@ discard block |
||
| 2963 | 2963 | public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
| 2964 | 2964 | { |
| 2965 | 2965 | // let's generate a default preview action button if there isn't one already present. |
| 2966 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2966 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2967 | 2967 | 'Upgrade to Event Espresso 4 Right Now', |
| 2968 | 2968 | 'event_espresso' |
| 2969 | 2969 | ); |
| 2970 | - $buy_now_url = add_query_arg( |
|
| 2970 | + $buy_now_url = add_query_arg( |
|
| 2971 | 2971 | [ |
| 2972 | 2972 | 'ee_ver' => 'ee4', |
| 2973 | 2973 | 'utm_source' => 'ee4_plugin_admin', |
@@ -2987,8 +2987,8 @@ discard block |
||
| 2987 | 2987 | true |
| 2988 | 2988 | ) |
| 2989 | 2989 | : $this->_template_args['preview_action_button']; |
| 2990 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2991 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2990 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2991 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
| 2992 | 2992 | $this->_template_args, |
| 2993 | 2993 | true |
| 2994 | 2994 | ); |
@@ -3046,7 +3046,7 @@ discard block |
||
| 3046 | 3046 | // setup search attributes |
| 3047 | 3047 | $this->_set_search_attributes(); |
| 3048 | 3048 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 3049 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3049 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 3050 | 3050 | $this->_template_args['table_url'] = $this->request->isAjax() |
| 3051 | 3051 | ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
| 3052 | 3052 | : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
@@ -3054,10 +3054,10 @@ discard block |
||
| 3054 | 3054 | $this->_template_args['current_route'] = $this->_req_action; |
| 3055 | 3055 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
| 3056 | 3056 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 3057 | - if (! empty($ajax_sorting_callback)) { |
|
| 3057 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 3058 | 3058 | $sortable_list_table_form_fields = wp_nonce_field( |
| 3059 | - $ajax_sorting_callback . '_nonce', |
|
| 3060 | - $ajax_sorting_callback . '_nonce', |
|
| 3059 | + $ajax_sorting_callback.'_nonce', |
|
| 3060 | + $ajax_sorting_callback.'_nonce', |
|
| 3061 | 3061 | false, |
| 3062 | 3062 | false |
| 3063 | 3063 | ); |
@@ -3075,20 +3075,20 @@ discard block |
||
| 3075 | 3075 | isset($this->_template_args['list_table_hidden_fields']) |
| 3076 | 3076 | ? $this->_template_args['list_table_hidden_fields'] |
| 3077 | 3077 | : ''; |
| 3078 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3079 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3078 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 3079 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3080 | 3080 | . $nonce_ref |
| 3081 | 3081 | . '" value="' |
| 3082 | 3082 | . wp_create_nonce($nonce_ref) |
| 3083 | 3083 | . '">'; |
| 3084 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3084 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3085 | 3085 | // display message about search results? |
| 3086 | 3086 | $search = $this->request->getRequestParam('s'); |
| 3087 | 3087 | $this->_template_args['before_list_table'] .= ! empty($search) |
| 3088 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3088 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 3089 | 3089 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 3090 | 3090 | trim($search, '%') |
| 3091 | - ) . '</p>' |
|
| 3091 | + ).'</p>' |
|
| 3092 | 3092 | : ''; |
| 3093 | 3093 | // filter before_list_table template arg |
| 3094 | 3094 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -3122,7 +3122,7 @@ discard block |
||
| 3122 | 3122 | // convert to array and filter again |
| 3123 | 3123 | // arrays are easier to inject new items in a specific location, |
| 3124 | 3124 | // but would not be backwards compatible, so we have to add a new filter |
| 3125 | - $this->_template_args['after_list_table'] = implode( |
|
| 3125 | + $this->_template_args['after_list_table'] = implode( |
|
| 3126 | 3126 | " \n", |
| 3127 | 3127 | (array) apply_filters( |
| 3128 | 3128 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
@@ -3170,15 +3170,15 @@ discard block |
||
| 3170 | 3170 | ); |
| 3171 | 3171 | /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
| 3172 | 3172 | $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
| 3173 | - if (! $status_change_notice->isDismissed()) { |
|
| 3173 | + if ( ! $status_change_notice->isDismissed()) { |
|
| 3174 | 3174 | $this->_template_args['status_change_notice'] = EEH_Template::display_template( |
| 3175 | - EE_ADMIN_TEMPLATE . 'status_change_notice.template.php', |
|
| 3176 | - [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ], |
|
| 3175 | + EE_ADMIN_TEMPLATE.'status_change_notice.template.php', |
|
| 3176 | + ['context' => '__admin-legend', 'page_slug' => $this->page_slug], |
|
| 3177 | 3177 | true |
| 3178 | 3178 | ); |
| 3179 | 3179 | } |
| 3180 | 3180 | return EEH_Template::display_template( |
| 3181 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3181 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
| 3182 | 3182 | $this->_template_args, |
| 3183 | 3183 | true |
| 3184 | 3184 | ); |
@@ -3294,17 +3294,17 @@ discard block |
||
| 3294 | 3294 | ? $this->_template_args['before_admin_page_content'] |
| 3295 | 3295 | : '' |
| 3296 | 3296 | ); |
| 3297 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3297 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3298 | 3298 | "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
| 3299 | 3299 | isset($this->_template_args['after_admin_page_content']) |
| 3300 | 3300 | ? $this->_template_args['after_admin_page_content'] |
| 3301 | 3301 | : '' |
| 3302 | 3302 | ); |
| 3303 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3303 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3304 | 3304 | // load settings page wrapper template |
| 3305 | 3305 | $template_path = ! $this->request->isAjax() |
| 3306 | 3306 | ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
| 3307 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 3307 | + : EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php'; |
|
| 3308 | 3308 | // about page? |
| 3309 | 3309 | $template_path = $about |
| 3310 | 3310 | ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
@@ -3397,7 +3397,7 @@ discard block |
||
| 3397 | 3397 | : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
| 3398 | 3398 | . $referrer |
| 3399 | 3399 | . '" />'; |
| 3400 | - $button_text = ! empty($text) |
|
| 3400 | + $button_text = ! empty($text) |
|
| 3401 | 3401 | ? $text |
| 3402 | 3402 | : [ |
| 3403 | 3403 | esc_html__('Save', 'event_espresso'), |
@@ -3407,17 +3407,17 @@ discard block |
||
| 3407 | 3407 | // add in a hidden index for the current page (so save and close redirects properly) |
| 3408 | 3408 | $this->_template_args['save_buttons'] = $referrer_url; |
| 3409 | 3409 | foreach ($button_text as $key => $button) { |
| 3410 | - $ref = $default_names[ $key ]; |
|
| 3410 | + $ref = $default_names[$key]; |
|
| 3411 | 3411 | $this->_template_args['save_buttons'] .= '<input type="submit" class="button--primary ' |
| 3412 | 3412 | . $ref |
| 3413 | 3413 | . '" value="' |
| 3414 | 3414 | . $button |
| 3415 | 3415 | . '" name="' |
| 3416 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3416 | + . ( ! empty($actions) ? $actions[$key] : $ref) |
|
| 3417 | 3417 | . '" id="' |
| 3418 | - . $this->_current_view . '_' . $ref |
|
| 3418 | + . $this->_current_view.'_'.$ref |
|
| 3419 | 3419 | . '" />'; |
| 3420 | - if (! $both) { |
|
| 3420 | + if ( ! $both) { |
|
| 3421 | 3421 | break; |
| 3422 | 3422 | } |
| 3423 | 3423 | } |
@@ -3452,13 +3452,13 @@ discard block |
||
| 3452 | 3452 | 'An error occurred. No action was set for this page\'s form.', |
| 3453 | 3453 | 'event_espresso' |
| 3454 | 3454 | ); |
| 3455 | - $dev_msg = $user_msg . "\n" |
|
| 3455 | + $dev_msg = $user_msg."\n" |
|
| 3456 | 3456 | . sprintf( |
| 3457 | 3457 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
| 3458 | 3458 | __FUNCTION__, |
| 3459 | 3459 | __CLASS__ |
| 3460 | 3460 | ); |
| 3461 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3461 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3462 | 3462 | } |
| 3463 | 3463 | // open form |
| 3464 | 3464 | $action = $this->_admin_base_url; |
@@ -3466,9 +3466,9 @@ discard block |
||
| 3466 | 3466 | <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' > |
| 3467 | 3467 | "; |
| 3468 | 3468 | // add nonce |
| 3469 | - $nonce = |
|
| 3470 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3471 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3469 | + $nonce = |
|
| 3470 | + wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 3471 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 3472 | 3472 | // add REQUIRED form action |
| 3473 | 3473 | $hidden_fields = [ |
| 3474 | 3474 | 'action' => ['type' => 'hidden', 'value' => $route], |
@@ -3481,7 +3481,7 @@ discard block |
||
| 3481 | 3481 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 3482 | 3482 | // add fields to form |
| 3483 | 3483 | foreach ((array) $form_fields as $field_name => $form_field) { |
| 3484 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3484 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 3485 | 3485 | } |
| 3486 | 3486 | // close form |
| 3487 | 3487 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3575,10 +3575,10 @@ discard block |
||
| 3575 | 3575 | $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
| 3576 | 3576 | $notices = EE_Error::get_notices(false); |
| 3577 | 3577 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
| 3578 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3578 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3579 | 3579 | EE_Error::overwrite_success(); |
| 3580 | 3580 | } |
| 3581 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3581 | + if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3582 | 3582 | // how many records affected ? more than one record ? or just one ? |
| 3583 | 3583 | if ($success > 1) { |
| 3584 | 3584 | // set plural msg |
@@ -3607,7 +3607,7 @@ discard block |
||
| 3607 | 3607 | } |
| 3608 | 3608 | } |
| 3609 | 3609 | // check that $query_args isn't something crazy |
| 3610 | - if (! is_array($query_args)) { |
|
| 3610 | + if ( ! is_array($query_args)) { |
|
| 3611 | 3611 | $query_args = []; |
| 3612 | 3612 | } |
| 3613 | 3613 | /** |
@@ -3636,7 +3636,7 @@ discard block |
||
| 3636 | 3636 | $redirect_url = admin_url('admin.php'); |
| 3637 | 3637 | } |
| 3638 | 3638 | // merge any default query_args set in _default_route_query_args property |
| 3639 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3639 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3640 | 3640 | $args_to_merge = []; |
| 3641 | 3641 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 3642 | 3642 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3648,15 +3648,15 @@ discard block |
||
| 3648 | 3648 | } |
| 3649 | 3649 | // finally we will override any arguments in the referer with |
| 3650 | 3650 | // what might be set on the _default_route_query_args array. |
| 3651 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3652 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3651 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3652 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3653 | 3653 | } else { |
| 3654 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3654 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3655 | 3655 | } |
| 3656 | 3656 | } |
| 3657 | 3657 | continue; |
| 3658 | 3658 | } |
| 3659 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3659 | + $args_to_merge[$query_param] = $query_value; |
|
| 3660 | 3660 | } |
| 3661 | 3661 | // now let's merge these arguments but override with what was specifically sent in to the |
| 3662 | 3662 | // redirect. |
@@ -3668,19 +3668,19 @@ discard block |
||
| 3668 | 3668 | if (isset($query_args['action'])) { |
| 3669 | 3669 | // manually generate wp_nonce and merge that with the query vars |
| 3670 | 3670 | // becuz the wp_nonce_url function wrecks havoc on some vars |
| 3671 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3671 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 3672 | 3672 | } |
| 3673 | 3673 | // we're adding some hooks and filters in here for processing any things just before redirects |
| 3674 | 3674 | // (example: an admin page has done an insert or update and we want to run something after that). |
| 3675 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3675 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 3676 | 3676 | $redirect_url = apply_filters( |
| 3677 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3677 | + 'FHEE_redirect_'.$classname.$this->_req_action, |
|
| 3678 | 3678 | EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
| 3679 | 3679 | $query_args |
| 3680 | 3680 | ); |
| 3681 | 3681 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
| 3682 | 3682 | if ($this->request->isAjax()) { |
| 3683 | - $default_data = [ |
|
| 3683 | + $default_data = [ |
|
| 3684 | 3684 | 'close' => true, |
| 3685 | 3685 | 'redirect_url' => $redirect_url, |
| 3686 | 3686 | 'where' => 'main', |
@@ -3730,7 +3730,7 @@ discard block |
||
| 3730 | 3730 | } |
| 3731 | 3731 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 3732 | 3732 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
| 3733 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3733 | + if ( ! $this->request->isAjax() || $sticky_notices) { |
|
| 3734 | 3734 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
| 3735 | 3735 | $this->_add_transient( |
| 3736 | 3736 | $route, |
@@ -3770,7 +3770,7 @@ discard block |
||
| 3770 | 3770 | $exclude_nonce = false |
| 3771 | 3771 | ) { |
| 3772 | 3772 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
| 3773 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3773 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3774 | 3774 | throw new EE_Error( |
| 3775 | 3775 | sprintf( |
| 3776 | 3776 | esc_html__( |
@@ -3781,7 +3781,7 @@ discard block |
||
| 3781 | 3781 | ) |
| 3782 | 3782 | ); |
| 3783 | 3783 | } |
| 3784 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3784 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 3785 | 3785 | throw new EE_Error( |
| 3786 | 3786 | sprintf( |
| 3787 | 3787 | esc_html__( |
@@ -3794,7 +3794,7 @@ discard block |
||
| 3794 | 3794 | } |
| 3795 | 3795 | // finally check user access for this button. |
| 3796 | 3796 | $has_access = $this->check_user_access($action, true); |
| 3797 | - if (! $has_access) { |
|
| 3797 | + if ( ! $has_access) { |
|
| 3798 | 3798 | return ''; |
| 3799 | 3799 | } |
| 3800 | 3800 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3802,11 +3802,11 @@ discard block |
||
| 3802 | 3802 | 'action' => $action, |
| 3803 | 3803 | ]; |
| 3804 | 3804 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
| 3805 | - if (! empty($extra_request)) { |
|
| 3805 | + if ( ! empty($extra_request)) { |
|
| 3806 | 3806 | $query_args = array_merge($extra_request, $query_args); |
| 3807 | 3807 | } |
| 3808 | 3808 | $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
| 3809 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3809 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3810 | 3810 | } |
| 3811 | 3811 | |
| 3812 | 3812 | |
@@ -3832,7 +3832,7 @@ discard block |
||
| 3832 | 3832 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
| 3833 | 3833 | 20 |
| 3834 | 3834 | ), |
| 3835 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3835 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3836 | 3836 | ]; |
| 3837 | 3837 | // ONLY add the screen option if the user has access to it. |
| 3838 | 3838 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3853,18 +3853,18 @@ discard block |
||
| 3853 | 3853 | { |
| 3854 | 3854 | if ($this->request->requestParamIsSet('wp_screen_options')) { |
| 3855 | 3855 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
| 3856 | - if (! $user = wp_get_current_user()) { |
|
| 3856 | + if ( ! $user = wp_get_current_user()) { |
|
| 3857 | 3857 | return; |
| 3858 | 3858 | } |
| 3859 | 3859 | $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
| 3860 | - if (! $option) { |
|
| 3860 | + if ( ! $option) { |
|
| 3861 | 3861 | return; |
| 3862 | 3862 | } |
| 3863 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3863 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3864 | 3864 | $map_option = $option; |
| 3865 | 3865 | $option = str_replace('-', '_', $option); |
| 3866 | 3866 | switch ($map_option) { |
| 3867 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3867 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3868 | 3868 | $max_value = apply_filters( |
| 3869 | 3869 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
| 3870 | 3870 | 999, |
@@ -3921,13 +3921,13 @@ discard block |
||
| 3921 | 3921 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
| 3922 | 3922 | { |
| 3923 | 3923 | $user_id = get_current_user_id(); |
| 3924 | - if (! $skip_route_verify) { |
|
| 3924 | + if ( ! $skip_route_verify) { |
|
| 3925 | 3925 | $this->_verify_route($route); |
| 3926 | 3926 | } |
| 3927 | 3927 | // now let's set the string for what kind of transient we're setting |
| 3928 | 3928 | $transient = $notices |
| 3929 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3930 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3929 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3930 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3931 | 3931 | $data = $notices ? ['notices' => $data] : $data; |
| 3932 | 3932 | // is there already a transient for this route? If there is then let's ADD to that transient |
| 3933 | 3933 | $existing = is_multisite() && is_network_admin() |
@@ -3956,8 +3956,8 @@ discard block |
||
| 3956 | 3956 | $user_id = get_current_user_id(); |
| 3957 | 3957 | $route = ! $route ? $this->_req_action : $route; |
| 3958 | 3958 | $transient = $notices |
| 3959 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3960 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3959 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3960 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3961 | 3961 | $data = is_multisite() && is_network_admin() |
| 3962 | 3962 | ? get_site_transient($transient) |
| 3963 | 3963 | : get_transient($transient); |
@@ -4193,7 +4193,7 @@ discard block |
||
| 4193 | 4193 | */ |
| 4194 | 4194 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 4195 | 4195 | { |
| 4196 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4196 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4197 | 4197 | } |
| 4198 | 4198 | |
| 4199 | 4199 | |
@@ -4206,7 +4206,7 @@ discard block |
||
| 4206 | 4206 | */ |
| 4207 | 4207 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 4208 | 4208 | { |
| 4209 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4209 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4210 | 4210 | } |
| 4211 | 4211 | |
| 4212 | 4212 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (! class_exists('WP_List_Table')) { |
| 4 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 4 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -20,904 +20,904 @@ discard block |
||
| 20 | 20 | abstract class EE_Admin_List_Table extends WP_List_Table |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * holds the data that will be processed for the table |
|
| 25 | - * |
|
| 26 | - * @var array $_data |
|
| 27 | - */ |
|
| 28 | - protected $_data; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * This holds the value of all the data available for the given view (for all pages). |
|
| 33 | - * |
|
| 34 | - * @var int $_all_data_count |
|
| 35 | - */ |
|
| 36 | - protected $_all_data_count; |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Will contain the count of trashed items for the view label. |
|
| 41 | - * |
|
| 42 | - * @var int $_trashed_count |
|
| 43 | - */ |
|
| 44 | - protected $_trashed_count; |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * This is what will be referenced as the slug for the current screen |
|
| 49 | - * |
|
| 50 | - * @var string $_screen |
|
| 51 | - */ |
|
| 52 | - protected $_screen; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * this is the EE_Admin_Page object |
|
| 57 | - * |
|
| 58 | - * @var EE_Admin_Page $_admin_page |
|
| 59 | - */ |
|
| 60 | - protected $_admin_page; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * The current view |
|
| 65 | - * |
|
| 66 | - * @var string $_view |
|
| 67 | - */ |
|
| 68 | - protected $_view; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * array of possible views for this table |
|
| 73 | - * |
|
| 74 | - * @var array $_views |
|
| 75 | - */ |
|
| 76 | - protected $_views; |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * An array of key => value pairs containing information about the current table |
|
| 81 | - * array( |
|
| 82 | - * 'plural' => 'plural label', |
|
| 83 | - * 'singular' => 'singular label', |
|
| 84 | - * 'ajax' => false, //whether to use ajax or not |
|
| 85 | - * 'screen' => null, //string used to reference what screen this is |
|
| 86 | - * (WP_List_table converts to screen object) |
|
| 87 | - * ) |
|
| 88 | - * |
|
| 89 | - * @var array $_wp_list_args |
|
| 90 | - */ |
|
| 91 | - protected $_wp_list_args; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * an array of column names |
|
| 95 | - * array( |
|
| 96 | - * 'internal-name' => 'Title' |
|
| 97 | - * ) |
|
| 98 | - * |
|
| 99 | - * @var array $_columns |
|
| 100 | - */ |
|
| 101 | - protected $_columns; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * An array of sortable columns |
|
| 105 | - * array( |
|
| 106 | - * 'internal-name' => 'orderby' //or |
|
| 107 | - * 'internal-name' => array( 'orderby', true ) |
|
| 108 | - * ) |
|
| 109 | - * |
|
| 110 | - * @var array $_sortable_columns |
|
| 111 | - */ |
|
| 112 | - protected $_sortable_columns; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * callback method used to perform AJAX row reordering |
|
| 116 | - * |
|
| 117 | - * @var string $_ajax_sorting_callback |
|
| 118 | - */ |
|
| 119 | - protected $_ajax_sorting_callback; |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * An array of hidden columns (if needed) |
|
| 123 | - * array('internal-name', 'internal-name') |
|
| 124 | - * |
|
| 125 | - * @var array $_hidden_columns |
|
| 126 | - */ |
|
| 127 | - protected $_hidden_columns; |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * holds the per_page value |
|
| 131 | - * |
|
| 132 | - * @var int $_per_page |
|
| 133 | - */ |
|
| 134 | - protected $_per_page; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * holds what page number is currently being viewed |
|
| 138 | - * |
|
| 139 | - * @var int $_current_page |
|
| 140 | - */ |
|
| 141 | - protected $_current_page; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * the reference string for the nonce_action |
|
| 145 | - * |
|
| 146 | - * @var string $_nonce_action_ref |
|
| 147 | - */ |
|
| 148 | - protected $_nonce_action_ref; |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * property to hold incoming request data (as set by the admin_page_core) |
|
| 152 | - * |
|
| 153 | - * @var array $_req_data |
|
| 154 | - */ |
|
| 155 | - protected $_req_data; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * yes / no array for admin form fields |
|
| 160 | - * |
|
| 161 | - * @var array $_yes_no |
|
| 162 | - */ |
|
| 163 | - protected $_yes_no = []; |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Array describing buttons that should appear at the bottom of the page |
|
| 167 | - * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 168 | - * and the values are another array with the following keys |
|
| 169 | - * array( |
|
| 170 | - * 'route' => 'page_route', |
|
| 171 | - * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 172 | - * ) |
|
| 173 | - * |
|
| 174 | - * @var array $_bottom_buttons |
|
| 175 | - */ |
|
| 176 | - protected $_bottom_buttons = []; |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Used to indicate what should be the primary column for the list table. |
|
| 181 | - * If not present then falls back to what WP calculates |
|
| 182 | - * as the primary column. |
|
| 183 | - * |
|
| 184 | - * @type string $_primary_column |
|
| 185 | - */ |
|
| 186 | - protected $_primary_column = ''; |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Used to indicate whether the table has a checkbox column or not. |
|
| 191 | - * |
|
| 192 | - * @type bool $_has_checkbox_column |
|
| 193 | - */ |
|
| 194 | - protected $_has_checkbox_column = false; |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 199 | - */ |
|
| 200 | - public function __construct(EE_Admin_Page $admin_page) |
|
| 201 | - { |
|
| 202 | - $this->_admin_page = $admin_page; |
|
| 203 | - $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 204 | - $this->_view = $this->_admin_page->get_view(); |
|
| 205 | - $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
| 206 | - $this->_current_page = $this->get_pagenum(); |
|
| 207 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 208 | - $this->_yes_no = [ |
|
| 209 | - esc_html__('No', 'event_espresso'), |
|
| 210 | - esc_html__('Yes', 'event_espresso') |
|
| 211 | - ]; |
|
| 212 | - |
|
| 213 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 214 | - |
|
| 215 | - $this->_setup_data(); |
|
| 216 | - $this->_add_view_counts(); |
|
| 217 | - |
|
| 218 | - $this->_nonce_action_ref = $this->_view; |
|
| 219 | - |
|
| 220 | - $this->_set_properties(); |
|
| 221 | - |
|
| 222 | - // set primary column |
|
| 223 | - add_filter('list_table_primary_column', [$this, 'set_primary_column']); |
|
| 224 | - |
|
| 225 | - // set parent defaults |
|
| 226 | - parent::__construct($this->_wp_list_args); |
|
| 227 | - |
|
| 228 | - $this->prepare_items(); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * _setup_data |
|
| 234 | - * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 235 | - * |
|
| 236 | - * @return void |
|
| 237 | - * @uses $this->_admin_page |
|
| 238 | - */ |
|
| 239 | - abstract protected function _setup_data(); |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 244 | - * properties set: |
|
| 245 | - * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 246 | - * _columns = set the columns in an array. |
|
| 247 | - * _sortable_columns = columns that are sortable (array). |
|
| 248 | - * _hidden_columns = columns that are hidden (array) |
|
| 249 | - * _default_orderby = the default orderby for sorting. |
|
| 250 | - * |
|
| 251 | - * @abstract |
|
| 252 | - * @access protected |
|
| 253 | - * @return void |
|
| 254 | - */ |
|
| 255 | - abstract protected function _set_properties(); |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * _get_table_filters |
|
| 260 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 261 | - * gets shown in the table. |
|
| 262 | - * |
|
| 263 | - * @abstract |
|
| 264 | - * @access protected |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - abstract protected function _get_table_filters(); |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 272 | - * counts of the views is accurate. |
|
| 273 | - * |
|
| 274 | - * @abstract |
|
| 275 | - * @access protected |
|
| 276 | - * @return void |
|
| 277 | - */ |
|
| 278 | - abstract protected function _add_view_counts(); |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * _get_hidden_fields |
|
| 283 | - * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 284 | - * |
|
| 285 | - * @return string |
|
| 286 | - */ |
|
| 287 | - protected function _get_hidden_fields() |
|
| 288 | - { |
|
| 289 | - $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 290 | - $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 291 | - // if action is STILL empty, then we set it to default |
|
| 292 | - $action = empty($action) ? 'default' : $action; |
|
| 293 | - $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 294 | - $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 295 | - $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 296 | - |
|
| 297 | - $bulk_actions = $this->_get_bulk_actions(); |
|
| 298 | - foreach ($bulk_actions as $bulk_action => $label) { |
|
| 299 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 300 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - return $field; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * _set_column_info |
|
| 309 | - * we're using this to set the column headers property. |
|
| 310 | - * |
|
| 311 | - * @access protected |
|
| 312 | - * @return void |
|
| 313 | - */ |
|
| 314 | - protected function _set_column_info() |
|
| 315 | - { |
|
| 316 | - $columns = $this->get_columns(); |
|
| 317 | - $hidden = $this->get_hidden_columns(); |
|
| 318 | - $_sortable = $this->get_sortable_columns(); |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 322 | - * Note that $this->screen->id is in the format |
|
| 323 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 324 | - * table it is: event-espresso_page_espresso_messages. |
|
| 325 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 326 | - * hook prefix ("event-espresso") will be different. |
|
| 327 | - * |
|
| 328 | - * @var array |
|
| 329 | - */ |
|
| 330 | - $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
| 331 | - |
|
| 332 | - $sortable = []; |
|
| 333 | - foreach ($_sortable as $id => $data) { |
|
| 334 | - if (empty($data)) { |
|
| 335 | - continue; |
|
| 336 | - } |
|
| 337 | - // fix for offset errors with WP_List_Table default get_columninfo() |
|
| 338 | - if (is_array($data)) { |
|
| 339 | - $_data[0] = key($data); |
|
| 340 | - $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 341 | - } else { |
|
| 342 | - $_data[0] = $data; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - $data = (array) $data; |
|
| 346 | - |
|
| 347 | - if (! isset($data[1])) { |
|
| 348 | - $_data[1] = false; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - $sortable[ $id ] = $_data; |
|
| 352 | - } |
|
| 353 | - $primary = $this->get_primary_column_name(); |
|
| 354 | - $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 360 | - * |
|
| 361 | - * @return string |
|
| 362 | - */ |
|
| 363 | - protected function get_primary_column_name() |
|
| 364 | - { |
|
| 365 | - foreach (class_parents($this) as $parent) { |
|
| 366 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 367 | - return parent::get_primary_column_name(); |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - return $this->_primary_column; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 376 | - * |
|
| 377 | - * @param EE_Base_Class $item |
|
| 378 | - * @param string $column_name |
|
| 379 | - * @param string $primary |
|
| 380 | - * @return string |
|
| 381 | - */ |
|
| 382 | - protected function handle_row_actions($item, $column_name, $primary) |
|
| 383 | - { |
|
| 384 | - foreach (class_parents($this) as $parent) { |
|
| 385 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 386 | - return parent::handle_row_actions($item, $column_name, $primary); |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - return ''; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * _get_bulk_actions |
|
| 395 | - * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 396 | - * |
|
| 397 | - * @access protected |
|
| 398 | - * @return array bulk_actions |
|
| 399 | - */ |
|
| 400 | - protected function _get_bulk_actions() |
|
| 401 | - { |
|
| 402 | - $actions = []; |
|
| 403 | - // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
| 404 | - // formatted array for the wp_list_table(); |
|
| 405 | - foreach ($this->_views as $view => $args) { |
|
| 406 | - if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 407 | - // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
| 408 | - // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 409 | - foreach ($args['bulk_action'] as $route => $label) { |
|
| 410 | - if ($this->_admin_page->check_user_access($route, true)) { |
|
| 411 | - $actions[ $route ] = $label; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - return $actions; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * Generate the table navigation above or below the table. |
|
| 422 | - * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
| 423 | - * |
|
| 424 | - * @throws EE_Error |
|
| 425 | - * @since 4.9.44.rc.001 |
|
| 426 | - */ |
|
| 427 | - public function display_tablenav($which) |
|
| 428 | - { |
|
| 429 | - if ('top' === $which) { |
|
| 430 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 431 | - } |
|
| 432 | - ?> |
|
| 23 | + /** |
|
| 24 | + * holds the data that will be processed for the table |
|
| 25 | + * |
|
| 26 | + * @var array $_data |
|
| 27 | + */ |
|
| 28 | + protected $_data; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * This holds the value of all the data available for the given view (for all pages). |
|
| 33 | + * |
|
| 34 | + * @var int $_all_data_count |
|
| 35 | + */ |
|
| 36 | + protected $_all_data_count; |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Will contain the count of trashed items for the view label. |
|
| 41 | + * |
|
| 42 | + * @var int $_trashed_count |
|
| 43 | + */ |
|
| 44 | + protected $_trashed_count; |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * This is what will be referenced as the slug for the current screen |
|
| 49 | + * |
|
| 50 | + * @var string $_screen |
|
| 51 | + */ |
|
| 52 | + protected $_screen; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * this is the EE_Admin_Page object |
|
| 57 | + * |
|
| 58 | + * @var EE_Admin_Page $_admin_page |
|
| 59 | + */ |
|
| 60 | + protected $_admin_page; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * The current view |
|
| 65 | + * |
|
| 66 | + * @var string $_view |
|
| 67 | + */ |
|
| 68 | + protected $_view; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * array of possible views for this table |
|
| 73 | + * |
|
| 74 | + * @var array $_views |
|
| 75 | + */ |
|
| 76 | + protected $_views; |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * An array of key => value pairs containing information about the current table |
|
| 81 | + * array( |
|
| 82 | + * 'plural' => 'plural label', |
|
| 83 | + * 'singular' => 'singular label', |
|
| 84 | + * 'ajax' => false, //whether to use ajax or not |
|
| 85 | + * 'screen' => null, //string used to reference what screen this is |
|
| 86 | + * (WP_List_table converts to screen object) |
|
| 87 | + * ) |
|
| 88 | + * |
|
| 89 | + * @var array $_wp_list_args |
|
| 90 | + */ |
|
| 91 | + protected $_wp_list_args; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * an array of column names |
|
| 95 | + * array( |
|
| 96 | + * 'internal-name' => 'Title' |
|
| 97 | + * ) |
|
| 98 | + * |
|
| 99 | + * @var array $_columns |
|
| 100 | + */ |
|
| 101 | + protected $_columns; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * An array of sortable columns |
|
| 105 | + * array( |
|
| 106 | + * 'internal-name' => 'orderby' //or |
|
| 107 | + * 'internal-name' => array( 'orderby', true ) |
|
| 108 | + * ) |
|
| 109 | + * |
|
| 110 | + * @var array $_sortable_columns |
|
| 111 | + */ |
|
| 112 | + protected $_sortable_columns; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * callback method used to perform AJAX row reordering |
|
| 116 | + * |
|
| 117 | + * @var string $_ajax_sorting_callback |
|
| 118 | + */ |
|
| 119 | + protected $_ajax_sorting_callback; |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * An array of hidden columns (if needed) |
|
| 123 | + * array('internal-name', 'internal-name') |
|
| 124 | + * |
|
| 125 | + * @var array $_hidden_columns |
|
| 126 | + */ |
|
| 127 | + protected $_hidden_columns; |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * holds the per_page value |
|
| 131 | + * |
|
| 132 | + * @var int $_per_page |
|
| 133 | + */ |
|
| 134 | + protected $_per_page; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * holds what page number is currently being viewed |
|
| 138 | + * |
|
| 139 | + * @var int $_current_page |
|
| 140 | + */ |
|
| 141 | + protected $_current_page; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * the reference string for the nonce_action |
|
| 145 | + * |
|
| 146 | + * @var string $_nonce_action_ref |
|
| 147 | + */ |
|
| 148 | + protected $_nonce_action_ref; |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * property to hold incoming request data (as set by the admin_page_core) |
|
| 152 | + * |
|
| 153 | + * @var array $_req_data |
|
| 154 | + */ |
|
| 155 | + protected $_req_data; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * yes / no array for admin form fields |
|
| 160 | + * |
|
| 161 | + * @var array $_yes_no |
|
| 162 | + */ |
|
| 163 | + protected $_yes_no = []; |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Array describing buttons that should appear at the bottom of the page |
|
| 167 | + * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 168 | + * and the values are another array with the following keys |
|
| 169 | + * array( |
|
| 170 | + * 'route' => 'page_route', |
|
| 171 | + * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 172 | + * ) |
|
| 173 | + * |
|
| 174 | + * @var array $_bottom_buttons |
|
| 175 | + */ |
|
| 176 | + protected $_bottom_buttons = []; |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Used to indicate what should be the primary column for the list table. |
|
| 181 | + * If not present then falls back to what WP calculates |
|
| 182 | + * as the primary column. |
|
| 183 | + * |
|
| 184 | + * @type string $_primary_column |
|
| 185 | + */ |
|
| 186 | + protected $_primary_column = ''; |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Used to indicate whether the table has a checkbox column or not. |
|
| 191 | + * |
|
| 192 | + * @type bool $_has_checkbox_column |
|
| 193 | + */ |
|
| 194 | + protected $_has_checkbox_column = false; |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 199 | + */ |
|
| 200 | + public function __construct(EE_Admin_Page $admin_page) |
|
| 201 | + { |
|
| 202 | + $this->_admin_page = $admin_page; |
|
| 203 | + $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 204 | + $this->_view = $this->_admin_page->get_view(); |
|
| 205 | + $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
| 206 | + $this->_current_page = $this->get_pagenum(); |
|
| 207 | + $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 208 | + $this->_yes_no = [ |
|
| 209 | + esc_html__('No', 'event_espresso'), |
|
| 210 | + esc_html__('Yes', 'event_espresso') |
|
| 211 | + ]; |
|
| 212 | + |
|
| 213 | + $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 214 | + |
|
| 215 | + $this->_setup_data(); |
|
| 216 | + $this->_add_view_counts(); |
|
| 217 | + |
|
| 218 | + $this->_nonce_action_ref = $this->_view; |
|
| 219 | + |
|
| 220 | + $this->_set_properties(); |
|
| 221 | + |
|
| 222 | + // set primary column |
|
| 223 | + add_filter('list_table_primary_column', [$this, 'set_primary_column']); |
|
| 224 | + |
|
| 225 | + // set parent defaults |
|
| 226 | + parent::__construct($this->_wp_list_args); |
|
| 227 | + |
|
| 228 | + $this->prepare_items(); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * _setup_data |
|
| 234 | + * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 235 | + * |
|
| 236 | + * @return void |
|
| 237 | + * @uses $this->_admin_page |
|
| 238 | + */ |
|
| 239 | + abstract protected function _setup_data(); |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 244 | + * properties set: |
|
| 245 | + * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 246 | + * _columns = set the columns in an array. |
|
| 247 | + * _sortable_columns = columns that are sortable (array). |
|
| 248 | + * _hidden_columns = columns that are hidden (array) |
|
| 249 | + * _default_orderby = the default orderby for sorting. |
|
| 250 | + * |
|
| 251 | + * @abstract |
|
| 252 | + * @access protected |
|
| 253 | + * @return void |
|
| 254 | + */ |
|
| 255 | + abstract protected function _set_properties(); |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * _get_table_filters |
|
| 260 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 261 | + * gets shown in the table. |
|
| 262 | + * |
|
| 263 | + * @abstract |
|
| 264 | + * @access protected |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + abstract protected function _get_table_filters(); |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 272 | + * counts of the views is accurate. |
|
| 273 | + * |
|
| 274 | + * @abstract |
|
| 275 | + * @access protected |
|
| 276 | + * @return void |
|
| 277 | + */ |
|
| 278 | + abstract protected function _add_view_counts(); |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * _get_hidden_fields |
|
| 283 | + * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 284 | + * |
|
| 285 | + * @return string |
|
| 286 | + */ |
|
| 287 | + protected function _get_hidden_fields() |
|
| 288 | + { |
|
| 289 | + $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 290 | + $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 291 | + // if action is STILL empty, then we set it to default |
|
| 292 | + $action = empty($action) ? 'default' : $action; |
|
| 293 | + $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 294 | + $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 295 | + $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 296 | + |
|
| 297 | + $bulk_actions = $this->_get_bulk_actions(); |
|
| 298 | + foreach ($bulk_actions as $bulk_action => $label) { |
|
| 299 | + $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 300 | + . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + return $field; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * _set_column_info |
|
| 309 | + * we're using this to set the column headers property. |
|
| 310 | + * |
|
| 311 | + * @access protected |
|
| 312 | + * @return void |
|
| 313 | + */ |
|
| 314 | + protected function _set_column_info() |
|
| 315 | + { |
|
| 316 | + $columns = $this->get_columns(); |
|
| 317 | + $hidden = $this->get_hidden_columns(); |
|
| 318 | + $_sortable = $this->get_sortable_columns(); |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 322 | + * Note that $this->screen->id is in the format |
|
| 323 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 324 | + * table it is: event-espresso_page_espresso_messages. |
|
| 325 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 326 | + * hook prefix ("event-espresso") will be different. |
|
| 327 | + * |
|
| 328 | + * @var array |
|
| 329 | + */ |
|
| 330 | + $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
| 331 | + |
|
| 332 | + $sortable = []; |
|
| 333 | + foreach ($_sortable as $id => $data) { |
|
| 334 | + if (empty($data)) { |
|
| 335 | + continue; |
|
| 336 | + } |
|
| 337 | + // fix for offset errors with WP_List_Table default get_columninfo() |
|
| 338 | + if (is_array($data)) { |
|
| 339 | + $_data[0] = key($data); |
|
| 340 | + $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 341 | + } else { |
|
| 342 | + $_data[0] = $data; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + $data = (array) $data; |
|
| 346 | + |
|
| 347 | + if (! isset($data[1])) { |
|
| 348 | + $_data[1] = false; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + $sortable[ $id ] = $_data; |
|
| 352 | + } |
|
| 353 | + $primary = $this->get_primary_column_name(); |
|
| 354 | + $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 360 | + * |
|
| 361 | + * @return string |
|
| 362 | + */ |
|
| 363 | + protected function get_primary_column_name() |
|
| 364 | + { |
|
| 365 | + foreach (class_parents($this) as $parent) { |
|
| 366 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 367 | + return parent::get_primary_column_name(); |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + return $this->_primary_column; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 376 | + * |
|
| 377 | + * @param EE_Base_Class $item |
|
| 378 | + * @param string $column_name |
|
| 379 | + * @param string $primary |
|
| 380 | + * @return string |
|
| 381 | + */ |
|
| 382 | + protected function handle_row_actions($item, $column_name, $primary) |
|
| 383 | + { |
|
| 384 | + foreach (class_parents($this) as $parent) { |
|
| 385 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 386 | + return parent::handle_row_actions($item, $column_name, $primary); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + return ''; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * _get_bulk_actions |
|
| 395 | + * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 396 | + * |
|
| 397 | + * @access protected |
|
| 398 | + * @return array bulk_actions |
|
| 399 | + */ |
|
| 400 | + protected function _get_bulk_actions() |
|
| 401 | + { |
|
| 402 | + $actions = []; |
|
| 403 | + // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
| 404 | + // formatted array for the wp_list_table(); |
|
| 405 | + foreach ($this->_views as $view => $args) { |
|
| 406 | + if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 407 | + // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
| 408 | + // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 409 | + foreach ($args['bulk_action'] as $route => $label) { |
|
| 410 | + if ($this->_admin_page->check_user_access($route, true)) { |
|
| 411 | + $actions[ $route ] = $label; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + return $actions; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * Generate the table navigation above or below the table. |
|
| 422 | + * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
| 423 | + * |
|
| 424 | + * @throws EE_Error |
|
| 425 | + * @since 4.9.44.rc.001 |
|
| 426 | + */ |
|
| 427 | + public function display_tablenav($which) |
|
| 428 | + { |
|
| 429 | + if ('top' === $which) { |
|
| 430 | + wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 431 | + } |
|
| 432 | + ?> |
|
| 433 | 433 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
| 434 | 434 | <?php if ($this->_get_bulk_actions()) { ?> |
| 435 | 435 | <div class="alignleft actions bulkactions"> |
| 436 | 436 | <?php $this->bulk_actions(); ?> |
| 437 | 437 | </div> |
| 438 | 438 | <?php } |
| 439 | - $this->extra_tablenav($which); |
|
| 440 | - $this->pagination($which); |
|
| 441 | - ?> |
|
| 439 | + $this->extra_tablenav($which); |
|
| 440 | + $this->pagination($which); |
|
| 441 | + ?> |
|
| 442 | 442 | |
| 443 | 443 | <br class="clear" /> |
| 444 | 444 | </div> |
| 445 | 445 | <?php |
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * _filters |
|
| 451 | - * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 452 | - * button. |
|
| 453 | - * |
|
| 454 | - * @access private |
|
| 455 | - * @return void echos html showing filters |
|
| 456 | - */ |
|
| 457 | - private function _filters() |
|
| 458 | - { |
|
| 459 | - $classname = get_class($this); |
|
| 460 | - $filters = apply_filters( |
|
| 461 | - "FHEE__{$classname}__filters", |
|
| 462 | - (array) $this->_get_table_filters(), |
|
| 463 | - $this, |
|
| 464 | - $this->_screen |
|
| 465 | - ); |
|
| 466 | - |
|
| 467 | - if (empty($filters)) { |
|
| 468 | - return; |
|
| 469 | - } |
|
| 470 | - foreach ($filters as $filter) { |
|
| 471 | - echo $filter; // already escaped |
|
| 472 | - } |
|
| 473 | - // add filter button at end |
|
| 474 | - echo '<input type="submit" class="button button--secondary" value="' |
|
| 475 | - . esc_html__('Filter', 'event_espresso') |
|
| 476 | - . '" id="post-query-submit" />'; |
|
| 477 | - // add reset filters button at end |
|
| 478 | - echo '<a class="button button--secondary" href="' |
|
| 479 | - . esc_url_raw($this->_admin_page->get_current_page_view_url()) |
|
| 480 | - . '">' |
|
| 481 | - . esc_html__('Reset Filters', 'event_espresso') |
|
| 482 | - . '</a>'; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Callback for 'list_table_primary_column' WordPress filter |
|
| 488 | - * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 489 | - * column when class is instantiated. |
|
| 490 | - * |
|
| 491 | - * @param string $column_name |
|
| 492 | - * @return string |
|
| 493 | - * @see WP_List_Table::get_primary_column_name |
|
| 494 | - */ |
|
| 495 | - public function set_primary_column($column_name) |
|
| 496 | - { |
|
| 497 | - return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * |
|
| 503 | - */ |
|
| 504 | - public function prepare_items() |
|
| 505 | - { |
|
| 506 | - |
|
| 507 | - $this->_set_column_info(); |
|
| 508 | - // $this->_column_headers = $this->get_column_info(); |
|
| 509 | - $total_items = $this->_all_data_count; |
|
| 510 | - $this->process_bulk_action(); |
|
| 511 | - |
|
| 512 | - $this->items = $this->_data; |
|
| 513 | - $this->set_pagination_args( |
|
| 514 | - [ |
|
| 515 | - 'total_items' => $total_items, |
|
| 516 | - 'per_page' => $this->_per_page, |
|
| 517 | - 'total_pages' => ceil($total_items / $this->_per_page), |
|
| 518 | - ] |
|
| 519 | - ); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * @param object|array $item |
|
| 525 | - * @return string html content for the column |
|
| 526 | - */ |
|
| 527 | - protected function column_cb($item) |
|
| 528 | - { |
|
| 529 | - return ''; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * This column is the default for when there is no defined column method for a registered column. |
|
| 535 | - * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 536 | - * |
|
| 537 | - * @param EE_Base_Class $item |
|
| 538 | - * @param string $column_name The column being called. |
|
| 539 | - * @return string html content for the column |
|
| 540 | - */ |
|
| 541 | - public function column_default($item, $column_name) |
|
| 542 | - { |
|
| 543 | - /** |
|
| 544 | - * Dynamic hook allowing for adding additional column content in this list table. |
|
| 545 | - * Note that $this->screen->id is in the format |
|
| 546 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 547 | - * table it is: event-espresso_page_espresso_messages. |
|
| 548 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 549 | - * hook prefix ("event-espresso") will be different. |
|
| 550 | - */ |
|
| 551 | - ob_start(); |
|
| 552 | - do_action( |
|
| 553 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 554 | - $item, |
|
| 555 | - $this->_screen |
|
| 556 | - ); |
|
| 557 | - return ob_get_clean(); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Get a list of columns. The format is: |
|
| 563 | - * 'internal-name' => 'Title' |
|
| 564 | - * |
|
| 565 | - * @return array |
|
| 566 | - * @since 3.1.0 |
|
| 567 | - * @access public |
|
| 568 | - * @abstract |
|
| 569 | - */ |
|
| 570 | - public function get_columns() |
|
| 571 | - { |
|
| 572 | - /** |
|
| 573 | - * Dynamic hook allowing for adding additional columns in this list table. |
|
| 574 | - * Note that $this->screen->id is in the format |
|
| 575 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 576 | - * table it is: event-espresso_page_espresso_messages. |
|
| 577 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 578 | - * hook prefix ("event-espresso") will be different. |
|
| 579 | - * |
|
| 580 | - * @var array |
|
| 581 | - */ |
|
| 582 | - return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Get an associative array ( id => link ) with the list |
|
| 588 | - * of views available on this table. |
|
| 589 | - * |
|
| 590 | - * @return array |
|
| 591 | - * @since 3.1.0 |
|
| 592 | - * @access protected |
|
| 593 | - */ |
|
| 594 | - public function get_views() |
|
| 595 | - { |
|
| 596 | - return $this->_views; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Generate the views html. |
|
| 602 | - */ |
|
| 603 | - public function display_views() |
|
| 604 | - { |
|
| 605 | - $views = $this->get_views(); |
|
| 606 | - $assembled_views = []; |
|
| 607 | - |
|
| 608 | - if (empty($views)) { |
|
| 609 | - return; |
|
| 610 | - } |
|
| 611 | - echo "<ul class='subsubsub'>\n"; |
|
| 612 | - foreach ($views as $view) { |
|
| 613 | - $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 614 | - if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 615 | - $filter = "<li"; |
|
| 616 | - $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 617 | - $filter .= ">"; |
|
| 618 | - $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 619 | - $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 620 | - $filter .= '</li>'; |
|
| 621 | - $assembled_views[ $view['slug'] ] = $filter; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - echo ! empty($assembled_views) |
|
| 626 | - ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views) |
|
| 627 | - : ''; |
|
| 628 | - echo "</ul>"; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Generates content for a single row of the table |
|
| 634 | - * |
|
| 635 | - * @param EE_Base_Class $item The current item |
|
| 636 | - * @since 4.1 |
|
| 637 | - * @access public |
|
| 638 | - */ |
|
| 639 | - public function single_row($item) |
|
| 640 | - { |
|
| 641 | - $row_class = $this->_get_row_class($item); |
|
| 642 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 643 | - $this->single_row_columns($item); // already escaped |
|
| 644 | - echo '</tr>'; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * This simply sets up the row class for the table rows. |
|
| 650 | - * Allows for easier overriding of child methods for setting up sorting. |
|
| 651 | - * |
|
| 652 | - * @param EE_Base_Class $item the current item |
|
| 653 | - * @return string |
|
| 654 | - */ |
|
| 655 | - protected function _get_row_class($item) |
|
| 656 | - { |
|
| 657 | - static $row_class = ''; |
|
| 658 | - $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 659 | - |
|
| 660 | - $new_row_class = $row_class; |
|
| 661 | - |
|
| 662 | - if (! empty($this->_ajax_sorting_callback)) { |
|
| 663 | - $new_row_class .= ' rowsortable'; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $new_row_class; |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * @return array |
|
| 672 | - */ |
|
| 673 | - public function get_sortable_columns() |
|
| 674 | - { |
|
| 675 | - return (array) $this->_sortable_columns; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * @return string |
|
| 681 | - */ |
|
| 682 | - public function get_ajax_sorting_callback() |
|
| 683 | - { |
|
| 684 | - return $this->_ajax_sorting_callback; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * @return array |
|
| 690 | - */ |
|
| 691 | - public function get_hidden_columns() |
|
| 692 | - { |
|
| 693 | - $user_id = get_current_user_id(); |
|
| 694 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 695 | - if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 696 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 697 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 698 | - } |
|
| 699 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 700 | - return (array) get_user_option($ref, $user_id); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * Generates the columns for a single row of the table. |
|
| 706 | - * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 707 | - * column. |
|
| 708 | - * |
|
| 709 | - * @param EE_Base_Class $item The current item |
|
| 710 | - * @since 3.1.0 |
|
| 711 | - */ |
|
| 712 | - public function single_row_columns($item) |
|
| 713 | - { |
|
| 714 | - [$columns, $hidden, $sortable, $primary] = $this->get_column_info(); |
|
| 715 | - |
|
| 716 | - foreach ($columns as $column_name => $column_display_name) { |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
| 720 | - * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 721 | - */ |
|
| 722 | - $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 723 | - |
|
| 724 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 725 | - if ($primary === $column_name) { |
|
| 726 | - $classes .= ' has-row-actions column-primary'; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 730 | - |
|
| 731 | - $class = 'class="' . esc_attr($classes) . '"'; |
|
| 732 | - |
|
| 733 | - $attributes = "{$class}{$data}"; |
|
| 734 | - |
|
| 735 | - if ($column_name === 'cb') { |
|
| 736 | - echo '<th scope="row" class="check-column">'; |
|
| 737 | - echo apply_filters( |
|
| 738 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 739 | - $this->column_cb($item), // already escaped |
|
| 740 | - $item, |
|
| 741 | - $this |
|
| 742 | - ); |
|
| 743 | - echo '</th>'; |
|
| 744 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 745 | - echo "<td $attributes>"; // already escaped |
|
| 746 | - echo apply_filters( |
|
| 747 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 748 | - call_user_func([$this, 'column_' . $column_name], $item), |
|
| 749 | - $item, |
|
| 750 | - $this |
|
| 751 | - ); |
|
| 752 | - echo $this->handle_row_actions($item, $column_name, $primary); |
|
| 753 | - echo "</td>"; |
|
| 754 | - } else { |
|
| 755 | - echo "<td $attributes>"; // already escaped |
|
| 756 | - echo apply_filters( |
|
| 757 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 758 | - $this->column_default($item, $column_name), |
|
| 759 | - $item, |
|
| 760 | - $column_name, |
|
| 761 | - $this |
|
| 762 | - ); |
|
| 763 | - echo $this->handle_row_actions($item, $column_name, $primary); |
|
| 764 | - echo "</td>"; |
|
| 765 | - } |
|
| 766 | - } |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * Extra controls to be displayed between bulk actions and pagination |
|
| 772 | - * |
|
| 773 | - * @access public |
|
| 774 | - * @param string $which |
|
| 775 | - * @throws EE_Error |
|
| 776 | - */ |
|
| 777 | - public function extra_tablenav($which) |
|
| 778 | - { |
|
| 779 | - if ($which === 'top') { |
|
| 780 | - $this->_filters(); |
|
| 781 | - echo $this->_get_hidden_fields(); // already escaped |
|
| 782 | - } else { |
|
| 783 | - echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 784 | - foreach ($this->_bottom_buttons as $type => $action) { |
|
| 785 | - $route = isset($action['route']) ? $action['route'] : ''; |
|
| 786 | - $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
| 787 | - // already escaped |
|
| 788 | - echo $this->_admin_page->get_action_link_or_button( |
|
| 789 | - $route, |
|
| 790 | - $type, |
|
| 791 | - $extra_request, |
|
| 792 | - 'button button--secondary' |
|
| 793 | - ); |
|
| 794 | - } |
|
| 795 | - do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 796 | - echo '</div>'; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * Get an associative array ( option_name => option_title ) with the list |
|
| 803 | - * of bulk actions available on this table. |
|
| 804 | - * |
|
| 805 | - * @return array |
|
| 806 | - * @since 3.1.0 |
|
| 807 | - * @access protected |
|
| 808 | - */ |
|
| 809 | - public function get_bulk_actions() |
|
| 810 | - { |
|
| 811 | - return (array) $this->_get_bulk_actions(); |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * Processing bulk actions. |
|
| 817 | - */ |
|
| 818 | - public function process_bulk_action() |
|
| 819 | - { |
|
| 820 | - // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
| 821 | - // reference in case there is a case where it gets used. |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * returns the EE admin page this list table is associated with |
|
| 827 | - * |
|
| 828 | - * @return EE_Admin_Page |
|
| 829 | - */ |
|
| 830 | - public function get_admin_page() |
|
| 831 | - { |
|
| 832 | - return $this->_admin_page; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * A "helper" function for all children to provide an html string of |
|
| 838 | - * actions to output in their content. It is preferable for child classes |
|
| 839 | - * to use this method for generating their actions content so that it's |
|
| 840 | - * filterable by plugins |
|
| 841 | - * |
|
| 842 | - * @param string $action_container what are the html container |
|
| 843 | - * elements for this actions string? |
|
| 844 | - * @param string $action_class What class is for the container |
|
| 845 | - * element. |
|
| 846 | - * @param string $action_items The contents for the action items |
|
| 847 | - * container. This is filtered before |
|
| 848 | - * returned. |
|
| 849 | - * @param string $action_id What id (optional) is used for the |
|
| 850 | - * container element. |
|
| 851 | - * @param EE_Base_Class $item The object for the column displaying |
|
| 852 | - * the actions. |
|
| 853 | - * @return string The assembled action elements container. |
|
| 854 | - */ |
|
| 855 | - protected function _action_string( |
|
| 856 | - $action_items, |
|
| 857 | - $item, |
|
| 858 | - $action_container = 'ul', |
|
| 859 | - $action_class = '', |
|
| 860 | - $action_id = '' |
|
| 861 | - ) { |
|
| 862 | - $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 863 | - $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 864 | - $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 865 | - $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 866 | - try { |
|
| 867 | - $content = apply_filters( |
|
| 868 | - 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 869 | - $action_items, |
|
| 870 | - $item, |
|
| 871 | - $this |
|
| 872 | - ); |
|
| 873 | - } catch (Exception $e) { |
|
| 874 | - if (WP_DEBUG) { |
|
| 875 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 876 | - } |
|
| 877 | - $content = $action_items; |
|
| 878 | - } |
|
| 879 | - return "{$open_tag}{$content}{$close_tag}"; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * @return string |
|
| 885 | - */ |
|
| 886 | - protected function getReturnUrl() |
|
| 887 | - { |
|
| 888 | - $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST'); |
|
| 889 | - $uri = $this->_admin_page->get_request()->getServerParam('REQUEST_URI'); |
|
| 890 | - return urlencode(esc_url_raw("//{$host}{$uri}")); |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - |
|
| 894 | - /** |
|
| 895 | - * @param string $id |
|
| 896 | - * @param string $content |
|
| 897 | - * @param string $align start (default), center, end |
|
| 898 | - * @return string |
|
| 899 | - * @since $VID:$ |
|
| 900 | - */ |
|
| 901 | - protected function columnContent($id, $content, $align = 'start') |
|
| 902 | - { |
|
| 903 | - if (! isset($this->_columns[ $id ])) { |
|
| 904 | - throw new DomainException('missing column id'); |
|
| 905 | - } |
|
| 906 | - $heading = $id !== 'cb' ? $this->_columns[ $id ] : ''; |
|
| 907 | - $align = in_array($align, ['start', 'center', 'end']) ? $align : 'start'; |
|
| 908 | - $align = "ee-responsive-table-cell--{$align}"; |
|
| 909 | - |
|
| 910 | - $html = "<div id='ee-responsive-table-cell-{$id}' class='ee-responsive-table-cell {$align} ee-layout-stack'>"; |
|
| 911 | - $html .= "<div class='ee-responsive-table-cell__heading'>{$heading}</div>"; |
|
| 912 | - $html .= "<div class='ee-responsive-table-cell__content ee-layout-stack'>{$content}</div>"; |
|
| 913 | - $html .= "</div>"; |
|
| 914 | - return $html; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - |
|
| 918 | - protected function actionsModalMenu($actions): string |
|
| 919 | - { |
|
| 920 | - return ' |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * _filters |
|
| 451 | + * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 452 | + * button. |
|
| 453 | + * |
|
| 454 | + * @access private |
|
| 455 | + * @return void echos html showing filters |
|
| 456 | + */ |
|
| 457 | + private function _filters() |
|
| 458 | + { |
|
| 459 | + $classname = get_class($this); |
|
| 460 | + $filters = apply_filters( |
|
| 461 | + "FHEE__{$classname}__filters", |
|
| 462 | + (array) $this->_get_table_filters(), |
|
| 463 | + $this, |
|
| 464 | + $this->_screen |
|
| 465 | + ); |
|
| 466 | + |
|
| 467 | + if (empty($filters)) { |
|
| 468 | + return; |
|
| 469 | + } |
|
| 470 | + foreach ($filters as $filter) { |
|
| 471 | + echo $filter; // already escaped |
|
| 472 | + } |
|
| 473 | + // add filter button at end |
|
| 474 | + echo '<input type="submit" class="button button--secondary" value="' |
|
| 475 | + . esc_html__('Filter', 'event_espresso') |
|
| 476 | + . '" id="post-query-submit" />'; |
|
| 477 | + // add reset filters button at end |
|
| 478 | + echo '<a class="button button--secondary" href="' |
|
| 479 | + . esc_url_raw($this->_admin_page->get_current_page_view_url()) |
|
| 480 | + . '">' |
|
| 481 | + . esc_html__('Reset Filters', 'event_espresso') |
|
| 482 | + . '</a>'; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Callback for 'list_table_primary_column' WordPress filter |
|
| 488 | + * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 489 | + * column when class is instantiated. |
|
| 490 | + * |
|
| 491 | + * @param string $column_name |
|
| 492 | + * @return string |
|
| 493 | + * @see WP_List_Table::get_primary_column_name |
|
| 494 | + */ |
|
| 495 | + public function set_primary_column($column_name) |
|
| 496 | + { |
|
| 497 | + return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * |
|
| 503 | + */ |
|
| 504 | + public function prepare_items() |
|
| 505 | + { |
|
| 506 | + |
|
| 507 | + $this->_set_column_info(); |
|
| 508 | + // $this->_column_headers = $this->get_column_info(); |
|
| 509 | + $total_items = $this->_all_data_count; |
|
| 510 | + $this->process_bulk_action(); |
|
| 511 | + |
|
| 512 | + $this->items = $this->_data; |
|
| 513 | + $this->set_pagination_args( |
|
| 514 | + [ |
|
| 515 | + 'total_items' => $total_items, |
|
| 516 | + 'per_page' => $this->_per_page, |
|
| 517 | + 'total_pages' => ceil($total_items / $this->_per_page), |
|
| 518 | + ] |
|
| 519 | + ); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * @param object|array $item |
|
| 525 | + * @return string html content for the column |
|
| 526 | + */ |
|
| 527 | + protected function column_cb($item) |
|
| 528 | + { |
|
| 529 | + return ''; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * This column is the default for when there is no defined column method for a registered column. |
|
| 535 | + * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 536 | + * |
|
| 537 | + * @param EE_Base_Class $item |
|
| 538 | + * @param string $column_name The column being called. |
|
| 539 | + * @return string html content for the column |
|
| 540 | + */ |
|
| 541 | + public function column_default($item, $column_name) |
|
| 542 | + { |
|
| 543 | + /** |
|
| 544 | + * Dynamic hook allowing for adding additional column content in this list table. |
|
| 545 | + * Note that $this->screen->id is in the format |
|
| 546 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 547 | + * table it is: event-espresso_page_espresso_messages. |
|
| 548 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 549 | + * hook prefix ("event-espresso") will be different. |
|
| 550 | + */ |
|
| 551 | + ob_start(); |
|
| 552 | + do_action( |
|
| 553 | + 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 554 | + $item, |
|
| 555 | + $this->_screen |
|
| 556 | + ); |
|
| 557 | + return ob_get_clean(); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Get a list of columns. The format is: |
|
| 563 | + * 'internal-name' => 'Title' |
|
| 564 | + * |
|
| 565 | + * @return array |
|
| 566 | + * @since 3.1.0 |
|
| 567 | + * @access public |
|
| 568 | + * @abstract |
|
| 569 | + */ |
|
| 570 | + public function get_columns() |
|
| 571 | + { |
|
| 572 | + /** |
|
| 573 | + * Dynamic hook allowing for adding additional columns in this list table. |
|
| 574 | + * Note that $this->screen->id is in the format |
|
| 575 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 576 | + * table it is: event-espresso_page_espresso_messages. |
|
| 577 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 578 | + * hook prefix ("event-espresso") will be different. |
|
| 579 | + * |
|
| 580 | + * @var array |
|
| 581 | + */ |
|
| 582 | + return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Get an associative array ( id => link ) with the list |
|
| 588 | + * of views available on this table. |
|
| 589 | + * |
|
| 590 | + * @return array |
|
| 591 | + * @since 3.1.0 |
|
| 592 | + * @access protected |
|
| 593 | + */ |
|
| 594 | + public function get_views() |
|
| 595 | + { |
|
| 596 | + return $this->_views; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Generate the views html. |
|
| 602 | + */ |
|
| 603 | + public function display_views() |
|
| 604 | + { |
|
| 605 | + $views = $this->get_views(); |
|
| 606 | + $assembled_views = []; |
|
| 607 | + |
|
| 608 | + if (empty($views)) { |
|
| 609 | + return; |
|
| 610 | + } |
|
| 611 | + echo "<ul class='subsubsub'>\n"; |
|
| 612 | + foreach ($views as $view) { |
|
| 613 | + $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 614 | + if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 615 | + $filter = "<li"; |
|
| 616 | + $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 617 | + $filter .= ">"; |
|
| 618 | + $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 619 | + $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 620 | + $filter .= '</li>'; |
|
| 621 | + $assembled_views[ $view['slug'] ] = $filter; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + echo ! empty($assembled_views) |
|
| 626 | + ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views) |
|
| 627 | + : ''; |
|
| 628 | + echo "</ul>"; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Generates content for a single row of the table |
|
| 634 | + * |
|
| 635 | + * @param EE_Base_Class $item The current item |
|
| 636 | + * @since 4.1 |
|
| 637 | + * @access public |
|
| 638 | + */ |
|
| 639 | + public function single_row($item) |
|
| 640 | + { |
|
| 641 | + $row_class = $this->_get_row_class($item); |
|
| 642 | + echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 643 | + $this->single_row_columns($item); // already escaped |
|
| 644 | + echo '</tr>'; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * This simply sets up the row class for the table rows. |
|
| 650 | + * Allows for easier overriding of child methods for setting up sorting. |
|
| 651 | + * |
|
| 652 | + * @param EE_Base_Class $item the current item |
|
| 653 | + * @return string |
|
| 654 | + */ |
|
| 655 | + protected function _get_row_class($item) |
|
| 656 | + { |
|
| 657 | + static $row_class = ''; |
|
| 658 | + $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 659 | + |
|
| 660 | + $new_row_class = $row_class; |
|
| 661 | + |
|
| 662 | + if (! empty($this->_ajax_sorting_callback)) { |
|
| 663 | + $new_row_class .= ' rowsortable'; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return $new_row_class; |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * @return array |
|
| 672 | + */ |
|
| 673 | + public function get_sortable_columns() |
|
| 674 | + { |
|
| 675 | + return (array) $this->_sortable_columns; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * @return string |
|
| 681 | + */ |
|
| 682 | + public function get_ajax_sorting_callback() |
|
| 683 | + { |
|
| 684 | + return $this->_ajax_sorting_callback; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * @return array |
|
| 690 | + */ |
|
| 691 | + public function get_hidden_columns() |
|
| 692 | + { |
|
| 693 | + $user_id = get_current_user_id(); |
|
| 694 | + $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 695 | + if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 696 | + update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 697 | + update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 698 | + } |
|
| 699 | + $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 700 | + return (array) get_user_option($ref, $user_id); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * Generates the columns for a single row of the table. |
|
| 706 | + * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 707 | + * column. |
|
| 708 | + * |
|
| 709 | + * @param EE_Base_Class $item The current item |
|
| 710 | + * @since 3.1.0 |
|
| 711 | + */ |
|
| 712 | + public function single_row_columns($item) |
|
| 713 | + { |
|
| 714 | + [$columns, $hidden, $sortable, $primary] = $this->get_column_info(); |
|
| 715 | + |
|
| 716 | + foreach ($columns as $column_name => $column_display_name) { |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
| 720 | + * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 721 | + */ |
|
| 722 | + $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 723 | + |
|
| 724 | + $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 725 | + if ($primary === $column_name) { |
|
| 726 | + $classes .= ' has-row-actions column-primary'; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 730 | + |
|
| 731 | + $class = 'class="' . esc_attr($classes) . '"'; |
|
| 732 | + |
|
| 733 | + $attributes = "{$class}{$data}"; |
|
| 734 | + |
|
| 735 | + if ($column_name === 'cb') { |
|
| 736 | + echo '<th scope="row" class="check-column">'; |
|
| 737 | + echo apply_filters( |
|
| 738 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 739 | + $this->column_cb($item), // already escaped |
|
| 740 | + $item, |
|
| 741 | + $this |
|
| 742 | + ); |
|
| 743 | + echo '</th>'; |
|
| 744 | + } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 745 | + echo "<td $attributes>"; // already escaped |
|
| 746 | + echo apply_filters( |
|
| 747 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 748 | + call_user_func([$this, 'column_' . $column_name], $item), |
|
| 749 | + $item, |
|
| 750 | + $this |
|
| 751 | + ); |
|
| 752 | + echo $this->handle_row_actions($item, $column_name, $primary); |
|
| 753 | + echo "</td>"; |
|
| 754 | + } else { |
|
| 755 | + echo "<td $attributes>"; // already escaped |
|
| 756 | + echo apply_filters( |
|
| 757 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 758 | + $this->column_default($item, $column_name), |
|
| 759 | + $item, |
|
| 760 | + $column_name, |
|
| 761 | + $this |
|
| 762 | + ); |
|
| 763 | + echo $this->handle_row_actions($item, $column_name, $primary); |
|
| 764 | + echo "</td>"; |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * Extra controls to be displayed between bulk actions and pagination |
|
| 772 | + * |
|
| 773 | + * @access public |
|
| 774 | + * @param string $which |
|
| 775 | + * @throws EE_Error |
|
| 776 | + */ |
|
| 777 | + public function extra_tablenav($which) |
|
| 778 | + { |
|
| 779 | + if ($which === 'top') { |
|
| 780 | + $this->_filters(); |
|
| 781 | + echo $this->_get_hidden_fields(); // already escaped |
|
| 782 | + } else { |
|
| 783 | + echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 784 | + foreach ($this->_bottom_buttons as $type => $action) { |
|
| 785 | + $route = isset($action['route']) ? $action['route'] : ''; |
|
| 786 | + $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
| 787 | + // already escaped |
|
| 788 | + echo $this->_admin_page->get_action_link_or_button( |
|
| 789 | + $route, |
|
| 790 | + $type, |
|
| 791 | + $extra_request, |
|
| 792 | + 'button button--secondary' |
|
| 793 | + ); |
|
| 794 | + } |
|
| 795 | + do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 796 | + echo '</div>'; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * Get an associative array ( option_name => option_title ) with the list |
|
| 803 | + * of bulk actions available on this table. |
|
| 804 | + * |
|
| 805 | + * @return array |
|
| 806 | + * @since 3.1.0 |
|
| 807 | + * @access protected |
|
| 808 | + */ |
|
| 809 | + public function get_bulk_actions() |
|
| 810 | + { |
|
| 811 | + return (array) $this->_get_bulk_actions(); |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * Processing bulk actions. |
|
| 817 | + */ |
|
| 818 | + public function process_bulk_action() |
|
| 819 | + { |
|
| 820 | + // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
| 821 | + // reference in case there is a case where it gets used. |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * returns the EE admin page this list table is associated with |
|
| 827 | + * |
|
| 828 | + * @return EE_Admin_Page |
|
| 829 | + */ |
|
| 830 | + public function get_admin_page() |
|
| 831 | + { |
|
| 832 | + return $this->_admin_page; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + /** |
|
| 837 | + * A "helper" function for all children to provide an html string of |
|
| 838 | + * actions to output in their content. It is preferable for child classes |
|
| 839 | + * to use this method for generating their actions content so that it's |
|
| 840 | + * filterable by plugins |
|
| 841 | + * |
|
| 842 | + * @param string $action_container what are the html container |
|
| 843 | + * elements for this actions string? |
|
| 844 | + * @param string $action_class What class is for the container |
|
| 845 | + * element. |
|
| 846 | + * @param string $action_items The contents for the action items |
|
| 847 | + * container. This is filtered before |
|
| 848 | + * returned. |
|
| 849 | + * @param string $action_id What id (optional) is used for the |
|
| 850 | + * container element. |
|
| 851 | + * @param EE_Base_Class $item The object for the column displaying |
|
| 852 | + * the actions. |
|
| 853 | + * @return string The assembled action elements container. |
|
| 854 | + */ |
|
| 855 | + protected function _action_string( |
|
| 856 | + $action_items, |
|
| 857 | + $item, |
|
| 858 | + $action_container = 'ul', |
|
| 859 | + $action_class = '', |
|
| 860 | + $action_id = '' |
|
| 861 | + ) { |
|
| 862 | + $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 863 | + $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 864 | + $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 865 | + $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 866 | + try { |
|
| 867 | + $content = apply_filters( |
|
| 868 | + 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 869 | + $action_items, |
|
| 870 | + $item, |
|
| 871 | + $this |
|
| 872 | + ); |
|
| 873 | + } catch (Exception $e) { |
|
| 874 | + if (WP_DEBUG) { |
|
| 875 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 876 | + } |
|
| 877 | + $content = $action_items; |
|
| 878 | + } |
|
| 879 | + return "{$open_tag}{$content}{$close_tag}"; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * @return string |
|
| 885 | + */ |
|
| 886 | + protected function getReturnUrl() |
|
| 887 | + { |
|
| 888 | + $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST'); |
|
| 889 | + $uri = $this->_admin_page->get_request()->getServerParam('REQUEST_URI'); |
|
| 890 | + return urlencode(esc_url_raw("//{$host}{$uri}")); |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + |
|
| 894 | + /** |
|
| 895 | + * @param string $id |
|
| 896 | + * @param string $content |
|
| 897 | + * @param string $align start (default), center, end |
|
| 898 | + * @return string |
|
| 899 | + * @since $VID:$ |
|
| 900 | + */ |
|
| 901 | + protected function columnContent($id, $content, $align = 'start') |
|
| 902 | + { |
|
| 903 | + if (! isset($this->_columns[ $id ])) { |
|
| 904 | + throw new DomainException('missing column id'); |
|
| 905 | + } |
|
| 906 | + $heading = $id !== 'cb' ? $this->_columns[ $id ] : ''; |
|
| 907 | + $align = in_array($align, ['start', 'center', 'end']) ? $align : 'start'; |
|
| 908 | + $align = "ee-responsive-table-cell--{$align}"; |
|
| 909 | + |
|
| 910 | + $html = "<div id='ee-responsive-table-cell-{$id}' class='ee-responsive-table-cell {$align} ee-layout-stack'>"; |
|
| 911 | + $html .= "<div class='ee-responsive-table-cell__heading'>{$heading}</div>"; |
|
| 912 | + $html .= "<div class='ee-responsive-table-cell__content ee-layout-stack'>{$content}</div>"; |
|
| 913 | + $html .= "</div>"; |
|
| 914 | + return $html; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + |
|
| 918 | + protected function actionsModalMenu($actions): string |
|
| 919 | + { |
|
| 920 | + return ' |
|
| 921 | 921 | <div class="ee-modal-menu"> |
| 922 | 922 | <button class="ee-modal-menu__button button button--small button--icon-only ee-aria-tooltip" |
| 923 | 923 | aria-label="' . esc_attr__('list table actions menu', 'event_espresso') . '" |
@@ -929,15 +929,15 @@ discard block |
||
| 929 | 929 | ' . $actions . ' |
| 930 | 930 | </div> |
| 931 | 931 | </div>'; |
| 932 | - } |
|
| 932 | + } |
|
| 933 | 933 | |
| 934 | 934 | |
| 935 | - protected function actionsColumnHeader(): string |
|
| 936 | - { |
|
| 937 | - return ' |
|
| 935 | + protected function actionsColumnHeader(): string |
|
| 936 | + { |
|
| 937 | + return ' |
|
| 938 | 938 | <span class="ee-actions-column-header-wrap"> |
| 939 | 939 | <span class="dashicons dashicons-screenoptions"></span> |
| 940 | 940 | <span class="ee-actions-column-header">' . esc_html__('Actions', 'event_espresso') . '</span> |
| 941 | 941 | </span>'; |
| 942 | - } |
|
| 942 | + } |
|
| 943 | 943 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (! class_exists('WP_List_Table')) { |
|
| 4 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 3 | +if ( ! class_exists('WP_List_Table')) { |
|
| 4 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -204,13 +204,13 @@ discard block |
||
| 204 | 204 | $this->_view = $this->_admin_page->get_view(); |
| 205 | 205 | $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
| 206 | 206 | $this->_current_page = $this->get_pagenum(); |
| 207 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 207 | + $this->_screen = $this->_admin_page->get_current_page().'_'.$this->_admin_page->get_current_view(); |
|
| 208 | 208 | $this->_yes_no = [ |
| 209 | 209 | esc_html__('No', 'event_espresso'), |
| 210 | 210 | esc_html__('Yes', 'event_espresso') |
| 211 | 211 | ]; |
| 212 | 212 | |
| 213 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 213 | + $this->_per_page = $this->get_items_per_page($this->_screen.'_per_page'); |
|
| 214 | 214 | |
| 215 | 215 | $this->_setup_data(); |
| 216 | 216 | $this->_add_view_counts(); |
@@ -290,14 +290,14 @@ discard block |
||
| 290 | 290 | $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
| 291 | 291 | // if action is STILL empty, then we set it to default |
| 292 | 292 | $action = empty($action) ? 'default' : $action; |
| 293 | - $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 294 | - $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 295 | - $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 293 | + $field = '<input type="hidden" name="page" value="'.esc_attr($this->_req_data['page']).'" />'."\n"; |
|
| 294 | + $field .= '<input type="hidden" name="route" value="'.esc_attr($action).'" />'."\n"; |
|
| 295 | + $field .= '<input type="hidden" name="perpage" value="'.esc_attr($this->_per_page).'" />'."\n"; |
|
| 296 | 296 | |
| 297 | 297 | $bulk_actions = $this->_get_bulk_actions(); |
| 298 | 298 | foreach ($bulk_actions as $bulk_action => $label) { |
| 299 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 300 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 299 | + $field .= '<input type="hidden" name="'.$bulk_action.'_nonce"' |
|
| 300 | + . ' value="'.wp_create_nonce($bulk_action.'_nonce').'" />'."\n"; |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | return $field; |
@@ -344,11 +344,11 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | $data = (array) $data; |
| 346 | 346 | |
| 347 | - if (! isset($data[1])) { |
|
| 347 | + if ( ! isset($data[1])) { |
|
| 348 | 348 | $_data[1] = false; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - $sortable[ $id ] = $_data; |
|
| 351 | + $sortable[$id] = $_data; |
|
| 352 | 352 | } |
| 353 | 353 | $primary = $this->get_primary_column_name(); |
| 354 | 354 | $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | // for that page route and skip adding the bulk action if no access for the current logged in user. |
| 409 | 409 | foreach ($args['bulk_action'] as $route => $label) { |
| 410 | 410 | if ($this->_admin_page->check_user_access($route, true)) { |
| 411 | - $actions[ $route ] = $label; |
|
| 411 | + $actions[$route] = $label; |
|
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | 414 | } |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | public function display_tablenav($which) |
| 428 | 428 | { |
| 429 | 429 | if ('top' === $which) { |
| 430 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 430 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
| 431 | 431 | } |
| 432 | 432 | ?> |
| 433 | 433 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | */ |
| 551 | 551 | ob_start(); |
| 552 | 552 | do_action( |
| 553 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 553 | + 'AHEE__EE_Admin_List_Table__column_'.$column_name.'__'.$this->screen->id, |
|
| 554 | 554 | $item, |
| 555 | 555 | $this->_screen |
| 556 | 556 | ); |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | * |
| 580 | 580 | * @var array |
| 581 | 581 | */ |
| 582 | - return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 582 | + return apply_filters('FHEE_manage_'.$this->screen->id.'_columns', $this->_columns, $this->_screen); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
@@ -613,12 +613,12 @@ discard block |
||
| 613 | 613 | $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
| 614 | 614 | if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
| 615 | 615 | $filter = "<li"; |
| 616 | - $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 616 | + $filter .= $view['class'] ? " class='".esc_attr($view['class'])."'" : ''; |
|
| 617 | 617 | $filter .= ">"; |
| 618 | - $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 619 | - $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 618 | + $filter .= '<a href="'.esc_url_raw($view['url']).'">'.esc_html($view['label']).'</a>'; |
|
| 619 | + $filter .= '<span class="count">('.$count.')</span>'; |
|
| 620 | 620 | $filter .= '</li>'; |
| 621 | - $assembled_views[ $view['slug'] ] = $filter; |
|
| 621 | + $assembled_views[$view['slug']] = $filter; |
|
| 622 | 622 | } |
| 623 | 623 | } |
| 624 | 624 | |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | public function single_row($item) |
| 640 | 640 | { |
| 641 | 641 | $row_class = $this->_get_row_class($item); |
| 642 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 642 | + echo '<tr class="'.esc_attr($row_class).'">'; |
|
| 643 | 643 | $this->single_row_columns($item); // already escaped |
| 644 | 644 | echo '</tr>'; |
| 645 | 645 | } |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | |
| 660 | 660 | $new_row_class = $row_class; |
| 661 | 661 | |
| 662 | - if (! empty($this->_ajax_sorting_callback)) { |
|
| 662 | + if ( ! empty($this->_ajax_sorting_callback)) { |
|
| 663 | 663 | $new_row_class .= ' rowsortable'; |
| 664 | 664 | } |
| 665 | 665 | |
@@ -691,12 +691,12 @@ discard block |
||
| 691 | 691 | public function get_hidden_columns() |
| 692 | 692 | { |
| 693 | 693 | $user_id = get_current_user_id(); |
| 694 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 694 | + $has_default = get_user_option('default'.$this->screen->id.'columnshidden', $user_id); |
|
| 695 | 695 | if (empty($has_default) && ! empty($this->_hidden_columns)) { |
| 696 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 697 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 696 | + update_user_option($user_id, 'default'.$this->screen->id.'columnshidden', true); |
|
| 697 | + update_user_option($user_id, 'manage'.$this->screen->id.'columnshidden', $this->_hidden_columns, true); |
|
| 698 | 698 | } |
| 699 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 699 | + $ref = 'manage'.$this->screen->id.'columnshidden'; |
|
| 700 | 700 | return (array) get_user_option($ref, $user_id); |
| 701 | 701 | } |
| 702 | 702 | |
@@ -721,14 +721,14 @@ discard block |
||
| 721 | 721 | */ |
| 722 | 722 | $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
| 723 | 723 | |
| 724 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 724 | + $classes = $column_name.' column-'.$column_name.$hidden_class; |
|
| 725 | 725 | if ($primary === $column_name) { |
| 726 | 726 | $classes .= ' has-row-actions column-primary'; |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 729 | + $data = ' data-colname="'.wp_strip_all_tags($column_display_name).'"'; |
|
| 730 | 730 | |
| 731 | - $class = 'class="' . esc_attr($classes) . '"'; |
|
| 731 | + $class = 'class="'.esc_attr($classes).'"'; |
|
| 732 | 732 | |
| 733 | 733 | $attributes = "{$class}{$data}"; |
| 734 | 734 | |
@@ -741,11 +741,11 @@ discard block |
||
| 741 | 741 | $this |
| 742 | 742 | ); |
| 743 | 743 | echo '</th>'; |
| 744 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 744 | + } elseif (method_exists($this, 'column_'.$column_name)) { |
|
| 745 | 745 | echo "<td $attributes>"; // already escaped |
| 746 | 746 | echo apply_filters( |
| 747 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 748 | - call_user_func([$this, 'column_' . $column_name], $item), |
|
| 747 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_'.$column_name.'__column_content', |
|
| 748 | + call_user_func([$this, 'column_'.$column_name], $item), |
|
| 749 | 749 | $item, |
| 750 | 750 | $this |
| 751 | 751 | ); |
@@ -859,10 +859,10 @@ discard block |
||
| 859 | 859 | $action_class = '', |
| 860 | 860 | $action_id = '' |
| 861 | 861 | ) { |
| 862 | - $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 863 | - $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 864 | - $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 865 | - $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 862 | + $action_class = ! empty($action_class) ? ' class="'.esc_attr($action_class).'"' : ''; |
|
| 863 | + $action_id = ! empty($action_id) ? ' id="'.esc_attr($action_id).'"' : ''; |
|
| 864 | + $open_tag = ! empty($action_container) ? '<'.$action_container.$action_class.$action_id.'>' : ''; |
|
| 865 | + $close_tag = ! empty($action_container) ? '</'.$action_container.'>' : ''; |
|
| 866 | 866 | try { |
| 867 | 867 | $content = apply_filters( |
| 868 | 868 | 'FHEE__EE_Admin_List_Table___action_string__action_items', |
@@ -900,10 +900,10 @@ discard block |
||
| 900 | 900 | */ |
| 901 | 901 | protected function columnContent($id, $content, $align = 'start') |
| 902 | 902 | { |
| 903 | - if (! isset($this->_columns[ $id ])) { |
|
| 903 | + if ( ! isset($this->_columns[$id])) { |
|
| 904 | 904 | throw new DomainException('missing column id'); |
| 905 | 905 | } |
| 906 | - $heading = $id !== 'cb' ? $this->_columns[ $id ] : ''; |
|
| 906 | + $heading = $id !== 'cb' ? $this->_columns[$id] : ''; |
|
| 907 | 907 | $align = in_array($align, ['start', 'center', 'end']) ? $align : 'start'; |
| 908 | 908 | $align = "ee-responsive-table-cell--{$align}"; |
| 909 | 909 | |
@@ -920,13 +920,13 @@ discard block |
||
| 920 | 920 | return ' |
| 921 | 921 | <div class="ee-modal-menu"> |
| 922 | 922 | <button class="ee-modal-menu__button button button--small button--icon-only ee-aria-tooltip" |
| 923 | - aria-label="' . esc_attr__('list table actions menu', 'event_espresso') . '" |
|
| 923 | + aria-label="' . esc_attr__('list table actions menu', 'event_espresso').'" |
|
| 924 | 924 | > |
| 925 | 925 | <span class="dashicons dashicons-menu"></span> |
| 926 | 926 | </button> |
| 927 | 927 | <div class="ee-modal-menu__content ee-admin-container"> |
| 928 | 928 | <span class="ee-modal-menu__close dashicons dashicons-no"></span> |
| 929 | - ' . $actions . ' |
|
| 929 | + ' . $actions.' |
|
| 930 | 930 | </div> |
| 931 | 931 | </div>'; |
| 932 | 932 | } |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | return ' |
| 938 | 938 | <span class="ee-actions-column-header-wrap"> |
| 939 | 939 | <span class="dashicons dashicons-screenoptions"></span> |
| 940 | - <span class="ee-actions-column-header">' . esc_html__('Actions', 'event_espresso') . '</span> |
|
| 940 | + <span class="ee-actions-column-header">' . esc_html__('Actions', 'event_espresso').'</span> |
|
| 941 | 941 | </span>'; |
| 942 | 942 | } |
| 943 | 943 | } |
@@ -16,2915 +16,2915 @@ |
||
| 16 | 16 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This will hold the event object for event_details screen. |
|
| 19 | + /** |
|
| 20 | + * This will hold the event object for event_details screen. |
|
| 21 | + * |
|
| 22 | + * @var EE_Event $_event |
|
| 23 | + */ |
|
| 24 | + protected $_event; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * This will hold the category object for category_details screen. |
|
| 29 | + * |
|
| 30 | + * @var stdClass $_category |
|
| 31 | + */ |
|
| 32 | + protected $_category; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * This will hold the event model instance |
|
| 37 | + * |
|
| 38 | + * @var EEM_Event $_event_model |
|
| 39 | + */ |
|
| 40 | + protected $_event_model; |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Event |
|
| 45 | + */ |
|
| 46 | + protected $_cpt_model_obj = false; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var NodeGroupDao |
|
| 51 | + */ |
|
| 52 | + protected $model_obj_node_group_persister; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Initialize page props for this admin page group. |
|
| 57 | + */ |
|
| 58 | + protected function _init_page_props() |
|
| 59 | + { |
|
| 60 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 61 | + $this->page_label = EVENTS_LABEL; |
|
| 62 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 63 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 64 | + $this->_cpt_model_names = [ |
|
| 65 | + 'create_new' => 'EEM_Event', |
|
| 66 | + 'edit' => 'EEM_Event', |
|
| 67 | + ]; |
|
| 68 | + $this->_cpt_edit_routes = [ |
|
| 69 | + 'espresso_events' => 'edit', |
|
| 70 | + ]; |
|
| 71 | + add_action( |
|
| 72 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 73 | + [$this, 'verify_event_edit'], |
|
| 74 | + 10, |
|
| 75 | + 2 |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Sets the ajax hooks used for this admin page group. |
|
| 82 | + */ |
|
| 83 | + protected function _ajax_hooks() |
|
| 84 | + { |
|
| 85 | + add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Sets the page properties for this admin page group. |
|
| 91 | + */ |
|
| 92 | + protected function _define_page_props() |
|
| 93 | + { |
|
| 94 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 95 | + $this->_labels = [ |
|
| 96 | + 'buttons' => [ |
|
| 97 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 98 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 99 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 100 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 101 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 102 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 103 | + ], |
|
| 104 | + 'editor_title' => [ |
|
| 105 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 106 | + ], |
|
| 107 | + 'publishbox' => [ |
|
| 108 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 109 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 110 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 111 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 112 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 113 | + ], |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Sets the page routes property for this admin page group. |
|
| 120 | + */ |
|
| 121 | + protected function _set_page_routes() |
|
| 122 | + { |
|
| 123 | + // load formatter helper |
|
| 124 | + // load field generator helper |
|
| 125 | + // is there a evt_id in the request? |
|
| 126 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 127 | + $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
| 128 | + |
|
| 129 | + $this->_page_routes = [ |
|
| 130 | + 'default' => [ |
|
| 131 | + 'func' => '_events_overview_list_table', |
|
| 132 | + 'capability' => 'ee_read_events', |
|
| 133 | + ], |
|
| 134 | + 'create_new' => [ |
|
| 135 | + 'func' => '_create_new_cpt_item', |
|
| 136 | + 'capability' => 'ee_edit_events', |
|
| 137 | + ], |
|
| 138 | + 'edit' => [ |
|
| 139 | + 'func' => '_edit_cpt_item', |
|
| 140 | + 'capability' => 'ee_edit_event', |
|
| 141 | + 'obj_id' => $EVT_ID, |
|
| 142 | + ], |
|
| 143 | + 'copy_event' => [ |
|
| 144 | + 'func' => '_copy_events', |
|
| 145 | + 'capability' => 'ee_edit_event', |
|
| 146 | + 'obj_id' => $EVT_ID, |
|
| 147 | + 'noheader' => true, |
|
| 148 | + ], |
|
| 149 | + 'trash_event' => [ |
|
| 150 | + 'func' => '_trash_or_restore_event', |
|
| 151 | + 'args' => ['event_status' => 'trash'], |
|
| 152 | + 'capability' => 'ee_delete_event', |
|
| 153 | + 'obj_id' => $EVT_ID, |
|
| 154 | + 'noheader' => true, |
|
| 155 | + ], |
|
| 156 | + 'trash_events' => [ |
|
| 157 | + 'func' => '_trash_or_restore_events', |
|
| 158 | + 'args' => ['event_status' => 'trash'], |
|
| 159 | + 'capability' => 'ee_delete_events', |
|
| 160 | + 'noheader' => true, |
|
| 161 | + ], |
|
| 162 | + 'restore_event' => [ |
|
| 163 | + 'func' => '_trash_or_restore_event', |
|
| 164 | + 'args' => ['event_status' => 'draft'], |
|
| 165 | + 'capability' => 'ee_delete_event', |
|
| 166 | + 'obj_id' => $EVT_ID, |
|
| 167 | + 'noheader' => true, |
|
| 168 | + ], |
|
| 169 | + 'restore_events' => [ |
|
| 170 | + 'func' => '_trash_or_restore_events', |
|
| 171 | + 'args' => ['event_status' => 'draft'], |
|
| 172 | + 'capability' => 'ee_delete_events', |
|
| 173 | + 'noheader' => true, |
|
| 174 | + ], |
|
| 175 | + 'delete_event' => [ |
|
| 176 | + 'func' => '_delete_event', |
|
| 177 | + 'capability' => 'ee_delete_event', |
|
| 178 | + 'obj_id' => $EVT_ID, |
|
| 179 | + 'noheader' => true, |
|
| 180 | + ], |
|
| 181 | + 'delete_events' => [ |
|
| 182 | + 'func' => '_delete_events', |
|
| 183 | + 'capability' => 'ee_delete_events', |
|
| 184 | + 'noheader' => true, |
|
| 185 | + ], |
|
| 186 | + 'view_report' => [ |
|
| 187 | + 'func' => '_view_report', |
|
| 188 | + 'capability' => 'ee_edit_events', |
|
| 189 | + ], |
|
| 190 | + 'default_event_settings' => [ |
|
| 191 | + 'func' => '_default_event_settings', |
|
| 192 | + 'capability' => 'manage_options', |
|
| 193 | + ], |
|
| 194 | + 'update_default_event_settings' => [ |
|
| 195 | + 'func' => '_update_default_event_settings', |
|
| 196 | + 'capability' => 'manage_options', |
|
| 197 | + 'noheader' => true, |
|
| 198 | + ], |
|
| 199 | + 'template_settings' => [ |
|
| 200 | + 'func' => '_template_settings', |
|
| 201 | + 'capability' => 'manage_options', |
|
| 202 | + ], |
|
| 203 | + // event category tab related |
|
| 204 | + 'add_category' => [ |
|
| 205 | + 'func' => '_category_details', |
|
| 206 | + 'capability' => 'ee_edit_event_category', |
|
| 207 | + 'args' => ['add'], |
|
| 208 | + ], |
|
| 209 | + 'edit_category' => [ |
|
| 210 | + 'func' => '_category_details', |
|
| 211 | + 'capability' => 'ee_edit_event_category', |
|
| 212 | + 'args' => ['edit'], |
|
| 213 | + ], |
|
| 214 | + 'delete_categories' => [ |
|
| 215 | + 'func' => '_delete_categories', |
|
| 216 | + 'capability' => 'ee_delete_event_category', |
|
| 217 | + 'noheader' => true, |
|
| 218 | + ], |
|
| 219 | + 'delete_category' => [ |
|
| 220 | + 'func' => '_delete_categories', |
|
| 221 | + 'capability' => 'ee_delete_event_category', |
|
| 222 | + 'noheader' => true, |
|
| 223 | + ], |
|
| 224 | + 'insert_category' => [ |
|
| 225 | + 'func' => '_insert_or_update_category', |
|
| 226 | + 'args' => ['new_category' => true], |
|
| 227 | + 'capability' => 'ee_edit_event_category', |
|
| 228 | + 'noheader' => true, |
|
| 229 | + ], |
|
| 230 | + 'update_category' => [ |
|
| 231 | + 'func' => '_insert_or_update_category', |
|
| 232 | + 'args' => ['new_category' => false], |
|
| 233 | + 'capability' => 'ee_edit_event_category', |
|
| 234 | + 'noheader' => true, |
|
| 235 | + ], |
|
| 236 | + 'category_list' => [ |
|
| 237 | + 'func' => '_category_list_table', |
|
| 238 | + 'capability' => 'ee_manage_event_categories', |
|
| 239 | + ], |
|
| 240 | + 'preview_deletion' => [ |
|
| 241 | + 'func' => 'previewDeletion', |
|
| 242 | + 'capability' => 'ee_delete_events', |
|
| 243 | + ], |
|
| 244 | + 'confirm_deletion' => [ |
|
| 245 | + 'func' => 'confirmDeletion', |
|
| 246 | + 'capability' => 'ee_delete_events', |
|
| 247 | + 'noheader' => true, |
|
| 248 | + ], |
|
| 249 | + ]; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Set the _page_config property for this admin page group. |
|
| 255 | + */ |
|
| 256 | + protected function _set_page_config() |
|
| 257 | + { |
|
| 258 | + $post_id = $this->request->getRequestParam('post', 0, 'int'); |
|
| 259 | + $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 260 | + $this->_page_config = [ |
|
| 261 | + 'default' => [ |
|
| 262 | + 'nav' => [ |
|
| 263 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 264 | + 'order' => 10, |
|
| 265 | + ], |
|
| 266 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 267 | + 'help_tabs' => [ |
|
| 268 | + 'events_overview_help_tab' => [ |
|
| 269 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 270 | + 'filename' => 'events_overview', |
|
| 271 | + ], |
|
| 272 | + 'events_overview_table_column_headings_help_tab' => [ |
|
| 273 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 274 | + 'filename' => 'events_overview_table_column_headings', |
|
| 275 | + ], |
|
| 276 | + 'events_overview_filters_help_tab' => [ |
|
| 277 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 278 | + 'filename' => 'events_overview_filters', |
|
| 279 | + ], |
|
| 280 | + 'events_overview_view_help_tab' => [ |
|
| 281 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 282 | + 'filename' => 'events_overview_views', |
|
| 283 | + ], |
|
| 284 | + 'events_overview_other_help_tab' => [ |
|
| 285 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 286 | + 'filename' => 'events_overview_other', |
|
| 287 | + ], |
|
| 288 | + ], |
|
| 289 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 290 | + // 'help_tour' => [ |
|
| 291 | + // 'Event_Overview_Help_Tour', |
|
| 292 | + // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 293 | + // ], |
|
| 294 | + 'qtips' => ['EE_Event_List_Table_Tips'], |
|
| 295 | + 'require_nonce' => false, |
|
| 296 | + ], |
|
| 297 | + 'create_new' => [ |
|
| 298 | + 'nav' => [ |
|
| 299 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 300 | + 'order' => 5, |
|
| 301 | + 'persistent' => false, |
|
| 302 | + ], |
|
| 303 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 304 | + 'help_tabs' => [ |
|
| 305 | + 'event_editor_help_tab' => [ |
|
| 306 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 307 | + 'filename' => 'event_editor', |
|
| 308 | + ], |
|
| 309 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 310 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 311 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 312 | + ], |
|
| 313 | + 'event_editor_venue_details_help_tab' => [ |
|
| 314 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 315 | + 'filename' => 'event_editor_venue_details', |
|
| 316 | + ], |
|
| 317 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 318 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 319 | + 'filename' => 'event_editor_event_datetimes', |
|
| 320 | + ], |
|
| 321 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 322 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 323 | + 'filename' => 'event_editor_event_tickets', |
|
| 324 | + ], |
|
| 325 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 326 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 327 | + 'filename' => 'event_editor_event_registration_options', |
|
| 328 | + ], |
|
| 329 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 330 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 331 | + 'filename' => 'event_editor_tags_categories', |
|
| 332 | + ], |
|
| 333 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 334 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 335 | + 'filename' => 'event_editor_questions_registrants', |
|
| 336 | + ], |
|
| 337 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 338 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 339 | + 'filename' => 'event_editor_save_new_event', |
|
| 340 | + ], |
|
| 341 | + 'event_editor_other_help_tab' => [ |
|
| 342 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 343 | + 'filename' => 'event_editor_other', |
|
| 344 | + ], |
|
| 345 | + ], |
|
| 346 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 347 | + // 'help_tour' => [ |
|
| 348 | + // 'Event_Editor_Help_Tour', |
|
| 349 | + // ], |
|
| 350 | + 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 351 | + 'require_nonce' => false, |
|
| 352 | + ], |
|
| 353 | + 'edit' => [ |
|
| 354 | + 'nav' => [ |
|
| 355 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 356 | + 'order' => 5, |
|
| 357 | + 'persistent' => false, |
|
| 358 | + 'url' => $post_id |
|
| 359 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 360 | + ['post' => $post_id, 'action' => 'edit'], |
|
| 361 | + $this->_current_page_view_url |
|
| 362 | + ) |
|
| 363 | + : $this->_admin_base_url, |
|
| 364 | + ], |
|
| 365 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 366 | + 'help_tabs' => [ |
|
| 367 | + 'event_editor_help_tab' => [ |
|
| 368 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 369 | + 'filename' => 'event_editor', |
|
| 370 | + ], |
|
| 371 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 372 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 373 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 374 | + ], |
|
| 375 | + 'event_editor_venue_details_help_tab' => [ |
|
| 376 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 377 | + 'filename' => 'event_editor_venue_details', |
|
| 378 | + ], |
|
| 379 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 380 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 381 | + 'filename' => 'event_editor_event_datetimes', |
|
| 382 | + ], |
|
| 383 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 384 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 385 | + 'filename' => 'event_editor_event_tickets', |
|
| 386 | + ], |
|
| 387 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 388 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 389 | + 'filename' => 'event_editor_event_registration_options', |
|
| 390 | + ], |
|
| 391 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 392 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 393 | + 'filename' => 'event_editor_tags_categories', |
|
| 394 | + ], |
|
| 395 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 396 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 397 | + 'filename' => 'event_editor_questions_registrants', |
|
| 398 | + ], |
|
| 399 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 400 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 401 | + 'filename' => 'event_editor_save_new_event', |
|
| 402 | + ], |
|
| 403 | + 'event_editor_other_help_tab' => [ |
|
| 404 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 405 | + 'filename' => 'event_editor_other', |
|
| 406 | + ], |
|
| 407 | + ], |
|
| 408 | + 'require_nonce' => false, |
|
| 409 | + ], |
|
| 410 | + 'default_event_settings' => [ |
|
| 411 | + 'nav' => [ |
|
| 412 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 413 | + 'order' => 40, |
|
| 414 | + ], |
|
| 415 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 416 | + 'labels' => [ |
|
| 417 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 418 | + ], |
|
| 419 | + 'help_tabs' => [ |
|
| 420 | + 'default_settings_help_tab' => [ |
|
| 421 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 422 | + 'filename' => 'events_default_settings', |
|
| 423 | + ], |
|
| 424 | + 'default_settings_status_help_tab' => [ |
|
| 425 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 426 | + 'filename' => 'events_default_settings_status', |
|
| 427 | + ], |
|
| 428 | + 'default_maximum_tickets_help_tab' => [ |
|
| 429 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 430 | + 'filename' => 'events_default_settings_max_tickets', |
|
| 431 | + ], |
|
| 432 | + ], |
|
| 433 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 434 | + // 'help_tour' => ['Event_Default_Settings_Help_Tour'], |
|
| 435 | + 'require_nonce' => false, |
|
| 436 | + ], |
|
| 437 | + // template settings |
|
| 438 | + 'template_settings' => [ |
|
| 439 | + 'nav' => [ |
|
| 440 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 441 | + 'order' => 30, |
|
| 442 | + ], |
|
| 443 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 444 | + 'help_tabs' => [ |
|
| 445 | + 'general_settings_templates_help_tab' => [ |
|
| 446 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 447 | + 'filename' => 'general_settings_templates', |
|
| 448 | + ], |
|
| 449 | + ], |
|
| 450 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 451 | + // 'help_tour' => ['Templates_Help_Tour'], |
|
| 452 | + 'require_nonce' => false, |
|
| 453 | + ], |
|
| 454 | + // event category stuff |
|
| 455 | + 'add_category' => [ |
|
| 456 | + 'nav' => [ |
|
| 457 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 458 | + 'order' => 15, |
|
| 459 | + 'persistent' => false, |
|
| 460 | + ], |
|
| 461 | + 'help_tabs' => [ |
|
| 462 | + 'add_category_help_tab' => [ |
|
| 463 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 464 | + 'filename' => 'events_add_category', |
|
| 465 | + ], |
|
| 466 | + ], |
|
| 467 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 468 | + // 'help_tour' => ['Event_Add_Category_Help_Tour'], |
|
| 469 | + 'metaboxes' => ['_publish_post_box'], |
|
| 470 | + 'require_nonce' => false, |
|
| 471 | + ], |
|
| 472 | + 'edit_category' => [ |
|
| 473 | + 'nav' => [ |
|
| 474 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 475 | + 'order' => 15, |
|
| 476 | + 'persistent' => false, |
|
| 477 | + 'url' => $EVT_CAT_ID |
|
| 478 | + ? add_query_arg( |
|
| 479 | + ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
| 480 | + $this->_current_page_view_url |
|
| 481 | + ) |
|
| 482 | + : $this->_admin_base_url, |
|
| 483 | + ], |
|
| 484 | + 'help_tabs' => [ |
|
| 485 | + 'edit_category_help_tab' => [ |
|
| 486 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 487 | + 'filename' => 'events_edit_category', |
|
| 488 | + ], |
|
| 489 | + ], |
|
| 490 | + /*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/ |
|
| 491 | + 'metaboxes' => ['_publish_post_box'], |
|
| 492 | + 'require_nonce' => false, |
|
| 493 | + ], |
|
| 494 | + 'category_list' => [ |
|
| 495 | + 'nav' => [ |
|
| 496 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 497 | + 'order' => 20, |
|
| 498 | + ], |
|
| 499 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 500 | + 'help_tabs' => [ |
|
| 501 | + 'events_categories_help_tab' => [ |
|
| 502 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 503 | + 'filename' => 'events_categories', |
|
| 504 | + ], |
|
| 505 | + 'events_categories_table_column_headings_help_tab' => [ |
|
| 506 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 507 | + 'filename' => 'events_categories_table_column_headings', |
|
| 508 | + ], |
|
| 509 | + 'events_categories_view_help_tab' => [ |
|
| 510 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 511 | + 'filename' => 'events_categories_views', |
|
| 512 | + ], |
|
| 513 | + 'events_categories_other_help_tab' => [ |
|
| 514 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 515 | + 'filename' => 'events_categories_other', |
|
| 516 | + ], |
|
| 517 | + ], |
|
| 518 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 519 | + // 'help_tour' => [ |
|
| 520 | + // 'Event_Categories_Help_Tour', |
|
| 521 | + // ], |
|
| 522 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 523 | + 'require_nonce' => false, |
|
| 524 | + ], |
|
| 525 | + 'preview_deletion' => [ |
|
| 526 | + 'nav' => [ |
|
| 527 | + 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 528 | + 'order' => 15, |
|
| 529 | + 'persistent' => false, |
|
| 530 | + 'url' => '', |
|
| 531 | + ], |
|
| 532 | + 'require_nonce' => false, |
|
| 533 | + ], |
|
| 534 | + ]; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 540 | + */ |
|
| 541 | + protected function _add_screen_options() |
|
| 542 | + { |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Implementing the screen options for the 'default' route. |
|
| 548 | + * |
|
| 549 | + * @throws InvalidArgumentException |
|
| 550 | + * @throws InvalidDataTypeException |
|
| 551 | + * @throws InvalidInterfaceException |
|
| 552 | + */ |
|
| 553 | + protected function _add_screen_options_default() |
|
| 554 | + { |
|
| 555 | + $this->_per_page_screen_option(); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Implementing screen options for the category list route. |
|
| 561 | + * |
|
| 562 | + * @throws InvalidArgumentException |
|
| 563 | + * @throws InvalidDataTypeException |
|
| 564 | + * @throws InvalidInterfaceException |
|
| 565 | + */ |
|
| 566 | + protected function _add_screen_options_category_list() |
|
| 567 | + { |
|
| 568 | + $page_title = $this->_admin_page_title; |
|
| 569 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 570 | + $this->_per_page_screen_option(); |
|
| 571 | + $this->_admin_page_title = $page_title; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Used to register any global feature pointers for the admin page group. |
|
| 577 | + */ |
|
| 578 | + protected function _add_feature_pointers() |
|
| 579 | + { |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 585 | + */ |
|
| 586 | + public function load_scripts_styles() |
|
| 587 | + { |
|
| 588 | + wp_register_style( |
|
| 589 | + 'events-admin-css', |
|
| 590 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 591 | + [], |
|
| 592 | + EVENT_ESPRESSO_VERSION |
|
| 593 | + ); |
|
| 594 | + wp_register_style( |
|
| 595 | + 'ee-cat-admin', |
|
| 596 | + EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 597 | + [], |
|
| 598 | + EVENT_ESPRESSO_VERSION |
|
| 599 | + ); |
|
| 600 | + wp_enqueue_style('events-admin-css'); |
|
| 601 | + wp_enqueue_style('ee-cat-admin'); |
|
| 602 | + // scripts |
|
| 603 | + wp_register_script( |
|
| 604 | + 'event_editor_js', |
|
| 605 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 606 | + ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 607 | + EVENT_ESPRESSO_VERSION, |
|
| 608 | + true |
|
| 609 | + ); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Enqueuing scripts and styles specific to this view |
|
| 615 | + */ |
|
| 616 | + public function load_scripts_styles_create_new() |
|
| 617 | + { |
|
| 618 | + $this->load_scripts_styles_edit(); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * Enqueuing scripts and styles specific to this view |
|
| 624 | + */ |
|
| 625 | + public function load_scripts_styles_edit() |
|
| 626 | + { |
|
| 627 | + // styles |
|
| 628 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 629 | + wp_register_style( |
|
| 630 | + 'event-editor-css', |
|
| 631 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 632 | + ['ee-admin-css'], |
|
| 633 | + EVENT_ESPRESSO_VERSION |
|
| 634 | + ); |
|
| 635 | + wp_enqueue_style('event-editor-css'); |
|
| 636 | + // scripts |
|
| 637 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
| 638 | + wp_register_script( |
|
| 639 | + 'event-datetime-metabox', |
|
| 640 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 641 | + ['event_editor_js', 'ee-datepicker'], |
|
| 642 | + EVENT_ESPRESSO_VERSION |
|
| 643 | + ); |
|
| 644 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * Populating the _views property for the category list table view. |
|
| 651 | + */ |
|
| 652 | + protected function _set_list_table_views_category_list() |
|
| 653 | + { |
|
| 654 | + $this->_views = [ |
|
| 655 | + 'all' => [ |
|
| 656 | + 'slug' => 'all', |
|
| 657 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 658 | + 'count' => 0, |
|
| 659 | + 'bulk_action' => [ |
|
| 660 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 661 | + ], |
|
| 662 | + ], |
|
| 663 | + ]; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 669 | + */ |
|
| 670 | + public function admin_init() |
|
| 671 | + { |
|
| 672 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 673 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 674 | + 'event_espresso' |
|
| 675 | + ); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 681 | + * group. |
|
| 682 | + */ |
|
| 683 | + public function admin_notices() |
|
| 684 | + { |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 690 | + * this admin page group. |
|
| 691 | + */ |
|
| 692 | + public function admin_footer_scripts() |
|
| 693 | + { |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 699 | + * warning (via EE_Error::add_error()); |
|
| 700 | + * |
|
| 701 | + * @param EE_Event $event Event object |
|
| 702 | + * @param string $req_type |
|
| 703 | + * @return void |
|
| 704 | + * @throws EE_Error |
|
| 705 | + * @throws ReflectionException |
|
| 706 | + */ |
|
| 707 | + public function verify_event_edit($event = null, $req_type = '') |
|
| 708 | + { |
|
| 709 | + // don't need to do this when processing |
|
| 710 | + if (! empty($req_type)) { |
|
| 711 | + return; |
|
| 712 | + } |
|
| 713 | + // no event? |
|
| 714 | + if (! $event instanceof EE_Event) { |
|
| 715 | + $event = $this->_cpt_model_obj; |
|
| 716 | + } |
|
| 717 | + // STILL no event? |
|
| 718 | + if (! $event instanceof EE_Event) { |
|
| 719 | + return; |
|
| 720 | + } |
|
| 721 | + $orig_status = $event->status(); |
|
| 722 | + // first check if event is active. |
|
| 723 | + if ( |
|
| 724 | + $orig_status === EEM_Event::cancelled |
|
| 725 | + || $orig_status === EEM_Event::postponed |
|
| 726 | + || $event->is_expired() |
|
| 727 | + || $event->is_inactive() |
|
| 728 | + ) { |
|
| 729 | + return; |
|
| 730 | + } |
|
| 731 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
| 732 | + if ($event->is_sold_out(true)) { |
|
| 733 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 734 | + EE_Error::add_attention( |
|
| 735 | + sprintf( |
|
| 736 | + esc_html__( |
|
| 737 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 738 | + 'event_espresso' |
|
| 739 | + ), |
|
| 740 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 741 | + ) |
|
| 742 | + ); |
|
| 743 | + } |
|
| 744 | + return; |
|
| 745 | + } |
|
| 746 | + if ($orig_status === EEM_Event::sold_out) { |
|
| 747 | + EE_Error::add_attention( |
|
| 748 | + sprintf( |
|
| 749 | + esc_html__( |
|
| 750 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 751 | + 'event_espresso' |
|
| 752 | + ), |
|
| 753 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 754 | + ) |
|
| 755 | + ); |
|
| 756 | + } |
|
| 757 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 758 | + if (! $event->tickets_on_sale()) { |
|
| 759 | + return; |
|
| 760 | + } |
|
| 761 | + // made it here so show warning |
|
| 762 | + $this->_edit_event_warning(); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 768 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 769 | + * |
|
| 770 | + * @access protected |
|
| 771 | + * @return void |
|
| 772 | + */ |
|
| 773 | + protected function _edit_event_warning() |
|
| 774 | + { |
|
| 775 | + // we don't want to add warnings during these requests |
|
| 776 | + if ($this->request->getRequestParam('action') === 'editpost') { |
|
| 777 | + return; |
|
| 778 | + } |
|
| 779 | + EE_Error::add_attention( |
|
| 780 | + sprintf( |
|
| 781 | + esc_html__( |
|
| 782 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 783 | + 'event_espresso' |
|
| 784 | + ), |
|
| 785 | + '<a class="espresso-help-tab-lnk">', |
|
| 786 | + '</a>' |
|
| 787 | + ) |
|
| 788 | + ); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 794 | + * Otherwise, do the normal logic |
|
| 795 | + * |
|
| 796 | + * @return void |
|
| 797 | + * @throws EE_Error |
|
| 798 | + * @throws InvalidArgumentException |
|
| 799 | + * @throws InvalidDataTypeException |
|
| 800 | + * @throws InvalidInterfaceException |
|
| 801 | + */ |
|
| 802 | + protected function _create_new_cpt_item() |
|
| 803 | + { |
|
| 804 | + $has_timezone_string = get_option('timezone_string'); |
|
| 805 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 806 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 807 | + EE_Error::add_attention( |
|
| 808 | + sprintf( |
|
| 809 | + esc_html__( |
|
| 810 | + 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
| 811 | + 'event_espresso' |
|
| 812 | + ), |
|
| 813 | + '<br>', |
|
| 814 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 815 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 816 | + . '</select>', |
|
| 817 | + '<button class="button button--secondary timezone-submit">', |
|
| 818 | + '</button><span class="spinner"></span>' |
|
| 819 | + ), |
|
| 820 | + __FILE__, |
|
| 821 | + __FUNCTION__, |
|
| 822 | + __LINE__ |
|
| 823 | + ); |
|
| 824 | + } |
|
| 825 | + parent::_create_new_cpt_item(); |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * Sets the _views property for the default route in this admin page group. |
|
| 831 | + */ |
|
| 832 | + protected function _set_list_table_views_default() |
|
| 833 | + { |
|
| 834 | + $this->_views = [ |
|
| 835 | + 'all' => [ |
|
| 836 | + 'slug' => 'all', |
|
| 837 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 838 | + 'count' => 0, |
|
| 839 | + 'bulk_action' => [ |
|
| 840 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 841 | + ], |
|
| 842 | + ], |
|
| 843 | + 'draft' => [ |
|
| 844 | + 'slug' => 'draft', |
|
| 845 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 846 | + 'count' => 0, |
|
| 847 | + 'bulk_action' => [ |
|
| 848 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 849 | + ], |
|
| 850 | + ], |
|
| 851 | + ]; |
|
| 852 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 853 | + $this->_views['trash'] = [ |
|
| 854 | + 'slug' => 'trash', |
|
| 855 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 856 | + 'count' => 0, |
|
| 857 | + 'bulk_action' => [ |
|
| 858 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 859 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 860 | + ], |
|
| 861 | + ]; |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * Provides the legend item array for the default list table view. |
|
| 868 | + * |
|
| 869 | + * @return array |
|
| 870 | + * @throws EE_Error |
|
| 871 | + * @throws EE_Error |
|
| 872 | + */ |
|
| 873 | + protected function _event_legend_items() |
|
| 874 | + { |
|
| 875 | + $items = [ |
|
| 876 | + 'view_details' => [ |
|
| 877 | + 'class' => 'dashicons dashicons-search', |
|
| 878 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 879 | + ], |
|
| 880 | + 'edit_event' => [ |
|
| 881 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 882 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 883 | + ], |
|
| 884 | + 'view_attendees' => [ |
|
| 885 | + 'class' => 'dashicons dashicons-groups', |
|
| 886 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 887 | + ], |
|
| 888 | + ]; |
|
| 889 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 890 | + $statuses = [ |
|
| 891 | + 'sold_out_status' => [ |
|
| 892 | + 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::sold_out, |
|
| 893 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 894 | + ], |
|
| 895 | + 'active_status' => [ |
|
| 896 | + 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::active, |
|
| 897 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 898 | + ], |
|
| 899 | + 'upcoming_status' => [ |
|
| 900 | + 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::upcoming, |
|
| 901 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 902 | + ], |
|
| 903 | + 'postponed_status' => [ |
|
| 904 | + 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::postponed, |
|
| 905 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 906 | + ], |
|
| 907 | + 'cancelled_status' => [ |
|
| 908 | + 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::cancelled, |
|
| 909 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 910 | + ], |
|
| 911 | + 'expired_status' => [ |
|
| 912 | + 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::expired, |
|
| 913 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 914 | + ], |
|
| 915 | + 'inactive_status' => [ |
|
| 916 | + 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::inactive, |
|
| 917 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 918 | + ], |
|
| 919 | + ]; |
|
| 920 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 921 | + return array_merge($items, $statuses); |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * @return EEM_Event |
|
| 927 | + * @throws EE_Error |
|
| 928 | + * @throws InvalidArgumentException |
|
| 929 | + * @throws InvalidDataTypeException |
|
| 930 | + * @throws InvalidInterfaceException |
|
| 931 | + * @throws ReflectionException |
|
| 932 | + */ |
|
| 933 | + private function _event_model() |
|
| 934 | + { |
|
| 935 | + if (! $this->_event_model instanceof EEM_Event) { |
|
| 936 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 937 | + } |
|
| 938 | + return $this->_event_model; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 944 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 945 | + * |
|
| 946 | + * @param string $return the current html |
|
| 947 | + * @param int $id the post id for the page |
|
| 948 | + * @param string $new_title What the title is |
|
| 949 | + * @param string $new_slug what the slug is |
|
| 950 | + * @return string The new html string for the permalink area |
|
| 951 | + */ |
|
| 952 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 953 | + { |
|
| 954 | + // make sure this is only when editing |
|
| 955 | + if (! empty($id)) { |
|
| 956 | + $post = get_post($id); |
|
| 957 | + $return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 958 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 959 | + . '</a> '; |
|
| 960 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 961 | + . $post->ID |
|
| 962 | + . ']">'; |
|
| 963 | + } |
|
| 964 | + return $return; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + |
|
| 968 | + /** |
|
| 969 | + * _events_overview_list_table |
|
| 970 | + * This contains the logic for showing the events_overview list |
|
| 971 | + * |
|
| 972 | + * @access protected |
|
| 973 | + * @return void |
|
| 974 | + * @throws DomainException |
|
| 975 | + * @throws EE_Error |
|
| 976 | + * @throws InvalidArgumentException |
|
| 977 | + * @throws InvalidDataTypeException |
|
| 978 | + * @throws InvalidInterfaceException |
|
| 979 | + */ |
|
| 980 | + protected function _events_overview_list_table() |
|
| 981 | + { |
|
| 982 | + $after_list_table = []; |
|
| 983 | + $after_list_table['view_event_list_button'] = EEH_HTML::div( |
|
| 984 | + EEH_Template::get_button_or_link( |
|
| 985 | + get_post_type_archive_link('espresso_events'), |
|
| 986 | + esc_html__('View Event Archive Page', 'event_espresso'), |
|
| 987 | + 'button button--small button--secondary' |
|
| 988 | + ), |
|
| 989 | + '', |
|
| 990 | + 'ee-admin-button-row' |
|
| 991 | + ); |
|
| 992 | + |
|
| 993 | + $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 994 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 995 | + 'create_new', |
|
| 996 | + 'add', |
|
| 997 | + [], |
|
| 998 | + 'add-new-h2' |
|
| 999 | + ); |
|
| 1000 | + |
|
| 1001 | + $this->_template_args['after_list_table'] = array_merge( |
|
| 1002 | + (array) $this->_template_args['after_list_table'], |
|
| 1003 | + $after_list_table |
|
| 1004 | + ); |
|
| 1005 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + |
|
| 1009 | + /** |
|
| 1010 | + * this allows for extra misc actions in the default WP publish box |
|
| 1011 | + * |
|
| 1012 | + * @return void |
|
| 1013 | + * @throws DomainException |
|
| 1014 | + * @throws EE_Error |
|
| 1015 | + * @throws InvalidArgumentException |
|
| 1016 | + * @throws InvalidDataTypeException |
|
| 1017 | + * @throws InvalidInterfaceException |
|
| 1018 | + * @throws ReflectionException |
|
| 1019 | + */ |
|
| 1020 | + public function extra_misc_actions_publish_box() |
|
| 1021 | + { |
|
| 1022 | + $this->_generate_publish_box_extra_content(); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + |
|
| 1026 | + /** |
|
| 1027 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1028 | + * saved. |
|
| 1029 | + * Typically you would use this to save any additional data. |
|
| 1030 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1031 | + * ALSO very important. When a post transitions from scheduled to published, |
|
| 1032 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1033 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1034 | + * |
|
| 1035 | + * @access protected |
|
| 1036 | + * @abstract |
|
| 1037 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1038 | + * @param object $post The post object of the cpt that was saved. |
|
| 1039 | + * @return void |
|
| 1040 | + * @throws EE_Error |
|
| 1041 | + * @throws InvalidArgumentException |
|
| 1042 | + * @throws InvalidDataTypeException |
|
| 1043 | + * @throws InvalidInterfaceException |
|
| 1044 | + * @throws ReflectionException |
|
| 1045 | + */ |
|
| 1046 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 1047 | + { |
|
| 1048 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1049 | + // get out we're not processing an event save. |
|
| 1050 | + return; |
|
| 1051 | + } |
|
| 1052 | + $event_values = [ |
|
| 1053 | + 'EVT_member_only' => $this->request->getRequestParam('member_only', false, 'bool'), |
|
| 1054 | + 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'), |
|
| 1055 | + 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
| 1056 | + ]; |
|
| 1057 | + // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
| 1058 | + if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1059 | + $event_values['EVT_display_ticket_selector'] = $this->request->getRequestParam( |
|
| 1060 | + 'display_ticket_selector', |
|
| 1061 | + false, |
|
| 1062 | + 'bool' |
|
| 1063 | + ); |
|
| 1064 | + $event_values['EVT_additional_limit'] = min( |
|
| 1065 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1066 | + $this->request->getRequestParam('additional_limit', null, 'int') |
|
| 1067 | + ); |
|
| 1068 | + $event_values['EVT_default_registration_status'] = $this->request->getRequestParam( |
|
| 1069 | + 'EVT_default_registration_status', |
|
| 1070 | + EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 1071 | + ); |
|
| 1072 | + |
|
| 1073 | + $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL'); |
|
| 1074 | + $event_values['EVT_phone'] = $this->request->getRequestParam('event_phone'); |
|
| 1075 | + $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool'); |
|
| 1076 | + } |
|
| 1077 | + // update event |
|
| 1078 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1079 | + // get event_object for other metaboxes... |
|
| 1080 | + // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
| 1081 | + // i have to setup where conditions to override the filters in the model |
|
| 1082 | + // that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 1083 | + $event = $this->_event_model()->get_one( |
|
| 1084 | + [ |
|
| 1085 | + [ |
|
| 1086 | + $this->_event_model()->primary_key_name() => $post_id, |
|
| 1087 | + 'OR' => [ |
|
| 1088 | + 'status' => $post->post_status, |
|
| 1089 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1090 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1091 | + 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
| 1092 | + ], |
|
| 1093 | + ], |
|
| 1094 | + ] |
|
| 1095 | + ); |
|
| 1096 | + |
|
| 1097 | + // the following are default callbacks for event attachment updates |
|
| 1098 | + // that can be overridden by caffeinated functionality and/or addons. |
|
| 1099 | + $event_update_callbacks = []; |
|
| 1100 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
| 1101 | + $event_update_callbacks['_default_venue_update'] = [$this, '_default_venue_update']; |
|
| 1102 | + $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update']; |
|
| 1103 | + } |
|
| 1104 | + $event_update_callbacks = apply_filters( |
|
| 1105 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1106 | + $event_update_callbacks |
|
| 1107 | + ); |
|
| 1108 | + |
|
| 1109 | + $att_success = true; |
|
| 1110 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 1111 | + $_success = is_callable($e_callback) |
|
| 1112 | + ? $e_callback($event, $this->request->requestParams()) |
|
| 1113 | + : false; |
|
| 1114 | + // if ANY of these updates fail then we want the appropriate global error message |
|
| 1115 | + $att_success = $_success !== false ? $att_success : false; |
|
| 1116 | + } |
|
| 1117 | + // any errors? |
|
| 1118 | + if ($success && $att_success === false) { |
|
| 1119 | + EE_Error::add_error( |
|
| 1120 | + esc_html__( |
|
| 1121 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1122 | + 'event_espresso' |
|
| 1123 | + ), |
|
| 1124 | + __FILE__, |
|
| 1125 | + __FUNCTION__, |
|
| 1126 | + __LINE__ |
|
| 1127 | + ); |
|
| 1128 | + } elseif ($success === false) { |
|
| 1129 | + EE_Error::add_error( |
|
| 1130 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1131 | + __FILE__, |
|
| 1132 | + __FUNCTION__, |
|
| 1133 | + __LINE__ |
|
| 1134 | + ); |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + |
|
| 1139 | + /** |
|
| 1140 | + * @param int $post_id |
|
| 1141 | + * @param int $revision_id |
|
| 1142 | + * @throws EE_Error |
|
| 1143 | + * @throws EE_Error |
|
| 1144 | + * @throws ReflectionException |
|
| 1145 | + * @see parent::restore_item() |
|
| 1146 | + */ |
|
| 1147 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1148 | + { |
|
| 1149 | + // copy existing event meta to new post |
|
| 1150 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1151 | + if ($post_evt instanceof EE_Event) { |
|
| 1152 | + // meta revision restore |
|
| 1153 | + $post_evt->restore_revision($revision_id); |
|
| 1154 | + // related objs restore |
|
| 1155 | + $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1156 | + } |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + |
|
| 1160 | + /** |
|
| 1161 | + * Attach the venue to the Event |
|
| 1162 | + * |
|
| 1163 | + * @param EE_Event $event Event Object to add the venue to |
|
| 1164 | + * @param array $data The request data from the form |
|
| 1165 | + * @return bool Success or fail. |
|
| 1166 | + * @throws EE_Error |
|
| 1167 | + * @throws ReflectionException |
|
| 1168 | + */ |
|
| 1169 | + protected function _default_venue_update(EE_Event $event, $data) |
|
| 1170 | + { |
|
| 1171 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1172 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1173 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1174 | + // very important. If we don't have a venue name... |
|
| 1175 | + // then we'll get out because not necessary to create empty venue |
|
| 1176 | + if (empty($data['venue_title'])) { |
|
| 1177 | + return false; |
|
| 1178 | + } |
|
| 1179 | + $venue_array = [ |
|
| 1180 | + 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
| 1181 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1182 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1183 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1184 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
| 1185 | + ? $data['venue_short_description'] |
|
| 1186 | + : null, |
|
| 1187 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1188 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1189 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1190 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1191 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1192 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1193 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1194 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1195 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1196 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1197 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1198 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1199 | + 'status' => 'publish', |
|
| 1200 | + ]; |
|
| 1201 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1202 | + if (! empty($venue_id)) { |
|
| 1203 | + $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1204 | + $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1205 | + // we've gotta make sure that the venue is always attached to a revision.. |
|
| 1206 | + // add_relation_to should take care of making sure that the relation is already present. |
|
| 1207 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1208 | + return $rows_affected > 0; |
|
| 1209 | + } |
|
| 1210 | + // we insert the venue |
|
| 1211 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1212 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1213 | + return ! empty($venue_id); |
|
| 1214 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1220 | + * |
|
| 1221 | + * @param EE_Event $event The Event object we're attaching data to |
|
| 1222 | + * @param array $data The request data from the form |
|
| 1223 | + * @return array |
|
| 1224 | + * @throws EE_Error |
|
| 1225 | + * @throws ReflectionException |
|
| 1226 | + * @throws Exception |
|
| 1227 | + */ |
|
| 1228 | + protected function _default_tickets_update(EE_Event $event, $data) |
|
| 1229 | + { |
|
| 1230 | + if ($this->admin_config->useAdvancedEditor()) { |
|
| 1231 | + return []; |
|
| 1232 | + } |
|
| 1233 | + $datetime = null; |
|
| 1234 | + $saved_tickets = []; |
|
| 1235 | + $event_timezone = $event->get_timezone(); |
|
| 1236 | + $date_formats = ['Y-m-d', 'h:i a']; |
|
| 1237 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 1238 | + // trim all values to ensure any excess whitespace is removed. |
|
| 1239 | + $datetime_data = array_map('trim', $datetime_data); |
|
| 1240 | + $datetime_data['DTT_EVT_end'] = |
|
| 1241 | + isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
|
| 1242 | + ? $datetime_data['DTT_EVT_end'] |
|
| 1243 | + : $datetime_data['DTT_EVT_start']; |
|
| 1244 | + $datetime_values = [ |
|
| 1245 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
| 1246 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 1247 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 1248 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
| 1249 | + 'DTT_order' => $row, |
|
| 1250 | + ]; |
|
| 1251 | + // if we have an id then let's get existing object first and then set the new values. |
|
| 1252 | + // Otherwise we instantiate a new object for save. |
|
| 1253 | + if (! empty($datetime_data['DTT_ID'])) { |
|
| 1254 | + $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 1255 | + if (! $datetime instanceof EE_Ticket) { |
|
| 1256 | + throw new RuntimeException( |
|
| 1257 | + sprintf( |
|
| 1258 | + esc_html__( |
|
| 1259 | + 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1260 | + 'event_espresso' |
|
| 1261 | + ), |
|
| 1262 | + $datetime_data['DTT_ID'] |
|
| 1263 | + ) |
|
| 1264 | + ); |
|
| 1265 | + } |
|
| 1266 | + $datetime->set_date_format($date_formats[0]); |
|
| 1267 | + $datetime->set_time_format($date_formats[1]); |
|
| 1268 | + foreach ($datetime_values as $field => $value) { |
|
| 1269 | + $datetime->set($field, $value); |
|
| 1270 | + } |
|
| 1271 | + } else { |
|
| 1272 | + $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
| 1273 | + } |
|
| 1274 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1275 | + throw new RuntimeException( |
|
| 1276 | + sprintf( |
|
| 1277 | + esc_html__( |
|
| 1278 | + 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
| 1279 | + 'event_espresso' |
|
| 1280 | + ), |
|
| 1281 | + print_r($datetime_values, true) |
|
| 1282 | + ) |
|
| 1283 | + ); |
|
| 1284 | + } |
|
| 1285 | + // before going any further make sure our dates are setup correctly |
|
| 1286 | + // so that the end date is always equal or greater than the start date. |
|
| 1287 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 1288 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 1289 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 1290 | + } |
|
| 1291 | + $datetime->save(); |
|
| 1292 | + $event->_add_relation_to($datetime, 'Datetime'); |
|
| 1293 | + } |
|
| 1294 | + // no datetimes get deleted so we don't do any of that logic here. |
|
| 1295 | + // update tickets next |
|
| 1296 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1297 | + |
|
| 1298 | + // set up some default start and end dates in case those are not present in the incoming data |
|
| 1299 | + $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 1300 | + $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
| 1301 | + // use the start date of the first datetime for the end date |
|
| 1302 | + $first_datetime = $event->first_datetime(); |
|
| 1303 | + $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
| 1304 | + |
|
| 1305 | + // now process the incoming data |
|
| 1306 | + foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
| 1307 | + $update_prices = false; |
|
| 1308 | + $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1309 | + ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
| 1310 | + : 0; |
|
| 1311 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1312 | + $ticket_data = array_map('trim', $ticket_data); |
|
| 1313 | + $ticket_values = [ |
|
| 1314 | + 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
| 1315 | + 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
| 1316 | + 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
| 1317 | + 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
| 1318 | + 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
| 1319 | + ? $ticket_data['TKT_start_date'] |
|
| 1320 | + : $default_start_date, |
|
| 1321 | + 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
| 1322 | + ? $ticket_data['TKT_end_date'] |
|
| 1323 | + : $default_end_date, |
|
| 1324 | + 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
| 1325 | + || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
| 1326 | + ? $ticket_data['TKT_qty'] |
|
| 1327 | + : EE_INF, |
|
| 1328 | + 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
| 1329 | + || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
| 1330 | + ? $ticket_data['TKT_uses'] |
|
| 1331 | + : EE_INF, |
|
| 1332 | + 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
| 1333 | + 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
| 1334 | + 'TKT_order' => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row, |
|
| 1335 | + 'TKT_price' => $ticket_price, |
|
| 1336 | + 'TKT_row' => $row, |
|
| 1337 | + ]; |
|
| 1338 | + // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 1339 | + // which means in turn that the prices will become new prices as well. |
|
| 1340 | + if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
| 1341 | + $ticket_values['TKT_ID'] = 0; |
|
| 1342 | + $ticket_values['TKT_is_default'] = 0; |
|
| 1343 | + $update_prices = true; |
|
| 1344 | + } |
|
| 1345 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1346 | + // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
| 1347 | + // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
| 1348 | + // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
| 1349 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1350 | + if (! empty($ticket_data['TKT_ID'])) { |
|
| 1351 | + $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
| 1352 | + if (! $existing_ticket instanceof EE_Ticket) { |
|
| 1353 | + throw new RuntimeException( |
|
| 1354 | + sprintf( |
|
| 1355 | + esc_html__( |
|
| 1356 | + 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1357 | + 'event_espresso' |
|
| 1358 | + ), |
|
| 1359 | + $ticket_data['TKT_ID'] |
|
| 1360 | + ) |
|
| 1361 | + ); |
|
| 1362 | + } |
|
| 1363 | + $ticket_sold = $existing_ticket->count_related( |
|
| 1364 | + 'Registration', |
|
| 1365 | + [ |
|
| 1366 | + [ |
|
| 1367 | + 'STS_ID' => [ |
|
| 1368 | + 'NOT IN', |
|
| 1369 | + [EEM_Registration::status_id_incomplete], |
|
| 1370 | + ], |
|
| 1371 | + ], |
|
| 1372 | + ] |
|
| 1373 | + ) > 0; |
|
| 1374 | + // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
| 1375 | + // if they are different then we create a new ticket (if $ticket_sold) |
|
| 1376 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 1377 | + $create_new_ticket = $ticket_sold |
|
| 1378 | + && $ticket_price !== $existing_ticket->price() |
|
| 1379 | + && ! $existing_ticket->deleted(); |
|
| 1380 | + $existing_ticket->set_date_format($date_formats[0]); |
|
| 1381 | + $existing_ticket->set_time_format($date_formats[1]); |
|
| 1382 | + // set new values |
|
| 1383 | + foreach ($ticket_values as $field => $value) { |
|
| 1384 | + if ($field == 'TKT_qty') { |
|
| 1385 | + $existing_ticket->set_qty($value); |
|
| 1386 | + } elseif ($field == 'TKT_price') { |
|
| 1387 | + $existing_ticket->set('TKT_price', $ticket_price); |
|
| 1388 | + } else { |
|
| 1389 | + $existing_ticket->set($field, $value); |
|
| 1390 | + } |
|
| 1391 | + } |
|
| 1392 | + $ticket = $existing_ticket; |
|
| 1393 | + // if $create_new_ticket is false then we can safely update the existing ticket. |
|
| 1394 | + // Otherwise we have to create a new ticket. |
|
| 1395 | + if ($create_new_ticket) { |
|
| 1396 | + // archive the old ticket first |
|
| 1397 | + $existing_ticket->set('TKT_deleted', 1); |
|
| 1398 | + $existing_ticket->save(); |
|
| 1399 | + // make sure this ticket is still recorded in our $saved_tickets |
|
| 1400 | + // so we don't run it through the regular trash routine. |
|
| 1401 | + $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
| 1402 | + // create new ticket that's a copy of the existing except, |
|
| 1403 | + // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
| 1404 | + $new_ticket = clone $existing_ticket; |
|
| 1405 | + $new_ticket->set('TKT_ID', 0); |
|
| 1406 | + $new_ticket->set('TKT_deleted', 0); |
|
| 1407 | + $new_ticket->set('TKT_sold', 0); |
|
| 1408 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1409 | + $update_prices = true; |
|
| 1410 | + $ticket = $new_ticket; |
|
| 1411 | + } |
|
| 1412 | + } else { |
|
| 1413 | + // no TKT_id so a new ticket |
|
| 1414 | + $ticket_values['TKT_price'] = $ticket_price; |
|
| 1415 | + $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
| 1416 | + $update_prices = true; |
|
| 1417 | + } |
|
| 1418 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1419 | + throw new RuntimeException( |
|
| 1420 | + sprintf( |
|
| 1421 | + esc_html__( |
|
| 1422 | + 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
| 1423 | + 'event_espresso' |
|
| 1424 | + ), |
|
| 1425 | + print_r($ticket_values, true) |
|
| 1426 | + ) |
|
| 1427 | + ); |
|
| 1428 | + } |
|
| 1429 | + // cap ticket qty by datetime reg limits |
|
| 1430 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 1431 | + // update ticket. |
|
| 1432 | + $ticket->save(); |
|
| 1433 | + // before going any further make sure our dates are setup correctly |
|
| 1434 | + // so that the end date is always equal or greater than the start date. |
|
| 1435 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 1436 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 1437 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 1438 | + $ticket->save(); |
|
| 1439 | + } |
|
| 1440 | + // initially let's add the ticket to the datetime |
|
| 1441 | + $datetime->_add_relation_to($ticket, 'Ticket'); |
|
| 1442 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 1443 | + // add prices to ticket |
|
| 1444 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices); |
|
| 1445 | + } |
|
| 1446 | + // however now we need to handle permanently deleting tickets via the ui. |
|
| 1447 | + // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
| 1448 | + // However, it does allow for deleting tickets that have no tickets sold, |
|
| 1449 | + // in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1450 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
| 1451 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1452 | + foreach ($tickets_removed as $id) { |
|
| 1453 | + $id = absint($id); |
|
| 1454 | + // get the ticket for this id |
|
| 1455 | + $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
| 1456 | + if (! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1457 | + continue; |
|
| 1458 | + } |
|
| 1459 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 1460 | + // (remember this process can ONLY kick off if there are NO tickets sold) |
|
| 1461 | + $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
| 1462 | + foreach ($related_datetimes as $related_datetime) { |
|
| 1463 | + $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
| 1464 | + } |
|
| 1465 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 1466 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1467 | + $ticket_to_remove->delete_related_permanently('Price'); |
|
| 1468 | + // finally let's delete this ticket |
|
| 1469 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1470 | + $ticket_to_remove->delete_permanently(); |
|
| 1471 | + } |
|
| 1472 | + return [$datetime, $saved_tickets]; |
|
| 1473 | + } |
|
| 1474 | + |
|
| 1475 | + |
|
| 1476 | + /** |
|
| 1477 | + * This attaches a list of given prices to a ticket. |
|
| 1478 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) |
|
| 1479 | + * because if there is a change in price information on a ticket, a new ticket is created anyways |
|
| 1480 | + * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket. |
|
| 1481 | + * |
|
| 1482 | + * @access private |
|
| 1483 | + * @param array $prices_data Array of prices from the form. |
|
| 1484 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1485 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1486 | + * @return void |
|
| 1487 | + * @throws EE_Error |
|
| 1488 | + * @throws ReflectionException |
|
| 1489 | + */ |
|
| 1490 | + private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false) |
|
| 1491 | + { |
|
| 1492 | + $timezone = $ticket->get_timezone(); |
|
| 1493 | + foreach ($prices_data as $row => $price_data) { |
|
| 1494 | + $price_values = [ |
|
| 1495 | + 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
| 1496 | + 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
| 1497 | + 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
| 1498 | + 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
| 1499 | + 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
| 1500 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1501 | + 'PRC_order' => $row, |
|
| 1502 | + ]; |
|
| 1503 | + if ($new_prices || empty($price_values['PRC_ID'])) { |
|
| 1504 | + $price_values['PRC_ID'] = 0; |
|
| 1505 | + $price = EE_Price::new_instance($price_values, $timezone); |
|
| 1506 | + } else { |
|
| 1507 | + $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
| 1508 | + // update this price with new values |
|
| 1509 | + foreach ($price_values as $field => $new_price) { |
|
| 1510 | + $price->set($field, $new_price); |
|
| 1511 | + } |
|
| 1512 | + } |
|
| 1513 | + if (! $price instanceof EE_Price) { |
|
| 1514 | + throw new RuntimeException( |
|
| 1515 | + sprintf( |
|
| 1516 | + esc_html__( |
|
| 1517 | + 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
| 1518 | + 'event_espresso' |
|
| 1519 | + ), |
|
| 1520 | + print_r($price_values, true) |
|
| 1521 | + ) |
|
| 1522 | + ); |
|
| 1523 | + } |
|
| 1524 | + $price->save(); |
|
| 1525 | + $ticket->_add_relation_to($price, 'Price'); |
|
| 1526 | + } |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * Add in our autosave ajax handlers |
|
| 1532 | + * |
|
| 1533 | + */ |
|
| 1534 | + protected function _ee_autosave_create_new() |
|
| 1535 | + { |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + |
|
| 1539 | + /** |
|
| 1540 | + * More autosave handlers. |
|
| 1541 | + */ |
|
| 1542 | + protected function _ee_autosave_edit() |
|
| 1543 | + { |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + |
|
| 1547 | + /** |
|
| 1548 | + * @throws EE_Error |
|
| 1549 | + * @throws ReflectionException |
|
| 1550 | + */ |
|
| 1551 | + private function _generate_publish_box_extra_content() |
|
| 1552 | + { |
|
| 1553 | + // load formatter helper |
|
| 1554 | + // args for getting related registrations |
|
| 1555 | + $approved_query_args = [ |
|
| 1556 | + [ |
|
| 1557 | + 'REG_deleted' => 0, |
|
| 1558 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1559 | + ], |
|
| 1560 | + ]; |
|
| 1561 | + $not_approved_query_args = [ |
|
| 1562 | + [ |
|
| 1563 | + 'REG_deleted' => 0, |
|
| 1564 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1565 | + ], |
|
| 1566 | + ]; |
|
| 1567 | + $pending_payment_query_args = [ |
|
| 1568 | + [ |
|
| 1569 | + 'REG_deleted' => 0, |
|
| 1570 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1571 | + ], |
|
| 1572 | + ]; |
|
| 1573 | + // publish box |
|
| 1574 | + $publish_box_extra_args = [ |
|
| 1575 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1576 | + [ |
|
| 1577 | + 'action' => 'default', |
|
| 1578 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1579 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1580 | + ], |
|
| 1581 | + REG_ADMIN_URL |
|
| 1582 | + ), |
|
| 1583 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1584 | + [ |
|
| 1585 | + 'action' => 'default', |
|
| 1586 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1587 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1588 | + ], |
|
| 1589 | + REG_ADMIN_URL |
|
| 1590 | + ), |
|
| 1591 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1592 | + [ |
|
| 1593 | + 'action' => 'default', |
|
| 1594 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1595 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1596 | + ], |
|
| 1597 | + REG_ADMIN_URL |
|
| 1598 | + ), |
|
| 1599 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1600 | + 'Registration', |
|
| 1601 | + $approved_query_args |
|
| 1602 | + ), |
|
| 1603 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1604 | + 'Registration', |
|
| 1605 | + $not_approved_query_args |
|
| 1606 | + ), |
|
| 1607 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1608 | + 'Registration', |
|
| 1609 | + $pending_payment_query_args |
|
| 1610 | + ), |
|
| 1611 | + 'misc_pub_section_class' => apply_filters( |
|
| 1612 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1613 | + 'misc-pub-section' |
|
| 1614 | + ), |
|
| 1615 | + ]; |
|
| 1616 | + ob_start(); |
|
| 1617 | + do_action( |
|
| 1618 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1619 | + $this->_cpt_model_obj |
|
| 1620 | + ); |
|
| 1621 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1622 | + // load template |
|
| 1623 | + EEH_Template::display_template( |
|
| 1624 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1625 | + $publish_box_extra_args |
|
| 1626 | + ); |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * @return EE_Event |
|
| 1632 | + */ |
|
| 1633 | + public function get_event_object() |
|
| 1634 | + { |
|
| 1635 | + return $this->_cpt_model_obj; |
|
| 1636 | + } |
|
| 1637 | + |
|
| 1638 | + |
|
| 1639 | + |
|
| 1640 | + |
|
| 1641 | + /** METABOXES * */ |
|
| 1642 | + /** |
|
| 1643 | + * _register_event_editor_meta_boxes |
|
| 1644 | + * add all metaboxes related to the event_editor |
|
| 1645 | + * |
|
| 1646 | + * @return void |
|
| 1647 | + * @throws EE_Error |
|
| 1648 | + * @throws ReflectionException |
|
| 1649 | + */ |
|
| 1650 | + protected function _register_event_editor_meta_boxes() |
|
| 1651 | + { |
|
| 1652 | + $this->verify_cpt_object(); |
|
| 1653 | + $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
| 1654 | + // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1655 | + if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1656 | + $this->addMetaBox( |
|
| 1657 | + 'espresso_event_editor_event_options', |
|
| 1658 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1659 | + [$this, 'registration_options_meta_box'], |
|
| 1660 | + $this->page_slug, |
|
| 1661 | + 'side' |
|
| 1662 | + ); |
|
| 1663 | + } |
|
| 1664 | + if (! $use_advanced_editor) { |
|
| 1665 | + $this->addMetaBox( |
|
| 1666 | + 'espresso_event_editor_tickets', |
|
| 1667 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1668 | + [$this, 'ticket_metabox'], |
|
| 1669 | + $this->page_slug, |
|
| 1670 | + 'normal', |
|
| 1671 | + 'high' |
|
| 1672 | + ); |
|
| 1673 | + } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1674 | + add_action( |
|
| 1675 | + 'add_meta_boxes_espresso_events', |
|
| 1676 | + function () { |
|
| 1677 | + global $current_screen; |
|
| 1678 | + remove_meta_box('authordiv', $current_screen, 'normal'); |
|
| 1679 | + }, |
|
| 1680 | + 99 |
|
| 1681 | + ); |
|
| 1682 | + } |
|
| 1683 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1684 | + // where a metabox has a related management page in the admin |
|
| 1685 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1686 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1687 | + } |
|
| 1688 | + |
|
| 1689 | + |
|
| 1690 | + /** |
|
| 1691 | + * @throws DomainException |
|
| 1692 | + * @throws EE_Error |
|
| 1693 | + * @throws ReflectionException |
|
| 1694 | + */ |
|
| 1695 | + public function ticket_metabox() |
|
| 1696 | + { |
|
| 1697 | + $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1698 | + // defaults for template args |
|
| 1699 | + $template_args = [ |
|
| 1700 | + 'existing_datetime_ids' => '', |
|
| 1701 | + 'event_datetime_help_link' => '', |
|
| 1702 | + 'ticket_options_help_link' => '', |
|
| 1703 | + 'time' => null, |
|
| 1704 | + 'ticket_rows' => '', |
|
| 1705 | + 'existing_ticket_ids' => '', |
|
| 1706 | + 'total_ticket_rows' => 1, |
|
| 1707 | + 'ticket_js_structure' => '', |
|
| 1708 | + 'trash_icon' => 'dashicons dashicons-lock', |
|
| 1709 | + 'disabled' => '', |
|
| 1710 | + ]; |
|
| 1711 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1712 | + /** |
|
| 1713 | + * 1. Start with retrieving Datetimes |
|
| 1714 | + * 2. Fore each datetime get related tickets |
|
| 1715 | + * 3. For each ticket get related prices |
|
| 1716 | + */ |
|
| 1717 | + /** @var EEM_Datetime $datetime_model */ |
|
| 1718 | + $datetime_model = EE_Registry::instance()->load_model('Datetime'); |
|
| 1719 | + /** @var EEM_Ticket $datetime_model */ |
|
| 1720 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1721 | + $times = $datetime_model->get_all_event_dates($event_id); |
|
| 1722 | + /** @type EE_Datetime $first_datetime */ |
|
| 1723 | + $first_datetime = reset($times); |
|
| 1724 | + // do we get related tickets? |
|
| 1725 | + if ( |
|
| 1726 | + $first_datetime instanceof EE_Datetime |
|
| 1727 | + && $first_datetime->ID() !== 0 |
|
| 1728 | + ) { |
|
| 1729 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1730 | + $template_args['time'] = $first_datetime; |
|
| 1731 | + $related_tickets = $first_datetime->tickets( |
|
| 1732 | + [ |
|
| 1733 | + ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1734 | + 'default_where_conditions' => 'none', |
|
| 1735 | + ] |
|
| 1736 | + ); |
|
| 1737 | + if (! empty($related_tickets)) { |
|
| 1738 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1739 | + $row = 0; |
|
| 1740 | + foreach ($related_tickets as $ticket) { |
|
| 1741 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1742 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1743 | + $row++; |
|
| 1744 | + } |
|
| 1745 | + } else { |
|
| 1746 | + $template_args['total_ticket_rows'] = 1; |
|
| 1747 | + /** @type EE_Ticket $ticket */ |
|
| 1748 | + $ticket = $ticket_model->create_default_object(); |
|
| 1749 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1750 | + } |
|
| 1751 | + } else { |
|
| 1752 | + $template_args['time'] = $times[0]; |
|
| 1753 | + /** @type EE_Ticket[] $tickets */ |
|
| 1754 | + $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1755 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
| 1756 | + // NOTE: we're just sending the first default row |
|
| 1757 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1758 | + } |
|
| 1759 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1760 | + 'event_editor_event_datetimes_help_tab' |
|
| 1761 | + ); |
|
| 1762 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1763 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1764 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1765 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1766 | + $ticket_model->create_default_object(), |
|
| 1767 | + true |
|
| 1768 | + ); |
|
| 1769 | + $template = apply_filters( |
|
| 1770 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1771 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1772 | + ); |
|
| 1773 | + EEH_Template::display_template($template, $template_args); |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + |
|
| 1777 | + /** |
|
| 1778 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1779 | + * |
|
| 1780 | + * @access private |
|
| 1781 | + * @param EE_Ticket $ticket the ticket object |
|
| 1782 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1783 | + * @param int $row |
|
| 1784 | + * @return string generated html for the ticket row. |
|
| 1785 | + * @throws EE_Error |
|
| 1786 | + * @throws ReflectionException |
|
| 1787 | + */ |
|
| 1788 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1789 | + { |
|
| 1790 | + $template_args = [ |
|
| 1791 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1792 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1793 | + : '', |
|
| 1794 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1795 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1796 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1797 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1798 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1799 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1800 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1801 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1802 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1803 | + 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1804 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1805 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock', |
|
| 1806 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1807 | + : ' disabled=disabled', |
|
| 1808 | + ]; |
|
| 1809 | + $price = $ticket->ID() !== 0 |
|
| 1810 | + ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1811 | + : null; |
|
| 1812 | + $price = $price instanceof EE_Price |
|
| 1813 | + ? $price |
|
| 1814 | + : EEM_Price::instance()->create_default_object(); |
|
| 1815 | + $price_args = [ |
|
| 1816 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1817 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1818 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1819 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1820 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1821 | + ]; |
|
| 1822 | + // make sure we have default start and end dates if skeleton |
|
| 1823 | + // handle rows that should NOT be empty |
|
| 1824 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1825 | + // if empty then the start date will be now. |
|
| 1826 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1827 | + } |
|
| 1828 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1829 | + // get the earliest datetime (if present); |
|
| 1830 | + $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1831 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1832 | + 'Datetime', |
|
| 1833 | + ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1834 | + ) |
|
| 1835 | + : null; |
|
| 1836 | + $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
| 1837 | + ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
| 1838 | + : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
| 1839 | + } |
|
| 1840 | + $template_args = array_merge($template_args, $price_args); |
|
| 1841 | + $template = apply_filters( |
|
| 1842 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1843 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1844 | + $ticket |
|
| 1845 | + ); |
|
| 1846 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1847 | + } |
|
| 1848 | + |
|
| 1849 | + |
|
| 1850 | + /** |
|
| 1851 | + * @throws EE_Error |
|
| 1852 | + * @throws ReflectionException |
|
| 1853 | + */ |
|
| 1854 | + public function registration_options_meta_box() |
|
| 1855 | + { |
|
| 1856 | + $yes_no_values = [ |
|
| 1857 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1858 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1859 | + ]; |
|
| 1860 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1861 | + [ |
|
| 1862 | + EEM_Registration::status_id_cancelled, |
|
| 1863 | + EEM_Registration::status_id_declined, |
|
| 1864 | + EEM_Registration::status_id_incomplete, |
|
| 1865 | + ], |
|
| 1866 | + true |
|
| 1867 | + ); |
|
| 1868 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1869 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1870 | + $template_args['event'] = $this->_cpt_model_obj; |
|
| 1871 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1872 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1873 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1874 | + 'default_reg_status', |
|
| 1875 | + $default_reg_status_values, |
|
| 1876 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1877 | + ); |
|
| 1878 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1879 | + 'display_desc', |
|
| 1880 | + $yes_no_values, |
|
| 1881 | + $this->_cpt_model_obj->display_description() |
|
| 1882 | + ); |
|
| 1883 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1884 | + 'display_ticket_selector', |
|
| 1885 | + $yes_no_values, |
|
| 1886 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1887 | + '', |
|
| 1888 | + '', |
|
| 1889 | + false |
|
| 1890 | + ); |
|
| 1891 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1892 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1893 | + '', |
|
| 1894 | + $template_args, |
|
| 1895 | + $yes_no_values, |
|
| 1896 | + $default_reg_status_values |
|
| 1897 | + ); |
|
| 1898 | + EEH_Template::display_template( |
|
| 1899 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1900 | + $template_args |
|
| 1901 | + ); |
|
| 1902 | + } |
|
| 1903 | + |
|
| 1904 | + |
|
| 1905 | + /** |
|
| 1906 | + * _get_events() |
|
| 1907 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1908 | + * |
|
| 1909 | + * @access public |
|
| 1910 | + * @param int $per_page count of items per page (20 default); |
|
| 1911 | + * @param int $current_page what is the current page being viewed. |
|
| 1912 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1913 | + * If FALSE then we return an array of event objects |
|
| 1914 | + * that match the given _view and paging parameters. |
|
| 1915 | + * @return array|int an array of event objects or a count of them. |
|
| 1916 | + * @throws Exception |
|
| 1917 | + */ |
|
| 1918 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1919 | + { |
|
| 1920 | + $EEM_Event = $this->_event_model(); |
|
| 1921 | + $offset = ($current_page - 1) * $per_page; |
|
| 1922 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1923 | + $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
| 1924 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 1925 | + $month_range = $this->request->getRequestParam('month_range'); |
|
| 1926 | + if ($month_range) { |
|
| 1927 | + $pieces = explode(' ', $month_range, 3); |
|
| 1928 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1929 | + // where PHP doesn't know what to assume for date. |
|
| 1930 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1931 | + $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1932 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1933 | + } |
|
| 1934 | + $where = []; |
|
| 1935 | + $status = $this->request->getRequestParam('status'); |
|
| 1936 | + // determine what post_status our condition will have for the query. |
|
| 1937 | + switch ($status) { |
|
| 1938 | + case 'month': |
|
| 1939 | + case 'today': |
|
| 1940 | + case null: |
|
| 1941 | + case 'all': |
|
| 1942 | + break; |
|
| 1943 | + case 'draft': |
|
| 1944 | + $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1945 | + break; |
|
| 1946 | + default: |
|
| 1947 | + $where['status'] = $status; |
|
| 1948 | + } |
|
| 1949 | + // categories? The default for all categories is -1 |
|
| 1950 | + $category = $this->request->getRequestParam('EVT_CAT', -1, 'int'); |
|
| 1951 | + if ($category !== -1) { |
|
| 1952 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1953 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1954 | + } |
|
| 1955 | + // date where conditions |
|
| 1956 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1957 | + if ($month_range) { |
|
| 1958 | + $DateTime = new DateTime( |
|
| 1959 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1960 | + new DateTimeZone('UTC') |
|
| 1961 | + ); |
|
| 1962 | + $start = $DateTime->getTimestamp(); |
|
| 1963 | + // set the datetime to be the end of the month |
|
| 1964 | + $DateTime->setDate( |
|
| 1965 | + $year_r, |
|
| 1966 | + $month_r, |
|
| 1967 | + $DateTime->format('t') |
|
| 1968 | + )->setTime(23, 59, 59); |
|
| 1969 | + $end = $DateTime->getTimestamp(); |
|
| 1970 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1971 | + } elseif ($status === 'today') { |
|
| 1972 | + $DateTime = |
|
| 1973 | + new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1974 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1975 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1976 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1977 | + } elseif ($status === 'month') { |
|
| 1978 | + $now = date('Y-m-01'); |
|
| 1979 | + $DateTime = |
|
| 1980 | + new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1981 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1982 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1983 | + ->setTime(23, 59, 59) |
|
| 1984 | + ->format(implode(' ', $start_formats)); |
|
| 1985 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1986 | + } |
|
| 1987 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1988 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1989 | + } else { |
|
| 1990 | + if (! isset($where['status'])) { |
|
| 1991 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1992 | + $where['OR'] = [ |
|
| 1993 | + 'status*restrict_private' => ['!=', 'private'], |
|
| 1994 | + 'AND' => [ |
|
| 1995 | + 'status*inclusive' => ['=', 'private'], |
|
| 1996 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1997 | + ], |
|
| 1998 | + ]; |
|
| 1999 | + } |
|
| 2000 | + } |
|
| 2001 | + } |
|
| 2002 | + $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int'); |
|
| 2003 | + if ( |
|
| 2004 | + $wp_user |
|
| 2005 | + && $wp_user !== get_current_user_id() |
|
| 2006 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 2007 | + ) { |
|
| 2008 | + $where['EVT_wp_user'] = $wp_user; |
|
| 2009 | + } |
|
| 2010 | + // search query handling |
|
| 2011 | + $search_term = $this->request->getRequestParam('s'); |
|
| 2012 | + if ($search_term) { |
|
| 2013 | + $search_term = '%' . $search_term . '%'; |
|
| 2014 | + $where['OR'] = [ |
|
| 2015 | + 'EVT_name' => ['LIKE', $search_term], |
|
| 2016 | + 'EVT_desc' => ['LIKE', $search_term], |
|
| 2017 | + 'EVT_short_desc' => ['LIKE', $search_term], |
|
| 2018 | + ]; |
|
| 2019 | + } |
|
| 2020 | + // filter events by venue. |
|
| 2021 | + $venue = $this->request->getRequestParam('venue', 0, 'int'); |
|
| 2022 | + if ($venue) { |
|
| 2023 | + $where['Venue.VNU_ID'] = $venue; |
|
| 2024 | + } |
|
| 2025 | + $request_params = $this->request->requestParams(); |
|
| 2026 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
| 2027 | + $query_params = apply_filters( |
|
| 2028 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 2029 | + [ |
|
| 2030 | + $where, |
|
| 2031 | + 'limit' => $limit, |
|
| 2032 | + 'order_by' => $orderby, |
|
| 2033 | + 'order' => $order, |
|
| 2034 | + 'group_by' => 'EVT_ID', |
|
| 2035 | + ], |
|
| 2036 | + $request_params |
|
| 2037 | + ); |
|
| 2038 | + |
|
| 2039 | + // let's first check if we have special requests coming in. |
|
| 2040 | + $active_status = $this->request->getRequestParam('active_status'); |
|
| 2041 | + if ($active_status) { |
|
| 2042 | + switch ($active_status) { |
|
| 2043 | + case 'upcoming': |
|
| 2044 | + return $EEM_Event->get_upcoming_events($query_params, $count); |
|
| 2045 | + case 'expired': |
|
| 2046 | + return $EEM_Event->get_expired_events($query_params, $count); |
|
| 2047 | + case 'active': |
|
| 2048 | + return $EEM_Event->get_active_events($query_params, $count); |
|
| 2049 | + case 'inactive': |
|
| 2050 | + return $EEM_Event->get_inactive_events($query_params, $count); |
|
| 2051 | + } |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
| 2055 | + } |
|
| 2056 | + |
|
| 2057 | + |
|
| 2058 | + /** |
|
| 2059 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 2060 | + * |
|
| 2061 | + * @param string $post_id |
|
| 2062 | + * @throws EE_Error |
|
| 2063 | + * @throws ReflectionException |
|
| 2064 | + */ |
|
| 2065 | + public function trash_cpt_item($post_id) |
|
| 2066 | + { |
|
| 2067 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2068 | + $this->_trash_or_restore_event('trash', false); |
|
| 2069 | + } |
|
| 2070 | + |
|
| 2071 | + |
|
| 2072 | + /** |
|
| 2073 | + * @param string $post_id |
|
| 2074 | + * @throws EE_Error |
|
| 2075 | + * @throws ReflectionException |
|
| 2076 | + */ |
|
| 2077 | + public function restore_cpt_item($post_id) |
|
| 2078 | + { |
|
| 2079 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2080 | + $this->_trash_or_restore_event('draft', false); |
|
| 2081 | + } |
|
| 2082 | + |
|
| 2083 | + |
|
| 2084 | + /** |
|
| 2085 | + * @param string $post_id |
|
| 2086 | + * @throws EE_Error |
|
| 2087 | + * @throws EE_Error |
|
| 2088 | + */ |
|
| 2089 | + public function delete_cpt_item($post_id) |
|
| 2090 | + { |
|
| 2091 | + throw new EE_Error( |
|
| 2092 | + esc_html__( |
|
| 2093 | + 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
| 2094 | + 'event_espresso' |
|
| 2095 | + ) |
|
| 2096 | + ); |
|
| 2097 | + // $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2098 | + // $this->_delete_event(); |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + |
|
| 2102 | + /** |
|
| 2103 | + * _trash_or_restore_event |
|
| 2104 | + * |
|
| 2105 | + * @access protected |
|
| 2106 | + * @param string $event_status |
|
| 2107 | + * @param bool $redirect_after |
|
| 2108 | + * @throws EE_Error |
|
| 2109 | + * @throws EE_Error |
|
| 2110 | + * @throws ReflectionException |
|
| 2111 | + */ |
|
| 2112 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 2113 | + { |
|
| 2114 | + // determine the event id and set to array. |
|
| 2115 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 2116 | + // loop thru events |
|
| 2117 | + if ($EVT_ID) { |
|
| 2118 | + // clean status |
|
| 2119 | + $event_status = sanitize_key($event_status); |
|
| 2120 | + // grab status |
|
| 2121 | + if (! empty($event_status)) { |
|
| 2122 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2123 | + } else { |
|
| 2124 | + $success = false; |
|
| 2125 | + $msg = esc_html__( |
|
| 2126 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2127 | + 'event_espresso' |
|
| 2128 | + ); |
|
| 2129 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2130 | + } |
|
| 2131 | + } else { |
|
| 2132 | + $success = false; |
|
| 2133 | + $msg = esc_html__( |
|
| 2134 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2135 | + 'event_espresso' |
|
| 2136 | + ); |
|
| 2137 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2138 | + } |
|
| 2139 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2140 | + if ($redirect_after) { |
|
| 2141 | + $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2142 | + } |
|
| 2143 | + } |
|
| 2144 | + |
|
| 2145 | + |
|
| 2146 | + /** |
|
| 2147 | + * _trash_or_restore_events |
|
| 2148 | + * |
|
| 2149 | + * @access protected |
|
| 2150 | + * @param string $event_status |
|
| 2151 | + * @return void |
|
| 2152 | + * @throws EE_Error |
|
| 2153 | + * @throws EE_Error |
|
| 2154 | + * @throws ReflectionException |
|
| 2155 | + */ |
|
| 2156 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2157 | + { |
|
| 2158 | + // clean status |
|
| 2159 | + $event_status = sanitize_key($event_status); |
|
| 2160 | + // grab status |
|
| 2161 | + if (! empty($event_status)) { |
|
| 2162 | + $success = true; |
|
| 2163 | + // determine the event id and set to array. |
|
| 2164 | + $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2165 | + // loop thru events |
|
| 2166 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2167 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 2168 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2169 | + $success = $results !== false ? $success : false; |
|
| 2170 | + } else { |
|
| 2171 | + $msg = sprintf( |
|
| 2172 | + esc_html__( |
|
| 2173 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2174 | + 'event_espresso' |
|
| 2175 | + ), |
|
| 2176 | + $EVT_ID |
|
| 2177 | + ); |
|
| 2178 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2179 | + $success = false; |
|
| 2180 | + } |
|
| 2181 | + } |
|
| 2182 | + } else { |
|
| 2183 | + $success = false; |
|
| 2184 | + $msg = esc_html__( |
|
| 2185 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2186 | + 'event_espresso' |
|
| 2187 | + ); |
|
| 2188 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2189 | + } |
|
| 2190 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2191 | + $success = $success ? 2 : false; |
|
| 2192 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2193 | + $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2194 | + } |
|
| 2195 | + |
|
| 2196 | + |
|
| 2197 | + /** |
|
| 2198 | + * @param int $EVT_ID |
|
| 2199 | + * @param string $event_status |
|
| 2200 | + * @return bool |
|
| 2201 | + * @throws EE_Error |
|
| 2202 | + * @throws ReflectionException |
|
| 2203 | + */ |
|
| 2204 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2205 | + { |
|
| 2206 | + // grab event id |
|
| 2207 | + if (! $EVT_ID) { |
|
| 2208 | + $msg = esc_html__( |
|
| 2209 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2210 | + 'event_espresso' |
|
| 2211 | + ); |
|
| 2212 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2213 | + return false; |
|
| 2214 | + } |
|
| 2215 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2216 | + // clean status |
|
| 2217 | + $event_status = sanitize_key($event_status); |
|
| 2218 | + // grab status |
|
| 2219 | + if (empty($event_status)) { |
|
| 2220 | + $msg = esc_html__( |
|
| 2221 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2222 | + 'event_espresso' |
|
| 2223 | + ); |
|
| 2224 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2225 | + return false; |
|
| 2226 | + } |
|
| 2227 | + // was event trashed or restored ? |
|
| 2228 | + switch ($event_status) { |
|
| 2229 | + case 'draft': |
|
| 2230 | + $action = 'restored from the trash'; |
|
| 2231 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2232 | + break; |
|
| 2233 | + case 'trash': |
|
| 2234 | + $action = 'moved to the trash'; |
|
| 2235 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2236 | + break; |
|
| 2237 | + default: |
|
| 2238 | + $action = 'updated'; |
|
| 2239 | + $hook = false; |
|
| 2240 | + } |
|
| 2241 | + // use class to change status |
|
| 2242 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2243 | + $success = $this->_cpt_model_obj->save(); |
|
| 2244 | + if (! $success) { |
|
| 2245 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2246 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2247 | + return false; |
|
| 2248 | + } |
|
| 2249 | + if ($hook) { |
|
| 2250 | + do_action($hook); |
|
| 2251 | + } |
|
| 2252 | + return true; |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + |
|
| 2256 | + /** |
|
| 2257 | + * @param array $event_ids |
|
| 2258 | + * @return array |
|
| 2259 | + * @since 4.10.23.p |
|
| 2260 | + */ |
|
| 2261 | + private function cleanEventIds(array $event_ids) |
|
| 2262 | + { |
|
| 2263 | + return array_map('absint', $event_ids); |
|
| 2264 | + } |
|
| 2265 | + |
|
| 2266 | + |
|
| 2267 | + /** |
|
| 2268 | + * @return array |
|
| 2269 | + * @since 4.10.23.p |
|
| 2270 | + */ |
|
| 2271 | + private function getEventIdsFromRequest() |
|
| 2272 | + { |
|
| 2273 | + if ($this->request->requestParamIsSet('EVT_IDs')) { |
|
| 2274 | + return $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2275 | + } else { |
|
| 2276 | + return $this->request->getRequestParam('EVT_ID', [], 'int', true); |
|
| 2277 | + } |
|
| 2278 | + } |
|
| 2279 | + |
|
| 2280 | + |
|
| 2281 | + /** |
|
| 2282 | + * @param bool $preview_delete |
|
| 2283 | + * @throws EE_Error |
|
| 2284 | + */ |
|
| 2285 | + protected function _delete_event($preview_delete = true) |
|
| 2286 | + { |
|
| 2287 | + $this->_delete_events($preview_delete); |
|
| 2288 | + } |
|
| 2289 | + |
|
| 2290 | + |
|
| 2291 | + /** |
|
| 2292 | + * Gets the tree traversal batch persister. |
|
| 2293 | + * |
|
| 2294 | + * @return NodeGroupDao |
|
| 2295 | + * @throws InvalidArgumentException |
|
| 2296 | + * @throws InvalidDataTypeException |
|
| 2297 | + * @throws InvalidInterfaceException |
|
| 2298 | + * @since 4.10.12.p |
|
| 2299 | + */ |
|
| 2300 | + protected function getModelObjNodeGroupPersister() |
|
| 2301 | + { |
|
| 2302 | + if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2303 | + $this->model_obj_node_group_persister = |
|
| 2304 | + $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2305 | + } |
|
| 2306 | + return $this->model_obj_node_group_persister; |
|
| 2307 | + } |
|
| 2308 | + |
|
| 2309 | + |
|
| 2310 | + /** |
|
| 2311 | + * @param bool $preview_delete |
|
| 2312 | + * @return void |
|
| 2313 | + * @throws EE_Error |
|
| 2314 | + */ |
|
| 2315 | + protected function _delete_events($preview_delete = true) |
|
| 2316 | + { |
|
| 2317 | + $event_ids = $this->getEventIdsFromRequest(); |
|
| 2318 | + if ($preview_delete) { |
|
| 2319 | + $this->generateDeletionPreview($event_ids); |
|
| 2320 | + } else { |
|
| 2321 | + EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]); |
|
| 2322 | + } |
|
| 2323 | + } |
|
| 2324 | + |
|
| 2325 | + |
|
| 2326 | + /** |
|
| 2327 | + * @param array $event_ids |
|
| 2328 | + */ |
|
| 2329 | + protected function generateDeletionPreview(array $event_ids) |
|
| 2330 | + { |
|
| 2331 | + $event_ids = $this->cleanEventIds($event_ids); |
|
| 2332 | + // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2333 | + $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2334 | + $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2335 | + [ |
|
| 2336 | + 'action' => 'preview_deletion', |
|
| 2337 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2338 | + ], |
|
| 2339 | + $this->_admin_base_url |
|
| 2340 | + ); |
|
| 2341 | + EEH_URL::safeRedirectAndExit( |
|
| 2342 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2343 | + [ |
|
| 2344 | + 'page' => 'espresso_batch', |
|
| 2345 | + 'batch' => EED_Batch::batch_job, |
|
| 2346 | + 'EVT_IDs' => $event_ids, |
|
| 2347 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2348 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
| 2349 | + 'return_url' => urlencode($return_url), |
|
| 2350 | + ], |
|
| 2351 | + admin_url() |
|
| 2352 | + ) |
|
| 2353 | + ); |
|
| 2354 | + } |
|
| 2355 | + |
|
| 2356 | + |
|
| 2357 | + /** |
|
| 2358 | + * Checks for a POST submission |
|
| 2359 | + * |
|
| 2360 | + * @since 4.10.12.p |
|
| 2361 | + */ |
|
| 2362 | + protected function confirmDeletion() |
|
| 2363 | + { |
|
| 2364 | + $deletion_redirect_logic = |
|
| 2365 | + $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
| 2366 | + $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2367 | + } |
|
| 2368 | + |
|
| 2369 | + |
|
| 2370 | + /** |
|
| 2371 | + * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2372 | + * |
|
| 2373 | + * @throws EE_Error |
|
| 2374 | + * @since 4.10.12.p |
|
| 2375 | + */ |
|
| 2376 | + protected function previewDeletion() |
|
| 2377 | + { |
|
| 2378 | + $preview_deletion_logic = |
|
| 2379 | + $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
| 2380 | + $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2381 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2382 | + } |
|
| 2383 | + |
|
| 2384 | + |
|
| 2385 | + /** |
|
| 2386 | + * get total number of events |
|
| 2387 | + * |
|
| 2388 | + * @access public |
|
| 2389 | + * @return int |
|
| 2390 | + * @throws EE_Error |
|
| 2391 | + * @throws EE_Error |
|
| 2392 | + */ |
|
| 2393 | + public function total_events() |
|
| 2394 | + { |
|
| 2395 | + return EEM_Event::instance()->count( |
|
| 2396 | + ['caps' => 'read_admin'], |
|
| 2397 | + 'EVT_ID', |
|
| 2398 | + true |
|
| 2399 | + ); |
|
| 2400 | + } |
|
| 2401 | + |
|
| 2402 | + |
|
| 2403 | + /** |
|
| 2404 | + * get total number of draft events |
|
| 2405 | + * |
|
| 2406 | + * @access public |
|
| 2407 | + * @return int |
|
| 2408 | + * @throws EE_Error |
|
| 2409 | + * @throws EE_Error |
|
| 2410 | + */ |
|
| 2411 | + public function total_events_draft() |
|
| 2412 | + { |
|
| 2413 | + return EEM_Event::instance()->count( |
|
| 2414 | + [ |
|
| 2415 | + ['status' => ['IN', ['draft', 'auto-draft']]], |
|
| 2416 | + 'caps' => 'read_admin', |
|
| 2417 | + ], |
|
| 2418 | + 'EVT_ID', |
|
| 2419 | + true |
|
| 2420 | + ); |
|
| 2421 | + } |
|
| 2422 | + |
|
| 2423 | + |
|
| 2424 | + /** |
|
| 2425 | + * get total number of trashed events |
|
| 2426 | + * |
|
| 2427 | + * @access public |
|
| 2428 | + * @return int |
|
| 2429 | + * @throws EE_Error |
|
| 2430 | + * @throws EE_Error |
|
| 2431 | + */ |
|
| 2432 | + public function total_trashed_events() |
|
| 2433 | + { |
|
| 2434 | + return EEM_Event::instance()->count( |
|
| 2435 | + [ |
|
| 2436 | + ['status' => 'trash'], |
|
| 2437 | + 'caps' => 'read_admin', |
|
| 2438 | + ], |
|
| 2439 | + 'EVT_ID', |
|
| 2440 | + true |
|
| 2441 | + ); |
|
| 2442 | + } |
|
| 2443 | + |
|
| 2444 | + |
|
| 2445 | + /** |
|
| 2446 | + * _default_event_settings |
|
| 2447 | + * This generates the Default Settings Tab |
|
| 2448 | + * |
|
| 2449 | + * @return void |
|
| 2450 | + * @throws DomainException |
|
| 2451 | + * @throws EE_Error |
|
| 2452 | + * @throws InvalidArgumentException |
|
| 2453 | + * @throws InvalidDataTypeException |
|
| 2454 | + * @throws InvalidInterfaceException |
|
| 2455 | + */ |
|
| 2456 | + protected function _default_event_settings() |
|
| 2457 | + { |
|
| 2458 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2459 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2460 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
| 2461 | + $this->_default_event_settings_form()->get_html(), |
|
| 2462 | + '', |
|
| 2463 | + 'padding' |
|
| 2464 | + ); |
|
| 2465 | + $this->display_admin_page_with_sidebar(); |
|
| 2466 | + } |
|
| 2467 | + |
|
| 2468 | + |
|
| 2469 | + /** |
|
| 2470 | + * Return the form for event settings. |
|
| 2471 | + * |
|
| 2472 | + * @return EE_Form_Section_Proper |
|
| 2473 | + * @throws EE_Error |
|
| 2474 | + */ |
|
| 2475 | + protected function _default_event_settings_form() |
|
| 2476 | + { |
|
| 2477 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2478 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2479 | + // exclude |
|
| 2480 | + [ |
|
| 2481 | + EEM_Registration::status_id_cancelled, |
|
| 2482 | + EEM_Registration::status_id_declined, |
|
| 2483 | + EEM_Registration::status_id_incomplete, |
|
| 2484 | + EEM_Registration::status_id_wait_list, |
|
| 2485 | + ], |
|
| 2486 | + true |
|
| 2487 | + ); |
|
| 2488 | + return new EE_Form_Section_Proper( |
|
| 2489 | + [ |
|
| 2490 | + 'name' => 'update_default_event_settings', |
|
| 2491 | + 'html_id' => 'update_default_event_settings', |
|
| 2492 | + 'html_class' => 'form-table', |
|
| 2493 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2494 | + 'subsections' => apply_filters( |
|
| 2495 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2496 | + [ |
|
| 2497 | + 'defaults_section_header' => new EE_Form_Section_HTML( |
|
| 2498 | + EEH_HTML::h2( |
|
| 2499 | + esc_html__('Default Settings', 'event_espresso'), |
|
| 2500 | + '', |
|
| 2501 | + 'ee-admin-settings-hdr' |
|
| 2502 | + ) |
|
| 2503 | + ), |
|
| 2504 | + 'default_reg_status' => new EE_Select_Input( |
|
| 2505 | + $registration_stati_for_selection, |
|
| 2506 | + [ |
|
| 2507 | + 'default' => isset($registration_config->default_STS_ID) |
|
| 2508 | + && array_key_exists( |
|
| 2509 | + $registration_config->default_STS_ID, |
|
| 2510 | + $registration_stati_for_selection |
|
| 2511 | + ) |
|
| 2512 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2513 | + : EEM_Registration::status_id_pending_payment, |
|
| 2514 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2515 | + . EEH_Template::get_help_tab_link( |
|
| 2516 | + 'default_settings_status_help_tab' |
|
| 2517 | + ), |
|
| 2518 | + 'html_help_text' => esc_html__( |
|
| 2519 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2520 | + 'event_espresso' |
|
| 2521 | + ), |
|
| 2522 | + ] |
|
| 2523 | + ), |
|
| 2524 | + 'default_max_tickets' => new EE_Integer_Input( |
|
| 2525 | + [ |
|
| 2526 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2527 | + ? $registration_config->default_maximum_number_of_tickets |
|
| 2528 | + : EEM_Event::get_default_additional_limit(), |
|
| 2529 | + 'html_label_text' => esc_html__( |
|
| 2530 | + 'Default Maximum Tickets Allowed Per Order:', |
|
| 2531 | + 'event_espresso' |
|
| 2532 | + ) |
|
| 2533 | + . EEH_Template::get_help_tab_link( |
|
| 2534 | + 'default_maximum_tickets_help_tab"' |
|
| 2535 | + ), |
|
| 2536 | + 'html_help_text' => esc_html__( |
|
| 2537 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2538 | + 'event_espresso' |
|
| 2539 | + ), |
|
| 2540 | + ] |
|
| 2541 | + ), |
|
| 2542 | + ] |
|
| 2543 | + ), |
|
| 2544 | + ] |
|
| 2545 | + ); |
|
| 2546 | + } |
|
| 2547 | + |
|
| 2548 | + |
|
| 2549 | + /** |
|
| 2550 | + * @return void |
|
| 2551 | + * @throws EE_Error |
|
| 2552 | + * @throws InvalidArgumentException |
|
| 2553 | + * @throws InvalidDataTypeException |
|
| 2554 | + * @throws InvalidInterfaceException |
|
| 2555 | + */ |
|
| 2556 | + protected function _update_default_event_settings() |
|
| 2557 | + { |
|
| 2558 | + $form = $this->_default_event_settings_form(); |
|
| 2559 | + if ($form->was_submitted()) { |
|
| 2560 | + $form->receive_form_submission(); |
|
| 2561 | + if ($form->is_valid()) { |
|
| 2562 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2563 | + $valid_data = $form->valid_data(); |
|
| 2564 | + if (isset($valid_data['default_reg_status'])) { |
|
| 2565 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2566 | + } |
|
| 2567 | + if (isset($valid_data['default_max_tickets'])) { |
|
| 2568 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2569 | + } |
|
| 2570 | + do_action( |
|
| 2571 | + 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
| 2572 | + $valid_data, |
|
| 2573 | + EE_Registry::instance()->CFG, |
|
| 2574 | + $this |
|
| 2575 | + ); |
|
| 2576 | + // update because data was valid! |
|
| 2577 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2578 | + EE_Error::overwrite_success(); |
|
| 2579 | + EE_Error::add_success( |
|
| 2580 | + esc_html__('Default Event Settings were updated', 'event_espresso') |
|
| 2581 | + ); |
|
| 2582 | + } |
|
| 2583 | + } |
|
| 2584 | + $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2585 | + } |
|
| 2586 | + |
|
| 2587 | + |
|
| 2588 | + /************* Templates ************* |
|
| 21 | 2589 | * |
| 22 | - * @var EE_Event $_event |
|
| 23 | - */ |
|
| 24 | - protected $_event; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * This will hold the category object for category_details screen. |
|
| 29 | - * |
|
| 30 | - * @var stdClass $_category |
|
| 31 | - */ |
|
| 32 | - protected $_category; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * This will hold the event model instance |
|
| 37 | - * |
|
| 38 | - * @var EEM_Event $_event_model |
|
| 39 | - */ |
|
| 40 | - protected $_event_model; |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Event |
|
| 45 | - */ |
|
| 46 | - protected $_cpt_model_obj = false; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var NodeGroupDao |
|
| 51 | - */ |
|
| 52 | - protected $model_obj_node_group_persister; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Initialize page props for this admin page group. |
|
| 57 | - */ |
|
| 58 | - protected function _init_page_props() |
|
| 59 | - { |
|
| 60 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 61 | - $this->page_label = EVENTS_LABEL; |
|
| 62 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 63 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 64 | - $this->_cpt_model_names = [ |
|
| 65 | - 'create_new' => 'EEM_Event', |
|
| 66 | - 'edit' => 'EEM_Event', |
|
| 67 | - ]; |
|
| 68 | - $this->_cpt_edit_routes = [ |
|
| 69 | - 'espresso_events' => 'edit', |
|
| 70 | - ]; |
|
| 71 | - add_action( |
|
| 72 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 73 | - [$this, 'verify_event_edit'], |
|
| 74 | - 10, |
|
| 75 | - 2 |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Sets the ajax hooks used for this admin page group. |
|
| 82 | - */ |
|
| 83 | - protected function _ajax_hooks() |
|
| 84 | - { |
|
| 85 | - add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Sets the page properties for this admin page group. |
|
| 91 | - */ |
|
| 92 | - protected function _define_page_props() |
|
| 93 | - { |
|
| 94 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 95 | - $this->_labels = [ |
|
| 96 | - 'buttons' => [ |
|
| 97 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 98 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 99 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 100 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 101 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 102 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 103 | - ], |
|
| 104 | - 'editor_title' => [ |
|
| 105 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 106 | - ], |
|
| 107 | - 'publishbox' => [ |
|
| 108 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 109 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 110 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 111 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 112 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 113 | - ], |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Sets the page routes property for this admin page group. |
|
| 120 | - */ |
|
| 121 | - protected function _set_page_routes() |
|
| 122 | - { |
|
| 123 | - // load formatter helper |
|
| 124 | - // load field generator helper |
|
| 125 | - // is there a evt_id in the request? |
|
| 126 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 127 | - $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
| 128 | - |
|
| 129 | - $this->_page_routes = [ |
|
| 130 | - 'default' => [ |
|
| 131 | - 'func' => '_events_overview_list_table', |
|
| 132 | - 'capability' => 'ee_read_events', |
|
| 133 | - ], |
|
| 134 | - 'create_new' => [ |
|
| 135 | - 'func' => '_create_new_cpt_item', |
|
| 136 | - 'capability' => 'ee_edit_events', |
|
| 137 | - ], |
|
| 138 | - 'edit' => [ |
|
| 139 | - 'func' => '_edit_cpt_item', |
|
| 140 | - 'capability' => 'ee_edit_event', |
|
| 141 | - 'obj_id' => $EVT_ID, |
|
| 142 | - ], |
|
| 143 | - 'copy_event' => [ |
|
| 144 | - 'func' => '_copy_events', |
|
| 145 | - 'capability' => 'ee_edit_event', |
|
| 146 | - 'obj_id' => $EVT_ID, |
|
| 147 | - 'noheader' => true, |
|
| 148 | - ], |
|
| 149 | - 'trash_event' => [ |
|
| 150 | - 'func' => '_trash_or_restore_event', |
|
| 151 | - 'args' => ['event_status' => 'trash'], |
|
| 152 | - 'capability' => 'ee_delete_event', |
|
| 153 | - 'obj_id' => $EVT_ID, |
|
| 154 | - 'noheader' => true, |
|
| 155 | - ], |
|
| 156 | - 'trash_events' => [ |
|
| 157 | - 'func' => '_trash_or_restore_events', |
|
| 158 | - 'args' => ['event_status' => 'trash'], |
|
| 159 | - 'capability' => 'ee_delete_events', |
|
| 160 | - 'noheader' => true, |
|
| 161 | - ], |
|
| 162 | - 'restore_event' => [ |
|
| 163 | - 'func' => '_trash_or_restore_event', |
|
| 164 | - 'args' => ['event_status' => 'draft'], |
|
| 165 | - 'capability' => 'ee_delete_event', |
|
| 166 | - 'obj_id' => $EVT_ID, |
|
| 167 | - 'noheader' => true, |
|
| 168 | - ], |
|
| 169 | - 'restore_events' => [ |
|
| 170 | - 'func' => '_trash_or_restore_events', |
|
| 171 | - 'args' => ['event_status' => 'draft'], |
|
| 172 | - 'capability' => 'ee_delete_events', |
|
| 173 | - 'noheader' => true, |
|
| 174 | - ], |
|
| 175 | - 'delete_event' => [ |
|
| 176 | - 'func' => '_delete_event', |
|
| 177 | - 'capability' => 'ee_delete_event', |
|
| 178 | - 'obj_id' => $EVT_ID, |
|
| 179 | - 'noheader' => true, |
|
| 180 | - ], |
|
| 181 | - 'delete_events' => [ |
|
| 182 | - 'func' => '_delete_events', |
|
| 183 | - 'capability' => 'ee_delete_events', |
|
| 184 | - 'noheader' => true, |
|
| 185 | - ], |
|
| 186 | - 'view_report' => [ |
|
| 187 | - 'func' => '_view_report', |
|
| 188 | - 'capability' => 'ee_edit_events', |
|
| 189 | - ], |
|
| 190 | - 'default_event_settings' => [ |
|
| 191 | - 'func' => '_default_event_settings', |
|
| 192 | - 'capability' => 'manage_options', |
|
| 193 | - ], |
|
| 194 | - 'update_default_event_settings' => [ |
|
| 195 | - 'func' => '_update_default_event_settings', |
|
| 196 | - 'capability' => 'manage_options', |
|
| 197 | - 'noheader' => true, |
|
| 198 | - ], |
|
| 199 | - 'template_settings' => [ |
|
| 200 | - 'func' => '_template_settings', |
|
| 201 | - 'capability' => 'manage_options', |
|
| 202 | - ], |
|
| 203 | - // event category tab related |
|
| 204 | - 'add_category' => [ |
|
| 205 | - 'func' => '_category_details', |
|
| 206 | - 'capability' => 'ee_edit_event_category', |
|
| 207 | - 'args' => ['add'], |
|
| 208 | - ], |
|
| 209 | - 'edit_category' => [ |
|
| 210 | - 'func' => '_category_details', |
|
| 211 | - 'capability' => 'ee_edit_event_category', |
|
| 212 | - 'args' => ['edit'], |
|
| 213 | - ], |
|
| 214 | - 'delete_categories' => [ |
|
| 215 | - 'func' => '_delete_categories', |
|
| 216 | - 'capability' => 'ee_delete_event_category', |
|
| 217 | - 'noheader' => true, |
|
| 218 | - ], |
|
| 219 | - 'delete_category' => [ |
|
| 220 | - 'func' => '_delete_categories', |
|
| 221 | - 'capability' => 'ee_delete_event_category', |
|
| 222 | - 'noheader' => true, |
|
| 223 | - ], |
|
| 224 | - 'insert_category' => [ |
|
| 225 | - 'func' => '_insert_or_update_category', |
|
| 226 | - 'args' => ['new_category' => true], |
|
| 227 | - 'capability' => 'ee_edit_event_category', |
|
| 228 | - 'noheader' => true, |
|
| 229 | - ], |
|
| 230 | - 'update_category' => [ |
|
| 231 | - 'func' => '_insert_or_update_category', |
|
| 232 | - 'args' => ['new_category' => false], |
|
| 233 | - 'capability' => 'ee_edit_event_category', |
|
| 234 | - 'noheader' => true, |
|
| 235 | - ], |
|
| 236 | - 'category_list' => [ |
|
| 237 | - 'func' => '_category_list_table', |
|
| 238 | - 'capability' => 'ee_manage_event_categories', |
|
| 239 | - ], |
|
| 240 | - 'preview_deletion' => [ |
|
| 241 | - 'func' => 'previewDeletion', |
|
| 242 | - 'capability' => 'ee_delete_events', |
|
| 243 | - ], |
|
| 244 | - 'confirm_deletion' => [ |
|
| 245 | - 'func' => 'confirmDeletion', |
|
| 246 | - 'capability' => 'ee_delete_events', |
|
| 247 | - 'noheader' => true, |
|
| 248 | - ], |
|
| 249 | - ]; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Set the _page_config property for this admin page group. |
|
| 255 | - */ |
|
| 256 | - protected function _set_page_config() |
|
| 257 | - { |
|
| 258 | - $post_id = $this->request->getRequestParam('post', 0, 'int'); |
|
| 259 | - $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 260 | - $this->_page_config = [ |
|
| 261 | - 'default' => [ |
|
| 262 | - 'nav' => [ |
|
| 263 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 264 | - 'order' => 10, |
|
| 265 | - ], |
|
| 266 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 267 | - 'help_tabs' => [ |
|
| 268 | - 'events_overview_help_tab' => [ |
|
| 269 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 270 | - 'filename' => 'events_overview', |
|
| 271 | - ], |
|
| 272 | - 'events_overview_table_column_headings_help_tab' => [ |
|
| 273 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 274 | - 'filename' => 'events_overview_table_column_headings', |
|
| 275 | - ], |
|
| 276 | - 'events_overview_filters_help_tab' => [ |
|
| 277 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 278 | - 'filename' => 'events_overview_filters', |
|
| 279 | - ], |
|
| 280 | - 'events_overview_view_help_tab' => [ |
|
| 281 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 282 | - 'filename' => 'events_overview_views', |
|
| 283 | - ], |
|
| 284 | - 'events_overview_other_help_tab' => [ |
|
| 285 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 286 | - 'filename' => 'events_overview_other', |
|
| 287 | - ], |
|
| 288 | - ], |
|
| 289 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 290 | - // 'help_tour' => [ |
|
| 291 | - // 'Event_Overview_Help_Tour', |
|
| 292 | - // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 293 | - // ], |
|
| 294 | - 'qtips' => ['EE_Event_List_Table_Tips'], |
|
| 295 | - 'require_nonce' => false, |
|
| 296 | - ], |
|
| 297 | - 'create_new' => [ |
|
| 298 | - 'nav' => [ |
|
| 299 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 300 | - 'order' => 5, |
|
| 301 | - 'persistent' => false, |
|
| 302 | - ], |
|
| 303 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 304 | - 'help_tabs' => [ |
|
| 305 | - 'event_editor_help_tab' => [ |
|
| 306 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 307 | - 'filename' => 'event_editor', |
|
| 308 | - ], |
|
| 309 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 310 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 311 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 312 | - ], |
|
| 313 | - 'event_editor_venue_details_help_tab' => [ |
|
| 314 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 315 | - 'filename' => 'event_editor_venue_details', |
|
| 316 | - ], |
|
| 317 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 318 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 319 | - 'filename' => 'event_editor_event_datetimes', |
|
| 320 | - ], |
|
| 321 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 322 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 323 | - 'filename' => 'event_editor_event_tickets', |
|
| 324 | - ], |
|
| 325 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 326 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 327 | - 'filename' => 'event_editor_event_registration_options', |
|
| 328 | - ], |
|
| 329 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 330 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 331 | - 'filename' => 'event_editor_tags_categories', |
|
| 332 | - ], |
|
| 333 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 334 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 335 | - 'filename' => 'event_editor_questions_registrants', |
|
| 336 | - ], |
|
| 337 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 338 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 339 | - 'filename' => 'event_editor_save_new_event', |
|
| 340 | - ], |
|
| 341 | - 'event_editor_other_help_tab' => [ |
|
| 342 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 343 | - 'filename' => 'event_editor_other', |
|
| 344 | - ], |
|
| 345 | - ], |
|
| 346 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 347 | - // 'help_tour' => [ |
|
| 348 | - // 'Event_Editor_Help_Tour', |
|
| 349 | - // ], |
|
| 350 | - 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 351 | - 'require_nonce' => false, |
|
| 352 | - ], |
|
| 353 | - 'edit' => [ |
|
| 354 | - 'nav' => [ |
|
| 355 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 356 | - 'order' => 5, |
|
| 357 | - 'persistent' => false, |
|
| 358 | - 'url' => $post_id |
|
| 359 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 360 | - ['post' => $post_id, 'action' => 'edit'], |
|
| 361 | - $this->_current_page_view_url |
|
| 362 | - ) |
|
| 363 | - : $this->_admin_base_url, |
|
| 364 | - ], |
|
| 365 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 366 | - 'help_tabs' => [ |
|
| 367 | - 'event_editor_help_tab' => [ |
|
| 368 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 369 | - 'filename' => 'event_editor', |
|
| 370 | - ], |
|
| 371 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 372 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 373 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 374 | - ], |
|
| 375 | - 'event_editor_venue_details_help_tab' => [ |
|
| 376 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 377 | - 'filename' => 'event_editor_venue_details', |
|
| 378 | - ], |
|
| 379 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 380 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 381 | - 'filename' => 'event_editor_event_datetimes', |
|
| 382 | - ], |
|
| 383 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 384 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 385 | - 'filename' => 'event_editor_event_tickets', |
|
| 386 | - ], |
|
| 387 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 388 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 389 | - 'filename' => 'event_editor_event_registration_options', |
|
| 390 | - ], |
|
| 391 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 392 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 393 | - 'filename' => 'event_editor_tags_categories', |
|
| 394 | - ], |
|
| 395 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 396 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 397 | - 'filename' => 'event_editor_questions_registrants', |
|
| 398 | - ], |
|
| 399 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 400 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 401 | - 'filename' => 'event_editor_save_new_event', |
|
| 402 | - ], |
|
| 403 | - 'event_editor_other_help_tab' => [ |
|
| 404 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 405 | - 'filename' => 'event_editor_other', |
|
| 406 | - ], |
|
| 407 | - ], |
|
| 408 | - 'require_nonce' => false, |
|
| 409 | - ], |
|
| 410 | - 'default_event_settings' => [ |
|
| 411 | - 'nav' => [ |
|
| 412 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 413 | - 'order' => 40, |
|
| 414 | - ], |
|
| 415 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 416 | - 'labels' => [ |
|
| 417 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 418 | - ], |
|
| 419 | - 'help_tabs' => [ |
|
| 420 | - 'default_settings_help_tab' => [ |
|
| 421 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 422 | - 'filename' => 'events_default_settings', |
|
| 423 | - ], |
|
| 424 | - 'default_settings_status_help_tab' => [ |
|
| 425 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 426 | - 'filename' => 'events_default_settings_status', |
|
| 427 | - ], |
|
| 428 | - 'default_maximum_tickets_help_tab' => [ |
|
| 429 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 430 | - 'filename' => 'events_default_settings_max_tickets', |
|
| 431 | - ], |
|
| 432 | - ], |
|
| 433 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 434 | - // 'help_tour' => ['Event_Default_Settings_Help_Tour'], |
|
| 435 | - 'require_nonce' => false, |
|
| 436 | - ], |
|
| 437 | - // template settings |
|
| 438 | - 'template_settings' => [ |
|
| 439 | - 'nav' => [ |
|
| 440 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 441 | - 'order' => 30, |
|
| 442 | - ], |
|
| 443 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 444 | - 'help_tabs' => [ |
|
| 445 | - 'general_settings_templates_help_tab' => [ |
|
| 446 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 447 | - 'filename' => 'general_settings_templates', |
|
| 448 | - ], |
|
| 449 | - ], |
|
| 450 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 451 | - // 'help_tour' => ['Templates_Help_Tour'], |
|
| 452 | - 'require_nonce' => false, |
|
| 453 | - ], |
|
| 454 | - // event category stuff |
|
| 455 | - 'add_category' => [ |
|
| 456 | - 'nav' => [ |
|
| 457 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 458 | - 'order' => 15, |
|
| 459 | - 'persistent' => false, |
|
| 460 | - ], |
|
| 461 | - 'help_tabs' => [ |
|
| 462 | - 'add_category_help_tab' => [ |
|
| 463 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 464 | - 'filename' => 'events_add_category', |
|
| 465 | - ], |
|
| 466 | - ], |
|
| 467 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 468 | - // 'help_tour' => ['Event_Add_Category_Help_Tour'], |
|
| 469 | - 'metaboxes' => ['_publish_post_box'], |
|
| 470 | - 'require_nonce' => false, |
|
| 471 | - ], |
|
| 472 | - 'edit_category' => [ |
|
| 473 | - 'nav' => [ |
|
| 474 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 475 | - 'order' => 15, |
|
| 476 | - 'persistent' => false, |
|
| 477 | - 'url' => $EVT_CAT_ID |
|
| 478 | - ? add_query_arg( |
|
| 479 | - ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
| 480 | - $this->_current_page_view_url |
|
| 481 | - ) |
|
| 482 | - : $this->_admin_base_url, |
|
| 483 | - ], |
|
| 484 | - 'help_tabs' => [ |
|
| 485 | - 'edit_category_help_tab' => [ |
|
| 486 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 487 | - 'filename' => 'events_edit_category', |
|
| 488 | - ], |
|
| 489 | - ], |
|
| 490 | - /*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/ |
|
| 491 | - 'metaboxes' => ['_publish_post_box'], |
|
| 492 | - 'require_nonce' => false, |
|
| 493 | - ], |
|
| 494 | - 'category_list' => [ |
|
| 495 | - 'nav' => [ |
|
| 496 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 497 | - 'order' => 20, |
|
| 498 | - ], |
|
| 499 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 500 | - 'help_tabs' => [ |
|
| 501 | - 'events_categories_help_tab' => [ |
|
| 502 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 503 | - 'filename' => 'events_categories', |
|
| 504 | - ], |
|
| 505 | - 'events_categories_table_column_headings_help_tab' => [ |
|
| 506 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 507 | - 'filename' => 'events_categories_table_column_headings', |
|
| 508 | - ], |
|
| 509 | - 'events_categories_view_help_tab' => [ |
|
| 510 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 511 | - 'filename' => 'events_categories_views', |
|
| 512 | - ], |
|
| 513 | - 'events_categories_other_help_tab' => [ |
|
| 514 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 515 | - 'filename' => 'events_categories_other', |
|
| 516 | - ], |
|
| 517 | - ], |
|
| 518 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 519 | - // 'help_tour' => [ |
|
| 520 | - // 'Event_Categories_Help_Tour', |
|
| 521 | - // ], |
|
| 522 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 523 | - 'require_nonce' => false, |
|
| 524 | - ], |
|
| 525 | - 'preview_deletion' => [ |
|
| 526 | - 'nav' => [ |
|
| 527 | - 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 528 | - 'order' => 15, |
|
| 529 | - 'persistent' => false, |
|
| 530 | - 'url' => '', |
|
| 531 | - ], |
|
| 532 | - 'require_nonce' => false, |
|
| 533 | - ], |
|
| 534 | - ]; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 540 | - */ |
|
| 541 | - protected function _add_screen_options() |
|
| 542 | - { |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Implementing the screen options for the 'default' route. |
|
| 548 | - * |
|
| 549 | - * @throws InvalidArgumentException |
|
| 550 | - * @throws InvalidDataTypeException |
|
| 551 | - * @throws InvalidInterfaceException |
|
| 552 | - */ |
|
| 553 | - protected function _add_screen_options_default() |
|
| 554 | - { |
|
| 555 | - $this->_per_page_screen_option(); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Implementing screen options for the category list route. |
|
| 561 | - * |
|
| 562 | - * @throws InvalidArgumentException |
|
| 563 | - * @throws InvalidDataTypeException |
|
| 564 | - * @throws InvalidInterfaceException |
|
| 565 | - */ |
|
| 566 | - protected function _add_screen_options_category_list() |
|
| 567 | - { |
|
| 568 | - $page_title = $this->_admin_page_title; |
|
| 569 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 570 | - $this->_per_page_screen_option(); |
|
| 571 | - $this->_admin_page_title = $page_title; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Used to register any global feature pointers for the admin page group. |
|
| 577 | - */ |
|
| 578 | - protected function _add_feature_pointers() |
|
| 579 | - { |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 585 | - */ |
|
| 586 | - public function load_scripts_styles() |
|
| 587 | - { |
|
| 588 | - wp_register_style( |
|
| 589 | - 'events-admin-css', |
|
| 590 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 591 | - [], |
|
| 592 | - EVENT_ESPRESSO_VERSION |
|
| 593 | - ); |
|
| 594 | - wp_register_style( |
|
| 595 | - 'ee-cat-admin', |
|
| 596 | - EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 597 | - [], |
|
| 598 | - EVENT_ESPRESSO_VERSION |
|
| 599 | - ); |
|
| 600 | - wp_enqueue_style('events-admin-css'); |
|
| 601 | - wp_enqueue_style('ee-cat-admin'); |
|
| 602 | - // scripts |
|
| 603 | - wp_register_script( |
|
| 604 | - 'event_editor_js', |
|
| 605 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 606 | - ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 607 | - EVENT_ESPRESSO_VERSION, |
|
| 608 | - true |
|
| 609 | - ); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Enqueuing scripts and styles specific to this view |
|
| 615 | - */ |
|
| 616 | - public function load_scripts_styles_create_new() |
|
| 617 | - { |
|
| 618 | - $this->load_scripts_styles_edit(); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * Enqueuing scripts and styles specific to this view |
|
| 624 | - */ |
|
| 625 | - public function load_scripts_styles_edit() |
|
| 626 | - { |
|
| 627 | - // styles |
|
| 628 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 629 | - wp_register_style( |
|
| 630 | - 'event-editor-css', |
|
| 631 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 632 | - ['ee-admin-css'], |
|
| 633 | - EVENT_ESPRESSO_VERSION |
|
| 634 | - ); |
|
| 635 | - wp_enqueue_style('event-editor-css'); |
|
| 636 | - // scripts |
|
| 637 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 638 | - wp_register_script( |
|
| 639 | - 'event-datetime-metabox', |
|
| 640 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 641 | - ['event_editor_js', 'ee-datepicker'], |
|
| 642 | - EVENT_ESPRESSO_VERSION |
|
| 643 | - ); |
|
| 644 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * Populating the _views property for the category list table view. |
|
| 651 | - */ |
|
| 652 | - protected function _set_list_table_views_category_list() |
|
| 653 | - { |
|
| 654 | - $this->_views = [ |
|
| 655 | - 'all' => [ |
|
| 656 | - 'slug' => 'all', |
|
| 657 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 658 | - 'count' => 0, |
|
| 659 | - 'bulk_action' => [ |
|
| 660 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 661 | - ], |
|
| 662 | - ], |
|
| 663 | - ]; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 669 | - */ |
|
| 670 | - public function admin_init() |
|
| 671 | - { |
|
| 672 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 673 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 674 | - 'event_espresso' |
|
| 675 | - ); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 681 | - * group. |
|
| 682 | - */ |
|
| 683 | - public function admin_notices() |
|
| 684 | - { |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 690 | - * this admin page group. |
|
| 691 | - */ |
|
| 692 | - public function admin_footer_scripts() |
|
| 693 | - { |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 699 | - * warning (via EE_Error::add_error()); |
|
| 700 | - * |
|
| 701 | - * @param EE_Event $event Event object |
|
| 702 | - * @param string $req_type |
|
| 703 | - * @return void |
|
| 704 | - * @throws EE_Error |
|
| 705 | - * @throws ReflectionException |
|
| 706 | - */ |
|
| 707 | - public function verify_event_edit($event = null, $req_type = '') |
|
| 708 | - { |
|
| 709 | - // don't need to do this when processing |
|
| 710 | - if (! empty($req_type)) { |
|
| 711 | - return; |
|
| 712 | - } |
|
| 713 | - // no event? |
|
| 714 | - if (! $event instanceof EE_Event) { |
|
| 715 | - $event = $this->_cpt_model_obj; |
|
| 716 | - } |
|
| 717 | - // STILL no event? |
|
| 718 | - if (! $event instanceof EE_Event) { |
|
| 719 | - return; |
|
| 720 | - } |
|
| 721 | - $orig_status = $event->status(); |
|
| 722 | - // first check if event is active. |
|
| 723 | - if ( |
|
| 724 | - $orig_status === EEM_Event::cancelled |
|
| 725 | - || $orig_status === EEM_Event::postponed |
|
| 726 | - || $event->is_expired() |
|
| 727 | - || $event->is_inactive() |
|
| 728 | - ) { |
|
| 729 | - return; |
|
| 730 | - } |
|
| 731 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
| 732 | - if ($event->is_sold_out(true)) { |
|
| 733 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 734 | - EE_Error::add_attention( |
|
| 735 | - sprintf( |
|
| 736 | - esc_html__( |
|
| 737 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 738 | - 'event_espresso' |
|
| 739 | - ), |
|
| 740 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 741 | - ) |
|
| 742 | - ); |
|
| 743 | - } |
|
| 744 | - return; |
|
| 745 | - } |
|
| 746 | - if ($orig_status === EEM_Event::sold_out) { |
|
| 747 | - EE_Error::add_attention( |
|
| 748 | - sprintf( |
|
| 749 | - esc_html__( |
|
| 750 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 751 | - 'event_espresso' |
|
| 752 | - ), |
|
| 753 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 754 | - ) |
|
| 755 | - ); |
|
| 756 | - } |
|
| 757 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 758 | - if (! $event->tickets_on_sale()) { |
|
| 759 | - return; |
|
| 760 | - } |
|
| 761 | - // made it here so show warning |
|
| 762 | - $this->_edit_event_warning(); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 768 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 769 | - * |
|
| 770 | - * @access protected |
|
| 771 | - * @return void |
|
| 772 | - */ |
|
| 773 | - protected function _edit_event_warning() |
|
| 774 | - { |
|
| 775 | - // we don't want to add warnings during these requests |
|
| 776 | - if ($this->request->getRequestParam('action') === 'editpost') { |
|
| 777 | - return; |
|
| 778 | - } |
|
| 779 | - EE_Error::add_attention( |
|
| 780 | - sprintf( |
|
| 781 | - esc_html__( |
|
| 782 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 783 | - 'event_espresso' |
|
| 784 | - ), |
|
| 785 | - '<a class="espresso-help-tab-lnk">', |
|
| 786 | - '</a>' |
|
| 787 | - ) |
|
| 788 | - ); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 794 | - * Otherwise, do the normal logic |
|
| 795 | - * |
|
| 796 | - * @return void |
|
| 797 | - * @throws EE_Error |
|
| 798 | - * @throws InvalidArgumentException |
|
| 799 | - * @throws InvalidDataTypeException |
|
| 800 | - * @throws InvalidInterfaceException |
|
| 801 | - */ |
|
| 802 | - protected function _create_new_cpt_item() |
|
| 803 | - { |
|
| 804 | - $has_timezone_string = get_option('timezone_string'); |
|
| 805 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 806 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 807 | - EE_Error::add_attention( |
|
| 808 | - sprintf( |
|
| 809 | - esc_html__( |
|
| 810 | - 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
| 811 | - 'event_espresso' |
|
| 812 | - ), |
|
| 813 | - '<br>', |
|
| 814 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 815 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 816 | - . '</select>', |
|
| 817 | - '<button class="button button--secondary timezone-submit">', |
|
| 818 | - '</button><span class="spinner"></span>' |
|
| 819 | - ), |
|
| 820 | - __FILE__, |
|
| 821 | - __FUNCTION__, |
|
| 822 | - __LINE__ |
|
| 823 | - ); |
|
| 824 | - } |
|
| 825 | - parent::_create_new_cpt_item(); |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * Sets the _views property for the default route in this admin page group. |
|
| 831 | - */ |
|
| 832 | - protected function _set_list_table_views_default() |
|
| 833 | - { |
|
| 834 | - $this->_views = [ |
|
| 835 | - 'all' => [ |
|
| 836 | - 'slug' => 'all', |
|
| 837 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 838 | - 'count' => 0, |
|
| 839 | - 'bulk_action' => [ |
|
| 840 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 841 | - ], |
|
| 842 | - ], |
|
| 843 | - 'draft' => [ |
|
| 844 | - 'slug' => 'draft', |
|
| 845 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 846 | - 'count' => 0, |
|
| 847 | - 'bulk_action' => [ |
|
| 848 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 849 | - ], |
|
| 850 | - ], |
|
| 851 | - ]; |
|
| 852 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 853 | - $this->_views['trash'] = [ |
|
| 854 | - 'slug' => 'trash', |
|
| 855 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 856 | - 'count' => 0, |
|
| 857 | - 'bulk_action' => [ |
|
| 858 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 859 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 860 | - ], |
|
| 861 | - ]; |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * Provides the legend item array for the default list table view. |
|
| 868 | - * |
|
| 869 | - * @return array |
|
| 870 | - * @throws EE_Error |
|
| 871 | - * @throws EE_Error |
|
| 872 | - */ |
|
| 873 | - protected function _event_legend_items() |
|
| 874 | - { |
|
| 875 | - $items = [ |
|
| 876 | - 'view_details' => [ |
|
| 877 | - 'class' => 'dashicons dashicons-search', |
|
| 878 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 879 | - ], |
|
| 880 | - 'edit_event' => [ |
|
| 881 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 882 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 883 | - ], |
|
| 884 | - 'view_attendees' => [ |
|
| 885 | - 'class' => 'dashicons dashicons-groups', |
|
| 886 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 887 | - ], |
|
| 888 | - ]; |
|
| 889 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 890 | - $statuses = [ |
|
| 891 | - 'sold_out_status' => [ |
|
| 892 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::sold_out, |
|
| 893 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 894 | - ], |
|
| 895 | - 'active_status' => [ |
|
| 896 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::active, |
|
| 897 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 898 | - ], |
|
| 899 | - 'upcoming_status' => [ |
|
| 900 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::upcoming, |
|
| 901 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 902 | - ], |
|
| 903 | - 'postponed_status' => [ |
|
| 904 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::postponed, |
|
| 905 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 906 | - ], |
|
| 907 | - 'cancelled_status' => [ |
|
| 908 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::cancelled, |
|
| 909 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 910 | - ], |
|
| 911 | - 'expired_status' => [ |
|
| 912 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::expired, |
|
| 913 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 914 | - ], |
|
| 915 | - 'inactive_status' => [ |
|
| 916 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::inactive, |
|
| 917 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 918 | - ], |
|
| 919 | - ]; |
|
| 920 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 921 | - return array_merge($items, $statuses); |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * @return EEM_Event |
|
| 927 | - * @throws EE_Error |
|
| 928 | - * @throws InvalidArgumentException |
|
| 929 | - * @throws InvalidDataTypeException |
|
| 930 | - * @throws InvalidInterfaceException |
|
| 931 | - * @throws ReflectionException |
|
| 932 | - */ |
|
| 933 | - private function _event_model() |
|
| 934 | - { |
|
| 935 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 936 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 937 | - } |
|
| 938 | - return $this->_event_model; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 944 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 945 | - * |
|
| 946 | - * @param string $return the current html |
|
| 947 | - * @param int $id the post id for the page |
|
| 948 | - * @param string $new_title What the title is |
|
| 949 | - * @param string $new_slug what the slug is |
|
| 950 | - * @return string The new html string for the permalink area |
|
| 951 | - */ |
|
| 952 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 953 | - { |
|
| 954 | - // make sure this is only when editing |
|
| 955 | - if (! empty($id)) { |
|
| 956 | - $post = get_post($id); |
|
| 957 | - $return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 958 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 959 | - . '</a> '; |
|
| 960 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 961 | - . $post->ID |
|
| 962 | - . ']">'; |
|
| 963 | - } |
|
| 964 | - return $return; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - |
|
| 968 | - /** |
|
| 969 | - * _events_overview_list_table |
|
| 970 | - * This contains the logic for showing the events_overview list |
|
| 971 | - * |
|
| 972 | - * @access protected |
|
| 973 | - * @return void |
|
| 974 | - * @throws DomainException |
|
| 975 | - * @throws EE_Error |
|
| 976 | - * @throws InvalidArgumentException |
|
| 977 | - * @throws InvalidDataTypeException |
|
| 978 | - * @throws InvalidInterfaceException |
|
| 979 | - */ |
|
| 980 | - protected function _events_overview_list_table() |
|
| 981 | - { |
|
| 982 | - $after_list_table = []; |
|
| 983 | - $after_list_table['view_event_list_button'] = EEH_HTML::div( |
|
| 984 | - EEH_Template::get_button_or_link( |
|
| 985 | - get_post_type_archive_link('espresso_events'), |
|
| 986 | - esc_html__('View Event Archive Page', 'event_espresso'), |
|
| 987 | - 'button button--small button--secondary' |
|
| 988 | - ), |
|
| 989 | - '', |
|
| 990 | - 'ee-admin-button-row' |
|
| 991 | - ); |
|
| 992 | - |
|
| 993 | - $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 994 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 995 | - 'create_new', |
|
| 996 | - 'add', |
|
| 997 | - [], |
|
| 998 | - 'add-new-h2' |
|
| 999 | - ); |
|
| 1000 | - |
|
| 1001 | - $this->_template_args['after_list_table'] = array_merge( |
|
| 1002 | - (array) $this->_template_args['after_list_table'], |
|
| 1003 | - $after_list_table |
|
| 1004 | - ); |
|
| 1005 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - |
|
| 1009 | - /** |
|
| 1010 | - * this allows for extra misc actions in the default WP publish box |
|
| 1011 | - * |
|
| 1012 | - * @return void |
|
| 1013 | - * @throws DomainException |
|
| 1014 | - * @throws EE_Error |
|
| 1015 | - * @throws InvalidArgumentException |
|
| 1016 | - * @throws InvalidDataTypeException |
|
| 1017 | - * @throws InvalidInterfaceException |
|
| 1018 | - * @throws ReflectionException |
|
| 1019 | - */ |
|
| 1020 | - public function extra_misc_actions_publish_box() |
|
| 1021 | - { |
|
| 1022 | - $this->_generate_publish_box_extra_content(); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - |
|
| 1026 | - /** |
|
| 1027 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1028 | - * saved. |
|
| 1029 | - * Typically you would use this to save any additional data. |
|
| 1030 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1031 | - * ALSO very important. When a post transitions from scheduled to published, |
|
| 1032 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1033 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1034 | - * |
|
| 1035 | - * @access protected |
|
| 1036 | - * @abstract |
|
| 1037 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1038 | - * @param object $post The post object of the cpt that was saved. |
|
| 1039 | - * @return void |
|
| 1040 | - * @throws EE_Error |
|
| 1041 | - * @throws InvalidArgumentException |
|
| 1042 | - * @throws InvalidDataTypeException |
|
| 1043 | - * @throws InvalidInterfaceException |
|
| 1044 | - * @throws ReflectionException |
|
| 1045 | - */ |
|
| 1046 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 1047 | - { |
|
| 1048 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1049 | - // get out we're not processing an event save. |
|
| 1050 | - return; |
|
| 1051 | - } |
|
| 1052 | - $event_values = [ |
|
| 1053 | - 'EVT_member_only' => $this->request->getRequestParam('member_only', false, 'bool'), |
|
| 1054 | - 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'), |
|
| 1055 | - 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
| 1056 | - ]; |
|
| 1057 | - // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
| 1058 | - if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1059 | - $event_values['EVT_display_ticket_selector'] = $this->request->getRequestParam( |
|
| 1060 | - 'display_ticket_selector', |
|
| 1061 | - false, |
|
| 1062 | - 'bool' |
|
| 1063 | - ); |
|
| 1064 | - $event_values['EVT_additional_limit'] = min( |
|
| 1065 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1066 | - $this->request->getRequestParam('additional_limit', null, 'int') |
|
| 1067 | - ); |
|
| 1068 | - $event_values['EVT_default_registration_status'] = $this->request->getRequestParam( |
|
| 1069 | - 'EVT_default_registration_status', |
|
| 1070 | - EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 1071 | - ); |
|
| 1072 | - |
|
| 1073 | - $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL'); |
|
| 1074 | - $event_values['EVT_phone'] = $this->request->getRequestParam('event_phone'); |
|
| 1075 | - $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool'); |
|
| 1076 | - } |
|
| 1077 | - // update event |
|
| 1078 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1079 | - // get event_object for other metaboxes... |
|
| 1080 | - // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
| 1081 | - // i have to setup where conditions to override the filters in the model |
|
| 1082 | - // that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 1083 | - $event = $this->_event_model()->get_one( |
|
| 1084 | - [ |
|
| 1085 | - [ |
|
| 1086 | - $this->_event_model()->primary_key_name() => $post_id, |
|
| 1087 | - 'OR' => [ |
|
| 1088 | - 'status' => $post->post_status, |
|
| 1089 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1090 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1091 | - 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
| 1092 | - ], |
|
| 1093 | - ], |
|
| 1094 | - ] |
|
| 1095 | - ); |
|
| 1096 | - |
|
| 1097 | - // the following are default callbacks for event attachment updates |
|
| 1098 | - // that can be overridden by caffeinated functionality and/or addons. |
|
| 1099 | - $event_update_callbacks = []; |
|
| 1100 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 1101 | - $event_update_callbacks['_default_venue_update'] = [$this, '_default_venue_update']; |
|
| 1102 | - $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update']; |
|
| 1103 | - } |
|
| 1104 | - $event_update_callbacks = apply_filters( |
|
| 1105 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1106 | - $event_update_callbacks |
|
| 1107 | - ); |
|
| 1108 | - |
|
| 1109 | - $att_success = true; |
|
| 1110 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 1111 | - $_success = is_callable($e_callback) |
|
| 1112 | - ? $e_callback($event, $this->request->requestParams()) |
|
| 1113 | - : false; |
|
| 1114 | - // if ANY of these updates fail then we want the appropriate global error message |
|
| 1115 | - $att_success = $_success !== false ? $att_success : false; |
|
| 1116 | - } |
|
| 1117 | - // any errors? |
|
| 1118 | - if ($success && $att_success === false) { |
|
| 1119 | - EE_Error::add_error( |
|
| 1120 | - esc_html__( |
|
| 1121 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1122 | - 'event_espresso' |
|
| 1123 | - ), |
|
| 1124 | - __FILE__, |
|
| 1125 | - __FUNCTION__, |
|
| 1126 | - __LINE__ |
|
| 1127 | - ); |
|
| 1128 | - } elseif ($success === false) { |
|
| 1129 | - EE_Error::add_error( |
|
| 1130 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1131 | - __FILE__, |
|
| 1132 | - __FUNCTION__, |
|
| 1133 | - __LINE__ |
|
| 1134 | - ); |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - |
|
| 1139 | - /** |
|
| 1140 | - * @param int $post_id |
|
| 1141 | - * @param int $revision_id |
|
| 1142 | - * @throws EE_Error |
|
| 1143 | - * @throws EE_Error |
|
| 1144 | - * @throws ReflectionException |
|
| 1145 | - * @see parent::restore_item() |
|
| 1146 | - */ |
|
| 1147 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1148 | - { |
|
| 1149 | - // copy existing event meta to new post |
|
| 1150 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1151 | - if ($post_evt instanceof EE_Event) { |
|
| 1152 | - // meta revision restore |
|
| 1153 | - $post_evt->restore_revision($revision_id); |
|
| 1154 | - // related objs restore |
|
| 1155 | - $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1156 | - } |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - |
|
| 1160 | - /** |
|
| 1161 | - * Attach the venue to the Event |
|
| 1162 | - * |
|
| 1163 | - * @param EE_Event $event Event Object to add the venue to |
|
| 1164 | - * @param array $data The request data from the form |
|
| 1165 | - * @return bool Success or fail. |
|
| 1166 | - * @throws EE_Error |
|
| 1167 | - * @throws ReflectionException |
|
| 1168 | - */ |
|
| 1169 | - protected function _default_venue_update(EE_Event $event, $data) |
|
| 1170 | - { |
|
| 1171 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1172 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1173 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1174 | - // very important. If we don't have a venue name... |
|
| 1175 | - // then we'll get out because not necessary to create empty venue |
|
| 1176 | - if (empty($data['venue_title'])) { |
|
| 1177 | - return false; |
|
| 1178 | - } |
|
| 1179 | - $venue_array = [ |
|
| 1180 | - 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
| 1181 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1182 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1183 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1184 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
| 1185 | - ? $data['venue_short_description'] |
|
| 1186 | - : null, |
|
| 1187 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1188 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1189 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1190 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1191 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1192 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1193 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1194 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1195 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1196 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1197 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1198 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1199 | - 'status' => 'publish', |
|
| 1200 | - ]; |
|
| 1201 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1202 | - if (! empty($venue_id)) { |
|
| 1203 | - $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1204 | - $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1205 | - // we've gotta make sure that the venue is always attached to a revision.. |
|
| 1206 | - // add_relation_to should take care of making sure that the relation is already present. |
|
| 1207 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1208 | - return $rows_affected > 0; |
|
| 1209 | - } |
|
| 1210 | - // we insert the venue |
|
| 1211 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1212 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1213 | - return ! empty($venue_id); |
|
| 1214 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1220 | - * |
|
| 1221 | - * @param EE_Event $event The Event object we're attaching data to |
|
| 1222 | - * @param array $data The request data from the form |
|
| 1223 | - * @return array |
|
| 1224 | - * @throws EE_Error |
|
| 1225 | - * @throws ReflectionException |
|
| 1226 | - * @throws Exception |
|
| 1227 | - */ |
|
| 1228 | - protected function _default_tickets_update(EE_Event $event, $data) |
|
| 1229 | - { |
|
| 1230 | - if ($this->admin_config->useAdvancedEditor()) { |
|
| 1231 | - return []; |
|
| 1232 | - } |
|
| 1233 | - $datetime = null; |
|
| 1234 | - $saved_tickets = []; |
|
| 1235 | - $event_timezone = $event->get_timezone(); |
|
| 1236 | - $date_formats = ['Y-m-d', 'h:i a']; |
|
| 1237 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 1238 | - // trim all values to ensure any excess whitespace is removed. |
|
| 1239 | - $datetime_data = array_map('trim', $datetime_data); |
|
| 1240 | - $datetime_data['DTT_EVT_end'] = |
|
| 1241 | - isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
|
| 1242 | - ? $datetime_data['DTT_EVT_end'] |
|
| 1243 | - : $datetime_data['DTT_EVT_start']; |
|
| 1244 | - $datetime_values = [ |
|
| 1245 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
| 1246 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 1247 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 1248 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
| 1249 | - 'DTT_order' => $row, |
|
| 1250 | - ]; |
|
| 1251 | - // if we have an id then let's get existing object first and then set the new values. |
|
| 1252 | - // Otherwise we instantiate a new object for save. |
|
| 1253 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 1254 | - $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 1255 | - if (! $datetime instanceof EE_Ticket) { |
|
| 1256 | - throw new RuntimeException( |
|
| 1257 | - sprintf( |
|
| 1258 | - esc_html__( |
|
| 1259 | - 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1260 | - 'event_espresso' |
|
| 1261 | - ), |
|
| 1262 | - $datetime_data['DTT_ID'] |
|
| 1263 | - ) |
|
| 1264 | - ); |
|
| 1265 | - } |
|
| 1266 | - $datetime->set_date_format($date_formats[0]); |
|
| 1267 | - $datetime->set_time_format($date_formats[1]); |
|
| 1268 | - foreach ($datetime_values as $field => $value) { |
|
| 1269 | - $datetime->set($field, $value); |
|
| 1270 | - } |
|
| 1271 | - } else { |
|
| 1272 | - $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
| 1273 | - } |
|
| 1274 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1275 | - throw new RuntimeException( |
|
| 1276 | - sprintf( |
|
| 1277 | - esc_html__( |
|
| 1278 | - 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
| 1279 | - 'event_espresso' |
|
| 1280 | - ), |
|
| 1281 | - print_r($datetime_values, true) |
|
| 1282 | - ) |
|
| 1283 | - ); |
|
| 1284 | - } |
|
| 1285 | - // before going any further make sure our dates are setup correctly |
|
| 1286 | - // so that the end date is always equal or greater than the start date. |
|
| 1287 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 1288 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 1289 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 1290 | - } |
|
| 1291 | - $datetime->save(); |
|
| 1292 | - $event->_add_relation_to($datetime, 'Datetime'); |
|
| 1293 | - } |
|
| 1294 | - // no datetimes get deleted so we don't do any of that logic here. |
|
| 1295 | - // update tickets next |
|
| 1296 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1297 | - |
|
| 1298 | - // set up some default start and end dates in case those are not present in the incoming data |
|
| 1299 | - $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 1300 | - $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
| 1301 | - // use the start date of the first datetime for the end date |
|
| 1302 | - $first_datetime = $event->first_datetime(); |
|
| 1303 | - $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
| 1304 | - |
|
| 1305 | - // now process the incoming data |
|
| 1306 | - foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
| 1307 | - $update_prices = false; |
|
| 1308 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1309 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
| 1310 | - : 0; |
|
| 1311 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1312 | - $ticket_data = array_map('trim', $ticket_data); |
|
| 1313 | - $ticket_values = [ |
|
| 1314 | - 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
| 1315 | - 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
| 1316 | - 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
| 1317 | - 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
| 1318 | - 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
| 1319 | - ? $ticket_data['TKT_start_date'] |
|
| 1320 | - : $default_start_date, |
|
| 1321 | - 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
| 1322 | - ? $ticket_data['TKT_end_date'] |
|
| 1323 | - : $default_end_date, |
|
| 1324 | - 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
| 1325 | - || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
| 1326 | - ? $ticket_data['TKT_qty'] |
|
| 1327 | - : EE_INF, |
|
| 1328 | - 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
| 1329 | - || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
| 1330 | - ? $ticket_data['TKT_uses'] |
|
| 1331 | - : EE_INF, |
|
| 1332 | - 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
| 1333 | - 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
| 1334 | - 'TKT_order' => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row, |
|
| 1335 | - 'TKT_price' => $ticket_price, |
|
| 1336 | - 'TKT_row' => $row, |
|
| 1337 | - ]; |
|
| 1338 | - // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 1339 | - // which means in turn that the prices will become new prices as well. |
|
| 1340 | - if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
| 1341 | - $ticket_values['TKT_ID'] = 0; |
|
| 1342 | - $ticket_values['TKT_is_default'] = 0; |
|
| 1343 | - $update_prices = true; |
|
| 1344 | - } |
|
| 1345 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1346 | - // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
| 1347 | - // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
| 1348 | - // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
| 1349 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1350 | - if (! empty($ticket_data['TKT_ID'])) { |
|
| 1351 | - $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
| 1352 | - if (! $existing_ticket instanceof EE_Ticket) { |
|
| 1353 | - throw new RuntimeException( |
|
| 1354 | - sprintf( |
|
| 1355 | - esc_html__( |
|
| 1356 | - 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1357 | - 'event_espresso' |
|
| 1358 | - ), |
|
| 1359 | - $ticket_data['TKT_ID'] |
|
| 1360 | - ) |
|
| 1361 | - ); |
|
| 1362 | - } |
|
| 1363 | - $ticket_sold = $existing_ticket->count_related( |
|
| 1364 | - 'Registration', |
|
| 1365 | - [ |
|
| 1366 | - [ |
|
| 1367 | - 'STS_ID' => [ |
|
| 1368 | - 'NOT IN', |
|
| 1369 | - [EEM_Registration::status_id_incomplete], |
|
| 1370 | - ], |
|
| 1371 | - ], |
|
| 1372 | - ] |
|
| 1373 | - ) > 0; |
|
| 1374 | - // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
| 1375 | - // if they are different then we create a new ticket (if $ticket_sold) |
|
| 1376 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 1377 | - $create_new_ticket = $ticket_sold |
|
| 1378 | - && $ticket_price !== $existing_ticket->price() |
|
| 1379 | - && ! $existing_ticket->deleted(); |
|
| 1380 | - $existing_ticket->set_date_format($date_formats[0]); |
|
| 1381 | - $existing_ticket->set_time_format($date_formats[1]); |
|
| 1382 | - // set new values |
|
| 1383 | - foreach ($ticket_values as $field => $value) { |
|
| 1384 | - if ($field == 'TKT_qty') { |
|
| 1385 | - $existing_ticket->set_qty($value); |
|
| 1386 | - } elseif ($field == 'TKT_price') { |
|
| 1387 | - $existing_ticket->set('TKT_price', $ticket_price); |
|
| 1388 | - } else { |
|
| 1389 | - $existing_ticket->set($field, $value); |
|
| 1390 | - } |
|
| 1391 | - } |
|
| 1392 | - $ticket = $existing_ticket; |
|
| 1393 | - // if $create_new_ticket is false then we can safely update the existing ticket. |
|
| 1394 | - // Otherwise we have to create a new ticket. |
|
| 1395 | - if ($create_new_ticket) { |
|
| 1396 | - // archive the old ticket first |
|
| 1397 | - $existing_ticket->set('TKT_deleted', 1); |
|
| 1398 | - $existing_ticket->save(); |
|
| 1399 | - // make sure this ticket is still recorded in our $saved_tickets |
|
| 1400 | - // so we don't run it through the regular trash routine. |
|
| 1401 | - $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
| 1402 | - // create new ticket that's a copy of the existing except, |
|
| 1403 | - // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
| 1404 | - $new_ticket = clone $existing_ticket; |
|
| 1405 | - $new_ticket->set('TKT_ID', 0); |
|
| 1406 | - $new_ticket->set('TKT_deleted', 0); |
|
| 1407 | - $new_ticket->set('TKT_sold', 0); |
|
| 1408 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1409 | - $update_prices = true; |
|
| 1410 | - $ticket = $new_ticket; |
|
| 1411 | - } |
|
| 1412 | - } else { |
|
| 1413 | - // no TKT_id so a new ticket |
|
| 1414 | - $ticket_values['TKT_price'] = $ticket_price; |
|
| 1415 | - $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
| 1416 | - $update_prices = true; |
|
| 1417 | - } |
|
| 1418 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1419 | - throw new RuntimeException( |
|
| 1420 | - sprintf( |
|
| 1421 | - esc_html__( |
|
| 1422 | - 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
| 1423 | - 'event_espresso' |
|
| 1424 | - ), |
|
| 1425 | - print_r($ticket_values, true) |
|
| 1426 | - ) |
|
| 1427 | - ); |
|
| 1428 | - } |
|
| 1429 | - // cap ticket qty by datetime reg limits |
|
| 1430 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 1431 | - // update ticket. |
|
| 1432 | - $ticket->save(); |
|
| 1433 | - // before going any further make sure our dates are setup correctly |
|
| 1434 | - // so that the end date is always equal or greater than the start date. |
|
| 1435 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 1436 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 1437 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 1438 | - $ticket->save(); |
|
| 1439 | - } |
|
| 1440 | - // initially let's add the ticket to the datetime |
|
| 1441 | - $datetime->_add_relation_to($ticket, 'Ticket'); |
|
| 1442 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 1443 | - // add prices to ticket |
|
| 1444 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices); |
|
| 1445 | - } |
|
| 1446 | - // however now we need to handle permanently deleting tickets via the ui. |
|
| 1447 | - // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
| 1448 | - // However, it does allow for deleting tickets that have no tickets sold, |
|
| 1449 | - // in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1450 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
| 1451 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1452 | - foreach ($tickets_removed as $id) { |
|
| 1453 | - $id = absint($id); |
|
| 1454 | - // get the ticket for this id |
|
| 1455 | - $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
| 1456 | - if (! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1457 | - continue; |
|
| 1458 | - } |
|
| 1459 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 1460 | - // (remember this process can ONLY kick off if there are NO tickets sold) |
|
| 1461 | - $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
| 1462 | - foreach ($related_datetimes as $related_datetime) { |
|
| 1463 | - $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
| 1464 | - } |
|
| 1465 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 1466 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1467 | - $ticket_to_remove->delete_related_permanently('Price'); |
|
| 1468 | - // finally let's delete this ticket |
|
| 1469 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1470 | - $ticket_to_remove->delete_permanently(); |
|
| 1471 | - } |
|
| 1472 | - return [$datetime, $saved_tickets]; |
|
| 1473 | - } |
|
| 1474 | - |
|
| 1475 | - |
|
| 1476 | - /** |
|
| 1477 | - * This attaches a list of given prices to a ticket. |
|
| 1478 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) |
|
| 1479 | - * because if there is a change in price information on a ticket, a new ticket is created anyways |
|
| 1480 | - * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket. |
|
| 1481 | - * |
|
| 1482 | - * @access private |
|
| 1483 | - * @param array $prices_data Array of prices from the form. |
|
| 1484 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1485 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1486 | - * @return void |
|
| 1487 | - * @throws EE_Error |
|
| 1488 | - * @throws ReflectionException |
|
| 1489 | - */ |
|
| 1490 | - private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false) |
|
| 1491 | - { |
|
| 1492 | - $timezone = $ticket->get_timezone(); |
|
| 1493 | - foreach ($prices_data as $row => $price_data) { |
|
| 1494 | - $price_values = [ |
|
| 1495 | - 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
| 1496 | - 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
| 1497 | - 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
| 1498 | - 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
| 1499 | - 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
| 1500 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1501 | - 'PRC_order' => $row, |
|
| 1502 | - ]; |
|
| 1503 | - if ($new_prices || empty($price_values['PRC_ID'])) { |
|
| 1504 | - $price_values['PRC_ID'] = 0; |
|
| 1505 | - $price = EE_Price::new_instance($price_values, $timezone); |
|
| 1506 | - } else { |
|
| 1507 | - $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
| 1508 | - // update this price with new values |
|
| 1509 | - foreach ($price_values as $field => $new_price) { |
|
| 1510 | - $price->set($field, $new_price); |
|
| 1511 | - } |
|
| 1512 | - } |
|
| 1513 | - if (! $price instanceof EE_Price) { |
|
| 1514 | - throw new RuntimeException( |
|
| 1515 | - sprintf( |
|
| 1516 | - esc_html__( |
|
| 1517 | - 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
| 1518 | - 'event_espresso' |
|
| 1519 | - ), |
|
| 1520 | - print_r($price_values, true) |
|
| 1521 | - ) |
|
| 1522 | - ); |
|
| 1523 | - } |
|
| 1524 | - $price->save(); |
|
| 1525 | - $ticket->_add_relation_to($price, 'Price'); |
|
| 1526 | - } |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - /** |
|
| 1531 | - * Add in our autosave ajax handlers |
|
| 1532 | - * |
|
| 1533 | - */ |
|
| 1534 | - protected function _ee_autosave_create_new() |
|
| 1535 | - { |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - |
|
| 1539 | - /** |
|
| 1540 | - * More autosave handlers. |
|
| 1541 | - */ |
|
| 1542 | - protected function _ee_autosave_edit() |
|
| 1543 | - { |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - |
|
| 1547 | - /** |
|
| 1548 | - * @throws EE_Error |
|
| 1549 | - * @throws ReflectionException |
|
| 1550 | - */ |
|
| 1551 | - private function _generate_publish_box_extra_content() |
|
| 1552 | - { |
|
| 1553 | - // load formatter helper |
|
| 1554 | - // args for getting related registrations |
|
| 1555 | - $approved_query_args = [ |
|
| 1556 | - [ |
|
| 1557 | - 'REG_deleted' => 0, |
|
| 1558 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1559 | - ], |
|
| 1560 | - ]; |
|
| 1561 | - $not_approved_query_args = [ |
|
| 1562 | - [ |
|
| 1563 | - 'REG_deleted' => 0, |
|
| 1564 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1565 | - ], |
|
| 1566 | - ]; |
|
| 1567 | - $pending_payment_query_args = [ |
|
| 1568 | - [ |
|
| 1569 | - 'REG_deleted' => 0, |
|
| 1570 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1571 | - ], |
|
| 1572 | - ]; |
|
| 1573 | - // publish box |
|
| 1574 | - $publish_box_extra_args = [ |
|
| 1575 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1576 | - [ |
|
| 1577 | - 'action' => 'default', |
|
| 1578 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1579 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1580 | - ], |
|
| 1581 | - REG_ADMIN_URL |
|
| 1582 | - ), |
|
| 1583 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1584 | - [ |
|
| 1585 | - 'action' => 'default', |
|
| 1586 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1587 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1588 | - ], |
|
| 1589 | - REG_ADMIN_URL |
|
| 1590 | - ), |
|
| 1591 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1592 | - [ |
|
| 1593 | - 'action' => 'default', |
|
| 1594 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1595 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1596 | - ], |
|
| 1597 | - REG_ADMIN_URL |
|
| 1598 | - ), |
|
| 1599 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1600 | - 'Registration', |
|
| 1601 | - $approved_query_args |
|
| 1602 | - ), |
|
| 1603 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1604 | - 'Registration', |
|
| 1605 | - $not_approved_query_args |
|
| 1606 | - ), |
|
| 1607 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1608 | - 'Registration', |
|
| 1609 | - $pending_payment_query_args |
|
| 1610 | - ), |
|
| 1611 | - 'misc_pub_section_class' => apply_filters( |
|
| 1612 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1613 | - 'misc-pub-section' |
|
| 1614 | - ), |
|
| 1615 | - ]; |
|
| 1616 | - ob_start(); |
|
| 1617 | - do_action( |
|
| 1618 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1619 | - $this->_cpt_model_obj |
|
| 1620 | - ); |
|
| 1621 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1622 | - // load template |
|
| 1623 | - EEH_Template::display_template( |
|
| 1624 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1625 | - $publish_box_extra_args |
|
| 1626 | - ); |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * @return EE_Event |
|
| 1632 | - */ |
|
| 1633 | - public function get_event_object() |
|
| 1634 | - { |
|
| 1635 | - return $this->_cpt_model_obj; |
|
| 1636 | - } |
|
| 1637 | - |
|
| 1638 | - |
|
| 1639 | - |
|
| 1640 | - |
|
| 1641 | - /** METABOXES * */ |
|
| 1642 | - /** |
|
| 1643 | - * _register_event_editor_meta_boxes |
|
| 1644 | - * add all metaboxes related to the event_editor |
|
| 1645 | - * |
|
| 1646 | - * @return void |
|
| 1647 | - * @throws EE_Error |
|
| 1648 | - * @throws ReflectionException |
|
| 1649 | - */ |
|
| 1650 | - protected function _register_event_editor_meta_boxes() |
|
| 1651 | - { |
|
| 1652 | - $this->verify_cpt_object(); |
|
| 1653 | - $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
| 1654 | - // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1655 | - if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1656 | - $this->addMetaBox( |
|
| 1657 | - 'espresso_event_editor_event_options', |
|
| 1658 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1659 | - [$this, 'registration_options_meta_box'], |
|
| 1660 | - $this->page_slug, |
|
| 1661 | - 'side' |
|
| 1662 | - ); |
|
| 1663 | - } |
|
| 1664 | - if (! $use_advanced_editor) { |
|
| 1665 | - $this->addMetaBox( |
|
| 1666 | - 'espresso_event_editor_tickets', |
|
| 1667 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1668 | - [$this, 'ticket_metabox'], |
|
| 1669 | - $this->page_slug, |
|
| 1670 | - 'normal', |
|
| 1671 | - 'high' |
|
| 1672 | - ); |
|
| 1673 | - } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1674 | - add_action( |
|
| 1675 | - 'add_meta_boxes_espresso_events', |
|
| 1676 | - function () { |
|
| 1677 | - global $current_screen; |
|
| 1678 | - remove_meta_box('authordiv', $current_screen, 'normal'); |
|
| 1679 | - }, |
|
| 1680 | - 99 |
|
| 1681 | - ); |
|
| 1682 | - } |
|
| 1683 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1684 | - // where a metabox has a related management page in the admin |
|
| 1685 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1686 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1687 | - } |
|
| 1688 | - |
|
| 1689 | - |
|
| 1690 | - /** |
|
| 1691 | - * @throws DomainException |
|
| 1692 | - * @throws EE_Error |
|
| 1693 | - * @throws ReflectionException |
|
| 1694 | - */ |
|
| 1695 | - public function ticket_metabox() |
|
| 1696 | - { |
|
| 1697 | - $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1698 | - // defaults for template args |
|
| 1699 | - $template_args = [ |
|
| 1700 | - 'existing_datetime_ids' => '', |
|
| 1701 | - 'event_datetime_help_link' => '', |
|
| 1702 | - 'ticket_options_help_link' => '', |
|
| 1703 | - 'time' => null, |
|
| 1704 | - 'ticket_rows' => '', |
|
| 1705 | - 'existing_ticket_ids' => '', |
|
| 1706 | - 'total_ticket_rows' => 1, |
|
| 1707 | - 'ticket_js_structure' => '', |
|
| 1708 | - 'trash_icon' => 'dashicons dashicons-lock', |
|
| 1709 | - 'disabled' => '', |
|
| 1710 | - ]; |
|
| 1711 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1712 | - /** |
|
| 1713 | - * 1. Start with retrieving Datetimes |
|
| 1714 | - * 2. Fore each datetime get related tickets |
|
| 1715 | - * 3. For each ticket get related prices |
|
| 1716 | - */ |
|
| 1717 | - /** @var EEM_Datetime $datetime_model */ |
|
| 1718 | - $datetime_model = EE_Registry::instance()->load_model('Datetime'); |
|
| 1719 | - /** @var EEM_Ticket $datetime_model */ |
|
| 1720 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1721 | - $times = $datetime_model->get_all_event_dates($event_id); |
|
| 1722 | - /** @type EE_Datetime $first_datetime */ |
|
| 1723 | - $first_datetime = reset($times); |
|
| 1724 | - // do we get related tickets? |
|
| 1725 | - if ( |
|
| 1726 | - $first_datetime instanceof EE_Datetime |
|
| 1727 | - && $first_datetime->ID() !== 0 |
|
| 1728 | - ) { |
|
| 1729 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1730 | - $template_args['time'] = $first_datetime; |
|
| 1731 | - $related_tickets = $first_datetime->tickets( |
|
| 1732 | - [ |
|
| 1733 | - ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1734 | - 'default_where_conditions' => 'none', |
|
| 1735 | - ] |
|
| 1736 | - ); |
|
| 1737 | - if (! empty($related_tickets)) { |
|
| 1738 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1739 | - $row = 0; |
|
| 1740 | - foreach ($related_tickets as $ticket) { |
|
| 1741 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1742 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1743 | - $row++; |
|
| 1744 | - } |
|
| 1745 | - } else { |
|
| 1746 | - $template_args['total_ticket_rows'] = 1; |
|
| 1747 | - /** @type EE_Ticket $ticket */ |
|
| 1748 | - $ticket = $ticket_model->create_default_object(); |
|
| 1749 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1750 | - } |
|
| 1751 | - } else { |
|
| 1752 | - $template_args['time'] = $times[0]; |
|
| 1753 | - /** @type EE_Ticket[] $tickets */ |
|
| 1754 | - $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1755 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
| 1756 | - // NOTE: we're just sending the first default row |
|
| 1757 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1758 | - } |
|
| 1759 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1760 | - 'event_editor_event_datetimes_help_tab' |
|
| 1761 | - ); |
|
| 1762 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1763 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1764 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1765 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1766 | - $ticket_model->create_default_object(), |
|
| 1767 | - true |
|
| 1768 | - ); |
|
| 1769 | - $template = apply_filters( |
|
| 1770 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1771 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1772 | - ); |
|
| 1773 | - EEH_Template::display_template($template, $template_args); |
|
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - |
|
| 1777 | - /** |
|
| 1778 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1779 | - * |
|
| 1780 | - * @access private |
|
| 1781 | - * @param EE_Ticket $ticket the ticket object |
|
| 1782 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1783 | - * @param int $row |
|
| 1784 | - * @return string generated html for the ticket row. |
|
| 1785 | - * @throws EE_Error |
|
| 1786 | - * @throws ReflectionException |
|
| 1787 | - */ |
|
| 1788 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1789 | - { |
|
| 1790 | - $template_args = [ |
|
| 1791 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1792 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1793 | - : '', |
|
| 1794 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1795 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1796 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1797 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1798 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1799 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1800 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1801 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1802 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1803 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1804 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1805 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock', |
|
| 1806 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1807 | - : ' disabled=disabled', |
|
| 1808 | - ]; |
|
| 1809 | - $price = $ticket->ID() !== 0 |
|
| 1810 | - ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1811 | - : null; |
|
| 1812 | - $price = $price instanceof EE_Price |
|
| 1813 | - ? $price |
|
| 1814 | - : EEM_Price::instance()->create_default_object(); |
|
| 1815 | - $price_args = [ |
|
| 1816 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1817 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1818 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1819 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1820 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1821 | - ]; |
|
| 1822 | - // make sure we have default start and end dates if skeleton |
|
| 1823 | - // handle rows that should NOT be empty |
|
| 1824 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1825 | - // if empty then the start date will be now. |
|
| 1826 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1827 | - } |
|
| 1828 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1829 | - // get the earliest datetime (if present); |
|
| 1830 | - $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1831 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1832 | - 'Datetime', |
|
| 1833 | - ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1834 | - ) |
|
| 1835 | - : null; |
|
| 1836 | - $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
| 1837 | - ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
| 1838 | - : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
| 1839 | - } |
|
| 1840 | - $template_args = array_merge($template_args, $price_args); |
|
| 1841 | - $template = apply_filters( |
|
| 1842 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1843 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1844 | - $ticket |
|
| 1845 | - ); |
|
| 1846 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1847 | - } |
|
| 1848 | - |
|
| 1849 | - |
|
| 1850 | - /** |
|
| 1851 | - * @throws EE_Error |
|
| 1852 | - * @throws ReflectionException |
|
| 1853 | - */ |
|
| 1854 | - public function registration_options_meta_box() |
|
| 1855 | - { |
|
| 1856 | - $yes_no_values = [ |
|
| 1857 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1858 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1859 | - ]; |
|
| 1860 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1861 | - [ |
|
| 1862 | - EEM_Registration::status_id_cancelled, |
|
| 1863 | - EEM_Registration::status_id_declined, |
|
| 1864 | - EEM_Registration::status_id_incomplete, |
|
| 1865 | - ], |
|
| 1866 | - true |
|
| 1867 | - ); |
|
| 1868 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1869 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1870 | - $template_args['event'] = $this->_cpt_model_obj; |
|
| 1871 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1872 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1873 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1874 | - 'default_reg_status', |
|
| 1875 | - $default_reg_status_values, |
|
| 1876 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1877 | - ); |
|
| 1878 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1879 | - 'display_desc', |
|
| 1880 | - $yes_no_values, |
|
| 1881 | - $this->_cpt_model_obj->display_description() |
|
| 1882 | - ); |
|
| 1883 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1884 | - 'display_ticket_selector', |
|
| 1885 | - $yes_no_values, |
|
| 1886 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1887 | - '', |
|
| 1888 | - '', |
|
| 1889 | - false |
|
| 1890 | - ); |
|
| 1891 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1892 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1893 | - '', |
|
| 1894 | - $template_args, |
|
| 1895 | - $yes_no_values, |
|
| 1896 | - $default_reg_status_values |
|
| 1897 | - ); |
|
| 1898 | - EEH_Template::display_template( |
|
| 1899 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1900 | - $template_args |
|
| 1901 | - ); |
|
| 1902 | - } |
|
| 1903 | - |
|
| 1904 | - |
|
| 1905 | - /** |
|
| 1906 | - * _get_events() |
|
| 1907 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1908 | - * |
|
| 1909 | - * @access public |
|
| 1910 | - * @param int $per_page count of items per page (20 default); |
|
| 1911 | - * @param int $current_page what is the current page being viewed. |
|
| 1912 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1913 | - * If FALSE then we return an array of event objects |
|
| 1914 | - * that match the given _view and paging parameters. |
|
| 1915 | - * @return array|int an array of event objects or a count of them. |
|
| 1916 | - * @throws Exception |
|
| 1917 | - */ |
|
| 1918 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1919 | - { |
|
| 1920 | - $EEM_Event = $this->_event_model(); |
|
| 1921 | - $offset = ($current_page - 1) * $per_page; |
|
| 1922 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1923 | - $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
| 1924 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 1925 | - $month_range = $this->request->getRequestParam('month_range'); |
|
| 1926 | - if ($month_range) { |
|
| 1927 | - $pieces = explode(' ', $month_range, 3); |
|
| 1928 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1929 | - // where PHP doesn't know what to assume for date. |
|
| 1930 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1931 | - $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1932 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1933 | - } |
|
| 1934 | - $where = []; |
|
| 1935 | - $status = $this->request->getRequestParam('status'); |
|
| 1936 | - // determine what post_status our condition will have for the query. |
|
| 1937 | - switch ($status) { |
|
| 1938 | - case 'month': |
|
| 1939 | - case 'today': |
|
| 1940 | - case null: |
|
| 1941 | - case 'all': |
|
| 1942 | - break; |
|
| 1943 | - case 'draft': |
|
| 1944 | - $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1945 | - break; |
|
| 1946 | - default: |
|
| 1947 | - $where['status'] = $status; |
|
| 1948 | - } |
|
| 1949 | - // categories? The default for all categories is -1 |
|
| 1950 | - $category = $this->request->getRequestParam('EVT_CAT', -1, 'int'); |
|
| 1951 | - if ($category !== -1) { |
|
| 1952 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1953 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1954 | - } |
|
| 1955 | - // date where conditions |
|
| 1956 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1957 | - if ($month_range) { |
|
| 1958 | - $DateTime = new DateTime( |
|
| 1959 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1960 | - new DateTimeZone('UTC') |
|
| 1961 | - ); |
|
| 1962 | - $start = $DateTime->getTimestamp(); |
|
| 1963 | - // set the datetime to be the end of the month |
|
| 1964 | - $DateTime->setDate( |
|
| 1965 | - $year_r, |
|
| 1966 | - $month_r, |
|
| 1967 | - $DateTime->format('t') |
|
| 1968 | - )->setTime(23, 59, 59); |
|
| 1969 | - $end = $DateTime->getTimestamp(); |
|
| 1970 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1971 | - } elseif ($status === 'today') { |
|
| 1972 | - $DateTime = |
|
| 1973 | - new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1974 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1975 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1976 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1977 | - } elseif ($status === 'month') { |
|
| 1978 | - $now = date('Y-m-01'); |
|
| 1979 | - $DateTime = |
|
| 1980 | - new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1981 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1982 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1983 | - ->setTime(23, 59, 59) |
|
| 1984 | - ->format(implode(' ', $start_formats)); |
|
| 1985 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1986 | - } |
|
| 1987 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1988 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1989 | - } else { |
|
| 1990 | - if (! isset($where['status'])) { |
|
| 1991 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1992 | - $where['OR'] = [ |
|
| 1993 | - 'status*restrict_private' => ['!=', 'private'], |
|
| 1994 | - 'AND' => [ |
|
| 1995 | - 'status*inclusive' => ['=', 'private'], |
|
| 1996 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1997 | - ], |
|
| 1998 | - ]; |
|
| 1999 | - } |
|
| 2000 | - } |
|
| 2001 | - } |
|
| 2002 | - $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int'); |
|
| 2003 | - if ( |
|
| 2004 | - $wp_user |
|
| 2005 | - && $wp_user !== get_current_user_id() |
|
| 2006 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 2007 | - ) { |
|
| 2008 | - $where['EVT_wp_user'] = $wp_user; |
|
| 2009 | - } |
|
| 2010 | - // search query handling |
|
| 2011 | - $search_term = $this->request->getRequestParam('s'); |
|
| 2012 | - if ($search_term) { |
|
| 2013 | - $search_term = '%' . $search_term . '%'; |
|
| 2014 | - $where['OR'] = [ |
|
| 2015 | - 'EVT_name' => ['LIKE', $search_term], |
|
| 2016 | - 'EVT_desc' => ['LIKE', $search_term], |
|
| 2017 | - 'EVT_short_desc' => ['LIKE', $search_term], |
|
| 2018 | - ]; |
|
| 2019 | - } |
|
| 2020 | - // filter events by venue. |
|
| 2021 | - $venue = $this->request->getRequestParam('venue', 0, 'int'); |
|
| 2022 | - if ($venue) { |
|
| 2023 | - $where['Venue.VNU_ID'] = $venue; |
|
| 2024 | - } |
|
| 2025 | - $request_params = $this->request->requestParams(); |
|
| 2026 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
| 2027 | - $query_params = apply_filters( |
|
| 2028 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 2029 | - [ |
|
| 2030 | - $where, |
|
| 2031 | - 'limit' => $limit, |
|
| 2032 | - 'order_by' => $orderby, |
|
| 2033 | - 'order' => $order, |
|
| 2034 | - 'group_by' => 'EVT_ID', |
|
| 2035 | - ], |
|
| 2036 | - $request_params |
|
| 2037 | - ); |
|
| 2038 | - |
|
| 2039 | - // let's first check if we have special requests coming in. |
|
| 2040 | - $active_status = $this->request->getRequestParam('active_status'); |
|
| 2041 | - if ($active_status) { |
|
| 2042 | - switch ($active_status) { |
|
| 2043 | - case 'upcoming': |
|
| 2044 | - return $EEM_Event->get_upcoming_events($query_params, $count); |
|
| 2045 | - case 'expired': |
|
| 2046 | - return $EEM_Event->get_expired_events($query_params, $count); |
|
| 2047 | - case 'active': |
|
| 2048 | - return $EEM_Event->get_active_events($query_params, $count); |
|
| 2049 | - case 'inactive': |
|
| 2050 | - return $EEM_Event->get_inactive_events($query_params, $count); |
|
| 2051 | - } |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
| 2055 | - } |
|
| 2056 | - |
|
| 2057 | - |
|
| 2058 | - /** |
|
| 2059 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 2060 | - * |
|
| 2061 | - * @param string $post_id |
|
| 2062 | - * @throws EE_Error |
|
| 2063 | - * @throws ReflectionException |
|
| 2064 | - */ |
|
| 2065 | - public function trash_cpt_item($post_id) |
|
| 2066 | - { |
|
| 2067 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2068 | - $this->_trash_or_restore_event('trash', false); |
|
| 2069 | - } |
|
| 2070 | - |
|
| 2071 | - |
|
| 2072 | - /** |
|
| 2073 | - * @param string $post_id |
|
| 2074 | - * @throws EE_Error |
|
| 2075 | - * @throws ReflectionException |
|
| 2076 | - */ |
|
| 2077 | - public function restore_cpt_item($post_id) |
|
| 2078 | - { |
|
| 2079 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2080 | - $this->_trash_or_restore_event('draft', false); |
|
| 2081 | - } |
|
| 2082 | - |
|
| 2083 | - |
|
| 2084 | - /** |
|
| 2085 | - * @param string $post_id |
|
| 2086 | - * @throws EE_Error |
|
| 2087 | - * @throws EE_Error |
|
| 2088 | - */ |
|
| 2089 | - public function delete_cpt_item($post_id) |
|
| 2090 | - { |
|
| 2091 | - throw new EE_Error( |
|
| 2092 | - esc_html__( |
|
| 2093 | - 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
| 2094 | - 'event_espresso' |
|
| 2095 | - ) |
|
| 2096 | - ); |
|
| 2097 | - // $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2098 | - // $this->_delete_event(); |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - |
|
| 2102 | - /** |
|
| 2103 | - * _trash_or_restore_event |
|
| 2104 | - * |
|
| 2105 | - * @access protected |
|
| 2106 | - * @param string $event_status |
|
| 2107 | - * @param bool $redirect_after |
|
| 2108 | - * @throws EE_Error |
|
| 2109 | - * @throws EE_Error |
|
| 2110 | - * @throws ReflectionException |
|
| 2111 | - */ |
|
| 2112 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 2113 | - { |
|
| 2114 | - // determine the event id and set to array. |
|
| 2115 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 2116 | - // loop thru events |
|
| 2117 | - if ($EVT_ID) { |
|
| 2118 | - // clean status |
|
| 2119 | - $event_status = sanitize_key($event_status); |
|
| 2120 | - // grab status |
|
| 2121 | - if (! empty($event_status)) { |
|
| 2122 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2123 | - } else { |
|
| 2124 | - $success = false; |
|
| 2125 | - $msg = esc_html__( |
|
| 2126 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2127 | - 'event_espresso' |
|
| 2128 | - ); |
|
| 2129 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2130 | - } |
|
| 2131 | - } else { |
|
| 2132 | - $success = false; |
|
| 2133 | - $msg = esc_html__( |
|
| 2134 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2135 | - 'event_espresso' |
|
| 2136 | - ); |
|
| 2137 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2138 | - } |
|
| 2139 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2140 | - if ($redirect_after) { |
|
| 2141 | - $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2142 | - } |
|
| 2143 | - } |
|
| 2144 | - |
|
| 2145 | - |
|
| 2146 | - /** |
|
| 2147 | - * _trash_or_restore_events |
|
| 2148 | - * |
|
| 2149 | - * @access protected |
|
| 2150 | - * @param string $event_status |
|
| 2151 | - * @return void |
|
| 2152 | - * @throws EE_Error |
|
| 2153 | - * @throws EE_Error |
|
| 2154 | - * @throws ReflectionException |
|
| 2155 | - */ |
|
| 2156 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2157 | - { |
|
| 2158 | - // clean status |
|
| 2159 | - $event_status = sanitize_key($event_status); |
|
| 2160 | - // grab status |
|
| 2161 | - if (! empty($event_status)) { |
|
| 2162 | - $success = true; |
|
| 2163 | - // determine the event id and set to array. |
|
| 2164 | - $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2165 | - // loop thru events |
|
| 2166 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2167 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 2168 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2169 | - $success = $results !== false ? $success : false; |
|
| 2170 | - } else { |
|
| 2171 | - $msg = sprintf( |
|
| 2172 | - esc_html__( |
|
| 2173 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2174 | - 'event_espresso' |
|
| 2175 | - ), |
|
| 2176 | - $EVT_ID |
|
| 2177 | - ); |
|
| 2178 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2179 | - $success = false; |
|
| 2180 | - } |
|
| 2181 | - } |
|
| 2182 | - } else { |
|
| 2183 | - $success = false; |
|
| 2184 | - $msg = esc_html__( |
|
| 2185 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2186 | - 'event_espresso' |
|
| 2187 | - ); |
|
| 2188 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2189 | - } |
|
| 2190 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2191 | - $success = $success ? 2 : false; |
|
| 2192 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2193 | - $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2194 | - } |
|
| 2195 | - |
|
| 2196 | - |
|
| 2197 | - /** |
|
| 2198 | - * @param int $EVT_ID |
|
| 2199 | - * @param string $event_status |
|
| 2200 | - * @return bool |
|
| 2201 | - * @throws EE_Error |
|
| 2202 | - * @throws ReflectionException |
|
| 2203 | - */ |
|
| 2204 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2205 | - { |
|
| 2206 | - // grab event id |
|
| 2207 | - if (! $EVT_ID) { |
|
| 2208 | - $msg = esc_html__( |
|
| 2209 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2210 | - 'event_espresso' |
|
| 2211 | - ); |
|
| 2212 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2213 | - return false; |
|
| 2214 | - } |
|
| 2215 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2216 | - // clean status |
|
| 2217 | - $event_status = sanitize_key($event_status); |
|
| 2218 | - // grab status |
|
| 2219 | - if (empty($event_status)) { |
|
| 2220 | - $msg = esc_html__( |
|
| 2221 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2222 | - 'event_espresso' |
|
| 2223 | - ); |
|
| 2224 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2225 | - return false; |
|
| 2226 | - } |
|
| 2227 | - // was event trashed or restored ? |
|
| 2228 | - switch ($event_status) { |
|
| 2229 | - case 'draft': |
|
| 2230 | - $action = 'restored from the trash'; |
|
| 2231 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2232 | - break; |
|
| 2233 | - case 'trash': |
|
| 2234 | - $action = 'moved to the trash'; |
|
| 2235 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2236 | - break; |
|
| 2237 | - default: |
|
| 2238 | - $action = 'updated'; |
|
| 2239 | - $hook = false; |
|
| 2240 | - } |
|
| 2241 | - // use class to change status |
|
| 2242 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2243 | - $success = $this->_cpt_model_obj->save(); |
|
| 2244 | - if (! $success) { |
|
| 2245 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2246 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2247 | - return false; |
|
| 2248 | - } |
|
| 2249 | - if ($hook) { |
|
| 2250 | - do_action($hook); |
|
| 2251 | - } |
|
| 2252 | - return true; |
|
| 2253 | - } |
|
| 2254 | - |
|
| 2255 | - |
|
| 2256 | - /** |
|
| 2257 | - * @param array $event_ids |
|
| 2258 | - * @return array |
|
| 2259 | - * @since 4.10.23.p |
|
| 2260 | - */ |
|
| 2261 | - private function cleanEventIds(array $event_ids) |
|
| 2262 | - { |
|
| 2263 | - return array_map('absint', $event_ids); |
|
| 2264 | - } |
|
| 2265 | - |
|
| 2266 | - |
|
| 2267 | - /** |
|
| 2268 | - * @return array |
|
| 2269 | - * @since 4.10.23.p |
|
| 2270 | - */ |
|
| 2271 | - private function getEventIdsFromRequest() |
|
| 2272 | - { |
|
| 2273 | - if ($this->request->requestParamIsSet('EVT_IDs')) { |
|
| 2274 | - return $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2275 | - } else { |
|
| 2276 | - return $this->request->getRequestParam('EVT_ID', [], 'int', true); |
|
| 2277 | - } |
|
| 2278 | - } |
|
| 2279 | - |
|
| 2280 | - |
|
| 2281 | - /** |
|
| 2282 | - * @param bool $preview_delete |
|
| 2283 | - * @throws EE_Error |
|
| 2284 | - */ |
|
| 2285 | - protected function _delete_event($preview_delete = true) |
|
| 2286 | - { |
|
| 2287 | - $this->_delete_events($preview_delete); |
|
| 2288 | - } |
|
| 2289 | - |
|
| 2290 | - |
|
| 2291 | - /** |
|
| 2292 | - * Gets the tree traversal batch persister. |
|
| 2293 | - * |
|
| 2294 | - * @return NodeGroupDao |
|
| 2295 | - * @throws InvalidArgumentException |
|
| 2296 | - * @throws InvalidDataTypeException |
|
| 2297 | - * @throws InvalidInterfaceException |
|
| 2298 | - * @since 4.10.12.p |
|
| 2299 | - */ |
|
| 2300 | - protected function getModelObjNodeGroupPersister() |
|
| 2301 | - { |
|
| 2302 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2303 | - $this->model_obj_node_group_persister = |
|
| 2304 | - $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2305 | - } |
|
| 2306 | - return $this->model_obj_node_group_persister; |
|
| 2307 | - } |
|
| 2308 | - |
|
| 2309 | - |
|
| 2310 | - /** |
|
| 2311 | - * @param bool $preview_delete |
|
| 2312 | - * @return void |
|
| 2313 | - * @throws EE_Error |
|
| 2314 | - */ |
|
| 2315 | - protected function _delete_events($preview_delete = true) |
|
| 2316 | - { |
|
| 2317 | - $event_ids = $this->getEventIdsFromRequest(); |
|
| 2318 | - if ($preview_delete) { |
|
| 2319 | - $this->generateDeletionPreview($event_ids); |
|
| 2320 | - } else { |
|
| 2321 | - EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]); |
|
| 2322 | - } |
|
| 2323 | - } |
|
| 2324 | - |
|
| 2325 | - |
|
| 2326 | - /** |
|
| 2327 | - * @param array $event_ids |
|
| 2328 | - */ |
|
| 2329 | - protected function generateDeletionPreview(array $event_ids) |
|
| 2330 | - { |
|
| 2331 | - $event_ids = $this->cleanEventIds($event_ids); |
|
| 2332 | - // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2333 | - $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2334 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2335 | - [ |
|
| 2336 | - 'action' => 'preview_deletion', |
|
| 2337 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2338 | - ], |
|
| 2339 | - $this->_admin_base_url |
|
| 2340 | - ); |
|
| 2341 | - EEH_URL::safeRedirectAndExit( |
|
| 2342 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2343 | - [ |
|
| 2344 | - 'page' => 'espresso_batch', |
|
| 2345 | - 'batch' => EED_Batch::batch_job, |
|
| 2346 | - 'EVT_IDs' => $event_ids, |
|
| 2347 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2348 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
| 2349 | - 'return_url' => urlencode($return_url), |
|
| 2350 | - ], |
|
| 2351 | - admin_url() |
|
| 2352 | - ) |
|
| 2353 | - ); |
|
| 2354 | - } |
|
| 2355 | - |
|
| 2356 | - |
|
| 2357 | - /** |
|
| 2358 | - * Checks for a POST submission |
|
| 2359 | - * |
|
| 2360 | - * @since 4.10.12.p |
|
| 2361 | - */ |
|
| 2362 | - protected function confirmDeletion() |
|
| 2363 | - { |
|
| 2364 | - $deletion_redirect_logic = |
|
| 2365 | - $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
| 2366 | - $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2367 | - } |
|
| 2368 | - |
|
| 2369 | - |
|
| 2370 | - /** |
|
| 2371 | - * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2372 | - * |
|
| 2373 | - * @throws EE_Error |
|
| 2374 | - * @since 4.10.12.p |
|
| 2375 | - */ |
|
| 2376 | - protected function previewDeletion() |
|
| 2377 | - { |
|
| 2378 | - $preview_deletion_logic = |
|
| 2379 | - $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
| 2380 | - $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2381 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2382 | - } |
|
| 2383 | - |
|
| 2384 | - |
|
| 2385 | - /** |
|
| 2386 | - * get total number of events |
|
| 2387 | - * |
|
| 2388 | - * @access public |
|
| 2389 | - * @return int |
|
| 2390 | - * @throws EE_Error |
|
| 2391 | - * @throws EE_Error |
|
| 2392 | - */ |
|
| 2393 | - public function total_events() |
|
| 2394 | - { |
|
| 2395 | - return EEM_Event::instance()->count( |
|
| 2396 | - ['caps' => 'read_admin'], |
|
| 2397 | - 'EVT_ID', |
|
| 2398 | - true |
|
| 2399 | - ); |
|
| 2400 | - } |
|
| 2401 | - |
|
| 2402 | - |
|
| 2403 | - /** |
|
| 2404 | - * get total number of draft events |
|
| 2405 | - * |
|
| 2406 | - * @access public |
|
| 2407 | - * @return int |
|
| 2408 | - * @throws EE_Error |
|
| 2409 | - * @throws EE_Error |
|
| 2410 | - */ |
|
| 2411 | - public function total_events_draft() |
|
| 2412 | - { |
|
| 2413 | - return EEM_Event::instance()->count( |
|
| 2414 | - [ |
|
| 2415 | - ['status' => ['IN', ['draft', 'auto-draft']]], |
|
| 2416 | - 'caps' => 'read_admin', |
|
| 2417 | - ], |
|
| 2418 | - 'EVT_ID', |
|
| 2419 | - true |
|
| 2420 | - ); |
|
| 2421 | - } |
|
| 2422 | - |
|
| 2423 | - |
|
| 2424 | - /** |
|
| 2425 | - * get total number of trashed events |
|
| 2426 | - * |
|
| 2427 | - * @access public |
|
| 2428 | - * @return int |
|
| 2429 | - * @throws EE_Error |
|
| 2430 | - * @throws EE_Error |
|
| 2431 | - */ |
|
| 2432 | - public function total_trashed_events() |
|
| 2433 | - { |
|
| 2434 | - return EEM_Event::instance()->count( |
|
| 2435 | - [ |
|
| 2436 | - ['status' => 'trash'], |
|
| 2437 | - 'caps' => 'read_admin', |
|
| 2438 | - ], |
|
| 2439 | - 'EVT_ID', |
|
| 2440 | - true |
|
| 2441 | - ); |
|
| 2442 | - } |
|
| 2443 | - |
|
| 2444 | - |
|
| 2445 | - /** |
|
| 2446 | - * _default_event_settings |
|
| 2447 | - * This generates the Default Settings Tab |
|
| 2448 | - * |
|
| 2449 | - * @return void |
|
| 2450 | - * @throws DomainException |
|
| 2451 | - * @throws EE_Error |
|
| 2452 | - * @throws InvalidArgumentException |
|
| 2453 | - * @throws InvalidDataTypeException |
|
| 2454 | - * @throws InvalidInterfaceException |
|
| 2455 | - */ |
|
| 2456 | - protected function _default_event_settings() |
|
| 2457 | - { |
|
| 2458 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2459 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2460 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
| 2461 | - $this->_default_event_settings_form()->get_html(), |
|
| 2462 | - '', |
|
| 2463 | - 'padding' |
|
| 2464 | - ); |
|
| 2465 | - $this->display_admin_page_with_sidebar(); |
|
| 2466 | - } |
|
| 2467 | - |
|
| 2468 | - |
|
| 2469 | - /** |
|
| 2470 | - * Return the form for event settings. |
|
| 2471 | - * |
|
| 2472 | - * @return EE_Form_Section_Proper |
|
| 2473 | - * @throws EE_Error |
|
| 2474 | - */ |
|
| 2475 | - protected function _default_event_settings_form() |
|
| 2476 | - { |
|
| 2477 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2478 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2479 | - // exclude |
|
| 2480 | - [ |
|
| 2481 | - EEM_Registration::status_id_cancelled, |
|
| 2482 | - EEM_Registration::status_id_declined, |
|
| 2483 | - EEM_Registration::status_id_incomplete, |
|
| 2484 | - EEM_Registration::status_id_wait_list, |
|
| 2485 | - ], |
|
| 2486 | - true |
|
| 2487 | - ); |
|
| 2488 | - return new EE_Form_Section_Proper( |
|
| 2489 | - [ |
|
| 2490 | - 'name' => 'update_default_event_settings', |
|
| 2491 | - 'html_id' => 'update_default_event_settings', |
|
| 2492 | - 'html_class' => 'form-table', |
|
| 2493 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2494 | - 'subsections' => apply_filters( |
|
| 2495 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2496 | - [ |
|
| 2497 | - 'defaults_section_header' => new EE_Form_Section_HTML( |
|
| 2498 | - EEH_HTML::h2( |
|
| 2499 | - esc_html__('Default Settings', 'event_espresso'), |
|
| 2500 | - '', |
|
| 2501 | - 'ee-admin-settings-hdr' |
|
| 2502 | - ) |
|
| 2503 | - ), |
|
| 2504 | - 'default_reg_status' => new EE_Select_Input( |
|
| 2505 | - $registration_stati_for_selection, |
|
| 2506 | - [ |
|
| 2507 | - 'default' => isset($registration_config->default_STS_ID) |
|
| 2508 | - && array_key_exists( |
|
| 2509 | - $registration_config->default_STS_ID, |
|
| 2510 | - $registration_stati_for_selection |
|
| 2511 | - ) |
|
| 2512 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2513 | - : EEM_Registration::status_id_pending_payment, |
|
| 2514 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2515 | - . EEH_Template::get_help_tab_link( |
|
| 2516 | - 'default_settings_status_help_tab' |
|
| 2517 | - ), |
|
| 2518 | - 'html_help_text' => esc_html__( |
|
| 2519 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2520 | - 'event_espresso' |
|
| 2521 | - ), |
|
| 2522 | - ] |
|
| 2523 | - ), |
|
| 2524 | - 'default_max_tickets' => new EE_Integer_Input( |
|
| 2525 | - [ |
|
| 2526 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2527 | - ? $registration_config->default_maximum_number_of_tickets |
|
| 2528 | - : EEM_Event::get_default_additional_limit(), |
|
| 2529 | - 'html_label_text' => esc_html__( |
|
| 2530 | - 'Default Maximum Tickets Allowed Per Order:', |
|
| 2531 | - 'event_espresso' |
|
| 2532 | - ) |
|
| 2533 | - . EEH_Template::get_help_tab_link( |
|
| 2534 | - 'default_maximum_tickets_help_tab"' |
|
| 2535 | - ), |
|
| 2536 | - 'html_help_text' => esc_html__( |
|
| 2537 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2538 | - 'event_espresso' |
|
| 2539 | - ), |
|
| 2540 | - ] |
|
| 2541 | - ), |
|
| 2542 | - ] |
|
| 2543 | - ), |
|
| 2544 | - ] |
|
| 2545 | - ); |
|
| 2546 | - } |
|
| 2547 | - |
|
| 2548 | - |
|
| 2549 | - /** |
|
| 2550 | - * @return void |
|
| 2551 | - * @throws EE_Error |
|
| 2552 | - * @throws InvalidArgumentException |
|
| 2553 | - * @throws InvalidDataTypeException |
|
| 2554 | - * @throws InvalidInterfaceException |
|
| 2555 | - */ |
|
| 2556 | - protected function _update_default_event_settings() |
|
| 2557 | - { |
|
| 2558 | - $form = $this->_default_event_settings_form(); |
|
| 2559 | - if ($form->was_submitted()) { |
|
| 2560 | - $form->receive_form_submission(); |
|
| 2561 | - if ($form->is_valid()) { |
|
| 2562 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2563 | - $valid_data = $form->valid_data(); |
|
| 2564 | - if (isset($valid_data['default_reg_status'])) { |
|
| 2565 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2566 | - } |
|
| 2567 | - if (isset($valid_data['default_max_tickets'])) { |
|
| 2568 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2569 | - } |
|
| 2570 | - do_action( |
|
| 2571 | - 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
| 2572 | - $valid_data, |
|
| 2573 | - EE_Registry::instance()->CFG, |
|
| 2574 | - $this |
|
| 2575 | - ); |
|
| 2576 | - // update because data was valid! |
|
| 2577 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2578 | - EE_Error::overwrite_success(); |
|
| 2579 | - EE_Error::add_success( |
|
| 2580 | - esc_html__('Default Event Settings were updated', 'event_espresso') |
|
| 2581 | - ); |
|
| 2582 | - } |
|
| 2583 | - } |
|
| 2584 | - $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2585 | - } |
|
| 2586 | - |
|
| 2587 | - |
|
| 2588 | - /************* Templates ************* |
|
| 2589 | - * |
|
| 2590 | - * @throws EE_Error |
|
| 2591 | - */ |
|
| 2592 | - protected function _template_settings() |
|
| 2593 | - { |
|
| 2594 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2595 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2596 | - . EVENTS_ASSETS_URL |
|
| 2597 | - . '/images/' |
|
| 2598 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2599 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2600 | - . '" />'; |
|
| 2601 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 2602 | - . esc_html__( |
|
| 2603 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2604 | - 'event_espresso' |
|
| 2605 | - ) . '</strong>'; |
|
| 2606 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2607 | - } |
|
| 2608 | - |
|
| 2609 | - |
|
| 2610 | - /** Event Category Stuff **/ |
|
| 2611 | - /** |
|
| 2612 | - * set the _category property with the category object for the loaded page. |
|
| 2613 | - * |
|
| 2614 | - * @access private |
|
| 2615 | - * @return void |
|
| 2616 | - */ |
|
| 2617 | - private function _set_category_object() |
|
| 2618 | - { |
|
| 2619 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2620 | - return; |
|
| 2621 | - } //already have the category object so get out. |
|
| 2622 | - // set default category object |
|
| 2623 | - $this->_set_empty_category_object(); |
|
| 2624 | - // only set if we've got an id |
|
| 2625 | - $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 2626 | - if (! $category_ID) { |
|
| 2627 | - return; |
|
| 2628 | - } |
|
| 2629 | - $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2630 | - if (! empty($term)) { |
|
| 2631 | - $this->_category->category_name = $term->name; |
|
| 2632 | - $this->_category->category_identifier = $term->slug; |
|
| 2633 | - $this->_category->category_desc = $term->description; |
|
| 2634 | - $this->_category->id = $term->term_id; |
|
| 2635 | - $this->_category->parent = $term->parent; |
|
| 2636 | - } |
|
| 2637 | - } |
|
| 2638 | - |
|
| 2639 | - |
|
| 2640 | - /** |
|
| 2641 | - * Clears out category properties. |
|
| 2642 | - */ |
|
| 2643 | - private function _set_empty_category_object() |
|
| 2644 | - { |
|
| 2645 | - $this->_category = new stdClass(); |
|
| 2646 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2647 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2648 | - } |
|
| 2649 | - |
|
| 2650 | - |
|
| 2651 | - /** |
|
| 2652 | - * @throws DomainException |
|
| 2653 | - * @throws EE_Error |
|
| 2654 | - * @throws InvalidArgumentException |
|
| 2655 | - * @throws InvalidDataTypeException |
|
| 2656 | - * @throws InvalidInterfaceException |
|
| 2657 | - */ |
|
| 2658 | - protected function _category_list_table() |
|
| 2659 | - { |
|
| 2660 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2661 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2662 | - $this->_admin_page_title .= ' '; |
|
| 2663 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 2664 | - 'add_category', |
|
| 2665 | - 'add_category', |
|
| 2666 | - [], |
|
| 2667 | - 'add-new-h2' |
|
| 2668 | - ); |
|
| 2669 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2670 | - } |
|
| 2671 | - |
|
| 2672 | - |
|
| 2673 | - /** |
|
| 2674 | - * Output category details view. |
|
| 2675 | - * |
|
| 2676 | - * @throws EE_Error |
|
| 2677 | - * @throws EE_Error |
|
| 2678 | - */ |
|
| 2679 | - protected function _category_details($view) |
|
| 2680 | - { |
|
| 2681 | - // load formatter helper |
|
| 2682 | - // load field generator helper |
|
| 2683 | - $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
| 2684 | - $this->_set_add_edit_form_tags($route); |
|
| 2685 | - $this->_set_category_object(); |
|
| 2686 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2687 | - $delete_action = 'delete_category'; |
|
| 2688 | - // custom redirect |
|
| 2689 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2690 | - ['action' => 'category_list'], |
|
| 2691 | - $this->_admin_base_url |
|
| 2692 | - ); |
|
| 2693 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2694 | - // take care of contents |
|
| 2695 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2696 | - $this->display_admin_page_with_sidebar(); |
|
| 2697 | - } |
|
| 2698 | - |
|
| 2699 | - |
|
| 2700 | - /** |
|
| 2701 | - * Output category details content. |
|
| 2702 | - * |
|
| 2703 | - * @throws DomainException |
|
| 2704 | - */ |
|
| 2705 | - protected function _category_details_content() |
|
| 2706 | - { |
|
| 2707 | - $editor_args['category_desc'] = [ |
|
| 2708 | - 'type' => 'wp_editor', |
|
| 2709 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2710 | - 'class' => 'my_editor_custom', |
|
| 2711 | - 'wpeditor_args' => ['media_buttons' => false], |
|
| 2712 | - ]; |
|
| 2713 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2714 | - $all_terms = get_terms( |
|
| 2715 | - [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2716 | - ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2717 | - ); |
|
| 2718 | - // setup category select for term parents. |
|
| 2719 | - $category_select_values[] = [ |
|
| 2720 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2721 | - 'id' => 0, |
|
| 2722 | - ]; |
|
| 2723 | - foreach ($all_terms as $term) { |
|
| 2724 | - $category_select_values[] = [ |
|
| 2725 | - 'text' => $term->name, |
|
| 2726 | - 'id' => $term->term_id, |
|
| 2727 | - ]; |
|
| 2728 | - } |
|
| 2729 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2730 | - 'category_parent', |
|
| 2731 | - $category_select_values, |
|
| 2732 | - $this->_category->parent |
|
| 2733 | - ); |
|
| 2734 | - $template_args = [ |
|
| 2735 | - 'category' => $this->_category, |
|
| 2736 | - 'category_select' => $category_select, |
|
| 2737 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2738 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2739 | - 'disable' => '', |
|
| 2740 | - 'disabled_message' => false, |
|
| 2741 | - ]; |
|
| 2742 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2743 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2744 | - } |
|
| 2745 | - |
|
| 2746 | - |
|
| 2747 | - /** |
|
| 2748 | - * Handles deleting categories. |
|
| 2749 | - * |
|
| 2750 | - * @throws EE_Error |
|
| 2751 | - */ |
|
| 2752 | - protected function _delete_categories() |
|
| 2753 | - { |
|
| 2754 | - $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
| 2755 | - foreach ($category_IDs as $category_ID) { |
|
| 2756 | - $this->_delete_category($category_ID); |
|
| 2757 | - } |
|
| 2758 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2759 | - $query_args = [ |
|
| 2760 | - 'action' => 'category_list', |
|
| 2761 | - ]; |
|
| 2762 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2763 | - } |
|
| 2764 | - |
|
| 2765 | - |
|
| 2766 | - /** |
|
| 2767 | - * Handles deleting specific category. |
|
| 2768 | - * |
|
| 2769 | - * @param int $cat_id |
|
| 2770 | - */ |
|
| 2771 | - protected function _delete_category($cat_id) |
|
| 2772 | - { |
|
| 2773 | - $cat_id = absint($cat_id); |
|
| 2774 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2775 | - } |
|
| 2776 | - |
|
| 2777 | - |
|
| 2778 | - /** |
|
| 2779 | - * Handles triggering the update or insertion of a new category. |
|
| 2780 | - * |
|
| 2781 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2782 | - * @throws EE_Error |
|
| 2783 | - * @throws EE_Error |
|
| 2784 | - */ |
|
| 2785 | - protected function _insert_or_update_category($new_category) |
|
| 2786 | - { |
|
| 2787 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2788 | - $success = 0; // we already have a success message so lets not send another. |
|
| 2789 | - if ($cat_id) { |
|
| 2790 | - $query_args = [ |
|
| 2791 | - 'action' => 'edit_category', |
|
| 2792 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2793 | - ]; |
|
| 2794 | - } else { |
|
| 2795 | - $query_args = ['action' => 'add_category']; |
|
| 2796 | - } |
|
| 2797 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2798 | - } |
|
| 2799 | - |
|
| 2800 | - |
|
| 2801 | - /** |
|
| 2802 | - * Inserts or updates category |
|
| 2803 | - * |
|
| 2804 | - * @param bool $update (true indicates we're updating a category). |
|
| 2805 | - * @return bool|mixed|string |
|
| 2806 | - */ |
|
| 2807 | - private function _insert_category($update = false) |
|
| 2808 | - { |
|
| 2809 | - $category_ID = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0; |
|
| 2810 | - $category_name = $this->request->getRequestParam('category_name', ''); |
|
| 2811 | - $category_desc = $this->request->getRequestParam('category_desc', ''); |
|
| 2812 | - $category_parent = $this->request->getRequestParam('category_parent', 0, 'int'); |
|
| 2813 | - $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
| 2814 | - |
|
| 2815 | - if (empty($category_name)) { |
|
| 2816 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2817 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2818 | - return false; |
|
| 2819 | - } |
|
| 2820 | - $term_args = [ |
|
| 2821 | - 'name' => $category_name, |
|
| 2822 | - 'description' => $category_desc, |
|
| 2823 | - 'parent' => $category_parent, |
|
| 2824 | - ]; |
|
| 2825 | - // was the category_identifier input disabled? |
|
| 2826 | - if ($category_identifier) { |
|
| 2827 | - $term_args['slug'] = $category_identifier; |
|
| 2828 | - } |
|
| 2829 | - $insert_ids = $update |
|
| 2830 | - ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2831 | - : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2832 | - if (! is_array($insert_ids)) { |
|
| 2833 | - $msg = esc_html__( |
|
| 2834 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2835 | - 'event_espresso' |
|
| 2836 | - ); |
|
| 2837 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2838 | - } else { |
|
| 2839 | - $category_ID = $insert_ids['term_id']; |
|
| 2840 | - $msg = sprintf( |
|
| 2841 | - esc_html__('The category %s was successfully saved', 'event_espresso'), |
|
| 2842 | - $category_name |
|
| 2843 | - ); |
|
| 2844 | - EE_Error::add_success($msg); |
|
| 2845 | - } |
|
| 2846 | - return $category_ID; |
|
| 2847 | - } |
|
| 2848 | - |
|
| 2849 | - |
|
| 2850 | - /** |
|
| 2851 | - * Gets categories or count of categories matching the arguments in the request. |
|
| 2852 | - * |
|
| 2853 | - * @param int $per_page |
|
| 2854 | - * @param int $current_page |
|
| 2855 | - * @param bool $count |
|
| 2856 | - * @return EE_Term_Taxonomy[]|int |
|
| 2857 | - * @throws EE_Error |
|
| 2858 | - */ |
|
| 2859 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2860 | - { |
|
| 2861 | - // testing term stuff |
|
| 2862 | - $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
| 2863 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 2864 | - $limit = ($current_page - 1) * $per_page; |
|
| 2865 | - $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2866 | - $search_term = $this->request->getRequestParam('s'); |
|
| 2867 | - if ($search_term) { |
|
| 2868 | - $search_term = '%' . $search_term . '%'; |
|
| 2869 | - $where['OR'] = [ |
|
| 2870 | - 'Term.name' => ['LIKE', $search_term], |
|
| 2871 | - 'description' => ['LIKE', $search_term], |
|
| 2872 | - ]; |
|
| 2873 | - } |
|
| 2874 | - $query_params = [ |
|
| 2875 | - $where, |
|
| 2876 | - 'order_by' => [$orderby => $order], |
|
| 2877 | - 'limit' => $limit . ',' . $per_page, |
|
| 2878 | - 'force_join' => ['Term'], |
|
| 2879 | - ]; |
|
| 2880 | - return $count |
|
| 2881 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2882 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2883 | - } |
|
| 2884 | - |
|
| 2885 | - /* end category stuff */ |
|
| 2886 | - |
|
| 2887 | - |
|
| 2888 | - /**************/ |
|
| 2889 | - |
|
| 2890 | - |
|
| 2891 | - /** |
|
| 2892 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2893 | - * |
|
| 2894 | - * @throws EE_Error |
|
| 2895 | - * @throws InvalidArgumentException |
|
| 2896 | - * @throws InvalidDataTypeException |
|
| 2897 | - * @throws InvalidInterfaceException |
|
| 2898 | - */ |
|
| 2899 | - public function saveTimezoneString() |
|
| 2900 | - { |
|
| 2901 | - $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
| 2902 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2903 | - EE_Error::add_error( |
|
| 2904 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2905 | - __FILE__, |
|
| 2906 | - __FUNCTION__, |
|
| 2907 | - __LINE__ |
|
| 2908 | - ); |
|
| 2909 | - $this->_template_args['error'] = true; |
|
| 2910 | - $this->_return_json(); |
|
| 2911 | - } |
|
| 2912 | - |
|
| 2913 | - update_option('timezone_string', $timezone_string); |
|
| 2914 | - EE_Error::add_success( |
|
| 2915 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2916 | - ); |
|
| 2917 | - $this->_template_args['success'] = true; |
|
| 2918 | - $this->_return_json(true, ['action' => 'create_new']); |
|
| 2919 | - } |
|
| 2920 | - |
|
| 2921 | - |
|
| 2922 | - /** |
|
| 2923 | 2590 | * @throws EE_Error |
| 2924 | - * @deprecated 4.10.25.p |
|
| 2925 | 2591 | */ |
| 2926 | - public function save_timezonestring_setting() |
|
| 2927 | - { |
|
| 2928 | - $this->saveTimezoneString(); |
|
| 2929 | - } |
|
| 2592 | + protected function _template_settings() |
|
| 2593 | + { |
|
| 2594 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2595 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2596 | + . EVENTS_ASSETS_URL |
|
| 2597 | + . '/images/' |
|
| 2598 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2599 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2600 | + . '" />'; |
|
| 2601 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 2602 | + . esc_html__( |
|
| 2603 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2604 | + 'event_espresso' |
|
| 2605 | + ) . '</strong>'; |
|
| 2606 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2607 | + } |
|
| 2608 | + |
|
| 2609 | + |
|
| 2610 | + /** Event Category Stuff **/ |
|
| 2611 | + /** |
|
| 2612 | + * set the _category property with the category object for the loaded page. |
|
| 2613 | + * |
|
| 2614 | + * @access private |
|
| 2615 | + * @return void |
|
| 2616 | + */ |
|
| 2617 | + private function _set_category_object() |
|
| 2618 | + { |
|
| 2619 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2620 | + return; |
|
| 2621 | + } //already have the category object so get out. |
|
| 2622 | + // set default category object |
|
| 2623 | + $this->_set_empty_category_object(); |
|
| 2624 | + // only set if we've got an id |
|
| 2625 | + $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 2626 | + if (! $category_ID) { |
|
| 2627 | + return; |
|
| 2628 | + } |
|
| 2629 | + $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2630 | + if (! empty($term)) { |
|
| 2631 | + $this->_category->category_name = $term->name; |
|
| 2632 | + $this->_category->category_identifier = $term->slug; |
|
| 2633 | + $this->_category->category_desc = $term->description; |
|
| 2634 | + $this->_category->id = $term->term_id; |
|
| 2635 | + $this->_category->parent = $term->parent; |
|
| 2636 | + } |
|
| 2637 | + } |
|
| 2638 | + |
|
| 2639 | + |
|
| 2640 | + /** |
|
| 2641 | + * Clears out category properties. |
|
| 2642 | + */ |
|
| 2643 | + private function _set_empty_category_object() |
|
| 2644 | + { |
|
| 2645 | + $this->_category = new stdClass(); |
|
| 2646 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2647 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2648 | + } |
|
| 2649 | + |
|
| 2650 | + |
|
| 2651 | + /** |
|
| 2652 | + * @throws DomainException |
|
| 2653 | + * @throws EE_Error |
|
| 2654 | + * @throws InvalidArgumentException |
|
| 2655 | + * @throws InvalidDataTypeException |
|
| 2656 | + * @throws InvalidInterfaceException |
|
| 2657 | + */ |
|
| 2658 | + protected function _category_list_table() |
|
| 2659 | + { |
|
| 2660 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2661 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2662 | + $this->_admin_page_title .= ' '; |
|
| 2663 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 2664 | + 'add_category', |
|
| 2665 | + 'add_category', |
|
| 2666 | + [], |
|
| 2667 | + 'add-new-h2' |
|
| 2668 | + ); |
|
| 2669 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2670 | + } |
|
| 2671 | + |
|
| 2672 | + |
|
| 2673 | + /** |
|
| 2674 | + * Output category details view. |
|
| 2675 | + * |
|
| 2676 | + * @throws EE_Error |
|
| 2677 | + * @throws EE_Error |
|
| 2678 | + */ |
|
| 2679 | + protected function _category_details($view) |
|
| 2680 | + { |
|
| 2681 | + // load formatter helper |
|
| 2682 | + // load field generator helper |
|
| 2683 | + $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
| 2684 | + $this->_set_add_edit_form_tags($route); |
|
| 2685 | + $this->_set_category_object(); |
|
| 2686 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2687 | + $delete_action = 'delete_category'; |
|
| 2688 | + // custom redirect |
|
| 2689 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2690 | + ['action' => 'category_list'], |
|
| 2691 | + $this->_admin_base_url |
|
| 2692 | + ); |
|
| 2693 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2694 | + // take care of contents |
|
| 2695 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2696 | + $this->display_admin_page_with_sidebar(); |
|
| 2697 | + } |
|
| 2698 | + |
|
| 2699 | + |
|
| 2700 | + /** |
|
| 2701 | + * Output category details content. |
|
| 2702 | + * |
|
| 2703 | + * @throws DomainException |
|
| 2704 | + */ |
|
| 2705 | + protected function _category_details_content() |
|
| 2706 | + { |
|
| 2707 | + $editor_args['category_desc'] = [ |
|
| 2708 | + 'type' => 'wp_editor', |
|
| 2709 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2710 | + 'class' => 'my_editor_custom', |
|
| 2711 | + 'wpeditor_args' => ['media_buttons' => false], |
|
| 2712 | + ]; |
|
| 2713 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2714 | + $all_terms = get_terms( |
|
| 2715 | + [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2716 | + ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2717 | + ); |
|
| 2718 | + // setup category select for term parents. |
|
| 2719 | + $category_select_values[] = [ |
|
| 2720 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2721 | + 'id' => 0, |
|
| 2722 | + ]; |
|
| 2723 | + foreach ($all_terms as $term) { |
|
| 2724 | + $category_select_values[] = [ |
|
| 2725 | + 'text' => $term->name, |
|
| 2726 | + 'id' => $term->term_id, |
|
| 2727 | + ]; |
|
| 2728 | + } |
|
| 2729 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2730 | + 'category_parent', |
|
| 2731 | + $category_select_values, |
|
| 2732 | + $this->_category->parent |
|
| 2733 | + ); |
|
| 2734 | + $template_args = [ |
|
| 2735 | + 'category' => $this->_category, |
|
| 2736 | + 'category_select' => $category_select, |
|
| 2737 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2738 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2739 | + 'disable' => '', |
|
| 2740 | + 'disabled_message' => false, |
|
| 2741 | + ]; |
|
| 2742 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2743 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2744 | + } |
|
| 2745 | + |
|
| 2746 | + |
|
| 2747 | + /** |
|
| 2748 | + * Handles deleting categories. |
|
| 2749 | + * |
|
| 2750 | + * @throws EE_Error |
|
| 2751 | + */ |
|
| 2752 | + protected function _delete_categories() |
|
| 2753 | + { |
|
| 2754 | + $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
| 2755 | + foreach ($category_IDs as $category_ID) { |
|
| 2756 | + $this->_delete_category($category_ID); |
|
| 2757 | + } |
|
| 2758 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2759 | + $query_args = [ |
|
| 2760 | + 'action' => 'category_list', |
|
| 2761 | + ]; |
|
| 2762 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2763 | + } |
|
| 2764 | + |
|
| 2765 | + |
|
| 2766 | + /** |
|
| 2767 | + * Handles deleting specific category. |
|
| 2768 | + * |
|
| 2769 | + * @param int $cat_id |
|
| 2770 | + */ |
|
| 2771 | + protected function _delete_category($cat_id) |
|
| 2772 | + { |
|
| 2773 | + $cat_id = absint($cat_id); |
|
| 2774 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2775 | + } |
|
| 2776 | + |
|
| 2777 | + |
|
| 2778 | + /** |
|
| 2779 | + * Handles triggering the update or insertion of a new category. |
|
| 2780 | + * |
|
| 2781 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2782 | + * @throws EE_Error |
|
| 2783 | + * @throws EE_Error |
|
| 2784 | + */ |
|
| 2785 | + protected function _insert_or_update_category($new_category) |
|
| 2786 | + { |
|
| 2787 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2788 | + $success = 0; // we already have a success message so lets not send another. |
|
| 2789 | + if ($cat_id) { |
|
| 2790 | + $query_args = [ |
|
| 2791 | + 'action' => 'edit_category', |
|
| 2792 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2793 | + ]; |
|
| 2794 | + } else { |
|
| 2795 | + $query_args = ['action' => 'add_category']; |
|
| 2796 | + } |
|
| 2797 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2798 | + } |
|
| 2799 | + |
|
| 2800 | + |
|
| 2801 | + /** |
|
| 2802 | + * Inserts or updates category |
|
| 2803 | + * |
|
| 2804 | + * @param bool $update (true indicates we're updating a category). |
|
| 2805 | + * @return bool|mixed|string |
|
| 2806 | + */ |
|
| 2807 | + private function _insert_category($update = false) |
|
| 2808 | + { |
|
| 2809 | + $category_ID = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0; |
|
| 2810 | + $category_name = $this->request->getRequestParam('category_name', ''); |
|
| 2811 | + $category_desc = $this->request->getRequestParam('category_desc', ''); |
|
| 2812 | + $category_parent = $this->request->getRequestParam('category_parent', 0, 'int'); |
|
| 2813 | + $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
| 2814 | + |
|
| 2815 | + if (empty($category_name)) { |
|
| 2816 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2817 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2818 | + return false; |
|
| 2819 | + } |
|
| 2820 | + $term_args = [ |
|
| 2821 | + 'name' => $category_name, |
|
| 2822 | + 'description' => $category_desc, |
|
| 2823 | + 'parent' => $category_parent, |
|
| 2824 | + ]; |
|
| 2825 | + // was the category_identifier input disabled? |
|
| 2826 | + if ($category_identifier) { |
|
| 2827 | + $term_args['slug'] = $category_identifier; |
|
| 2828 | + } |
|
| 2829 | + $insert_ids = $update |
|
| 2830 | + ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2831 | + : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2832 | + if (! is_array($insert_ids)) { |
|
| 2833 | + $msg = esc_html__( |
|
| 2834 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2835 | + 'event_espresso' |
|
| 2836 | + ); |
|
| 2837 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2838 | + } else { |
|
| 2839 | + $category_ID = $insert_ids['term_id']; |
|
| 2840 | + $msg = sprintf( |
|
| 2841 | + esc_html__('The category %s was successfully saved', 'event_espresso'), |
|
| 2842 | + $category_name |
|
| 2843 | + ); |
|
| 2844 | + EE_Error::add_success($msg); |
|
| 2845 | + } |
|
| 2846 | + return $category_ID; |
|
| 2847 | + } |
|
| 2848 | + |
|
| 2849 | + |
|
| 2850 | + /** |
|
| 2851 | + * Gets categories or count of categories matching the arguments in the request. |
|
| 2852 | + * |
|
| 2853 | + * @param int $per_page |
|
| 2854 | + * @param int $current_page |
|
| 2855 | + * @param bool $count |
|
| 2856 | + * @return EE_Term_Taxonomy[]|int |
|
| 2857 | + * @throws EE_Error |
|
| 2858 | + */ |
|
| 2859 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2860 | + { |
|
| 2861 | + // testing term stuff |
|
| 2862 | + $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
| 2863 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 2864 | + $limit = ($current_page - 1) * $per_page; |
|
| 2865 | + $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2866 | + $search_term = $this->request->getRequestParam('s'); |
|
| 2867 | + if ($search_term) { |
|
| 2868 | + $search_term = '%' . $search_term . '%'; |
|
| 2869 | + $where['OR'] = [ |
|
| 2870 | + 'Term.name' => ['LIKE', $search_term], |
|
| 2871 | + 'description' => ['LIKE', $search_term], |
|
| 2872 | + ]; |
|
| 2873 | + } |
|
| 2874 | + $query_params = [ |
|
| 2875 | + $where, |
|
| 2876 | + 'order_by' => [$orderby => $order], |
|
| 2877 | + 'limit' => $limit . ',' . $per_page, |
|
| 2878 | + 'force_join' => ['Term'], |
|
| 2879 | + ]; |
|
| 2880 | + return $count |
|
| 2881 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2882 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2883 | + } |
|
| 2884 | + |
|
| 2885 | + /* end category stuff */ |
|
| 2886 | + |
|
| 2887 | + |
|
| 2888 | + /**************/ |
|
| 2889 | + |
|
| 2890 | + |
|
| 2891 | + /** |
|
| 2892 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2893 | + * |
|
| 2894 | + * @throws EE_Error |
|
| 2895 | + * @throws InvalidArgumentException |
|
| 2896 | + * @throws InvalidDataTypeException |
|
| 2897 | + * @throws InvalidInterfaceException |
|
| 2898 | + */ |
|
| 2899 | + public function saveTimezoneString() |
|
| 2900 | + { |
|
| 2901 | + $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
| 2902 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2903 | + EE_Error::add_error( |
|
| 2904 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2905 | + __FILE__, |
|
| 2906 | + __FUNCTION__, |
|
| 2907 | + __LINE__ |
|
| 2908 | + ); |
|
| 2909 | + $this->_template_args['error'] = true; |
|
| 2910 | + $this->_return_json(); |
|
| 2911 | + } |
|
| 2912 | + |
|
| 2913 | + update_option('timezone_string', $timezone_string); |
|
| 2914 | + EE_Error::add_success( |
|
| 2915 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2916 | + ); |
|
| 2917 | + $this->_template_args['success'] = true; |
|
| 2918 | + $this->_return_json(true, ['action' => 'create_new']); |
|
| 2919 | + } |
|
| 2920 | + |
|
| 2921 | + |
|
| 2922 | + /** |
|
| 2923 | + * @throws EE_Error |
|
| 2924 | + * @deprecated 4.10.25.p |
|
| 2925 | + */ |
|
| 2926 | + public function save_timezonestring_setting() |
|
| 2927 | + { |
|
| 2928 | + $this->saveTimezoneString(); |
|
| 2929 | + } |
|
| 2930 | 2930 | } |
@@ -587,13 +587,13 @@ discard block |
||
| 587 | 587 | { |
| 588 | 588 | wp_register_style( |
| 589 | 589 | 'events-admin-css', |
| 590 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 590 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
| 591 | 591 | [], |
| 592 | 592 | EVENT_ESPRESSO_VERSION |
| 593 | 593 | ); |
| 594 | 594 | wp_register_style( |
| 595 | 595 | 'ee-cat-admin', |
| 596 | - EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 596 | + EVENTS_ASSETS_URL.'ee-cat-admin.css', |
|
| 597 | 597 | [], |
| 598 | 598 | EVENT_ESPRESSO_VERSION |
| 599 | 599 | ); |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | // scripts |
| 603 | 603 | wp_register_script( |
| 604 | 604 | 'event_editor_js', |
| 605 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 605 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
| 606 | 606 | ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
| 607 | 607 | EVENT_ESPRESSO_VERSION, |
| 608 | 608 | true |
@@ -628,16 +628,16 @@ discard block |
||
| 628 | 628 | wp_enqueue_style('espresso-ui-theme'); |
| 629 | 629 | wp_register_style( |
| 630 | 630 | 'event-editor-css', |
| 631 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 631 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 632 | 632 | ['ee-admin-css'], |
| 633 | 633 | EVENT_ESPRESSO_VERSION |
| 634 | 634 | ); |
| 635 | 635 | wp_enqueue_style('event-editor-css'); |
| 636 | 636 | // scripts |
| 637 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 637 | + if ( ! $this->admin_config->useAdvancedEditor()) { |
|
| 638 | 638 | wp_register_script( |
| 639 | 639 | 'event-datetime-metabox', |
| 640 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 640 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
| 641 | 641 | ['event_editor_js', 'ee-datepicker'], |
| 642 | 642 | EVENT_ESPRESSO_VERSION |
| 643 | 643 | ); |
@@ -707,15 +707,15 @@ discard block |
||
| 707 | 707 | public function verify_event_edit($event = null, $req_type = '') |
| 708 | 708 | { |
| 709 | 709 | // don't need to do this when processing |
| 710 | - if (! empty($req_type)) { |
|
| 710 | + if ( ! empty($req_type)) { |
|
| 711 | 711 | return; |
| 712 | 712 | } |
| 713 | 713 | // no event? |
| 714 | - if (! $event instanceof EE_Event) { |
|
| 714 | + if ( ! $event instanceof EE_Event) { |
|
| 715 | 715 | $event = $this->_cpt_model_obj; |
| 716 | 716 | } |
| 717 | 717 | // STILL no event? |
| 718 | - if (! $event instanceof EE_Event) { |
|
| 718 | + if ( ! $event instanceof EE_Event) { |
|
| 719 | 719 | return; |
| 720 | 720 | } |
| 721 | 721 | $orig_status = $event->status(); |
@@ -755,7 +755,7 @@ discard block |
||
| 755 | 755 | ); |
| 756 | 756 | } |
| 757 | 757 | // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
| 758 | - if (! $event->tickets_on_sale()) { |
|
| 758 | + if ( ! $event->tickets_on_sale()) { |
|
| 759 | 759 | return; |
| 760 | 760 | } |
| 761 | 761 | // made it here so show warning |
@@ -803,7 +803,7 @@ discard block |
||
| 803 | 803 | { |
| 804 | 804 | $has_timezone_string = get_option('timezone_string'); |
| 805 | 805 | // only nag them about setting their timezone if it's their first event, and they haven't already done it |
| 806 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 806 | + if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 807 | 807 | EE_Error::add_attention( |
| 808 | 808 | sprintf( |
| 809 | 809 | esc_html__( |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | */ |
| 873 | 873 | protected function _event_legend_items() |
| 874 | 874 | { |
| 875 | - $items = [ |
|
| 875 | + $items = [ |
|
| 876 | 876 | 'view_details' => [ |
| 877 | 877 | 'class' => 'dashicons dashicons-search', |
| 878 | 878 | 'desc' => esc_html__('View Event', 'event_espresso'), |
@@ -889,31 +889,31 @@ discard block |
||
| 889 | 889 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
| 890 | 890 | $statuses = [ |
| 891 | 891 | 'sold_out_status' => [ |
| 892 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::sold_out, |
|
| 892 | + 'class' => 'ee-status-legend ee-status-legend--'.EE_Datetime::sold_out, |
|
| 893 | 893 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
| 894 | 894 | ], |
| 895 | 895 | 'active_status' => [ |
| 896 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::active, |
|
| 896 | + 'class' => 'ee-status-legend ee-status-legend--'.EE_Datetime::active, |
|
| 897 | 897 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
| 898 | 898 | ], |
| 899 | 899 | 'upcoming_status' => [ |
| 900 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::upcoming, |
|
| 900 | + 'class' => 'ee-status-legend ee-status-legend--'.EE_Datetime::upcoming, |
|
| 901 | 901 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
| 902 | 902 | ], |
| 903 | 903 | 'postponed_status' => [ |
| 904 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::postponed, |
|
| 904 | + 'class' => 'ee-status-legend ee-status-legend--'.EE_Datetime::postponed, |
|
| 905 | 905 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
| 906 | 906 | ], |
| 907 | 907 | 'cancelled_status' => [ |
| 908 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::cancelled, |
|
| 908 | + 'class' => 'ee-status-legend ee-status-legend--'.EE_Datetime::cancelled, |
|
| 909 | 909 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
| 910 | 910 | ], |
| 911 | 911 | 'expired_status' => [ |
| 912 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::expired, |
|
| 912 | + 'class' => 'ee-status-legend ee-status-legend--'.EE_Datetime::expired, |
|
| 913 | 913 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
| 914 | 914 | ], |
| 915 | 915 | 'inactive_status' => [ |
| 916 | - 'class' => 'ee-status-legend ee-status-legend--' . EE_Datetime::inactive, |
|
| 916 | + 'class' => 'ee-status-legend ee-status-legend--'.EE_Datetime::inactive, |
|
| 917 | 917 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
| 918 | 918 | ], |
| 919 | 919 | ]; |
@@ -932,7 +932,7 @@ discard block |
||
| 932 | 932 | */ |
| 933 | 933 | private function _event_model() |
| 934 | 934 | { |
| 935 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 935 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 936 | 936 | $this->_event_model = EE_Registry::instance()->load_model('Event'); |
| 937 | 937 | } |
| 938 | 938 | return $this->_event_model; |
@@ -952,7 +952,7 @@ discard block |
||
| 952 | 952 | public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
| 953 | 953 | { |
| 954 | 954 | // make sure this is only when editing |
| 955 | - if (! empty($id)) { |
|
| 955 | + if ( ! empty($id)) { |
|
| 956 | 956 | $post = get_post($id); |
| 957 | 957 | $return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
| 958 | 958 | . esc_html__('Shortcode', 'event_espresso') |
@@ -991,14 +991,14 @@ discard block |
||
| 991 | 991 | ); |
| 992 | 992 | |
| 993 | 993 | $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
| 994 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 994 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 995 | 995 | 'create_new', |
| 996 | 996 | 'add', |
| 997 | 997 | [], |
| 998 | 998 | 'add-new-h2' |
| 999 | 999 | ); |
| 1000 | 1000 | |
| 1001 | - $this->_template_args['after_list_table'] = array_merge( |
|
| 1001 | + $this->_template_args['after_list_table'] = array_merge( |
|
| 1002 | 1002 | (array) $this->_template_args['after_list_table'], |
| 1003 | 1003 | $after_list_table |
| 1004 | 1004 | ); |
@@ -1055,13 +1055,13 @@ discard block |
||
| 1055 | 1055 | 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
| 1056 | 1056 | ]; |
| 1057 | 1057 | // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
| 1058 | - if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1059 | - $event_values['EVT_display_ticket_selector'] = $this->request->getRequestParam( |
|
| 1058 | + if ( ! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1059 | + $event_values['EVT_display_ticket_selector'] = $this->request->getRequestParam( |
|
| 1060 | 1060 | 'display_ticket_selector', |
| 1061 | 1061 | false, |
| 1062 | 1062 | 'bool' |
| 1063 | 1063 | ); |
| 1064 | - $event_values['EVT_additional_limit'] = min( |
|
| 1064 | + $event_values['EVT_additional_limit'] = min( |
|
| 1065 | 1065 | apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
| 1066 | 1066 | $this->request->getRequestParam('additional_limit', null, 'int') |
| 1067 | 1067 | ); |
@@ -1097,7 +1097,7 @@ discard block |
||
| 1097 | 1097 | // the following are default callbacks for event attachment updates |
| 1098 | 1098 | // that can be overridden by caffeinated functionality and/or addons. |
| 1099 | 1099 | $event_update_callbacks = []; |
| 1100 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 1100 | + if ( ! $this->admin_config->useAdvancedEditor()) { |
|
| 1101 | 1101 | $event_update_callbacks['_default_venue_update'] = [$this, '_default_venue_update']; |
| 1102 | 1102 | $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update']; |
| 1103 | 1103 | } |
@@ -1168,7 +1168,7 @@ discard block |
||
| 1168 | 1168 | */ |
| 1169 | 1169 | protected function _default_venue_update(EE_Event $event, $data) |
| 1170 | 1170 | { |
| 1171 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1171 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
| 1172 | 1172 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
| 1173 | 1173 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
| 1174 | 1174 | // very important. If we don't have a venue name... |
@@ -1199,7 +1199,7 @@ discard block |
||
| 1199 | 1199 | 'status' => 'publish', |
| 1200 | 1200 | ]; |
| 1201 | 1201 | // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
| 1202 | - if (! empty($venue_id)) { |
|
| 1202 | + if ( ! empty($venue_id)) { |
|
| 1203 | 1203 | $update_where = [$venue_model->primary_key_name() => $venue_id]; |
| 1204 | 1204 | $rows_affected = $venue_model->update($venue_array, [$update_where]); |
| 1205 | 1205 | // we've gotta make sure that the venue is always attached to a revision.. |
@@ -1241,7 +1241,7 @@ discard block |
||
| 1241 | 1241 | isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
| 1242 | 1242 | ? $datetime_data['DTT_EVT_end'] |
| 1243 | 1243 | : $datetime_data['DTT_EVT_start']; |
| 1244 | - $datetime_values = [ |
|
| 1244 | + $datetime_values = [ |
|
| 1245 | 1245 | 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
| 1246 | 1246 | 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
| 1247 | 1247 | 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
@@ -1250,9 +1250,9 @@ discard block |
||
| 1250 | 1250 | ]; |
| 1251 | 1251 | // if we have an id then let's get existing object first and then set the new values. |
| 1252 | 1252 | // Otherwise we instantiate a new object for save. |
| 1253 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 1253 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
| 1254 | 1254 | $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
| 1255 | - if (! $datetime instanceof EE_Ticket) { |
|
| 1255 | + if ( ! $datetime instanceof EE_Ticket) { |
|
| 1256 | 1256 | throw new RuntimeException( |
| 1257 | 1257 | sprintf( |
| 1258 | 1258 | esc_html__( |
@@ -1271,7 +1271,7 @@ discard block |
||
| 1271 | 1271 | } else { |
| 1272 | 1272 | $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
| 1273 | 1273 | } |
| 1274 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1274 | + if ( ! $datetime instanceof EE_Datetime) { |
|
| 1275 | 1275 | throw new RuntimeException( |
| 1276 | 1276 | sprintf( |
| 1277 | 1277 | esc_html__( |
@@ -1297,7 +1297,7 @@ discard block |
||
| 1297 | 1297 | |
| 1298 | 1298 | // set up some default start and end dates in case those are not present in the incoming data |
| 1299 | 1299 | $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
| 1300 | - $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
| 1300 | + $default_start_date = $default_start_date->format($date_formats[0].' '.$date_formats[1]); |
|
| 1301 | 1301 | // use the start date of the first datetime for the end date |
| 1302 | 1302 | $first_datetime = $event->first_datetime(); |
| 1303 | 1303 | $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
@@ -1305,8 +1305,8 @@ discard block |
||
| 1305 | 1305 | // now process the incoming data |
| 1306 | 1306 | foreach ($data['edit_tickets'] as $row => $ticket_data) { |
| 1307 | 1307 | $update_prices = false; |
| 1308 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1309 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
| 1308 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1309 | + ? $data['edit_prices'][$row][1]['PRC_amount'] |
|
| 1310 | 1310 | : 0; |
| 1311 | 1311 | // trim inputs to ensure any excess whitespace is removed. |
| 1312 | 1312 | $ticket_data = array_map('trim', $ticket_data); |
@@ -1347,9 +1347,9 @@ discard block |
||
| 1347 | 1347 | // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
| 1348 | 1348 | // keep in mind that if the ticket has been sold (and we have changed pricing information), |
| 1349 | 1349 | // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
| 1350 | - if (! empty($ticket_data['TKT_ID'])) { |
|
| 1350 | + if ( ! empty($ticket_data['TKT_ID'])) { |
|
| 1351 | 1351 | $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
| 1352 | - if (! $existing_ticket instanceof EE_Ticket) { |
|
| 1352 | + if ( ! $existing_ticket instanceof EE_Ticket) { |
|
| 1353 | 1353 | throw new RuntimeException( |
| 1354 | 1354 | sprintf( |
| 1355 | 1355 | esc_html__( |
@@ -1398,7 +1398,7 @@ discard block |
||
| 1398 | 1398 | $existing_ticket->save(); |
| 1399 | 1399 | // make sure this ticket is still recorded in our $saved_tickets |
| 1400 | 1400 | // so we don't run it through the regular trash routine. |
| 1401 | - $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
| 1401 | + $saved_tickets[$existing_ticket->ID()] = $existing_ticket; |
|
| 1402 | 1402 | // create new ticket that's a copy of the existing except, |
| 1403 | 1403 | // (a new id of course and not archived) AND has the new TKT_price associated with it. |
| 1404 | 1404 | $new_ticket = clone $existing_ticket; |
@@ -1415,7 +1415,7 @@ discard block |
||
| 1415 | 1415 | $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
| 1416 | 1416 | $update_prices = true; |
| 1417 | 1417 | } |
| 1418 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1418 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1419 | 1419 | throw new RuntimeException( |
| 1420 | 1420 | sprintf( |
| 1421 | 1421 | esc_html__( |
@@ -1439,9 +1439,9 @@ discard block |
||
| 1439 | 1439 | } |
| 1440 | 1440 | // initially let's add the ticket to the datetime |
| 1441 | 1441 | $datetime->_add_relation_to($ticket, 'Ticket'); |
| 1442 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 1442 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
| 1443 | 1443 | // add prices to ticket |
| 1444 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices); |
|
| 1444 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $ticket, $update_prices); |
|
| 1445 | 1445 | } |
| 1446 | 1446 | // however now we need to handle permanently deleting tickets via the ui. |
| 1447 | 1447 | // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
@@ -1453,7 +1453,7 @@ discard block |
||
| 1453 | 1453 | $id = absint($id); |
| 1454 | 1454 | // get the ticket for this id |
| 1455 | 1455 | $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
| 1456 | - if (! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1456 | + if ( ! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1457 | 1457 | continue; |
| 1458 | 1458 | } |
| 1459 | 1459 | // need to get all the related datetimes on this ticket and remove from every single one of them |
@@ -1510,7 +1510,7 @@ discard block |
||
| 1510 | 1510 | $price->set($field, $new_price); |
| 1511 | 1511 | } |
| 1512 | 1512 | } |
| 1513 | - if (! $price instanceof EE_Price) { |
|
| 1513 | + if ( ! $price instanceof EE_Price) { |
|
| 1514 | 1514 | throw new RuntimeException( |
| 1515 | 1515 | sprintf( |
| 1516 | 1516 | esc_html__( |
@@ -1552,13 +1552,13 @@ discard block |
||
| 1552 | 1552 | { |
| 1553 | 1553 | // load formatter helper |
| 1554 | 1554 | // args for getting related registrations |
| 1555 | - $approved_query_args = [ |
|
| 1555 | + $approved_query_args = [ |
|
| 1556 | 1556 | [ |
| 1557 | 1557 | 'REG_deleted' => 0, |
| 1558 | 1558 | 'STS_ID' => EEM_Registration::status_id_approved, |
| 1559 | 1559 | ], |
| 1560 | 1560 | ]; |
| 1561 | - $not_approved_query_args = [ |
|
| 1561 | + $not_approved_query_args = [ |
|
| 1562 | 1562 | [ |
| 1563 | 1563 | 'REG_deleted' => 0, |
| 1564 | 1564 | 'STS_ID' => EEM_Registration::status_id_not_approved, |
@@ -1621,7 +1621,7 @@ discard block |
||
| 1621 | 1621 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
| 1622 | 1622 | // load template |
| 1623 | 1623 | EEH_Template::display_template( |
| 1624 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1624 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
| 1625 | 1625 | $publish_box_extra_args |
| 1626 | 1626 | ); |
| 1627 | 1627 | } |
@@ -1652,7 +1652,7 @@ discard block |
||
| 1652 | 1652 | $this->verify_cpt_object(); |
| 1653 | 1653 | $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
| 1654 | 1654 | // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
| 1655 | - if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1655 | + if ( ! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1656 | 1656 | $this->addMetaBox( |
| 1657 | 1657 | 'espresso_event_editor_event_options', |
| 1658 | 1658 | esc_html__('Event Registration Options', 'event_espresso'), |
@@ -1661,7 +1661,7 @@ discard block |
||
| 1661 | 1661 | 'side' |
| 1662 | 1662 | ); |
| 1663 | 1663 | } |
| 1664 | - if (! $use_advanced_editor) { |
|
| 1664 | + if ( ! $use_advanced_editor) { |
|
| 1665 | 1665 | $this->addMetaBox( |
| 1666 | 1666 | 'espresso_event_editor_tickets', |
| 1667 | 1667 | esc_html__('Event Datetime & Ticket', 'event_espresso'), |
@@ -1673,7 +1673,7 @@ discard block |
||
| 1673 | 1673 | } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
| 1674 | 1674 | add_action( |
| 1675 | 1675 | 'add_meta_boxes_espresso_events', |
| 1676 | - function () { |
|
| 1676 | + function() { |
|
| 1677 | 1677 | global $current_screen; |
| 1678 | 1678 | remove_meta_box('authordiv', $current_screen, 'normal'); |
| 1679 | 1679 | }, |
@@ -1708,7 +1708,7 @@ discard block |
||
| 1708 | 1708 | 'trash_icon' => 'dashicons dashicons-lock', |
| 1709 | 1709 | 'disabled' => '', |
| 1710 | 1710 | ]; |
| 1711 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1711 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1712 | 1712 | /** |
| 1713 | 1713 | * 1. Start with retrieving Datetimes |
| 1714 | 1714 | * 2. Fore each datetime get related tickets |
@@ -1734,24 +1734,24 @@ discard block |
||
| 1734 | 1734 | 'default_where_conditions' => 'none', |
| 1735 | 1735 | ] |
| 1736 | 1736 | ); |
| 1737 | - if (! empty($related_tickets)) { |
|
| 1737 | + if ( ! empty($related_tickets)) { |
|
| 1738 | 1738 | $template_args['total_ticket_rows'] = count($related_tickets); |
| 1739 | 1739 | $row = 0; |
| 1740 | 1740 | foreach ($related_tickets as $ticket) { |
| 1741 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1741 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1742 | 1742 | $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
| 1743 | 1743 | $row++; |
| 1744 | 1744 | } |
| 1745 | 1745 | } else { |
| 1746 | 1746 | $template_args['total_ticket_rows'] = 1; |
| 1747 | 1747 | /** @type EE_Ticket $ticket */ |
| 1748 | - $ticket = $ticket_model->create_default_object(); |
|
| 1748 | + $ticket = $ticket_model->create_default_object(); |
|
| 1749 | 1749 | $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
| 1750 | 1750 | } |
| 1751 | 1751 | } else { |
| 1752 | 1752 | $template_args['time'] = $times[0]; |
| 1753 | 1753 | /** @type EE_Ticket[] $tickets */ |
| 1754 | - $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1754 | + $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1755 | 1755 | $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
| 1756 | 1756 | // NOTE: we're just sending the first default row |
| 1757 | 1757 | // (decaf can't manage default tickets so this should be sufficient); |
@@ -1766,9 +1766,9 @@ discard block |
||
| 1766 | 1766 | $ticket_model->create_default_object(), |
| 1767 | 1767 | true |
| 1768 | 1768 | ); |
| 1769 | - $template = apply_filters( |
|
| 1769 | + $template = apply_filters( |
|
| 1770 | 1770 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
| 1771 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1771 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
| 1772 | 1772 | ); |
| 1773 | 1773 | EEH_Template::display_template($template, $template_args); |
| 1774 | 1774 | } |
@@ -1788,7 +1788,7 @@ discard block |
||
| 1788 | 1788 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
| 1789 | 1789 | { |
| 1790 | 1790 | $template_args = [ |
| 1791 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1791 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
| 1792 | 1792 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
| 1793 | 1793 | : '', |
| 1794 | 1794 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1800,10 +1800,10 @@ discard block |
||
| 1800 | 1800 | 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
| 1801 | 1801 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
| 1802 | 1802 | 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
| 1803 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1804 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1803 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1804 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1805 | 1805 | ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock', |
| 1806 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1806 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1807 | 1807 | : ' disabled=disabled', |
| 1808 | 1808 | ]; |
| 1809 | 1809 | $price = $ticket->ID() !== 0 |
@@ -1827,7 +1827,7 @@ discard block |
||
| 1827 | 1827 | } |
| 1828 | 1828 | if (empty($template_args['TKT_end_date'])) { |
| 1829 | 1829 | // get the earliest datetime (if present); |
| 1830 | - $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1830 | + $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1831 | 1831 | ? $this->_cpt_model_obj->get_first_related( |
| 1832 | 1832 | 'Datetime', |
| 1833 | 1833 | ['order_by' => ['DTT_EVT_start' => 'ASC']] |
@@ -1840,7 +1840,7 @@ discard block |
||
| 1840 | 1840 | $template_args = array_merge($template_args, $price_args); |
| 1841 | 1841 | $template = apply_filters( |
| 1842 | 1842 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
| 1843 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1843 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
| 1844 | 1844 | $ticket |
| 1845 | 1845 | ); |
| 1846 | 1846 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1853,7 +1853,7 @@ discard block |
||
| 1853 | 1853 | */ |
| 1854 | 1854 | public function registration_options_meta_box() |
| 1855 | 1855 | { |
| 1856 | - $yes_no_values = [ |
|
| 1856 | + $yes_no_values = [ |
|
| 1857 | 1857 | ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
| 1858 | 1858 | ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
| 1859 | 1859 | ]; |
@@ -1875,12 +1875,12 @@ discard block |
||
| 1875 | 1875 | $default_reg_status_values, |
| 1876 | 1876 | $this->_cpt_model_obj->default_registration_status() |
| 1877 | 1877 | ); |
| 1878 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1878 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1879 | 1879 | 'display_desc', |
| 1880 | 1880 | $yes_no_values, |
| 1881 | 1881 | $this->_cpt_model_obj->display_description() |
| 1882 | 1882 | ); |
| 1883 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1883 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1884 | 1884 | 'display_ticket_selector', |
| 1885 | 1885 | $yes_no_values, |
| 1886 | 1886 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -1896,7 +1896,7 @@ discard block |
||
| 1896 | 1896 | $default_reg_status_values |
| 1897 | 1897 | ); |
| 1898 | 1898 | EEH_Template::display_template( |
| 1899 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1899 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1900 | 1900 | $template_args |
| 1901 | 1901 | ); |
| 1902 | 1902 | } |
@@ -1919,7 +1919,7 @@ discard block |
||
| 1919 | 1919 | { |
| 1920 | 1920 | $EEM_Event = $this->_event_model(); |
| 1921 | 1921 | $offset = ($current_page - 1) * $per_page; |
| 1922 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1922 | + $limit = $count ? null : $offset.','.$per_page; |
|
| 1923 | 1923 | $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
| 1924 | 1924 | $order = $this->request->getRequestParam('order', 'DESC'); |
| 1925 | 1925 | $month_range = $this->request->getRequestParam('month_range'); |
@@ -1956,10 +1956,10 @@ discard block |
||
| 1956 | 1956 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
| 1957 | 1957 | if ($month_range) { |
| 1958 | 1958 | $DateTime = new DateTime( |
| 1959 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1959 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
| 1960 | 1960 | new DateTimeZone('UTC') |
| 1961 | 1961 | ); |
| 1962 | - $start = $DateTime->getTimestamp(); |
|
| 1962 | + $start = $DateTime->getTimestamp(); |
|
| 1963 | 1963 | // set the datetime to be the end of the month |
| 1964 | 1964 | $DateTime->setDate( |
| 1965 | 1965 | $year_r, |
@@ -1984,11 +1984,11 @@ discard block |
||
| 1984 | 1984 | ->format(implode(' ', $start_formats)); |
| 1985 | 1985 | $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
| 1986 | 1986 | } |
| 1987 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1987 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1988 | 1988 | $where['EVT_wp_user'] = get_current_user_id(); |
| 1989 | 1989 | } else { |
| 1990 | - if (! isset($where['status'])) { |
|
| 1991 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1990 | + if ( ! isset($where['status'])) { |
|
| 1991 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1992 | 1992 | $where['OR'] = [ |
| 1993 | 1993 | 'status*restrict_private' => ['!=', 'private'], |
| 1994 | 1994 | 'AND' => [ |
@@ -2010,7 +2010,7 @@ discard block |
||
| 2010 | 2010 | // search query handling |
| 2011 | 2011 | $search_term = $this->request->getRequestParam('s'); |
| 2012 | 2012 | if ($search_term) { |
| 2013 | - $search_term = '%' . $search_term . '%'; |
|
| 2013 | + $search_term = '%'.$search_term.'%'; |
|
| 2014 | 2014 | $where['OR'] = [ |
| 2015 | 2015 | 'EVT_name' => ['LIKE', $search_term], |
| 2016 | 2016 | 'EVT_desc' => ['LIKE', $search_term], |
@@ -2118,7 +2118,7 @@ discard block |
||
| 2118 | 2118 | // clean status |
| 2119 | 2119 | $event_status = sanitize_key($event_status); |
| 2120 | 2120 | // grab status |
| 2121 | - if (! empty($event_status)) { |
|
| 2121 | + if ( ! empty($event_status)) { |
|
| 2122 | 2122 | $success = $this->_change_event_status($EVT_ID, $event_status); |
| 2123 | 2123 | } else { |
| 2124 | 2124 | $success = false; |
@@ -2158,7 +2158,7 @@ discard block |
||
| 2158 | 2158 | // clean status |
| 2159 | 2159 | $event_status = sanitize_key($event_status); |
| 2160 | 2160 | // grab status |
| 2161 | - if (! empty($event_status)) { |
|
| 2161 | + if ( ! empty($event_status)) { |
|
| 2162 | 2162 | $success = true; |
| 2163 | 2163 | // determine the event id and set to array. |
| 2164 | 2164 | $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
@@ -2204,7 +2204,7 @@ discard block |
||
| 2204 | 2204 | private function _change_event_status($EVT_ID = 0, $event_status = '') |
| 2205 | 2205 | { |
| 2206 | 2206 | // grab event id |
| 2207 | - if (! $EVT_ID) { |
|
| 2207 | + if ( ! $EVT_ID) { |
|
| 2208 | 2208 | $msg = esc_html__( |
| 2209 | 2209 | 'An error occurred. No Event ID or an invalid Event ID was received.', |
| 2210 | 2210 | 'event_espresso' |
@@ -2241,7 +2241,7 @@ discard block |
||
| 2241 | 2241 | // use class to change status |
| 2242 | 2242 | $this->_cpt_model_obj->set_status($event_status); |
| 2243 | 2243 | $success = $this->_cpt_model_obj->save(); |
| 2244 | - if (! $success) { |
|
| 2244 | + if ( ! $success) { |
|
| 2245 | 2245 | $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
| 2246 | 2246 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
| 2247 | 2247 | return false; |
@@ -2299,7 +2299,7 @@ discard block |
||
| 2299 | 2299 | */ |
| 2300 | 2300 | protected function getModelObjNodeGroupPersister() |
| 2301 | 2301 | { |
| 2302 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2302 | + if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2303 | 2303 | $this->model_obj_node_group_persister = |
| 2304 | 2304 | $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
| 2305 | 2305 | } |
@@ -2602,7 +2602,7 @@ discard block |
||
| 2602 | 2602 | . esc_html__( |
| 2603 | 2603 | 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
| 2604 | 2604 | 'event_espresso' |
| 2605 | - ) . '</strong>'; |
|
| 2605 | + ).'</strong>'; |
|
| 2606 | 2606 | $this->display_admin_caf_preview_page('template_settings_tab'); |
| 2607 | 2607 | } |
| 2608 | 2608 | |
@@ -2623,11 +2623,11 @@ discard block |
||
| 2623 | 2623 | $this->_set_empty_category_object(); |
| 2624 | 2624 | // only set if we've got an id |
| 2625 | 2625 | $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
| 2626 | - if (! $category_ID) { |
|
| 2626 | + if ( ! $category_ID) { |
|
| 2627 | 2627 | return; |
| 2628 | 2628 | } |
| 2629 | 2629 | $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
| 2630 | - if (! empty($term)) { |
|
| 2630 | + if ( ! empty($term)) { |
|
| 2631 | 2631 | $this->_category->category_name = $term->name; |
| 2632 | 2632 | $this->_category->category_identifier = $term->slug; |
| 2633 | 2633 | $this->_category->category_desc = $term->description; |
@@ -2731,7 +2731,7 @@ discard block |
||
| 2731 | 2731 | $category_select_values, |
| 2732 | 2732 | $this->_category->parent |
| 2733 | 2733 | ); |
| 2734 | - $template_args = [ |
|
| 2734 | + $template_args = [ |
|
| 2735 | 2735 | 'category' => $this->_category, |
| 2736 | 2736 | 'category_select' => $category_select, |
| 2737 | 2737 | 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
@@ -2739,7 +2739,7 @@ discard block |
||
| 2739 | 2739 | 'disable' => '', |
| 2740 | 2740 | 'disabled_message' => false, |
| 2741 | 2741 | ]; |
| 2742 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2742 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
| 2743 | 2743 | return EEH_Template::display_template($template, $template_args, true); |
| 2744 | 2744 | } |
| 2745 | 2745 | |
@@ -2829,7 +2829,7 @@ discard block |
||
| 2829 | 2829 | $insert_ids = $update |
| 2830 | 2830 | ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
| 2831 | 2831 | : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
| 2832 | - if (! is_array($insert_ids)) { |
|
| 2832 | + if ( ! is_array($insert_ids)) { |
|
| 2833 | 2833 | $msg = esc_html__( |
| 2834 | 2834 | 'An error occurred and the category has not been saved to the database.', |
| 2835 | 2835 | 'event_espresso' |
@@ -2865,7 +2865,7 @@ discard block |
||
| 2865 | 2865 | $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
| 2866 | 2866 | $search_term = $this->request->getRequestParam('s'); |
| 2867 | 2867 | if ($search_term) { |
| 2868 | - $search_term = '%' . $search_term . '%'; |
|
| 2868 | + $search_term = '%'.$search_term.'%'; |
|
| 2869 | 2869 | $where['OR'] = [ |
| 2870 | 2870 | 'Term.name' => ['LIKE', $search_term], |
| 2871 | 2871 | 'description' => ['LIKE', $search_term], |
@@ -2874,7 +2874,7 @@ discard block |
||
| 2874 | 2874 | $query_params = [ |
| 2875 | 2875 | $where, |
| 2876 | 2876 | 'order_by' => [$orderby => $order], |
| 2877 | - 'limit' => $limit . ',' . $per_page, |
|
| 2877 | + 'limit' => $limit.','.$per_page, |
|
| 2878 | 2878 | 'force_join' => ['Term'], |
| 2879 | 2879 | ]; |
| 2880 | 2880 | return $count |
@@ -15,570 +15,570 @@ |
||
| 15 | 15 | class Events_Admin_List_Table extends EE_Admin_List_Table |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var EE_Datetime |
|
| 20 | - */ |
|
| 21 | - private $_dtt; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Initial setup of data properties for the list table. |
|
| 26 | - */ |
|
| 27 | - protected function _setup_data() |
|
| 28 | - { |
|
| 29 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 30 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Set up of additional properties for the list table. |
|
| 36 | - * |
|
| 37 | - * @throws EE_Error |
|
| 38 | - */ |
|
| 39 | - protected function _set_properties() |
|
| 40 | - { |
|
| 41 | - $this->_wp_list_args = array( |
|
| 42 | - 'singular' => esc_html__('event', 'event_espresso'), |
|
| 43 | - 'plural' => esc_html__('events', 'event_espresso'), |
|
| 44 | - 'ajax' => true, // for now |
|
| 45 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 46 | - ); |
|
| 47 | - $this->_columns = array( |
|
| 48 | - 'cb' => '<input type="checkbox" />', |
|
| 49 | - // 'status' => '', |
|
| 50 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
| 51 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
| 52 | - 'author' => esc_html__('Author', 'event_espresso'), |
|
| 53 | - 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 54 | - 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 55 | - 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 56 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
| 57 | - . '<span class="screen-reader-text">' |
|
| 58 | - . esc_html__('Approved Registrations', 'event_espresso') |
|
| 59 | - . '</span>' |
|
| 60 | - . '</span>', |
|
| 61 | - 'actions' => $this->actionsColumnHeader(), |
|
| 62 | - ); |
|
| 63 | - $this->addConditionalColumns(); |
|
| 64 | - $this->_sortable_columns = array( |
|
| 65 | - 'id' => array('EVT_ID' => true), |
|
| 66 | - 'name' => array('EVT_name' => false), |
|
| 67 | - 'author' => array('EVT_wp_user' => false), |
|
| 68 | - 'venue' => array('Venue.VNU_name' => false), |
|
| 69 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
| 70 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
| 71 | - ); |
|
| 72 | - |
|
| 73 | - $this->_primary_column = 'id'; |
|
| 74 | - $this->_hidden_columns = array('author', 'event_category'); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - protected function _get_table_filters() |
|
| 82 | - { |
|
| 83 | - return array(); // no filters with decaf |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Setup of views properties. |
|
| 89 | - * |
|
| 90 | - * @throws InvalidDataTypeException |
|
| 91 | - * @throws InvalidInterfaceException |
|
| 92 | - * @throws InvalidArgumentException |
|
| 93 | - */ |
|
| 94 | - protected function _add_view_counts() |
|
| 95 | - { |
|
| 96 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 97 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 98 | - if ( |
|
| 99 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 100 | - 'ee_delete_events', |
|
| 101 | - 'espresso_events_trash_events' |
|
| 102 | - ) |
|
| 103 | - ) { |
|
| 104 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param EE_Event $item |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - protected function _get_row_class($item) |
|
| 114 | - { |
|
| 115 | - $class = parent::_get_row_class($item); |
|
| 116 | - if ($this->_has_checkbox_column) { |
|
| 117 | - $class .= ' has-checkbox-column'; |
|
| 118 | - } |
|
| 119 | - return $class; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param EE_Event $item |
|
| 125 | - * @return string |
|
| 126 | - * @throws EE_Error |
|
| 127 | - * @throws ReflectionException |
|
| 128 | - */ |
|
| 129 | - public function column_cb($item) |
|
| 130 | - { |
|
| 131 | - if (! $item instanceof EE_Event) { |
|
| 132 | - return ''; |
|
| 133 | - } |
|
| 134 | - $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
| 135 | - $content = sprintf( |
|
| 136 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 137 | - $item->ID() |
|
| 138 | - ); |
|
| 139 | - return $this->columnContent('cb', $content, 'center'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param EE_Event $item |
|
| 145 | - * @return mixed|string |
|
| 146 | - * @throws EE_Error |
|
| 147 | - * @throws ReflectionException |
|
| 148 | - */ |
|
| 149 | - public function column_id(EE_Event $item) |
|
| 150 | - { |
|
| 151 | - $content = $item->ID(); |
|
| 152 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 153 | - return $this->columnContent('id', $content, 'end'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param EE_Event $item |
|
| 159 | - * @return string |
|
| 160 | - * @throws EE_Error |
|
| 161 | - * @throws InvalidArgumentException |
|
| 162 | - * @throws InvalidDataTypeException |
|
| 163 | - * @throws InvalidInterfaceException |
|
| 164 | - * @throws ReflectionException |
|
| 165 | - */ |
|
| 166 | - public function column_name(EE_Event $event) |
|
| 167 | - { |
|
| 168 | - $edit_query_args = array( |
|
| 169 | - 'action' => 'edit', |
|
| 170 | - 'post' => $event->ID(), |
|
| 171 | - ); |
|
| 172 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 173 | - $actions = $this->_column_name_action_setup($event); |
|
| 174 | - $status = esc_attr($event->get_active_status()); |
|
| 175 | - $pretty_status = EEH_Template::pretty_status($status, false, 'sentence'); |
|
| 176 | - $status_dot = '<span class="ee-status-dot ee-status-dot--' . $status . '"></span>'; |
|
| 177 | - $content = '<div class="ee-layout-row">'; |
|
| 178 | - $content .= '<a class="row-title status-' . $status . ' ee-aria-tooltip" aria-label="' . |
|
| 179 | - $pretty_status . '" href="' . $edit_link . '">' . $status_dot . |
|
| 180 | - $event->name() . '</a>'; |
|
| 181 | - $content .= '</div>'; |
|
| 182 | - $content .= $this->row_actions($actions); |
|
| 183 | - return $this->columnContent('name', $content); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Just a method for setting up the actions for the name column |
|
| 189 | - * |
|
| 190 | - * @param EE_Event $event |
|
| 191 | - * @return array array of actions |
|
| 192 | - * @throws EE_Error |
|
| 193 | - * @throws InvalidArgumentException |
|
| 194 | - * @throws InvalidDataTypeException |
|
| 195 | - * @throws InvalidInterfaceException |
|
| 196 | - * @throws ReflectionException |
|
| 197 | - */ |
|
| 198 | - protected function _column_name_action_setup(EE_Event $event) |
|
| 199 | - { |
|
| 200 | - // todo: remove when attendees is active |
|
| 201 | - if (! defined('REG_ADMIN_URL')) { |
|
| 202 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 203 | - } |
|
| 204 | - $actions = array(); |
|
| 205 | - $restore_event_link = ''; |
|
| 206 | - $delete_event_link = ''; |
|
| 207 | - $trash_event_link = ''; |
|
| 208 | - if ( |
|
| 209 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 210 | - 'ee_edit_event', |
|
| 211 | - 'espresso_events_edit', |
|
| 212 | - $event->ID() |
|
| 213 | - ) |
|
| 214 | - ) { |
|
| 215 | - $edit_query_args = array( |
|
| 216 | - 'action' => 'edit', |
|
| 217 | - 'post' => $event->ID(), |
|
| 218 | - ); |
|
| 219 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 220 | - $actions['edit'] = '<a href="' . $edit_link . '" class="ee-aria-tooltip" ' |
|
| 221 | - . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 222 | - . esc_html__('Edit', 'event_espresso') |
|
| 223 | - . '</a>'; |
|
| 224 | - } |
|
| 225 | - if ( |
|
| 226 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 227 | - 'ee_read_registrations', |
|
| 228 | - 'espresso_registrations_view_registration' |
|
| 229 | - ) |
|
| 230 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 231 | - 'ee_read_event', |
|
| 232 | - 'espresso_registrations_view_registration', |
|
| 233 | - $event->ID() |
|
| 234 | - ) |
|
| 235 | - ) { |
|
| 236 | - $attendees_query_args = array( |
|
| 237 | - 'action' => 'default', |
|
| 238 | - 'event_id' => $event->ID(), |
|
| 239 | - ); |
|
| 240 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 241 | - $actions['attendees'] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip"' |
|
| 242 | - . ' aria-label="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 243 | - . esc_html__('Registrations', 'event_espresso') |
|
| 244 | - . '</a>'; |
|
| 245 | - } |
|
| 246 | - if ( |
|
| 247 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 248 | - 'ee_delete_event', |
|
| 249 | - 'espresso_events_trash_event', |
|
| 250 | - $event->ID() |
|
| 251 | - ) |
|
| 252 | - ) { |
|
| 253 | - $trash_event_query_args = array( |
|
| 254 | - 'action' => 'trash_event', |
|
| 255 | - 'EVT_ID' => $event->ID(), |
|
| 256 | - ); |
|
| 257 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 258 | - $trash_event_query_args, |
|
| 259 | - EVENTS_ADMIN_URL |
|
| 260 | - ); |
|
| 261 | - } |
|
| 262 | - if ( |
|
| 263 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 264 | - 'ee_delete_event', |
|
| 265 | - 'espresso_events_restore_event', |
|
| 266 | - $event->ID() |
|
| 267 | - ) |
|
| 268 | - ) { |
|
| 269 | - $restore_event_query_args = array( |
|
| 270 | - 'action' => 'restore_event', |
|
| 271 | - 'EVT_ID' => $event->ID(), |
|
| 272 | - ); |
|
| 273 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 274 | - $restore_event_query_args, |
|
| 275 | - EVENTS_ADMIN_URL |
|
| 276 | - ); |
|
| 277 | - } |
|
| 278 | - if ( |
|
| 279 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 280 | - 'ee_delete_event', |
|
| 281 | - 'espresso_events_delete_event', |
|
| 282 | - $event->ID() |
|
| 283 | - ) |
|
| 284 | - ) { |
|
| 285 | - $delete_event_query_args = array( |
|
| 286 | - 'action' => 'delete_event', |
|
| 287 | - 'EVT_ID' => $event->ID(), |
|
| 288 | - ); |
|
| 289 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 290 | - $delete_event_query_args, |
|
| 291 | - EVENTS_ADMIN_URL |
|
| 292 | - ); |
|
| 293 | - } |
|
| 294 | - $view_link = get_permalink($event->ID()); |
|
| 295 | - $actions['view'] = '<a href="' . $view_link . '" class="ee-aria-tooltip"' |
|
| 296 | - . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 297 | - . esc_html__('View', 'event_espresso') |
|
| 298 | - . '</a>'; |
|
| 299 | - if ($event->get('status') === 'trash') { |
|
| 300 | - if ( |
|
| 301 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 302 | - 'ee_delete_event', |
|
| 303 | - 'espresso_events_restore_event', |
|
| 304 | - $event->ID() |
|
| 305 | - ) |
|
| 306 | - ) { |
|
| 307 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" class="ee-aria-tooltip"' |
|
| 308 | - . ' aria-label="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 309 | - . '">' |
|
| 310 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
| 311 | - . '</a>'; |
|
| 312 | - } |
|
| 313 | - if ( |
|
| 314 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 315 | - 'ee_delete_event', |
|
| 316 | - 'espresso_events_delete_event', |
|
| 317 | - $event->ID() |
|
| 318 | - ) |
|
| 319 | - ) { |
|
| 320 | - $actions['delete'] = '<a href="' . $delete_event_link . '" class="ee-aria-tooltip"' |
|
| 321 | - . ' aria-label="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 322 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
| 323 | - . '</a>'; |
|
| 324 | - } |
|
| 325 | - } else { |
|
| 326 | - if ( |
|
| 327 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 328 | - 'ee_delete_event', |
|
| 329 | - 'espresso_events_trash_event', |
|
| 330 | - $event->ID() |
|
| 331 | - ) |
|
| 332 | - ) { |
|
| 333 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '" class="ee-aria-tooltip"' |
|
| 334 | - . ' aria-label="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 335 | - . esc_html__('Trash', 'event_espresso') |
|
| 336 | - . '</a>'; |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - return $actions; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * @param EE_Event $event |
|
| 345 | - * @return string |
|
| 346 | - * @throws EE_Error |
|
| 347 | - * @throws ReflectionException |
|
| 348 | - */ |
|
| 349 | - public function column_author(EE_Event $event) |
|
| 350 | - { |
|
| 351 | - // user author info |
|
| 352 | - $event_author = get_userdata($event->wp_user()); |
|
| 353 | - $gravatar = get_avatar($event->wp_user(), '24'); |
|
| 354 | - // filter link |
|
| 355 | - $query_args = array( |
|
| 356 | - 'action' => 'default', |
|
| 357 | - 'EVT_wp_user' => $event->wp_user(), |
|
| 358 | - ); |
|
| 359 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 360 | - $content = '<div class="ee-layout-row">'; |
|
| 361 | - $content .= $gravatar . ' <a href="' . $filter_url . '" class="ee-aria-tooltip"' |
|
| 362 | - . ' aria-label="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 363 | - . $event_author->display_name |
|
| 364 | - . '</a>'; |
|
| 365 | - $content .= '</div>'; |
|
| 366 | - return $this->columnContent('author', $content); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * @param EE_Event $event |
|
| 372 | - * @return string |
|
| 373 | - * @throws EE_Error |
|
| 374 | - * @throws ReflectionException |
|
| 375 | - */ |
|
| 376 | - public function column_event_category(EE_Event $event) |
|
| 377 | - { |
|
| 378 | - $event_categories = $event->get_all_event_categories(); |
|
| 379 | - $content = implode( |
|
| 380 | - ', ', |
|
| 381 | - array_map( |
|
| 382 | - function (EE_Term $category) { |
|
| 383 | - return $category->name(); |
|
| 384 | - }, |
|
| 385 | - $event_categories |
|
| 386 | - ) |
|
| 387 | - ); |
|
| 388 | - return $this->columnContent('event_category', $content); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * @param EE_Event $event |
|
| 394 | - * @return string |
|
| 395 | - * @throws EE_Error |
|
| 396 | - * @throws ReflectionException |
|
| 397 | - */ |
|
| 398 | - public function column_venue(EE_Event $event) |
|
| 399 | - { |
|
| 400 | - $venue = $event->get_first_related('Venue'); |
|
| 401 | - $content = ! empty($venue) |
|
| 402 | - ? $venue->name() |
|
| 403 | - : ''; |
|
| 404 | - return $this->columnContent('venue', $content); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * @param EE_Event $event |
|
| 410 | - * @return string |
|
| 411 | - * @throws EE_Error |
|
| 412 | - * @throws ReflectionException |
|
| 413 | - */ |
|
| 414 | - public function column_start_date_time(EE_Event $event) |
|
| 415 | - { |
|
| 416 | - $content = $this->_dtt instanceof EE_Datetime |
|
| 417 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 418 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 419 | - return $this->columnContent('start_date_time', $content); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * @param EE_Event $event |
|
| 425 | - * @return string |
|
| 426 | - * @throws EE_Error |
|
| 427 | - * @throws ReflectionException |
|
| 428 | - */ |
|
| 429 | - public function column_reg_begins(EE_Event $event) |
|
| 430 | - { |
|
| 431 | - $reg_start = $event->get_ticket_with_earliest_start_time(); |
|
| 432 | - $content = $reg_start instanceof EE_Ticket |
|
| 433 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 434 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 435 | - return $this->columnContent('reg_begins', $content); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @param EE_Event $event |
|
| 441 | - * @return int|string |
|
| 442 | - * @throws EE_Error |
|
| 443 | - * @throws InvalidArgumentException |
|
| 444 | - * @throws InvalidDataTypeException |
|
| 445 | - * @throws InvalidInterfaceException |
|
| 446 | - * @throws ReflectionException |
|
| 447 | - */ |
|
| 448 | - public function column_attendees(EE_Event $event) |
|
| 449 | - { |
|
| 450 | - $attendees_query_args = array( |
|
| 451 | - 'action' => 'default', |
|
| 452 | - 'event_id' => $event->ID(), |
|
| 453 | - ); |
|
| 454 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 455 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($event->ID()); |
|
| 456 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
| 457 | - 'ee_read_event', |
|
| 458 | - 'espresso_registrations_view_registration', |
|
| 459 | - $event->ID() |
|
| 460 | - ) |
|
| 461 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 462 | - 'ee_read_registrations', |
|
| 463 | - 'espresso_registrations_view_registration' |
|
| 464 | - ) |
|
| 465 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 466 | - : $registered_attendees; |
|
| 467 | - return $this->columnContent('attendees', $content, 'center'); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @param EE_Event $event |
|
| 473 | - * @return float |
|
| 474 | - * @throws EE_Error |
|
| 475 | - * @throws InvalidArgumentException |
|
| 476 | - * @throws InvalidDataTypeException |
|
| 477 | - * @throws InvalidInterfaceException |
|
| 478 | - * @throws ReflectionException |
|
| 479 | - */ |
|
| 480 | - public function column_tkts_sold(EE_Event $event) |
|
| 481 | - { |
|
| 482 | - $content = EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $event->ID())), 'TKT_sold'); |
|
| 483 | - return $this->columnContent('tkts_sold', $content); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @param EE_Event $event |
|
| 489 | - * @return string |
|
| 490 | - * @throws EE_Error |
|
| 491 | - * @throws InvalidArgumentException |
|
| 492 | - * @throws InvalidDataTypeException |
|
| 493 | - * @throws InvalidInterfaceException |
|
| 494 | - * @throws ReflectionException |
|
| 495 | - */ |
|
| 496 | - public function column_actions(EE_Event $event) |
|
| 497 | - { |
|
| 498 | - // todo: remove when attendees is active |
|
| 499 | - if (! defined('REG_ADMIN_URL')) { |
|
| 500 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 501 | - } |
|
| 502 | - $action_links = array(); |
|
| 503 | - $view_link = get_permalink($event->ID()); |
|
| 504 | - $action_links[] = '<a href="' . $view_link . '" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 505 | - . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank"> |
|
| 18 | + /** |
|
| 19 | + * @var EE_Datetime |
|
| 20 | + */ |
|
| 21 | + private $_dtt; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Initial setup of data properties for the list table. |
|
| 26 | + */ |
|
| 27 | + protected function _setup_data() |
|
| 28 | + { |
|
| 29 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 30 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Set up of additional properties for the list table. |
|
| 36 | + * |
|
| 37 | + * @throws EE_Error |
|
| 38 | + */ |
|
| 39 | + protected function _set_properties() |
|
| 40 | + { |
|
| 41 | + $this->_wp_list_args = array( |
|
| 42 | + 'singular' => esc_html__('event', 'event_espresso'), |
|
| 43 | + 'plural' => esc_html__('events', 'event_espresso'), |
|
| 44 | + 'ajax' => true, // for now |
|
| 45 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 46 | + ); |
|
| 47 | + $this->_columns = array( |
|
| 48 | + 'cb' => '<input type="checkbox" />', |
|
| 49 | + // 'status' => '', |
|
| 50 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
| 51 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
| 52 | + 'author' => esc_html__('Author', 'event_espresso'), |
|
| 53 | + 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 54 | + 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 55 | + 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 56 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
| 57 | + . '<span class="screen-reader-text">' |
|
| 58 | + . esc_html__('Approved Registrations', 'event_espresso') |
|
| 59 | + . '</span>' |
|
| 60 | + . '</span>', |
|
| 61 | + 'actions' => $this->actionsColumnHeader(), |
|
| 62 | + ); |
|
| 63 | + $this->addConditionalColumns(); |
|
| 64 | + $this->_sortable_columns = array( |
|
| 65 | + 'id' => array('EVT_ID' => true), |
|
| 66 | + 'name' => array('EVT_name' => false), |
|
| 67 | + 'author' => array('EVT_wp_user' => false), |
|
| 68 | + 'venue' => array('Venue.VNU_name' => false), |
|
| 69 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
| 70 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
| 71 | + ); |
|
| 72 | + |
|
| 73 | + $this->_primary_column = 'id'; |
|
| 74 | + $this->_hidden_columns = array('author', 'event_category'); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + protected function _get_table_filters() |
|
| 82 | + { |
|
| 83 | + return array(); // no filters with decaf |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Setup of views properties. |
|
| 89 | + * |
|
| 90 | + * @throws InvalidDataTypeException |
|
| 91 | + * @throws InvalidInterfaceException |
|
| 92 | + * @throws InvalidArgumentException |
|
| 93 | + */ |
|
| 94 | + protected function _add_view_counts() |
|
| 95 | + { |
|
| 96 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 97 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 98 | + if ( |
|
| 99 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 100 | + 'ee_delete_events', |
|
| 101 | + 'espresso_events_trash_events' |
|
| 102 | + ) |
|
| 103 | + ) { |
|
| 104 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param EE_Event $item |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + protected function _get_row_class($item) |
|
| 114 | + { |
|
| 115 | + $class = parent::_get_row_class($item); |
|
| 116 | + if ($this->_has_checkbox_column) { |
|
| 117 | + $class .= ' has-checkbox-column'; |
|
| 118 | + } |
|
| 119 | + return $class; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param EE_Event $item |
|
| 125 | + * @return string |
|
| 126 | + * @throws EE_Error |
|
| 127 | + * @throws ReflectionException |
|
| 128 | + */ |
|
| 129 | + public function column_cb($item) |
|
| 130 | + { |
|
| 131 | + if (! $item instanceof EE_Event) { |
|
| 132 | + return ''; |
|
| 133 | + } |
|
| 134 | + $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
| 135 | + $content = sprintf( |
|
| 136 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 137 | + $item->ID() |
|
| 138 | + ); |
|
| 139 | + return $this->columnContent('cb', $content, 'center'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param EE_Event $item |
|
| 145 | + * @return mixed|string |
|
| 146 | + * @throws EE_Error |
|
| 147 | + * @throws ReflectionException |
|
| 148 | + */ |
|
| 149 | + public function column_id(EE_Event $item) |
|
| 150 | + { |
|
| 151 | + $content = $item->ID(); |
|
| 152 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 153 | + return $this->columnContent('id', $content, 'end'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param EE_Event $item |
|
| 159 | + * @return string |
|
| 160 | + * @throws EE_Error |
|
| 161 | + * @throws InvalidArgumentException |
|
| 162 | + * @throws InvalidDataTypeException |
|
| 163 | + * @throws InvalidInterfaceException |
|
| 164 | + * @throws ReflectionException |
|
| 165 | + */ |
|
| 166 | + public function column_name(EE_Event $event) |
|
| 167 | + { |
|
| 168 | + $edit_query_args = array( |
|
| 169 | + 'action' => 'edit', |
|
| 170 | + 'post' => $event->ID(), |
|
| 171 | + ); |
|
| 172 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 173 | + $actions = $this->_column_name_action_setup($event); |
|
| 174 | + $status = esc_attr($event->get_active_status()); |
|
| 175 | + $pretty_status = EEH_Template::pretty_status($status, false, 'sentence'); |
|
| 176 | + $status_dot = '<span class="ee-status-dot ee-status-dot--' . $status . '"></span>'; |
|
| 177 | + $content = '<div class="ee-layout-row">'; |
|
| 178 | + $content .= '<a class="row-title status-' . $status . ' ee-aria-tooltip" aria-label="' . |
|
| 179 | + $pretty_status . '" href="' . $edit_link . '">' . $status_dot . |
|
| 180 | + $event->name() . '</a>'; |
|
| 181 | + $content .= '</div>'; |
|
| 182 | + $content .= $this->row_actions($actions); |
|
| 183 | + return $this->columnContent('name', $content); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Just a method for setting up the actions for the name column |
|
| 189 | + * |
|
| 190 | + * @param EE_Event $event |
|
| 191 | + * @return array array of actions |
|
| 192 | + * @throws EE_Error |
|
| 193 | + * @throws InvalidArgumentException |
|
| 194 | + * @throws InvalidDataTypeException |
|
| 195 | + * @throws InvalidInterfaceException |
|
| 196 | + * @throws ReflectionException |
|
| 197 | + */ |
|
| 198 | + protected function _column_name_action_setup(EE_Event $event) |
|
| 199 | + { |
|
| 200 | + // todo: remove when attendees is active |
|
| 201 | + if (! defined('REG_ADMIN_URL')) { |
|
| 202 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 203 | + } |
|
| 204 | + $actions = array(); |
|
| 205 | + $restore_event_link = ''; |
|
| 206 | + $delete_event_link = ''; |
|
| 207 | + $trash_event_link = ''; |
|
| 208 | + if ( |
|
| 209 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 210 | + 'ee_edit_event', |
|
| 211 | + 'espresso_events_edit', |
|
| 212 | + $event->ID() |
|
| 213 | + ) |
|
| 214 | + ) { |
|
| 215 | + $edit_query_args = array( |
|
| 216 | + 'action' => 'edit', |
|
| 217 | + 'post' => $event->ID(), |
|
| 218 | + ); |
|
| 219 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 220 | + $actions['edit'] = '<a href="' . $edit_link . '" class="ee-aria-tooltip" ' |
|
| 221 | + . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 222 | + . esc_html__('Edit', 'event_espresso') |
|
| 223 | + . '</a>'; |
|
| 224 | + } |
|
| 225 | + if ( |
|
| 226 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 227 | + 'ee_read_registrations', |
|
| 228 | + 'espresso_registrations_view_registration' |
|
| 229 | + ) |
|
| 230 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 231 | + 'ee_read_event', |
|
| 232 | + 'espresso_registrations_view_registration', |
|
| 233 | + $event->ID() |
|
| 234 | + ) |
|
| 235 | + ) { |
|
| 236 | + $attendees_query_args = array( |
|
| 237 | + 'action' => 'default', |
|
| 238 | + 'event_id' => $event->ID(), |
|
| 239 | + ); |
|
| 240 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 241 | + $actions['attendees'] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip"' |
|
| 242 | + . ' aria-label="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 243 | + . esc_html__('Registrations', 'event_espresso') |
|
| 244 | + . '</a>'; |
|
| 245 | + } |
|
| 246 | + if ( |
|
| 247 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 248 | + 'ee_delete_event', |
|
| 249 | + 'espresso_events_trash_event', |
|
| 250 | + $event->ID() |
|
| 251 | + ) |
|
| 252 | + ) { |
|
| 253 | + $trash_event_query_args = array( |
|
| 254 | + 'action' => 'trash_event', |
|
| 255 | + 'EVT_ID' => $event->ID(), |
|
| 256 | + ); |
|
| 257 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 258 | + $trash_event_query_args, |
|
| 259 | + EVENTS_ADMIN_URL |
|
| 260 | + ); |
|
| 261 | + } |
|
| 262 | + if ( |
|
| 263 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 264 | + 'ee_delete_event', |
|
| 265 | + 'espresso_events_restore_event', |
|
| 266 | + $event->ID() |
|
| 267 | + ) |
|
| 268 | + ) { |
|
| 269 | + $restore_event_query_args = array( |
|
| 270 | + 'action' => 'restore_event', |
|
| 271 | + 'EVT_ID' => $event->ID(), |
|
| 272 | + ); |
|
| 273 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 274 | + $restore_event_query_args, |
|
| 275 | + EVENTS_ADMIN_URL |
|
| 276 | + ); |
|
| 277 | + } |
|
| 278 | + if ( |
|
| 279 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 280 | + 'ee_delete_event', |
|
| 281 | + 'espresso_events_delete_event', |
|
| 282 | + $event->ID() |
|
| 283 | + ) |
|
| 284 | + ) { |
|
| 285 | + $delete_event_query_args = array( |
|
| 286 | + 'action' => 'delete_event', |
|
| 287 | + 'EVT_ID' => $event->ID(), |
|
| 288 | + ); |
|
| 289 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 290 | + $delete_event_query_args, |
|
| 291 | + EVENTS_ADMIN_URL |
|
| 292 | + ); |
|
| 293 | + } |
|
| 294 | + $view_link = get_permalink($event->ID()); |
|
| 295 | + $actions['view'] = '<a href="' . $view_link . '" class="ee-aria-tooltip"' |
|
| 296 | + . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 297 | + . esc_html__('View', 'event_espresso') |
|
| 298 | + . '</a>'; |
|
| 299 | + if ($event->get('status') === 'trash') { |
|
| 300 | + if ( |
|
| 301 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 302 | + 'ee_delete_event', |
|
| 303 | + 'espresso_events_restore_event', |
|
| 304 | + $event->ID() |
|
| 305 | + ) |
|
| 306 | + ) { |
|
| 307 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" class="ee-aria-tooltip"' |
|
| 308 | + . ' aria-label="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 309 | + . '">' |
|
| 310 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
| 311 | + . '</a>'; |
|
| 312 | + } |
|
| 313 | + if ( |
|
| 314 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 315 | + 'ee_delete_event', |
|
| 316 | + 'espresso_events_delete_event', |
|
| 317 | + $event->ID() |
|
| 318 | + ) |
|
| 319 | + ) { |
|
| 320 | + $actions['delete'] = '<a href="' . $delete_event_link . '" class="ee-aria-tooltip"' |
|
| 321 | + . ' aria-label="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 322 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
| 323 | + . '</a>'; |
|
| 324 | + } |
|
| 325 | + } else { |
|
| 326 | + if ( |
|
| 327 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 328 | + 'ee_delete_event', |
|
| 329 | + 'espresso_events_trash_event', |
|
| 330 | + $event->ID() |
|
| 331 | + ) |
|
| 332 | + ) { |
|
| 333 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '" class="ee-aria-tooltip"' |
|
| 334 | + . ' aria-label="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 335 | + . esc_html__('Trash', 'event_espresso') |
|
| 336 | + . '</a>'; |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + return $actions; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * @param EE_Event $event |
|
| 345 | + * @return string |
|
| 346 | + * @throws EE_Error |
|
| 347 | + * @throws ReflectionException |
|
| 348 | + */ |
|
| 349 | + public function column_author(EE_Event $event) |
|
| 350 | + { |
|
| 351 | + // user author info |
|
| 352 | + $event_author = get_userdata($event->wp_user()); |
|
| 353 | + $gravatar = get_avatar($event->wp_user(), '24'); |
|
| 354 | + // filter link |
|
| 355 | + $query_args = array( |
|
| 356 | + 'action' => 'default', |
|
| 357 | + 'EVT_wp_user' => $event->wp_user(), |
|
| 358 | + ); |
|
| 359 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 360 | + $content = '<div class="ee-layout-row">'; |
|
| 361 | + $content .= $gravatar . ' <a href="' . $filter_url . '" class="ee-aria-tooltip"' |
|
| 362 | + . ' aria-label="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 363 | + . $event_author->display_name |
|
| 364 | + . '</a>'; |
|
| 365 | + $content .= '</div>'; |
|
| 366 | + return $this->columnContent('author', $content); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * @param EE_Event $event |
|
| 372 | + * @return string |
|
| 373 | + * @throws EE_Error |
|
| 374 | + * @throws ReflectionException |
|
| 375 | + */ |
|
| 376 | + public function column_event_category(EE_Event $event) |
|
| 377 | + { |
|
| 378 | + $event_categories = $event->get_all_event_categories(); |
|
| 379 | + $content = implode( |
|
| 380 | + ', ', |
|
| 381 | + array_map( |
|
| 382 | + function (EE_Term $category) { |
|
| 383 | + return $category->name(); |
|
| 384 | + }, |
|
| 385 | + $event_categories |
|
| 386 | + ) |
|
| 387 | + ); |
|
| 388 | + return $this->columnContent('event_category', $content); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * @param EE_Event $event |
|
| 394 | + * @return string |
|
| 395 | + * @throws EE_Error |
|
| 396 | + * @throws ReflectionException |
|
| 397 | + */ |
|
| 398 | + public function column_venue(EE_Event $event) |
|
| 399 | + { |
|
| 400 | + $venue = $event->get_first_related('Venue'); |
|
| 401 | + $content = ! empty($venue) |
|
| 402 | + ? $venue->name() |
|
| 403 | + : ''; |
|
| 404 | + return $this->columnContent('venue', $content); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * @param EE_Event $event |
|
| 410 | + * @return string |
|
| 411 | + * @throws EE_Error |
|
| 412 | + * @throws ReflectionException |
|
| 413 | + */ |
|
| 414 | + public function column_start_date_time(EE_Event $event) |
|
| 415 | + { |
|
| 416 | + $content = $this->_dtt instanceof EE_Datetime |
|
| 417 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 418 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 419 | + return $this->columnContent('start_date_time', $content); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @param EE_Event $event |
|
| 425 | + * @return string |
|
| 426 | + * @throws EE_Error |
|
| 427 | + * @throws ReflectionException |
|
| 428 | + */ |
|
| 429 | + public function column_reg_begins(EE_Event $event) |
|
| 430 | + { |
|
| 431 | + $reg_start = $event->get_ticket_with_earliest_start_time(); |
|
| 432 | + $content = $reg_start instanceof EE_Ticket |
|
| 433 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 434 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 435 | + return $this->columnContent('reg_begins', $content); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @param EE_Event $event |
|
| 441 | + * @return int|string |
|
| 442 | + * @throws EE_Error |
|
| 443 | + * @throws InvalidArgumentException |
|
| 444 | + * @throws InvalidDataTypeException |
|
| 445 | + * @throws InvalidInterfaceException |
|
| 446 | + * @throws ReflectionException |
|
| 447 | + */ |
|
| 448 | + public function column_attendees(EE_Event $event) |
|
| 449 | + { |
|
| 450 | + $attendees_query_args = array( |
|
| 451 | + 'action' => 'default', |
|
| 452 | + 'event_id' => $event->ID(), |
|
| 453 | + ); |
|
| 454 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 455 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($event->ID()); |
|
| 456 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
| 457 | + 'ee_read_event', |
|
| 458 | + 'espresso_registrations_view_registration', |
|
| 459 | + $event->ID() |
|
| 460 | + ) |
|
| 461 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 462 | + 'ee_read_registrations', |
|
| 463 | + 'espresso_registrations_view_registration' |
|
| 464 | + ) |
|
| 465 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 466 | + : $registered_attendees; |
|
| 467 | + return $this->columnContent('attendees', $content, 'center'); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @param EE_Event $event |
|
| 473 | + * @return float |
|
| 474 | + * @throws EE_Error |
|
| 475 | + * @throws InvalidArgumentException |
|
| 476 | + * @throws InvalidDataTypeException |
|
| 477 | + * @throws InvalidInterfaceException |
|
| 478 | + * @throws ReflectionException |
|
| 479 | + */ |
|
| 480 | + public function column_tkts_sold(EE_Event $event) |
|
| 481 | + { |
|
| 482 | + $content = EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $event->ID())), 'TKT_sold'); |
|
| 483 | + return $this->columnContent('tkts_sold', $content); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @param EE_Event $event |
|
| 489 | + * @return string |
|
| 490 | + * @throws EE_Error |
|
| 491 | + * @throws InvalidArgumentException |
|
| 492 | + * @throws InvalidDataTypeException |
|
| 493 | + * @throws InvalidInterfaceException |
|
| 494 | + * @throws ReflectionException |
|
| 495 | + */ |
|
| 496 | + public function column_actions(EE_Event $event) |
|
| 497 | + { |
|
| 498 | + // todo: remove when attendees is active |
|
| 499 | + if (! defined('REG_ADMIN_URL')) { |
|
| 500 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 501 | + } |
|
| 502 | + $action_links = array(); |
|
| 503 | + $view_link = get_permalink($event->ID()); |
|
| 504 | + $action_links[] = '<a href="' . $view_link . '" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 505 | + . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank"> |
|
| 506 | 506 | <span class="dashicons dashicons-search"></span></a>'; |
| 507 | - if ( |
|
| 508 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 509 | - 'ee_edit_event', |
|
| 510 | - 'espresso_events_edit', |
|
| 511 | - $event->ID() |
|
| 512 | - ) |
|
| 513 | - ) { |
|
| 514 | - $edit_query_args = array( |
|
| 515 | - 'action' => 'edit', |
|
| 516 | - 'post' => $event->ID(), |
|
| 517 | - ); |
|
| 518 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 519 | - $action_links[] = '<a href="' . $edit_link . '" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 520 | - . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 521 | - . '<span class="ee-icon ee-icon-calendar-edit"></span>' |
|
| 522 | - . '</a>'; |
|
| 523 | - } |
|
| 524 | - if ( |
|
| 525 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 526 | - 'ee_read_registrations', |
|
| 527 | - 'espresso_registrations_view_registration' |
|
| 528 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 529 | - 'ee_read_event', |
|
| 530 | - 'espresso_registrations_view_registration', |
|
| 531 | - $event->ID() |
|
| 532 | - ) |
|
| 533 | - ) { |
|
| 534 | - $attendees_query_args = array( |
|
| 535 | - 'action' => 'default', |
|
| 536 | - 'event_id' => $event->ID(), |
|
| 537 | - ); |
|
| 538 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 539 | - $action_links[] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 540 | - . ' aria-label="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 541 | - . '<span class="dashicons dashicons-groups"></span>' |
|
| 542 | - . '</a>'; |
|
| 543 | - } |
|
| 544 | - $action_links = apply_filters( |
|
| 545 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 546 | - $action_links, |
|
| 547 | - $event |
|
| 548 | - ); |
|
| 549 | - $content = $this->_action_string( |
|
| 550 | - implode("\n\t", $action_links), |
|
| 551 | - $event, |
|
| 552 | - 'div', |
|
| 553 | - 'event-overview-actions ee-list-table-actions' |
|
| 554 | - ); |
|
| 555 | - return $this->columnContent('actions', $this->actionsModalMenu($content)); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Helper for adding columns conditionally |
|
| 561 | - * |
|
| 562 | - * @throws EE_Error |
|
| 563 | - * @throws InvalidArgumentException |
|
| 564 | - * @throws InvalidDataTypeException |
|
| 565 | - * @throws InvalidInterfaceException |
|
| 566 | - */ |
|
| 567 | - private function addConditionalColumns() |
|
| 568 | - { |
|
| 569 | - $event_category_count = EEM_Term::instance()->count( |
|
| 570 | - [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
| 571 | - ); |
|
| 572 | - if ($event_category_count === 0) { |
|
| 573 | - return; |
|
| 574 | - } |
|
| 575 | - $column_array = []; |
|
| 576 | - foreach ($this->_columns as $column => $column_label) { |
|
| 577 | - $column_array[ $column ] = $column_label; |
|
| 578 | - if ($column === 'venue') { |
|
| 579 | - $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - $this->_columns = $column_array; |
|
| 583 | - } |
|
| 507 | + if ( |
|
| 508 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 509 | + 'ee_edit_event', |
|
| 510 | + 'espresso_events_edit', |
|
| 511 | + $event->ID() |
|
| 512 | + ) |
|
| 513 | + ) { |
|
| 514 | + $edit_query_args = array( |
|
| 515 | + 'action' => 'edit', |
|
| 516 | + 'post' => $event->ID(), |
|
| 517 | + ); |
|
| 518 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 519 | + $action_links[] = '<a href="' . $edit_link . '" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 520 | + . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 521 | + . '<span class="ee-icon ee-icon-calendar-edit"></span>' |
|
| 522 | + . '</a>'; |
|
| 523 | + } |
|
| 524 | + if ( |
|
| 525 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 526 | + 'ee_read_registrations', |
|
| 527 | + 'espresso_registrations_view_registration' |
|
| 528 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 529 | + 'ee_read_event', |
|
| 530 | + 'espresso_registrations_view_registration', |
|
| 531 | + $event->ID() |
|
| 532 | + ) |
|
| 533 | + ) { |
|
| 534 | + $attendees_query_args = array( |
|
| 535 | + 'action' => 'default', |
|
| 536 | + 'event_id' => $event->ID(), |
|
| 537 | + ); |
|
| 538 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 539 | + $action_links[] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 540 | + . ' aria-label="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 541 | + . '<span class="dashicons dashicons-groups"></span>' |
|
| 542 | + . '</a>'; |
|
| 543 | + } |
|
| 544 | + $action_links = apply_filters( |
|
| 545 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 546 | + $action_links, |
|
| 547 | + $event |
|
| 548 | + ); |
|
| 549 | + $content = $this->_action_string( |
|
| 550 | + implode("\n\t", $action_links), |
|
| 551 | + $event, |
|
| 552 | + 'div', |
|
| 553 | + 'event-overview-actions ee-list-table-actions' |
|
| 554 | + ); |
|
| 555 | + return $this->columnContent('actions', $this->actionsModalMenu($content)); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Helper for adding columns conditionally |
|
| 561 | + * |
|
| 562 | + * @throws EE_Error |
|
| 563 | + * @throws InvalidArgumentException |
|
| 564 | + * @throws InvalidDataTypeException |
|
| 565 | + * @throws InvalidInterfaceException |
|
| 566 | + */ |
|
| 567 | + private function addConditionalColumns() |
|
| 568 | + { |
|
| 569 | + $event_category_count = EEM_Term::instance()->count( |
|
| 570 | + [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
| 571 | + ); |
|
| 572 | + if ($event_category_count === 0) { |
|
| 573 | + return; |
|
| 574 | + } |
|
| 575 | + $column_array = []; |
|
| 576 | + foreach ($this->_columns as $column => $column_label) { |
|
| 577 | + $column_array[ $column ] = $column_label; |
|
| 578 | + if ($column === 'venue') { |
|
| 579 | + $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + $this->_columns = $column_array; |
|
| 583 | + } |
|
| 584 | 584 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function column_cb($item) |
| 130 | 130 | { |
| 131 | - if (! $item instanceof EE_Event) { |
|
| 131 | + if ( ! $item instanceof EE_Event) { |
|
| 132 | 132 | return ''; |
| 133 | 133 | } |
| 134 | 134 | $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | public function column_id(EE_Event $item) |
| 150 | 150 | { |
| 151 | 151 | $content = $item->ID(); |
| 152 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 152 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
| 153 | 153 | return $this->columnContent('id', $content, 'end'); |
| 154 | 154 | } |
| 155 | 155 | |
@@ -173,11 +173,11 @@ discard block |
||
| 173 | 173 | $actions = $this->_column_name_action_setup($event); |
| 174 | 174 | $status = esc_attr($event->get_active_status()); |
| 175 | 175 | $pretty_status = EEH_Template::pretty_status($status, false, 'sentence'); |
| 176 | - $status_dot = '<span class="ee-status-dot ee-status-dot--' . $status . '"></span>'; |
|
| 176 | + $status_dot = '<span class="ee-status-dot ee-status-dot--'.$status.'"></span>'; |
|
| 177 | 177 | $content = '<div class="ee-layout-row">'; |
| 178 | - $content .= '<a class="row-title status-' . $status . ' ee-aria-tooltip" aria-label="' . |
|
| 179 | - $pretty_status . '" href="' . $edit_link . '">' . $status_dot . |
|
| 180 | - $event->name() . '</a>'; |
|
| 178 | + $content .= '<a class="row-title status-'.$status.' ee-aria-tooltip" aria-label="'. |
|
| 179 | + $pretty_status.'" href="'.$edit_link.'">'.$status_dot. |
|
| 180 | + $event->name().'</a>'; |
|
| 181 | 181 | $content .= '</div>'; |
| 182 | 182 | $content .= $this->row_actions($actions); |
| 183 | 183 | return $this->columnContent('name', $content); |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | protected function _column_name_action_setup(EE_Event $event) |
| 199 | 199 | { |
| 200 | 200 | // todo: remove when attendees is active |
| 201 | - if (! defined('REG_ADMIN_URL')) { |
|
| 201 | + if ( ! defined('REG_ADMIN_URL')) { |
|
| 202 | 202 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
| 203 | 203 | } |
| 204 | 204 | $actions = array(); |
@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | 'post' => $event->ID(), |
| 218 | 218 | ); |
| 219 | 219 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
| 220 | - $actions['edit'] = '<a href="' . $edit_link . '" class="ee-aria-tooltip" ' |
|
| 221 | - . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 220 | + $actions['edit'] = '<a href="'.$edit_link.'" class="ee-aria-tooltip" ' |
|
| 221 | + . ' aria-label="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
| 222 | 222 | . esc_html__('Edit', 'event_espresso') |
| 223 | 223 | . '</a>'; |
| 224 | 224 | } |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | 'event_id' => $event->ID(), |
| 239 | 239 | ); |
| 240 | 240 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
| 241 | - $actions['attendees'] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip"' |
|
| 242 | - . ' aria-label="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 241 | + $actions['attendees'] = '<a href="'.$attendees_link.'" class="ee-aria-tooltip"' |
|
| 242 | + . ' aria-label="'.esc_attr__('View Registrations', 'event_espresso').'">' |
|
| 243 | 243 | . esc_html__('Registrations', 'event_espresso') |
| 244 | 244 | . '</a>'; |
| 245 | 245 | } |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | ); |
| 293 | 293 | } |
| 294 | 294 | $view_link = get_permalink($event->ID()); |
| 295 | - $actions['view'] = '<a href="' . $view_link . '" class="ee-aria-tooltip"' |
|
| 296 | - . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 295 | + $actions['view'] = '<a href="'.$view_link.'" class="ee-aria-tooltip"' |
|
| 296 | + . ' aria-label="'.esc_attr__('View Event', 'event_espresso').'">' |
|
| 297 | 297 | . esc_html__('View', 'event_espresso') |
| 298 | 298 | . '</a>'; |
| 299 | 299 | if ($event->get('status') === 'trash') { |
@@ -304,8 +304,8 @@ discard block |
||
| 304 | 304 | $event->ID() |
| 305 | 305 | ) |
| 306 | 306 | ) { |
| 307 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" class="ee-aria-tooltip"' |
|
| 308 | - . ' aria-label="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 307 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'" class="ee-aria-tooltip"' |
|
| 308 | + . ' aria-label="'.esc_attr__('Restore from Trash', 'event_espresso') |
|
| 309 | 309 | . '">' |
| 310 | 310 | . esc_html__('Restore from Trash', 'event_espresso') |
| 311 | 311 | . '</a>'; |
@@ -317,8 +317,8 @@ discard block |
||
| 317 | 317 | $event->ID() |
| 318 | 318 | ) |
| 319 | 319 | ) { |
| 320 | - $actions['delete'] = '<a href="' . $delete_event_link . '" class="ee-aria-tooltip"' |
|
| 321 | - . ' aria-label="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 320 | + $actions['delete'] = '<a href="'.$delete_event_link.'" class="ee-aria-tooltip"' |
|
| 321 | + . ' aria-label="'.esc_attr__('Delete Permanently', 'event_espresso').'">' |
|
| 322 | 322 | . esc_html__('Delete Permanently', 'event_espresso') |
| 323 | 323 | . '</a>'; |
| 324 | 324 | } |
@@ -330,8 +330,8 @@ discard block |
||
| 330 | 330 | $event->ID() |
| 331 | 331 | ) |
| 332 | 332 | ) { |
| 333 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '" class="ee-aria-tooltip"' |
|
| 334 | - . ' aria-label="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 333 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'" class="ee-aria-tooltip"' |
|
| 334 | + . ' aria-label="'.esc_attr__('Trash Event', 'event_espresso').'">' |
|
| 335 | 335 | . esc_html__('Trash', 'event_espresso') |
| 336 | 336 | . '</a>'; |
| 337 | 337 | } |
@@ -358,8 +358,8 @@ discard block |
||
| 358 | 358 | ); |
| 359 | 359 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
| 360 | 360 | $content = '<div class="ee-layout-row">'; |
| 361 | - $content .= $gravatar . ' <a href="' . $filter_url . '" class="ee-aria-tooltip"' |
|
| 362 | - . ' aria-label="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 361 | + $content .= $gravatar.' <a href="'.$filter_url.'" class="ee-aria-tooltip"' |
|
| 362 | + . ' aria-label="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">' |
|
| 363 | 363 | . $event_author->display_name |
| 364 | 364 | . '</a>'; |
| 365 | 365 | $content .= '</div>'; |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | $content = implode( |
| 380 | 380 | ', ', |
| 381 | 381 | array_map( |
| 382 | - function (EE_Term $category) { |
|
| 382 | + function(EE_Term $category) { |
|
| 383 | 383 | return $category->name(); |
| 384 | 384 | }, |
| 385 | 385 | $event_categories |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | 'ee_read_registrations', |
| 463 | 463 | 'espresso_registrations_view_registration' |
| 464 | 464 | ) |
| 465 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 465 | + ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' |
|
| 466 | 466 | : $registered_attendees; |
| 467 | 467 | return $this->columnContent('attendees', $content, 'center'); |
| 468 | 468 | } |
@@ -496,13 +496,13 @@ discard block |
||
| 496 | 496 | public function column_actions(EE_Event $event) |
| 497 | 497 | { |
| 498 | 498 | // todo: remove when attendees is active |
| 499 | - if (! defined('REG_ADMIN_URL')) { |
|
| 499 | + if ( ! defined('REG_ADMIN_URL')) { |
|
| 500 | 500 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
| 501 | 501 | } |
| 502 | 502 | $action_links = array(); |
| 503 | 503 | $view_link = get_permalink($event->ID()); |
| 504 | - $action_links[] = '<a href="' . $view_link . '" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 505 | - . ' aria-label="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank"> |
|
| 504 | + $action_links[] = '<a href="'.$view_link.'" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 505 | + . ' aria-label="'.esc_attr__('View Event', 'event_espresso').'" target="_blank"> |
|
| 506 | 506 | <span class="dashicons dashicons-search"></span></a>'; |
| 507 | 507 | if ( |
| 508 | 508 | EE_Registry::instance()->CAP->current_user_can( |
@@ -516,8 +516,8 @@ discard block |
||
| 516 | 516 | 'post' => $event->ID(), |
| 517 | 517 | ); |
| 518 | 518 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
| 519 | - $action_links[] = '<a href="' . $edit_link . '" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 520 | - . ' aria-label="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 519 | + $action_links[] = '<a href="'.$edit_link.'" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 520 | + . ' aria-label="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
| 521 | 521 | . '<span class="ee-icon ee-icon-calendar-edit"></span>' |
| 522 | 522 | . '</a>'; |
| 523 | 523 | } |
@@ -536,8 +536,8 @@ discard block |
||
| 536 | 536 | 'event_id' => $event->ID(), |
| 537 | 537 | ); |
| 538 | 538 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
| 539 | - $action_links[] = '<a href="' . $attendees_link . '" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 540 | - . ' aria-label="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 539 | + $action_links[] = '<a href="'.$attendees_link.'" class="ee-aria-tooltip button button--small button--icon-only"' |
|
| 540 | + . ' aria-label="'.esc_attr__('View Registrants', 'event_espresso').'">' |
|
| 541 | 541 | . '<span class="dashicons dashicons-groups"></span>' |
| 542 | 542 | . '</a>'; |
| 543 | 543 | } |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | } |
| 575 | 575 | $column_array = []; |
| 576 | 576 | foreach ($this->_columns as $column => $column_label) { |
| 577 | - $column_array[ $column ] = $column_label; |
|
| 577 | + $column_array[$column] = $column_label; |
|
| 578 | 578 | if ($column === 'venue') { |
| 579 | 579 | $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
| 580 | 580 | } |
@@ -14,122 +14,122 @@ discard block |
||
| 14 | 14 | class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var SessionLifespan $session_lifespan |
|
| 19 | - */ |
|
| 20 | - private $session_lifespan; |
|
| 21 | - |
|
| 22 | - private $_status; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @param Transactions_Admin_Page $admin_page |
|
| 27 | - * @param SessionLifespan $lifespan |
|
| 28 | - */ |
|
| 29 | - public function __construct(Transactions_Admin_Page $admin_page, SessionLifespan $lifespan) |
|
| 30 | - { |
|
| 31 | - parent::__construct($admin_page); |
|
| 32 | - $this->session_lifespan = $lifespan; |
|
| 33 | - $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - *_setup_data |
|
| 39 | - */ |
|
| 40 | - protected function _setup_data() |
|
| 41 | - { |
|
| 42 | - $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
| 43 | - $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
| 44 | - $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - *_set_properties |
|
| 50 | - */ |
|
| 51 | - protected function _set_properties() |
|
| 52 | - { |
|
| 53 | - $this->_wp_list_args = array( |
|
| 54 | - 'singular' => esc_html__('transaction', 'event_espresso'), |
|
| 55 | - 'plural' => esc_html__('transactions', 'event_espresso'), |
|
| 56 | - 'ajax' => true, |
|
| 57 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 58 | - ); |
|
| 59 | - $ID_column_name = esc_html__('ID', 'event_espresso'); |
|
| 60 | - $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">'; |
|
| 61 | - $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso'); |
|
| 62 | - $ID_column_name .= '</span> '; |
|
| 63 | - $this->_columns = array( |
|
| 64 | - 'id' => $ID_column_name, |
|
| 65 | - 'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'), |
|
| 66 | - 'event_name' => esc_html__('Event', 'event_espresso'), |
|
| 67 | - 'ATT_fname' => esc_html__('Primary Registrant', 'event_espresso'), |
|
| 68 | - 'TXN_paid' => esc_html__('Paid', 'event_espresso'), |
|
| 69 | - 'TXN_total' => esc_html__('Total', 'event_espresso'), |
|
| 70 | - 'actions' => $this->actionsColumnHeader(), |
|
| 71 | - ); |
|
| 72 | - |
|
| 73 | - $this->_sortable_columns = array( |
|
| 74 | - 'id' => array('TXN_ID' => false), |
|
| 75 | - 'event_name' => array('event_name' => false), |
|
| 76 | - 'ATT_fname' => array('ATT_fname' => false), |
|
| 77 | - 'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - $this->_primary_column = 'TXN_ID'; |
|
| 81 | - |
|
| 82 | - $this->_hidden_columns = array(); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * This simply sets up the row class for the table rows. |
|
| 88 | - * Allows for easier overriding of child methods for setting up sorting. |
|
| 89 | - * |
|
| 90 | - * @param EE_Transaction $transaction the current item |
|
| 91 | - * @return string |
|
| 92 | - * @throws EE_Error |
|
| 93 | - * @throws ReflectionException |
|
| 94 | - */ |
|
| 95 | - protected function _get_row_class($transaction) |
|
| 96 | - { |
|
| 97 | - $class = parent::_get_row_class($transaction); |
|
| 98 | - // add status class |
|
| 99 | - $class .= ' txn-status-' . $transaction->status_ID(); |
|
| 100 | - if ($this->_has_checkbox_column) { |
|
| 101 | - $class .= ' has-checkbox-column'; |
|
| 102 | - } |
|
| 103 | - return $class; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * _get_table_filters |
|
| 109 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 110 | - * get's shown in the table. |
|
| 111 | - * |
|
| 112 | - * @abstract |
|
| 113 | - * @access protected |
|
| 114 | - * @return array |
|
| 115 | - */ |
|
| 116 | - protected function _get_table_filters() |
|
| 117 | - { |
|
| 118 | - $filters = array(); |
|
| 119 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 120 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 121 | - : date( |
|
| 122 | - 'm/d/Y', |
|
| 123 | - strtotime('-10 year') |
|
| 124 | - ); |
|
| 125 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 126 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 127 | - : date( |
|
| 128 | - 'm/d/Y', |
|
| 129 | - current_time('timestamp') |
|
| 130 | - ); |
|
| 131 | - ob_start(); |
|
| 132 | - ?> |
|
| 17 | + /** |
|
| 18 | + * @var SessionLifespan $session_lifespan |
|
| 19 | + */ |
|
| 20 | + private $session_lifespan; |
|
| 21 | + |
|
| 22 | + private $_status; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @param Transactions_Admin_Page $admin_page |
|
| 27 | + * @param SessionLifespan $lifespan |
|
| 28 | + */ |
|
| 29 | + public function __construct(Transactions_Admin_Page $admin_page, SessionLifespan $lifespan) |
|
| 30 | + { |
|
| 31 | + parent::__construct($admin_page); |
|
| 32 | + $this->session_lifespan = $lifespan; |
|
| 33 | + $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + *_setup_data |
|
| 39 | + */ |
|
| 40 | + protected function _setup_data() |
|
| 41 | + { |
|
| 42 | + $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
| 43 | + $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
| 44 | + $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + *_set_properties |
|
| 50 | + */ |
|
| 51 | + protected function _set_properties() |
|
| 52 | + { |
|
| 53 | + $this->_wp_list_args = array( |
|
| 54 | + 'singular' => esc_html__('transaction', 'event_espresso'), |
|
| 55 | + 'plural' => esc_html__('transactions', 'event_espresso'), |
|
| 56 | + 'ajax' => true, |
|
| 57 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 58 | + ); |
|
| 59 | + $ID_column_name = esc_html__('ID', 'event_espresso'); |
|
| 60 | + $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">'; |
|
| 61 | + $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso'); |
|
| 62 | + $ID_column_name .= '</span> '; |
|
| 63 | + $this->_columns = array( |
|
| 64 | + 'id' => $ID_column_name, |
|
| 65 | + 'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'), |
|
| 66 | + 'event_name' => esc_html__('Event', 'event_espresso'), |
|
| 67 | + 'ATT_fname' => esc_html__('Primary Registrant', 'event_espresso'), |
|
| 68 | + 'TXN_paid' => esc_html__('Paid', 'event_espresso'), |
|
| 69 | + 'TXN_total' => esc_html__('Total', 'event_espresso'), |
|
| 70 | + 'actions' => $this->actionsColumnHeader(), |
|
| 71 | + ); |
|
| 72 | + |
|
| 73 | + $this->_sortable_columns = array( |
|
| 74 | + 'id' => array('TXN_ID' => false), |
|
| 75 | + 'event_name' => array('event_name' => false), |
|
| 76 | + 'ATT_fname' => array('ATT_fname' => false), |
|
| 77 | + 'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + $this->_primary_column = 'TXN_ID'; |
|
| 81 | + |
|
| 82 | + $this->_hidden_columns = array(); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * This simply sets up the row class for the table rows. |
|
| 88 | + * Allows for easier overriding of child methods for setting up sorting. |
|
| 89 | + * |
|
| 90 | + * @param EE_Transaction $transaction the current item |
|
| 91 | + * @return string |
|
| 92 | + * @throws EE_Error |
|
| 93 | + * @throws ReflectionException |
|
| 94 | + */ |
|
| 95 | + protected function _get_row_class($transaction) |
|
| 96 | + { |
|
| 97 | + $class = parent::_get_row_class($transaction); |
|
| 98 | + // add status class |
|
| 99 | + $class .= ' txn-status-' . $transaction->status_ID(); |
|
| 100 | + if ($this->_has_checkbox_column) { |
|
| 101 | + $class .= ' has-checkbox-column'; |
|
| 102 | + } |
|
| 103 | + return $class; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * _get_table_filters |
|
| 109 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 110 | + * get's shown in the table. |
|
| 111 | + * |
|
| 112 | + * @abstract |
|
| 113 | + * @access protected |
|
| 114 | + * @return array |
|
| 115 | + */ |
|
| 116 | + protected function _get_table_filters() |
|
| 117 | + { |
|
| 118 | + $filters = array(); |
|
| 119 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 120 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 121 | + : date( |
|
| 122 | + 'm/d/Y', |
|
| 123 | + strtotime('-10 year') |
|
| 124 | + ); |
|
| 125 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 126 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 127 | + : date( |
|
| 128 | + 'm/d/Y', |
|
| 129 | + current_time('timestamp') |
|
| 130 | + ); |
|
| 131 | + ob_start(); |
|
| 132 | + ?> |
|
| 133 | 133 | <label for="txn-filter-start-date">Display Transactions from </label> |
| 134 | 134 | <input class="datepicker" |
| 135 | 135 | id="txn-filter-start-date" |
@@ -147,576 +147,576 @@ discard block |
||
| 147 | 147 | value="<?php echo esc_html($end_date); ?>" |
| 148 | 148 | /> |
| 149 | 149 | <?php |
| 150 | - $filters[] = ob_get_contents(); |
|
| 151 | - ob_end_clean(); |
|
| 152 | - return $filters; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - *_add_view_counts |
|
| 158 | - */ |
|
| 159 | - protected function _add_view_counts() |
|
| 160 | - { |
|
| 161 | - foreach ($this->_views as $view) { |
|
| 162 | - $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * column TXN_ID |
|
| 169 | - * |
|
| 170 | - * @param EE_Transaction $transaction |
|
| 171 | - * @return string |
|
| 172 | - * @throws EE_Error |
|
| 173 | - */ |
|
| 174 | - public function column_id(EE_Transaction $transaction) |
|
| 175 | - { |
|
| 176 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 177 | - array( |
|
| 178 | - 'action' => 'view_transaction', |
|
| 179 | - 'TXN_ID' => $transaction->ID(), |
|
| 180 | - ), |
|
| 181 | - TXN_ADMIN_URL |
|
| 182 | - ); |
|
| 183 | - $content = '<a class="ee-aria-tooltip" href="' . $view_lnk_url . '"' |
|
| 184 | - . ' aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
| 185 | - . $transaction->ID() |
|
| 186 | - . '</a>'; |
|
| 187 | - |
|
| 188 | - // txn timestamp |
|
| 189 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
| 190 | - return $this->columnContent('id', $content, 'end'); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param EE_Transaction $transaction |
|
| 196 | - * @return string |
|
| 197 | - * @throws EE_Error |
|
| 198 | - * @throws InvalidArgumentException |
|
| 199 | - * @throws InvalidDataTypeException |
|
| 200 | - * @throws InvalidInterfaceException |
|
| 201 | - */ |
|
| 202 | - protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
| 203 | - { |
|
| 204 | - // is TXN less than 2 hours old ? |
|
| 205 | - if ( |
|
| 206 | - ($transaction->failed() || $transaction->is_abandoned()) |
|
| 207 | - && $this->session_lifespan->expiration() < $transaction->datetime(false, true) |
|
| 208 | - ) { |
|
| 209 | - $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
| 210 | - } else { |
|
| 211 | - $timestamp = $transaction->get_i18n_datetime('TXN_timestamp', 'M jS Y g:i a'); |
|
| 212 | - } |
|
| 213 | - return $timestamp; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * column_cb |
|
| 219 | - * |
|
| 220 | - * @param EE_Transaction $transaction |
|
| 221 | - * @return string |
|
| 222 | - * @throws EE_Error |
|
| 223 | - */ |
|
| 224 | - public function column_cb($transaction) |
|
| 225 | - { |
|
| 226 | - return sprintf( |
|
| 227 | - '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
| 228 | - $this->_wp_list_args['singular'], |
|
| 229 | - $transaction->ID() |
|
| 230 | - ); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * column_TXN_timestamp |
|
| 236 | - * |
|
| 237 | - * @param EE_Transaction $transaction |
|
| 238 | - * @return string |
|
| 239 | - * @throws EE_Error |
|
| 240 | - * @throws ReflectionException |
|
| 241 | - */ |
|
| 242 | - public function column_TXN_timestamp(EE_Transaction $transaction) |
|
| 243 | - { |
|
| 244 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 245 | - array( |
|
| 246 | - 'action' => 'view_transaction', |
|
| 247 | - 'TXN_ID' => $transaction->ID(), |
|
| 248 | - ), |
|
| 249 | - TXN_ADMIN_URL |
|
| 250 | - ); |
|
| 251 | - $status = esc_attr($transaction->status_ID()); |
|
| 252 | - $pretty_status = EEH_Template::pretty_status($status, false, 'sentence' ); |
|
| 253 | - return ' |
|
| 150 | + $filters[] = ob_get_contents(); |
|
| 151 | + ob_end_clean(); |
|
| 152 | + return $filters; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + *_add_view_counts |
|
| 158 | + */ |
|
| 159 | + protected function _add_view_counts() |
|
| 160 | + { |
|
| 161 | + foreach ($this->_views as $view) { |
|
| 162 | + $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * column TXN_ID |
|
| 169 | + * |
|
| 170 | + * @param EE_Transaction $transaction |
|
| 171 | + * @return string |
|
| 172 | + * @throws EE_Error |
|
| 173 | + */ |
|
| 174 | + public function column_id(EE_Transaction $transaction) |
|
| 175 | + { |
|
| 176 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 177 | + array( |
|
| 178 | + 'action' => 'view_transaction', |
|
| 179 | + 'TXN_ID' => $transaction->ID(), |
|
| 180 | + ), |
|
| 181 | + TXN_ADMIN_URL |
|
| 182 | + ); |
|
| 183 | + $content = '<a class="ee-aria-tooltip" href="' . $view_lnk_url . '"' |
|
| 184 | + . ' aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
| 185 | + . $transaction->ID() |
|
| 186 | + . '</a>'; |
|
| 187 | + |
|
| 188 | + // txn timestamp |
|
| 189 | + $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
| 190 | + return $this->columnContent('id', $content, 'end'); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param EE_Transaction $transaction |
|
| 196 | + * @return string |
|
| 197 | + * @throws EE_Error |
|
| 198 | + * @throws InvalidArgumentException |
|
| 199 | + * @throws InvalidDataTypeException |
|
| 200 | + * @throws InvalidInterfaceException |
|
| 201 | + */ |
|
| 202 | + protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
| 203 | + { |
|
| 204 | + // is TXN less than 2 hours old ? |
|
| 205 | + if ( |
|
| 206 | + ($transaction->failed() || $transaction->is_abandoned()) |
|
| 207 | + && $this->session_lifespan->expiration() < $transaction->datetime(false, true) |
|
| 208 | + ) { |
|
| 209 | + $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
| 210 | + } else { |
|
| 211 | + $timestamp = $transaction->get_i18n_datetime('TXN_timestamp', 'M jS Y g:i a'); |
|
| 212 | + } |
|
| 213 | + return $timestamp; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * column_cb |
|
| 219 | + * |
|
| 220 | + * @param EE_Transaction $transaction |
|
| 221 | + * @return string |
|
| 222 | + * @throws EE_Error |
|
| 223 | + */ |
|
| 224 | + public function column_cb($transaction) |
|
| 225 | + { |
|
| 226 | + return sprintf( |
|
| 227 | + '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
| 228 | + $this->_wp_list_args['singular'], |
|
| 229 | + $transaction->ID() |
|
| 230 | + ); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * column_TXN_timestamp |
|
| 236 | + * |
|
| 237 | + * @param EE_Transaction $transaction |
|
| 238 | + * @return string |
|
| 239 | + * @throws EE_Error |
|
| 240 | + * @throws ReflectionException |
|
| 241 | + */ |
|
| 242 | + public function column_TXN_timestamp(EE_Transaction $transaction) |
|
| 243 | + { |
|
| 244 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 245 | + array( |
|
| 246 | + 'action' => 'view_transaction', |
|
| 247 | + 'TXN_ID' => $transaction->ID(), |
|
| 248 | + ), |
|
| 249 | + TXN_ADMIN_URL |
|
| 250 | + ); |
|
| 251 | + $status = esc_attr($transaction->status_ID()); |
|
| 252 | + $pretty_status = EEH_Template::pretty_status($status, false, 'sentence' ); |
|
| 253 | + return ' |
|
| 254 | 254 | <div class="ee-layout-row"> |
| 255 | 255 | <span aria-label="' . $pretty_status . '" class="ee-status-dot ee-status-dot--' . $status . ' ee-aria-tooltip"></span> |
| 256 | 256 | <a href="' . $view_lnk_url . '" |
| 257 | 257 | class="row-title status-' . $status . ' ee-aria-tooltip" |
| 258 | 258 | aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID |
| 259 | - () . '"> |
|
| 259 | + () . '"> |
|
| 260 | 260 | ' . $this->_get_txn_timestamp($transaction) . ' |
| 261 | 261 | </a> |
| 262 | 262 | </div>'; |
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * column_TXN_total |
|
| 268 | - * |
|
| 269 | - * @param EE_Transaction $transaction |
|
| 270 | - * @return string |
|
| 271 | - * @throws EE_Error |
|
| 272 | - */ |
|
| 273 | - public function column_TXN_total(EE_Transaction $transaction) |
|
| 274 | - { |
|
| 275 | - if ($transaction->get('TXN_total') > 0) { |
|
| 276 | - return '<span class="txn-pad-rght">' |
|
| 277 | - . apply_filters( |
|
| 278 | - 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
| 279 | - $transaction->get_pretty('TXN_total'), |
|
| 280 | - $transaction |
|
| 281 | - ) |
|
| 282 | - . '</span>'; |
|
| 283 | - } else { |
|
| 284 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * column_TXN_paid |
|
| 291 | - * |
|
| 292 | - * @param EE_Transaction $transaction |
|
| 293 | - * @return mixed|string |
|
| 294 | - * @throws EE_Error |
|
| 295 | - */ |
|
| 296 | - public function column_TXN_paid(EE_Transaction $transaction) |
|
| 297 | - { |
|
| 298 | - $transaction_total = $transaction->get('TXN_total'); |
|
| 299 | - $transaction_paid = $transaction->get('TXN_paid'); |
|
| 300 | - |
|
| 301 | - if (EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
| 302 | - // monies owing |
|
| 303 | - $span_class = 'txn-overview-part-payment-spn'; |
|
| 304 | - if (EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
| 305 | - // paid in full |
|
| 306 | - $span_class = 'txn-overview-full-payment-spn'; |
|
| 307 | - } elseif (EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
| 308 | - // no payments made |
|
| 309 | - $span_class = 'txn-overview-no-payment-spn'; |
|
| 310 | - } |
|
| 311 | - } else { |
|
| 312 | - // transaction_total == 0 so this is a free event |
|
| 313 | - $span_class = 'txn-overview-free-event-spn'; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $payment_method = $transaction->payment_method(); |
|
| 317 | - $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
| 318 | - ? $payment_method->admin_name() |
|
| 319 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 320 | - |
|
| 321 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
| 322 | - . $transaction->get_pretty('TXN_paid') |
|
| 323 | - . '</span>'; |
|
| 324 | - if ($transaction_paid > 0) { |
|
| 325 | - $content .= ' <span class="ee-status-text-small">' |
|
| 326 | - . sprintf( |
|
| 327 | - esc_html__('...via %s', 'event_espresso'), |
|
| 328 | - $payment_method_name |
|
| 329 | - ) |
|
| 330 | - . '</span>'; |
|
| 331 | - } |
|
| 332 | - return "<div>{$content}</div>"; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * column_ATT_fname |
|
| 338 | - * |
|
| 339 | - * @param EE_Transaction $transaction |
|
| 340 | - * @return string |
|
| 341 | - * @throws EE_Error |
|
| 342 | - * @throws InvalidArgumentException |
|
| 343 | - * @throws InvalidDataTypeException |
|
| 344 | - * @throws InvalidInterfaceException |
|
| 345 | - */ |
|
| 346 | - public function column_ATT_fname(EE_Transaction $transaction) |
|
| 347 | - { |
|
| 348 | - $primary_reg = $transaction->primary_registration(); |
|
| 349 | - $attendee = $primary_reg->get_first_related('Attendee'); |
|
| 350 | - if ($attendee instanceof EE_Attendee) { |
|
| 351 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 352 | - array( |
|
| 353 | - 'action' => 'view_registration', |
|
| 354 | - '_REG_ID' => $primary_reg->ID(), |
|
| 355 | - ), |
|
| 356 | - REG_ADMIN_URL |
|
| 357 | - ); |
|
| 358 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
| 359 | - 'ee_read_registration', |
|
| 360 | - 'espresso_registrations_view_registration', |
|
| 361 | - $primary_reg->ID() |
|
| 362 | - ) |
|
| 363 | - ? '<a href="' . $edit_lnk_url . '"' |
|
| 364 | - . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
| 365 | - . $attendee->full_name() |
|
| 366 | - . '</a>' |
|
| 367 | - : $attendee->full_name(); |
|
| 368 | - $content .= '<br>' . $attendee->email(); |
|
| 369 | - return $content; |
|
| 370 | - } |
|
| 371 | - return $transaction->failed() || $transaction->is_abandoned() |
|
| 372 | - ? esc_html__('no contact record.', 'event_espresso') |
|
| 373 | - : esc_html__( |
|
| 374 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
| 375 | - 'event_espresso' |
|
| 376 | - ); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * column_ATT_email |
|
| 382 | - * |
|
| 383 | - * @param EE_Transaction $transaction |
|
| 384 | - * @return string |
|
| 385 | - * @throws EE_Error |
|
| 386 | - */ |
|
| 387 | - public function column_ATT_email(EE_Transaction $transaction) |
|
| 388 | - { |
|
| 389 | - $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
| 390 | - if (! empty($attendee)) { |
|
| 391 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
| 392 | - . $attendee->get('ATT_email') |
|
| 393 | - . '</a>'; |
|
| 394 | - } else { |
|
| 395 | - return $transaction->failed() || $transaction->is_abandoned() |
|
| 396 | - ? esc_html__('no contact record.', 'event_espresso') |
|
| 397 | - : esc_html__( |
|
| 398 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
| 399 | - 'event_espresso' |
|
| 400 | - ); |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * column_event_name |
|
| 407 | - * |
|
| 408 | - * @param EE_Transaction $transaction |
|
| 409 | - * @return string |
|
| 410 | - * @throws EE_Error |
|
| 411 | - * @throws InvalidArgumentException |
|
| 412 | - * @throws InvalidDataTypeException |
|
| 413 | - * @throws InvalidInterfaceException |
|
| 414 | - */ |
|
| 415 | - public function column_event_name(EE_Transaction $transaction) |
|
| 416 | - { |
|
| 417 | - $actions = array(); |
|
| 418 | - $event = $transaction->primary_registration()->get_first_related('Event'); |
|
| 419 | - if (! empty($event)) { |
|
| 420 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 421 | - array('action' => 'edit', 'post' => $event->ID()), |
|
| 422 | - EVENTS_ADMIN_URL |
|
| 423 | - ); |
|
| 424 | - $event_name = $event->get('EVT_name'); |
|
| 425 | - |
|
| 426 | - // filter this view by transactions for this event |
|
| 427 | - $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce( |
|
| 428 | - array( |
|
| 429 | - 'action' => 'default', |
|
| 430 | - 'EVT_ID' => $event->ID(), |
|
| 431 | - ) |
|
| 432 | - ); |
|
| 433 | - if ( |
|
| 434 | - empty($this->_req_data['EVT_ID']) |
|
| 435 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 436 | - 'ee_edit_event', |
|
| 437 | - 'espresso_events_edit', |
|
| 438 | - $event->ID() |
|
| 439 | - ) |
|
| 440 | - ) { |
|
| 441 | - $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"' |
|
| 442 | - . ' aria-label="' . esc_attr__( |
|
| 443 | - 'Filter transactions by this event', |
|
| 444 | - 'event_espresso' |
|
| 445 | - ) . '">' |
|
| 446 | - . esc_html__('View Transactions for this event', 'event_espresso') |
|
| 447 | - . '</a>'; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - return sprintf( |
|
| 451 | - '%1$s %2$s', |
|
| 452 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 453 | - 'ee_edit_event', |
|
| 454 | - 'espresso_events_edit', |
|
| 455 | - $event->ID() |
|
| 456 | - ) |
|
| 457 | - ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"' |
|
| 458 | - . ' aria-label="' |
|
| 459 | - . sprintf( |
|
| 460 | - esc_attr__('Edit Event: %s', 'event_espresso'), |
|
| 461 | - $event->get('EVT_name') |
|
| 462 | - ) |
|
| 463 | - . '">' |
|
| 464 | - . wp_trim_words( |
|
| 465 | - $event_name, |
|
| 466 | - 30, |
|
| 467 | - '...' |
|
| 468 | - ) |
|
| 469 | - . '</a>' |
|
| 470 | - : wp_trim_words($event_name, 30, '...'), |
|
| 471 | - $this->row_actions($actions) |
|
| 472 | - ); |
|
| 473 | - } else { |
|
| 474 | - return esc_html__( |
|
| 475 | - 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
| 476 | - 'event_espresso' |
|
| 477 | - ); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * column_actions |
|
| 484 | - * |
|
| 485 | - * @param EE_Transaction $transaction |
|
| 486 | - * @return string |
|
| 487 | - * @throws EE_Error |
|
| 488 | - */ |
|
| 489 | - public function column_actions(EE_Transaction $transaction) |
|
| 490 | - { |
|
| 491 | - return $this->actionsModalMenu( |
|
| 492 | - $this->_action_string( |
|
| 493 | - $this->get_transaction_details_link($transaction) |
|
| 494 | - . $this->get_invoice_link($transaction) |
|
| 495 | - . $this->get_receipt_link($transaction) |
|
| 496 | - . $this->get_primary_registration_details_link($transaction) |
|
| 497 | - . $this->get_send_payment_reminder_trigger_link($transaction) |
|
| 498 | - . $this->get_payment_overview_link($transaction) |
|
| 499 | - . $this->get_related_messages_link($transaction), |
|
| 500 | - $transaction, |
|
| 501 | - 'div', |
|
| 502 | - 'txn-overview-actions ee-list-table-actions' |
|
| 503 | - ) |
|
| 504 | - ); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Get the transaction details link. |
|
| 510 | - * |
|
| 511 | - * @param EE_Transaction $transaction |
|
| 512 | - * @return string |
|
| 513 | - * @throws EE_Error |
|
| 514 | - */ |
|
| 515 | - protected function get_transaction_details_link(EE_Transaction $transaction) |
|
| 516 | - { |
|
| 517 | - $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 518 | - array( |
|
| 519 | - 'action' => 'view_transaction', |
|
| 520 | - 'TXN_ID' => $transaction->ID(), |
|
| 521 | - ), |
|
| 522 | - TXN_ADMIN_URL |
|
| 523 | - ); |
|
| 524 | - return ' |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * column_TXN_total |
|
| 268 | + * |
|
| 269 | + * @param EE_Transaction $transaction |
|
| 270 | + * @return string |
|
| 271 | + * @throws EE_Error |
|
| 272 | + */ |
|
| 273 | + public function column_TXN_total(EE_Transaction $transaction) |
|
| 274 | + { |
|
| 275 | + if ($transaction->get('TXN_total') > 0) { |
|
| 276 | + return '<span class="txn-pad-rght">' |
|
| 277 | + . apply_filters( |
|
| 278 | + 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
| 279 | + $transaction->get_pretty('TXN_total'), |
|
| 280 | + $transaction |
|
| 281 | + ) |
|
| 282 | + . '</span>'; |
|
| 283 | + } else { |
|
| 284 | + return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * column_TXN_paid |
|
| 291 | + * |
|
| 292 | + * @param EE_Transaction $transaction |
|
| 293 | + * @return mixed|string |
|
| 294 | + * @throws EE_Error |
|
| 295 | + */ |
|
| 296 | + public function column_TXN_paid(EE_Transaction $transaction) |
|
| 297 | + { |
|
| 298 | + $transaction_total = $transaction->get('TXN_total'); |
|
| 299 | + $transaction_paid = $transaction->get('TXN_paid'); |
|
| 300 | + |
|
| 301 | + if (EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
| 302 | + // monies owing |
|
| 303 | + $span_class = 'txn-overview-part-payment-spn'; |
|
| 304 | + if (EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
| 305 | + // paid in full |
|
| 306 | + $span_class = 'txn-overview-full-payment-spn'; |
|
| 307 | + } elseif (EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
| 308 | + // no payments made |
|
| 309 | + $span_class = 'txn-overview-no-payment-spn'; |
|
| 310 | + } |
|
| 311 | + } else { |
|
| 312 | + // transaction_total == 0 so this is a free event |
|
| 313 | + $span_class = 'txn-overview-free-event-spn'; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $payment_method = $transaction->payment_method(); |
|
| 317 | + $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
| 318 | + ? $payment_method->admin_name() |
|
| 319 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 320 | + |
|
| 321 | + $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
| 322 | + . $transaction->get_pretty('TXN_paid') |
|
| 323 | + . '</span>'; |
|
| 324 | + if ($transaction_paid > 0) { |
|
| 325 | + $content .= ' <span class="ee-status-text-small">' |
|
| 326 | + . sprintf( |
|
| 327 | + esc_html__('...via %s', 'event_espresso'), |
|
| 328 | + $payment_method_name |
|
| 329 | + ) |
|
| 330 | + . '</span>'; |
|
| 331 | + } |
|
| 332 | + return "<div>{$content}</div>"; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * column_ATT_fname |
|
| 338 | + * |
|
| 339 | + * @param EE_Transaction $transaction |
|
| 340 | + * @return string |
|
| 341 | + * @throws EE_Error |
|
| 342 | + * @throws InvalidArgumentException |
|
| 343 | + * @throws InvalidDataTypeException |
|
| 344 | + * @throws InvalidInterfaceException |
|
| 345 | + */ |
|
| 346 | + public function column_ATT_fname(EE_Transaction $transaction) |
|
| 347 | + { |
|
| 348 | + $primary_reg = $transaction->primary_registration(); |
|
| 349 | + $attendee = $primary_reg->get_first_related('Attendee'); |
|
| 350 | + if ($attendee instanceof EE_Attendee) { |
|
| 351 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 352 | + array( |
|
| 353 | + 'action' => 'view_registration', |
|
| 354 | + '_REG_ID' => $primary_reg->ID(), |
|
| 355 | + ), |
|
| 356 | + REG_ADMIN_URL |
|
| 357 | + ); |
|
| 358 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
| 359 | + 'ee_read_registration', |
|
| 360 | + 'espresso_registrations_view_registration', |
|
| 361 | + $primary_reg->ID() |
|
| 362 | + ) |
|
| 363 | + ? '<a href="' . $edit_lnk_url . '"' |
|
| 364 | + . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
| 365 | + . $attendee->full_name() |
|
| 366 | + . '</a>' |
|
| 367 | + : $attendee->full_name(); |
|
| 368 | + $content .= '<br>' . $attendee->email(); |
|
| 369 | + return $content; |
|
| 370 | + } |
|
| 371 | + return $transaction->failed() || $transaction->is_abandoned() |
|
| 372 | + ? esc_html__('no contact record.', 'event_espresso') |
|
| 373 | + : esc_html__( |
|
| 374 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
| 375 | + 'event_espresso' |
|
| 376 | + ); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * column_ATT_email |
|
| 382 | + * |
|
| 383 | + * @param EE_Transaction $transaction |
|
| 384 | + * @return string |
|
| 385 | + * @throws EE_Error |
|
| 386 | + */ |
|
| 387 | + public function column_ATT_email(EE_Transaction $transaction) |
|
| 388 | + { |
|
| 389 | + $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
| 390 | + if (! empty($attendee)) { |
|
| 391 | + return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
| 392 | + . $attendee->get('ATT_email') |
|
| 393 | + . '</a>'; |
|
| 394 | + } else { |
|
| 395 | + return $transaction->failed() || $transaction->is_abandoned() |
|
| 396 | + ? esc_html__('no contact record.', 'event_espresso') |
|
| 397 | + : esc_html__( |
|
| 398 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
| 399 | + 'event_espresso' |
|
| 400 | + ); |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * column_event_name |
|
| 407 | + * |
|
| 408 | + * @param EE_Transaction $transaction |
|
| 409 | + * @return string |
|
| 410 | + * @throws EE_Error |
|
| 411 | + * @throws InvalidArgumentException |
|
| 412 | + * @throws InvalidDataTypeException |
|
| 413 | + * @throws InvalidInterfaceException |
|
| 414 | + */ |
|
| 415 | + public function column_event_name(EE_Transaction $transaction) |
|
| 416 | + { |
|
| 417 | + $actions = array(); |
|
| 418 | + $event = $transaction->primary_registration()->get_first_related('Event'); |
|
| 419 | + if (! empty($event)) { |
|
| 420 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 421 | + array('action' => 'edit', 'post' => $event->ID()), |
|
| 422 | + EVENTS_ADMIN_URL |
|
| 423 | + ); |
|
| 424 | + $event_name = $event->get('EVT_name'); |
|
| 425 | + |
|
| 426 | + // filter this view by transactions for this event |
|
| 427 | + $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce( |
|
| 428 | + array( |
|
| 429 | + 'action' => 'default', |
|
| 430 | + 'EVT_ID' => $event->ID(), |
|
| 431 | + ) |
|
| 432 | + ); |
|
| 433 | + if ( |
|
| 434 | + empty($this->_req_data['EVT_ID']) |
|
| 435 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 436 | + 'ee_edit_event', |
|
| 437 | + 'espresso_events_edit', |
|
| 438 | + $event->ID() |
|
| 439 | + ) |
|
| 440 | + ) { |
|
| 441 | + $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"' |
|
| 442 | + . ' aria-label="' . esc_attr__( |
|
| 443 | + 'Filter transactions by this event', |
|
| 444 | + 'event_espresso' |
|
| 445 | + ) . '">' |
|
| 446 | + . esc_html__('View Transactions for this event', 'event_espresso') |
|
| 447 | + . '</a>'; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + return sprintf( |
|
| 451 | + '%1$s %2$s', |
|
| 452 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 453 | + 'ee_edit_event', |
|
| 454 | + 'espresso_events_edit', |
|
| 455 | + $event->ID() |
|
| 456 | + ) |
|
| 457 | + ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"' |
|
| 458 | + . ' aria-label="' |
|
| 459 | + . sprintf( |
|
| 460 | + esc_attr__('Edit Event: %s', 'event_espresso'), |
|
| 461 | + $event->get('EVT_name') |
|
| 462 | + ) |
|
| 463 | + . '">' |
|
| 464 | + . wp_trim_words( |
|
| 465 | + $event_name, |
|
| 466 | + 30, |
|
| 467 | + '...' |
|
| 468 | + ) |
|
| 469 | + . '</a>' |
|
| 470 | + : wp_trim_words($event_name, 30, '...'), |
|
| 471 | + $this->row_actions($actions) |
|
| 472 | + ); |
|
| 473 | + } else { |
|
| 474 | + return esc_html__( |
|
| 475 | + 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
| 476 | + 'event_espresso' |
|
| 477 | + ); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * column_actions |
|
| 484 | + * |
|
| 485 | + * @param EE_Transaction $transaction |
|
| 486 | + * @return string |
|
| 487 | + * @throws EE_Error |
|
| 488 | + */ |
|
| 489 | + public function column_actions(EE_Transaction $transaction) |
|
| 490 | + { |
|
| 491 | + return $this->actionsModalMenu( |
|
| 492 | + $this->_action_string( |
|
| 493 | + $this->get_transaction_details_link($transaction) |
|
| 494 | + . $this->get_invoice_link($transaction) |
|
| 495 | + . $this->get_receipt_link($transaction) |
|
| 496 | + . $this->get_primary_registration_details_link($transaction) |
|
| 497 | + . $this->get_send_payment_reminder_trigger_link($transaction) |
|
| 498 | + . $this->get_payment_overview_link($transaction) |
|
| 499 | + . $this->get_related_messages_link($transaction), |
|
| 500 | + $transaction, |
|
| 501 | + 'div', |
|
| 502 | + 'txn-overview-actions ee-list-table-actions' |
|
| 503 | + ) |
|
| 504 | + ); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Get the transaction details link. |
|
| 510 | + * |
|
| 511 | + * @param EE_Transaction $transaction |
|
| 512 | + * @return string |
|
| 513 | + * @throws EE_Error |
|
| 514 | + */ |
|
| 515 | + protected function get_transaction_details_link(EE_Transaction $transaction) |
|
| 516 | + { |
|
| 517 | + $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 518 | + array( |
|
| 519 | + 'action' => 'view_transaction', |
|
| 520 | + 'TXN_ID' => $transaction->ID(), |
|
| 521 | + ), |
|
| 522 | + TXN_ADMIN_URL |
|
| 523 | + ); |
|
| 524 | + return ' |
|
| 525 | 525 | <a class="ee-aria-tooltip button button--small button--icon-only" href="' . $url . '"' |
| 526 | - . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--small button--icon-only"> |
|
| 526 | + . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--small button--icon-only"> |
|
| 527 | 527 | <span class="dashicons dashicons-cart"></span> |
| 528 | 528 | </a>'; |
| 529 | - } |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Get the invoice link for the given registration. |
|
| 534 | - * |
|
| 535 | - * @param EE_Transaction $transaction |
|
| 536 | - * @return string |
|
| 537 | - * @throws EE_Error |
|
| 538 | - */ |
|
| 539 | - protected function get_invoice_link(EE_Transaction $transaction) |
|
| 540 | - { |
|
| 541 | - $registration = $transaction->primary_registration(); |
|
| 542 | - if ($registration instanceof EE_Registration) { |
|
| 543 | - $url = $registration->invoice_url(); |
|
| 544 | - // only show invoice link if message type is active. |
|
| 545 | - if ( |
|
| 546 | - $registration->attendee() instanceof EE_Attendee |
|
| 547 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
| 548 | - ) { |
|
| 549 | - return ' |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Get the invoice link for the given registration. |
|
| 534 | + * |
|
| 535 | + * @param EE_Transaction $transaction |
|
| 536 | + * @return string |
|
| 537 | + * @throws EE_Error |
|
| 538 | + */ |
|
| 539 | + protected function get_invoice_link(EE_Transaction $transaction) |
|
| 540 | + { |
|
| 541 | + $registration = $transaction->primary_registration(); |
|
| 542 | + if ($registration instanceof EE_Registration) { |
|
| 543 | + $url = $registration->invoice_url(); |
|
| 544 | + // only show invoice link if message type is active. |
|
| 545 | + if ( |
|
| 546 | + $registration->attendee() instanceof EE_Attendee |
|
| 547 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
| 548 | + ) { |
|
| 549 | + return ' |
|
| 550 | 550 | <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
| 551 | - . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 551 | + . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 552 | 552 | <span class="dashicons dashicons-media-spreadsheet"></span> |
| 553 | 553 | </a>'; |
| 554 | - } |
|
| 555 | - } |
|
| 556 | - return ''; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Get the receipt link for the transaction. |
|
| 562 | - * |
|
| 563 | - * @param EE_Transaction $transaction |
|
| 564 | - * @return string |
|
| 565 | - * @throws EE_Error |
|
| 566 | - */ |
|
| 567 | - protected function get_receipt_link(EE_Transaction $transaction) |
|
| 568 | - { |
|
| 569 | - $registration = $transaction->primary_registration(); |
|
| 570 | - if ($registration instanceof EE_Registration) { |
|
| 571 | - $url = $registration->receipt_url(); |
|
| 572 | - // only show receipt link if message type is active. |
|
| 573 | - if ( |
|
| 574 | - $registration->attendee() instanceof EE_Attendee |
|
| 575 | - && EEH_MSG_Template::is_mt_active('receipt') |
|
| 576 | - ) { |
|
| 577 | - return ' |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + return ''; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Get the receipt link for the transaction. |
|
| 562 | + * |
|
| 563 | + * @param EE_Transaction $transaction |
|
| 564 | + * @return string |
|
| 565 | + * @throws EE_Error |
|
| 566 | + */ |
|
| 567 | + protected function get_receipt_link(EE_Transaction $transaction) |
|
| 568 | + { |
|
| 569 | + $registration = $transaction->primary_registration(); |
|
| 570 | + if ($registration instanceof EE_Registration) { |
|
| 571 | + $url = $registration->receipt_url(); |
|
| 572 | + // only show receipt link if message type is active. |
|
| 573 | + if ( |
|
| 574 | + $registration->attendee() instanceof EE_Attendee |
|
| 575 | + && EEH_MSG_Template::is_mt_active('receipt') |
|
| 576 | + ) { |
|
| 577 | + return ' |
|
| 578 | 578 | <a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
| 579 | - . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 579 | + . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 580 | 580 | <span class="dashicons dashicons-text-page"></span> |
| 581 | 581 | </a>'; |
| 582 | - } |
|
| 583 | - } |
|
| 584 | - return ''; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Get the link to view the details for the primary registration. |
|
| 590 | - * |
|
| 591 | - * @param EE_Transaction $transaction |
|
| 592 | - * @return string |
|
| 593 | - * @throws EE_Error |
|
| 594 | - * @throws InvalidArgumentException |
|
| 595 | - * @throws InvalidDataTypeException |
|
| 596 | - * @throws InvalidInterfaceException |
|
| 597 | - */ |
|
| 598 | - protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
| 599 | - { |
|
| 600 | - $registration = $transaction->primary_registration(); |
|
| 601 | - if ($registration instanceof EE_Registration) { |
|
| 602 | - $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 603 | - array( |
|
| 604 | - 'action' => 'view_registration', |
|
| 605 | - '_REG_ID' => $registration->ID(), |
|
| 606 | - ), |
|
| 607 | - REG_ADMIN_URL |
|
| 608 | - ); |
|
| 609 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 610 | - 'ee_read_registration', |
|
| 611 | - 'espresso_registrations_view_registration', |
|
| 612 | - $registration->ID() |
|
| 613 | - ) |
|
| 614 | - ? ' |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + return ''; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Get the link to view the details for the primary registration. |
|
| 590 | + * |
|
| 591 | + * @param EE_Transaction $transaction |
|
| 592 | + * @return string |
|
| 593 | + * @throws EE_Error |
|
| 594 | + * @throws InvalidArgumentException |
|
| 595 | + * @throws InvalidDataTypeException |
|
| 596 | + * @throws InvalidInterfaceException |
|
| 597 | + */ |
|
| 598 | + protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
| 599 | + { |
|
| 600 | + $registration = $transaction->primary_registration(); |
|
| 601 | + if ($registration instanceof EE_Registration) { |
|
| 602 | + $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 603 | + array( |
|
| 604 | + 'action' => 'view_registration', |
|
| 605 | + '_REG_ID' => $registration->ID(), |
|
| 606 | + ), |
|
| 607 | + REG_ADMIN_URL |
|
| 608 | + ); |
|
| 609 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 610 | + 'ee_read_registration', |
|
| 611 | + 'espresso_registrations_view_registration', |
|
| 612 | + $registration->ID() |
|
| 613 | + ) |
|
| 614 | + ? ' |
|
| 615 | 615 | <a href="' . $url . '" |
| 616 | 616 | aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '" |
| 617 | 617 | class="ee-aria-tooltip button button--small button--icon-only" |
| 618 | 618 | > |
| 619 | 619 | <span class="dashicons dashicons-clipboard"></span> |
| 620 | 620 | </a>' |
| 621 | - : ''; |
|
| 622 | - } |
|
| 623 | - return ''; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Get send payment reminder trigger link |
|
| 629 | - * |
|
| 630 | - * @param EE_Transaction $transaction |
|
| 631 | - * @return string |
|
| 632 | - * @throws EE_Error |
|
| 633 | - * @throws InvalidArgumentException |
|
| 634 | - * @throws InvalidDataTypeException |
|
| 635 | - * @throws InvalidInterfaceException |
|
| 636 | - */ |
|
| 637 | - protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
| 638 | - { |
|
| 639 | - $registration = $transaction->primary_registration(); |
|
| 640 | - if ( |
|
| 641 | - $registration instanceof EE_Registration |
|
| 642 | - && $registration->attendee() instanceof EE_Attendee |
|
| 643 | - && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 644 | - && ! in_array( |
|
| 645 | - $transaction->status_ID(), |
|
| 646 | - array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
| 647 | - true |
|
| 648 | - ) |
|
| 649 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 650 | - 'ee_send_message', |
|
| 651 | - 'espresso_transactions_send_payment_reminder' |
|
| 652 | - ) |
|
| 653 | - ) { |
|
| 654 | - $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 655 | - array( |
|
| 656 | - 'action' => 'send_payment_reminder', |
|
| 657 | - 'TXN_ID' => $transaction->ID(), |
|
| 658 | - ), |
|
| 659 | - TXN_ADMIN_URL |
|
| 660 | - ); |
|
| 661 | - return ' |
|
| 621 | + : ''; |
|
| 622 | + } |
|
| 623 | + return ''; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Get send payment reminder trigger link |
|
| 629 | + * |
|
| 630 | + * @param EE_Transaction $transaction |
|
| 631 | + * @return string |
|
| 632 | + * @throws EE_Error |
|
| 633 | + * @throws InvalidArgumentException |
|
| 634 | + * @throws InvalidDataTypeException |
|
| 635 | + * @throws InvalidInterfaceException |
|
| 636 | + */ |
|
| 637 | + protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
| 638 | + { |
|
| 639 | + $registration = $transaction->primary_registration(); |
|
| 640 | + if ( |
|
| 641 | + $registration instanceof EE_Registration |
|
| 642 | + && $registration->attendee() instanceof EE_Attendee |
|
| 643 | + && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 644 | + && ! in_array( |
|
| 645 | + $transaction->status_ID(), |
|
| 646 | + array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
| 647 | + true |
|
| 648 | + ) |
|
| 649 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 650 | + 'ee_send_message', |
|
| 651 | + 'espresso_transactions_send_payment_reminder' |
|
| 652 | + ) |
|
| 653 | + ) { |
|
| 654 | + $url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 655 | + array( |
|
| 656 | + 'action' => 'send_payment_reminder', |
|
| 657 | + 'TXN_ID' => $transaction->ID(), |
|
| 658 | + ), |
|
| 659 | + TXN_ADMIN_URL |
|
| 660 | + ); |
|
| 661 | + return ' |
|
| 662 | 662 | <a href="' . $url . '" |
| 663 | 663 | aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" |
| 664 | 664 | class="ee-aria-tooltip button button--small button--icon-only" |
| 665 | 665 | > |
| 666 | 666 | <span class="dashicons dashicons-email-alt"></span> |
| 667 | 667 | </a>'; |
| 668 | - } |
|
| 669 | - return ''; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Get link to filtered view in the message activity list table of messages for this transaction. |
|
| 675 | - * |
|
| 676 | - * @param EE_Transaction $transaction |
|
| 677 | - * @return string |
|
| 678 | - * @throws EE_Error |
|
| 679 | - * @throws InvalidArgumentException |
|
| 680 | - * @throws InvalidDataTypeException |
|
| 681 | - * @throws InvalidInterfaceException |
|
| 682 | - */ |
|
| 683 | - protected function get_related_messages_link(EE_Transaction $transaction) |
|
| 684 | - { |
|
| 685 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 686 | - 'ee_read_global_messages', |
|
| 687 | - 'view_filtered_messages' |
|
| 688 | - ) |
|
| 689 | - ? EEH_MSG_Template::get_message_action_link( |
|
| 690 | - 'see_notifications_for', |
|
| 691 | - null, |
|
| 692 | - array('TXN_ID' => $transaction->ID()) |
|
| 693 | - ) |
|
| 694 | - : ''; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * Return the link to make a payment on the frontend |
|
| 700 | - * |
|
| 701 | - * @param EE_Transaction $transaction |
|
| 702 | - * @return string |
|
| 703 | - * @throws EE_Error |
|
| 704 | - */ |
|
| 705 | - protected function get_payment_overview_link(EE_Transaction $transaction) |
|
| 706 | - { |
|
| 707 | - $registration = $transaction->primary_registration(); |
|
| 708 | - if ( |
|
| 709 | - $registration instanceof EE_Registration |
|
| 710 | - && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 711 | - && $registration->owes_monies_and_can_pay() |
|
| 712 | - ) { |
|
| 713 | - return ' |
|
| 668 | + } |
|
| 669 | + return ''; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * Get link to filtered view in the message activity list table of messages for this transaction. |
|
| 675 | + * |
|
| 676 | + * @param EE_Transaction $transaction |
|
| 677 | + * @return string |
|
| 678 | + * @throws EE_Error |
|
| 679 | + * @throws InvalidArgumentException |
|
| 680 | + * @throws InvalidDataTypeException |
|
| 681 | + * @throws InvalidInterfaceException |
|
| 682 | + */ |
|
| 683 | + protected function get_related_messages_link(EE_Transaction $transaction) |
|
| 684 | + { |
|
| 685 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 686 | + 'ee_read_global_messages', |
|
| 687 | + 'view_filtered_messages' |
|
| 688 | + ) |
|
| 689 | + ? EEH_MSG_Template::get_message_action_link( |
|
| 690 | + 'see_notifications_for', |
|
| 691 | + null, |
|
| 692 | + array('TXN_ID' => $transaction->ID()) |
|
| 693 | + ) |
|
| 694 | + : ''; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * Return the link to make a payment on the frontend |
|
| 700 | + * |
|
| 701 | + * @param EE_Transaction $transaction |
|
| 702 | + * @return string |
|
| 703 | + * @throws EE_Error |
|
| 704 | + */ |
|
| 705 | + protected function get_payment_overview_link(EE_Transaction $transaction) |
|
| 706 | + { |
|
| 707 | + $registration = $transaction->primary_registration(); |
|
| 708 | + if ( |
|
| 709 | + $registration instanceof EE_Registration |
|
| 710 | + && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 711 | + && $registration->owes_monies_and_can_pay() |
|
| 712 | + ) { |
|
| 713 | + return ' |
|
| 714 | 714 | <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
| 715 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
| 716 | - . ' class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 715 | + . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
| 716 | + . ' class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 717 | 717 | <span class="dashicons dashicons-money"></span> |
| 718 | 718 | </a>'; |
| 719 | - } |
|
| 720 | - return ''; |
|
| 721 | - } |
|
| 719 | + } |
|
| 720 | + return ''; |
|
| 721 | + } |
|
| 722 | 722 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | ); |
| 59 | 59 | $ID_column_name = esc_html__('ID', 'event_espresso'); |
| 60 | 60 | $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">'; |
| 61 | - $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso'); |
|
| 61 | + $ID_column_name .= ' : '.esc_html__('Transaction Date', 'event_espresso'); |
|
| 62 | 62 | $ID_column_name .= '</span> '; |
| 63 | 63 | $this->_columns = array( |
| 64 | 64 | 'id' => $ID_column_name, |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | { |
| 97 | 97 | $class = parent::_get_row_class($transaction); |
| 98 | 98 | // add status class |
| 99 | - $class .= ' txn-status-' . $transaction->status_ID(); |
|
| 99 | + $class .= ' txn-status-'.$transaction->status_ID(); |
|
| 100 | 100 | if ($this->_has_checkbox_column) { |
| 101 | 101 | $class .= ' has-checkbox-column'; |
| 102 | 102 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | protected function _add_view_counts() |
| 160 | 160 | { |
| 161 | 161 | foreach ($this->_views as $view) { |
| 162 | - $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
| 162 | + $this->_views[$view['slug']]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']); |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | ), |
| 181 | 181 | TXN_ADMIN_URL |
| 182 | 182 | ); |
| 183 | - $content = '<a class="ee-aria-tooltip" href="' . $view_lnk_url . '"' |
|
| 184 | - . ' aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
| 183 | + $content = '<a class="ee-aria-tooltip" href="'.$view_lnk_url.'"' |
|
| 184 | + . ' aria-label="'.esc_attr__('Go to Transaction Details', 'event_espresso').'">' |
|
| 185 | 185 | . $transaction->ID() |
| 186 | 186 | . '</a>'; |
| 187 | 187 | |
| 188 | 188 | // txn timestamp |
| 189 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
| 189 | + $content .= ' <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>'; |
|
| 190 | 190 | return $this->columnContent('id', $content, 'end'); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -249,15 +249,14 @@ discard block |
||
| 249 | 249 | TXN_ADMIN_URL |
| 250 | 250 | ); |
| 251 | 251 | $status = esc_attr($transaction->status_ID()); |
| 252 | - $pretty_status = EEH_Template::pretty_status($status, false, 'sentence' ); |
|
| 252 | + $pretty_status = EEH_Template::pretty_status($status, false, 'sentence'); |
|
| 253 | 253 | return ' |
| 254 | 254 | <div class="ee-layout-row"> |
| 255 | - <span aria-label="' . $pretty_status . '" class="ee-status-dot ee-status-dot--' . $status . ' ee-aria-tooltip"></span> |
|
| 256 | - <a href="' . $view_lnk_url . '" |
|
| 257 | - class="row-title status-' . $status . ' ee-aria-tooltip" |
|
| 258 | - aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID |
|
| 259 | - () . '"> |
|
| 260 | - ' . $this->_get_txn_timestamp($transaction) . ' |
|
| 255 | + <span aria-label="' . $pretty_status.'" class="ee-status-dot ee-status-dot--'.$status.' ee-aria-tooltip"></span> |
|
| 256 | + <a href="' . $view_lnk_url.'" |
|
| 257 | + class="row-title status-' . $status.' ee-aria-tooltip" |
|
| 258 | + aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID().'"> |
|
| 259 | + ' . $this->_get_txn_timestamp($transaction).' |
|
| 261 | 260 | </a> |
| 262 | 261 | </div>'; |
| 263 | 262 | } |
@@ -281,7 +280,7 @@ discard block |
||
| 281 | 280 | ) |
| 282 | 281 | . '</span>'; |
| 283 | 282 | } else { |
| 284 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
| 283 | + return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>'; |
|
| 285 | 284 | } |
| 286 | 285 | } |
| 287 | 286 | |
@@ -318,7 +317,7 @@ discard block |
||
| 318 | 317 | ? $payment_method->admin_name() |
| 319 | 318 | : esc_html__('Unknown', 'event_espresso'); |
| 320 | 319 | |
| 321 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
| 320 | + $content = '<span class="'.$span_class.' txn-pad-rght">' |
|
| 322 | 321 | . $transaction->get_pretty('TXN_paid') |
| 323 | 322 | . '</span>'; |
| 324 | 323 | if ($transaction_paid > 0) { |
@@ -360,12 +359,12 @@ discard block |
||
| 360 | 359 | 'espresso_registrations_view_registration', |
| 361 | 360 | $primary_reg->ID() |
| 362 | 361 | ) |
| 363 | - ? '<a href="' . $edit_lnk_url . '"' |
|
| 364 | - . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
| 362 | + ? '<a href="'.$edit_lnk_url.'"' |
|
| 363 | + . ' aria-label="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
| 365 | 364 | . $attendee->full_name() |
| 366 | 365 | . '</a>' |
| 367 | 366 | : $attendee->full_name(); |
| 368 | - $content .= '<br>' . $attendee->email(); |
|
| 367 | + $content .= '<br>'.$attendee->email(); |
|
| 369 | 368 | return $content; |
| 370 | 369 | } |
| 371 | 370 | return $transaction->failed() || $transaction->is_abandoned() |
@@ -387,8 +386,8 @@ discard block |
||
| 387 | 386 | public function column_ATT_email(EE_Transaction $transaction) |
| 388 | 387 | { |
| 389 | 388 | $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
| 390 | - if (! empty($attendee)) { |
|
| 391 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
| 389 | + if ( ! empty($attendee)) { |
|
| 390 | + return '<a href="mailto:'.$attendee->get('ATT_email').'">' |
|
| 392 | 391 | . $attendee->get('ATT_email') |
| 393 | 392 | . '</a>'; |
| 394 | 393 | } else { |
@@ -416,7 +415,7 @@ discard block |
||
| 416 | 415 | { |
| 417 | 416 | $actions = array(); |
| 418 | 417 | $event = $transaction->primary_registration()->get_first_related('Event'); |
| 419 | - if (! empty($event)) { |
|
| 418 | + if ( ! empty($event)) { |
|
| 420 | 419 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
| 421 | 420 | array('action' => 'edit', 'post' => $event->ID()), |
| 422 | 421 | EVENTS_ADMIN_URL |
@@ -438,11 +437,11 @@ discard block |
||
| 438 | 437 | $event->ID() |
| 439 | 438 | ) |
| 440 | 439 | ) { |
| 441 | - $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"' |
|
| 442 | - . ' aria-label="' . esc_attr__( |
|
| 440 | + $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="'.$txn_by_event_lnk.'"' |
|
| 441 | + . ' aria-label="'.esc_attr__( |
|
| 443 | 442 | 'Filter transactions by this event', |
| 444 | 443 | 'event_espresso' |
| 445 | - ) . '">' |
|
| 444 | + ).'">' |
|
| 446 | 445 | . esc_html__('View Transactions for this event', 'event_espresso') |
| 447 | 446 | . '</a>'; |
| 448 | 447 | } |
@@ -454,7 +453,7 @@ discard block |
||
| 454 | 453 | 'espresso_events_edit', |
| 455 | 454 | $event->ID() |
| 456 | 455 | ) |
| 457 | - ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"' |
|
| 456 | + ? '<a class="ee-aria-tooltip" href="'.$edit_event_url.'"' |
|
| 458 | 457 | . ' aria-label="' |
| 459 | 458 | . sprintf( |
| 460 | 459 | esc_attr__('Edit Event: %s', 'event_espresso'), |
@@ -522,8 +521,8 @@ discard block |
||
| 522 | 521 | TXN_ADMIN_URL |
| 523 | 522 | ); |
| 524 | 523 | return ' |
| 525 | - <a class="ee-aria-tooltip button button--small button--icon-only" href="' . $url . '"' |
|
| 526 | - . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--small button--icon-only"> |
|
| 524 | + <a class="ee-aria-tooltip button button--small button--icon-only" href="' . $url.'"' |
|
| 525 | + . ' aria-label="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="button button--small button--icon-only"> |
|
| 527 | 526 | <span class="dashicons dashicons-cart"></span> |
| 528 | 527 | </a>'; |
| 529 | 528 | } |
@@ -547,8 +546,8 @@ discard block |
||
| 547 | 546 | && EEH_MSG_Template::is_mt_active('invoice') |
| 548 | 547 | ) { |
| 549 | 548 | return ' |
| 550 | - <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
|
| 551 | - . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 549 | + <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"' |
|
| 550 | + . ' target="_blank" href="'.$url.'" class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 552 | 551 | <span class="dashicons dashicons-media-spreadsheet"></span> |
| 553 | 552 | </a>'; |
| 554 | 553 | } |
@@ -575,8 +574,8 @@ discard block |
||
| 575 | 574 | && EEH_MSG_Template::is_mt_active('receipt') |
| 576 | 575 | ) { |
| 577 | 576 | return ' |
| 578 | - <a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
|
| 579 | - . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 577 | + <a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"' |
|
| 578 | + . ' target="_blank" href="'.$url.'" class="ee-aria-tooltip button button--small button--icon-only"> |
|
| 580 | 579 | <span class="dashicons dashicons-text-page"></span> |
| 581 | 580 | </a>'; |
| 582 | 581 | } |
@@ -612,8 +611,8 @@ discard block |
||
| 612 | 611 | $registration->ID() |
| 613 | 612 | ) |
| 614 | 613 | ? ' |
| 615 | - <a href="' . $url . '" |
|
| 616 | - aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '" |
|
| 614 | + <a href="' . $url.'" |
|
| 615 | + aria-label="' . esc_attr__('View Registration Details', 'event_espresso').'" |
|
| 617 | 616 | class="ee-aria-tooltip button button--small button--icon-only" |
| 618 | 617 | > |
| 619 | 618 | <span class="dashicons dashicons-clipboard"></span> |
@@ -659,8 +658,8 @@ discard block |
||
| 659 | 658 | TXN_ADMIN_URL |
| 660 | 659 | ); |
| 661 | 660 | return ' |
| 662 | - <a href="' . $url . '" |
|
| 663 | - aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" |
|
| 661 | + <a href="' . $url.'" |
|
| 662 | + aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso').'" |
|
| 664 | 663 | class="ee-aria-tooltip button button--small button--icon-only" |
| 665 | 664 | > |
| 666 | 665 | <span class="dashicons dashicons-email-alt"></span> |
@@ -711,8 +710,8 @@ discard block |
||
| 711 | 710 | && $registration->owes_monies_and_can_pay() |
| 712 | 711 | ) { |
| 713 | 712 | return ' |
| 714 | - <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
|
| 715 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
| 713 | + <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"' |
|
| 714 | + . ' target="_blank" href="'.$registration->payment_overview_url(true).'"' |
|
| 716 | 715 | . ' class="ee-aria-tooltip button button--small button--icon-only"> |
| 717 | 716 | <span class="dashicons dashicons-money"></span> |
| 718 | 717 | </a>'; |
@@ -19,2228 +19,2228 @@ discard block |
||
| 19 | 19 | class Registrations_Admin_Page extends EE_Admin_Page_CPT |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var EE_Registration |
|
| 24 | - */ |
|
| 25 | - private $_registration; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var EE_Event |
|
| 29 | - */ |
|
| 30 | - private $_reg_event; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var EE_Session |
|
| 34 | - */ |
|
| 35 | - private $_session; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - private static $_reg_status; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Form for displaying the custom questions for this registration. |
|
| 44 | - * This gets used a few times throughout the request so its best to cache it |
|
| 45 | - * |
|
| 46 | - * @var EE_Registration_Custom_Questions_Form |
|
| 47 | - */ |
|
| 48 | - protected $_reg_custom_questions_form; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var EEM_Registration $registration_model |
|
| 52 | - */ |
|
| 53 | - private $registration_model; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var EEM_Attendee $attendee_model |
|
| 57 | - */ |
|
| 58 | - private $attendee_model; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var EEM_Event $event_model |
|
| 62 | - */ |
|
| 63 | - private $event_model; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var EEM_Status $status_model |
|
| 67 | - */ |
|
| 68 | - private $status_model; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param bool $routing |
|
| 73 | - * @throws EE_Error |
|
| 74 | - * @throws InvalidArgumentException |
|
| 75 | - * @throws InvalidDataTypeException |
|
| 76 | - * @throws InvalidInterfaceException |
|
| 77 | - * @throws ReflectionException |
|
| 78 | - */ |
|
| 79 | - public function __construct($routing = true) |
|
| 80 | - { |
|
| 81 | - parent::__construct($routing); |
|
| 82 | - add_action('wp_loaded', [$this, 'wp_loaded']); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @return EEM_Registration |
|
| 88 | - * @throws InvalidArgumentException |
|
| 89 | - * @throws InvalidDataTypeException |
|
| 90 | - * @throws InvalidInterfaceException |
|
| 91 | - * @since 4.10.2.p |
|
| 92 | - */ |
|
| 93 | - protected function getRegistrationModel() |
|
| 94 | - { |
|
| 95 | - if (! $this->registration_model instanceof EEM_Registration) { |
|
| 96 | - $this->registration_model = $this->loader->getShared('EEM_Registration'); |
|
| 97 | - } |
|
| 98 | - return $this->registration_model; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @return EEM_Attendee |
|
| 104 | - * @throws InvalidArgumentException |
|
| 105 | - * @throws InvalidDataTypeException |
|
| 106 | - * @throws InvalidInterfaceException |
|
| 107 | - * @since 4.10.2.p |
|
| 108 | - */ |
|
| 109 | - protected function getAttendeeModel() |
|
| 110 | - { |
|
| 111 | - if (! $this->attendee_model instanceof EEM_Attendee) { |
|
| 112 | - $this->attendee_model = $this->loader->getShared('EEM_Attendee'); |
|
| 113 | - } |
|
| 114 | - return $this->attendee_model; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return EEM_Event |
|
| 120 | - * @throws InvalidArgumentException |
|
| 121 | - * @throws InvalidDataTypeException |
|
| 122 | - * @throws InvalidInterfaceException |
|
| 123 | - * @since 4.10.2.p |
|
| 124 | - */ |
|
| 125 | - protected function getEventModel() |
|
| 126 | - { |
|
| 127 | - if (! $this->event_model instanceof EEM_Event) { |
|
| 128 | - $this->event_model = $this->loader->getShared('EEM_Event'); |
|
| 129 | - } |
|
| 130 | - return $this->event_model; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @return EEM_Status |
|
| 136 | - * @throws InvalidArgumentException |
|
| 137 | - * @throws InvalidDataTypeException |
|
| 138 | - * @throws InvalidInterfaceException |
|
| 139 | - * @since 4.10.2.p |
|
| 140 | - */ |
|
| 141 | - protected function getStatusModel() |
|
| 142 | - { |
|
| 143 | - if (! $this->status_model instanceof EEM_Status) { |
|
| 144 | - $this->status_model = $this->loader->getShared('EEM_Status'); |
|
| 145 | - } |
|
| 146 | - return $this->status_model; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - public function wp_loaded() |
|
| 151 | - { |
|
| 152 | - // when adding a new registration... |
|
| 153 | - $action = $this->request->getRequestParam('action'); |
|
| 154 | - if ($action === 'new_registration') { |
|
| 155 | - EE_System::do_not_cache(); |
|
| 156 | - if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) { |
|
| 157 | - // and it's NOT the attendee information reg step |
|
| 158 | - // force cookie expiration by setting time to last week |
|
| 159 | - setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 160 | - // and update the global |
|
| 161 | - $_COOKIE['ee_registration_added'] = 0; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - protected function _init_page_props() |
|
| 168 | - { |
|
| 169 | - $this->page_slug = REG_PG_SLUG; |
|
| 170 | - $this->_admin_base_url = REG_ADMIN_URL; |
|
| 171 | - $this->_admin_base_path = REG_ADMIN; |
|
| 172 | - $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
| 173 | - $this->_cpt_routes = [ |
|
| 174 | - 'add_new_attendee' => 'espresso_attendees', |
|
| 175 | - 'edit_attendee' => 'espresso_attendees', |
|
| 176 | - 'insert_attendee' => 'espresso_attendees', |
|
| 177 | - 'update_attendee' => 'espresso_attendees', |
|
| 178 | - ]; |
|
| 179 | - $this->_cpt_model_names = [ |
|
| 180 | - 'add_new_attendee' => 'EEM_Attendee', |
|
| 181 | - 'edit_attendee' => 'EEM_Attendee', |
|
| 182 | - ]; |
|
| 183 | - $this->_cpt_edit_routes = [ |
|
| 184 | - 'espresso_attendees' => 'edit_attendee', |
|
| 185 | - ]; |
|
| 186 | - $this->_pagenow_map = [ |
|
| 187 | - 'add_new_attendee' => 'post-new.php', |
|
| 188 | - 'edit_attendee' => 'post.php', |
|
| 189 | - 'trash' => 'post.php', |
|
| 190 | - ]; |
|
| 191 | - add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10); |
|
| 192 | - // add filters so that the comment urls don't take users to a confusing 404 page |
|
| 193 | - add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param string $link The comment permalink with '#comment-$id' appended. |
|
| 199 | - * @param WP_Comment $comment The current comment object. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public function clear_comment_link($link, WP_Comment $comment) |
|
| 203 | - { |
|
| 204 | - // gotta make sure this only happens on this route |
|
| 205 | - $post_type = get_post_type($comment->comment_post_ID); |
|
| 206 | - if ($post_type === 'espresso_attendees') { |
|
| 207 | - return '#commentsdiv'; |
|
| 208 | - } |
|
| 209 | - return $link; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - protected function _ajax_hooks() |
|
| 214 | - { |
|
| 215 | - // todo: all hooks for registrations ajax goes in here |
|
| 216 | - add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - protected function _define_page_props() |
|
| 221 | - { |
|
| 222 | - $this->_admin_page_title = $this->page_label; |
|
| 223 | - $this->_labels = [ |
|
| 224 | - 'buttons' => [ |
|
| 225 | - 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 226 | - 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
| 227 | - 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 228 | - 'report' => esc_html__('Event Registrations CSV Report', 'event_espresso'), |
|
| 229 | - 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
| 230 | - 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
| 231 | - 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
| 232 | - 'contact_list_export' => esc_html__('Export Data', 'event_espresso'), |
|
| 233 | - ], |
|
| 234 | - 'publishbox' => [ |
|
| 235 | - 'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'), |
|
| 236 | - 'edit_attendee' => esc_html__('Update Contact Record', 'event_espresso'), |
|
| 237 | - ], |
|
| 238 | - 'hide_add_button_on_cpt_route' => [ |
|
| 239 | - 'edit_attendee' => true, |
|
| 240 | - ], |
|
| 241 | - ]; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * grab url requests and route them |
|
| 247 | - * |
|
| 248 | - * @return void |
|
| 249 | - * @throws EE_Error |
|
| 250 | - */ |
|
| 251 | - public function _set_page_routes() |
|
| 252 | - { |
|
| 253 | - $this->_get_registration_status_array(); |
|
| 254 | - $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 255 | - $REG_ID = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int'); |
|
| 256 | - $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int'); |
|
| 257 | - $ATT_ID = $this->request->getRequestParam('post', $ATT_ID, 'int'); |
|
| 258 | - $this->_page_routes = [ |
|
| 259 | - 'default' => [ |
|
| 260 | - 'func' => '_registrations_overview_list_table', |
|
| 261 | - 'capability' => 'ee_read_registrations', |
|
| 262 | - ], |
|
| 263 | - 'view_registration' => [ |
|
| 264 | - 'func' => '_registration_details', |
|
| 265 | - 'capability' => 'ee_read_registration', |
|
| 266 | - 'obj_id' => $REG_ID, |
|
| 267 | - ], |
|
| 268 | - 'edit_registration' => [ |
|
| 269 | - 'func' => '_update_attendee_registration_form', |
|
| 270 | - 'noheader' => true, |
|
| 271 | - 'headers_sent_route' => 'view_registration', |
|
| 272 | - 'capability' => 'ee_edit_registration', |
|
| 273 | - 'obj_id' => $REG_ID, |
|
| 274 | - '_REG_ID' => $REG_ID, |
|
| 275 | - ], |
|
| 276 | - 'trash_registrations' => [ |
|
| 277 | - 'func' => '_trash_or_restore_registrations', |
|
| 278 | - 'args' => ['trash' => true], |
|
| 279 | - 'noheader' => true, |
|
| 280 | - 'capability' => 'ee_delete_registrations', |
|
| 281 | - ], |
|
| 282 | - 'restore_registrations' => [ |
|
| 283 | - 'func' => '_trash_or_restore_registrations', |
|
| 284 | - 'args' => ['trash' => false], |
|
| 285 | - 'noheader' => true, |
|
| 286 | - 'capability' => 'ee_delete_registrations', |
|
| 287 | - ], |
|
| 288 | - 'delete_registrations' => [ |
|
| 289 | - 'func' => '_delete_registrations', |
|
| 290 | - 'noheader' => true, |
|
| 291 | - 'capability' => 'ee_delete_registrations', |
|
| 292 | - ], |
|
| 293 | - 'new_registration' => [ |
|
| 294 | - 'func' => 'new_registration', |
|
| 295 | - 'capability' => 'ee_edit_registrations', |
|
| 296 | - ], |
|
| 297 | - 'process_reg_step' => [ |
|
| 298 | - 'func' => 'process_reg_step', |
|
| 299 | - 'noheader' => true, |
|
| 300 | - 'capability' => 'ee_edit_registrations', |
|
| 301 | - ], |
|
| 302 | - 'redirect_to_txn' => [ |
|
| 303 | - 'func' => 'redirect_to_txn', |
|
| 304 | - 'noheader' => true, |
|
| 305 | - 'capability' => 'ee_edit_registrations', |
|
| 306 | - ], |
|
| 307 | - 'change_reg_status' => [ |
|
| 308 | - 'func' => '_change_reg_status', |
|
| 309 | - 'noheader' => true, |
|
| 310 | - 'capability' => 'ee_edit_registration', |
|
| 311 | - 'obj_id' => $REG_ID, |
|
| 312 | - ], |
|
| 313 | - 'approve_registration' => [ |
|
| 314 | - 'func' => 'approve_registration', |
|
| 315 | - 'noheader' => true, |
|
| 316 | - 'capability' => 'ee_edit_registration', |
|
| 317 | - 'obj_id' => $REG_ID, |
|
| 318 | - ], |
|
| 319 | - 'approve_and_notify_registration' => [ |
|
| 320 | - 'func' => 'approve_registration', |
|
| 321 | - 'noheader' => true, |
|
| 322 | - 'args' => [true], |
|
| 323 | - 'capability' => 'ee_edit_registration', |
|
| 324 | - 'obj_id' => $REG_ID, |
|
| 325 | - ], |
|
| 326 | - 'approve_registrations' => [ |
|
| 327 | - 'func' => 'bulk_action_on_registrations', |
|
| 328 | - 'noheader' => true, |
|
| 329 | - 'capability' => 'ee_edit_registrations', |
|
| 330 | - 'args' => ['approve'], |
|
| 331 | - ], |
|
| 332 | - 'approve_and_notify_registrations' => [ |
|
| 333 | - 'func' => 'bulk_action_on_registrations', |
|
| 334 | - 'noheader' => true, |
|
| 335 | - 'capability' => 'ee_edit_registrations', |
|
| 336 | - 'args' => ['approve', true], |
|
| 337 | - ], |
|
| 338 | - 'decline_registration' => [ |
|
| 339 | - 'func' => 'decline_registration', |
|
| 340 | - 'noheader' => true, |
|
| 341 | - 'capability' => 'ee_edit_registration', |
|
| 342 | - 'obj_id' => $REG_ID, |
|
| 343 | - ], |
|
| 344 | - 'decline_and_notify_registration' => [ |
|
| 345 | - 'func' => 'decline_registration', |
|
| 346 | - 'noheader' => true, |
|
| 347 | - 'args' => [true], |
|
| 348 | - 'capability' => 'ee_edit_registration', |
|
| 349 | - 'obj_id' => $REG_ID, |
|
| 350 | - ], |
|
| 351 | - 'decline_registrations' => [ |
|
| 352 | - 'func' => 'bulk_action_on_registrations', |
|
| 353 | - 'noheader' => true, |
|
| 354 | - 'capability' => 'ee_edit_registrations', |
|
| 355 | - 'args' => ['decline'], |
|
| 356 | - ], |
|
| 357 | - 'decline_and_notify_registrations' => [ |
|
| 358 | - 'func' => 'bulk_action_on_registrations', |
|
| 359 | - 'noheader' => true, |
|
| 360 | - 'capability' => 'ee_edit_registrations', |
|
| 361 | - 'args' => ['decline', true], |
|
| 362 | - ], |
|
| 363 | - 'pending_registration' => [ |
|
| 364 | - 'func' => 'pending_registration', |
|
| 365 | - 'noheader' => true, |
|
| 366 | - 'capability' => 'ee_edit_registration', |
|
| 367 | - 'obj_id' => $REG_ID, |
|
| 368 | - ], |
|
| 369 | - 'pending_and_notify_registration' => [ |
|
| 370 | - 'func' => 'pending_registration', |
|
| 371 | - 'noheader' => true, |
|
| 372 | - 'args' => [true], |
|
| 373 | - 'capability' => 'ee_edit_registration', |
|
| 374 | - 'obj_id' => $REG_ID, |
|
| 375 | - ], |
|
| 376 | - 'pending_registrations' => [ |
|
| 377 | - 'func' => 'bulk_action_on_registrations', |
|
| 378 | - 'noheader' => true, |
|
| 379 | - 'capability' => 'ee_edit_registrations', |
|
| 380 | - 'args' => ['pending'], |
|
| 381 | - ], |
|
| 382 | - 'pending_and_notify_registrations' => [ |
|
| 383 | - 'func' => 'bulk_action_on_registrations', |
|
| 384 | - 'noheader' => true, |
|
| 385 | - 'capability' => 'ee_edit_registrations', |
|
| 386 | - 'args' => ['pending', true], |
|
| 387 | - ], |
|
| 388 | - 'no_approve_registration' => [ |
|
| 389 | - 'func' => 'not_approve_registration', |
|
| 390 | - 'noheader' => true, |
|
| 391 | - 'capability' => 'ee_edit_registration', |
|
| 392 | - 'obj_id' => $REG_ID, |
|
| 393 | - ], |
|
| 394 | - 'no_approve_and_notify_registration' => [ |
|
| 395 | - 'func' => 'not_approve_registration', |
|
| 396 | - 'noheader' => true, |
|
| 397 | - 'args' => [true], |
|
| 398 | - 'capability' => 'ee_edit_registration', |
|
| 399 | - 'obj_id' => $REG_ID, |
|
| 400 | - ], |
|
| 401 | - 'no_approve_registrations' => [ |
|
| 402 | - 'func' => 'bulk_action_on_registrations', |
|
| 403 | - 'noheader' => true, |
|
| 404 | - 'capability' => 'ee_edit_registrations', |
|
| 405 | - 'args' => ['not_approve'], |
|
| 406 | - ], |
|
| 407 | - 'no_approve_and_notify_registrations' => [ |
|
| 408 | - 'func' => 'bulk_action_on_registrations', |
|
| 409 | - 'noheader' => true, |
|
| 410 | - 'capability' => 'ee_edit_registrations', |
|
| 411 | - 'args' => ['not_approve', true], |
|
| 412 | - ], |
|
| 413 | - 'cancel_registration' => [ |
|
| 414 | - 'func' => 'cancel_registration', |
|
| 415 | - 'noheader' => true, |
|
| 416 | - 'capability' => 'ee_edit_registration', |
|
| 417 | - 'obj_id' => $REG_ID, |
|
| 418 | - ], |
|
| 419 | - 'cancel_and_notify_registration' => [ |
|
| 420 | - 'func' => 'cancel_registration', |
|
| 421 | - 'noheader' => true, |
|
| 422 | - 'args' => [true], |
|
| 423 | - 'capability' => 'ee_edit_registration', |
|
| 424 | - 'obj_id' => $REG_ID, |
|
| 425 | - ], |
|
| 426 | - 'cancel_registrations' => [ |
|
| 427 | - 'func' => 'bulk_action_on_registrations', |
|
| 428 | - 'noheader' => true, |
|
| 429 | - 'capability' => 'ee_edit_registrations', |
|
| 430 | - 'args' => ['cancel'], |
|
| 431 | - ], |
|
| 432 | - 'cancel_and_notify_registrations' => [ |
|
| 433 | - 'func' => 'bulk_action_on_registrations', |
|
| 434 | - 'noheader' => true, |
|
| 435 | - 'capability' => 'ee_edit_registrations', |
|
| 436 | - 'args' => ['cancel', true], |
|
| 437 | - ], |
|
| 438 | - 'wait_list_registration' => [ |
|
| 439 | - 'func' => 'wait_list_registration', |
|
| 440 | - 'noheader' => true, |
|
| 441 | - 'capability' => 'ee_edit_registration', |
|
| 442 | - 'obj_id' => $REG_ID, |
|
| 443 | - ], |
|
| 444 | - 'wait_list_and_notify_registration' => [ |
|
| 445 | - 'func' => 'wait_list_registration', |
|
| 446 | - 'noheader' => true, |
|
| 447 | - 'args' => [true], |
|
| 448 | - 'capability' => 'ee_edit_registration', |
|
| 449 | - 'obj_id' => $REG_ID, |
|
| 450 | - ], |
|
| 451 | - 'contact_list' => [ |
|
| 452 | - 'func' => '_attendee_contact_list_table', |
|
| 453 | - 'capability' => 'ee_read_contacts', |
|
| 454 | - ], |
|
| 455 | - 'add_new_attendee' => [ |
|
| 456 | - 'func' => '_create_new_cpt_item', |
|
| 457 | - 'args' => [ |
|
| 458 | - 'new_attendee' => true, |
|
| 459 | - 'capability' => 'ee_edit_contacts', |
|
| 460 | - ], |
|
| 461 | - ], |
|
| 462 | - 'edit_attendee' => [ |
|
| 463 | - 'func' => '_edit_cpt_item', |
|
| 464 | - 'capability' => 'ee_edit_contacts', |
|
| 465 | - 'obj_id' => $ATT_ID, |
|
| 466 | - ], |
|
| 467 | - 'duplicate_attendee' => [ |
|
| 468 | - 'func' => '_duplicate_attendee', |
|
| 469 | - 'noheader' => true, |
|
| 470 | - 'capability' => 'ee_edit_contacts', |
|
| 471 | - 'obj_id' => $ATT_ID, |
|
| 472 | - ], |
|
| 473 | - 'insert_attendee' => [ |
|
| 474 | - 'func' => '_insert_or_update_attendee', |
|
| 475 | - 'args' => [ |
|
| 476 | - 'new_attendee' => true, |
|
| 477 | - ], |
|
| 478 | - 'noheader' => true, |
|
| 479 | - 'capability' => 'ee_edit_contacts', |
|
| 480 | - ], |
|
| 481 | - 'update_attendee' => [ |
|
| 482 | - 'func' => '_insert_or_update_attendee', |
|
| 483 | - 'args' => [ |
|
| 484 | - 'new_attendee' => false, |
|
| 485 | - ], |
|
| 486 | - 'noheader' => true, |
|
| 487 | - 'capability' => 'ee_edit_contacts', |
|
| 488 | - 'obj_id' => $ATT_ID, |
|
| 489 | - ], |
|
| 490 | - 'trash_attendees' => [ |
|
| 491 | - 'func' => '_trash_or_restore_attendees', |
|
| 492 | - 'args' => [ |
|
| 493 | - 'trash' => 'true', |
|
| 494 | - ], |
|
| 495 | - 'noheader' => true, |
|
| 496 | - 'capability' => 'ee_delete_contacts', |
|
| 497 | - ], |
|
| 498 | - 'trash_attendee' => [ |
|
| 499 | - 'func' => '_trash_or_restore_attendees', |
|
| 500 | - 'args' => [ |
|
| 501 | - 'trash' => true, |
|
| 502 | - ], |
|
| 503 | - 'noheader' => true, |
|
| 504 | - 'capability' => 'ee_delete_contacts', |
|
| 505 | - 'obj_id' => $ATT_ID, |
|
| 506 | - ], |
|
| 507 | - 'restore_attendees' => [ |
|
| 508 | - 'func' => '_trash_or_restore_attendees', |
|
| 509 | - 'args' => [ |
|
| 510 | - 'trash' => false, |
|
| 511 | - ], |
|
| 512 | - 'noheader' => true, |
|
| 513 | - 'capability' => 'ee_delete_contacts', |
|
| 514 | - 'obj_id' => $ATT_ID, |
|
| 515 | - ], |
|
| 516 | - 'resend_registration' => [ |
|
| 517 | - 'func' => '_resend_registration', |
|
| 518 | - 'noheader' => true, |
|
| 519 | - 'capability' => 'ee_send_message', |
|
| 520 | - ], |
|
| 521 | - 'registrations_report' => [ |
|
| 522 | - 'func' => '_registrations_report', |
|
| 523 | - 'noheader' => true, |
|
| 524 | - 'capability' => 'ee_read_registrations', |
|
| 525 | - ], |
|
| 526 | - 'contact_list_export' => [ |
|
| 527 | - 'func' => '_contact_list_export', |
|
| 528 | - 'noheader' => true, |
|
| 529 | - 'capability' => 'export', |
|
| 530 | - ], |
|
| 531 | - 'contact_list_report' => [ |
|
| 532 | - 'func' => '_contact_list_report', |
|
| 533 | - 'noheader' => true, |
|
| 534 | - 'capability' => 'ee_read_contacts', |
|
| 535 | - ], |
|
| 536 | - ]; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - protected function _set_page_config() |
|
| 541 | - { |
|
| 542 | - $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 543 | - $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int'); |
|
| 544 | - $this->_page_config = [ |
|
| 545 | - 'default' => [ |
|
| 546 | - 'nav' => [ |
|
| 547 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 548 | - 'order' => 5, |
|
| 549 | - ], |
|
| 550 | - 'help_tabs' => [ |
|
| 551 | - 'registrations_overview_help_tab' => [ |
|
| 552 | - 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
| 553 | - 'filename' => 'registrations_overview', |
|
| 554 | - ], |
|
| 555 | - 'registrations_overview_table_column_headings_help_tab' => [ |
|
| 556 | - 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
| 557 | - 'filename' => 'registrations_overview_table_column_headings', |
|
| 558 | - ], |
|
| 559 | - 'registrations_overview_filters_help_tab' => [ |
|
| 560 | - 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
| 561 | - 'filename' => 'registrations_overview_filters', |
|
| 562 | - ], |
|
| 563 | - 'registrations_overview_views_help_tab' => [ |
|
| 564 | - 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
| 565 | - 'filename' => 'registrations_overview_views', |
|
| 566 | - ], |
|
| 567 | - 'registrations_regoverview_other_help_tab' => [ |
|
| 568 | - 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
| 569 | - 'filename' => 'registrations_overview_other', |
|
| 570 | - ], |
|
| 571 | - ], |
|
| 572 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 573 | - // 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 574 | - 'qtips' => ['Registration_List_Table_Tips'], |
|
| 575 | - 'list_table' => 'EE_Registrations_List_Table', |
|
| 576 | - 'require_nonce' => false, |
|
| 577 | - ], |
|
| 578 | - 'view_registration' => [ |
|
| 579 | - 'nav' => [ |
|
| 580 | - 'label' => esc_html__('REG Details', 'event_espresso'), |
|
| 581 | - 'order' => 15, |
|
| 582 | - 'url' => $REG_ID |
|
| 583 | - ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url) |
|
| 584 | - : $this->_admin_base_url, |
|
| 585 | - 'persistent' => false, |
|
| 586 | - ], |
|
| 587 | - 'help_tabs' => [ |
|
| 588 | - 'registrations_details_help_tab' => [ |
|
| 589 | - 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
| 590 | - 'filename' => 'registrations_details', |
|
| 591 | - ], |
|
| 592 | - 'registrations_details_table_help_tab' => [ |
|
| 593 | - 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
| 594 | - 'filename' => 'registrations_details_table', |
|
| 595 | - ], |
|
| 596 | - 'registrations_details_form_answers_help_tab' => [ |
|
| 597 | - 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 598 | - 'filename' => 'registrations_details_form_answers', |
|
| 599 | - ], |
|
| 600 | - 'registrations_details_registrant_details_help_tab' => [ |
|
| 601 | - 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
| 602 | - 'filename' => 'registrations_details_registrant_details', |
|
| 603 | - ], |
|
| 604 | - ], |
|
| 605 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 606 | - // 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 607 | - 'metaboxes' => array_merge( |
|
| 608 | - $this->_default_espresso_metaboxes, |
|
| 609 | - ['_registration_details_metaboxes'] |
|
| 610 | - ), |
|
| 611 | - 'require_nonce' => false, |
|
| 612 | - ], |
|
| 613 | - 'new_registration' => [ |
|
| 614 | - 'nav' => [ |
|
| 615 | - 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 616 | - 'url' => '#', |
|
| 617 | - 'order' => 15, |
|
| 618 | - 'persistent' => false, |
|
| 619 | - ], |
|
| 620 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 621 | - 'labels' => [ |
|
| 622 | - 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
| 623 | - ], |
|
| 624 | - 'require_nonce' => false, |
|
| 625 | - ], |
|
| 626 | - 'add_new_attendee' => [ |
|
| 627 | - 'nav' => [ |
|
| 628 | - 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
| 629 | - 'order' => 15, |
|
| 630 | - 'persistent' => false, |
|
| 631 | - ], |
|
| 632 | - 'metaboxes' => array_merge( |
|
| 633 | - $this->_default_espresso_metaboxes, |
|
| 634 | - ['_publish_post_box', 'attendee_editor_metaboxes'] |
|
| 635 | - ), |
|
| 636 | - 'require_nonce' => false, |
|
| 637 | - ], |
|
| 638 | - 'edit_attendee' => [ |
|
| 639 | - 'nav' => [ |
|
| 640 | - 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 641 | - 'order' => 15, |
|
| 642 | - 'persistent' => false, |
|
| 643 | - 'url' => $ATT_ID |
|
| 644 | - ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url) |
|
| 645 | - : $this->_admin_base_url, |
|
| 646 | - ], |
|
| 647 | - 'metaboxes' => ['attendee_editor_metaboxes'], |
|
| 648 | - 'require_nonce' => false, |
|
| 649 | - ], |
|
| 650 | - 'contact_list' => [ |
|
| 651 | - 'nav' => [ |
|
| 652 | - 'label' => esc_html__('Contact List', 'event_espresso'), |
|
| 653 | - 'order' => 20, |
|
| 654 | - ], |
|
| 655 | - 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 656 | - 'help_tabs' => [ |
|
| 657 | - 'registrations_contact_list_help_tab' => [ |
|
| 658 | - 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
| 659 | - 'filename' => 'registrations_contact_list', |
|
| 660 | - ], |
|
| 661 | - 'registrations_contact-list_table_column_headings_help_tab' => [ |
|
| 662 | - 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
| 663 | - 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 664 | - ], |
|
| 665 | - 'registrations_contact_list_views_help_tab' => [ |
|
| 666 | - 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
| 667 | - 'filename' => 'registrations_contact_list_views', |
|
| 668 | - ], |
|
| 669 | - 'registrations_contact_list_other_help_tab' => [ |
|
| 670 | - 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
| 671 | - 'filename' => 'registrations_contact_list_other', |
|
| 672 | - ], |
|
| 673 | - ], |
|
| 674 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 675 | - // 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 676 | - 'metaboxes' => [], |
|
| 677 | - 'require_nonce' => false, |
|
| 678 | - ], |
|
| 679 | - // override default cpt routes |
|
| 680 | - 'create_new' => '', |
|
| 681 | - 'edit' => '', |
|
| 682 | - ]; |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * The below methods aren't used by this class currently |
|
| 688 | - */ |
|
| 689 | - protected function _add_screen_options() |
|
| 690 | - { |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - protected function _add_feature_pointers() |
|
| 695 | - { |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - public function admin_init() |
|
| 700 | - { |
|
| 701 | - EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
| 702 | - 'click "Update Registration Questions" to save your changes', |
|
| 703 | - 'event_espresso' |
|
| 704 | - ); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - public function admin_notices() |
|
| 709 | - { |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - public function admin_footer_scripts() |
|
| 714 | - { |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * get list of registration statuses |
|
| 720 | - * |
|
| 721 | - * @return void |
|
| 722 | - * @throws EE_Error |
|
| 723 | - */ |
|
| 724 | - private function _get_registration_status_array() |
|
| 725 | - { |
|
| 726 | - self::$_reg_status = EEM_Registration::reg_status_array([], true); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * @throws InvalidArgumentException |
|
| 732 | - * @throws InvalidDataTypeException |
|
| 733 | - * @throws InvalidInterfaceException |
|
| 734 | - * @since 4.10.2.p |
|
| 735 | - */ |
|
| 736 | - protected function _add_screen_options_default() |
|
| 737 | - { |
|
| 738 | - $this->_per_page_screen_option(); |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - |
|
| 742 | - /** |
|
| 743 | - * @throws InvalidArgumentException |
|
| 744 | - * @throws InvalidDataTypeException |
|
| 745 | - * @throws InvalidInterfaceException |
|
| 746 | - * @since 4.10.2.p |
|
| 747 | - */ |
|
| 748 | - protected function _add_screen_options_contact_list() |
|
| 749 | - { |
|
| 750 | - $page_title = $this->_admin_page_title; |
|
| 751 | - $this->_admin_page_title = esc_html__('Contacts', 'event_espresso'); |
|
| 752 | - $this->_per_page_screen_option(); |
|
| 753 | - $this->_admin_page_title = $page_title; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - public function load_scripts_styles() |
|
| 758 | - { |
|
| 759 | - // style |
|
| 760 | - wp_register_style( |
|
| 761 | - 'espresso_reg', |
|
| 762 | - REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
| 763 | - ['ee-admin-css'], |
|
| 764 | - EVENT_ESPRESSO_VERSION |
|
| 765 | - ); |
|
| 766 | - wp_enqueue_style('espresso_reg'); |
|
| 767 | - // script |
|
| 768 | - wp_register_script( |
|
| 769 | - 'espresso_reg', |
|
| 770 | - REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 771 | - ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'], |
|
| 772 | - EVENT_ESPRESSO_VERSION, |
|
| 773 | - true |
|
| 774 | - ); |
|
| 775 | - wp_enqueue_script('espresso_reg'); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * @throws EE_Error |
|
| 781 | - * @throws InvalidArgumentException |
|
| 782 | - * @throws InvalidDataTypeException |
|
| 783 | - * @throws InvalidInterfaceException |
|
| 784 | - * @throws ReflectionException |
|
| 785 | - * @since 4.10.2.p |
|
| 786 | - */ |
|
| 787 | - public function load_scripts_styles_edit_attendee() |
|
| 788 | - { |
|
| 789 | - // stuff to only show up on our attendee edit details page. |
|
| 790 | - $attendee_details_translations = [ |
|
| 791 | - 'att_publish_text' => sprintf( |
|
| 792 | - /* translators: The date and time */ |
|
| 793 | - wp_strip_all_tags(__('Created on: %s', 'event_espresso')), |
|
| 794 | - '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>' |
|
| 795 | - ), |
|
| 796 | - ]; |
|
| 797 | - wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 798 | - wp_enqueue_script('jquery-validate'); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * @throws EE_Error |
|
| 804 | - * @throws InvalidArgumentException |
|
| 805 | - * @throws InvalidDataTypeException |
|
| 806 | - * @throws InvalidInterfaceException |
|
| 807 | - * @throws ReflectionException |
|
| 808 | - * @since 4.10.2.p |
|
| 809 | - */ |
|
| 810 | - public function load_scripts_styles_view_registration() |
|
| 811 | - { |
|
| 812 | - // styles |
|
| 813 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 814 | - // scripts |
|
| 815 | - $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 816 | - $this->_reg_custom_questions_form->wp_enqueue_scripts(); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - |
|
| 820 | - public function load_scripts_styles_contact_list() |
|
| 821 | - { |
|
| 822 | - wp_dequeue_style('espresso_reg'); |
|
| 823 | - wp_register_style( |
|
| 824 | - 'espresso_att', |
|
| 825 | - REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
| 826 | - ['ee-admin-css'], |
|
| 827 | - EVENT_ESPRESSO_VERSION |
|
| 828 | - ); |
|
| 829 | - wp_enqueue_style('espresso_att'); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - |
|
| 833 | - public function load_scripts_styles_new_registration() |
|
| 834 | - { |
|
| 835 | - wp_register_script( |
|
| 836 | - 'ee-spco-for-admin', |
|
| 837 | - REG_ASSETS_URL . 'spco_for_admin.js', |
|
| 838 | - ['underscore', 'jquery'], |
|
| 839 | - EVENT_ESPRESSO_VERSION, |
|
| 840 | - true |
|
| 841 | - ); |
|
| 842 | - wp_enqueue_script('ee-spco-for-admin'); |
|
| 843 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 844 | - EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 845 | - EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 846 | - EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - |
|
| 850 | - public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 851 | - { |
|
| 852 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - |
|
| 856 | - public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 857 | - { |
|
| 858 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * @throws EE_Error |
|
| 864 | - * @throws InvalidArgumentException |
|
| 865 | - * @throws InvalidDataTypeException |
|
| 866 | - * @throws InvalidInterfaceException |
|
| 867 | - * @throws ReflectionException |
|
| 868 | - * @since 4.10.2.p |
|
| 869 | - */ |
|
| 870 | - protected function _set_list_table_views_default() |
|
| 871 | - { |
|
| 872 | - // for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 873 | - EED_Messages::set_autoloaders(); |
|
| 874 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 875 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 876 | - $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 877 | - // key= bulk_action_slug, value= message type. |
|
| 878 | - $match_array = [ |
|
| 879 | - 'approve_registrations' => 'registration', |
|
| 880 | - 'decline_registrations' => 'declined_registration', |
|
| 881 | - 'pending_registrations' => 'pending_approval', |
|
| 882 | - 'no_approve_registrations' => 'not_approved_registration', |
|
| 883 | - 'cancel_registrations' => 'cancelled_registration', |
|
| 884 | - ]; |
|
| 885 | - $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
| 886 | - 'ee_send_message', |
|
| 887 | - 'batch_send_messages' |
|
| 888 | - ); |
|
| 889 | - /** setup reg status bulk actions **/ |
|
| 890 | - $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso'); |
|
| 891 | - if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) { |
|
| 892 | - $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__( |
|
| 893 | - 'Approve and Notify Registrations', |
|
| 894 | - 'event_espresso' |
|
| 895 | - ); |
|
| 896 | - } |
|
| 897 | - $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso'); |
|
| 898 | - if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) { |
|
| 899 | - $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__( |
|
| 900 | - 'Decline and Notify Registrations', |
|
| 901 | - 'event_espresso' |
|
| 902 | - ); |
|
| 903 | - } |
|
| 904 | - $def_reg_status_actions['pending_registrations'] = esc_html__( |
|
| 905 | - 'Set Registrations to Pending Payment', |
|
| 906 | - 'event_espresso' |
|
| 907 | - ); |
|
| 908 | - if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) { |
|
| 909 | - $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__( |
|
| 910 | - 'Set Registrations to Pending Payment and Notify', |
|
| 911 | - 'event_espresso' |
|
| 912 | - ); |
|
| 913 | - } |
|
| 914 | - $def_reg_status_actions['no_approve_registrations'] = esc_html__( |
|
| 915 | - 'Set Registrations to Not Approved', |
|
| 916 | - 'event_espresso' |
|
| 917 | - ); |
|
| 918 | - if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) { |
|
| 919 | - $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__( |
|
| 920 | - 'Set Registrations to Not Approved and Notify', |
|
| 921 | - 'event_espresso' |
|
| 922 | - ); |
|
| 923 | - } |
|
| 924 | - $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso'); |
|
| 925 | - if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) { |
|
| 926 | - $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__( |
|
| 927 | - 'Cancel Registrations and Notify', |
|
| 928 | - 'event_espresso' |
|
| 929 | - ); |
|
| 930 | - } |
|
| 931 | - $def_reg_status_actions = apply_filters( |
|
| 932 | - 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
| 933 | - $def_reg_status_actions, |
|
| 934 | - $active_mts, |
|
| 935 | - $can_send |
|
| 936 | - ); |
|
| 937 | - |
|
| 938 | - $this->_views = [ |
|
| 939 | - 'all' => [ |
|
| 940 | - 'slug' => 'all', |
|
| 941 | - 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
| 942 | - 'count' => 0, |
|
| 943 | - 'bulk_action' => array_merge( |
|
| 944 | - $def_reg_status_actions, |
|
| 945 | - [ |
|
| 946 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 947 | - ] |
|
| 948 | - ), |
|
| 949 | - ], |
|
| 950 | - 'month' => [ |
|
| 951 | - 'slug' => 'month', |
|
| 952 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 953 | - 'count' => 0, |
|
| 954 | - 'bulk_action' => array_merge( |
|
| 955 | - $def_reg_status_actions, |
|
| 956 | - [ |
|
| 957 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 958 | - ] |
|
| 959 | - ), |
|
| 960 | - ], |
|
| 961 | - 'today' => [ |
|
| 962 | - 'slug' => 'today', |
|
| 963 | - 'label' => sprintf( |
|
| 964 | - esc_html__('Today - %s', 'event_espresso'), |
|
| 965 | - date('M d, Y', current_time('timestamp')) |
|
| 966 | - ), |
|
| 967 | - 'count' => 0, |
|
| 968 | - 'bulk_action' => array_merge( |
|
| 969 | - $def_reg_status_actions, |
|
| 970 | - [ |
|
| 971 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 972 | - ] |
|
| 973 | - ), |
|
| 974 | - ], |
|
| 975 | - ]; |
|
| 976 | - if ( |
|
| 977 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 978 | - 'ee_delete_registrations', |
|
| 979 | - 'espresso_registrations_delete_registration' |
|
| 980 | - ) |
|
| 981 | - ) { |
|
| 982 | - $this->_views['incomplete'] = [ |
|
| 983 | - 'slug' => 'incomplete', |
|
| 984 | - 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
| 985 | - 'count' => 0, |
|
| 986 | - 'bulk_action' => [ |
|
| 987 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 988 | - ], |
|
| 989 | - ]; |
|
| 990 | - $this->_views['trash'] = [ |
|
| 991 | - 'slug' => 'trash', |
|
| 992 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 993 | - 'count' => 0, |
|
| 994 | - 'bulk_action' => [ |
|
| 995 | - 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
| 996 | - 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
| 997 | - ], |
|
| 998 | - ]; |
|
| 999 | - } |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - |
|
| 1003 | - protected function _set_list_table_views_contact_list() |
|
| 1004 | - { |
|
| 1005 | - $this->_views = [ |
|
| 1006 | - 'in_use' => [ |
|
| 1007 | - 'slug' => 'in_use', |
|
| 1008 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 1009 | - 'count' => 0, |
|
| 1010 | - 'bulk_action' => [ |
|
| 1011 | - 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 1012 | - ], |
|
| 1013 | - ], |
|
| 1014 | - ]; |
|
| 1015 | - if ( |
|
| 1016 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 1017 | - 'ee_delete_contacts', |
|
| 1018 | - 'espresso_registrations_trash_attendees' |
|
| 1019 | - ) |
|
| 1020 | - ) { |
|
| 1021 | - $this->_views['trash'] = [ |
|
| 1022 | - 'slug' => 'trash', |
|
| 1023 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 1024 | - 'count' => 0, |
|
| 1025 | - 'bulk_action' => [ |
|
| 1026 | - 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 1027 | - ], |
|
| 1028 | - ]; |
|
| 1029 | - } |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - |
|
| 1033 | - /** |
|
| 1034 | - * @return array |
|
| 1035 | - * @throws EE_Error |
|
| 1036 | - */ |
|
| 1037 | - protected function _registration_legend_items() |
|
| 1038 | - { |
|
| 1039 | - $fc_items = [ |
|
| 1040 | - 'star-icon' => [ |
|
| 1041 | - 'class' => 'dashicons dashicons-star-filled gold-icon', |
|
| 1042 | - 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
| 1043 | - ], |
|
| 1044 | - 'view_details' => [ |
|
| 1045 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 1046 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 1047 | - ], |
|
| 1048 | - 'edit_attendee' => [ |
|
| 1049 | - 'class' => 'dashicons dashicons-groups', |
|
| 1050 | - 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
| 1051 | - ], |
|
| 1052 | - 'view_transaction' => [ |
|
| 1053 | - 'class' => 'dashicons dashicons-cart', |
|
| 1054 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 1055 | - ], |
|
| 1056 | - 'view_invoice' => [ |
|
| 1057 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 1058 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 1059 | - ], |
|
| 1060 | - ]; |
|
| 1061 | - if ( |
|
| 1062 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 1063 | - 'ee_send_message', |
|
| 1064 | - 'espresso_registrations_resend_registration' |
|
| 1065 | - ) |
|
| 1066 | - ) { |
|
| 1067 | - $fc_items['resend_registration'] = [ |
|
| 1068 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 1069 | - 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
| 1070 | - ]; |
|
| 1071 | - } else { |
|
| 1072 | - $fc_items['blank'] = ['class' => 'blank', 'desc' => '']; |
|
| 1073 | - } |
|
| 1074 | - if ( |
|
| 1075 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 1076 | - 'ee_read_global_messages', |
|
| 1077 | - 'view_filtered_messages' |
|
| 1078 | - ) |
|
| 1079 | - ) { |
|
| 1080 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 1081 | - if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) { |
|
| 1082 | - $fc_items['view_related_messages'] = [ |
|
| 1083 | - 'class' => $related_for_icon['css_class'], |
|
| 1084 | - 'desc' => $related_for_icon['label'], |
|
| 1085 | - ]; |
|
| 1086 | - } |
|
| 1087 | - } |
|
| 1088 | - $sc_items = [ |
|
| 1089 | - 'approved_status' => [ |
|
| 1090 | - 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_approved, |
|
| 1091 | - 'desc' => EEH_Template::pretty_status( |
|
| 1092 | - EEM_Registration::status_id_approved, |
|
| 1093 | - false, |
|
| 1094 | - 'sentence' |
|
| 1095 | - ), |
|
| 1096 | - ], |
|
| 1097 | - 'pending_status' => [ |
|
| 1098 | - 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_pending_payment, |
|
| 1099 | - 'desc' => EEH_Template::pretty_status( |
|
| 1100 | - EEM_Registration::status_id_pending_payment, |
|
| 1101 | - false, |
|
| 1102 | - 'sentence' |
|
| 1103 | - ), |
|
| 1104 | - ], |
|
| 1105 | - 'wait_list' => [ |
|
| 1106 | - 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_wait_list, |
|
| 1107 | - 'desc' => EEH_Template::pretty_status( |
|
| 1108 | - EEM_Registration::status_id_wait_list, |
|
| 1109 | - false, |
|
| 1110 | - 'sentence' |
|
| 1111 | - ), |
|
| 1112 | - ], |
|
| 1113 | - 'incomplete_status' => [ |
|
| 1114 | - 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_incomplete, |
|
| 1115 | - 'desc' => EEH_Template::pretty_status( |
|
| 1116 | - EEM_Registration::status_id_incomplete, |
|
| 1117 | - false, |
|
| 1118 | - 'sentence' |
|
| 1119 | - ), |
|
| 1120 | - ], |
|
| 1121 | - 'not_approved' => [ |
|
| 1122 | - 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_not_approved, |
|
| 1123 | - 'desc' => EEH_Template::pretty_status( |
|
| 1124 | - EEM_Registration::status_id_not_approved, |
|
| 1125 | - false, |
|
| 1126 | - 'sentence' |
|
| 1127 | - ), |
|
| 1128 | - ], |
|
| 1129 | - 'declined_status' => [ |
|
| 1130 | - 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_declined, |
|
| 1131 | - 'desc' => EEH_Template::pretty_status( |
|
| 1132 | - EEM_Registration::status_id_declined, |
|
| 1133 | - false, |
|
| 1134 | - 'sentence' |
|
| 1135 | - ), |
|
| 1136 | - ], |
|
| 1137 | - 'cancelled_status' => [ |
|
| 1138 | - 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_cancelled, |
|
| 1139 | - 'desc' => EEH_Template::pretty_status( |
|
| 1140 | - EEM_Registration::status_id_cancelled, |
|
| 1141 | - false, |
|
| 1142 | - 'sentence' |
|
| 1143 | - ), |
|
| 1144 | - ], |
|
| 1145 | - ]; |
|
| 1146 | - return array_merge($fc_items, $sc_items); |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - |
|
| 1151 | - /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 1152 | - |
|
| 1153 | - |
|
| 1154 | - /** |
|
| 1155 | - * @throws DomainException |
|
| 1156 | - * @throws EE_Error |
|
| 1157 | - * @throws InvalidArgumentException |
|
| 1158 | - * @throws InvalidDataTypeException |
|
| 1159 | - * @throws InvalidInterfaceException |
|
| 1160 | - */ |
|
| 1161 | - protected function _registrations_overview_list_table() |
|
| 1162 | - { |
|
| 1163 | - $this->appendAddNewRegistrationButtonToPageTitle(); |
|
| 1164 | - $header_text = ''; |
|
| 1165 | - $admin_page_header_decorators = [ |
|
| 1166 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader', |
|
| 1167 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader', |
|
| 1168 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader', |
|
| 1169 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader', |
|
| 1170 | - ]; |
|
| 1171 | - foreach ($admin_page_header_decorators as $admin_page_header_decorator) { |
|
| 1172 | - $filter_header_decorator = $this->loader->getNew($admin_page_header_decorator); |
|
| 1173 | - $header_text = $filter_header_decorator->getHeaderText($header_text); |
|
| 1174 | - } |
|
| 1175 | - $this->_template_args['admin_page_header'] = $header_text; |
|
| 1176 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 1177 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * @throws EE_Error |
|
| 1183 | - * @throws InvalidArgumentException |
|
| 1184 | - * @throws InvalidDataTypeException |
|
| 1185 | - * @throws InvalidInterfaceException |
|
| 1186 | - */ |
|
| 1187 | - private function appendAddNewRegistrationButtonToPageTitle() |
|
| 1188 | - { |
|
| 1189 | - $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int'); |
|
| 1190 | - if ( |
|
| 1191 | - $EVT_ID |
|
| 1192 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1193 | - 'ee_edit_registrations', |
|
| 1194 | - 'espresso_registrations_new_registration', |
|
| 1195 | - $EVT_ID |
|
| 1196 | - ) |
|
| 1197 | - ) { |
|
| 1198 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 1199 | - 'new_registration', |
|
| 1200 | - 'add-registrant', |
|
| 1201 | - ['event_id' => $EVT_ID], |
|
| 1202 | - 'add-new-h2' |
|
| 1203 | - ); |
|
| 1204 | - } |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * This sets the _registration property for the registration details screen |
|
| 1210 | - * |
|
| 1211 | - * @return void |
|
| 1212 | - * @throws EE_Error |
|
| 1213 | - * @throws InvalidArgumentException |
|
| 1214 | - * @throws InvalidDataTypeException |
|
| 1215 | - * @throws InvalidInterfaceException |
|
| 1216 | - */ |
|
| 1217 | - private function _set_registration_object() |
|
| 1218 | - { |
|
| 1219 | - // get out if we've already set the object |
|
| 1220 | - if ($this->_registration instanceof EE_Registration) { |
|
| 1221 | - return; |
|
| 1222 | - } |
|
| 1223 | - $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 1224 | - if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) { |
|
| 1225 | - return; |
|
| 1226 | - } |
|
| 1227 | - $error_msg = sprintf( |
|
| 1228 | - esc_html__( |
|
| 1229 | - 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 1230 | - 'event_espresso' |
|
| 1231 | - ), |
|
| 1232 | - $REG_ID |
|
| 1233 | - ); |
|
| 1234 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1235 | - $this->_registration = null; |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - /** |
|
| 1240 | - * Used to retrieve registrations for the list table. |
|
| 1241 | - * |
|
| 1242 | - * @param int $per_page |
|
| 1243 | - * @param bool $count |
|
| 1244 | - * @param bool $this_month |
|
| 1245 | - * @param bool $today |
|
| 1246 | - * @return EE_Registration[]|int |
|
| 1247 | - * @throws EE_Error |
|
| 1248 | - * @throws InvalidArgumentException |
|
| 1249 | - * @throws InvalidDataTypeException |
|
| 1250 | - * @throws InvalidInterfaceException |
|
| 1251 | - */ |
|
| 1252 | - public function get_registrations( |
|
| 1253 | - $per_page = 10, |
|
| 1254 | - $count = false, |
|
| 1255 | - $this_month = false, |
|
| 1256 | - $today = false |
|
| 1257 | - ) { |
|
| 1258 | - if ($this_month) { |
|
| 1259 | - $this->request->setRequestParam('status', 'month'); |
|
| 1260 | - } |
|
| 1261 | - if ($today) { |
|
| 1262 | - $this->request->setRequestParam('status', 'today'); |
|
| 1263 | - } |
|
| 1264 | - $query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count); |
|
| 1265 | - /** |
|
| 1266 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1267 | - * |
|
| 1268 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1269 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1270 | - * or if you have the development copy of EE you can view this at the path: |
|
| 1271 | - * /docs/G--Model-System/model-query-params.md |
|
| 1272 | - */ |
|
| 1273 | - $query_params['group_by'] = ''; |
|
| 1274 | - |
|
| 1275 | - return $count |
|
| 1276 | - ? $this->getRegistrationModel()->count($query_params) |
|
| 1277 | - /** @type EE_Registration[] */ |
|
| 1278 | - : $this->getRegistrationModel()->get_all($query_params); |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 1284 | - * Note: this listens to values on the request for some of the query parameters. |
|
| 1285 | - * |
|
| 1286 | - * @param array $request |
|
| 1287 | - * @param int $per_page |
|
| 1288 | - * @param bool $count |
|
| 1289 | - * @return array |
|
| 1290 | - * @throws EE_Error |
|
| 1291 | - * @throws InvalidArgumentException |
|
| 1292 | - * @throws InvalidDataTypeException |
|
| 1293 | - * @throws InvalidInterfaceException |
|
| 1294 | - */ |
|
| 1295 | - protected function _get_registration_query_parameters( |
|
| 1296 | - $request = [], |
|
| 1297 | - $per_page = 10, |
|
| 1298 | - $count = false |
|
| 1299 | - ) { |
|
| 1300 | - /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */ |
|
| 1301 | - $list_table_query_builder = $this->loader->getNew( |
|
| 1302 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder', |
|
| 1303 | - [null, null, $request] |
|
| 1304 | - ); |
|
| 1305 | - return $list_table_query_builder->getQueryParams($per_page, $count); |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - public function get_registration_status_array() |
|
| 1310 | - { |
|
| 1311 | - return self::$_reg_status; |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - |
|
| 1317 | - /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1318 | - /** |
|
| 1319 | - * generates HTML for the View Registration Details Admin page |
|
| 1320 | - * |
|
| 1321 | - * @return void |
|
| 1322 | - * @throws DomainException |
|
| 1323 | - * @throws EE_Error |
|
| 1324 | - * @throws InvalidArgumentException |
|
| 1325 | - * @throws InvalidDataTypeException |
|
| 1326 | - * @throws InvalidInterfaceException |
|
| 1327 | - * @throws EntityNotFoundException |
|
| 1328 | - * @throws ReflectionException |
|
| 1329 | - */ |
|
| 1330 | - protected function _registration_details() |
|
| 1331 | - { |
|
| 1332 | - $this->_template_args = []; |
|
| 1333 | - $this->_set_registration_object(); |
|
| 1334 | - if (is_object($this->_registration)) { |
|
| 1335 | - $transaction = $this->_registration->transaction() |
|
| 1336 | - ? $this->_registration->transaction() |
|
| 1337 | - : EE_Transaction::new_instance(); |
|
| 1338 | - $this->_session = $transaction->session_data(); |
|
| 1339 | - $event_id = $this->_registration->event_ID(); |
|
| 1340 | - $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1341 | - $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
| 1342 | - $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1343 | - $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 1344 | - $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1345 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1346 | - // link back to overview |
|
| 1347 | - $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1348 | - $this->_template_args['registration'] = $this->_registration; |
|
| 1349 | - $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1350 | - [ |
|
| 1351 | - 'action' => 'default', |
|
| 1352 | - 'event_id' => $event_id, |
|
| 1353 | - ], |
|
| 1354 | - REG_ADMIN_URL |
|
| 1355 | - ); |
|
| 1356 | - $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1357 | - [ |
|
| 1358 | - 'action' => 'default', |
|
| 1359 | - 'EVT_ID' => $event_id, |
|
| 1360 | - 'page' => 'espresso_transactions', |
|
| 1361 | - ], |
|
| 1362 | - admin_url('admin.php') |
|
| 1363 | - ); |
|
| 1364 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1365 | - [ |
|
| 1366 | - 'page' => 'espresso_events', |
|
| 1367 | - 'action' => 'edit', |
|
| 1368 | - 'post' => $event_id, |
|
| 1369 | - ], |
|
| 1370 | - admin_url('admin.php') |
|
| 1371 | - ); |
|
| 1372 | - // next and previous links |
|
| 1373 | - $next_reg = $this->_registration->next( |
|
| 1374 | - null, |
|
| 1375 | - [], |
|
| 1376 | - 'REG_ID' |
|
| 1377 | - ); |
|
| 1378 | - $this->_template_args['next_registration'] = $next_reg |
|
| 1379 | - ? $this->_next_link( |
|
| 1380 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1381 | - [ |
|
| 1382 | - 'action' => 'view_registration', |
|
| 1383 | - '_REG_ID' => $next_reg['REG_ID'], |
|
| 1384 | - ], |
|
| 1385 | - REG_ADMIN_URL |
|
| 1386 | - ), |
|
| 1387 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 1388 | - ) |
|
| 1389 | - : ''; |
|
| 1390 | - $previous_reg = $this->_registration->previous( |
|
| 1391 | - null, |
|
| 1392 | - [], |
|
| 1393 | - 'REG_ID' |
|
| 1394 | - ); |
|
| 1395 | - $this->_template_args['previous_registration'] = $previous_reg |
|
| 1396 | - ? $this->_previous_link( |
|
| 1397 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1398 | - [ |
|
| 1399 | - 'action' => 'view_registration', |
|
| 1400 | - '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1401 | - ], |
|
| 1402 | - REG_ADMIN_URL |
|
| 1403 | - ), |
|
| 1404 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 1405 | - ) |
|
| 1406 | - : ''; |
|
| 1407 | - // grab header |
|
| 1408 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1409 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1410 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 1411 | - $template_path, |
|
| 1412 | - $this->_template_args, |
|
| 1413 | - true |
|
| 1414 | - ); |
|
| 1415 | - } else { |
|
| 1416 | - $this->_template_args['admin_page_header'] = ''; |
|
| 1417 | - $this->_display_espresso_notices(); |
|
| 1418 | - } |
|
| 1419 | - // the details template wrapper |
|
| 1420 | - $this->display_admin_page_with_sidebar(); |
|
| 1421 | - } |
|
| 1422 | - |
|
| 1423 | - |
|
| 1424 | - /** |
|
| 1425 | - * @throws EE_Error |
|
| 1426 | - * @throws InvalidArgumentException |
|
| 1427 | - * @throws InvalidDataTypeException |
|
| 1428 | - * @throws InvalidInterfaceException |
|
| 1429 | - * @throws ReflectionException |
|
| 1430 | - * @since 4.10.2.p |
|
| 1431 | - */ |
|
| 1432 | - protected function _registration_details_metaboxes() |
|
| 1433 | - { |
|
| 1434 | - do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1435 | - $this->_set_registration_object(); |
|
| 1436 | - $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1437 | - $this->addMetaBox( |
|
| 1438 | - 'edit-reg-status-mbox', |
|
| 1439 | - esc_html__('Registration Status', 'event_espresso'), |
|
| 1440 | - [$this, 'set_reg_status_buttons_metabox'], |
|
| 1441 | - $this->_wp_page_slug |
|
| 1442 | - ); |
|
| 1443 | - $this->addMetaBox( |
|
| 1444 | - 'edit-reg-details-mbox', |
|
| 1445 | - '<span>' . esc_html__('Registration Details', 'event_espresso') |
|
| 1446 | - . ' <span class="dashicons dashicons-clipboard"></span></span>', |
|
| 1447 | - [$this, '_reg_details_meta_box'], |
|
| 1448 | - $this->_wp_page_slug |
|
| 1449 | - ); |
|
| 1450 | - if ( |
|
| 1451 | - $attendee instanceof EE_Attendee |
|
| 1452 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1453 | - 'ee_read_registration', |
|
| 1454 | - 'edit-reg-questions-mbox', |
|
| 1455 | - $this->_registration->ID() |
|
| 1456 | - ) |
|
| 1457 | - ) { |
|
| 1458 | - $this->addMetaBox( |
|
| 1459 | - $this->_wp_page_slug, |
|
| 1460 | - 'edit-reg-questions-mbox', |
|
| 1461 | - esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 1462 | - [$this, '_reg_questions_meta_box'], |
|
| 1463 | - $this->_wp_page_slug |
|
| 1464 | - ); |
|
| 1465 | - } |
|
| 1466 | - $this->addMetaBox( |
|
| 1467 | - 'edit-reg-registrant-mbox', |
|
| 1468 | - esc_html__('Contact Details', 'event_espresso'), |
|
| 1469 | - [$this, '_reg_registrant_side_meta_box'], |
|
| 1470 | - $this->_wp_page_slug, |
|
| 1471 | - 'side' |
|
| 1472 | - ); |
|
| 1473 | - if ($this->_registration->group_size() > 1) { |
|
| 1474 | - $this->addMetaBox( |
|
| 1475 | - 'edit-reg-attendees-mbox', |
|
| 1476 | - esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1477 | - [$this, '_reg_attendees_meta_box'], |
|
| 1478 | - $this->_wp_page_slug |
|
| 1479 | - ); |
|
| 1480 | - } |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - |
|
| 1484 | - /** |
|
| 1485 | - * set_reg_status_buttons_metabox |
|
| 1486 | - * |
|
| 1487 | - * @return void |
|
| 1488 | - * @throws EE_Error |
|
| 1489 | - * @throws EntityNotFoundException |
|
| 1490 | - * @throws InvalidArgumentException |
|
| 1491 | - * @throws InvalidDataTypeException |
|
| 1492 | - * @throws InvalidInterfaceException |
|
| 1493 | - * @throws ReflectionException |
|
| 1494 | - */ |
|
| 1495 | - public function set_reg_status_buttons_metabox() |
|
| 1496 | - { |
|
| 1497 | - $this->_set_registration_object(); |
|
| 1498 | - $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1499 | - $output = $change_reg_status_form->form_open( |
|
| 1500 | - self::add_query_args_and_nonce( |
|
| 1501 | - [ |
|
| 1502 | - 'action' => 'change_reg_status', |
|
| 1503 | - ], |
|
| 1504 | - REG_ADMIN_URL |
|
| 1505 | - ) |
|
| 1506 | - ); |
|
| 1507 | - $output .= $change_reg_status_form->get_html(); |
|
| 1508 | - $output .= $change_reg_status_form->form_close(); |
|
| 1509 | - echo $output; // already escaped |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - |
|
| 1513 | - /** |
|
| 1514 | - * @return EE_Form_Section_Proper |
|
| 1515 | - * @throws EE_Error |
|
| 1516 | - * @throws InvalidArgumentException |
|
| 1517 | - * @throws InvalidDataTypeException |
|
| 1518 | - * @throws InvalidInterfaceException |
|
| 1519 | - * @throws EntityNotFoundException |
|
| 1520 | - * @throws ReflectionException |
|
| 1521 | - */ |
|
| 1522 | - protected function _generate_reg_status_change_form() |
|
| 1523 | - { |
|
| 1524 | - $reg_status_change_form_array = [ |
|
| 1525 | - 'name' => 'reg_status_change_form', |
|
| 1526 | - 'html_id' => 'reg-status-change-form', |
|
| 1527 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1528 | - 'subsections' => [ |
|
| 1529 | - 'return' => new EE_Hidden_Input( |
|
| 1530 | - [ |
|
| 1531 | - 'name' => 'return', |
|
| 1532 | - 'default' => 'view_registration', |
|
| 1533 | - ] |
|
| 1534 | - ), |
|
| 1535 | - 'REG_ID' => new EE_Hidden_Input( |
|
| 1536 | - [ |
|
| 1537 | - 'name' => 'REG_ID', |
|
| 1538 | - 'default' => $this->_registration->ID(), |
|
| 1539 | - ] |
|
| 1540 | - ), |
|
| 1541 | - 'current_status' => new EE_Form_Section_HTML( |
|
| 1542 | - EEH_HTML::table( |
|
| 1543 | - EEH_HTML::tr( |
|
| 1544 | - EEH_HTML::th( |
|
| 1545 | - EEH_HTML::label( |
|
| 1546 | - EEH_HTML::strong( |
|
| 1547 | - esc_html__('Current Registration Status', 'event_espresso') |
|
| 1548 | - ) |
|
| 1549 | - ) |
|
| 1550 | - ) |
|
| 1551 | - . EEH_HTML::td( |
|
| 1552 | - EEH_HTML::strong( |
|
| 1553 | - $this->_registration->pretty_status(), |
|
| 1554 | - '', |
|
| 1555 | - 'status-' . $this->_registration->status_ID(), |
|
| 1556 | - 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
| 1557 | - ) |
|
| 1558 | - ) |
|
| 1559 | - ) |
|
| 1560 | - ) |
|
| 1561 | - ), |
|
| 1562 | - ], |
|
| 1563 | - ]; |
|
| 1564 | - if ( |
|
| 1565 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 1566 | - 'ee_edit_registration', |
|
| 1567 | - 'toggle_registration_status', |
|
| 1568 | - $this->_registration->ID() |
|
| 1569 | - ) |
|
| 1570 | - ) { |
|
| 1571 | - $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input( |
|
| 1572 | - $this->_get_reg_statuses(), |
|
| 1573 | - [ |
|
| 1574 | - 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
| 1575 | - 'default' => $this->_registration->status_ID(), |
|
| 1576 | - ] |
|
| 1577 | - ); |
|
| 1578 | - $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input( |
|
| 1579 | - [ |
|
| 1580 | - 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
| 1581 | - 'default' => false, |
|
| 1582 | - 'html_help_text' => esc_html__( |
|
| 1583 | - 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1584 | - 'event_espresso' |
|
| 1585 | - ), |
|
| 1586 | - ] |
|
| 1587 | - ); |
|
| 1588 | - $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input( |
|
| 1589 | - [ |
|
| 1590 | - 'html_class' => 'button--primary', |
|
| 1591 | - 'html_label_text' => ' ', |
|
| 1592 | - 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
| 1593 | - ] |
|
| 1594 | - ); |
|
| 1595 | - } |
|
| 1596 | - return new EE_Form_Section_Proper($reg_status_change_form_array); |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - |
|
| 1600 | - /** |
|
| 1601 | - * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1602 | - * |
|
| 1603 | - * @return array |
|
| 1604 | - * @throws EE_Error |
|
| 1605 | - * @throws InvalidArgumentException |
|
| 1606 | - * @throws InvalidDataTypeException |
|
| 1607 | - * @throws InvalidInterfaceException |
|
| 1608 | - * @throws EntityNotFoundException |
|
| 1609 | - */ |
|
| 1610 | - protected function _get_reg_statuses() |
|
| 1611 | - { |
|
| 1612 | - $reg_status_array = $this->getRegistrationModel()->reg_status_array(); |
|
| 1613 | - unset($reg_status_array[ EEM_Registration::status_id_incomplete ]); |
|
| 1614 | - // get current reg status |
|
| 1615 | - $current_status = $this->_registration->status_ID(); |
|
| 1616 | - // is registration for free event? This will determine whether to display the pending payment option |
|
| 1617 | - if ( |
|
| 1618 | - $current_status !== EEM_Registration::status_id_pending_payment |
|
| 1619 | - && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00) |
|
| 1620 | - ) { |
|
| 1621 | - unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]); |
|
| 1622 | - } |
|
| 1623 | - return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - |
|
| 1627 | - /** |
|
| 1628 | - * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1629 | - * |
|
| 1630 | - * @param bool $status REG status given for changing registrations to. |
|
| 1631 | - * @param bool $notify Whether to send messages notifications or not. |
|
| 1632 | - * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1633 | - * @throws DomainException |
|
| 1634 | - * @throws EE_Error |
|
| 1635 | - * @throws EntityNotFoundException |
|
| 1636 | - * @throws InvalidArgumentException |
|
| 1637 | - * @throws InvalidDataTypeException |
|
| 1638 | - * @throws InvalidInterfaceException |
|
| 1639 | - * @throws ReflectionException |
|
| 1640 | - * @throws RuntimeException |
|
| 1641 | - */ |
|
| 1642 | - protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1643 | - { |
|
| 1644 | - $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form') |
|
| 1645 | - ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true) |
|
| 1646 | - : $this->request->getRequestParam('_REG_ID', [], 'int', true); |
|
| 1647 | - |
|
| 1648 | - // sanitize $REG_IDs |
|
| 1649 | - $REG_IDs = array_map('absint', $REG_IDs); |
|
| 1650 | - // and remove empty entries |
|
| 1651 | - $REG_IDs = array_filter($REG_IDs); |
|
| 1652 | - |
|
| 1653 | - $result = $this->_set_registration_status($REG_IDs, $status, $notify); |
|
| 1654 | - |
|
| 1655 | - /** |
|
| 1656 | - * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications. |
|
| 1657 | - * Currently this value is used downstream by the _process_resend_registration method. |
|
| 1658 | - * |
|
| 1659 | - * @param int|array $registration_ids The registration ids that have had their status changed successfully. |
|
| 1660 | - * @param bool $status The status registrations were changed to. |
|
| 1661 | - * @param bool $success If the status was changed successfully for all registrations. |
|
| 1662 | - * @param Registrations_Admin_Page $admin_page_object |
|
| 1663 | - */ |
|
| 1664 | - $REG_ID = apply_filters( |
|
| 1665 | - 'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs', |
|
| 1666 | - $result['REG_ID'], |
|
| 1667 | - $status, |
|
| 1668 | - $result['success'], |
|
| 1669 | - $this |
|
| 1670 | - ); |
|
| 1671 | - $this->request->setRequestParam('_REG_ID', $REG_ID); |
|
| 1672 | - |
|
| 1673 | - // notify? |
|
| 1674 | - if ( |
|
| 1675 | - $notify |
|
| 1676 | - && $result['success'] |
|
| 1677 | - && ! empty($REG_ID) |
|
| 1678 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1679 | - 'ee_send_message', |
|
| 1680 | - 'espresso_registrations_resend_registration' |
|
| 1681 | - ) |
|
| 1682 | - ) { |
|
| 1683 | - $this->_process_resend_registration(); |
|
| 1684 | - } |
|
| 1685 | - return $result; |
|
| 1686 | - } |
|
| 1687 | - |
|
| 1688 | - |
|
| 1689 | - /** |
|
| 1690 | - * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1691 | - * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1692 | - * |
|
| 1693 | - * @param array $REG_IDs |
|
| 1694 | - * @param string $status |
|
| 1695 | - * @param bool $notify Used to indicate whether notification was requested or not. This determines the context |
|
| 1696 | - * slug sent with setting the registration status. |
|
| 1697 | - * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1698 | - * @throws EE_Error |
|
| 1699 | - * @throws InvalidArgumentException |
|
| 1700 | - * @throws InvalidDataTypeException |
|
| 1701 | - * @throws InvalidInterfaceException |
|
| 1702 | - * @throws ReflectionException |
|
| 1703 | - * @throws RuntimeException |
|
| 1704 | - * @throws EntityNotFoundException |
|
| 1705 | - * @throws DomainException |
|
| 1706 | - */ |
|
| 1707 | - protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false) |
|
| 1708 | - { |
|
| 1709 | - $success = false; |
|
| 1710 | - // typecast $REG_IDs |
|
| 1711 | - $REG_IDs = (array) $REG_IDs; |
|
| 1712 | - if (! empty($REG_IDs)) { |
|
| 1713 | - $success = true; |
|
| 1714 | - // set default status if none is passed |
|
| 1715 | - $status = $status ?: EEM_Registration::status_id_pending_payment; |
|
| 1716 | - $status_context = $notify |
|
| 1717 | - ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
| 1718 | - : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN; |
|
| 1719 | - // loop through REG_ID's and change status |
|
| 1720 | - foreach ($REG_IDs as $REG_ID) { |
|
| 1721 | - $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID); |
|
| 1722 | - if ($registration instanceof EE_Registration) { |
|
| 1723 | - $registration->set_status( |
|
| 1724 | - $status, |
|
| 1725 | - false, |
|
| 1726 | - new Context( |
|
| 1727 | - $status_context, |
|
| 1728 | - esc_html__( |
|
| 1729 | - 'Manually triggered status change on a Registration Admin Page route.', |
|
| 1730 | - 'event_espresso' |
|
| 1731 | - ) |
|
| 1732 | - ) |
|
| 1733 | - ); |
|
| 1734 | - $result = $registration->save(); |
|
| 1735 | - // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1736 | - $success = $result !== false ? $success : false; |
|
| 1737 | - } |
|
| 1738 | - } |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - // return $success and processed registrations |
|
| 1742 | - return ['REG_ID' => $REG_IDs, 'success' => $success]; |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - |
|
| 1746 | - /** |
|
| 1747 | - * Common logic for setting up success message and redirecting to appropriate route |
|
| 1748 | - * |
|
| 1749 | - * @param string $STS_ID status id for the registration changed to |
|
| 1750 | - * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1751 | - * @return void |
|
| 1752 | - * @throws DomainException |
|
| 1753 | - * @throws EE_Error |
|
| 1754 | - * @throws EntityNotFoundException |
|
| 1755 | - * @throws InvalidArgumentException |
|
| 1756 | - * @throws InvalidDataTypeException |
|
| 1757 | - * @throws InvalidInterfaceException |
|
| 1758 | - * @throws ReflectionException |
|
| 1759 | - * @throws RuntimeException |
|
| 1760 | - */ |
|
| 1761 | - protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1762 | - { |
|
| 1763 | - $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1764 | - : ['success' => false]; |
|
| 1765 | - $success = isset($result['success']) && $result['success']; |
|
| 1766 | - // setup success message |
|
| 1767 | - if ($success) { |
|
| 1768 | - if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1769 | - $msg = sprintf( |
|
| 1770 | - esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
| 1771 | - EEH_Template::pretty_status($STS_ID, false, 'lower') |
|
| 1772 | - ); |
|
| 1773 | - } else { |
|
| 1774 | - $msg = sprintf( |
|
| 1775 | - esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1776 | - EEH_Template::pretty_status($STS_ID, false, 'lower') |
|
| 1777 | - ); |
|
| 1778 | - } |
|
| 1779 | - EE_Error::add_success($msg); |
|
| 1780 | - } else { |
|
| 1781 | - EE_Error::add_error( |
|
| 1782 | - esc_html__( |
|
| 1783 | - 'Something went wrong, and the status was not changed', |
|
| 1784 | - 'event_espresso' |
|
| 1785 | - ), |
|
| 1786 | - __FILE__, |
|
| 1787 | - __LINE__, |
|
| 1788 | - __FUNCTION__ |
|
| 1789 | - ); |
|
| 1790 | - } |
|
| 1791 | - $return = $this->request->getRequestParam('return'); |
|
| 1792 | - $route = $return === 'view_registration' |
|
| 1793 | - ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])] |
|
| 1794 | - : ['action' => 'default']; |
|
| 1795 | - $route = $this->mergeExistingRequestParamsWithRedirectArgs($route); |
|
| 1796 | - $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * incoming reg status change from reg details page. |
|
| 1802 | - * |
|
| 1803 | - * @return void |
|
| 1804 | - * @throws EE_Error |
|
| 1805 | - * @throws EntityNotFoundException |
|
| 1806 | - * @throws InvalidArgumentException |
|
| 1807 | - * @throws InvalidDataTypeException |
|
| 1808 | - * @throws InvalidInterfaceException |
|
| 1809 | - * @throws ReflectionException |
|
| 1810 | - * @throws RuntimeException |
|
| 1811 | - * @throws DomainException |
|
| 1812 | - */ |
|
| 1813 | - protected function _change_reg_status() |
|
| 1814 | - { |
|
| 1815 | - $this->request->setRequestParam('return', 'view_registration'); |
|
| 1816 | - // set notify based on whether the send notifications toggle is set or not |
|
| 1817 | - $notify = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool'); |
|
| 1818 | - $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', ''); |
|
| 1819 | - $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status); |
|
| 1820 | - switch ($reg_status) { |
|
| 1821 | - case EEM_Registration::status_id_approved: |
|
| 1822 | - case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'): |
|
| 1823 | - $this->approve_registration($notify); |
|
| 1824 | - break; |
|
| 1825 | - case EEM_Registration::status_id_pending_payment: |
|
| 1826 | - case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'): |
|
| 1827 | - $this->pending_registration($notify); |
|
| 1828 | - break; |
|
| 1829 | - case EEM_Registration::status_id_not_approved: |
|
| 1830 | - case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'): |
|
| 1831 | - $this->not_approve_registration($notify); |
|
| 1832 | - break; |
|
| 1833 | - case EEM_Registration::status_id_declined: |
|
| 1834 | - case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'): |
|
| 1835 | - $this->decline_registration($notify); |
|
| 1836 | - break; |
|
| 1837 | - case EEM_Registration::status_id_cancelled: |
|
| 1838 | - case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'): |
|
| 1839 | - $this->cancel_registration($notify); |
|
| 1840 | - break; |
|
| 1841 | - case EEM_Registration::status_id_wait_list: |
|
| 1842 | - case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'): |
|
| 1843 | - $this->wait_list_registration($notify); |
|
| 1844 | - break; |
|
| 1845 | - case EEM_Registration::status_id_incomplete: |
|
| 1846 | - default: |
|
| 1847 | - $this->request->unSetRequestParam('return'); |
|
| 1848 | - $this->_reg_status_change_return(''); |
|
| 1849 | - break; |
|
| 1850 | - } |
|
| 1851 | - } |
|
| 1852 | - |
|
| 1853 | - |
|
| 1854 | - /** |
|
| 1855 | - * Callback for bulk action routes. |
|
| 1856 | - * Note: although we could just register the singular route callbacks for each bulk action route as well, this |
|
| 1857 | - * method was chosen so there is one central place all the registration status bulk actions are going through. |
|
| 1858 | - * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to |
|
| 1859 | - * when an action is happening on just a single registration). |
|
| 1860 | - * |
|
| 1861 | - * @param $action |
|
| 1862 | - * @param bool $notify |
|
| 1863 | - */ |
|
| 1864 | - protected function bulk_action_on_registrations($action, $notify = false) |
|
| 1865 | - { |
|
| 1866 | - do_action( |
|
| 1867 | - 'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution', |
|
| 1868 | - $this, |
|
| 1869 | - $action, |
|
| 1870 | - $notify |
|
| 1871 | - ); |
|
| 1872 | - $method = $action . '_registration'; |
|
| 1873 | - if (method_exists($this, $method)) { |
|
| 1874 | - $this->$method($notify); |
|
| 1875 | - } |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - /** |
|
| 1880 | - * approve_registration |
|
| 1881 | - * |
|
| 1882 | - * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1883 | - * @return void |
|
| 1884 | - * @throws EE_Error |
|
| 1885 | - * @throws EntityNotFoundException |
|
| 1886 | - * @throws InvalidArgumentException |
|
| 1887 | - * @throws InvalidDataTypeException |
|
| 1888 | - * @throws InvalidInterfaceException |
|
| 1889 | - * @throws ReflectionException |
|
| 1890 | - * @throws RuntimeException |
|
| 1891 | - * @throws DomainException |
|
| 1892 | - */ |
|
| 1893 | - protected function approve_registration($notify = false) |
|
| 1894 | - { |
|
| 1895 | - $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - |
|
| 1899 | - /** |
|
| 1900 | - * decline_registration |
|
| 1901 | - * |
|
| 1902 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1903 | - * @return void |
|
| 1904 | - * @throws EE_Error |
|
| 1905 | - * @throws EntityNotFoundException |
|
| 1906 | - * @throws InvalidArgumentException |
|
| 1907 | - * @throws InvalidDataTypeException |
|
| 1908 | - * @throws InvalidInterfaceException |
|
| 1909 | - * @throws ReflectionException |
|
| 1910 | - * @throws RuntimeException |
|
| 1911 | - * @throws DomainException |
|
| 1912 | - */ |
|
| 1913 | - protected function decline_registration($notify = false) |
|
| 1914 | - { |
|
| 1915 | - $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1916 | - } |
|
| 1917 | - |
|
| 1918 | - |
|
| 1919 | - /** |
|
| 1920 | - * cancel_registration |
|
| 1921 | - * |
|
| 1922 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1923 | - * @return void |
|
| 1924 | - * @throws EE_Error |
|
| 1925 | - * @throws EntityNotFoundException |
|
| 1926 | - * @throws InvalidArgumentException |
|
| 1927 | - * @throws InvalidDataTypeException |
|
| 1928 | - * @throws InvalidInterfaceException |
|
| 1929 | - * @throws ReflectionException |
|
| 1930 | - * @throws RuntimeException |
|
| 1931 | - * @throws DomainException |
|
| 1932 | - */ |
|
| 1933 | - protected function cancel_registration($notify = false) |
|
| 1934 | - { |
|
| 1935 | - $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1936 | - } |
|
| 1937 | - |
|
| 1938 | - |
|
| 1939 | - /** |
|
| 1940 | - * not_approve_registration |
|
| 1941 | - * |
|
| 1942 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1943 | - * @return void |
|
| 1944 | - * @throws EE_Error |
|
| 1945 | - * @throws EntityNotFoundException |
|
| 1946 | - * @throws InvalidArgumentException |
|
| 1947 | - * @throws InvalidDataTypeException |
|
| 1948 | - * @throws InvalidInterfaceException |
|
| 1949 | - * @throws ReflectionException |
|
| 1950 | - * @throws RuntimeException |
|
| 1951 | - * @throws DomainException |
|
| 1952 | - */ |
|
| 1953 | - protected function not_approve_registration($notify = false) |
|
| 1954 | - { |
|
| 1955 | - $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - |
|
| 1959 | - /** |
|
| 1960 | - * decline_registration |
|
| 1961 | - * |
|
| 1962 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1963 | - * @return void |
|
| 1964 | - * @throws EE_Error |
|
| 1965 | - * @throws EntityNotFoundException |
|
| 1966 | - * @throws InvalidArgumentException |
|
| 1967 | - * @throws InvalidDataTypeException |
|
| 1968 | - * @throws InvalidInterfaceException |
|
| 1969 | - * @throws ReflectionException |
|
| 1970 | - * @throws RuntimeException |
|
| 1971 | - * @throws DomainException |
|
| 1972 | - */ |
|
| 1973 | - protected function pending_registration($notify = false) |
|
| 1974 | - { |
|
| 1975 | - $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 1976 | - } |
|
| 1977 | - |
|
| 1978 | - |
|
| 1979 | - /** |
|
| 1980 | - * waitlist_registration |
|
| 1981 | - * |
|
| 1982 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1983 | - * @return void |
|
| 1984 | - * @throws EE_Error |
|
| 1985 | - * @throws EntityNotFoundException |
|
| 1986 | - * @throws InvalidArgumentException |
|
| 1987 | - * @throws InvalidDataTypeException |
|
| 1988 | - * @throws InvalidInterfaceException |
|
| 1989 | - * @throws ReflectionException |
|
| 1990 | - * @throws RuntimeException |
|
| 1991 | - * @throws DomainException |
|
| 1992 | - */ |
|
| 1993 | - protected function wait_list_registration($notify = false) |
|
| 1994 | - { |
|
| 1995 | - $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 1996 | - } |
|
| 1997 | - |
|
| 1998 | - |
|
| 1999 | - /** |
|
| 2000 | - * generates HTML for the Registration main meta box |
|
| 2001 | - * |
|
| 2002 | - * @return void |
|
| 2003 | - * @throws DomainException |
|
| 2004 | - * @throws EE_Error |
|
| 2005 | - * @throws InvalidArgumentException |
|
| 2006 | - * @throws InvalidDataTypeException |
|
| 2007 | - * @throws InvalidInterfaceException |
|
| 2008 | - * @throws ReflectionException |
|
| 2009 | - * @throws EntityNotFoundException |
|
| 2010 | - */ |
|
| 2011 | - public function _reg_details_meta_box() |
|
| 2012 | - { |
|
| 2013 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 2014 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 2015 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
| 2016 | - $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 2017 | - : EE_Transaction::new_instance(); |
|
| 2018 | - $this->_session = $transaction->session_data(); |
|
| 2019 | - $filters = new EE_Line_Item_Filter_Collection(); |
|
| 2020 | - $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 2021 | - $filters->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 2022 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 2023 | - $filters, |
|
| 2024 | - $transaction->total_line_item() |
|
| 2025 | - ); |
|
| 2026 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 2027 | - $line_item_display = new EE_Line_Item_Display( |
|
| 2028 | - 'reg_admin_table', |
|
| 2029 | - 'EE_Admin_Table_Registration_Line_Item_Display_Strategy' |
|
| 2030 | - ); |
|
| 2031 | - $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
| 2032 | - $filtered_line_item_tree, |
|
| 2033 | - ['EE_Registration' => $this->_registration] |
|
| 2034 | - ); |
|
| 2035 | - $attendee = $this->_registration->attendee(); |
|
| 2036 | - if ( |
|
| 2037 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 2038 | - 'ee_read_transaction', |
|
| 2039 | - 'espresso_transactions_view_transaction' |
|
| 2040 | - ) |
|
| 2041 | - ) { |
|
| 2042 | - $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
| 2043 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2044 | - [ |
|
| 2045 | - 'action' => 'view_transaction', |
|
| 2046 | - 'TXN_ID' => $transaction->ID(), |
|
| 2047 | - ], |
|
| 2048 | - TXN_ADMIN_URL |
|
| 2049 | - ), |
|
| 2050 | - esc_html__(' View Transaction', 'event_espresso'), |
|
| 2051 | - 'button button--secondary right', |
|
| 2052 | - 'dashicons dashicons-cart' |
|
| 2053 | - ); |
|
| 2054 | - } else { |
|
| 2055 | - $this->_template_args['view_transaction_button'] = ''; |
|
| 2056 | - } |
|
| 2057 | - if ( |
|
| 2058 | - $attendee instanceof EE_Attendee |
|
| 2059 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 2060 | - 'ee_send_message', |
|
| 2061 | - 'espresso_registrations_resend_registration' |
|
| 2062 | - ) |
|
| 2063 | - ) { |
|
| 2064 | - $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
| 2065 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2066 | - [ |
|
| 2067 | - 'action' => 'resend_registration', |
|
| 2068 | - '_REG_ID' => $this->_registration->ID(), |
|
| 2069 | - 'redirect_to' => 'view_registration', |
|
| 2070 | - ], |
|
| 2071 | - REG_ADMIN_URL |
|
| 2072 | - ), |
|
| 2073 | - esc_html__(' Resend Registration', 'event_espresso'), |
|
| 2074 | - 'button button--secondary right', |
|
| 2075 | - 'dashicons dashicons-email-alt' |
|
| 2076 | - ); |
|
| 2077 | - } else { |
|
| 2078 | - $this->_template_args['resend_registration_button'] = ''; |
|
| 2079 | - } |
|
| 2080 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2081 | - $payment = $transaction->get_first_related('Payment'); |
|
| 2082 | - $payment = ! $payment instanceof EE_Payment |
|
| 2083 | - ? EE_Payment::new_instance() |
|
| 2084 | - : $payment; |
|
| 2085 | - $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 2086 | - $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
| 2087 | - ? EE_Payment_Method::new_instance() |
|
| 2088 | - : $payment_method; |
|
| 2089 | - $reg_details = [ |
|
| 2090 | - 'payment_method' => $payment_method->name(), |
|
| 2091 | - 'response_msg' => $payment->gateway_response(), |
|
| 2092 | - 'registration_id' => $this->_registration->get('REG_code'), |
|
| 2093 | - 'registration_session' => $this->_registration->session_ID(), |
|
| 2094 | - 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 2095 | - 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 2096 | - ]; |
|
| 2097 | - if (isset($reg_details['registration_id'])) { |
|
| 2098 | - $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 2099 | - $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
| 2100 | - 'Registration ID', |
|
| 2101 | - 'event_espresso' |
|
| 2102 | - ); |
|
| 2103 | - $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 2104 | - } |
|
| 2105 | - if (isset($reg_details['payment_method'])) { |
|
| 2106 | - $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 2107 | - $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
| 2108 | - 'Most Recent Payment Method', |
|
| 2109 | - 'event_espresso' |
|
| 2110 | - ); |
|
| 2111 | - $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 2112 | - $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 2113 | - $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
| 2114 | - 'Payment method response', |
|
| 2115 | - 'event_espresso' |
|
| 2116 | - ); |
|
| 2117 | - $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2118 | - } |
|
| 2119 | - $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 2120 | - $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
| 2121 | - 'Registration Session', |
|
| 2122 | - 'event_espresso' |
|
| 2123 | - ); |
|
| 2124 | - $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 2125 | - $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 2126 | - $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
| 2127 | - 'Registration placed from IP', |
|
| 2128 | - 'event_espresso' |
|
| 2129 | - ); |
|
| 2130 | - $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 2131 | - $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 2132 | - $this->_template_args['reg_details']['user_agent']['label'] = esc_html__( |
|
| 2133 | - 'Registrant User Agent', |
|
| 2134 | - 'event_espresso' |
|
| 2135 | - ); |
|
| 2136 | - $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 2137 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2138 | - [ |
|
| 2139 | - 'action' => 'default', |
|
| 2140 | - 'event_id' => $this->_registration->event_ID(), |
|
| 2141 | - ], |
|
| 2142 | - REG_ADMIN_URL |
|
| 2143 | - ); |
|
| 2144 | - |
|
| 2145 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2146 | - $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 2147 | - |
|
| 2148 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2149 | - EEH_Template::display_template($template_path, $this->_template_args); // already escaped |
|
| 2150 | - } |
|
| 2151 | - |
|
| 2152 | - |
|
| 2153 | - /** |
|
| 2154 | - * generates HTML for the Registration Questions meta box. |
|
| 2155 | - * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 2156 | - * otherwise uses new forms system |
|
| 2157 | - * |
|
| 2158 | - * @return void |
|
| 2159 | - * @throws DomainException |
|
| 2160 | - * @throws EE_Error |
|
| 2161 | - * @throws InvalidArgumentException |
|
| 2162 | - * @throws InvalidDataTypeException |
|
| 2163 | - * @throws InvalidInterfaceException |
|
| 2164 | - * @throws ReflectionException |
|
| 2165 | - */ |
|
| 2166 | - public function _reg_questions_meta_box() |
|
| 2167 | - { |
|
| 2168 | - // allow someone to override this method entirely |
|
| 2169 | - if ( |
|
| 2170 | - apply_filters( |
|
| 2171 | - 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', |
|
| 2172 | - true, |
|
| 2173 | - $this, |
|
| 2174 | - $this->_registration |
|
| 2175 | - ) |
|
| 2176 | - ) { |
|
| 2177 | - $form = $this->_get_reg_custom_questions_form( |
|
| 2178 | - $this->_registration->ID() |
|
| 2179 | - ); |
|
| 2180 | - |
|
| 2181 | - $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
| 2182 | - ? $form->get_html_and_js() |
|
| 2183 | - : ''; |
|
| 2184 | - |
|
| 2185 | - $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 2186 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2187 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2188 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2189 | - } |
|
| 2190 | - } |
|
| 2191 | - |
|
| 2192 | - |
|
| 2193 | - /** |
|
| 2194 | - * form_before_question_group |
|
| 2195 | - * |
|
| 2196 | - * @param string $output |
|
| 2197 | - * @return string |
|
| 2198 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2199 | - */ |
|
| 2200 | - public function form_before_question_group($output) |
|
| 2201 | - { |
|
| 2202 | - EE_Error::doing_it_wrong( |
|
| 2203 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2204 | - esc_html__( |
|
| 2205 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2206 | - 'event_espresso' |
|
| 2207 | - ), |
|
| 2208 | - '4.8.32.rc.000' |
|
| 2209 | - ); |
|
| 2210 | - return ' |
|
| 22 | + /** |
|
| 23 | + * @var EE_Registration |
|
| 24 | + */ |
|
| 25 | + private $_registration; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var EE_Event |
|
| 29 | + */ |
|
| 30 | + private $_reg_event; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var EE_Session |
|
| 34 | + */ |
|
| 35 | + private $_session; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + private static $_reg_status; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Form for displaying the custom questions for this registration. |
|
| 44 | + * This gets used a few times throughout the request so its best to cache it |
|
| 45 | + * |
|
| 46 | + * @var EE_Registration_Custom_Questions_Form |
|
| 47 | + */ |
|
| 48 | + protected $_reg_custom_questions_form; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var EEM_Registration $registration_model |
|
| 52 | + */ |
|
| 53 | + private $registration_model; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var EEM_Attendee $attendee_model |
|
| 57 | + */ |
|
| 58 | + private $attendee_model; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var EEM_Event $event_model |
|
| 62 | + */ |
|
| 63 | + private $event_model; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var EEM_Status $status_model |
|
| 67 | + */ |
|
| 68 | + private $status_model; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param bool $routing |
|
| 73 | + * @throws EE_Error |
|
| 74 | + * @throws InvalidArgumentException |
|
| 75 | + * @throws InvalidDataTypeException |
|
| 76 | + * @throws InvalidInterfaceException |
|
| 77 | + * @throws ReflectionException |
|
| 78 | + */ |
|
| 79 | + public function __construct($routing = true) |
|
| 80 | + { |
|
| 81 | + parent::__construct($routing); |
|
| 82 | + add_action('wp_loaded', [$this, 'wp_loaded']); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @return EEM_Registration |
|
| 88 | + * @throws InvalidArgumentException |
|
| 89 | + * @throws InvalidDataTypeException |
|
| 90 | + * @throws InvalidInterfaceException |
|
| 91 | + * @since 4.10.2.p |
|
| 92 | + */ |
|
| 93 | + protected function getRegistrationModel() |
|
| 94 | + { |
|
| 95 | + if (! $this->registration_model instanceof EEM_Registration) { |
|
| 96 | + $this->registration_model = $this->loader->getShared('EEM_Registration'); |
|
| 97 | + } |
|
| 98 | + return $this->registration_model; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @return EEM_Attendee |
|
| 104 | + * @throws InvalidArgumentException |
|
| 105 | + * @throws InvalidDataTypeException |
|
| 106 | + * @throws InvalidInterfaceException |
|
| 107 | + * @since 4.10.2.p |
|
| 108 | + */ |
|
| 109 | + protected function getAttendeeModel() |
|
| 110 | + { |
|
| 111 | + if (! $this->attendee_model instanceof EEM_Attendee) { |
|
| 112 | + $this->attendee_model = $this->loader->getShared('EEM_Attendee'); |
|
| 113 | + } |
|
| 114 | + return $this->attendee_model; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return EEM_Event |
|
| 120 | + * @throws InvalidArgumentException |
|
| 121 | + * @throws InvalidDataTypeException |
|
| 122 | + * @throws InvalidInterfaceException |
|
| 123 | + * @since 4.10.2.p |
|
| 124 | + */ |
|
| 125 | + protected function getEventModel() |
|
| 126 | + { |
|
| 127 | + if (! $this->event_model instanceof EEM_Event) { |
|
| 128 | + $this->event_model = $this->loader->getShared('EEM_Event'); |
|
| 129 | + } |
|
| 130 | + return $this->event_model; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @return EEM_Status |
|
| 136 | + * @throws InvalidArgumentException |
|
| 137 | + * @throws InvalidDataTypeException |
|
| 138 | + * @throws InvalidInterfaceException |
|
| 139 | + * @since 4.10.2.p |
|
| 140 | + */ |
|
| 141 | + protected function getStatusModel() |
|
| 142 | + { |
|
| 143 | + if (! $this->status_model instanceof EEM_Status) { |
|
| 144 | + $this->status_model = $this->loader->getShared('EEM_Status'); |
|
| 145 | + } |
|
| 146 | + return $this->status_model; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + public function wp_loaded() |
|
| 151 | + { |
|
| 152 | + // when adding a new registration... |
|
| 153 | + $action = $this->request->getRequestParam('action'); |
|
| 154 | + if ($action === 'new_registration') { |
|
| 155 | + EE_System::do_not_cache(); |
|
| 156 | + if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) { |
|
| 157 | + // and it's NOT the attendee information reg step |
|
| 158 | + // force cookie expiration by setting time to last week |
|
| 159 | + setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 160 | + // and update the global |
|
| 161 | + $_COOKIE['ee_registration_added'] = 0; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + protected function _init_page_props() |
|
| 168 | + { |
|
| 169 | + $this->page_slug = REG_PG_SLUG; |
|
| 170 | + $this->_admin_base_url = REG_ADMIN_URL; |
|
| 171 | + $this->_admin_base_path = REG_ADMIN; |
|
| 172 | + $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
| 173 | + $this->_cpt_routes = [ |
|
| 174 | + 'add_new_attendee' => 'espresso_attendees', |
|
| 175 | + 'edit_attendee' => 'espresso_attendees', |
|
| 176 | + 'insert_attendee' => 'espresso_attendees', |
|
| 177 | + 'update_attendee' => 'espresso_attendees', |
|
| 178 | + ]; |
|
| 179 | + $this->_cpt_model_names = [ |
|
| 180 | + 'add_new_attendee' => 'EEM_Attendee', |
|
| 181 | + 'edit_attendee' => 'EEM_Attendee', |
|
| 182 | + ]; |
|
| 183 | + $this->_cpt_edit_routes = [ |
|
| 184 | + 'espresso_attendees' => 'edit_attendee', |
|
| 185 | + ]; |
|
| 186 | + $this->_pagenow_map = [ |
|
| 187 | + 'add_new_attendee' => 'post-new.php', |
|
| 188 | + 'edit_attendee' => 'post.php', |
|
| 189 | + 'trash' => 'post.php', |
|
| 190 | + ]; |
|
| 191 | + add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10); |
|
| 192 | + // add filters so that the comment urls don't take users to a confusing 404 page |
|
| 193 | + add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param string $link The comment permalink with '#comment-$id' appended. |
|
| 199 | + * @param WP_Comment $comment The current comment object. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public function clear_comment_link($link, WP_Comment $comment) |
|
| 203 | + { |
|
| 204 | + // gotta make sure this only happens on this route |
|
| 205 | + $post_type = get_post_type($comment->comment_post_ID); |
|
| 206 | + if ($post_type === 'espresso_attendees') { |
|
| 207 | + return '#commentsdiv'; |
|
| 208 | + } |
|
| 209 | + return $link; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + protected function _ajax_hooks() |
|
| 214 | + { |
|
| 215 | + // todo: all hooks for registrations ajax goes in here |
|
| 216 | + add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + protected function _define_page_props() |
|
| 221 | + { |
|
| 222 | + $this->_admin_page_title = $this->page_label; |
|
| 223 | + $this->_labels = [ |
|
| 224 | + 'buttons' => [ |
|
| 225 | + 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 226 | + 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
| 227 | + 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 228 | + 'report' => esc_html__('Event Registrations CSV Report', 'event_espresso'), |
|
| 229 | + 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
| 230 | + 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
| 231 | + 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
| 232 | + 'contact_list_export' => esc_html__('Export Data', 'event_espresso'), |
|
| 233 | + ], |
|
| 234 | + 'publishbox' => [ |
|
| 235 | + 'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'), |
|
| 236 | + 'edit_attendee' => esc_html__('Update Contact Record', 'event_espresso'), |
|
| 237 | + ], |
|
| 238 | + 'hide_add_button_on_cpt_route' => [ |
|
| 239 | + 'edit_attendee' => true, |
|
| 240 | + ], |
|
| 241 | + ]; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * grab url requests and route them |
|
| 247 | + * |
|
| 248 | + * @return void |
|
| 249 | + * @throws EE_Error |
|
| 250 | + */ |
|
| 251 | + public function _set_page_routes() |
|
| 252 | + { |
|
| 253 | + $this->_get_registration_status_array(); |
|
| 254 | + $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 255 | + $REG_ID = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int'); |
|
| 256 | + $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int'); |
|
| 257 | + $ATT_ID = $this->request->getRequestParam('post', $ATT_ID, 'int'); |
|
| 258 | + $this->_page_routes = [ |
|
| 259 | + 'default' => [ |
|
| 260 | + 'func' => '_registrations_overview_list_table', |
|
| 261 | + 'capability' => 'ee_read_registrations', |
|
| 262 | + ], |
|
| 263 | + 'view_registration' => [ |
|
| 264 | + 'func' => '_registration_details', |
|
| 265 | + 'capability' => 'ee_read_registration', |
|
| 266 | + 'obj_id' => $REG_ID, |
|
| 267 | + ], |
|
| 268 | + 'edit_registration' => [ |
|
| 269 | + 'func' => '_update_attendee_registration_form', |
|
| 270 | + 'noheader' => true, |
|
| 271 | + 'headers_sent_route' => 'view_registration', |
|
| 272 | + 'capability' => 'ee_edit_registration', |
|
| 273 | + 'obj_id' => $REG_ID, |
|
| 274 | + '_REG_ID' => $REG_ID, |
|
| 275 | + ], |
|
| 276 | + 'trash_registrations' => [ |
|
| 277 | + 'func' => '_trash_or_restore_registrations', |
|
| 278 | + 'args' => ['trash' => true], |
|
| 279 | + 'noheader' => true, |
|
| 280 | + 'capability' => 'ee_delete_registrations', |
|
| 281 | + ], |
|
| 282 | + 'restore_registrations' => [ |
|
| 283 | + 'func' => '_trash_or_restore_registrations', |
|
| 284 | + 'args' => ['trash' => false], |
|
| 285 | + 'noheader' => true, |
|
| 286 | + 'capability' => 'ee_delete_registrations', |
|
| 287 | + ], |
|
| 288 | + 'delete_registrations' => [ |
|
| 289 | + 'func' => '_delete_registrations', |
|
| 290 | + 'noheader' => true, |
|
| 291 | + 'capability' => 'ee_delete_registrations', |
|
| 292 | + ], |
|
| 293 | + 'new_registration' => [ |
|
| 294 | + 'func' => 'new_registration', |
|
| 295 | + 'capability' => 'ee_edit_registrations', |
|
| 296 | + ], |
|
| 297 | + 'process_reg_step' => [ |
|
| 298 | + 'func' => 'process_reg_step', |
|
| 299 | + 'noheader' => true, |
|
| 300 | + 'capability' => 'ee_edit_registrations', |
|
| 301 | + ], |
|
| 302 | + 'redirect_to_txn' => [ |
|
| 303 | + 'func' => 'redirect_to_txn', |
|
| 304 | + 'noheader' => true, |
|
| 305 | + 'capability' => 'ee_edit_registrations', |
|
| 306 | + ], |
|
| 307 | + 'change_reg_status' => [ |
|
| 308 | + 'func' => '_change_reg_status', |
|
| 309 | + 'noheader' => true, |
|
| 310 | + 'capability' => 'ee_edit_registration', |
|
| 311 | + 'obj_id' => $REG_ID, |
|
| 312 | + ], |
|
| 313 | + 'approve_registration' => [ |
|
| 314 | + 'func' => 'approve_registration', |
|
| 315 | + 'noheader' => true, |
|
| 316 | + 'capability' => 'ee_edit_registration', |
|
| 317 | + 'obj_id' => $REG_ID, |
|
| 318 | + ], |
|
| 319 | + 'approve_and_notify_registration' => [ |
|
| 320 | + 'func' => 'approve_registration', |
|
| 321 | + 'noheader' => true, |
|
| 322 | + 'args' => [true], |
|
| 323 | + 'capability' => 'ee_edit_registration', |
|
| 324 | + 'obj_id' => $REG_ID, |
|
| 325 | + ], |
|
| 326 | + 'approve_registrations' => [ |
|
| 327 | + 'func' => 'bulk_action_on_registrations', |
|
| 328 | + 'noheader' => true, |
|
| 329 | + 'capability' => 'ee_edit_registrations', |
|
| 330 | + 'args' => ['approve'], |
|
| 331 | + ], |
|
| 332 | + 'approve_and_notify_registrations' => [ |
|
| 333 | + 'func' => 'bulk_action_on_registrations', |
|
| 334 | + 'noheader' => true, |
|
| 335 | + 'capability' => 'ee_edit_registrations', |
|
| 336 | + 'args' => ['approve', true], |
|
| 337 | + ], |
|
| 338 | + 'decline_registration' => [ |
|
| 339 | + 'func' => 'decline_registration', |
|
| 340 | + 'noheader' => true, |
|
| 341 | + 'capability' => 'ee_edit_registration', |
|
| 342 | + 'obj_id' => $REG_ID, |
|
| 343 | + ], |
|
| 344 | + 'decline_and_notify_registration' => [ |
|
| 345 | + 'func' => 'decline_registration', |
|
| 346 | + 'noheader' => true, |
|
| 347 | + 'args' => [true], |
|
| 348 | + 'capability' => 'ee_edit_registration', |
|
| 349 | + 'obj_id' => $REG_ID, |
|
| 350 | + ], |
|
| 351 | + 'decline_registrations' => [ |
|
| 352 | + 'func' => 'bulk_action_on_registrations', |
|
| 353 | + 'noheader' => true, |
|
| 354 | + 'capability' => 'ee_edit_registrations', |
|
| 355 | + 'args' => ['decline'], |
|
| 356 | + ], |
|
| 357 | + 'decline_and_notify_registrations' => [ |
|
| 358 | + 'func' => 'bulk_action_on_registrations', |
|
| 359 | + 'noheader' => true, |
|
| 360 | + 'capability' => 'ee_edit_registrations', |
|
| 361 | + 'args' => ['decline', true], |
|
| 362 | + ], |
|
| 363 | + 'pending_registration' => [ |
|
| 364 | + 'func' => 'pending_registration', |
|
| 365 | + 'noheader' => true, |
|
| 366 | + 'capability' => 'ee_edit_registration', |
|
| 367 | + 'obj_id' => $REG_ID, |
|
| 368 | + ], |
|
| 369 | + 'pending_and_notify_registration' => [ |
|
| 370 | + 'func' => 'pending_registration', |
|
| 371 | + 'noheader' => true, |
|
| 372 | + 'args' => [true], |
|
| 373 | + 'capability' => 'ee_edit_registration', |
|
| 374 | + 'obj_id' => $REG_ID, |
|
| 375 | + ], |
|
| 376 | + 'pending_registrations' => [ |
|
| 377 | + 'func' => 'bulk_action_on_registrations', |
|
| 378 | + 'noheader' => true, |
|
| 379 | + 'capability' => 'ee_edit_registrations', |
|
| 380 | + 'args' => ['pending'], |
|
| 381 | + ], |
|
| 382 | + 'pending_and_notify_registrations' => [ |
|
| 383 | + 'func' => 'bulk_action_on_registrations', |
|
| 384 | + 'noheader' => true, |
|
| 385 | + 'capability' => 'ee_edit_registrations', |
|
| 386 | + 'args' => ['pending', true], |
|
| 387 | + ], |
|
| 388 | + 'no_approve_registration' => [ |
|
| 389 | + 'func' => 'not_approve_registration', |
|
| 390 | + 'noheader' => true, |
|
| 391 | + 'capability' => 'ee_edit_registration', |
|
| 392 | + 'obj_id' => $REG_ID, |
|
| 393 | + ], |
|
| 394 | + 'no_approve_and_notify_registration' => [ |
|
| 395 | + 'func' => 'not_approve_registration', |
|
| 396 | + 'noheader' => true, |
|
| 397 | + 'args' => [true], |
|
| 398 | + 'capability' => 'ee_edit_registration', |
|
| 399 | + 'obj_id' => $REG_ID, |
|
| 400 | + ], |
|
| 401 | + 'no_approve_registrations' => [ |
|
| 402 | + 'func' => 'bulk_action_on_registrations', |
|
| 403 | + 'noheader' => true, |
|
| 404 | + 'capability' => 'ee_edit_registrations', |
|
| 405 | + 'args' => ['not_approve'], |
|
| 406 | + ], |
|
| 407 | + 'no_approve_and_notify_registrations' => [ |
|
| 408 | + 'func' => 'bulk_action_on_registrations', |
|
| 409 | + 'noheader' => true, |
|
| 410 | + 'capability' => 'ee_edit_registrations', |
|
| 411 | + 'args' => ['not_approve', true], |
|
| 412 | + ], |
|
| 413 | + 'cancel_registration' => [ |
|
| 414 | + 'func' => 'cancel_registration', |
|
| 415 | + 'noheader' => true, |
|
| 416 | + 'capability' => 'ee_edit_registration', |
|
| 417 | + 'obj_id' => $REG_ID, |
|
| 418 | + ], |
|
| 419 | + 'cancel_and_notify_registration' => [ |
|
| 420 | + 'func' => 'cancel_registration', |
|
| 421 | + 'noheader' => true, |
|
| 422 | + 'args' => [true], |
|
| 423 | + 'capability' => 'ee_edit_registration', |
|
| 424 | + 'obj_id' => $REG_ID, |
|
| 425 | + ], |
|
| 426 | + 'cancel_registrations' => [ |
|
| 427 | + 'func' => 'bulk_action_on_registrations', |
|
| 428 | + 'noheader' => true, |
|
| 429 | + 'capability' => 'ee_edit_registrations', |
|
| 430 | + 'args' => ['cancel'], |
|
| 431 | + ], |
|
| 432 | + 'cancel_and_notify_registrations' => [ |
|
| 433 | + 'func' => 'bulk_action_on_registrations', |
|
| 434 | + 'noheader' => true, |
|
| 435 | + 'capability' => 'ee_edit_registrations', |
|
| 436 | + 'args' => ['cancel', true], |
|
| 437 | + ], |
|
| 438 | + 'wait_list_registration' => [ |
|
| 439 | + 'func' => 'wait_list_registration', |
|
| 440 | + 'noheader' => true, |
|
| 441 | + 'capability' => 'ee_edit_registration', |
|
| 442 | + 'obj_id' => $REG_ID, |
|
| 443 | + ], |
|
| 444 | + 'wait_list_and_notify_registration' => [ |
|
| 445 | + 'func' => 'wait_list_registration', |
|
| 446 | + 'noheader' => true, |
|
| 447 | + 'args' => [true], |
|
| 448 | + 'capability' => 'ee_edit_registration', |
|
| 449 | + 'obj_id' => $REG_ID, |
|
| 450 | + ], |
|
| 451 | + 'contact_list' => [ |
|
| 452 | + 'func' => '_attendee_contact_list_table', |
|
| 453 | + 'capability' => 'ee_read_contacts', |
|
| 454 | + ], |
|
| 455 | + 'add_new_attendee' => [ |
|
| 456 | + 'func' => '_create_new_cpt_item', |
|
| 457 | + 'args' => [ |
|
| 458 | + 'new_attendee' => true, |
|
| 459 | + 'capability' => 'ee_edit_contacts', |
|
| 460 | + ], |
|
| 461 | + ], |
|
| 462 | + 'edit_attendee' => [ |
|
| 463 | + 'func' => '_edit_cpt_item', |
|
| 464 | + 'capability' => 'ee_edit_contacts', |
|
| 465 | + 'obj_id' => $ATT_ID, |
|
| 466 | + ], |
|
| 467 | + 'duplicate_attendee' => [ |
|
| 468 | + 'func' => '_duplicate_attendee', |
|
| 469 | + 'noheader' => true, |
|
| 470 | + 'capability' => 'ee_edit_contacts', |
|
| 471 | + 'obj_id' => $ATT_ID, |
|
| 472 | + ], |
|
| 473 | + 'insert_attendee' => [ |
|
| 474 | + 'func' => '_insert_or_update_attendee', |
|
| 475 | + 'args' => [ |
|
| 476 | + 'new_attendee' => true, |
|
| 477 | + ], |
|
| 478 | + 'noheader' => true, |
|
| 479 | + 'capability' => 'ee_edit_contacts', |
|
| 480 | + ], |
|
| 481 | + 'update_attendee' => [ |
|
| 482 | + 'func' => '_insert_or_update_attendee', |
|
| 483 | + 'args' => [ |
|
| 484 | + 'new_attendee' => false, |
|
| 485 | + ], |
|
| 486 | + 'noheader' => true, |
|
| 487 | + 'capability' => 'ee_edit_contacts', |
|
| 488 | + 'obj_id' => $ATT_ID, |
|
| 489 | + ], |
|
| 490 | + 'trash_attendees' => [ |
|
| 491 | + 'func' => '_trash_or_restore_attendees', |
|
| 492 | + 'args' => [ |
|
| 493 | + 'trash' => 'true', |
|
| 494 | + ], |
|
| 495 | + 'noheader' => true, |
|
| 496 | + 'capability' => 'ee_delete_contacts', |
|
| 497 | + ], |
|
| 498 | + 'trash_attendee' => [ |
|
| 499 | + 'func' => '_trash_or_restore_attendees', |
|
| 500 | + 'args' => [ |
|
| 501 | + 'trash' => true, |
|
| 502 | + ], |
|
| 503 | + 'noheader' => true, |
|
| 504 | + 'capability' => 'ee_delete_contacts', |
|
| 505 | + 'obj_id' => $ATT_ID, |
|
| 506 | + ], |
|
| 507 | + 'restore_attendees' => [ |
|
| 508 | + 'func' => '_trash_or_restore_attendees', |
|
| 509 | + 'args' => [ |
|
| 510 | + 'trash' => false, |
|
| 511 | + ], |
|
| 512 | + 'noheader' => true, |
|
| 513 | + 'capability' => 'ee_delete_contacts', |
|
| 514 | + 'obj_id' => $ATT_ID, |
|
| 515 | + ], |
|
| 516 | + 'resend_registration' => [ |
|
| 517 | + 'func' => '_resend_registration', |
|
| 518 | + 'noheader' => true, |
|
| 519 | + 'capability' => 'ee_send_message', |
|
| 520 | + ], |
|
| 521 | + 'registrations_report' => [ |
|
| 522 | + 'func' => '_registrations_report', |
|
| 523 | + 'noheader' => true, |
|
| 524 | + 'capability' => 'ee_read_registrations', |
|
| 525 | + ], |
|
| 526 | + 'contact_list_export' => [ |
|
| 527 | + 'func' => '_contact_list_export', |
|
| 528 | + 'noheader' => true, |
|
| 529 | + 'capability' => 'export', |
|
| 530 | + ], |
|
| 531 | + 'contact_list_report' => [ |
|
| 532 | + 'func' => '_contact_list_report', |
|
| 533 | + 'noheader' => true, |
|
| 534 | + 'capability' => 'ee_read_contacts', |
|
| 535 | + ], |
|
| 536 | + ]; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + protected function _set_page_config() |
|
| 541 | + { |
|
| 542 | + $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 543 | + $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int'); |
|
| 544 | + $this->_page_config = [ |
|
| 545 | + 'default' => [ |
|
| 546 | + 'nav' => [ |
|
| 547 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 548 | + 'order' => 5, |
|
| 549 | + ], |
|
| 550 | + 'help_tabs' => [ |
|
| 551 | + 'registrations_overview_help_tab' => [ |
|
| 552 | + 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
| 553 | + 'filename' => 'registrations_overview', |
|
| 554 | + ], |
|
| 555 | + 'registrations_overview_table_column_headings_help_tab' => [ |
|
| 556 | + 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
| 557 | + 'filename' => 'registrations_overview_table_column_headings', |
|
| 558 | + ], |
|
| 559 | + 'registrations_overview_filters_help_tab' => [ |
|
| 560 | + 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
| 561 | + 'filename' => 'registrations_overview_filters', |
|
| 562 | + ], |
|
| 563 | + 'registrations_overview_views_help_tab' => [ |
|
| 564 | + 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
| 565 | + 'filename' => 'registrations_overview_views', |
|
| 566 | + ], |
|
| 567 | + 'registrations_regoverview_other_help_tab' => [ |
|
| 568 | + 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
| 569 | + 'filename' => 'registrations_overview_other', |
|
| 570 | + ], |
|
| 571 | + ], |
|
| 572 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 573 | + // 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 574 | + 'qtips' => ['Registration_List_Table_Tips'], |
|
| 575 | + 'list_table' => 'EE_Registrations_List_Table', |
|
| 576 | + 'require_nonce' => false, |
|
| 577 | + ], |
|
| 578 | + 'view_registration' => [ |
|
| 579 | + 'nav' => [ |
|
| 580 | + 'label' => esc_html__('REG Details', 'event_espresso'), |
|
| 581 | + 'order' => 15, |
|
| 582 | + 'url' => $REG_ID |
|
| 583 | + ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url) |
|
| 584 | + : $this->_admin_base_url, |
|
| 585 | + 'persistent' => false, |
|
| 586 | + ], |
|
| 587 | + 'help_tabs' => [ |
|
| 588 | + 'registrations_details_help_tab' => [ |
|
| 589 | + 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
| 590 | + 'filename' => 'registrations_details', |
|
| 591 | + ], |
|
| 592 | + 'registrations_details_table_help_tab' => [ |
|
| 593 | + 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
| 594 | + 'filename' => 'registrations_details_table', |
|
| 595 | + ], |
|
| 596 | + 'registrations_details_form_answers_help_tab' => [ |
|
| 597 | + 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 598 | + 'filename' => 'registrations_details_form_answers', |
|
| 599 | + ], |
|
| 600 | + 'registrations_details_registrant_details_help_tab' => [ |
|
| 601 | + 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
| 602 | + 'filename' => 'registrations_details_registrant_details', |
|
| 603 | + ], |
|
| 604 | + ], |
|
| 605 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 606 | + // 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 607 | + 'metaboxes' => array_merge( |
|
| 608 | + $this->_default_espresso_metaboxes, |
|
| 609 | + ['_registration_details_metaboxes'] |
|
| 610 | + ), |
|
| 611 | + 'require_nonce' => false, |
|
| 612 | + ], |
|
| 613 | + 'new_registration' => [ |
|
| 614 | + 'nav' => [ |
|
| 615 | + 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 616 | + 'url' => '#', |
|
| 617 | + 'order' => 15, |
|
| 618 | + 'persistent' => false, |
|
| 619 | + ], |
|
| 620 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 621 | + 'labels' => [ |
|
| 622 | + 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
| 623 | + ], |
|
| 624 | + 'require_nonce' => false, |
|
| 625 | + ], |
|
| 626 | + 'add_new_attendee' => [ |
|
| 627 | + 'nav' => [ |
|
| 628 | + 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
| 629 | + 'order' => 15, |
|
| 630 | + 'persistent' => false, |
|
| 631 | + ], |
|
| 632 | + 'metaboxes' => array_merge( |
|
| 633 | + $this->_default_espresso_metaboxes, |
|
| 634 | + ['_publish_post_box', 'attendee_editor_metaboxes'] |
|
| 635 | + ), |
|
| 636 | + 'require_nonce' => false, |
|
| 637 | + ], |
|
| 638 | + 'edit_attendee' => [ |
|
| 639 | + 'nav' => [ |
|
| 640 | + 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 641 | + 'order' => 15, |
|
| 642 | + 'persistent' => false, |
|
| 643 | + 'url' => $ATT_ID |
|
| 644 | + ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url) |
|
| 645 | + : $this->_admin_base_url, |
|
| 646 | + ], |
|
| 647 | + 'metaboxes' => ['attendee_editor_metaboxes'], |
|
| 648 | + 'require_nonce' => false, |
|
| 649 | + ], |
|
| 650 | + 'contact_list' => [ |
|
| 651 | + 'nav' => [ |
|
| 652 | + 'label' => esc_html__('Contact List', 'event_espresso'), |
|
| 653 | + 'order' => 20, |
|
| 654 | + ], |
|
| 655 | + 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 656 | + 'help_tabs' => [ |
|
| 657 | + 'registrations_contact_list_help_tab' => [ |
|
| 658 | + 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
| 659 | + 'filename' => 'registrations_contact_list', |
|
| 660 | + ], |
|
| 661 | + 'registrations_contact-list_table_column_headings_help_tab' => [ |
|
| 662 | + 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
| 663 | + 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 664 | + ], |
|
| 665 | + 'registrations_contact_list_views_help_tab' => [ |
|
| 666 | + 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
| 667 | + 'filename' => 'registrations_contact_list_views', |
|
| 668 | + ], |
|
| 669 | + 'registrations_contact_list_other_help_tab' => [ |
|
| 670 | + 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
| 671 | + 'filename' => 'registrations_contact_list_other', |
|
| 672 | + ], |
|
| 673 | + ], |
|
| 674 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 675 | + // 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 676 | + 'metaboxes' => [], |
|
| 677 | + 'require_nonce' => false, |
|
| 678 | + ], |
|
| 679 | + // override default cpt routes |
|
| 680 | + 'create_new' => '', |
|
| 681 | + 'edit' => '', |
|
| 682 | + ]; |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * The below methods aren't used by this class currently |
|
| 688 | + */ |
|
| 689 | + protected function _add_screen_options() |
|
| 690 | + { |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + protected function _add_feature_pointers() |
|
| 695 | + { |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + public function admin_init() |
|
| 700 | + { |
|
| 701 | + EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
| 702 | + 'click "Update Registration Questions" to save your changes', |
|
| 703 | + 'event_espresso' |
|
| 704 | + ); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + public function admin_notices() |
|
| 709 | + { |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + public function admin_footer_scripts() |
|
| 714 | + { |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * get list of registration statuses |
|
| 720 | + * |
|
| 721 | + * @return void |
|
| 722 | + * @throws EE_Error |
|
| 723 | + */ |
|
| 724 | + private function _get_registration_status_array() |
|
| 725 | + { |
|
| 726 | + self::$_reg_status = EEM_Registration::reg_status_array([], true); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * @throws InvalidArgumentException |
|
| 732 | + * @throws InvalidDataTypeException |
|
| 733 | + * @throws InvalidInterfaceException |
|
| 734 | + * @since 4.10.2.p |
|
| 735 | + */ |
|
| 736 | + protected function _add_screen_options_default() |
|
| 737 | + { |
|
| 738 | + $this->_per_page_screen_option(); |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * @throws InvalidArgumentException |
|
| 744 | + * @throws InvalidDataTypeException |
|
| 745 | + * @throws InvalidInterfaceException |
|
| 746 | + * @since 4.10.2.p |
|
| 747 | + */ |
|
| 748 | + protected function _add_screen_options_contact_list() |
|
| 749 | + { |
|
| 750 | + $page_title = $this->_admin_page_title; |
|
| 751 | + $this->_admin_page_title = esc_html__('Contacts', 'event_espresso'); |
|
| 752 | + $this->_per_page_screen_option(); |
|
| 753 | + $this->_admin_page_title = $page_title; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + public function load_scripts_styles() |
|
| 758 | + { |
|
| 759 | + // style |
|
| 760 | + wp_register_style( |
|
| 761 | + 'espresso_reg', |
|
| 762 | + REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
| 763 | + ['ee-admin-css'], |
|
| 764 | + EVENT_ESPRESSO_VERSION |
|
| 765 | + ); |
|
| 766 | + wp_enqueue_style('espresso_reg'); |
|
| 767 | + // script |
|
| 768 | + wp_register_script( |
|
| 769 | + 'espresso_reg', |
|
| 770 | + REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 771 | + ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'], |
|
| 772 | + EVENT_ESPRESSO_VERSION, |
|
| 773 | + true |
|
| 774 | + ); |
|
| 775 | + wp_enqueue_script('espresso_reg'); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * @throws EE_Error |
|
| 781 | + * @throws InvalidArgumentException |
|
| 782 | + * @throws InvalidDataTypeException |
|
| 783 | + * @throws InvalidInterfaceException |
|
| 784 | + * @throws ReflectionException |
|
| 785 | + * @since 4.10.2.p |
|
| 786 | + */ |
|
| 787 | + public function load_scripts_styles_edit_attendee() |
|
| 788 | + { |
|
| 789 | + // stuff to only show up on our attendee edit details page. |
|
| 790 | + $attendee_details_translations = [ |
|
| 791 | + 'att_publish_text' => sprintf( |
|
| 792 | + /* translators: The date and time */ |
|
| 793 | + wp_strip_all_tags(__('Created on: %s', 'event_espresso')), |
|
| 794 | + '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>' |
|
| 795 | + ), |
|
| 796 | + ]; |
|
| 797 | + wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 798 | + wp_enqueue_script('jquery-validate'); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * @throws EE_Error |
|
| 804 | + * @throws InvalidArgumentException |
|
| 805 | + * @throws InvalidDataTypeException |
|
| 806 | + * @throws InvalidInterfaceException |
|
| 807 | + * @throws ReflectionException |
|
| 808 | + * @since 4.10.2.p |
|
| 809 | + */ |
|
| 810 | + public function load_scripts_styles_view_registration() |
|
| 811 | + { |
|
| 812 | + // styles |
|
| 813 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 814 | + // scripts |
|
| 815 | + $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 816 | + $this->_reg_custom_questions_form->wp_enqueue_scripts(); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + |
|
| 820 | + public function load_scripts_styles_contact_list() |
|
| 821 | + { |
|
| 822 | + wp_dequeue_style('espresso_reg'); |
|
| 823 | + wp_register_style( |
|
| 824 | + 'espresso_att', |
|
| 825 | + REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
| 826 | + ['ee-admin-css'], |
|
| 827 | + EVENT_ESPRESSO_VERSION |
|
| 828 | + ); |
|
| 829 | + wp_enqueue_style('espresso_att'); |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + |
|
| 833 | + public function load_scripts_styles_new_registration() |
|
| 834 | + { |
|
| 835 | + wp_register_script( |
|
| 836 | + 'ee-spco-for-admin', |
|
| 837 | + REG_ASSETS_URL . 'spco_for_admin.js', |
|
| 838 | + ['underscore', 'jquery'], |
|
| 839 | + EVENT_ESPRESSO_VERSION, |
|
| 840 | + true |
|
| 841 | + ); |
|
| 842 | + wp_enqueue_script('ee-spco-for-admin'); |
|
| 843 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 844 | + EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 845 | + EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 846 | + EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + |
|
| 850 | + public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 851 | + { |
|
| 852 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + |
|
| 856 | + public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 857 | + { |
|
| 858 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * @throws EE_Error |
|
| 864 | + * @throws InvalidArgumentException |
|
| 865 | + * @throws InvalidDataTypeException |
|
| 866 | + * @throws InvalidInterfaceException |
|
| 867 | + * @throws ReflectionException |
|
| 868 | + * @since 4.10.2.p |
|
| 869 | + */ |
|
| 870 | + protected function _set_list_table_views_default() |
|
| 871 | + { |
|
| 872 | + // for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 873 | + EED_Messages::set_autoloaders(); |
|
| 874 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 875 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 876 | + $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 877 | + // key= bulk_action_slug, value= message type. |
|
| 878 | + $match_array = [ |
|
| 879 | + 'approve_registrations' => 'registration', |
|
| 880 | + 'decline_registrations' => 'declined_registration', |
|
| 881 | + 'pending_registrations' => 'pending_approval', |
|
| 882 | + 'no_approve_registrations' => 'not_approved_registration', |
|
| 883 | + 'cancel_registrations' => 'cancelled_registration', |
|
| 884 | + ]; |
|
| 885 | + $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
| 886 | + 'ee_send_message', |
|
| 887 | + 'batch_send_messages' |
|
| 888 | + ); |
|
| 889 | + /** setup reg status bulk actions **/ |
|
| 890 | + $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso'); |
|
| 891 | + if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) { |
|
| 892 | + $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__( |
|
| 893 | + 'Approve and Notify Registrations', |
|
| 894 | + 'event_espresso' |
|
| 895 | + ); |
|
| 896 | + } |
|
| 897 | + $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso'); |
|
| 898 | + if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) { |
|
| 899 | + $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__( |
|
| 900 | + 'Decline and Notify Registrations', |
|
| 901 | + 'event_espresso' |
|
| 902 | + ); |
|
| 903 | + } |
|
| 904 | + $def_reg_status_actions['pending_registrations'] = esc_html__( |
|
| 905 | + 'Set Registrations to Pending Payment', |
|
| 906 | + 'event_espresso' |
|
| 907 | + ); |
|
| 908 | + if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) { |
|
| 909 | + $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__( |
|
| 910 | + 'Set Registrations to Pending Payment and Notify', |
|
| 911 | + 'event_espresso' |
|
| 912 | + ); |
|
| 913 | + } |
|
| 914 | + $def_reg_status_actions['no_approve_registrations'] = esc_html__( |
|
| 915 | + 'Set Registrations to Not Approved', |
|
| 916 | + 'event_espresso' |
|
| 917 | + ); |
|
| 918 | + if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) { |
|
| 919 | + $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__( |
|
| 920 | + 'Set Registrations to Not Approved and Notify', |
|
| 921 | + 'event_espresso' |
|
| 922 | + ); |
|
| 923 | + } |
|
| 924 | + $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso'); |
|
| 925 | + if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) { |
|
| 926 | + $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__( |
|
| 927 | + 'Cancel Registrations and Notify', |
|
| 928 | + 'event_espresso' |
|
| 929 | + ); |
|
| 930 | + } |
|
| 931 | + $def_reg_status_actions = apply_filters( |
|
| 932 | + 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
| 933 | + $def_reg_status_actions, |
|
| 934 | + $active_mts, |
|
| 935 | + $can_send |
|
| 936 | + ); |
|
| 937 | + |
|
| 938 | + $this->_views = [ |
|
| 939 | + 'all' => [ |
|
| 940 | + 'slug' => 'all', |
|
| 941 | + 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
| 942 | + 'count' => 0, |
|
| 943 | + 'bulk_action' => array_merge( |
|
| 944 | + $def_reg_status_actions, |
|
| 945 | + [ |
|
| 946 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 947 | + ] |
|
| 948 | + ), |
|
| 949 | + ], |
|
| 950 | + 'month' => [ |
|
| 951 | + 'slug' => 'month', |
|
| 952 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 953 | + 'count' => 0, |
|
| 954 | + 'bulk_action' => array_merge( |
|
| 955 | + $def_reg_status_actions, |
|
| 956 | + [ |
|
| 957 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 958 | + ] |
|
| 959 | + ), |
|
| 960 | + ], |
|
| 961 | + 'today' => [ |
|
| 962 | + 'slug' => 'today', |
|
| 963 | + 'label' => sprintf( |
|
| 964 | + esc_html__('Today - %s', 'event_espresso'), |
|
| 965 | + date('M d, Y', current_time('timestamp')) |
|
| 966 | + ), |
|
| 967 | + 'count' => 0, |
|
| 968 | + 'bulk_action' => array_merge( |
|
| 969 | + $def_reg_status_actions, |
|
| 970 | + [ |
|
| 971 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 972 | + ] |
|
| 973 | + ), |
|
| 974 | + ], |
|
| 975 | + ]; |
|
| 976 | + if ( |
|
| 977 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 978 | + 'ee_delete_registrations', |
|
| 979 | + 'espresso_registrations_delete_registration' |
|
| 980 | + ) |
|
| 981 | + ) { |
|
| 982 | + $this->_views['incomplete'] = [ |
|
| 983 | + 'slug' => 'incomplete', |
|
| 984 | + 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
| 985 | + 'count' => 0, |
|
| 986 | + 'bulk_action' => [ |
|
| 987 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 988 | + ], |
|
| 989 | + ]; |
|
| 990 | + $this->_views['trash'] = [ |
|
| 991 | + 'slug' => 'trash', |
|
| 992 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 993 | + 'count' => 0, |
|
| 994 | + 'bulk_action' => [ |
|
| 995 | + 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
| 996 | + 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
| 997 | + ], |
|
| 998 | + ]; |
|
| 999 | + } |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + |
|
| 1003 | + protected function _set_list_table_views_contact_list() |
|
| 1004 | + { |
|
| 1005 | + $this->_views = [ |
|
| 1006 | + 'in_use' => [ |
|
| 1007 | + 'slug' => 'in_use', |
|
| 1008 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 1009 | + 'count' => 0, |
|
| 1010 | + 'bulk_action' => [ |
|
| 1011 | + 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 1012 | + ], |
|
| 1013 | + ], |
|
| 1014 | + ]; |
|
| 1015 | + if ( |
|
| 1016 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 1017 | + 'ee_delete_contacts', |
|
| 1018 | + 'espresso_registrations_trash_attendees' |
|
| 1019 | + ) |
|
| 1020 | + ) { |
|
| 1021 | + $this->_views['trash'] = [ |
|
| 1022 | + 'slug' => 'trash', |
|
| 1023 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 1024 | + 'count' => 0, |
|
| 1025 | + 'bulk_action' => [ |
|
| 1026 | + 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 1027 | + ], |
|
| 1028 | + ]; |
|
| 1029 | + } |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * @return array |
|
| 1035 | + * @throws EE_Error |
|
| 1036 | + */ |
|
| 1037 | + protected function _registration_legend_items() |
|
| 1038 | + { |
|
| 1039 | + $fc_items = [ |
|
| 1040 | + 'star-icon' => [ |
|
| 1041 | + 'class' => 'dashicons dashicons-star-filled gold-icon', |
|
| 1042 | + 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
| 1043 | + ], |
|
| 1044 | + 'view_details' => [ |
|
| 1045 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 1046 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 1047 | + ], |
|
| 1048 | + 'edit_attendee' => [ |
|
| 1049 | + 'class' => 'dashicons dashicons-groups', |
|
| 1050 | + 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
| 1051 | + ], |
|
| 1052 | + 'view_transaction' => [ |
|
| 1053 | + 'class' => 'dashicons dashicons-cart', |
|
| 1054 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 1055 | + ], |
|
| 1056 | + 'view_invoice' => [ |
|
| 1057 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 1058 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 1059 | + ], |
|
| 1060 | + ]; |
|
| 1061 | + if ( |
|
| 1062 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 1063 | + 'ee_send_message', |
|
| 1064 | + 'espresso_registrations_resend_registration' |
|
| 1065 | + ) |
|
| 1066 | + ) { |
|
| 1067 | + $fc_items['resend_registration'] = [ |
|
| 1068 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 1069 | + 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
| 1070 | + ]; |
|
| 1071 | + } else { |
|
| 1072 | + $fc_items['blank'] = ['class' => 'blank', 'desc' => '']; |
|
| 1073 | + } |
|
| 1074 | + if ( |
|
| 1075 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 1076 | + 'ee_read_global_messages', |
|
| 1077 | + 'view_filtered_messages' |
|
| 1078 | + ) |
|
| 1079 | + ) { |
|
| 1080 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 1081 | + if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) { |
|
| 1082 | + $fc_items['view_related_messages'] = [ |
|
| 1083 | + 'class' => $related_for_icon['css_class'], |
|
| 1084 | + 'desc' => $related_for_icon['label'], |
|
| 1085 | + ]; |
|
| 1086 | + } |
|
| 1087 | + } |
|
| 1088 | + $sc_items = [ |
|
| 1089 | + 'approved_status' => [ |
|
| 1090 | + 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_approved, |
|
| 1091 | + 'desc' => EEH_Template::pretty_status( |
|
| 1092 | + EEM_Registration::status_id_approved, |
|
| 1093 | + false, |
|
| 1094 | + 'sentence' |
|
| 1095 | + ), |
|
| 1096 | + ], |
|
| 1097 | + 'pending_status' => [ |
|
| 1098 | + 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_pending_payment, |
|
| 1099 | + 'desc' => EEH_Template::pretty_status( |
|
| 1100 | + EEM_Registration::status_id_pending_payment, |
|
| 1101 | + false, |
|
| 1102 | + 'sentence' |
|
| 1103 | + ), |
|
| 1104 | + ], |
|
| 1105 | + 'wait_list' => [ |
|
| 1106 | + 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_wait_list, |
|
| 1107 | + 'desc' => EEH_Template::pretty_status( |
|
| 1108 | + EEM_Registration::status_id_wait_list, |
|
| 1109 | + false, |
|
| 1110 | + 'sentence' |
|
| 1111 | + ), |
|
| 1112 | + ], |
|
| 1113 | + 'incomplete_status' => [ |
|
| 1114 | + 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_incomplete, |
|
| 1115 | + 'desc' => EEH_Template::pretty_status( |
|
| 1116 | + EEM_Registration::status_id_incomplete, |
|
| 1117 | + false, |
|
| 1118 | + 'sentence' |
|
| 1119 | + ), |
|
| 1120 | + ], |
|
| 1121 | + 'not_approved' => [ |
|
| 1122 | + 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_not_approved, |
|
| 1123 | + 'desc' => EEH_Template::pretty_status( |
|
| 1124 | + EEM_Registration::status_id_not_approved, |
|
| 1125 | + false, |
|
| 1126 | + 'sentence' |
|
| 1127 | + ), |
|
| 1128 | + ], |
|
| 1129 | + 'declined_status' => [ |
|
| 1130 | + 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_declined, |
|
| 1131 | + 'desc' => EEH_Template::pretty_status( |
|
| 1132 | + EEM_Registration::status_id_declined, |
|
| 1133 | + false, |
|
| 1134 | + 'sentence' |
|
| 1135 | + ), |
|
| 1136 | + ], |
|
| 1137 | + 'cancelled_status' => [ |
|
| 1138 | + 'class' => 'ee-status-legend ee-status-legend--' . EEM_Registration::status_id_cancelled, |
|
| 1139 | + 'desc' => EEH_Template::pretty_status( |
|
| 1140 | + EEM_Registration::status_id_cancelled, |
|
| 1141 | + false, |
|
| 1142 | + 'sentence' |
|
| 1143 | + ), |
|
| 1144 | + ], |
|
| 1145 | + ]; |
|
| 1146 | + return array_merge($fc_items, $sc_items); |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + |
|
| 1151 | + /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 1152 | + |
|
| 1153 | + |
|
| 1154 | + /** |
|
| 1155 | + * @throws DomainException |
|
| 1156 | + * @throws EE_Error |
|
| 1157 | + * @throws InvalidArgumentException |
|
| 1158 | + * @throws InvalidDataTypeException |
|
| 1159 | + * @throws InvalidInterfaceException |
|
| 1160 | + */ |
|
| 1161 | + protected function _registrations_overview_list_table() |
|
| 1162 | + { |
|
| 1163 | + $this->appendAddNewRegistrationButtonToPageTitle(); |
|
| 1164 | + $header_text = ''; |
|
| 1165 | + $admin_page_header_decorators = [ |
|
| 1166 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader', |
|
| 1167 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader', |
|
| 1168 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader', |
|
| 1169 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader', |
|
| 1170 | + ]; |
|
| 1171 | + foreach ($admin_page_header_decorators as $admin_page_header_decorator) { |
|
| 1172 | + $filter_header_decorator = $this->loader->getNew($admin_page_header_decorator); |
|
| 1173 | + $header_text = $filter_header_decorator->getHeaderText($header_text); |
|
| 1174 | + } |
|
| 1175 | + $this->_template_args['admin_page_header'] = $header_text; |
|
| 1176 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 1177 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * @throws EE_Error |
|
| 1183 | + * @throws InvalidArgumentException |
|
| 1184 | + * @throws InvalidDataTypeException |
|
| 1185 | + * @throws InvalidInterfaceException |
|
| 1186 | + */ |
|
| 1187 | + private function appendAddNewRegistrationButtonToPageTitle() |
|
| 1188 | + { |
|
| 1189 | + $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int'); |
|
| 1190 | + if ( |
|
| 1191 | + $EVT_ID |
|
| 1192 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1193 | + 'ee_edit_registrations', |
|
| 1194 | + 'espresso_registrations_new_registration', |
|
| 1195 | + $EVT_ID |
|
| 1196 | + ) |
|
| 1197 | + ) { |
|
| 1198 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 1199 | + 'new_registration', |
|
| 1200 | + 'add-registrant', |
|
| 1201 | + ['event_id' => $EVT_ID], |
|
| 1202 | + 'add-new-h2' |
|
| 1203 | + ); |
|
| 1204 | + } |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * This sets the _registration property for the registration details screen |
|
| 1210 | + * |
|
| 1211 | + * @return void |
|
| 1212 | + * @throws EE_Error |
|
| 1213 | + * @throws InvalidArgumentException |
|
| 1214 | + * @throws InvalidDataTypeException |
|
| 1215 | + * @throws InvalidInterfaceException |
|
| 1216 | + */ |
|
| 1217 | + private function _set_registration_object() |
|
| 1218 | + { |
|
| 1219 | + // get out if we've already set the object |
|
| 1220 | + if ($this->_registration instanceof EE_Registration) { |
|
| 1221 | + return; |
|
| 1222 | + } |
|
| 1223 | + $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 1224 | + if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) { |
|
| 1225 | + return; |
|
| 1226 | + } |
|
| 1227 | + $error_msg = sprintf( |
|
| 1228 | + esc_html__( |
|
| 1229 | + 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 1230 | + 'event_espresso' |
|
| 1231 | + ), |
|
| 1232 | + $REG_ID |
|
| 1233 | + ); |
|
| 1234 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1235 | + $this->_registration = null; |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + /** |
|
| 1240 | + * Used to retrieve registrations for the list table. |
|
| 1241 | + * |
|
| 1242 | + * @param int $per_page |
|
| 1243 | + * @param bool $count |
|
| 1244 | + * @param bool $this_month |
|
| 1245 | + * @param bool $today |
|
| 1246 | + * @return EE_Registration[]|int |
|
| 1247 | + * @throws EE_Error |
|
| 1248 | + * @throws InvalidArgumentException |
|
| 1249 | + * @throws InvalidDataTypeException |
|
| 1250 | + * @throws InvalidInterfaceException |
|
| 1251 | + */ |
|
| 1252 | + public function get_registrations( |
|
| 1253 | + $per_page = 10, |
|
| 1254 | + $count = false, |
|
| 1255 | + $this_month = false, |
|
| 1256 | + $today = false |
|
| 1257 | + ) { |
|
| 1258 | + if ($this_month) { |
|
| 1259 | + $this->request->setRequestParam('status', 'month'); |
|
| 1260 | + } |
|
| 1261 | + if ($today) { |
|
| 1262 | + $this->request->setRequestParam('status', 'today'); |
|
| 1263 | + } |
|
| 1264 | + $query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count); |
|
| 1265 | + /** |
|
| 1266 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1267 | + * |
|
| 1268 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1269 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1270 | + * or if you have the development copy of EE you can view this at the path: |
|
| 1271 | + * /docs/G--Model-System/model-query-params.md |
|
| 1272 | + */ |
|
| 1273 | + $query_params['group_by'] = ''; |
|
| 1274 | + |
|
| 1275 | + return $count |
|
| 1276 | + ? $this->getRegistrationModel()->count($query_params) |
|
| 1277 | + /** @type EE_Registration[] */ |
|
| 1278 | + : $this->getRegistrationModel()->get_all($query_params); |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 1284 | + * Note: this listens to values on the request for some of the query parameters. |
|
| 1285 | + * |
|
| 1286 | + * @param array $request |
|
| 1287 | + * @param int $per_page |
|
| 1288 | + * @param bool $count |
|
| 1289 | + * @return array |
|
| 1290 | + * @throws EE_Error |
|
| 1291 | + * @throws InvalidArgumentException |
|
| 1292 | + * @throws InvalidDataTypeException |
|
| 1293 | + * @throws InvalidInterfaceException |
|
| 1294 | + */ |
|
| 1295 | + protected function _get_registration_query_parameters( |
|
| 1296 | + $request = [], |
|
| 1297 | + $per_page = 10, |
|
| 1298 | + $count = false |
|
| 1299 | + ) { |
|
| 1300 | + /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */ |
|
| 1301 | + $list_table_query_builder = $this->loader->getNew( |
|
| 1302 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder', |
|
| 1303 | + [null, null, $request] |
|
| 1304 | + ); |
|
| 1305 | + return $list_table_query_builder->getQueryParams($per_page, $count); |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + public function get_registration_status_array() |
|
| 1310 | + { |
|
| 1311 | + return self::$_reg_status; |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + |
|
| 1317 | + /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1318 | + /** |
|
| 1319 | + * generates HTML for the View Registration Details Admin page |
|
| 1320 | + * |
|
| 1321 | + * @return void |
|
| 1322 | + * @throws DomainException |
|
| 1323 | + * @throws EE_Error |
|
| 1324 | + * @throws InvalidArgumentException |
|
| 1325 | + * @throws InvalidDataTypeException |
|
| 1326 | + * @throws InvalidInterfaceException |
|
| 1327 | + * @throws EntityNotFoundException |
|
| 1328 | + * @throws ReflectionException |
|
| 1329 | + */ |
|
| 1330 | + protected function _registration_details() |
|
| 1331 | + { |
|
| 1332 | + $this->_template_args = []; |
|
| 1333 | + $this->_set_registration_object(); |
|
| 1334 | + if (is_object($this->_registration)) { |
|
| 1335 | + $transaction = $this->_registration->transaction() |
|
| 1336 | + ? $this->_registration->transaction() |
|
| 1337 | + : EE_Transaction::new_instance(); |
|
| 1338 | + $this->_session = $transaction->session_data(); |
|
| 1339 | + $event_id = $this->_registration->event_ID(); |
|
| 1340 | + $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1341 | + $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
| 1342 | + $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1343 | + $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 1344 | + $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1345 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1346 | + // link back to overview |
|
| 1347 | + $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1348 | + $this->_template_args['registration'] = $this->_registration; |
|
| 1349 | + $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1350 | + [ |
|
| 1351 | + 'action' => 'default', |
|
| 1352 | + 'event_id' => $event_id, |
|
| 1353 | + ], |
|
| 1354 | + REG_ADMIN_URL |
|
| 1355 | + ); |
|
| 1356 | + $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1357 | + [ |
|
| 1358 | + 'action' => 'default', |
|
| 1359 | + 'EVT_ID' => $event_id, |
|
| 1360 | + 'page' => 'espresso_transactions', |
|
| 1361 | + ], |
|
| 1362 | + admin_url('admin.php') |
|
| 1363 | + ); |
|
| 1364 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1365 | + [ |
|
| 1366 | + 'page' => 'espresso_events', |
|
| 1367 | + 'action' => 'edit', |
|
| 1368 | + 'post' => $event_id, |
|
| 1369 | + ], |
|
| 1370 | + admin_url('admin.php') |
|
| 1371 | + ); |
|
| 1372 | + // next and previous links |
|
| 1373 | + $next_reg = $this->_registration->next( |
|
| 1374 | + null, |
|
| 1375 | + [], |
|
| 1376 | + 'REG_ID' |
|
| 1377 | + ); |
|
| 1378 | + $this->_template_args['next_registration'] = $next_reg |
|
| 1379 | + ? $this->_next_link( |
|
| 1380 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1381 | + [ |
|
| 1382 | + 'action' => 'view_registration', |
|
| 1383 | + '_REG_ID' => $next_reg['REG_ID'], |
|
| 1384 | + ], |
|
| 1385 | + REG_ADMIN_URL |
|
| 1386 | + ), |
|
| 1387 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 1388 | + ) |
|
| 1389 | + : ''; |
|
| 1390 | + $previous_reg = $this->_registration->previous( |
|
| 1391 | + null, |
|
| 1392 | + [], |
|
| 1393 | + 'REG_ID' |
|
| 1394 | + ); |
|
| 1395 | + $this->_template_args['previous_registration'] = $previous_reg |
|
| 1396 | + ? $this->_previous_link( |
|
| 1397 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1398 | + [ |
|
| 1399 | + 'action' => 'view_registration', |
|
| 1400 | + '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1401 | + ], |
|
| 1402 | + REG_ADMIN_URL |
|
| 1403 | + ), |
|
| 1404 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 1405 | + ) |
|
| 1406 | + : ''; |
|
| 1407 | + // grab header |
|
| 1408 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1409 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1410 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 1411 | + $template_path, |
|
| 1412 | + $this->_template_args, |
|
| 1413 | + true |
|
| 1414 | + ); |
|
| 1415 | + } else { |
|
| 1416 | + $this->_template_args['admin_page_header'] = ''; |
|
| 1417 | + $this->_display_espresso_notices(); |
|
| 1418 | + } |
|
| 1419 | + // the details template wrapper |
|
| 1420 | + $this->display_admin_page_with_sidebar(); |
|
| 1421 | + } |
|
| 1422 | + |
|
| 1423 | + |
|
| 1424 | + /** |
|
| 1425 | + * @throws EE_Error |
|
| 1426 | + * @throws InvalidArgumentException |
|
| 1427 | + * @throws InvalidDataTypeException |
|
| 1428 | + * @throws InvalidInterfaceException |
|
| 1429 | + * @throws ReflectionException |
|
| 1430 | + * @since 4.10.2.p |
|
| 1431 | + */ |
|
| 1432 | + protected function _registration_details_metaboxes() |
|
| 1433 | + { |
|
| 1434 | + do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1435 | + $this->_set_registration_object(); |
|
| 1436 | + $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1437 | + $this->addMetaBox( |
|
| 1438 | + 'edit-reg-status-mbox', |
|
| 1439 | + esc_html__('Registration Status', 'event_espresso'), |
|
| 1440 | + [$this, 'set_reg_status_buttons_metabox'], |
|
| 1441 | + $this->_wp_page_slug |
|
| 1442 | + ); |
|
| 1443 | + $this->addMetaBox( |
|
| 1444 | + 'edit-reg-details-mbox', |
|
| 1445 | + '<span>' . esc_html__('Registration Details', 'event_espresso') |
|
| 1446 | + . ' <span class="dashicons dashicons-clipboard"></span></span>', |
|
| 1447 | + [$this, '_reg_details_meta_box'], |
|
| 1448 | + $this->_wp_page_slug |
|
| 1449 | + ); |
|
| 1450 | + if ( |
|
| 1451 | + $attendee instanceof EE_Attendee |
|
| 1452 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1453 | + 'ee_read_registration', |
|
| 1454 | + 'edit-reg-questions-mbox', |
|
| 1455 | + $this->_registration->ID() |
|
| 1456 | + ) |
|
| 1457 | + ) { |
|
| 1458 | + $this->addMetaBox( |
|
| 1459 | + $this->_wp_page_slug, |
|
| 1460 | + 'edit-reg-questions-mbox', |
|
| 1461 | + esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 1462 | + [$this, '_reg_questions_meta_box'], |
|
| 1463 | + $this->_wp_page_slug |
|
| 1464 | + ); |
|
| 1465 | + } |
|
| 1466 | + $this->addMetaBox( |
|
| 1467 | + 'edit-reg-registrant-mbox', |
|
| 1468 | + esc_html__('Contact Details', 'event_espresso'), |
|
| 1469 | + [$this, '_reg_registrant_side_meta_box'], |
|
| 1470 | + $this->_wp_page_slug, |
|
| 1471 | + 'side' |
|
| 1472 | + ); |
|
| 1473 | + if ($this->_registration->group_size() > 1) { |
|
| 1474 | + $this->addMetaBox( |
|
| 1475 | + 'edit-reg-attendees-mbox', |
|
| 1476 | + esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1477 | + [$this, '_reg_attendees_meta_box'], |
|
| 1478 | + $this->_wp_page_slug |
|
| 1479 | + ); |
|
| 1480 | + } |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + |
|
| 1484 | + /** |
|
| 1485 | + * set_reg_status_buttons_metabox |
|
| 1486 | + * |
|
| 1487 | + * @return void |
|
| 1488 | + * @throws EE_Error |
|
| 1489 | + * @throws EntityNotFoundException |
|
| 1490 | + * @throws InvalidArgumentException |
|
| 1491 | + * @throws InvalidDataTypeException |
|
| 1492 | + * @throws InvalidInterfaceException |
|
| 1493 | + * @throws ReflectionException |
|
| 1494 | + */ |
|
| 1495 | + public function set_reg_status_buttons_metabox() |
|
| 1496 | + { |
|
| 1497 | + $this->_set_registration_object(); |
|
| 1498 | + $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1499 | + $output = $change_reg_status_form->form_open( |
|
| 1500 | + self::add_query_args_and_nonce( |
|
| 1501 | + [ |
|
| 1502 | + 'action' => 'change_reg_status', |
|
| 1503 | + ], |
|
| 1504 | + REG_ADMIN_URL |
|
| 1505 | + ) |
|
| 1506 | + ); |
|
| 1507 | + $output .= $change_reg_status_form->get_html(); |
|
| 1508 | + $output .= $change_reg_status_form->form_close(); |
|
| 1509 | + echo $output; // already escaped |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + |
|
| 1513 | + /** |
|
| 1514 | + * @return EE_Form_Section_Proper |
|
| 1515 | + * @throws EE_Error |
|
| 1516 | + * @throws InvalidArgumentException |
|
| 1517 | + * @throws InvalidDataTypeException |
|
| 1518 | + * @throws InvalidInterfaceException |
|
| 1519 | + * @throws EntityNotFoundException |
|
| 1520 | + * @throws ReflectionException |
|
| 1521 | + */ |
|
| 1522 | + protected function _generate_reg_status_change_form() |
|
| 1523 | + { |
|
| 1524 | + $reg_status_change_form_array = [ |
|
| 1525 | + 'name' => 'reg_status_change_form', |
|
| 1526 | + 'html_id' => 'reg-status-change-form', |
|
| 1527 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1528 | + 'subsections' => [ |
|
| 1529 | + 'return' => new EE_Hidden_Input( |
|
| 1530 | + [ |
|
| 1531 | + 'name' => 'return', |
|
| 1532 | + 'default' => 'view_registration', |
|
| 1533 | + ] |
|
| 1534 | + ), |
|
| 1535 | + 'REG_ID' => new EE_Hidden_Input( |
|
| 1536 | + [ |
|
| 1537 | + 'name' => 'REG_ID', |
|
| 1538 | + 'default' => $this->_registration->ID(), |
|
| 1539 | + ] |
|
| 1540 | + ), |
|
| 1541 | + 'current_status' => new EE_Form_Section_HTML( |
|
| 1542 | + EEH_HTML::table( |
|
| 1543 | + EEH_HTML::tr( |
|
| 1544 | + EEH_HTML::th( |
|
| 1545 | + EEH_HTML::label( |
|
| 1546 | + EEH_HTML::strong( |
|
| 1547 | + esc_html__('Current Registration Status', 'event_espresso') |
|
| 1548 | + ) |
|
| 1549 | + ) |
|
| 1550 | + ) |
|
| 1551 | + . EEH_HTML::td( |
|
| 1552 | + EEH_HTML::strong( |
|
| 1553 | + $this->_registration->pretty_status(), |
|
| 1554 | + '', |
|
| 1555 | + 'status-' . $this->_registration->status_ID(), |
|
| 1556 | + 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
| 1557 | + ) |
|
| 1558 | + ) |
|
| 1559 | + ) |
|
| 1560 | + ) |
|
| 1561 | + ), |
|
| 1562 | + ], |
|
| 1563 | + ]; |
|
| 1564 | + if ( |
|
| 1565 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 1566 | + 'ee_edit_registration', |
|
| 1567 | + 'toggle_registration_status', |
|
| 1568 | + $this->_registration->ID() |
|
| 1569 | + ) |
|
| 1570 | + ) { |
|
| 1571 | + $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input( |
|
| 1572 | + $this->_get_reg_statuses(), |
|
| 1573 | + [ |
|
| 1574 | + 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
| 1575 | + 'default' => $this->_registration->status_ID(), |
|
| 1576 | + ] |
|
| 1577 | + ); |
|
| 1578 | + $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input( |
|
| 1579 | + [ |
|
| 1580 | + 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
| 1581 | + 'default' => false, |
|
| 1582 | + 'html_help_text' => esc_html__( |
|
| 1583 | + 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1584 | + 'event_espresso' |
|
| 1585 | + ), |
|
| 1586 | + ] |
|
| 1587 | + ); |
|
| 1588 | + $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input( |
|
| 1589 | + [ |
|
| 1590 | + 'html_class' => 'button--primary', |
|
| 1591 | + 'html_label_text' => ' ', |
|
| 1592 | + 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
| 1593 | + ] |
|
| 1594 | + ); |
|
| 1595 | + } |
|
| 1596 | + return new EE_Form_Section_Proper($reg_status_change_form_array); |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + |
|
| 1600 | + /** |
|
| 1601 | + * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1602 | + * |
|
| 1603 | + * @return array |
|
| 1604 | + * @throws EE_Error |
|
| 1605 | + * @throws InvalidArgumentException |
|
| 1606 | + * @throws InvalidDataTypeException |
|
| 1607 | + * @throws InvalidInterfaceException |
|
| 1608 | + * @throws EntityNotFoundException |
|
| 1609 | + */ |
|
| 1610 | + protected function _get_reg_statuses() |
|
| 1611 | + { |
|
| 1612 | + $reg_status_array = $this->getRegistrationModel()->reg_status_array(); |
|
| 1613 | + unset($reg_status_array[ EEM_Registration::status_id_incomplete ]); |
|
| 1614 | + // get current reg status |
|
| 1615 | + $current_status = $this->_registration->status_ID(); |
|
| 1616 | + // is registration for free event? This will determine whether to display the pending payment option |
|
| 1617 | + if ( |
|
| 1618 | + $current_status !== EEM_Registration::status_id_pending_payment |
|
| 1619 | + && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00) |
|
| 1620 | + ) { |
|
| 1621 | + unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]); |
|
| 1622 | + } |
|
| 1623 | + return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + |
|
| 1627 | + /** |
|
| 1628 | + * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1629 | + * |
|
| 1630 | + * @param bool $status REG status given for changing registrations to. |
|
| 1631 | + * @param bool $notify Whether to send messages notifications or not. |
|
| 1632 | + * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1633 | + * @throws DomainException |
|
| 1634 | + * @throws EE_Error |
|
| 1635 | + * @throws EntityNotFoundException |
|
| 1636 | + * @throws InvalidArgumentException |
|
| 1637 | + * @throws InvalidDataTypeException |
|
| 1638 | + * @throws InvalidInterfaceException |
|
| 1639 | + * @throws ReflectionException |
|
| 1640 | + * @throws RuntimeException |
|
| 1641 | + */ |
|
| 1642 | + protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1643 | + { |
|
| 1644 | + $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form') |
|
| 1645 | + ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true) |
|
| 1646 | + : $this->request->getRequestParam('_REG_ID', [], 'int', true); |
|
| 1647 | + |
|
| 1648 | + // sanitize $REG_IDs |
|
| 1649 | + $REG_IDs = array_map('absint', $REG_IDs); |
|
| 1650 | + // and remove empty entries |
|
| 1651 | + $REG_IDs = array_filter($REG_IDs); |
|
| 1652 | + |
|
| 1653 | + $result = $this->_set_registration_status($REG_IDs, $status, $notify); |
|
| 1654 | + |
|
| 1655 | + /** |
|
| 1656 | + * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications. |
|
| 1657 | + * Currently this value is used downstream by the _process_resend_registration method. |
|
| 1658 | + * |
|
| 1659 | + * @param int|array $registration_ids The registration ids that have had their status changed successfully. |
|
| 1660 | + * @param bool $status The status registrations were changed to. |
|
| 1661 | + * @param bool $success If the status was changed successfully for all registrations. |
|
| 1662 | + * @param Registrations_Admin_Page $admin_page_object |
|
| 1663 | + */ |
|
| 1664 | + $REG_ID = apply_filters( |
|
| 1665 | + 'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs', |
|
| 1666 | + $result['REG_ID'], |
|
| 1667 | + $status, |
|
| 1668 | + $result['success'], |
|
| 1669 | + $this |
|
| 1670 | + ); |
|
| 1671 | + $this->request->setRequestParam('_REG_ID', $REG_ID); |
|
| 1672 | + |
|
| 1673 | + // notify? |
|
| 1674 | + if ( |
|
| 1675 | + $notify |
|
| 1676 | + && $result['success'] |
|
| 1677 | + && ! empty($REG_ID) |
|
| 1678 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1679 | + 'ee_send_message', |
|
| 1680 | + 'espresso_registrations_resend_registration' |
|
| 1681 | + ) |
|
| 1682 | + ) { |
|
| 1683 | + $this->_process_resend_registration(); |
|
| 1684 | + } |
|
| 1685 | + return $result; |
|
| 1686 | + } |
|
| 1687 | + |
|
| 1688 | + |
|
| 1689 | + /** |
|
| 1690 | + * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1691 | + * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1692 | + * |
|
| 1693 | + * @param array $REG_IDs |
|
| 1694 | + * @param string $status |
|
| 1695 | + * @param bool $notify Used to indicate whether notification was requested or not. This determines the context |
|
| 1696 | + * slug sent with setting the registration status. |
|
| 1697 | + * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1698 | + * @throws EE_Error |
|
| 1699 | + * @throws InvalidArgumentException |
|
| 1700 | + * @throws InvalidDataTypeException |
|
| 1701 | + * @throws InvalidInterfaceException |
|
| 1702 | + * @throws ReflectionException |
|
| 1703 | + * @throws RuntimeException |
|
| 1704 | + * @throws EntityNotFoundException |
|
| 1705 | + * @throws DomainException |
|
| 1706 | + */ |
|
| 1707 | + protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false) |
|
| 1708 | + { |
|
| 1709 | + $success = false; |
|
| 1710 | + // typecast $REG_IDs |
|
| 1711 | + $REG_IDs = (array) $REG_IDs; |
|
| 1712 | + if (! empty($REG_IDs)) { |
|
| 1713 | + $success = true; |
|
| 1714 | + // set default status if none is passed |
|
| 1715 | + $status = $status ?: EEM_Registration::status_id_pending_payment; |
|
| 1716 | + $status_context = $notify |
|
| 1717 | + ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
| 1718 | + : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN; |
|
| 1719 | + // loop through REG_ID's and change status |
|
| 1720 | + foreach ($REG_IDs as $REG_ID) { |
|
| 1721 | + $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID); |
|
| 1722 | + if ($registration instanceof EE_Registration) { |
|
| 1723 | + $registration->set_status( |
|
| 1724 | + $status, |
|
| 1725 | + false, |
|
| 1726 | + new Context( |
|
| 1727 | + $status_context, |
|
| 1728 | + esc_html__( |
|
| 1729 | + 'Manually triggered status change on a Registration Admin Page route.', |
|
| 1730 | + 'event_espresso' |
|
| 1731 | + ) |
|
| 1732 | + ) |
|
| 1733 | + ); |
|
| 1734 | + $result = $registration->save(); |
|
| 1735 | + // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1736 | + $success = $result !== false ? $success : false; |
|
| 1737 | + } |
|
| 1738 | + } |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + // return $success and processed registrations |
|
| 1742 | + return ['REG_ID' => $REG_IDs, 'success' => $success]; |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + |
|
| 1746 | + /** |
|
| 1747 | + * Common logic for setting up success message and redirecting to appropriate route |
|
| 1748 | + * |
|
| 1749 | + * @param string $STS_ID status id for the registration changed to |
|
| 1750 | + * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1751 | + * @return void |
|
| 1752 | + * @throws DomainException |
|
| 1753 | + * @throws EE_Error |
|
| 1754 | + * @throws EntityNotFoundException |
|
| 1755 | + * @throws InvalidArgumentException |
|
| 1756 | + * @throws InvalidDataTypeException |
|
| 1757 | + * @throws InvalidInterfaceException |
|
| 1758 | + * @throws ReflectionException |
|
| 1759 | + * @throws RuntimeException |
|
| 1760 | + */ |
|
| 1761 | + protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1762 | + { |
|
| 1763 | + $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1764 | + : ['success' => false]; |
|
| 1765 | + $success = isset($result['success']) && $result['success']; |
|
| 1766 | + // setup success message |
|
| 1767 | + if ($success) { |
|
| 1768 | + if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1769 | + $msg = sprintf( |
|
| 1770 | + esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
| 1771 | + EEH_Template::pretty_status($STS_ID, false, 'lower') |
|
| 1772 | + ); |
|
| 1773 | + } else { |
|
| 1774 | + $msg = sprintf( |
|
| 1775 | + esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1776 | + EEH_Template::pretty_status($STS_ID, false, 'lower') |
|
| 1777 | + ); |
|
| 1778 | + } |
|
| 1779 | + EE_Error::add_success($msg); |
|
| 1780 | + } else { |
|
| 1781 | + EE_Error::add_error( |
|
| 1782 | + esc_html__( |
|
| 1783 | + 'Something went wrong, and the status was not changed', |
|
| 1784 | + 'event_espresso' |
|
| 1785 | + ), |
|
| 1786 | + __FILE__, |
|
| 1787 | + __LINE__, |
|
| 1788 | + __FUNCTION__ |
|
| 1789 | + ); |
|
| 1790 | + } |
|
| 1791 | + $return = $this->request->getRequestParam('return'); |
|
| 1792 | + $route = $return === 'view_registration' |
|
| 1793 | + ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])] |
|
| 1794 | + : ['action' => 'default']; |
|
| 1795 | + $route = $this->mergeExistingRequestParamsWithRedirectArgs($route); |
|
| 1796 | + $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * incoming reg status change from reg details page. |
|
| 1802 | + * |
|
| 1803 | + * @return void |
|
| 1804 | + * @throws EE_Error |
|
| 1805 | + * @throws EntityNotFoundException |
|
| 1806 | + * @throws InvalidArgumentException |
|
| 1807 | + * @throws InvalidDataTypeException |
|
| 1808 | + * @throws InvalidInterfaceException |
|
| 1809 | + * @throws ReflectionException |
|
| 1810 | + * @throws RuntimeException |
|
| 1811 | + * @throws DomainException |
|
| 1812 | + */ |
|
| 1813 | + protected function _change_reg_status() |
|
| 1814 | + { |
|
| 1815 | + $this->request->setRequestParam('return', 'view_registration'); |
|
| 1816 | + // set notify based on whether the send notifications toggle is set or not |
|
| 1817 | + $notify = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool'); |
|
| 1818 | + $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', ''); |
|
| 1819 | + $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status); |
|
| 1820 | + switch ($reg_status) { |
|
| 1821 | + case EEM_Registration::status_id_approved: |
|
| 1822 | + case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'): |
|
| 1823 | + $this->approve_registration($notify); |
|
| 1824 | + break; |
|
| 1825 | + case EEM_Registration::status_id_pending_payment: |
|
| 1826 | + case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'): |
|
| 1827 | + $this->pending_registration($notify); |
|
| 1828 | + break; |
|
| 1829 | + case EEM_Registration::status_id_not_approved: |
|
| 1830 | + case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'): |
|
| 1831 | + $this->not_approve_registration($notify); |
|
| 1832 | + break; |
|
| 1833 | + case EEM_Registration::status_id_declined: |
|
| 1834 | + case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'): |
|
| 1835 | + $this->decline_registration($notify); |
|
| 1836 | + break; |
|
| 1837 | + case EEM_Registration::status_id_cancelled: |
|
| 1838 | + case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'): |
|
| 1839 | + $this->cancel_registration($notify); |
|
| 1840 | + break; |
|
| 1841 | + case EEM_Registration::status_id_wait_list: |
|
| 1842 | + case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'): |
|
| 1843 | + $this->wait_list_registration($notify); |
|
| 1844 | + break; |
|
| 1845 | + case EEM_Registration::status_id_incomplete: |
|
| 1846 | + default: |
|
| 1847 | + $this->request->unSetRequestParam('return'); |
|
| 1848 | + $this->_reg_status_change_return(''); |
|
| 1849 | + break; |
|
| 1850 | + } |
|
| 1851 | + } |
|
| 1852 | + |
|
| 1853 | + |
|
| 1854 | + /** |
|
| 1855 | + * Callback for bulk action routes. |
|
| 1856 | + * Note: although we could just register the singular route callbacks for each bulk action route as well, this |
|
| 1857 | + * method was chosen so there is one central place all the registration status bulk actions are going through. |
|
| 1858 | + * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to |
|
| 1859 | + * when an action is happening on just a single registration). |
|
| 1860 | + * |
|
| 1861 | + * @param $action |
|
| 1862 | + * @param bool $notify |
|
| 1863 | + */ |
|
| 1864 | + protected function bulk_action_on_registrations($action, $notify = false) |
|
| 1865 | + { |
|
| 1866 | + do_action( |
|
| 1867 | + 'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution', |
|
| 1868 | + $this, |
|
| 1869 | + $action, |
|
| 1870 | + $notify |
|
| 1871 | + ); |
|
| 1872 | + $method = $action . '_registration'; |
|
| 1873 | + if (method_exists($this, $method)) { |
|
| 1874 | + $this->$method($notify); |
|
| 1875 | + } |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + /** |
|
| 1880 | + * approve_registration |
|
| 1881 | + * |
|
| 1882 | + * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1883 | + * @return void |
|
| 1884 | + * @throws EE_Error |
|
| 1885 | + * @throws EntityNotFoundException |
|
| 1886 | + * @throws InvalidArgumentException |
|
| 1887 | + * @throws InvalidDataTypeException |
|
| 1888 | + * @throws InvalidInterfaceException |
|
| 1889 | + * @throws ReflectionException |
|
| 1890 | + * @throws RuntimeException |
|
| 1891 | + * @throws DomainException |
|
| 1892 | + */ |
|
| 1893 | + protected function approve_registration($notify = false) |
|
| 1894 | + { |
|
| 1895 | + $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + |
|
| 1899 | + /** |
|
| 1900 | + * decline_registration |
|
| 1901 | + * |
|
| 1902 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1903 | + * @return void |
|
| 1904 | + * @throws EE_Error |
|
| 1905 | + * @throws EntityNotFoundException |
|
| 1906 | + * @throws InvalidArgumentException |
|
| 1907 | + * @throws InvalidDataTypeException |
|
| 1908 | + * @throws InvalidInterfaceException |
|
| 1909 | + * @throws ReflectionException |
|
| 1910 | + * @throws RuntimeException |
|
| 1911 | + * @throws DomainException |
|
| 1912 | + */ |
|
| 1913 | + protected function decline_registration($notify = false) |
|
| 1914 | + { |
|
| 1915 | + $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1916 | + } |
|
| 1917 | + |
|
| 1918 | + |
|
| 1919 | + /** |
|
| 1920 | + * cancel_registration |
|
| 1921 | + * |
|
| 1922 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1923 | + * @return void |
|
| 1924 | + * @throws EE_Error |
|
| 1925 | + * @throws EntityNotFoundException |
|
| 1926 | + * @throws InvalidArgumentException |
|
| 1927 | + * @throws InvalidDataTypeException |
|
| 1928 | + * @throws InvalidInterfaceException |
|
| 1929 | + * @throws ReflectionException |
|
| 1930 | + * @throws RuntimeException |
|
| 1931 | + * @throws DomainException |
|
| 1932 | + */ |
|
| 1933 | + protected function cancel_registration($notify = false) |
|
| 1934 | + { |
|
| 1935 | + $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + |
|
| 1939 | + /** |
|
| 1940 | + * not_approve_registration |
|
| 1941 | + * |
|
| 1942 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1943 | + * @return void |
|
| 1944 | + * @throws EE_Error |
|
| 1945 | + * @throws EntityNotFoundException |
|
| 1946 | + * @throws InvalidArgumentException |
|
| 1947 | + * @throws InvalidDataTypeException |
|
| 1948 | + * @throws InvalidInterfaceException |
|
| 1949 | + * @throws ReflectionException |
|
| 1950 | + * @throws RuntimeException |
|
| 1951 | + * @throws DomainException |
|
| 1952 | + */ |
|
| 1953 | + protected function not_approve_registration($notify = false) |
|
| 1954 | + { |
|
| 1955 | + $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + |
|
| 1959 | + /** |
|
| 1960 | + * decline_registration |
|
| 1961 | + * |
|
| 1962 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1963 | + * @return void |
|
| 1964 | + * @throws EE_Error |
|
| 1965 | + * @throws EntityNotFoundException |
|
| 1966 | + * @throws InvalidArgumentException |
|
| 1967 | + * @throws InvalidDataTypeException |
|
| 1968 | + * @throws InvalidInterfaceException |
|
| 1969 | + * @throws ReflectionException |
|
| 1970 | + * @throws RuntimeException |
|
| 1971 | + * @throws DomainException |
|
| 1972 | + */ |
|
| 1973 | + protected function pending_registration($notify = false) |
|
| 1974 | + { |
|
| 1975 | + $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 1976 | + } |
|
| 1977 | + |
|
| 1978 | + |
|
| 1979 | + /** |
|
| 1980 | + * waitlist_registration |
|
| 1981 | + * |
|
| 1982 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1983 | + * @return void |
|
| 1984 | + * @throws EE_Error |
|
| 1985 | + * @throws EntityNotFoundException |
|
| 1986 | + * @throws InvalidArgumentException |
|
| 1987 | + * @throws InvalidDataTypeException |
|
| 1988 | + * @throws InvalidInterfaceException |
|
| 1989 | + * @throws ReflectionException |
|
| 1990 | + * @throws RuntimeException |
|
| 1991 | + * @throws DomainException |
|
| 1992 | + */ |
|
| 1993 | + protected function wait_list_registration($notify = false) |
|
| 1994 | + { |
|
| 1995 | + $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 1996 | + } |
|
| 1997 | + |
|
| 1998 | + |
|
| 1999 | + /** |
|
| 2000 | + * generates HTML for the Registration main meta box |
|
| 2001 | + * |
|
| 2002 | + * @return void |
|
| 2003 | + * @throws DomainException |
|
| 2004 | + * @throws EE_Error |
|
| 2005 | + * @throws InvalidArgumentException |
|
| 2006 | + * @throws InvalidDataTypeException |
|
| 2007 | + * @throws InvalidInterfaceException |
|
| 2008 | + * @throws ReflectionException |
|
| 2009 | + * @throws EntityNotFoundException |
|
| 2010 | + */ |
|
| 2011 | + public function _reg_details_meta_box() |
|
| 2012 | + { |
|
| 2013 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 2014 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 2015 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 2016 | + $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 2017 | + : EE_Transaction::new_instance(); |
|
| 2018 | + $this->_session = $transaction->session_data(); |
|
| 2019 | + $filters = new EE_Line_Item_Filter_Collection(); |
|
| 2020 | + $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 2021 | + $filters->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 2022 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 2023 | + $filters, |
|
| 2024 | + $transaction->total_line_item() |
|
| 2025 | + ); |
|
| 2026 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 2027 | + $line_item_display = new EE_Line_Item_Display( |
|
| 2028 | + 'reg_admin_table', |
|
| 2029 | + 'EE_Admin_Table_Registration_Line_Item_Display_Strategy' |
|
| 2030 | + ); |
|
| 2031 | + $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
| 2032 | + $filtered_line_item_tree, |
|
| 2033 | + ['EE_Registration' => $this->_registration] |
|
| 2034 | + ); |
|
| 2035 | + $attendee = $this->_registration->attendee(); |
|
| 2036 | + if ( |
|
| 2037 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 2038 | + 'ee_read_transaction', |
|
| 2039 | + 'espresso_transactions_view_transaction' |
|
| 2040 | + ) |
|
| 2041 | + ) { |
|
| 2042 | + $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
| 2043 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2044 | + [ |
|
| 2045 | + 'action' => 'view_transaction', |
|
| 2046 | + 'TXN_ID' => $transaction->ID(), |
|
| 2047 | + ], |
|
| 2048 | + TXN_ADMIN_URL |
|
| 2049 | + ), |
|
| 2050 | + esc_html__(' View Transaction', 'event_espresso'), |
|
| 2051 | + 'button button--secondary right', |
|
| 2052 | + 'dashicons dashicons-cart' |
|
| 2053 | + ); |
|
| 2054 | + } else { |
|
| 2055 | + $this->_template_args['view_transaction_button'] = ''; |
|
| 2056 | + } |
|
| 2057 | + if ( |
|
| 2058 | + $attendee instanceof EE_Attendee |
|
| 2059 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 2060 | + 'ee_send_message', |
|
| 2061 | + 'espresso_registrations_resend_registration' |
|
| 2062 | + ) |
|
| 2063 | + ) { |
|
| 2064 | + $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
| 2065 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2066 | + [ |
|
| 2067 | + 'action' => 'resend_registration', |
|
| 2068 | + '_REG_ID' => $this->_registration->ID(), |
|
| 2069 | + 'redirect_to' => 'view_registration', |
|
| 2070 | + ], |
|
| 2071 | + REG_ADMIN_URL |
|
| 2072 | + ), |
|
| 2073 | + esc_html__(' Resend Registration', 'event_espresso'), |
|
| 2074 | + 'button button--secondary right', |
|
| 2075 | + 'dashicons dashicons-email-alt' |
|
| 2076 | + ); |
|
| 2077 | + } else { |
|
| 2078 | + $this->_template_args['resend_registration_button'] = ''; |
|
| 2079 | + } |
|
| 2080 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2081 | + $payment = $transaction->get_first_related('Payment'); |
|
| 2082 | + $payment = ! $payment instanceof EE_Payment |
|
| 2083 | + ? EE_Payment::new_instance() |
|
| 2084 | + : $payment; |
|
| 2085 | + $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 2086 | + $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
| 2087 | + ? EE_Payment_Method::new_instance() |
|
| 2088 | + : $payment_method; |
|
| 2089 | + $reg_details = [ |
|
| 2090 | + 'payment_method' => $payment_method->name(), |
|
| 2091 | + 'response_msg' => $payment->gateway_response(), |
|
| 2092 | + 'registration_id' => $this->_registration->get('REG_code'), |
|
| 2093 | + 'registration_session' => $this->_registration->session_ID(), |
|
| 2094 | + 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 2095 | + 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 2096 | + ]; |
|
| 2097 | + if (isset($reg_details['registration_id'])) { |
|
| 2098 | + $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 2099 | + $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
| 2100 | + 'Registration ID', |
|
| 2101 | + 'event_espresso' |
|
| 2102 | + ); |
|
| 2103 | + $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 2104 | + } |
|
| 2105 | + if (isset($reg_details['payment_method'])) { |
|
| 2106 | + $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 2107 | + $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
| 2108 | + 'Most Recent Payment Method', |
|
| 2109 | + 'event_espresso' |
|
| 2110 | + ); |
|
| 2111 | + $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 2112 | + $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 2113 | + $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
| 2114 | + 'Payment method response', |
|
| 2115 | + 'event_espresso' |
|
| 2116 | + ); |
|
| 2117 | + $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2118 | + } |
|
| 2119 | + $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 2120 | + $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
| 2121 | + 'Registration Session', |
|
| 2122 | + 'event_espresso' |
|
| 2123 | + ); |
|
| 2124 | + $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 2125 | + $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 2126 | + $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
| 2127 | + 'Registration placed from IP', |
|
| 2128 | + 'event_espresso' |
|
| 2129 | + ); |
|
| 2130 | + $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 2131 | + $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 2132 | + $this->_template_args['reg_details']['user_agent']['label'] = esc_html__( |
|
| 2133 | + 'Registrant User Agent', |
|
| 2134 | + 'event_espresso' |
|
| 2135 | + ); |
|
| 2136 | + $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 2137 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2138 | + [ |
|
| 2139 | + 'action' => 'default', |
|
| 2140 | + 'event_id' => $this->_registration->event_ID(), |
|
| 2141 | + ], |
|
| 2142 | + REG_ADMIN_URL |
|
| 2143 | + ); |
|
| 2144 | + |
|
| 2145 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2146 | + $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 2147 | + |
|
| 2148 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2149 | + EEH_Template::display_template($template_path, $this->_template_args); // already escaped |
|
| 2150 | + } |
|
| 2151 | + |
|
| 2152 | + |
|
| 2153 | + /** |
|
| 2154 | + * generates HTML for the Registration Questions meta box. |
|
| 2155 | + * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 2156 | + * otherwise uses new forms system |
|
| 2157 | + * |
|
| 2158 | + * @return void |
|
| 2159 | + * @throws DomainException |
|
| 2160 | + * @throws EE_Error |
|
| 2161 | + * @throws InvalidArgumentException |
|
| 2162 | + * @throws InvalidDataTypeException |
|
| 2163 | + * @throws InvalidInterfaceException |
|
| 2164 | + * @throws ReflectionException |
|
| 2165 | + */ |
|
| 2166 | + public function _reg_questions_meta_box() |
|
| 2167 | + { |
|
| 2168 | + // allow someone to override this method entirely |
|
| 2169 | + if ( |
|
| 2170 | + apply_filters( |
|
| 2171 | + 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', |
|
| 2172 | + true, |
|
| 2173 | + $this, |
|
| 2174 | + $this->_registration |
|
| 2175 | + ) |
|
| 2176 | + ) { |
|
| 2177 | + $form = $this->_get_reg_custom_questions_form( |
|
| 2178 | + $this->_registration->ID() |
|
| 2179 | + ); |
|
| 2180 | + |
|
| 2181 | + $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
| 2182 | + ? $form->get_html_and_js() |
|
| 2183 | + : ''; |
|
| 2184 | + |
|
| 2185 | + $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 2186 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2187 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2188 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2189 | + } |
|
| 2190 | + } |
|
| 2191 | + |
|
| 2192 | + |
|
| 2193 | + /** |
|
| 2194 | + * form_before_question_group |
|
| 2195 | + * |
|
| 2196 | + * @param string $output |
|
| 2197 | + * @return string |
|
| 2198 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2199 | + */ |
|
| 2200 | + public function form_before_question_group($output) |
|
| 2201 | + { |
|
| 2202 | + EE_Error::doing_it_wrong( |
|
| 2203 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2204 | + esc_html__( |
|
| 2205 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2206 | + 'event_espresso' |
|
| 2207 | + ), |
|
| 2208 | + '4.8.32.rc.000' |
|
| 2209 | + ); |
|
| 2210 | + return ' |
|
| 2211 | 2211 | <table class="form-table ee-width-100"> |
| 2212 | 2212 | <tbody> |
| 2213 | 2213 | '; |
| 2214 | - } |
|
| 2215 | - |
|
| 2216 | - |
|
| 2217 | - /** |
|
| 2218 | - * form_after_question_group |
|
| 2219 | - * |
|
| 2220 | - * @param string $output |
|
| 2221 | - * @return string |
|
| 2222 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2223 | - */ |
|
| 2224 | - public function form_after_question_group($output) |
|
| 2225 | - { |
|
| 2226 | - EE_Error::doing_it_wrong( |
|
| 2227 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2228 | - esc_html__( |
|
| 2229 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2230 | - 'event_espresso' |
|
| 2231 | - ), |
|
| 2232 | - '4.8.32.rc.000' |
|
| 2233 | - ); |
|
| 2234 | - return ' |
|
| 2214 | + } |
|
| 2215 | + |
|
| 2216 | + |
|
| 2217 | + /** |
|
| 2218 | + * form_after_question_group |
|
| 2219 | + * |
|
| 2220 | + * @param string $output |
|
| 2221 | + * @return string |
|
| 2222 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2223 | + */ |
|
| 2224 | + public function form_after_question_group($output) |
|
| 2225 | + { |
|
| 2226 | + EE_Error::doing_it_wrong( |
|
| 2227 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2228 | + esc_html__( |
|
| 2229 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2230 | + 'event_espresso' |
|
| 2231 | + ), |
|
| 2232 | + '4.8.32.rc.000' |
|
| 2233 | + ); |
|
| 2234 | + return ' |
|
| 2235 | 2235 | <tr class="hide-if-no-js"> |
| 2236 | 2236 | <th> </th> |
| 2237 | 2237 | <td class="reg-admin-edit-attendee-question-td"> |
| 2238 | 2238 | <a class="reg-admin-edit-attendee-question-lnk" href="#" title="' |
| 2239 | - . esc_attr__('click to edit question', 'event_espresso') |
|
| 2240 | - . '"> |
|
| 2239 | + . esc_attr__('click to edit question', 'event_espresso') |
|
| 2240 | + . '"> |
|
| 2241 | 2241 | <span class="reg-admin-edit-question-group-spn lt-grey-txt">' |
| 2242 | - . esc_html__('edit the above question group', 'event_espresso') |
|
| 2243 | - . '</span> |
|
| 2242 | + . esc_html__('edit the above question group', 'event_espresso') |
|
| 2243 | + . '</span> |
|
| 2244 | 2244 | <div class="dashicons dashicons-edit"></div> |
| 2245 | 2245 | </a> |
| 2246 | 2246 | </td> |
@@ -2248,636 +2248,636 @@ discard block |
||
| 2248 | 2248 | </tbody> |
| 2249 | 2249 | </table> |
| 2250 | 2250 | '; |
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - |
|
| 2254 | - /** |
|
| 2255 | - * form_form_field_label_wrap |
|
| 2256 | - * |
|
| 2257 | - * @param string $label |
|
| 2258 | - * @return string |
|
| 2259 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2260 | - */ |
|
| 2261 | - public function form_form_field_label_wrap($label) |
|
| 2262 | - { |
|
| 2263 | - EE_Error::doing_it_wrong( |
|
| 2264 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2265 | - esc_html__( |
|
| 2266 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2267 | - 'event_espresso' |
|
| 2268 | - ), |
|
| 2269 | - '4.8.32.rc.000' |
|
| 2270 | - ); |
|
| 2271 | - return ' |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + |
|
| 2254 | + /** |
|
| 2255 | + * form_form_field_label_wrap |
|
| 2256 | + * |
|
| 2257 | + * @param string $label |
|
| 2258 | + * @return string |
|
| 2259 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2260 | + */ |
|
| 2261 | + public function form_form_field_label_wrap($label) |
|
| 2262 | + { |
|
| 2263 | + EE_Error::doing_it_wrong( |
|
| 2264 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2265 | + esc_html__( |
|
| 2266 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2267 | + 'event_espresso' |
|
| 2268 | + ), |
|
| 2269 | + '4.8.32.rc.000' |
|
| 2270 | + ); |
|
| 2271 | + return ' |
|
| 2272 | 2272 | <tr> |
| 2273 | 2273 | <th> |
| 2274 | 2274 | ' . $label . ' |
| 2275 | 2275 | </th>'; |
| 2276 | - } |
|
| 2277 | - |
|
| 2278 | - |
|
| 2279 | - /** |
|
| 2280 | - * form_form_field_input__wrap |
|
| 2281 | - * |
|
| 2282 | - * @param string $input |
|
| 2283 | - * @return string |
|
| 2284 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2285 | - */ |
|
| 2286 | - public function form_form_field_input__wrap($input) |
|
| 2287 | - { |
|
| 2288 | - EE_Error::doing_it_wrong( |
|
| 2289 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2290 | - esc_html__( |
|
| 2291 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2292 | - 'event_espresso' |
|
| 2293 | - ), |
|
| 2294 | - '4.8.32.rc.000' |
|
| 2295 | - ); |
|
| 2296 | - return ' |
|
| 2276 | + } |
|
| 2277 | + |
|
| 2278 | + |
|
| 2279 | + /** |
|
| 2280 | + * form_form_field_input__wrap |
|
| 2281 | + * |
|
| 2282 | + * @param string $input |
|
| 2283 | + * @return string |
|
| 2284 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2285 | + */ |
|
| 2286 | + public function form_form_field_input__wrap($input) |
|
| 2287 | + { |
|
| 2288 | + EE_Error::doing_it_wrong( |
|
| 2289 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2290 | + esc_html__( |
|
| 2291 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2292 | + 'event_espresso' |
|
| 2293 | + ), |
|
| 2294 | + '4.8.32.rc.000' |
|
| 2295 | + ); |
|
| 2296 | + return ' |
|
| 2297 | 2297 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
| 2298 | 2298 | ' . $input . ' |
| 2299 | 2299 | </td> |
| 2300 | 2300 | </tr>'; |
| 2301 | - } |
|
| 2302 | - |
|
| 2303 | - |
|
| 2304 | - /** |
|
| 2305 | - * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 2306 | - * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 2307 | - * to display the page |
|
| 2308 | - * |
|
| 2309 | - * @return void |
|
| 2310 | - * @throws EE_Error |
|
| 2311 | - * @throws InvalidArgumentException |
|
| 2312 | - * @throws InvalidDataTypeException |
|
| 2313 | - * @throws InvalidInterfaceException |
|
| 2314 | - * @throws ReflectionException |
|
| 2315 | - */ |
|
| 2316 | - protected function _update_attendee_registration_form() |
|
| 2317 | - { |
|
| 2318 | - do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 2319 | - if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 2320 | - $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 2321 | - $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 2322 | - if ($success) { |
|
| 2323 | - $what = esc_html__('Registration Form', 'event_espresso'); |
|
| 2324 | - $route = $REG_ID |
|
| 2325 | - ? ['action' => 'view_registration', '_REG_ID' => $REG_ID] |
|
| 2326 | - : ['action' => 'default']; |
|
| 2327 | - $this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route); |
|
| 2328 | - } |
|
| 2329 | - } |
|
| 2330 | - } |
|
| 2331 | - |
|
| 2332 | - |
|
| 2333 | - /** |
|
| 2334 | - * Gets the form for saving registrations custom questions (if done |
|
| 2335 | - * previously retrieves the cached form object, which may have validation errors in it) |
|
| 2336 | - * |
|
| 2337 | - * @param int $REG_ID |
|
| 2338 | - * @return EE_Registration_Custom_Questions_Form |
|
| 2339 | - * @throws EE_Error |
|
| 2340 | - * @throws InvalidArgumentException |
|
| 2341 | - * @throws InvalidDataTypeException |
|
| 2342 | - * @throws InvalidInterfaceException |
|
| 2343 | - * @throws ReflectionException |
|
| 2344 | - */ |
|
| 2345 | - protected function _get_reg_custom_questions_form($REG_ID) |
|
| 2346 | - { |
|
| 2347 | - if (! $this->_reg_custom_questions_form) { |
|
| 2348 | - require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2349 | - $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 2350 | - $this->getRegistrationModel()->get_one_by_ID($REG_ID) |
|
| 2351 | - ); |
|
| 2352 | - $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 2353 | - } |
|
| 2354 | - return $this->_reg_custom_questions_form; |
|
| 2355 | - } |
|
| 2356 | - |
|
| 2357 | - |
|
| 2358 | - /** |
|
| 2359 | - * Saves |
|
| 2360 | - * |
|
| 2361 | - * @param bool $REG_ID |
|
| 2362 | - * @return bool |
|
| 2363 | - * @throws EE_Error |
|
| 2364 | - * @throws InvalidArgumentException |
|
| 2365 | - * @throws InvalidDataTypeException |
|
| 2366 | - * @throws InvalidInterfaceException |
|
| 2367 | - * @throws ReflectionException |
|
| 2368 | - */ |
|
| 2369 | - private function _save_reg_custom_questions_form($REG_ID = 0) |
|
| 2370 | - { |
|
| 2371 | - if (! $REG_ID) { |
|
| 2372 | - EE_Error::add_error( |
|
| 2373 | - esc_html__( |
|
| 2374 | - 'An error occurred. No registration ID was received.', |
|
| 2375 | - 'event_espresso' |
|
| 2376 | - ), |
|
| 2377 | - __FILE__, |
|
| 2378 | - __FUNCTION__, |
|
| 2379 | - __LINE__ |
|
| 2380 | - ); |
|
| 2381 | - } |
|
| 2382 | - $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 2383 | - $form->receive_form_submission($this->request->requestParams()); |
|
| 2384 | - $success = false; |
|
| 2385 | - if ($form->is_valid()) { |
|
| 2386 | - foreach ($form->subforms() as $question_group_form) { |
|
| 2387 | - foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 2388 | - $where_conditions = [ |
|
| 2389 | - 'QST_ID' => $question_id, |
|
| 2390 | - 'REG_ID' => $REG_ID, |
|
| 2391 | - ]; |
|
| 2392 | - $possibly_new_values = [ |
|
| 2393 | - 'ANS_value' => $input->normalized_value(), |
|
| 2394 | - ]; |
|
| 2395 | - $answer = EEM_Answer::instance()->get_one([$where_conditions]); |
|
| 2396 | - if ($answer instanceof EE_Answer) { |
|
| 2397 | - $success = $answer->save($possibly_new_values); |
|
| 2398 | - } else { |
|
| 2399 | - // insert it then |
|
| 2400 | - $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 2401 | - $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 2402 | - $success = $answer->save(); |
|
| 2403 | - } |
|
| 2404 | - } |
|
| 2405 | - } |
|
| 2406 | - } else { |
|
| 2407 | - EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2408 | - } |
|
| 2409 | - return $success; |
|
| 2410 | - } |
|
| 2411 | - |
|
| 2412 | - |
|
| 2413 | - /** |
|
| 2414 | - * generates HTML for the Registration main meta box |
|
| 2415 | - * |
|
| 2416 | - * @return void |
|
| 2417 | - * @throws DomainException |
|
| 2418 | - * @throws EE_Error |
|
| 2419 | - * @throws InvalidArgumentException |
|
| 2420 | - * @throws InvalidDataTypeException |
|
| 2421 | - * @throws InvalidInterfaceException |
|
| 2422 | - * @throws ReflectionException |
|
| 2423 | - */ |
|
| 2424 | - public function _reg_attendees_meta_box() |
|
| 2425 | - { |
|
| 2426 | - $REG = $this->getRegistrationModel(); |
|
| 2427 | - // get all other registrations on this transaction, and cache |
|
| 2428 | - // the attendees for them so we don't have to run another query using force_join |
|
| 2429 | - $registrations = $REG->get_all( |
|
| 2430 | - [ |
|
| 2431 | - [ |
|
| 2432 | - 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2433 | - 'REG_ID' => ['!=', $this->_registration->ID()], |
|
| 2434 | - ], |
|
| 2435 | - 'force_join' => ['Attendee'], |
|
| 2436 | - 'default_where_conditions' => 'other_models_only', |
|
| 2437 | - ] |
|
| 2438 | - ); |
|
| 2439 | - $this->_template_args['attendees'] = []; |
|
| 2440 | - $this->_template_args['attendee_notice'] = ''; |
|
| 2441 | - if ( |
|
| 2442 | - empty($registrations) |
|
| 2443 | - || (is_array($registrations) |
|
| 2444 | - && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2445 | - ) { |
|
| 2446 | - EE_Error::add_error( |
|
| 2447 | - esc_html__( |
|
| 2448 | - 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2449 | - 'event_espresso' |
|
| 2450 | - ), |
|
| 2451 | - __FILE__, |
|
| 2452 | - __FUNCTION__, |
|
| 2453 | - __LINE__ |
|
| 2454 | - ); |
|
| 2455 | - $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2456 | - } else { |
|
| 2457 | - $att_nmbr = 1; |
|
| 2458 | - foreach ($registrations as $registration) { |
|
| 2459 | - /* @var $registration EE_Registration */ |
|
| 2460 | - $attendee = $registration->attendee() |
|
| 2461 | - ? $registration->attendee() |
|
| 2462 | - : $this->getAttendeeModel()->create_default_object(); |
|
| 2463 | - $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID(); |
|
| 2464 | - $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname(); |
|
| 2465 | - $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname(); |
|
| 2466 | - $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email(); |
|
| 2467 | - $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price(); |
|
| 2468 | - $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode( |
|
| 2469 | - ', ', |
|
| 2470 | - $attendee->full_address_as_array() |
|
| 2471 | - ); |
|
| 2472 | - $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce( |
|
| 2473 | - [ |
|
| 2474 | - 'action' => 'edit_attendee', |
|
| 2475 | - 'post' => $attendee->ID(), |
|
| 2476 | - ], |
|
| 2477 | - REG_ADMIN_URL |
|
| 2478 | - ); |
|
| 2479 | - $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = |
|
| 2480 | - $registration->event_obj() instanceof EE_Event |
|
| 2481 | - ? $registration->event_obj()->name() |
|
| 2482 | - : ''; |
|
| 2483 | - $att_nmbr++; |
|
| 2484 | - } |
|
| 2485 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2486 | - } |
|
| 2487 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2488 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - /** |
|
| 2493 | - * generates HTML for the Edit Registration side meta box |
|
| 2494 | - * |
|
| 2495 | - * @return void |
|
| 2496 | - * @throws DomainException |
|
| 2497 | - * @throws EE_Error |
|
| 2498 | - * @throws InvalidArgumentException |
|
| 2499 | - * @throws InvalidDataTypeException |
|
| 2500 | - * @throws InvalidInterfaceException |
|
| 2501 | - * @throws ReflectionException |
|
| 2502 | - */ |
|
| 2503 | - public function _reg_registrant_side_meta_box() |
|
| 2504 | - { |
|
| 2505 | - /*@var $attendee EE_Attendee */ |
|
| 2506 | - $att_check = $this->_registration->attendee(); |
|
| 2507 | - $attendee = $att_check instanceof EE_Attendee |
|
| 2508 | - ? $att_check |
|
| 2509 | - : $this->getAttendeeModel()->create_default_object(); |
|
| 2510 | - // now let's determine if this is not the primary registration. If it isn't then we set the |
|
| 2511 | - // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
| 2512 | - // primary registration object (that way we know if we need to show create button or not) |
|
| 2513 | - if (! $this->_registration->is_primary_registrant()) { |
|
| 2514 | - $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2515 | - $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2516 | - : null; |
|
| 2517 | - if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2518 | - // in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
| 2519 | - // custom attendee object so let's not worry about the primary reg. |
|
| 2520 | - $primary_registration = null; |
|
| 2521 | - } |
|
| 2522 | - } else { |
|
| 2523 | - $primary_registration = null; |
|
| 2524 | - } |
|
| 2525 | - $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2526 | - $this->_template_args['fname'] = $attendee->fname(); |
|
| 2527 | - $this->_template_args['lname'] = $attendee->lname(); |
|
| 2528 | - $this->_template_args['email'] = $attendee->email(); |
|
| 2529 | - $this->_template_args['phone'] = $attendee->phone(); |
|
| 2530 | - $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2531 | - // edit link |
|
| 2532 | - $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2533 | - [ |
|
| 2534 | - 'action' => 'edit_attendee', |
|
| 2535 | - 'post' => $attendee->ID(), |
|
| 2536 | - ], |
|
| 2537 | - REG_ADMIN_URL |
|
| 2538 | - ); |
|
| 2539 | - $this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso'); |
|
| 2540 | - $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
| 2541 | - // create link |
|
| 2542 | - $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2543 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 2544 | - [ |
|
| 2545 | - 'action' => 'duplicate_attendee', |
|
| 2546 | - '_REG_ID' => $this->_registration->ID(), |
|
| 2547 | - ], |
|
| 2548 | - REG_ADMIN_URL |
|
| 2549 | - ) : ''; |
|
| 2550 | - $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
| 2551 | - $this->_template_args['att_check'] = $att_check; |
|
| 2552 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2553 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2554 | - } |
|
| 2555 | - |
|
| 2556 | - |
|
| 2557 | - /** |
|
| 2558 | - * trash or restore registrations |
|
| 2559 | - * |
|
| 2560 | - * @param boolean $trash whether to archive or restore |
|
| 2561 | - * @return void |
|
| 2562 | - * @throws EE_Error |
|
| 2563 | - * @throws InvalidArgumentException |
|
| 2564 | - * @throws InvalidDataTypeException |
|
| 2565 | - * @throws InvalidInterfaceException |
|
| 2566 | - * @throws RuntimeException |
|
| 2567 | - */ |
|
| 2568 | - protected function _trash_or_restore_registrations($trash = true) |
|
| 2569 | - { |
|
| 2570 | - // if empty _REG_ID then get out because there's nothing to do |
|
| 2571 | - $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true); |
|
| 2572 | - if (empty($REG_IDs)) { |
|
| 2573 | - EE_Error::add_error( |
|
| 2574 | - sprintf( |
|
| 2575 | - esc_html__( |
|
| 2576 | - 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2577 | - 'event_espresso' |
|
| 2578 | - ), |
|
| 2579 | - $trash ? 'trash' : 'restore' |
|
| 2580 | - ), |
|
| 2581 | - __FILE__, |
|
| 2582 | - __LINE__, |
|
| 2583 | - __FUNCTION__ |
|
| 2584 | - ); |
|
| 2585 | - $this->_redirect_after_action(false, '', '', [], true); |
|
| 2586 | - } |
|
| 2587 | - $success = 0; |
|
| 2588 | - $overwrite_msgs = false; |
|
| 2589 | - // Checkboxes |
|
| 2590 | - $reg_count = count($REG_IDs); |
|
| 2591 | - // cycle thru checkboxes |
|
| 2592 | - foreach ($REG_IDs as $REG_ID) { |
|
| 2593 | - /** @var EE_Registration $REG */ |
|
| 2594 | - $REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID); |
|
| 2595 | - $payments = $REG->registration_payments(); |
|
| 2596 | - if (! empty($payments)) { |
|
| 2597 | - $name = $REG->attendee() instanceof EE_Attendee |
|
| 2598 | - ? $REG->attendee()->full_name() |
|
| 2599 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 2600 | - $overwrite_msgs = true; |
|
| 2601 | - EE_Error::add_error( |
|
| 2602 | - sprintf( |
|
| 2603 | - esc_html__( |
|
| 2604 | - 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2605 | - 'event_espresso' |
|
| 2606 | - ), |
|
| 2607 | - $name |
|
| 2608 | - ), |
|
| 2609 | - __FILE__, |
|
| 2610 | - __FUNCTION__, |
|
| 2611 | - __LINE__ |
|
| 2612 | - ); |
|
| 2613 | - // can't trash this registration because it has payments. |
|
| 2614 | - continue; |
|
| 2615 | - } |
|
| 2616 | - $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2617 | - if ($updated) { |
|
| 2618 | - $success++; |
|
| 2619 | - } |
|
| 2620 | - } |
|
| 2621 | - $this->_redirect_after_action( |
|
| 2622 | - $success === $reg_count, // were ALL registrations affected? |
|
| 2623 | - $success > 1 |
|
| 2624 | - ? esc_html__('Registrations', 'event_espresso') |
|
| 2625 | - : esc_html__('Registration', 'event_espresso'), |
|
| 2626 | - $trash |
|
| 2627 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 2628 | - : esc_html__('restored', 'event_espresso'), |
|
| 2629 | - $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']), |
|
| 2630 | - $overwrite_msgs |
|
| 2631 | - ); |
|
| 2632 | - } |
|
| 2633 | - |
|
| 2634 | - |
|
| 2635 | - /** |
|
| 2636 | - * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2637 | - * registration but also. |
|
| 2638 | - * 1. Removing relations to EE_Attendee |
|
| 2639 | - * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2640 | - * ALSO trashed. |
|
| 2641 | - * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2642 | - * 4. Removing relationships between all tickets and the related registrations |
|
| 2643 | - * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2644 | - * 6. Deleting permanently any related Checkins. |
|
| 2645 | - * |
|
| 2646 | - * @return void |
|
| 2647 | - * @throws EE_Error |
|
| 2648 | - * @throws InvalidArgumentException |
|
| 2649 | - * @throws InvalidDataTypeException |
|
| 2650 | - * @throws InvalidInterfaceException |
|
| 2651 | - * @throws ReflectionException |
|
| 2652 | - */ |
|
| 2653 | - protected function _delete_registrations() |
|
| 2654 | - { |
|
| 2655 | - $REG_MDL = $this->getRegistrationModel(); |
|
| 2656 | - $success = 0; |
|
| 2657 | - // Checkboxes |
|
| 2658 | - $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true); |
|
| 2659 | - |
|
| 2660 | - if (! empty($REG_IDs)) { |
|
| 2661 | - // if array has more than one element than success message should be plural |
|
| 2662 | - $success = count($REG_IDs) > 1 ? 2 : 1; |
|
| 2663 | - // cycle thru checkboxes |
|
| 2664 | - foreach ($REG_IDs as $REG_ID) { |
|
| 2665 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2666 | - if (! $REG instanceof EE_Registration) { |
|
| 2667 | - continue; |
|
| 2668 | - } |
|
| 2669 | - $deleted = $this->_delete_registration($REG); |
|
| 2670 | - if (! $deleted) { |
|
| 2671 | - $success = 0; |
|
| 2672 | - } |
|
| 2673 | - } |
|
| 2674 | - } |
|
| 2675 | - |
|
| 2676 | - $what = $success > 1 |
|
| 2677 | - ? esc_html__('Registrations', 'event_espresso') |
|
| 2678 | - : esc_html__('Registration', 'event_espresso'); |
|
| 2679 | - $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
| 2680 | - $this->_redirect_after_action( |
|
| 2681 | - $success, |
|
| 2682 | - $what, |
|
| 2683 | - $action_desc, |
|
| 2684 | - $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']), |
|
| 2685 | - true |
|
| 2686 | - ); |
|
| 2687 | - } |
|
| 2688 | - |
|
| 2689 | - |
|
| 2690 | - /** |
|
| 2691 | - * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2692 | - * models get affected. |
|
| 2693 | - * |
|
| 2694 | - * @param EE_Registration $REG registration to be deleted permanently |
|
| 2695 | - * @return bool true = successful deletion, false = fail. |
|
| 2696 | - * @throws EE_Error |
|
| 2697 | - * @throws InvalidArgumentException |
|
| 2698 | - * @throws InvalidDataTypeException |
|
| 2699 | - * @throws InvalidInterfaceException |
|
| 2700 | - * @throws ReflectionException |
|
| 2701 | - */ |
|
| 2702 | - protected function _delete_registration(EE_Registration $REG) |
|
| 2703 | - { |
|
| 2704 | - // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
| 2705 | - // registrations on the transaction that are NOT trashed. |
|
| 2706 | - $TXN = $REG->get_first_related('Transaction'); |
|
| 2707 | - if (! $TXN instanceof EE_Transaction) { |
|
| 2708 | - EE_Error::add_error( |
|
| 2709 | - sprintf( |
|
| 2710 | - esc_html__( |
|
| 2711 | - 'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.', |
|
| 2712 | - 'event_espresso' |
|
| 2713 | - ), |
|
| 2714 | - $REG->id() |
|
| 2715 | - ), |
|
| 2716 | - __FILE__, |
|
| 2717 | - __FUNCTION__, |
|
| 2718 | - __LINE__ |
|
| 2719 | - ); |
|
| 2720 | - return false; |
|
| 2721 | - } |
|
| 2722 | - $REGS = $TXN->get_many_related('Registration'); |
|
| 2723 | - $all_trashed = true; |
|
| 2724 | - foreach ($REGS as $registration) { |
|
| 2725 | - if (! $registration->get('REG_deleted')) { |
|
| 2726 | - $all_trashed = false; |
|
| 2727 | - } |
|
| 2728 | - } |
|
| 2729 | - if (! $all_trashed) { |
|
| 2730 | - EE_Error::add_error( |
|
| 2731 | - esc_html__( |
|
| 2732 | - 'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2733 | - 'event_espresso' |
|
| 2734 | - ), |
|
| 2735 | - __FILE__, |
|
| 2736 | - __FUNCTION__, |
|
| 2737 | - __LINE__ |
|
| 2738 | - ); |
|
| 2739 | - return false; |
|
| 2740 | - } |
|
| 2741 | - // k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
| 2742 | - // separately from THIS one). |
|
| 2743 | - foreach ($REGS as $registration) { |
|
| 2744 | - // delete related answers |
|
| 2745 | - $registration->delete_related_permanently('Answer'); |
|
| 2746 | - // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2747 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 2748 | - if ($attendee instanceof EE_Attendee) { |
|
| 2749 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2750 | - } |
|
| 2751 | - // now remove relationships to tickets on this registration. |
|
| 2752 | - $registration->_remove_relations('Ticket'); |
|
| 2753 | - // now delete permanently the checkins related to this registration. |
|
| 2754 | - $registration->delete_related_permanently('Checkin'); |
|
| 2755 | - if ($registration->ID() === $REG->ID()) { |
|
| 2756 | - continue; |
|
| 2757 | - } //we don't want to delete permanently the existing registration just yet. |
|
| 2758 | - // remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2759 | - $registration->_remove_relations('Transaction'); |
|
| 2760 | - // delete permanently any related messages. |
|
| 2761 | - $registration->delete_related_permanently('Message'); |
|
| 2762 | - // now delete this registration permanently |
|
| 2763 | - $registration->delete_permanently(); |
|
| 2764 | - } |
|
| 2765 | - // now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
| 2766 | - // (the transaction and line items should be all that's left). |
|
| 2767 | - // delete the line items related to the transaction for this registration. |
|
| 2768 | - $TXN->delete_related_permanently('Line_Item'); |
|
| 2769 | - // we need to remove all the relationships on the transaction |
|
| 2770 | - $TXN->delete_related_permanently('Payment'); |
|
| 2771 | - $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2772 | - $TXN->delete_related_permanently('Message'); |
|
| 2773 | - // now we can delete this REG permanently (and the transaction of course) |
|
| 2774 | - $REG->delete_related_permanently('Transaction'); |
|
| 2775 | - return $REG->delete_permanently(); |
|
| 2776 | - } |
|
| 2777 | - |
|
| 2778 | - |
|
| 2779 | - /** |
|
| 2780 | - * generates HTML for the Register New Attendee Admin page |
|
| 2781 | - * |
|
| 2782 | - * @throws DomainException |
|
| 2783 | - * @throws EE_Error |
|
| 2784 | - * @throws InvalidArgumentException |
|
| 2785 | - * @throws InvalidDataTypeException |
|
| 2786 | - * @throws InvalidInterfaceException |
|
| 2787 | - * @throws ReflectionException |
|
| 2788 | - */ |
|
| 2789 | - public function new_registration() |
|
| 2790 | - { |
|
| 2791 | - if (! $this->_set_reg_event()) { |
|
| 2792 | - throw new EE_Error( |
|
| 2793 | - esc_html__( |
|
| 2794 | - 'Unable to continue with registering because there is no Event ID in the request', |
|
| 2795 | - 'event_espresso' |
|
| 2796 | - ) |
|
| 2797 | - ); |
|
| 2798 | - } |
|
| 2799 | - /** @var CurrentPage $current_page */ |
|
| 2800 | - $current_page = $this->loader->getShared(CurrentPage::class); |
|
| 2801 | - $current_page->setEspressoPage(true); |
|
| 2802 | - // gotta start with a clean slate if we're not coming here via ajax |
|
| 2803 | - if ( |
|
| 2804 | - ! $this->request->isAjax() |
|
| 2805 | - && ( |
|
| 2806 | - ! $this->request->requestParamIsSet('processing_registration') |
|
| 2807 | - || $this->request->requestParamIsSet('step_error') |
|
| 2808 | - ) |
|
| 2809 | - ) { |
|
| 2810 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2811 | - } |
|
| 2812 | - $this->_template_args['event_name'] = ''; |
|
| 2813 | - // event name |
|
| 2814 | - if ($this->_reg_event) { |
|
| 2815 | - $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2816 | - $edit_event_url = self::add_query_args_and_nonce( |
|
| 2817 | - [ |
|
| 2818 | - 'action' => 'edit', |
|
| 2819 | - 'post' => $this->_reg_event->ID(), |
|
| 2820 | - ], |
|
| 2821 | - EVENTS_ADMIN_URL |
|
| 2822 | - ); |
|
| 2823 | - $edit_event_lnk = '<a href="' |
|
| 2824 | - . $edit_event_url |
|
| 2825 | - . '" title="' |
|
| 2826 | - . esc_attr__('Edit ', 'event_espresso') |
|
| 2827 | - . $this->_reg_event->name() |
|
| 2828 | - . '">' |
|
| 2829 | - . esc_html__('Edit Event', 'event_espresso') |
|
| 2830 | - . '</a>'; |
|
| 2831 | - $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2832 | - . $edit_event_lnk |
|
| 2833 | - . '</span>'; |
|
| 2834 | - } |
|
| 2835 | - $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2836 | - if ($this->request->isAjax()) { |
|
| 2837 | - $this->_return_json(); |
|
| 2838 | - } |
|
| 2839 | - // grab header |
|
| 2840 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2841 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2842 | - $template_path, |
|
| 2843 | - $this->_template_args, |
|
| 2844 | - true |
|
| 2845 | - ); |
|
| 2846 | - // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2847 | - // the details template wrapper |
|
| 2848 | - $this->display_admin_page_with_sidebar(); |
|
| 2849 | - } |
|
| 2850 | - |
|
| 2851 | - |
|
| 2852 | - /** |
|
| 2853 | - * This returns the content for a registration step |
|
| 2854 | - * |
|
| 2855 | - * @return string html |
|
| 2856 | - * @throws DomainException |
|
| 2857 | - * @throws EE_Error |
|
| 2858 | - * @throws InvalidArgumentException |
|
| 2859 | - * @throws InvalidDataTypeException |
|
| 2860 | - * @throws InvalidInterfaceException |
|
| 2861 | - * @throws ReflectionException |
|
| 2862 | - */ |
|
| 2863 | - protected function _get_registration_step_content() |
|
| 2864 | - { |
|
| 2865 | - if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2866 | - $warning_msg = sprintf( |
|
| 2867 | - esc_html__( |
|
| 2868 | - '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
| 2869 | - 'event_espresso' |
|
| 2870 | - ), |
|
| 2871 | - '<br />', |
|
| 2872 | - '<h3 class="important-notice">', |
|
| 2873 | - '</h3>', |
|
| 2874 | - '<div class="float-right">', |
|
| 2875 | - '<span id="redirect_timer" class="important-notice">30</span>', |
|
| 2876 | - '</div>', |
|
| 2877 | - '<b>', |
|
| 2878 | - '</b>' |
|
| 2879 | - ); |
|
| 2880 | - return ' |
|
| 2301 | + } |
|
| 2302 | + |
|
| 2303 | + |
|
| 2304 | + /** |
|
| 2305 | + * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 2306 | + * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 2307 | + * to display the page |
|
| 2308 | + * |
|
| 2309 | + * @return void |
|
| 2310 | + * @throws EE_Error |
|
| 2311 | + * @throws InvalidArgumentException |
|
| 2312 | + * @throws InvalidDataTypeException |
|
| 2313 | + * @throws InvalidInterfaceException |
|
| 2314 | + * @throws ReflectionException |
|
| 2315 | + */ |
|
| 2316 | + protected function _update_attendee_registration_form() |
|
| 2317 | + { |
|
| 2318 | + do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 2319 | + if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 2320 | + $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 2321 | + $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 2322 | + if ($success) { |
|
| 2323 | + $what = esc_html__('Registration Form', 'event_espresso'); |
|
| 2324 | + $route = $REG_ID |
|
| 2325 | + ? ['action' => 'view_registration', '_REG_ID' => $REG_ID] |
|
| 2326 | + : ['action' => 'default']; |
|
| 2327 | + $this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route); |
|
| 2328 | + } |
|
| 2329 | + } |
|
| 2330 | + } |
|
| 2331 | + |
|
| 2332 | + |
|
| 2333 | + /** |
|
| 2334 | + * Gets the form for saving registrations custom questions (if done |
|
| 2335 | + * previously retrieves the cached form object, which may have validation errors in it) |
|
| 2336 | + * |
|
| 2337 | + * @param int $REG_ID |
|
| 2338 | + * @return EE_Registration_Custom_Questions_Form |
|
| 2339 | + * @throws EE_Error |
|
| 2340 | + * @throws InvalidArgumentException |
|
| 2341 | + * @throws InvalidDataTypeException |
|
| 2342 | + * @throws InvalidInterfaceException |
|
| 2343 | + * @throws ReflectionException |
|
| 2344 | + */ |
|
| 2345 | + protected function _get_reg_custom_questions_form($REG_ID) |
|
| 2346 | + { |
|
| 2347 | + if (! $this->_reg_custom_questions_form) { |
|
| 2348 | + require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2349 | + $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 2350 | + $this->getRegistrationModel()->get_one_by_ID($REG_ID) |
|
| 2351 | + ); |
|
| 2352 | + $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 2353 | + } |
|
| 2354 | + return $this->_reg_custom_questions_form; |
|
| 2355 | + } |
|
| 2356 | + |
|
| 2357 | + |
|
| 2358 | + /** |
|
| 2359 | + * Saves |
|
| 2360 | + * |
|
| 2361 | + * @param bool $REG_ID |
|
| 2362 | + * @return bool |
|
| 2363 | + * @throws EE_Error |
|
| 2364 | + * @throws InvalidArgumentException |
|
| 2365 | + * @throws InvalidDataTypeException |
|
| 2366 | + * @throws InvalidInterfaceException |
|
| 2367 | + * @throws ReflectionException |
|
| 2368 | + */ |
|
| 2369 | + private function _save_reg_custom_questions_form($REG_ID = 0) |
|
| 2370 | + { |
|
| 2371 | + if (! $REG_ID) { |
|
| 2372 | + EE_Error::add_error( |
|
| 2373 | + esc_html__( |
|
| 2374 | + 'An error occurred. No registration ID was received.', |
|
| 2375 | + 'event_espresso' |
|
| 2376 | + ), |
|
| 2377 | + __FILE__, |
|
| 2378 | + __FUNCTION__, |
|
| 2379 | + __LINE__ |
|
| 2380 | + ); |
|
| 2381 | + } |
|
| 2382 | + $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 2383 | + $form->receive_form_submission($this->request->requestParams()); |
|
| 2384 | + $success = false; |
|
| 2385 | + if ($form->is_valid()) { |
|
| 2386 | + foreach ($form->subforms() as $question_group_form) { |
|
| 2387 | + foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 2388 | + $where_conditions = [ |
|
| 2389 | + 'QST_ID' => $question_id, |
|
| 2390 | + 'REG_ID' => $REG_ID, |
|
| 2391 | + ]; |
|
| 2392 | + $possibly_new_values = [ |
|
| 2393 | + 'ANS_value' => $input->normalized_value(), |
|
| 2394 | + ]; |
|
| 2395 | + $answer = EEM_Answer::instance()->get_one([$where_conditions]); |
|
| 2396 | + if ($answer instanceof EE_Answer) { |
|
| 2397 | + $success = $answer->save($possibly_new_values); |
|
| 2398 | + } else { |
|
| 2399 | + // insert it then |
|
| 2400 | + $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 2401 | + $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 2402 | + $success = $answer->save(); |
|
| 2403 | + } |
|
| 2404 | + } |
|
| 2405 | + } |
|
| 2406 | + } else { |
|
| 2407 | + EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2408 | + } |
|
| 2409 | + return $success; |
|
| 2410 | + } |
|
| 2411 | + |
|
| 2412 | + |
|
| 2413 | + /** |
|
| 2414 | + * generates HTML for the Registration main meta box |
|
| 2415 | + * |
|
| 2416 | + * @return void |
|
| 2417 | + * @throws DomainException |
|
| 2418 | + * @throws EE_Error |
|
| 2419 | + * @throws InvalidArgumentException |
|
| 2420 | + * @throws InvalidDataTypeException |
|
| 2421 | + * @throws InvalidInterfaceException |
|
| 2422 | + * @throws ReflectionException |
|
| 2423 | + */ |
|
| 2424 | + public function _reg_attendees_meta_box() |
|
| 2425 | + { |
|
| 2426 | + $REG = $this->getRegistrationModel(); |
|
| 2427 | + // get all other registrations on this transaction, and cache |
|
| 2428 | + // the attendees for them so we don't have to run another query using force_join |
|
| 2429 | + $registrations = $REG->get_all( |
|
| 2430 | + [ |
|
| 2431 | + [ |
|
| 2432 | + 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2433 | + 'REG_ID' => ['!=', $this->_registration->ID()], |
|
| 2434 | + ], |
|
| 2435 | + 'force_join' => ['Attendee'], |
|
| 2436 | + 'default_where_conditions' => 'other_models_only', |
|
| 2437 | + ] |
|
| 2438 | + ); |
|
| 2439 | + $this->_template_args['attendees'] = []; |
|
| 2440 | + $this->_template_args['attendee_notice'] = ''; |
|
| 2441 | + if ( |
|
| 2442 | + empty($registrations) |
|
| 2443 | + || (is_array($registrations) |
|
| 2444 | + && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2445 | + ) { |
|
| 2446 | + EE_Error::add_error( |
|
| 2447 | + esc_html__( |
|
| 2448 | + 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2449 | + 'event_espresso' |
|
| 2450 | + ), |
|
| 2451 | + __FILE__, |
|
| 2452 | + __FUNCTION__, |
|
| 2453 | + __LINE__ |
|
| 2454 | + ); |
|
| 2455 | + $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2456 | + } else { |
|
| 2457 | + $att_nmbr = 1; |
|
| 2458 | + foreach ($registrations as $registration) { |
|
| 2459 | + /* @var $registration EE_Registration */ |
|
| 2460 | + $attendee = $registration->attendee() |
|
| 2461 | + ? $registration->attendee() |
|
| 2462 | + : $this->getAttendeeModel()->create_default_object(); |
|
| 2463 | + $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID(); |
|
| 2464 | + $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname(); |
|
| 2465 | + $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname(); |
|
| 2466 | + $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email(); |
|
| 2467 | + $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price(); |
|
| 2468 | + $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode( |
|
| 2469 | + ', ', |
|
| 2470 | + $attendee->full_address_as_array() |
|
| 2471 | + ); |
|
| 2472 | + $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce( |
|
| 2473 | + [ |
|
| 2474 | + 'action' => 'edit_attendee', |
|
| 2475 | + 'post' => $attendee->ID(), |
|
| 2476 | + ], |
|
| 2477 | + REG_ADMIN_URL |
|
| 2478 | + ); |
|
| 2479 | + $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = |
|
| 2480 | + $registration->event_obj() instanceof EE_Event |
|
| 2481 | + ? $registration->event_obj()->name() |
|
| 2482 | + : ''; |
|
| 2483 | + $att_nmbr++; |
|
| 2484 | + } |
|
| 2485 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2486 | + } |
|
| 2487 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2488 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + /** |
|
| 2493 | + * generates HTML for the Edit Registration side meta box |
|
| 2494 | + * |
|
| 2495 | + * @return void |
|
| 2496 | + * @throws DomainException |
|
| 2497 | + * @throws EE_Error |
|
| 2498 | + * @throws InvalidArgumentException |
|
| 2499 | + * @throws InvalidDataTypeException |
|
| 2500 | + * @throws InvalidInterfaceException |
|
| 2501 | + * @throws ReflectionException |
|
| 2502 | + */ |
|
| 2503 | + public function _reg_registrant_side_meta_box() |
|
| 2504 | + { |
|
| 2505 | + /*@var $attendee EE_Attendee */ |
|
| 2506 | + $att_check = $this->_registration->attendee(); |
|
| 2507 | + $attendee = $att_check instanceof EE_Attendee |
|
| 2508 | + ? $att_check |
|
| 2509 | + : $this->getAttendeeModel()->create_default_object(); |
|
| 2510 | + // now let's determine if this is not the primary registration. If it isn't then we set the |
|
| 2511 | + // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
| 2512 | + // primary registration object (that way we know if we need to show create button or not) |
|
| 2513 | + if (! $this->_registration->is_primary_registrant()) { |
|
| 2514 | + $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2515 | + $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2516 | + : null; |
|
| 2517 | + if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2518 | + // in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
| 2519 | + // custom attendee object so let's not worry about the primary reg. |
|
| 2520 | + $primary_registration = null; |
|
| 2521 | + } |
|
| 2522 | + } else { |
|
| 2523 | + $primary_registration = null; |
|
| 2524 | + } |
|
| 2525 | + $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2526 | + $this->_template_args['fname'] = $attendee->fname(); |
|
| 2527 | + $this->_template_args['lname'] = $attendee->lname(); |
|
| 2528 | + $this->_template_args['email'] = $attendee->email(); |
|
| 2529 | + $this->_template_args['phone'] = $attendee->phone(); |
|
| 2530 | + $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2531 | + // edit link |
|
| 2532 | + $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2533 | + [ |
|
| 2534 | + 'action' => 'edit_attendee', |
|
| 2535 | + 'post' => $attendee->ID(), |
|
| 2536 | + ], |
|
| 2537 | + REG_ADMIN_URL |
|
| 2538 | + ); |
|
| 2539 | + $this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso'); |
|
| 2540 | + $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
| 2541 | + // create link |
|
| 2542 | + $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2543 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 2544 | + [ |
|
| 2545 | + 'action' => 'duplicate_attendee', |
|
| 2546 | + '_REG_ID' => $this->_registration->ID(), |
|
| 2547 | + ], |
|
| 2548 | + REG_ADMIN_URL |
|
| 2549 | + ) : ''; |
|
| 2550 | + $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
| 2551 | + $this->_template_args['att_check'] = $att_check; |
|
| 2552 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2553 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2554 | + } |
|
| 2555 | + |
|
| 2556 | + |
|
| 2557 | + /** |
|
| 2558 | + * trash or restore registrations |
|
| 2559 | + * |
|
| 2560 | + * @param boolean $trash whether to archive or restore |
|
| 2561 | + * @return void |
|
| 2562 | + * @throws EE_Error |
|
| 2563 | + * @throws InvalidArgumentException |
|
| 2564 | + * @throws InvalidDataTypeException |
|
| 2565 | + * @throws InvalidInterfaceException |
|
| 2566 | + * @throws RuntimeException |
|
| 2567 | + */ |
|
| 2568 | + protected function _trash_or_restore_registrations($trash = true) |
|
| 2569 | + { |
|
| 2570 | + // if empty _REG_ID then get out because there's nothing to do |
|
| 2571 | + $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true); |
|
| 2572 | + if (empty($REG_IDs)) { |
|
| 2573 | + EE_Error::add_error( |
|
| 2574 | + sprintf( |
|
| 2575 | + esc_html__( |
|
| 2576 | + 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2577 | + 'event_espresso' |
|
| 2578 | + ), |
|
| 2579 | + $trash ? 'trash' : 'restore' |
|
| 2580 | + ), |
|
| 2581 | + __FILE__, |
|
| 2582 | + __LINE__, |
|
| 2583 | + __FUNCTION__ |
|
| 2584 | + ); |
|
| 2585 | + $this->_redirect_after_action(false, '', '', [], true); |
|
| 2586 | + } |
|
| 2587 | + $success = 0; |
|
| 2588 | + $overwrite_msgs = false; |
|
| 2589 | + // Checkboxes |
|
| 2590 | + $reg_count = count($REG_IDs); |
|
| 2591 | + // cycle thru checkboxes |
|
| 2592 | + foreach ($REG_IDs as $REG_ID) { |
|
| 2593 | + /** @var EE_Registration $REG */ |
|
| 2594 | + $REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID); |
|
| 2595 | + $payments = $REG->registration_payments(); |
|
| 2596 | + if (! empty($payments)) { |
|
| 2597 | + $name = $REG->attendee() instanceof EE_Attendee |
|
| 2598 | + ? $REG->attendee()->full_name() |
|
| 2599 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 2600 | + $overwrite_msgs = true; |
|
| 2601 | + EE_Error::add_error( |
|
| 2602 | + sprintf( |
|
| 2603 | + esc_html__( |
|
| 2604 | + 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2605 | + 'event_espresso' |
|
| 2606 | + ), |
|
| 2607 | + $name |
|
| 2608 | + ), |
|
| 2609 | + __FILE__, |
|
| 2610 | + __FUNCTION__, |
|
| 2611 | + __LINE__ |
|
| 2612 | + ); |
|
| 2613 | + // can't trash this registration because it has payments. |
|
| 2614 | + continue; |
|
| 2615 | + } |
|
| 2616 | + $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2617 | + if ($updated) { |
|
| 2618 | + $success++; |
|
| 2619 | + } |
|
| 2620 | + } |
|
| 2621 | + $this->_redirect_after_action( |
|
| 2622 | + $success === $reg_count, // were ALL registrations affected? |
|
| 2623 | + $success > 1 |
|
| 2624 | + ? esc_html__('Registrations', 'event_espresso') |
|
| 2625 | + : esc_html__('Registration', 'event_espresso'), |
|
| 2626 | + $trash |
|
| 2627 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 2628 | + : esc_html__('restored', 'event_espresso'), |
|
| 2629 | + $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']), |
|
| 2630 | + $overwrite_msgs |
|
| 2631 | + ); |
|
| 2632 | + } |
|
| 2633 | + |
|
| 2634 | + |
|
| 2635 | + /** |
|
| 2636 | + * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2637 | + * registration but also. |
|
| 2638 | + * 1. Removing relations to EE_Attendee |
|
| 2639 | + * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2640 | + * ALSO trashed. |
|
| 2641 | + * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2642 | + * 4. Removing relationships between all tickets and the related registrations |
|
| 2643 | + * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2644 | + * 6. Deleting permanently any related Checkins. |
|
| 2645 | + * |
|
| 2646 | + * @return void |
|
| 2647 | + * @throws EE_Error |
|
| 2648 | + * @throws InvalidArgumentException |
|
| 2649 | + * @throws InvalidDataTypeException |
|
| 2650 | + * @throws InvalidInterfaceException |
|
| 2651 | + * @throws ReflectionException |
|
| 2652 | + */ |
|
| 2653 | + protected function _delete_registrations() |
|
| 2654 | + { |
|
| 2655 | + $REG_MDL = $this->getRegistrationModel(); |
|
| 2656 | + $success = 0; |
|
| 2657 | + // Checkboxes |
|
| 2658 | + $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true); |
|
| 2659 | + |
|
| 2660 | + if (! empty($REG_IDs)) { |
|
| 2661 | + // if array has more than one element than success message should be plural |
|
| 2662 | + $success = count($REG_IDs) > 1 ? 2 : 1; |
|
| 2663 | + // cycle thru checkboxes |
|
| 2664 | + foreach ($REG_IDs as $REG_ID) { |
|
| 2665 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2666 | + if (! $REG instanceof EE_Registration) { |
|
| 2667 | + continue; |
|
| 2668 | + } |
|
| 2669 | + $deleted = $this->_delete_registration($REG); |
|
| 2670 | + if (! $deleted) { |
|
| 2671 | + $success = 0; |
|
| 2672 | + } |
|
| 2673 | + } |
|
| 2674 | + } |
|
| 2675 | + |
|
| 2676 | + $what = $success > 1 |
|
| 2677 | + ? esc_html__('Registrations', 'event_espresso') |
|
| 2678 | + : esc_html__('Registration', 'event_espresso'); |
|
| 2679 | + $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
| 2680 | + $this->_redirect_after_action( |
|
| 2681 | + $success, |
|
| 2682 | + $what, |
|
| 2683 | + $action_desc, |
|
| 2684 | + $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']), |
|
| 2685 | + true |
|
| 2686 | + ); |
|
| 2687 | + } |
|
| 2688 | + |
|
| 2689 | + |
|
| 2690 | + /** |
|
| 2691 | + * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2692 | + * models get affected. |
|
| 2693 | + * |
|
| 2694 | + * @param EE_Registration $REG registration to be deleted permanently |
|
| 2695 | + * @return bool true = successful deletion, false = fail. |
|
| 2696 | + * @throws EE_Error |
|
| 2697 | + * @throws InvalidArgumentException |
|
| 2698 | + * @throws InvalidDataTypeException |
|
| 2699 | + * @throws InvalidInterfaceException |
|
| 2700 | + * @throws ReflectionException |
|
| 2701 | + */ |
|
| 2702 | + protected function _delete_registration(EE_Registration $REG) |
|
| 2703 | + { |
|
| 2704 | + // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
| 2705 | + // registrations on the transaction that are NOT trashed. |
|
| 2706 | + $TXN = $REG->get_first_related('Transaction'); |
|
| 2707 | + if (! $TXN instanceof EE_Transaction) { |
|
| 2708 | + EE_Error::add_error( |
|
| 2709 | + sprintf( |
|
| 2710 | + esc_html__( |
|
| 2711 | + 'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.', |
|
| 2712 | + 'event_espresso' |
|
| 2713 | + ), |
|
| 2714 | + $REG->id() |
|
| 2715 | + ), |
|
| 2716 | + __FILE__, |
|
| 2717 | + __FUNCTION__, |
|
| 2718 | + __LINE__ |
|
| 2719 | + ); |
|
| 2720 | + return false; |
|
| 2721 | + } |
|
| 2722 | + $REGS = $TXN->get_many_related('Registration'); |
|
| 2723 | + $all_trashed = true; |
|
| 2724 | + foreach ($REGS as $registration) { |
|
| 2725 | + if (! $registration->get('REG_deleted')) { |
|
| 2726 | + $all_trashed = false; |
|
| 2727 | + } |
|
| 2728 | + } |
|
| 2729 | + if (! $all_trashed) { |
|
| 2730 | + EE_Error::add_error( |
|
| 2731 | + esc_html__( |
|
| 2732 | + 'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2733 | + 'event_espresso' |
|
| 2734 | + ), |
|
| 2735 | + __FILE__, |
|
| 2736 | + __FUNCTION__, |
|
| 2737 | + __LINE__ |
|
| 2738 | + ); |
|
| 2739 | + return false; |
|
| 2740 | + } |
|
| 2741 | + // k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
| 2742 | + // separately from THIS one). |
|
| 2743 | + foreach ($REGS as $registration) { |
|
| 2744 | + // delete related answers |
|
| 2745 | + $registration->delete_related_permanently('Answer'); |
|
| 2746 | + // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2747 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 2748 | + if ($attendee instanceof EE_Attendee) { |
|
| 2749 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2750 | + } |
|
| 2751 | + // now remove relationships to tickets on this registration. |
|
| 2752 | + $registration->_remove_relations('Ticket'); |
|
| 2753 | + // now delete permanently the checkins related to this registration. |
|
| 2754 | + $registration->delete_related_permanently('Checkin'); |
|
| 2755 | + if ($registration->ID() === $REG->ID()) { |
|
| 2756 | + continue; |
|
| 2757 | + } //we don't want to delete permanently the existing registration just yet. |
|
| 2758 | + // remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2759 | + $registration->_remove_relations('Transaction'); |
|
| 2760 | + // delete permanently any related messages. |
|
| 2761 | + $registration->delete_related_permanently('Message'); |
|
| 2762 | + // now delete this registration permanently |
|
| 2763 | + $registration->delete_permanently(); |
|
| 2764 | + } |
|
| 2765 | + // now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
| 2766 | + // (the transaction and line items should be all that's left). |
|
| 2767 | + // delete the line items related to the transaction for this registration. |
|
| 2768 | + $TXN->delete_related_permanently('Line_Item'); |
|
| 2769 | + // we need to remove all the relationships on the transaction |
|
| 2770 | + $TXN->delete_related_permanently('Payment'); |
|
| 2771 | + $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2772 | + $TXN->delete_related_permanently('Message'); |
|
| 2773 | + // now we can delete this REG permanently (and the transaction of course) |
|
| 2774 | + $REG->delete_related_permanently('Transaction'); |
|
| 2775 | + return $REG->delete_permanently(); |
|
| 2776 | + } |
|
| 2777 | + |
|
| 2778 | + |
|
| 2779 | + /** |
|
| 2780 | + * generates HTML for the Register New Attendee Admin page |
|
| 2781 | + * |
|
| 2782 | + * @throws DomainException |
|
| 2783 | + * @throws EE_Error |
|
| 2784 | + * @throws InvalidArgumentException |
|
| 2785 | + * @throws InvalidDataTypeException |
|
| 2786 | + * @throws InvalidInterfaceException |
|
| 2787 | + * @throws ReflectionException |
|
| 2788 | + */ |
|
| 2789 | + public function new_registration() |
|
| 2790 | + { |
|
| 2791 | + if (! $this->_set_reg_event()) { |
|
| 2792 | + throw new EE_Error( |
|
| 2793 | + esc_html__( |
|
| 2794 | + 'Unable to continue with registering because there is no Event ID in the request', |
|
| 2795 | + 'event_espresso' |
|
| 2796 | + ) |
|
| 2797 | + ); |
|
| 2798 | + } |
|
| 2799 | + /** @var CurrentPage $current_page */ |
|
| 2800 | + $current_page = $this->loader->getShared(CurrentPage::class); |
|
| 2801 | + $current_page->setEspressoPage(true); |
|
| 2802 | + // gotta start with a clean slate if we're not coming here via ajax |
|
| 2803 | + if ( |
|
| 2804 | + ! $this->request->isAjax() |
|
| 2805 | + && ( |
|
| 2806 | + ! $this->request->requestParamIsSet('processing_registration') |
|
| 2807 | + || $this->request->requestParamIsSet('step_error') |
|
| 2808 | + ) |
|
| 2809 | + ) { |
|
| 2810 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2811 | + } |
|
| 2812 | + $this->_template_args['event_name'] = ''; |
|
| 2813 | + // event name |
|
| 2814 | + if ($this->_reg_event) { |
|
| 2815 | + $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2816 | + $edit_event_url = self::add_query_args_and_nonce( |
|
| 2817 | + [ |
|
| 2818 | + 'action' => 'edit', |
|
| 2819 | + 'post' => $this->_reg_event->ID(), |
|
| 2820 | + ], |
|
| 2821 | + EVENTS_ADMIN_URL |
|
| 2822 | + ); |
|
| 2823 | + $edit_event_lnk = '<a href="' |
|
| 2824 | + . $edit_event_url |
|
| 2825 | + . '" title="' |
|
| 2826 | + . esc_attr__('Edit ', 'event_espresso') |
|
| 2827 | + . $this->_reg_event->name() |
|
| 2828 | + . '">' |
|
| 2829 | + . esc_html__('Edit Event', 'event_espresso') |
|
| 2830 | + . '</a>'; |
|
| 2831 | + $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2832 | + . $edit_event_lnk |
|
| 2833 | + . '</span>'; |
|
| 2834 | + } |
|
| 2835 | + $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2836 | + if ($this->request->isAjax()) { |
|
| 2837 | + $this->_return_json(); |
|
| 2838 | + } |
|
| 2839 | + // grab header |
|
| 2840 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2841 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2842 | + $template_path, |
|
| 2843 | + $this->_template_args, |
|
| 2844 | + true |
|
| 2845 | + ); |
|
| 2846 | + // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2847 | + // the details template wrapper |
|
| 2848 | + $this->display_admin_page_with_sidebar(); |
|
| 2849 | + } |
|
| 2850 | + |
|
| 2851 | + |
|
| 2852 | + /** |
|
| 2853 | + * This returns the content for a registration step |
|
| 2854 | + * |
|
| 2855 | + * @return string html |
|
| 2856 | + * @throws DomainException |
|
| 2857 | + * @throws EE_Error |
|
| 2858 | + * @throws InvalidArgumentException |
|
| 2859 | + * @throws InvalidDataTypeException |
|
| 2860 | + * @throws InvalidInterfaceException |
|
| 2861 | + * @throws ReflectionException |
|
| 2862 | + */ |
|
| 2863 | + protected function _get_registration_step_content() |
|
| 2864 | + { |
|
| 2865 | + if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2866 | + $warning_msg = sprintf( |
|
| 2867 | + esc_html__( |
|
| 2868 | + '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
| 2869 | + 'event_espresso' |
|
| 2870 | + ), |
|
| 2871 | + '<br />', |
|
| 2872 | + '<h3 class="important-notice">', |
|
| 2873 | + '</h3>', |
|
| 2874 | + '<div class="float-right">', |
|
| 2875 | + '<span id="redirect_timer" class="important-notice">30</span>', |
|
| 2876 | + '</div>', |
|
| 2877 | + '<b>', |
|
| 2878 | + '</b>' |
|
| 2879 | + ); |
|
| 2880 | + return ' |
|
| 2881 | 2881 | <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
| 2882 | 2882 | <script > |
| 2883 | 2883 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
@@ -2890,844 +2890,844 @@ discard block |
||
| 2890 | 2890 | } |
| 2891 | 2891 | }, 800 ); |
| 2892 | 2892 | </script >'; |
| 2893 | - } |
|
| 2894 | - $template_args = [ |
|
| 2895 | - 'title' => '', |
|
| 2896 | - 'content' => '', |
|
| 2897 | - 'step_button_text' => '', |
|
| 2898 | - 'show_notification_toggle' => false, |
|
| 2899 | - ]; |
|
| 2900 | - // to indicate we're processing a new registration |
|
| 2901 | - $hidden_fields = [ |
|
| 2902 | - 'processing_registration' => [ |
|
| 2903 | - 'type' => 'hidden', |
|
| 2904 | - 'value' => 0, |
|
| 2905 | - ], |
|
| 2906 | - 'event_id' => [ |
|
| 2907 | - 'type' => 'hidden', |
|
| 2908 | - 'value' => $this->_reg_event->ID(), |
|
| 2909 | - ], |
|
| 2910 | - ]; |
|
| 2911 | - // if the cart is empty then we know we're at step one, so we'll display the ticket selector |
|
| 2912 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2913 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2914 | - switch ($step) { |
|
| 2915 | - case 'ticket': |
|
| 2916 | - $hidden_fields['processing_registration']['value'] = 1; |
|
| 2917 | - $template_args['title'] = esc_html__( |
|
| 2918 | - 'Step One: Select the Ticket for this registration', |
|
| 2919 | - 'event_espresso' |
|
| 2920 | - ); |
|
| 2921 | - $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2922 | - $template_args['content'] .= '</div>'; |
|
| 2923 | - $template_args['step_button_text'] = esc_html__( |
|
| 2924 | - 'Add Tickets and Continue to Registrant Details', |
|
| 2925 | - 'event_espresso' |
|
| 2926 | - ); |
|
| 2927 | - $template_args['show_notification_toggle'] = false; |
|
| 2928 | - break; |
|
| 2929 | - case 'questions': |
|
| 2930 | - $hidden_fields['processing_registration']['value'] = 2; |
|
| 2931 | - $template_args['title'] = esc_html__( |
|
| 2932 | - 'Step Two: Add Registrant Details for this Registration', |
|
| 2933 | - 'event_espresso' |
|
| 2934 | - ); |
|
| 2935 | - // in theory, we should be able to run EED_SPCO at this point |
|
| 2936 | - // because the cart should have been set up properly by the first process_reg_step run. |
|
| 2937 | - $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2938 | - $template_args['step_button_text'] = esc_html__( |
|
| 2939 | - 'Save Registration and Continue to Details', |
|
| 2940 | - 'event_espresso' |
|
| 2941 | - ); |
|
| 2942 | - $template_args['show_notification_toggle'] = true; |
|
| 2943 | - break; |
|
| 2944 | - } |
|
| 2945 | - // we come back to the process_registration_step route. |
|
| 2946 | - $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
| 2947 | - return EEH_Template::display_template( |
|
| 2948 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2949 | - $template_args, |
|
| 2950 | - true |
|
| 2951 | - ); |
|
| 2952 | - } |
|
| 2953 | - |
|
| 2954 | - |
|
| 2955 | - /** |
|
| 2956 | - * set_reg_event |
|
| 2957 | - * |
|
| 2958 | - * @return bool |
|
| 2959 | - * @throws EE_Error |
|
| 2960 | - * @throws InvalidArgumentException |
|
| 2961 | - * @throws InvalidDataTypeException |
|
| 2962 | - * @throws InvalidInterfaceException |
|
| 2963 | - */ |
|
| 2964 | - private function _set_reg_event() |
|
| 2965 | - { |
|
| 2966 | - if (is_object($this->_reg_event)) { |
|
| 2967 | - return true; |
|
| 2968 | - } |
|
| 2969 | - |
|
| 2970 | - $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int'); |
|
| 2971 | - if (! $EVT_ID) { |
|
| 2972 | - return false; |
|
| 2973 | - } |
|
| 2974 | - $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID); |
|
| 2975 | - return true; |
|
| 2976 | - } |
|
| 2977 | - |
|
| 2978 | - |
|
| 2979 | - /** |
|
| 2980 | - * process_reg_step |
|
| 2981 | - * |
|
| 2982 | - * @return void |
|
| 2983 | - * @throws DomainException |
|
| 2984 | - * @throws EE_Error |
|
| 2985 | - * @throws InvalidArgumentException |
|
| 2986 | - * @throws InvalidDataTypeException |
|
| 2987 | - * @throws InvalidInterfaceException |
|
| 2988 | - * @throws ReflectionException |
|
| 2989 | - * @throws RuntimeException |
|
| 2990 | - */ |
|
| 2991 | - public function process_reg_step() |
|
| 2992 | - { |
|
| 2993 | - EE_System::do_not_cache(); |
|
| 2994 | - $this->_set_reg_event(); |
|
| 2995 | - /** @var CurrentPage $current_page */ |
|
| 2996 | - $current_page = $this->loader->getShared(CurrentPage::class); |
|
| 2997 | - $current_page->setEspressoPage(true); |
|
| 2998 | - $this->request->setRequestParam('uts', time()); |
|
| 2999 | - // what step are we on? |
|
| 3000 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 3001 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 3002 | - // if doing ajax then we need to verify the nonce |
|
| 3003 | - if ($this->request->isAjax()) { |
|
| 3004 | - $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 3005 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 3006 | - } |
|
| 3007 | - switch ($step) { |
|
| 3008 | - case 'ticket': |
|
| 3009 | - // process ticket selection |
|
| 3010 | - $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 3011 | - if ($success) { |
|
| 3012 | - EE_Error::add_success( |
|
| 3013 | - esc_html__( |
|
| 3014 | - 'Tickets Selected. Now complete the registration.', |
|
| 3015 | - 'event_espresso' |
|
| 3016 | - ) |
|
| 3017 | - ); |
|
| 3018 | - } else { |
|
| 3019 | - $this->request->setRequestParam('step_error', true); |
|
| 3020 | - $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool'); |
|
| 3021 | - } |
|
| 3022 | - if ($this->request->isAjax()) { |
|
| 3023 | - $this->new_registration(); // display next step |
|
| 3024 | - } else { |
|
| 3025 | - $query_args = [ |
|
| 3026 | - 'action' => 'new_registration', |
|
| 3027 | - 'processing_registration' => 1, |
|
| 3028 | - 'event_id' => $this->_reg_event->ID(), |
|
| 3029 | - 'uts' => time(), |
|
| 3030 | - ]; |
|
| 3031 | - $this->_redirect_after_action( |
|
| 3032 | - false, |
|
| 3033 | - '', |
|
| 3034 | - '', |
|
| 3035 | - $query_args, |
|
| 3036 | - true |
|
| 3037 | - ); |
|
| 3038 | - } |
|
| 3039 | - break; |
|
| 3040 | - case 'questions': |
|
| 3041 | - if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) { |
|
| 3042 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 3043 | - } |
|
| 3044 | - // process registration |
|
| 3045 | - $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 3046 | - if ($cart instanceof EE_Cart) { |
|
| 3047 | - $grand_total = $cart->get_grand_total(); |
|
| 3048 | - if ($grand_total instanceof EE_Line_Item) { |
|
| 3049 | - $grand_total->save_this_and_descendants_to_txn(); |
|
| 3050 | - } |
|
| 3051 | - } |
|
| 3052 | - if (! $transaction instanceof EE_Transaction) { |
|
| 3053 | - $query_args = [ |
|
| 3054 | - 'action' => 'new_registration', |
|
| 3055 | - 'processing_registration' => 2, |
|
| 3056 | - 'event_id' => $this->_reg_event->ID(), |
|
| 3057 | - 'uts' => time(), |
|
| 3058 | - ]; |
|
| 3059 | - if ($this->request->isAjax()) { |
|
| 3060 | - // display registration form again because there are errors (maybe validation?) |
|
| 3061 | - $this->new_registration(); |
|
| 3062 | - return; |
|
| 3063 | - } |
|
| 3064 | - $this->_redirect_after_action( |
|
| 3065 | - false, |
|
| 3066 | - '', |
|
| 3067 | - '', |
|
| 3068 | - $query_args, |
|
| 3069 | - true |
|
| 3070 | - ); |
|
| 3071 | - return; |
|
| 3072 | - } |
|
| 3073 | - // maybe update status, and make sure to save transaction if not done already |
|
| 3074 | - if (! $transaction->update_status_based_on_total_paid()) { |
|
| 3075 | - $transaction->save(); |
|
| 3076 | - } |
|
| 3077 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3078 | - $query_args = [ |
|
| 3079 | - 'action' => 'redirect_to_txn', |
|
| 3080 | - 'TXN_ID' => $transaction->ID(), |
|
| 3081 | - 'EVT_ID' => $this->_reg_event->ID(), |
|
| 3082 | - 'event_name' => urlencode($this->_reg_event->name()), |
|
| 3083 | - 'redirect_from' => 'new_registration', |
|
| 3084 | - ]; |
|
| 3085 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3086 | - break; |
|
| 3087 | - } |
|
| 3088 | - // what are you looking here for? Should be nothing to do at this point. |
|
| 3089 | - } |
|
| 3090 | - |
|
| 3091 | - |
|
| 3092 | - /** |
|
| 3093 | - * redirect_to_txn |
|
| 3094 | - * |
|
| 3095 | - * @return void |
|
| 3096 | - * @throws EE_Error |
|
| 3097 | - * @throws InvalidArgumentException |
|
| 3098 | - * @throws InvalidDataTypeException |
|
| 3099 | - * @throws InvalidInterfaceException |
|
| 3100 | - * @throws ReflectionException |
|
| 3101 | - */ |
|
| 3102 | - public function redirect_to_txn() |
|
| 3103 | - { |
|
| 3104 | - EE_System::do_not_cache(); |
|
| 3105 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3106 | - $query_args = [ |
|
| 3107 | - 'action' => 'view_transaction', |
|
| 3108 | - 'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'), |
|
| 3109 | - 'page' => 'espresso_transactions', |
|
| 3110 | - ]; |
|
| 3111 | - if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) { |
|
| 3112 | - $query_args['EVT_ID'] = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 3113 | - $query_args['event_name'] = urlencode($this->request->getRequestParam('event_name')); |
|
| 3114 | - $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from'); |
|
| 3115 | - } |
|
| 3116 | - EE_Error::add_success( |
|
| 3117 | - esc_html__( |
|
| 3118 | - 'Registration Created. Please review the transaction and add any payments as necessary', |
|
| 3119 | - 'event_espresso' |
|
| 3120 | - ) |
|
| 3121 | - ); |
|
| 3122 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3123 | - } |
|
| 3124 | - |
|
| 3125 | - |
|
| 3126 | - /** |
|
| 3127 | - * generates HTML for the Attendee Contact List |
|
| 3128 | - * |
|
| 3129 | - * @return void |
|
| 3130 | - * @throws DomainException |
|
| 3131 | - * @throws EE_Error |
|
| 3132 | - */ |
|
| 3133 | - protected function _attendee_contact_list_table() |
|
| 3134 | - { |
|
| 3135 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3136 | - $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
| 3137 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 3138 | - } |
|
| 3139 | - |
|
| 3140 | - |
|
| 3141 | - /** |
|
| 3142 | - * get_attendees |
|
| 3143 | - * |
|
| 3144 | - * @param $per_page |
|
| 3145 | - * @param bool $count whether to return count or data. |
|
| 3146 | - * @param bool $trash |
|
| 3147 | - * @return array|int |
|
| 3148 | - * @throws EE_Error |
|
| 3149 | - * @throws InvalidArgumentException |
|
| 3150 | - * @throws InvalidDataTypeException |
|
| 3151 | - * @throws InvalidInterfaceException |
|
| 3152 | - */ |
|
| 3153 | - public function get_attendees($per_page, $count = false, $trash = false) |
|
| 3154 | - { |
|
| 3155 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3156 | - require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 3157 | - $orderby = $this->request->getRequestParam('orderby'); |
|
| 3158 | - switch ($orderby) { |
|
| 3159 | - case 'ATT_ID': |
|
| 3160 | - case 'ATT_fname': |
|
| 3161 | - case 'ATT_email': |
|
| 3162 | - case 'ATT_city': |
|
| 3163 | - case 'STA_ID': |
|
| 3164 | - case 'CNT_ID': |
|
| 3165 | - break; |
|
| 3166 | - case 'Registration_Count': |
|
| 3167 | - $orderby = 'Registration_Count'; |
|
| 3168 | - break; |
|
| 3169 | - default: |
|
| 3170 | - $orderby = 'ATT_lname'; |
|
| 3171 | - } |
|
| 3172 | - $sort = $this->request->getRequestParam('order', 'ASC'); |
|
| 3173 | - $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
| 3174 | - $per_page = absint($per_page) ? $per_page : 10; |
|
| 3175 | - $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
| 3176 | - $_where = []; |
|
| 3177 | - $search_term = $this->request->getRequestParam('s'); |
|
| 3178 | - if ($search_term) { |
|
| 3179 | - $search_term = '%' . $search_term . '%'; |
|
| 3180 | - $_where['OR'] = [ |
|
| 3181 | - 'Registration.Event.EVT_name' => ['LIKE', $search_term], |
|
| 3182 | - 'Registration.Event.EVT_desc' => ['LIKE', $search_term], |
|
| 3183 | - 'Registration.Event.EVT_short_desc' => ['LIKE', $search_term], |
|
| 3184 | - 'ATT_fname' => ['LIKE', $search_term], |
|
| 3185 | - 'ATT_lname' => ['LIKE', $search_term], |
|
| 3186 | - 'ATT_short_bio' => ['LIKE', $search_term], |
|
| 3187 | - 'ATT_email' => ['LIKE', $search_term], |
|
| 3188 | - 'ATT_address' => ['LIKE', $search_term], |
|
| 3189 | - 'ATT_address2' => ['LIKE', $search_term], |
|
| 3190 | - 'ATT_city' => ['LIKE', $search_term], |
|
| 3191 | - 'Country.CNT_name' => ['LIKE', $search_term], |
|
| 3192 | - 'State.STA_name' => ['LIKE', $search_term], |
|
| 3193 | - 'ATT_phone' => ['LIKE', $search_term], |
|
| 3194 | - 'Registration.REG_final_price' => ['LIKE', $search_term], |
|
| 3195 | - 'Registration.REG_code' => ['LIKE', $search_term], |
|
| 3196 | - 'Registration.REG_group_size' => ['LIKE', $search_term], |
|
| 3197 | - ]; |
|
| 3198 | - } |
|
| 3199 | - $offset = ($current_page - 1) * $per_page; |
|
| 3200 | - $limit = $count ? null : [$offset, $per_page]; |
|
| 3201 | - $query_args = [ |
|
| 3202 | - $_where, |
|
| 3203 | - 'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']], |
|
| 3204 | - 'limit' => $limit, |
|
| 3205 | - ]; |
|
| 3206 | - if (! $count) { |
|
| 3207 | - $query_args['order_by'] = [$orderby => $sort]; |
|
| 3208 | - } |
|
| 3209 | - $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']]; |
|
| 3210 | - return $count |
|
| 3211 | - ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true) |
|
| 3212 | - : $this->getAttendeeModel()->get_all($query_args); |
|
| 3213 | - } |
|
| 3214 | - |
|
| 3215 | - |
|
| 3216 | - /** |
|
| 3217 | - * This is just taking care of resending the registration confirmation |
|
| 3218 | - * |
|
| 3219 | - * @return void |
|
| 3220 | - * @throws EE_Error |
|
| 3221 | - * @throws InvalidArgumentException |
|
| 3222 | - * @throws InvalidDataTypeException |
|
| 3223 | - * @throws InvalidInterfaceException |
|
| 3224 | - * @throws ReflectionException |
|
| 3225 | - */ |
|
| 3226 | - protected function _resend_registration() |
|
| 3227 | - { |
|
| 3228 | - $this->_process_resend_registration(); |
|
| 3229 | - $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 3230 | - $redirect_to = $this->request->getRequestParam('redirect_to'); |
|
| 3231 | - $query_args = $redirect_to |
|
| 3232 | - ? ['action' => $redirect_to, '_REG_ID' => $REG_ID] |
|
| 3233 | - : ['action' => 'default']; |
|
| 3234 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3235 | - } |
|
| 3236 | - |
|
| 3237 | - |
|
| 3238 | - /** |
|
| 3239 | - * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 3240 | - * to use when selecting registrations |
|
| 3241 | - * |
|
| 3242 | - * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 3243 | - * the query parameters from the request |
|
| 3244 | - * @return void ends the request with a redirect or download |
|
| 3245 | - */ |
|
| 3246 | - public function _registrations_report_base($method_name_for_getting_query_params) |
|
| 3247 | - { |
|
| 3248 | - $EVT_ID = $this->request->requestParamIsSet('EVT_ID') |
|
| 3249 | - ? $this->request->getRequestParam('EVT_ID', 0, 'int') |
|
| 3250 | - : null; |
|
| 3251 | - if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3252 | - $request_params = $this->request->requestParams(); |
|
| 3253 | - wp_redirect( |
|
| 3254 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 3255 | - [ |
|
| 3256 | - 'page' => 'espresso_batch', |
|
| 3257 | - 'batch' => 'file', |
|
| 3258 | - 'EVT_ID' => $EVT_ID, |
|
| 3259 | - 'filters' => urlencode( |
|
| 3260 | - serialize( |
|
| 3261 | - $this->$method_name_for_getting_query_params( |
|
| 3262 | - EEH_Array::is_set($request_params, 'filters', []) |
|
| 3263 | - ) |
|
| 3264 | - ) |
|
| 3265 | - ), |
|
| 3266 | - 'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false), |
|
| 3267 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 3268 | - 'return_url' => urlencode($this->request->getRequestParam('return_url', '', 'url')), |
|
| 3269 | - ] |
|
| 3270 | - ) |
|
| 3271 | - ); |
|
| 3272 | - } else { |
|
| 3273 | - // Pull the current request params |
|
| 3274 | - $request_args = $this->request->requestParams(); |
|
| 3275 | - // Set the required request_args to be passed to the export |
|
| 3276 | - $required_request_args = [ |
|
| 3277 | - 'export' => 'report', |
|
| 3278 | - 'action' => 'registrations_report_for_event', |
|
| 3279 | - 'EVT_ID' => $EVT_ID, |
|
| 3280 | - ]; |
|
| 3281 | - // Merge required request args, overriding any currently set |
|
| 3282 | - $request_args = array_merge($request_args, $required_request_args); |
|
| 3283 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3284 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3285 | - $EE_Export = EE_Export::instance($request_args); |
|
| 3286 | - $EE_Export->export(); |
|
| 3287 | - } |
|
| 3288 | - } |
|
| 3289 | - } |
|
| 3290 | - |
|
| 3291 | - |
|
| 3292 | - /** |
|
| 3293 | - * Creates a registration report using only query parameters in the request |
|
| 3294 | - * |
|
| 3295 | - * @return void |
|
| 3296 | - */ |
|
| 3297 | - public function _registrations_report() |
|
| 3298 | - { |
|
| 3299 | - $this->_registrations_report_base('_get_registration_query_parameters'); |
|
| 3300 | - } |
|
| 3301 | - |
|
| 3302 | - |
|
| 3303 | - public function _contact_list_export() |
|
| 3304 | - { |
|
| 3305 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3306 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3307 | - $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
| 3308 | - $EE_Export->export_attendees(); |
|
| 3309 | - } |
|
| 3310 | - } |
|
| 3311 | - |
|
| 3312 | - |
|
| 3313 | - public function _contact_list_report() |
|
| 3314 | - { |
|
| 3315 | - if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3316 | - wp_redirect( |
|
| 3317 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 3318 | - [ |
|
| 3319 | - 'page' => 'espresso_batch', |
|
| 3320 | - 'batch' => 'file', |
|
| 3321 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 3322 | - 'return_url' => urlencode($this->request->getRequestParam('return_url', '', 'url')), |
|
| 3323 | - ] |
|
| 3324 | - ) |
|
| 3325 | - ); |
|
| 3326 | - } else { |
|
| 3327 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3328 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3329 | - $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
| 3330 | - $EE_Export->report_attendees(); |
|
| 3331 | - } |
|
| 3332 | - } |
|
| 3333 | - } |
|
| 3334 | - |
|
| 3335 | - |
|
| 3336 | - |
|
| 3337 | - |
|
| 3338 | - |
|
| 3339 | - /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 3340 | - /** |
|
| 3341 | - * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 3342 | - * |
|
| 3343 | - * @return void |
|
| 3344 | - * @throws EE_Error |
|
| 3345 | - * @throws InvalidArgumentException |
|
| 3346 | - * @throws InvalidDataTypeException |
|
| 3347 | - * @throws InvalidInterfaceException |
|
| 3348 | - * @throws ReflectionException |
|
| 3349 | - */ |
|
| 3350 | - protected function _duplicate_attendee() |
|
| 3351 | - { |
|
| 3352 | - $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 3353 | - $action = $this->request->getRequestParam('return', 'default'); |
|
| 3354 | - // verify we have necessary info |
|
| 3355 | - if (! $REG_ID) { |
|
| 3356 | - EE_Error::add_error( |
|
| 3357 | - esc_html__( |
|
| 3358 | - 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 3359 | - 'event_espresso' |
|
| 3360 | - ), |
|
| 3361 | - __FILE__, |
|
| 3362 | - __LINE__, |
|
| 3363 | - __FUNCTION__ |
|
| 3364 | - ); |
|
| 3365 | - $query_args = ['action' => $action]; |
|
| 3366 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3367 | - } |
|
| 3368 | - // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 3369 | - $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID); |
|
| 3370 | - if (! $registration instanceof EE_Registration) { |
|
| 3371 | - throw new RuntimeException( |
|
| 3372 | - sprintf( |
|
| 3373 | - esc_html__( |
|
| 3374 | - 'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d', |
|
| 3375 | - 'event_espresso' |
|
| 3376 | - ), |
|
| 3377 | - $REG_ID |
|
| 3378 | - ) |
|
| 3379 | - ); |
|
| 3380 | - } |
|
| 3381 | - $attendee = $registration->attendee(); |
|
| 3382 | - // remove relation of existing attendee on registration |
|
| 3383 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 3384 | - // new attendee |
|
| 3385 | - $new_attendee = clone $attendee; |
|
| 3386 | - $new_attendee->set('ATT_ID', 0); |
|
| 3387 | - $new_attendee->save(); |
|
| 3388 | - // add new attendee to reg |
|
| 3389 | - $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 3390 | - EE_Error::add_success( |
|
| 3391 | - esc_html__( |
|
| 3392 | - 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 3393 | - 'event_espresso' |
|
| 3394 | - ) |
|
| 3395 | - ); |
|
| 3396 | - // redirect to edit page for attendee |
|
| 3397 | - $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee']; |
|
| 3398 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3399 | - } |
|
| 3400 | - |
|
| 3401 | - |
|
| 3402 | - /** |
|
| 3403 | - * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook. |
|
| 3404 | - * |
|
| 3405 | - * @param int $post_id |
|
| 3406 | - * @param WP_POST $post |
|
| 3407 | - * @throws DomainException |
|
| 3408 | - * @throws EE_Error |
|
| 3409 | - * @throws InvalidArgumentException |
|
| 3410 | - * @throws InvalidDataTypeException |
|
| 3411 | - * @throws InvalidInterfaceException |
|
| 3412 | - * @throws LogicException |
|
| 3413 | - * @throws InvalidFormSubmissionException |
|
| 3414 | - * @throws ReflectionException |
|
| 3415 | - */ |
|
| 3416 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 3417 | - { |
|
| 3418 | - $success = true; |
|
| 3419 | - $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees' |
|
| 3420 | - ? $this->getAttendeeModel()->get_one_by_ID($post_id) |
|
| 3421 | - : null; |
|
| 3422 | - // for attendee updates |
|
| 3423 | - if ($attendee instanceof EE_Attendee) { |
|
| 3424 | - // note we should only be UPDATING attendees at this point. |
|
| 3425 | - $fname = $this->request->getRequestParam('ATT_fname', ''); |
|
| 3426 | - $lname = $this->request->getRequestParam('ATT_lname', ''); |
|
| 3427 | - $updated_fields = [ |
|
| 3428 | - 'ATT_fname' => $fname, |
|
| 3429 | - 'ATT_lname' => $lname, |
|
| 3430 | - 'ATT_full_name' => "{$fname} {$lname}", |
|
| 3431 | - 'ATT_address' => $this->request->getRequestParam('ATT_address', ''), |
|
| 3432 | - 'ATT_address2' => $this->request->getRequestParam('ATT_address2', ''), |
|
| 3433 | - 'ATT_city' => $this->request->getRequestParam('ATT_city', ''), |
|
| 3434 | - 'STA_ID' => $this->request->getRequestParam('STA_ID', ''), |
|
| 3435 | - 'CNT_ISO' => $this->request->getRequestParam('CNT_ISO', ''), |
|
| 3436 | - 'ATT_zip' => $this->request->getRequestParam('ATT_zip', ''), |
|
| 3437 | - ]; |
|
| 3438 | - foreach ($updated_fields as $field => $value) { |
|
| 3439 | - $attendee->set($field, $value); |
|
| 3440 | - } |
|
| 3441 | - |
|
| 3442 | - // process contact details metabox form handler (which will also save the attendee) |
|
| 3443 | - $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee); |
|
| 3444 | - $success = $contact_details_form->process($this->request->requestParams()); |
|
| 3445 | - |
|
| 3446 | - $attendee_update_callbacks = apply_filters( |
|
| 3447 | - 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 3448 | - [] |
|
| 3449 | - ); |
|
| 3450 | - foreach ($attendee_update_callbacks as $a_callback) { |
|
| 3451 | - if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) { |
|
| 3452 | - throw new EE_Error( |
|
| 3453 | - sprintf( |
|
| 3454 | - esc_html__( |
|
| 3455 | - 'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 3456 | - 'event_espresso' |
|
| 3457 | - ), |
|
| 3458 | - $a_callback |
|
| 3459 | - ) |
|
| 3460 | - ); |
|
| 3461 | - } |
|
| 3462 | - } |
|
| 3463 | - } |
|
| 3464 | - |
|
| 3465 | - if ($success === false) { |
|
| 3466 | - EE_Error::add_error( |
|
| 3467 | - esc_html__( |
|
| 3468 | - 'Something went wrong with updating the meta table data for the registration.', |
|
| 3469 | - 'event_espresso' |
|
| 3470 | - ), |
|
| 3471 | - __FILE__, |
|
| 3472 | - __FUNCTION__, |
|
| 3473 | - __LINE__ |
|
| 3474 | - ); |
|
| 3475 | - } |
|
| 3476 | - } |
|
| 3477 | - |
|
| 3478 | - |
|
| 3479 | - public function trash_cpt_item($post_id) |
|
| 3480 | - { |
|
| 3481 | - } |
|
| 3482 | - |
|
| 3483 | - |
|
| 3484 | - public function delete_cpt_item($post_id) |
|
| 3485 | - { |
|
| 3486 | - } |
|
| 3487 | - |
|
| 3488 | - |
|
| 3489 | - public function restore_cpt_item($post_id) |
|
| 3490 | - { |
|
| 3491 | - } |
|
| 3492 | - |
|
| 3493 | - |
|
| 3494 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 3495 | - { |
|
| 3496 | - } |
|
| 3497 | - |
|
| 3498 | - |
|
| 3499 | - /** |
|
| 3500 | - * @throws EE_Error |
|
| 3501 | - * @throws ReflectionException |
|
| 3502 | - * @since 4.10.2.p |
|
| 3503 | - */ |
|
| 3504 | - public function attendee_editor_metaboxes() |
|
| 3505 | - { |
|
| 3506 | - $this->verify_cpt_object(); |
|
| 3507 | - remove_meta_box( |
|
| 3508 | - 'postexcerpt', |
|
| 3509 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3510 | - 'normal' |
|
| 3511 | - ); |
|
| 3512 | - remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal'); |
|
| 3513 | - if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 3514 | - $this->addMetaBox( |
|
| 3515 | - 'postexcerpt', |
|
| 3516 | - esc_html__('Short Biography', 'event_espresso'), |
|
| 3517 | - 'post_excerpt_meta_box', |
|
| 3518 | - $this->_cpt_routes[ $this->_req_action ] |
|
| 3519 | - ); |
|
| 3520 | - } |
|
| 3521 | - if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 3522 | - $this->addMetaBox( |
|
| 3523 | - 'commentsdiv', |
|
| 3524 | - esc_html__('Notes on the Contact', 'event_espresso'), |
|
| 3525 | - 'post_comment_meta_box', |
|
| 3526 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3527 | - 'normal', |
|
| 3528 | - 'core' |
|
| 3529 | - ); |
|
| 3530 | - } |
|
| 3531 | - $this->addMetaBox( |
|
| 3532 | - 'attendee_contact_info', |
|
| 3533 | - esc_html__('Contact Info', 'event_espresso'), |
|
| 3534 | - [$this, 'attendee_contact_info'], |
|
| 3535 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3536 | - 'side', |
|
| 3537 | - 'core' |
|
| 3538 | - ); |
|
| 3539 | - $this->addMetaBox( |
|
| 3540 | - 'attendee_details_address', |
|
| 3541 | - esc_html__('Address Details', 'event_espresso'), |
|
| 3542 | - [$this, 'attendee_address_details'], |
|
| 3543 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3544 | - 'normal', |
|
| 3545 | - 'core' |
|
| 3546 | - ); |
|
| 3547 | - $this->addMetaBox( |
|
| 3548 | - 'attendee_registrations', |
|
| 3549 | - esc_html__('Registrations for this Contact', 'event_espresso'), |
|
| 3550 | - [$this, 'attendee_registrations_meta_box'], |
|
| 3551 | - $this->_cpt_routes[ $this->_req_action ] |
|
| 3552 | - ); |
|
| 3553 | - } |
|
| 3554 | - |
|
| 3555 | - |
|
| 3556 | - /** |
|
| 3557 | - * Metabox for attendee contact info |
|
| 3558 | - * |
|
| 3559 | - * @param WP_Post $post wp post object |
|
| 3560 | - * @return void attendee contact info ( and form ) |
|
| 3561 | - * @throws EE_Error |
|
| 3562 | - * @throws InvalidArgumentException |
|
| 3563 | - * @throws InvalidDataTypeException |
|
| 3564 | - * @throws InvalidInterfaceException |
|
| 3565 | - * @throws LogicException |
|
| 3566 | - * @throws DomainException |
|
| 3567 | - */ |
|
| 3568 | - public function attendee_contact_info($post) |
|
| 3569 | - { |
|
| 3570 | - // get attendee object ( should already have it ) |
|
| 3571 | - $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj); |
|
| 3572 | - $form->enqueueStylesAndScripts(); |
|
| 3573 | - echo $form->display(); // already escaped |
|
| 3574 | - } |
|
| 3575 | - |
|
| 3576 | - |
|
| 3577 | - /** |
|
| 3578 | - * Return form handler for the contact details metabox |
|
| 3579 | - * |
|
| 3580 | - * @param EE_Attendee $attendee |
|
| 3581 | - * @return AttendeeContactDetailsMetaboxFormHandler |
|
| 3582 | - * @throws DomainException |
|
| 3583 | - * @throws InvalidArgumentException |
|
| 3584 | - * @throws InvalidDataTypeException |
|
| 3585 | - * @throws InvalidInterfaceException |
|
| 3586 | - */ |
|
| 3587 | - protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee) |
|
| 3588 | - { |
|
| 3589 | - return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance()); |
|
| 3590 | - } |
|
| 3591 | - |
|
| 3592 | - |
|
| 3593 | - /** |
|
| 3594 | - * Metabox for attendee details |
|
| 3595 | - * |
|
| 3596 | - * @param WP_Post $post wp post object |
|
| 3597 | - * @throws EE_Error |
|
| 3598 | - * @throws ReflectionException |
|
| 3599 | - */ |
|
| 3600 | - public function attendee_address_details($post) |
|
| 3601 | - { |
|
| 3602 | - // get attendee object (should already have it) |
|
| 3603 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3604 | - $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3605 | - new EE_Question_Form_Input( |
|
| 3606 | - EE_Question::new_instance( |
|
| 3607 | - [ |
|
| 3608 | - 'QST_ID' => 0, |
|
| 3609 | - 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
| 3610 | - 'QST_system' => 'admin-state', |
|
| 3611 | - ] |
|
| 3612 | - ), |
|
| 3613 | - EE_Answer::new_instance( |
|
| 3614 | - [ |
|
| 3615 | - 'ANS_ID' => 0, |
|
| 3616 | - 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 3617 | - ] |
|
| 3618 | - ), |
|
| 3619 | - [ |
|
| 3620 | - 'input_id' => 'STA_ID', |
|
| 3621 | - 'input_name' => 'STA_ID', |
|
| 3622 | - 'input_prefix' => '', |
|
| 3623 | - 'append_qstn_id' => false, |
|
| 3624 | - ] |
|
| 3625 | - ) |
|
| 3626 | - ); |
|
| 3627 | - $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3628 | - new EE_Question_Form_Input( |
|
| 3629 | - EE_Question::new_instance( |
|
| 3630 | - [ |
|
| 3631 | - 'QST_ID' => 0, |
|
| 3632 | - 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
| 3633 | - 'QST_system' => 'admin-country', |
|
| 3634 | - ] |
|
| 3635 | - ), |
|
| 3636 | - EE_Answer::new_instance( |
|
| 3637 | - [ |
|
| 3638 | - 'ANS_ID' => 0, |
|
| 3639 | - 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 3640 | - ] |
|
| 3641 | - ), |
|
| 3642 | - [ |
|
| 3643 | - 'input_id' => 'CNT_ISO', |
|
| 3644 | - 'input_name' => 'CNT_ISO', |
|
| 3645 | - 'input_prefix' => '', |
|
| 3646 | - 'append_qstn_id' => false, |
|
| 3647 | - ] |
|
| 3648 | - ) |
|
| 3649 | - ); |
|
| 3650 | - $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 3651 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3652 | - } |
|
| 3653 | - |
|
| 3654 | - |
|
| 3655 | - /** |
|
| 3656 | - * _attendee_details |
|
| 3657 | - * |
|
| 3658 | - * @param $post |
|
| 3659 | - * @return void |
|
| 3660 | - * @throws DomainException |
|
| 3661 | - * @throws EE_Error |
|
| 3662 | - * @throws InvalidArgumentException |
|
| 3663 | - * @throws InvalidDataTypeException |
|
| 3664 | - * @throws InvalidInterfaceException |
|
| 3665 | - * @throws ReflectionException |
|
| 3666 | - */ |
|
| 3667 | - public function attendee_registrations_meta_box($post) |
|
| 3668 | - { |
|
| 3669 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3670 | - $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 3671 | - $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 3672 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3673 | - } |
|
| 3674 | - |
|
| 3675 | - |
|
| 3676 | - /** |
|
| 3677 | - * add in the form fields for the attendee edit |
|
| 3678 | - * |
|
| 3679 | - * @param WP_Post $post wp post object |
|
| 3680 | - * @return void echos html for new form. |
|
| 3681 | - * @throws DomainException |
|
| 3682 | - */ |
|
| 3683 | - public function after_title_form_fields($post) |
|
| 3684 | - { |
|
| 3685 | - if ($post->post_type === 'espresso_attendees') { |
|
| 3686 | - $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 3687 | - $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3688 | - EEH_Template::display_template($template, $template_args); |
|
| 3689 | - } |
|
| 3690 | - } |
|
| 3691 | - |
|
| 3692 | - |
|
| 3693 | - /** |
|
| 3694 | - * _trash_or_restore_attendee |
|
| 3695 | - * |
|
| 3696 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 3697 | - * @return void |
|
| 3698 | - * @throws EE_Error |
|
| 3699 | - * @throws InvalidArgumentException |
|
| 3700 | - * @throws InvalidDataTypeException |
|
| 3701 | - * @throws InvalidInterfaceException |
|
| 3702 | - */ |
|
| 3703 | - protected function _trash_or_restore_attendees($trash = true) |
|
| 3704 | - { |
|
| 3705 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3706 | - $status = $trash ? 'trash' : 'publish'; |
|
| 3707 | - // Checkboxes |
|
| 3708 | - if ($this->request->requestParamIsSet('checkbox')) { |
|
| 3709 | - $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
| 3710 | - // if array has more than one element than success message should be plural |
|
| 3711 | - $success = count($ATT_IDs) > 1 ? 2 : 1; |
|
| 3712 | - // cycle thru checkboxes |
|
| 3713 | - foreach ($ATT_IDs as $ATT_ID) { |
|
| 3714 | - $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID); |
|
| 3715 | - if (! $updated) { |
|
| 3716 | - $success = 0; |
|
| 3717 | - } |
|
| 3718 | - } |
|
| 3719 | - } else { |
|
| 3720 | - // grab single id and delete |
|
| 3721 | - $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int'); |
|
| 3722 | - // update attendee |
|
| 3723 | - $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0; |
|
| 3724 | - } |
|
| 3725 | - $what = $success > 1 |
|
| 3726 | - ? esc_html__('Contacts', 'event_espresso') |
|
| 3727 | - : esc_html__('Contact', 'event_espresso'); |
|
| 3728 | - $action_desc = $trash |
|
| 3729 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3730 | - : esc_html__('restored', 'event_espresso'); |
|
| 3731 | - $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']); |
|
| 3732 | - } |
|
| 2893 | + } |
|
| 2894 | + $template_args = [ |
|
| 2895 | + 'title' => '', |
|
| 2896 | + 'content' => '', |
|
| 2897 | + 'step_button_text' => '', |
|
| 2898 | + 'show_notification_toggle' => false, |
|
| 2899 | + ]; |
|
| 2900 | + // to indicate we're processing a new registration |
|
| 2901 | + $hidden_fields = [ |
|
| 2902 | + 'processing_registration' => [ |
|
| 2903 | + 'type' => 'hidden', |
|
| 2904 | + 'value' => 0, |
|
| 2905 | + ], |
|
| 2906 | + 'event_id' => [ |
|
| 2907 | + 'type' => 'hidden', |
|
| 2908 | + 'value' => $this->_reg_event->ID(), |
|
| 2909 | + ], |
|
| 2910 | + ]; |
|
| 2911 | + // if the cart is empty then we know we're at step one, so we'll display the ticket selector |
|
| 2912 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2913 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2914 | + switch ($step) { |
|
| 2915 | + case 'ticket': |
|
| 2916 | + $hidden_fields['processing_registration']['value'] = 1; |
|
| 2917 | + $template_args['title'] = esc_html__( |
|
| 2918 | + 'Step One: Select the Ticket for this registration', |
|
| 2919 | + 'event_espresso' |
|
| 2920 | + ); |
|
| 2921 | + $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2922 | + $template_args['content'] .= '</div>'; |
|
| 2923 | + $template_args['step_button_text'] = esc_html__( |
|
| 2924 | + 'Add Tickets and Continue to Registrant Details', |
|
| 2925 | + 'event_espresso' |
|
| 2926 | + ); |
|
| 2927 | + $template_args['show_notification_toggle'] = false; |
|
| 2928 | + break; |
|
| 2929 | + case 'questions': |
|
| 2930 | + $hidden_fields['processing_registration']['value'] = 2; |
|
| 2931 | + $template_args['title'] = esc_html__( |
|
| 2932 | + 'Step Two: Add Registrant Details for this Registration', |
|
| 2933 | + 'event_espresso' |
|
| 2934 | + ); |
|
| 2935 | + // in theory, we should be able to run EED_SPCO at this point |
|
| 2936 | + // because the cart should have been set up properly by the first process_reg_step run. |
|
| 2937 | + $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2938 | + $template_args['step_button_text'] = esc_html__( |
|
| 2939 | + 'Save Registration and Continue to Details', |
|
| 2940 | + 'event_espresso' |
|
| 2941 | + ); |
|
| 2942 | + $template_args['show_notification_toggle'] = true; |
|
| 2943 | + break; |
|
| 2944 | + } |
|
| 2945 | + // we come back to the process_registration_step route. |
|
| 2946 | + $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
| 2947 | + return EEH_Template::display_template( |
|
| 2948 | + REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2949 | + $template_args, |
|
| 2950 | + true |
|
| 2951 | + ); |
|
| 2952 | + } |
|
| 2953 | + |
|
| 2954 | + |
|
| 2955 | + /** |
|
| 2956 | + * set_reg_event |
|
| 2957 | + * |
|
| 2958 | + * @return bool |
|
| 2959 | + * @throws EE_Error |
|
| 2960 | + * @throws InvalidArgumentException |
|
| 2961 | + * @throws InvalidDataTypeException |
|
| 2962 | + * @throws InvalidInterfaceException |
|
| 2963 | + */ |
|
| 2964 | + private function _set_reg_event() |
|
| 2965 | + { |
|
| 2966 | + if (is_object($this->_reg_event)) { |
|
| 2967 | + return true; |
|
| 2968 | + } |
|
| 2969 | + |
|
| 2970 | + $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int'); |
|
| 2971 | + if (! $EVT_ID) { |
|
| 2972 | + return false; |
|
| 2973 | + } |
|
| 2974 | + $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID); |
|
| 2975 | + return true; |
|
| 2976 | + } |
|
| 2977 | + |
|
| 2978 | + |
|
| 2979 | + /** |
|
| 2980 | + * process_reg_step |
|
| 2981 | + * |
|
| 2982 | + * @return void |
|
| 2983 | + * @throws DomainException |
|
| 2984 | + * @throws EE_Error |
|
| 2985 | + * @throws InvalidArgumentException |
|
| 2986 | + * @throws InvalidDataTypeException |
|
| 2987 | + * @throws InvalidInterfaceException |
|
| 2988 | + * @throws ReflectionException |
|
| 2989 | + * @throws RuntimeException |
|
| 2990 | + */ |
|
| 2991 | + public function process_reg_step() |
|
| 2992 | + { |
|
| 2993 | + EE_System::do_not_cache(); |
|
| 2994 | + $this->_set_reg_event(); |
|
| 2995 | + /** @var CurrentPage $current_page */ |
|
| 2996 | + $current_page = $this->loader->getShared(CurrentPage::class); |
|
| 2997 | + $current_page->setEspressoPage(true); |
|
| 2998 | + $this->request->setRequestParam('uts', time()); |
|
| 2999 | + // what step are we on? |
|
| 3000 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 3001 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 3002 | + // if doing ajax then we need to verify the nonce |
|
| 3003 | + if ($this->request->isAjax()) { |
|
| 3004 | + $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 3005 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 3006 | + } |
|
| 3007 | + switch ($step) { |
|
| 3008 | + case 'ticket': |
|
| 3009 | + // process ticket selection |
|
| 3010 | + $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 3011 | + if ($success) { |
|
| 3012 | + EE_Error::add_success( |
|
| 3013 | + esc_html__( |
|
| 3014 | + 'Tickets Selected. Now complete the registration.', |
|
| 3015 | + 'event_espresso' |
|
| 3016 | + ) |
|
| 3017 | + ); |
|
| 3018 | + } else { |
|
| 3019 | + $this->request->setRequestParam('step_error', true); |
|
| 3020 | + $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool'); |
|
| 3021 | + } |
|
| 3022 | + if ($this->request->isAjax()) { |
|
| 3023 | + $this->new_registration(); // display next step |
|
| 3024 | + } else { |
|
| 3025 | + $query_args = [ |
|
| 3026 | + 'action' => 'new_registration', |
|
| 3027 | + 'processing_registration' => 1, |
|
| 3028 | + 'event_id' => $this->_reg_event->ID(), |
|
| 3029 | + 'uts' => time(), |
|
| 3030 | + ]; |
|
| 3031 | + $this->_redirect_after_action( |
|
| 3032 | + false, |
|
| 3033 | + '', |
|
| 3034 | + '', |
|
| 3035 | + $query_args, |
|
| 3036 | + true |
|
| 3037 | + ); |
|
| 3038 | + } |
|
| 3039 | + break; |
|
| 3040 | + case 'questions': |
|
| 3041 | + if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) { |
|
| 3042 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 3043 | + } |
|
| 3044 | + // process registration |
|
| 3045 | + $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 3046 | + if ($cart instanceof EE_Cart) { |
|
| 3047 | + $grand_total = $cart->get_grand_total(); |
|
| 3048 | + if ($grand_total instanceof EE_Line_Item) { |
|
| 3049 | + $grand_total->save_this_and_descendants_to_txn(); |
|
| 3050 | + } |
|
| 3051 | + } |
|
| 3052 | + if (! $transaction instanceof EE_Transaction) { |
|
| 3053 | + $query_args = [ |
|
| 3054 | + 'action' => 'new_registration', |
|
| 3055 | + 'processing_registration' => 2, |
|
| 3056 | + 'event_id' => $this->_reg_event->ID(), |
|
| 3057 | + 'uts' => time(), |
|
| 3058 | + ]; |
|
| 3059 | + if ($this->request->isAjax()) { |
|
| 3060 | + // display registration form again because there are errors (maybe validation?) |
|
| 3061 | + $this->new_registration(); |
|
| 3062 | + return; |
|
| 3063 | + } |
|
| 3064 | + $this->_redirect_after_action( |
|
| 3065 | + false, |
|
| 3066 | + '', |
|
| 3067 | + '', |
|
| 3068 | + $query_args, |
|
| 3069 | + true |
|
| 3070 | + ); |
|
| 3071 | + return; |
|
| 3072 | + } |
|
| 3073 | + // maybe update status, and make sure to save transaction if not done already |
|
| 3074 | + if (! $transaction->update_status_based_on_total_paid()) { |
|
| 3075 | + $transaction->save(); |
|
| 3076 | + } |
|
| 3077 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3078 | + $query_args = [ |
|
| 3079 | + 'action' => 'redirect_to_txn', |
|
| 3080 | + 'TXN_ID' => $transaction->ID(), |
|
| 3081 | + 'EVT_ID' => $this->_reg_event->ID(), |
|
| 3082 | + 'event_name' => urlencode($this->_reg_event->name()), |
|
| 3083 | + 'redirect_from' => 'new_registration', |
|
| 3084 | + ]; |
|
| 3085 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3086 | + break; |
|
| 3087 | + } |
|
| 3088 | + // what are you looking here for? Should be nothing to do at this point. |
|
| 3089 | + } |
|
| 3090 | + |
|
| 3091 | + |
|
| 3092 | + /** |
|
| 3093 | + * redirect_to_txn |
|
| 3094 | + * |
|
| 3095 | + * @return void |
|
| 3096 | + * @throws EE_Error |
|
| 3097 | + * @throws InvalidArgumentException |
|
| 3098 | + * @throws InvalidDataTypeException |
|
| 3099 | + * @throws InvalidInterfaceException |
|
| 3100 | + * @throws ReflectionException |
|
| 3101 | + */ |
|
| 3102 | + public function redirect_to_txn() |
|
| 3103 | + { |
|
| 3104 | + EE_System::do_not_cache(); |
|
| 3105 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3106 | + $query_args = [ |
|
| 3107 | + 'action' => 'view_transaction', |
|
| 3108 | + 'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'), |
|
| 3109 | + 'page' => 'espresso_transactions', |
|
| 3110 | + ]; |
|
| 3111 | + if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) { |
|
| 3112 | + $query_args['EVT_ID'] = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 3113 | + $query_args['event_name'] = urlencode($this->request->getRequestParam('event_name')); |
|
| 3114 | + $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from'); |
|
| 3115 | + } |
|
| 3116 | + EE_Error::add_success( |
|
| 3117 | + esc_html__( |
|
| 3118 | + 'Registration Created. Please review the transaction and add any payments as necessary', |
|
| 3119 | + 'event_espresso' |
|
| 3120 | + ) |
|
| 3121 | + ); |
|
| 3122 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3123 | + } |
|
| 3124 | + |
|
| 3125 | + |
|
| 3126 | + /** |
|
| 3127 | + * generates HTML for the Attendee Contact List |
|
| 3128 | + * |
|
| 3129 | + * @return void |
|
| 3130 | + * @throws DomainException |
|
| 3131 | + * @throws EE_Error |
|
| 3132 | + */ |
|
| 3133 | + protected function _attendee_contact_list_table() |
|
| 3134 | + { |
|
| 3135 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3136 | + $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
| 3137 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 3138 | + } |
|
| 3139 | + |
|
| 3140 | + |
|
| 3141 | + /** |
|
| 3142 | + * get_attendees |
|
| 3143 | + * |
|
| 3144 | + * @param $per_page |
|
| 3145 | + * @param bool $count whether to return count or data. |
|
| 3146 | + * @param bool $trash |
|
| 3147 | + * @return array|int |
|
| 3148 | + * @throws EE_Error |
|
| 3149 | + * @throws InvalidArgumentException |
|
| 3150 | + * @throws InvalidDataTypeException |
|
| 3151 | + * @throws InvalidInterfaceException |
|
| 3152 | + */ |
|
| 3153 | + public function get_attendees($per_page, $count = false, $trash = false) |
|
| 3154 | + { |
|
| 3155 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3156 | + require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 3157 | + $orderby = $this->request->getRequestParam('orderby'); |
|
| 3158 | + switch ($orderby) { |
|
| 3159 | + case 'ATT_ID': |
|
| 3160 | + case 'ATT_fname': |
|
| 3161 | + case 'ATT_email': |
|
| 3162 | + case 'ATT_city': |
|
| 3163 | + case 'STA_ID': |
|
| 3164 | + case 'CNT_ID': |
|
| 3165 | + break; |
|
| 3166 | + case 'Registration_Count': |
|
| 3167 | + $orderby = 'Registration_Count'; |
|
| 3168 | + break; |
|
| 3169 | + default: |
|
| 3170 | + $orderby = 'ATT_lname'; |
|
| 3171 | + } |
|
| 3172 | + $sort = $this->request->getRequestParam('order', 'ASC'); |
|
| 3173 | + $current_page = $this->request->getRequestParam('paged', 1, 'int'); |
|
| 3174 | + $per_page = absint($per_page) ? $per_page : 10; |
|
| 3175 | + $per_page = $this->request->getRequestParam('perpage', $per_page, 'int'); |
|
| 3176 | + $_where = []; |
|
| 3177 | + $search_term = $this->request->getRequestParam('s'); |
|
| 3178 | + if ($search_term) { |
|
| 3179 | + $search_term = '%' . $search_term . '%'; |
|
| 3180 | + $_where['OR'] = [ |
|
| 3181 | + 'Registration.Event.EVT_name' => ['LIKE', $search_term], |
|
| 3182 | + 'Registration.Event.EVT_desc' => ['LIKE', $search_term], |
|
| 3183 | + 'Registration.Event.EVT_short_desc' => ['LIKE', $search_term], |
|
| 3184 | + 'ATT_fname' => ['LIKE', $search_term], |
|
| 3185 | + 'ATT_lname' => ['LIKE', $search_term], |
|
| 3186 | + 'ATT_short_bio' => ['LIKE', $search_term], |
|
| 3187 | + 'ATT_email' => ['LIKE', $search_term], |
|
| 3188 | + 'ATT_address' => ['LIKE', $search_term], |
|
| 3189 | + 'ATT_address2' => ['LIKE', $search_term], |
|
| 3190 | + 'ATT_city' => ['LIKE', $search_term], |
|
| 3191 | + 'Country.CNT_name' => ['LIKE', $search_term], |
|
| 3192 | + 'State.STA_name' => ['LIKE', $search_term], |
|
| 3193 | + 'ATT_phone' => ['LIKE', $search_term], |
|
| 3194 | + 'Registration.REG_final_price' => ['LIKE', $search_term], |
|
| 3195 | + 'Registration.REG_code' => ['LIKE', $search_term], |
|
| 3196 | + 'Registration.REG_group_size' => ['LIKE', $search_term], |
|
| 3197 | + ]; |
|
| 3198 | + } |
|
| 3199 | + $offset = ($current_page - 1) * $per_page; |
|
| 3200 | + $limit = $count ? null : [$offset, $per_page]; |
|
| 3201 | + $query_args = [ |
|
| 3202 | + $_where, |
|
| 3203 | + 'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']], |
|
| 3204 | + 'limit' => $limit, |
|
| 3205 | + ]; |
|
| 3206 | + if (! $count) { |
|
| 3207 | + $query_args['order_by'] = [$orderby => $sort]; |
|
| 3208 | + } |
|
| 3209 | + $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']]; |
|
| 3210 | + return $count |
|
| 3211 | + ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true) |
|
| 3212 | + : $this->getAttendeeModel()->get_all($query_args); |
|
| 3213 | + } |
|
| 3214 | + |
|
| 3215 | + |
|
| 3216 | + /** |
|
| 3217 | + * This is just taking care of resending the registration confirmation |
|
| 3218 | + * |
|
| 3219 | + * @return void |
|
| 3220 | + * @throws EE_Error |
|
| 3221 | + * @throws InvalidArgumentException |
|
| 3222 | + * @throws InvalidDataTypeException |
|
| 3223 | + * @throws InvalidInterfaceException |
|
| 3224 | + * @throws ReflectionException |
|
| 3225 | + */ |
|
| 3226 | + protected function _resend_registration() |
|
| 3227 | + { |
|
| 3228 | + $this->_process_resend_registration(); |
|
| 3229 | + $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 3230 | + $redirect_to = $this->request->getRequestParam('redirect_to'); |
|
| 3231 | + $query_args = $redirect_to |
|
| 3232 | + ? ['action' => $redirect_to, '_REG_ID' => $REG_ID] |
|
| 3233 | + : ['action' => 'default']; |
|
| 3234 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3235 | + } |
|
| 3236 | + |
|
| 3237 | + |
|
| 3238 | + /** |
|
| 3239 | + * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 3240 | + * to use when selecting registrations |
|
| 3241 | + * |
|
| 3242 | + * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 3243 | + * the query parameters from the request |
|
| 3244 | + * @return void ends the request with a redirect or download |
|
| 3245 | + */ |
|
| 3246 | + public function _registrations_report_base($method_name_for_getting_query_params) |
|
| 3247 | + { |
|
| 3248 | + $EVT_ID = $this->request->requestParamIsSet('EVT_ID') |
|
| 3249 | + ? $this->request->getRequestParam('EVT_ID', 0, 'int') |
|
| 3250 | + : null; |
|
| 3251 | + if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3252 | + $request_params = $this->request->requestParams(); |
|
| 3253 | + wp_redirect( |
|
| 3254 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 3255 | + [ |
|
| 3256 | + 'page' => 'espresso_batch', |
|
| 3257 | + 'batch' => 'file', |
|
| 3258 | + 'EVT_ID' => $EVT_ID, |
|
| 3259 | + 'filters' => urlencode( |
|
| 3260 | + serialize( |
|
| 3261 | + $this->$method_name_for_getting_query_params( |
|
| 3262 | + EEH_Array::is_set($request_params, 'filters', []) |
|
| 3263 | + ) |
|
| 3264 | + ) |
|
| 3265 | + ), |
|
| 3266 | + 'use_filters' => EEH_Array::is_set($request_params, 'use_filters', false), |
|
| 3267 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 3268 | + 'return_url' => urlencode($this->request->getRequestParam('return_url', '', 'url')), |
|
| 3269 | + ] |
|
| 3270 | + ) |
|
| 3271 | + ); |
|
| 3272 | + } else { |
|
| 3273 | + // Pull the current request params |
|
| 3274 | + $request_args = $this->request->requestParams(); |
|
| 3275 | + // Set the required request_args to be passed to the export |
|
| 3276 | + $required_request_args = [ |
|
| 3277 | + 'export' => 'report', |
|
| 3278 | + 'action' => 'registrations_report_for_event', |
|
| 3279 | + 'EVT_ID' => $EVT_ID, |
|
| 3280 | + ]; |
|
| 3281 | + // Merge required request args, overriding any currently set |
|
| 3282 | + $request_args = array_merge($request_args, $required_request_args); |
|
| 3283 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3284 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3285 | + $EE_Export = EE_Export::instance($request_args); |
|
| 3286 | + $EE_Export->export(); |
|
| 3287 | + } |
|
| 3288 | + } |
|
| 3289 | + } |
|
| 3290 | + |
|
| 3291 | + |
|
| 3292 | + /** |
|
| 3293 | + * Creates a registration report using only query parameters in the request |
|
| 3294 | + * |
|
| 3295 | + * @return void |
|
| 3296 | + */ |
|
| 3297 | + public function _registrations_report() |
|
| 3298 | + { |
|
| 3299 | + $this->_registrations_report_base('_get_registration_query_parameters'); |
|
| 3300 | + } |
|
| 3301 | + |
|
| 3302 | + |
|
| 3303 | + public function _contact_list_export() |
|
| 3304 | + { |
|
| 3305 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3306 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3307 | + $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
| 3308 | + $EE_Export->export_attendees(); |
|
| 3309 | + } |
|
| 3310 | + } |
|
| 3311 | + |
|
| 3312 | + |
|
| 3313 | + public function _contact_list_report() |
|
| 3314 | + { |
|
| 3315 | + if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3316 | + wp_redirect( |
|
| 3317 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 3318 | + [ |
|
| 3319 | + 'page' => 'espresso_batch', |
|
| 3320 | + 'batch' => 'file', |
|
| 3321 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 3322 | + 'return_url' => urlencode($this->request->getRequestParam('return_url', '', 'url')), |
|
| 3323 | + ] |
|
| 3324 | + ) |
|
| 3325 | + ); |
|
| 3326 | + } else { |
|
| 3327 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3328 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3329 | + $EE_Export = EE_Export::instance($this->request->requestParams()); |
|
| 3330 | + $EE_Export->report_attendees(); |
|
| 3331 | + } |
|
| 3332 | + } |
|
| 3333 | + } |
|
| 3334 | + |
|
| 3335 | + |
|
| 3336 | + |
|
| 3337 | + |
|
| 3338 | + |
|
| 3339 | + /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 3340 | + /** |
|
| 3341 | + * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 3342 | + * |
|
| 3343 | + * @return void |
|
| 3344 | + * @throws EE_Error |
|
| 3345 | + * @throws InvalidArgumentException |
|
| 3346 | + * @throws InvalidDataTypeException |
|
| 3347 | + * @throws InvalidInterfaceException |
|
| 3348 | + * @throws ReflectionException |
|
| 3349 | + */ |
|
| 3350 | + protected function _duplicate_attendee() |
|
| 3351 | + { |
|
| 3352 | + $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int'); |
|
| 3353 | + $action = $this->request->getRequestParam('return', 'default'); |
|
| 3354 | + // verify we have necessary info |
|
| 3355 | + if (! $REG_ID) { |
|
| 3356 | + EE_Error::add_error( |
|
| 3357 | + esc_html__( |
|
| 3358 | + 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 3359 | + 'event_espresso' |
|
| 3360 | + ), |
|
| 3361 | + __FILE__, |
|
| 3362 | + __LINE__, |
|
| 3363 | + __FUNCTION__ |
|
| 3364 | + ); |
|
| 3365 | + $query_args = ['action' => $action]; |
|
| 3366 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3367 | + } |
|
| 3368 | + // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 3369 | + $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID); |
|
| 3370 | + if (! $registration instanceof EE_Registration) { |
|
| 3371 | + throw new RuntimeException( |
|
| 3372 | + sprintf( |
|
| 3373 | + esc_html__( |
|
| 3374 | + 'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d', |
|
| 3375 | + 'event_espresso' |
|
| 3376 | + ), |
|
| 3377 | + $REG_ID |
|
| 3378 | + ) |
|
| 3379 | + ); |
|
| 3380 | + } |
|
| 3381 | + $attendee = $registration->attendee(); |
|
| 3382 | + // remove relation of existing attendee on registration |
|
| 3383 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 3384 | + // new attendee |
|
| 3385 | + $new_attendee = clone $attendee; |
|
| 3386 | + $new_attendee->set('ATT_ID', 0); |
|
| 3387 | + $new_attendee->save(); |
|
| 3388 | + // add new attendee to reg |
|
| 3389 | + $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 3390 | + EE_Error::add_success( |
|
| 3391 | + esc_html__( |
|
| 3392 | + 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 3393 | + 'event_espresso' |
|
| 3394 | + ) |
|
| 3395 | + ); |
|
| 3396 | + // redirect to edit page for attendee |
|
| 3397 | + $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee']; |
|
| 3398 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3399 | + } |
|
| 3400 | + |
|
| 3401 | + |
|
| 3402 | + /** |
|
| 3403 | + * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook. |
|
| 3404 | + * |
|
| 3405 | + * @param int $post_id |
|
| 3406 | + * @param WP_POST $post |
|
| 3407 | + * @throws DomainException |
|
| 3408 | + * @throws EE_Error |
|
| 3409 | + * @throws InvalidArgumentException |
|
| 3410 | + * @throws InvalidDataTypeException |
|
| 3411 | + * @throws InvalidInterfaceException |
|
| 3412 | + * @throws LogicException |
|
| 3413 | + * @throws InvalidFormSubmissionException |
|
| 3414 | + * @throws ReflectionException |
|
| 3415 | + */ |
|
| 3416 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 3417 | + { |
|
| 3418 | + $success = true; |
|
| 3419 | + $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees' |
|
| 3420 | + ? $this->getAttendeeModel()->get_one_by_ID($post_id) |
|
| 3421 | + : null; |
|
| 3422 | + // for attendee updates |
|
| 3423 | + if ($attendee instanceof EE_Attendee) { |
|
| 3424 | + // note we should only be UPDATING attendees at this point. |
|
| 3425 | + $fname = $this->request->getRequestParam('ATT_fname', ''); |
|
| 3426 | + $lname = $this->request->getRequestParam('ATT_lname', ''); |
|
| 3427 | + $updated_fields = [ |
|
| 3428 | + 'ATT_fname' => $fname, |
|
| 3429 | + 'ATT_lname' => $lname, |
|
| 3430 | + 'ATT_full_name' => "{$fname} {$lname}", |
|
| 3431 | + 'ATT_address' => $this->request->getRequestParam('ATT_address', ''), |
|
| 3432 | + 'ATT_address2' => $this->request->getRequestParam('ATT_address2', ''), |
|
| 3433 | + 'ATT_city' => $this->request->getRequestParam('ATT_city', ''), |
|
| 3434 | + 'STA_ID' => $this->request->getRequestParam('STA_ID', ''), |
|
| 3435 | + 'CNT_ISO' => $this->request->getRequestParam('CNT_ISO', ''), |
|
| 3436 | + 'ATT_zip' => $this->request->getRequestParam('ATT_zip', ''), |
|
| 3437 | + ]; |
|
| 3438 | + foreach ($updated_fields as $field => $value) { |
|
| 3439 | + $attendee->set($field, $value); |
|
| 3440 | + } |
|
| 3441 | + |
|
| 3442 | + // process contact details metabox form handler (which will also save the attendee) |
|
| 3443 | + $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee); |
|
| 3444 | + $success = $contact_details_form->process($this->request->requestParams()); |
|
| 3445 | + |
|
| 3446 | + $attendee_update_callbacks = apply_filters( |
|
| 3447 | + 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 3448 | + [] |
|
| 3449 | + ); |
|
| 3450 | + foreach ($attendee_update_callbacks as $a_callback) { |
|
| 3451 | + if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) { |
|
| 3452 | + throw new EE_Error( |
|
| 3453 | + sprintf( |
|
| 3454 | + esc_html__( |
|
| 3455 | + 'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 3456 | + 'event_espresso' |
|
| 3457 | + ), |
|
| 3458 | + $a_callback |
|
| 3459 | + ) |
|
| 3460 | + ); |
|
| 3461 | + } |
|
| 3462 | + } |
|
| 3463 | + } |
|
| 3464 | + |
|
| 3465 | + if ($success === false) { |
|
| 3466 | + EE_Error::add_error( |
|
| 3467 | + esc_html__( |
|
| 3468 | + 'Something went wrong with updating the meta table data for the registration.', |
|
| 3469 | + 'event_espresso' |
|
| 3470 | + ), |
|
| 3471 | + __FILE__, |
|
| 3472 | + __FUNCTION__, |
|
| 3473 | + __LINE__ |
|
| 3474 | + ); |
|
| 3475 | + } |
|
| 3476 | + } |
|
| 3477 | + |
|
| 3478 | + |
|
| 3479 | + public function trash_cpt_item($post_id) |
|
| 3480 | + { |
|
| 3481 | + } |
|
| 3482 | + |
|
| 3483 | + |
|
| 3484 | + public function delete_cpt_item($post_id) |
|
| 3485 | + { |
|
| 3486 | + } |
|
| 3487 | + |
|
| 3488 | + |
|
| 3489 | + public function restore_cpt_item($post_id) |
|
| 3490 | + { |
|
| 3491 | + } |
|
| 3492 | + |
|
| 3493 | + |
|
| 3494 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 3495 | + { |
|
| 3496 | + } |
|
| 3497 | + |
|
| 3498 | + |
|
| 3499 | + /** |
|
| 3500 | + * @throws EE_Error |
|
| 3501 | + * @throws ReflectionException |
|
| 3502 | + * @since 4.10.2.p |
|
| 3503 | + */ |
|
| 3504 | + public function attendee_editor_metaboxes() |
|
| 3505 | + { |
|
| 3506 | + $this->verify_cpt_object(); |
|
| 3507 | + remove_meta_box( |
|
| 3508 | + 'postexcerpt', |
|
| 3509 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3510 | + 'normal' |
|
| 3511 | + ); |
|
| 3512 | + remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal'); |
|
| 3513 | + if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 3514 | + $this->addMetaBox( |
|
| 3515 | + 'postexcerpt', |
|
| 3516 | + esc_html__('Short Biography', 'event_espresso'), |
|
| 3517 | + 'post_excerpt_meta_box', |
|
| 3518 | + $this->_cpt_routes[ $this->_req_action ] |
|
| 3519 | + ); |
|
| 3520 | + } |
|
| 3521 | + if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 3522 | + $this->addMetaBox( |
|
| 3523 | + 'commentsdiv', |
|
| 3524 | + esc_html__('Notes on the Contact', 'event_espresso'), |
|
| 3525 | + 'post_comment_meta_box', |
|
| 3526 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3527 | + 'normal', |
|
| 3528 | + 'core' |
|
| 3529 | + ); |
|
| 3530 | + } |
|
| 3531 | + $this->addMetaBox( |
|
| 3532 | + 'attendee_contact_info', |
|
| 3533 | + esc_html__('Contact Info', 'event_espresso'), |
|
| 3534 | + [$this, 'attendee_contact_info'], |
|
| 3535 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3536 | + 'side', |
|
| 3537 | + 'core' |
|
| 3538 | + ); |
|
| 3539 | + $this->addMetaBox( |
|
| 3540 | + 'attendee_details_address', |
|
| 3541 | + esc_html__('Address Details', 'event_espresso'), |
|
| 3542 | + [$this, 'attendee_address_details'], |
|
| 3543 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3544 | + 'normal', |
|
| 3545 | + 'core' |
|
| 3546 | + ); |
|
| 3547 | + $this->addMetaBox( |
|
| 3548 | + 'attendee_registrations', |
|
| 3549 | + esc_html__('Registrations for this Contact', 'event_espresso'), |
|
| 3550 | + [$this, 'attendee_registrations_meta_box'], |
|
| 3551 | + $this->_cpt_routes[ $this->_req_action ] |
|
| 3552 | + ); |
|
| 3553 | + } |
|
| 3554 | + |
|
| 3555 | + |
|
| 3556 | + /** |
|
| 3557 | + * Metabox for attendee contact info |
|
| 3558 | + * |
|
| 3559 | + * @param WP_Post $post wp post object |
|
| 3560 | + * @return void attendee contact info ( and form ) |
|
| 3561 | + * @throws EE_Error |
|
| 3562 | + * @throws InvalidArgumentException |
|
| 3563 | + * @throws InvalidDataTypeException |
|
| 3564 | + * @throws InvalidInterfaceException |
|
| 3565 | + * @throws LogicException |
|
| 3566 | + * @throws DomainException |
|
| 3567 | + */ |
|
| 3568 | + public function attendee_contact_info($post) |
|
| 3569 | + { |
|
| 3570 | + // get attendee object ( should already have it ) |
|
| 3571 | + $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj); |
|
| 3572 | + $form->enqueueStylesAndScripts(); |
|
| 3573 | + echo $form->display(); // already escaped |
|
| 3574 | + } |
|
| 3575 | + |
|
| 3576 | + |
|
| 3577 | + /** |
|
| 3578 | + * Return form handler for the contact details metabox |
|
| 3579 | + * |
|
| 3580 | + * @param EE_Attendee $attendee |
|
| 3581 | + * @return AttendeeContactDetailsMetaboxFormHandler |
|
| 3582 | + * @throws DomainException |
|
| 3583 | + * @throws InvalidArgumentException |
|
| 3584 | + * @throws InvalidDataTypeException |
|
| 3585 | + * @throws InvalidInterfaceException |
|
| 3586 | + */ |
|
| 3587 | + protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee) |
|
| 3588 | + { |
|
| 3589 | + return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance()); |
|
| 3590 | + } |
|
| 3591 | + |
|
| 3592 | + |
|
| 3593 | + /** |
|
| 3594 | + * Metabox for attendee details |
|
| 3595 | + * |
|
| 3596 | + * @param WP_Post $post wp post object |
|
| 3597 | + * @throws EE_Error |
|
| 3598 | + * @throws ReflectionException |
|
| 3599 | + */ |
|
| 3600 | + public function attendee_address_details($post) |
|
| 3601 | + { |
|
| 3602 | + // get attendee object (should already have it) |
|
| 3603 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3604 | + $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3605 | + new EE_Question_Form_Input( |
|
| 3606 | + EE_Question::new_instance( |
|
| 3607 | + [ |
|
| 3608 | + 'QST_ID' => 0, |
|
| 3609 | + 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
| 3610 | + 'QST_system' => 'admin-state', |
|
| 3611 | + ] |
|
| 3612 | + ), |
|
| 3613 | + EE_Answer::new_instance( |
|
| 3614 | + [ |
|
| 3615 | + 'ANS_ID' => 0, |
|
| 3616 | + 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 3617 | + ] |
|
| 3618 | + ), |
|
| 3619 | + [ |
|
| 3620 | + 'input_id' => 'STA_ID', |
|
| 3621 | + 'input_name' => 'STA_ID', |
|
| 3622 | + 'input_prefix' => '', |
|
| 3623 | + 'append_qstn_id' => false, |
|
| 3624 | + ] |
|
| 3625 | + ) |
|
| 3626 | + ); |
|
| 3627 | + $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3628 | + new EE_Question_Form_Input( |
|
| 3629 | + EE_Question::new_instance( |
|
| 3630 | + [ |
|
| 3631 | + 'QST_ID' => 0, |
|
| 3632 | + 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
| 3633 | + 'QST_system' => 'admin-country', |
|
| 3634 | + ] |
|
| 3635 | + ), |
|
| 3636 | + EE_Answer::new_instance( |
|
| 3637 | + [ |
|
| 3638 | + 'ANS_ID' => 0, |
|
| 3639 | + 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 3640 | + ] |
|
| 3641 | + ), |
|
| 3642 | + [ |
|
| 3643 | + 'input_id' => 'CNT_ISO', |
|
| 3644 | + 'input_name' => 'CNT_ISO', |
|
| 3645 | + 'input_prefix' => '', |
|
| 3646 | + 'append_qstn_id' => false, |
|
| 3647 | + ] |
|
| 3648 | + ) |
|
| 3649 | + ); |
|
| 3650 | + $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 3651 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3652 | + } |
|
| 3653 | + |
|
| 3654 | + |
|
| 3655 | + /** |
|
| 3656 | + * _attendee_details |
|
| 3657 | + * |
|
| 3658 | + * @param $post |
|
| 3659 | + * @return void |
|
| 3660 | + * @throws DomainException |
|
| 3661 | + * @throws EE_Error |
|
| 3662 | + * @throws InvalidArgumentException |
|
| 3663 | + * @throws InvalidDataTypeException |
|
| 3664 | + * @throws InvalidInterfaceException |
|
| 3665 | + * @throws ReflectionException |
|
| 3666 | + */ |
|
| 3667 | + public function attendee_registrations_meta_box($post) |
|
| 3668 | + { |
|
| 3669 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3670 | + $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 3671 | + $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 3672 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3673 | + } |
|
| 3674 | + |
|
| 3675 | + |
|
| 3676 | + /** |
|
| 3677 | + * add in the form fields for the attendee edit |
|
| 3678 | + * |
|
| 3679 | + * @param WP_Post $post wp post object |
|
| 3680 | + * @return void echos html for new form. |
|
| 3681 | + * @throws DomainException |
|
| 3682 | + */ |
|
| 3683 | + public function after_title_form_fields($post) |
|
| 3684 | + { |
|
| 3685 | + if ($post->post_type === 'espresso_attendees') { |
|
| 3686 | + $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 3687 | + $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3688 | + EEH_Template::display_template($template, $template_args); |
|
| 3689 | + } |
|
| 3690 | + } |
|
| 3691 | + |
|
| 3692 | + |
|
| 3693 | + /** |
|
| 3694 | + * _trash_or_restore_attendee |
|
| 3695 | + * |
|
| 3696 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 3697 | + * @return void |
|
| 3698 | + * @throws EE_Error |
|
| 3699 | + * @throws InvalidArgumentException |
|
| 3700 | + * @throws InvalidDataTypeException |
|
| 3701 | + * @throws InvalidInterfaceException |
|
| 3702 | + */ |
|
| 3703 | + protected function _trash_or_restore_attendees($trash = true) |
|
| 3704 | + { |
|
| 3705 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3706 | + $status = $trash ? 'trash' : 'publish'; |
|
| 3707 | + // Checkboxes |
|
| 3708 | + if ($this->request->requestParamIsSet('checkbox')) { |
|
| 3709 | + $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true); |
|
| 3710 | + // if array has more than one element than success message should be plural |
|
| 3711 | + $success = count($ATT_IDs) > 1 ? 2 : 1; |
|
| 3712 | + // cycle thru checkboxes |
|
| 3713 | + foreach ($ATT_IDs as $ATT_ID) { |
|
| 3714 | + $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID); |
|
| 3715 | + if (! $updated) { |
|
| 3716 | + $success = 0; |
|
| 3717 | + } |
|
| 3718 | + } |
|
| 3719 | + } else { |
|
| 3720 | + // grab single id and delete |
|
| 3721 | + $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int'); |
|
| 3722 | + // update attendee |
|
| 3723 | + $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0; |
|
| 3724 | + } |
|
| 3725 | + $what = $success > 1 |
|
| 3726 | + ? esc_html__('Contacts', 'event_espresso') |
|
| 3727 | + : esc_html__('Contact', 'event_espresso'); |
|
| 3728 | + $action_desc = $trash |
|
| 3729 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3730 | + : esc_html__('restored', 'event_espresso'); |
|
| 3731 | + $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']); |
|
| 3732 | + } |
|
| 3733 | 3733 | } |