@@ -7,36 +7,36 @@ discard block |
||
| 7 | 7 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
| 8 | 8 | |
| 9 | 9 | if (! function_exists('espresso_get_template_part')) { |
| 10 | - /** |
|
| 11 | - * espresso_get_template_part |
|
| 12 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
| 13 | - * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
| 14 | - * |
|
| 15 | - * @param string $slug The slug name for the generic template. |
|
| 16 | - * @param string $name The name of the specialised template. |
|
| 17 | - */ |
|
| 18 | - function espresso_get_template_part($slug = null, $name = null) |
|
| 19 | - { |
|
| 20 | - EEH_Template::get_template_part($slug, $name); |
|
| 21 | - } |
|
| 10 | + /** |
|
| 11 | + * espresso_get_template_part |
|
| 12 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
| 13 | + * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
| 14 | + * |
|
| 15 | + * @param string $slug The slug name for the generic template. |
|
| 16 | + * @param string $name The name of the specialised template. |
|
| 17 | + */ |
|
| 18 | + function espresso_get_template_part($slug = null, $name = null) |
|
| 19 | + { |
|
| 20 | + EEH_Template::get_template_part($slug, $name); |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | if (! function_exists('espresso_get_object_css_class')) { |
| 26 | - /** |
|
| 27 | - * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 28 | - * |
|
| 29 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 30 | - * @param string $prefix added to the beginning of the generated class |
|
| 31 | - * @param string $suffix added to the end of the generated class |
|
| 32 | - * @return string |
|
| 33 | - * @throws EE_Error |
|
| 34 | - * @throws ReflectionException |
|
| 35 | - */ |
|
| 36 | - function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 37 | - { |
|
| 38 | - return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
| 39 | - } |
|
| 26 | + /** |
|
| 27 | + * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 28 | + * |
|
| 29 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 30 | + * @param string $prefix added to the beginning of the generated class |
|
| 31 | + * @param string $suffix added to the end of the generated class |
|
| 32 | + * @return string |
|
| 33 | + * @throws EE_Error |
|
| 34 | + * @throws ReflectionException |
|
| 35 | + */ |
|
| 36 | + function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 37 | + { |
|
| 38 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -51,640 +51,640 @@ discard block |
||
| 51 | 51 | class EEH_Template |
| 52 | 52 | { |
| 53 | 53 | |
| 54 | - private static $_espresso_themes = []; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
| 59 | - * |
|
| 60 | - * @return boolean |
|
| 61 | - */ |
|
| 62 | - public static function is_espresso_theme() |
|
| 63 | - { |
|
| 64 | - return wp_get_theme()->get('TextDomain') === 'event_espresso'; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 70 | - * load its functions.php file ( if not already loaded ) |
|
| 71 | - * |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - public static function load_espresso_theme_functions() |
|
| 75 | - { |
|
| 76 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 77 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
| 78 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
| 86 | - * |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - public static function get_espresso_themes() |
|
| 90 | - { |
|
| 91 | - if (empty(EEH_Template::$_espresso_themes)) { |
|
| 92 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 93 | - if (empty($espresso_themes)) { |
|
| 94 | - return []; |
|
| 95 | - } |
|
| 96 | - if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
| 97 | - unset($espresso_themes[ $key ]); |
|
| 98 | - } |
|
| 99 | - EEH_Template::$_espresso_themes = []; |
|
| 100 | - foreach ($espresso_themes as $espresso_theme) { |
|
| 101 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - return EEH_Template::$_espresso_themes; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * EEH_Template::get_template_part |
|
| 110 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
| 111 | - * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
| 112 | - * filtering based off of the entire template part name |
|
| 113 | - * |
|
| 114 | - * @param string $slug The slug name for the generic template. |
|
| 115 | - * @param string $name The name of the specialised template. |
|
| 116 | - * @param array $template_args |
|
| 117 | - * @param bool $return_string |
|
| 118 | - * @return string the html output for the formatted money value |
|
| 119 | - */ |
|
| 120 | - public static function get_template_part( |
|
| 121 | - $slug = null, |
|
| 122 | - $name = null, |
|
| 123 | - $template_args = [], |
|
| 124 | - $return_string = false |
|
| 125 | - ) { |
|
| 126 | - do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
| 127 | - $templates = []; |
|
| 128 | - $name = (string) $name; |
|
| 129 | - if ($name != '') { |
|
| 130 | - $templates[] = "{$slug}-{$name}.php"; |
|
| 131 | - } |
|
| 132 | - // allow template parts to be turned off via something like: |
|
| 133 | - // add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
| 134 | - if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
| 135 | - return EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
| 136 | - } |
|
| 137 | - return ''; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * locate_template |
|
| 143 | - * locate a template file by looking in the following places, in the following order: |
|
| 144 | - * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
| 145 | - * <assumed full absolute server path> |
|
| 146 | - * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
| 147 | - * <server path up to>/wp-content/uploads/espresso/templates/ |
|
| 148 | - * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
| 149 | - * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
| 150 | - * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
| 151 | - * as soon as the template is found in one of these locations, it will be returned or loaded |
|
| 152 | - * Example: |
|
| 153 | - * You are using the WordPress Twenty Sixteen theme, |
|
| 154 | - * and you want to customize the "some-event.template.php" template, |
|
| 155 | - * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
| 156 | - * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
| 157 | - * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
| 158 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 159 | - * /relative/path/to/some-event.template.php |
|
| 160 | - * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 161 | - * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
| 162 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 163 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 164 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
| 165 | - * Had you passed an absolute path to your template that was in some other location, |
|
| 166 | - * ie: "/absolute/path/to/some-event.template.php" |
|
| 167 | - * then the search would have been : |
|
| 168 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 169 | - * /absolute/path/to/some-event.template.php |
|
| 170 | - * and stopped there upon finding it in the second location |
|
| 171 | - * |
|
| 172 | - * @param array|string $templates array of template file names including extension (or just a single string) |
|
| 173 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 174 | - * @param boolean $load whether to pass the located template path on to the |
|
| 175 | - * EEH_Template::display_template() method or simply return it |
|
| 176 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 177 | - * string |
|
| 178 | - * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
| 179 | - * generate a custom template or not. Used in places where you don't actually |
|
| 180 | - * load the template, you just want to know if there's a custom version of it. |
|
| 181 | - * @return mixed |
|
| 182 | - * @throws DomainException |
|
| 183 | - * @throws InvalidArgumentException |
|
| 184 | - * @throws InvalidDataTypeException |
|
| 185 | - * @throws InvalidInterfaceException |
|
| 186 | - */ |
|
| 187 | - public static function locate_template( |
|
| 188 | - $templates = [], |
|
| 189 | - $template_args = [], |
|
| 190 | - $load = true, |
|
| 191 | - $return_string = true, |
|
| 192 | - $check_if_custom = false |
|
| 193 | - ) { |
|
| 194 | - // first use WP locate_template to check for template in the current theme folder |
|
| 195 | - $template_path = locate_template($templates); |
|
| 196 | - |
|
| 197 | - if ($check_if_custom && ! empty($template_path)) { |
|
| 198 | - return true; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // not in the theme |
|
| 202 | - if (empty($template_path)) { |
|
| 203 | - // not even a template to look for ? |
|
| 204 | - if (empty($templates)) { |
|
| 205 | - $loader = LoaderFactory::getLoader(); |
|
| 206 | - /** @var RequestInterface $request */ |
|
| 207 | - $request = $loader->getShared(RequestInterface::class); |
|
| 208 | - // get post_type |
|
| 209 | - $post_type = $request->getRequestParam('post_type'); |
|
| 210 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 211 | - $custom_post_types = $loader->getShared( |
|
| 212 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 213 | - ); |
|
| 214 | - // get array of EE Custom Post Types |
|
| 215 | - $EE_CPTs = $custom_post_types->getDefinitions(); |
|
| 216 | - // build template name based on request |
|
| 217 | - if (isset($EE_CPTs[ $post_type ])) { |
|
| 218 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
| 219 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
| 220 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - // currently active EE template theme |
|
| 224 | - $current_theme = EE_Config::get_current_theme(); |
|
| 225 | - |
|
| 226 | - // array of paths to folders that may contain templates |
|
| 227 | - $template_folder_paths = [ |
|
| 228 | - // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
| 229 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 230 | - // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
| 231 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 232 | - ]; |
|
| 233 | - |
|
| 234 | - // add core plugin folders for checking only if we're not $check_if_custom |
|
| 235 | - if (! $check_if_custom) { |
|
| 236 | - $core_paths = [ |
|
| 237 | - // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
| 238 | - EE_PUBLIC . $current_theme, |
|
| 239 | - // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
| 240 | - EE_TEMPLATES . $current_theme, |
|
| 241 | - // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
| 242 | - EE_PLUGIN_DIR_PATH, |
|
| 243 | - ]; |
|
| 244 | - $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - // now filter that array |
|
| 248 | - $template_folder_paths = apply_filters( |
|
| 249 | - 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
| 250 | - $template_folder_paths |
|
| 251 | - ); |
|
| 252 | - $templates = is_array($templates) ? $templates : [$templates]; |
|
| 253 | - $template_folder_paths = |
|
| 254 | - is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths]; |
|
| 255 | - // array to hold all possible template paths |
|
| 256 | - $full_template_paths = []; |
|
| 257 | - $file_name = ''; |
|
| 258 | - |
|
| 259 | - // loop through $templates |
|
| 260 | - foreach ($templates as $template) { |
|
| 261 | - // normalize directory separators |
|
| 262 | - $template = EEH_File::standardise_directory_separators($template); |
|
| 263 | - $file_name = basename($template); |
|
| 264 | - $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
| 265 | - // while looping through all template folder paths |
|
| 266 | - foreach ($template_folder_paths as $template_folder_path) { |
|
| 267 | - // normalize directory separators |
|
| 268 | - $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
| 269 | - // determine if any common base path exists between the two paths |
|
| 270 | - $common_base_path = EEH_Template::_find_common_base_path( |
|
| 271 | - [$template_folder_path, $template_path_minus_file_name] |
|
| 272 | - ); |
|
| 273 | - if ($common_base_path !== '') { |
|
| 274 | - // both paths have a common base, so just tack the filename onto our search path |
|
| 275 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 276 | - } else { |
|
| 277 | - // no common base path, so let's just concatenate |
|
| 278 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 279 | - } |
|
| 280 | - // build up our template locations array by adding our resolved paths |
|
| 281 | - $full_template_paths[] = $resolved_path; |
|
| 282 | - } |
|
| 283 | - // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
| 284 | - array_unshift($full_template_paths, $template); |
|
| 285 | - // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
| 286 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
| 287 | - } |
|
| 288 | - // filter final array of full template paths |
|
| 289 | - $full_template_paths = apply_filters( |
|
| 290 | - 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
| 291 | - $full_template_paths, |
|
| 292 | - $file_name |
|
| 293 | - ); |
|
| 294 | - // now loop through our final array of template location paths and check each location |
|
| 295 | - foreach ((array) $full_template_paths as $full_template_path) { |
|
| 296 | - if (is_readable($full_template_path)) { |
|
| 297 | - $template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path); |
|
| 298 | - break; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // hook that can be used to display the full template path that will be used |
|
| 304 | - do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
| 305 | - |
|
| 306 | - // if we got it and you want to see it... |
|
| 307 | - if ($template_path && $load && ! $check_if_custom) { |
|
| 308 | - if ($return_string) { |
|
| 309 | - return EEH_Template::display_template($template_path, $template_args, true); |
|
| 310 | - } |
|
| 311 | - EEH_Template::display_template($template_path, $template_args); |
|
| 312 | - } |
|
| 313 | - return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * _find_common_base_path |
|
| 319 | - * given two paths, this determines if there is a common base path between the two |
|
| 320 | - * |
|
| 321 | - * @param array $paths |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 324 | - protected static function _find_common_base_path($paths) |
|
| 325 | - { |
|
| 326 | - $last_offset = 0; |
|
| 327 | - $common_base_path = ''; |
|
| 328 | - while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
| 329 | - $dir_length = $index - $last_offset + 1; |
|
| 330 | - $directory = substr($paths[0], $last_offset, $dir_length); |
|
| 331 | - foreach ($paths as $path) { |
|
| 332 | - if (substr($path, $last_offset, $dir_length) != $directory) { |
|
| 333 | - return $common_base_path; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - $common_base_path .= $directory; |
|
| 337 | - $last_offset = $index + 1; |
|
| 338 | - } |
|
| 339 | - return substr($common_base_path, 0, -1); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * load and display a template |
|
| 345 | - * |
|
| 346 | - * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
| 347 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 348 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 349 | - * string |
|
| 350 | - * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
| 351 | - * not found or is not readable |
|
| 352 | - * @return string |
|
| 353 | - * @throws DomainException |
|
| 354 | - */ |
|
| 355 | - public static function display_template( |
|
| 356 | - $template_path = false, |
|
| 357 | - $template_args = [], |
|
| 358 | - $return_string = false, |
|
| 359 | - $throw_exceptions = false |
|
| 360 | - ) { |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
| 364 | - * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
| 365 | - * the display_template method are templates we DON'T want modified (usually because of js |
|
| 366 | - * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
| 367 | - * using this. |
|
| 368 | - * |
|
| 369 | - * @since 4.6.0 |
|
| 370 | - */ |
|
| 371 | - $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
| 372 | - $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
| 373 | - |
|
| 374 | - // you gimme nuttin - YOU GET NUTTIN !! |
|
| 375 | - if (! $template_path || ! is_readable($template_path)) { |
|
| 376 | - // ignore whether template is accessible ? |
|
| 377 | - if ($throw_exceptions) { |
|
| 378 | - throw new DomainException( |
|
| 379 | - esc_html__('Invalid, unreadable, or missing file.', 'event_espresso') |
|
| 380 | - ); |
|
| 381 | - } |
|
| 382 | - return ''; |
|
| 383 | - } |
|
| 384 | - // if $template_args are not in an array, then make it so |
|
| 385 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
| 386 | - $template_args = [$template_args]; |
|
| 387 | - } |
|
| 388 | - extract($template_args, EXTR_SKIP); |
|
| 389 | - |
|
| 390 | - if ($return_string) { |
|
| 391 | - // because we want to return a string, we are going to capture the output |
|
| 392 | - ob_start(); |
|
| 393 | - include($template_path); |
|
| 394 | - return ob_get_clean(); |
|
| 395 | - } |
|
| 396 | - include($template_path); |
|
| 397 | - return ''; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 403 | - * |
|
| 404 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 405 | - * @param string $prefix added to the beginning of the generated class |
|
| 406 | - * @param string $suffix added to the end of the generated class |
|
| 407 | - * @return string |
|
| 408 | - * @throws EE_Error |
|
| 409 | - * @throws ReflectionException |
|
| 410 | - */ |
|
| 411 | - public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 412 | - { |
|
| 413 | - // in the beginning... |
|
| 414 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 415 | - // da muddle |
|
| 416 | - $class = ''; |
|
| 417 | - // the end |
|
| 418 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 419 | - // is the passed object an EE object ? |
|
| 420 | - if ($object instanceof EE_Base_Class) { |
|
| 421 | - // grab the exact type of object |
|
| 422 | - $obj_class = get_class($object); |
|
| 423 | - // depending on the type of object... |
|
| 424 | - switch ($obj_class) { |
|
| 425 | - // no specifics just yet... |
|
| 426 | - default: |
|
| 427 | - $class = strtolower(str_replace('_', '-', $obj_class)); |
|
| 428 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - return $prefix . $class . $suffix; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * EEH_Template::format_currency |
|
| 437 | - * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
| 438 | - * the country currency settings from the supplied country ISO code |
|
| 439 | - * |
|
| 440 | - * @param float $amount raw money value |
|
| 441 | - * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
| 442 | - * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
| 443 | - * @param string $CNT_ISO 2 letter ISO code for a country |
|
| 444 | - * @param string $cur_code_span_class |
|
| 445 | - * @return string the html output for the formatted money value |
|
| 446 | - */ |
|
| 447 | - public static function format_currency( |
|
| 448 | - $amount = null, |
|
| 449 | - $return_raw = false, |
|
| 450 | - $display_code = true, |
|
| 451 | - $CNT_ISO = '', |
|
| 452 | - $cur_code_span_class = 'currency-code' |
|
| 453 | - ) { |
|
| 454 | - // ensure amount was received |
|
| 455 | - if ($amount === null) { |
|
| 456 | - $msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
| 457 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 458 | - return ''; |
|
| 459 | - } |
|
| 460 | - // ensure amount is float |
|
| 461 | - $amount = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
| 462 | - $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
| 463 | - // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
| 464 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
| 465 | - // still a number, or was amount converted to a string like "free" ? |
|
| 466 | - if (! is_float($amount_formatted)) { |
|
| 467 | - return esc_html($amount_formatted); |
|
| 468 | - } |
|
| 469 | - try { |
|
| 470 | - // was a country ISO code passed ? if so generate currency config object for that country |
|
| 471 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
| 472 | - } catch (Exception $e) { |
|
| 473 | - // eat exception |
|
| 474 | - $mny = null; |
|
| 475 | - } |
|
| 476 | - // verify results |
|
| 477 | - if (! $mny instanceof EE_Currency_Config) { |
|
| 478 | - // set default config country currency settings |
|
| 479 | - $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
| 480 | - ? EE_Registry::instance()->CFG->currency |
|
| 481 | - : new EE_Currency_Config(); |
|
| 482 | - } |
|
| 483 | - // format float |
|
| 484 | - $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
| 485 | - // add formatting ? |
|
| 486 | - if (! $return_raw) { |
|
| 487 | - // add currency sign |
|
| 488 | - if ($mny->sign_b4) { |
|
| 489 | - if ($amount >= 0) { |
|
| 490 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
| 491 | - } else { |
|
| 492 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 493 | - } |
|
| 494 | - } else { |
|
| 495 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - // filter to allow global setting of display_code |
|
| 499 | - $display_code = (bool) apply_filters( |
|
| 500 | - 'FHEE__EEH_Template__format_currency__display_code', |
|
| 501 | - $display_code |
|
| 502 | - ); |
|
| 503 | - |
|
| 504 | - // add currency code ? |
|
| 505 | - $amount_formatted = $display_code |
|
| 506 | - ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' |
|
| 507 | - : $amount_formatted; |
|
| 508 | - } |
|
| 509 | - // filter results |
|
| 510 | - $amount_formatted = apply_filters( |
|
| 511 | - 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
| 512 | - $amount_formatted, |
|
| 513 | - $mny, |
|
| 514 | - $return_raw |
|
| 515 | - ); |
|
| 516 | - // clean up vars |
|
| 517 | - unset($mny); |
|
| 518 | - // return formatted currency amount |
|
| 519 | - return $amount_formatted; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
| 525 | - * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
| 526 | - * related status model or model object (i.e. in documentation etc.) |
|
| 527 | - * |
|
| 528 | - * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
| 529 | - * match, then 'Unknown' will be returned. |
|
| 530 | - * @param boolean $plural Whether to return plural or not |
|
| 531 | - * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
| 532 | - * @return string The localized label for the status id. |
|
| 533 | - * @throws EE_Error |
|
| 534 | - */ |
|
| 535 | - public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
| 536 | - { |
|
| 537 | - $status = EEM_Status::instance()->localized_status( |
|
| 538 | - [$status_id => esc_html__('unknown', 'event_espresso')], |
|
| 539 | - $plural, |
|
| 540 | - $schema |
|
| 541 | - ); |
|
| 542 | - return $status[ $status_id ]; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * This helper just returns a button or link for the given parameters |
|
| 548 | - * |
|
| 549 | - * @param string $url the url for the link, note that `esc_url` will be called on it |
|
| 550 | - * @param string $label What is the label you want displayed for the button |
|
| 551 | - * @param string $class what class is used for the button (defaults to 'button-primary') |
|
| 552 | - * @param string $icon |
|
| 553 | - * @param string $title |
|
| 554 | - * @return string the html output for the button |
|
| 555 | - */ |
|
| 556 | - public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '') |
|
| 557 | - { |
|
| 558 | - $icon_html = ''; |
|
| 559 | - if (! empty($icon)) { |
|
| 560 | - $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
| 561 | - $dashicons = array_filter($dashicons); |
|
| 562 | - $count = count($dashicons); |
|
| 563 | - $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
| 564 | - foreach ($dashicons as $dashicon) { |
|
| 565 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 566 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 567 | - } |
|
| 568 | - $icon_html .= $count > 1 ? '</span>' : ''; |
|
| 569 | - } |
|
| 570 | - // sanitize & escape |
|
| 571 | - $id = sanitize_title_with_dashes($label); |
|
| 572 | - $url = esc_url_raw($url); |
|
| 573 | - $class = esc_attr($class); |
|
| 574 | - $title = esc_attr($title); |
|
| 575 | - $label = esc_html($label); |
|
| 576 | - return "<a id='{$id}' href='{$url}' class='{$class}' title='{$title}'>{$icon_html}{$label}</a>"; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * This returns a generated link that will load the related help tab on admin pages. |
|
| 582 | - * |
|
| 583 | - * @param string $help_tab_id the id for the connected help tab |
|
| 584 | - * @param bool|string $page The page identifier for the page the help tab is on |
|
| 585 | - * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
| 586 | - * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 587 | - * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 588 | - * @return string generated link |
|
| 589 | - */ |
|
| 590 | - public static function get_help_tab_link( |
|
| 591 | - $help_tab_id, |
|
| 592 | - $page = false, |
|
| 593 | - $action = false, |
|
| 594 | - $icon_style = false, |
|
| 595 | - $help_text = false |
|
| 596 | - ) { |
|
| 597 | - $allowedtags = AllowedTags::getAllowedTags(); |
|
| 598 | - /** @var RequestInterface $request */ |
|
| 599 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 600 | - $page = $page ?: $request->getRequestParam('page', '', 'key'); |
|
| 601 | - $action = $action ?: $request->getRequestParam('action', 'default', 'key'); |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 605 | - $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
| 606 | - $help_text = ! $help_text ? '' : $help_text; |
|
| 607 | - return '<a id="' |
|
| 608 | - . esc_attr($help_tab_lnk) |
|
| 609 | - . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' |
|
| 610 | - . esc_attr($icon) |
|
| 611 | - . '" title="' |
|
| 612 | - . esc_attr__( |
|
| 613 | - 'Click to open the \'Help\' tab for more information about this feature.', |
|
| 614 | - 'event_espresso' |
|
| 615 | - ) |
|
| 616 | - . '" > ' |
|
| 617 | - . wp_kses($help_text, $allowedtags) |
|
| 618 | - . ' </a>'; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * This is a helper method to generate a status legend for a given status array. |
|
| 624 | - * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
| 625 | - * status_array. |
|
| 626 | - * |
|
| 627 | - * @param array $status_array array of statuses that will make up the legend. In format: |
|
| 628 | - * array( |
|
| 629 | - * 'status_item' => 'status_name' |
|
| 630 | - * ) |
|
| 631 | - * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
| 632 | - * the legend. |
|
| 633 | - * @return string html structure for status. |
|
| 634 | - * @throws EE_Error |
|
| 635 | - */ |
|
| 636 | - public static function status_legend($status_array, $active_status = '') |
|
| 637 | - { |
|
| 638 | - if (! is_array($status_array)) { |
|
| 639 | - throw new EE_Error( |
|
| 640 | - esc_html__( |
|
| 641 | - 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
| 642 | - 'event_espresso' |
|
| 643 | - ) |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - $content = ' |
|
| 54 | + private static $_espresso_themes = []; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
| 59 | + * |
|
| 60 | + * @return boolean |
|
| 61 | + */ |
|
| 62 | + public static function is_espresso_theme() |
|
| 63 | + { |
|
| 64 | + return wp_get_theme()->get('TextDomain') === 'event_espresso'; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 70 | + * load its functions.php file ( if not already loaded ) |
|
| 71 | + * |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + public static function load_espresso_theme_functions() |
|
| 75 | + { |
|
| 76 | + if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 77 | + if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
| 78 | + require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
| 86 | + * |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + public static function get_espresso_themes() |
|
| 90 | + { |
|
| 91 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
| 92 | + $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 93 | + if (empty($espresso_themes)) { |
|
| 94 | + return []; |
|
| 95 | + } |
|
| 96 | + if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
| 97 | + unset($espresso_themes[ $key ]); |
|
| 98 | + } |
|
| 99 | + EEH_Template::$_espresso_themes = []; |
|
| 100 | + foreach ($espresso_themes as $espresso_theme) { |
|
| 101 | + EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + return EEH_Template::$_espresso_themes; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * EEH_Template::get_template_part |
|
| 110 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
| 111 | + * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
| 112 | + * filtering based off of the entire template part name |
|
| 113 | + * |
|
| 114 | + * @param string $slug The slug name for the generic template. |
|
| 115 | + * @param string $name The name of the specialised template. |
|
| 116 | + * @param array $template_args |
|
| 117 | + * @param bool $return_string |
|
| 118 | + * @return string the html output for the formatted money value |
|
| 119 | + */ |
|
| 120 | + public static function get_template_part( |
|
| 121 | + $slug = null, |
|
| 122 | + $name = null, |
|
| 123 | + $template_args = [], |
|
| 124 | + $return_string = false |
|
| 125 | + ) { |
|
| 126 | + do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
| 127 | + $templates = []; |
|
| 128 | + $name = (string) $name; |
|
| 129 | + if ($name != '') { |
|
| 130 | + $templates[] = "{$slug}-{$name}.php"; |
|
| 131 | + } |
|
| 132 | + // allow template parts to be turned off via something like: |
|
| 133 | + // add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
| 134 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
| 135 | + return EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
| 136 | + } |
|
| 137 | + return ''; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * locate_template |
|
| 143 | + * locate a template file by looking in the following places, in the following order: |
|
| 144 | + * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
| 145 | + * <assumed full absolute server path> |
|
| 146 | + * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
| 147 | + * <server path up to>/wp-content/uploads/espresso/templates/ |
|
| 148 | + * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
| 149 | + * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
| 150 | + * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
| 151 | + * as soon as the template is found in one of these locations, it will be returned or loaded |
|
| 152 | + * Example: |
|
| 153 | + * You are using the WordPress Twenty Sixteen theme, |
|
| 154 | + * and you want to customize the "some-event.template.php" template, |
|
| 155 | + * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
| 156 | + * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
| 157 | + * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
| 158 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 159 | + * /relative/path/to/some-event.template.php |
|
| 160 | + * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 161 | + * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
| 162 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 163 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
| 164 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
| 165 | + * Had you passed an absolute path to your template that was in some other location, |
|
| 166 | + * ie: "/absolute/path/to/some-event.template.php" |
|
| 167 | + * then the search would have been : |
|
| 168 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
| 169 | + * /absolute/path/to/some-event.template.php |
|
| 170 | + * and stopped there upon finding it in the second location |
|
| 171 | + * |
|
| 172 | + * @param array|string $templates array of template file names including extension (or just a single string) |
|
| 173 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 174 | + * @param boolean $load whether to pass the located template path on to the |
|
| 175 | + * EEH_Template::display_template() method or simply return it |
|
| 176 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 177 | + * string |
|
| 178 | + * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
| 179 | + * generate a custom template or not. Used in places where you don't actually |
|
| 180 | + * load the template, you just want to know if there's a custom version of it. |
|
| 181 | + * @return mixed |
|
| 182 | + * @throws DomainException |
|
| 183 | + * @throws InvalidArgumentException |
|
| 184 | + * @throws InvalidDataTypeException |
|
| 185 | + * @throws InvalidInterfaceException |
|
| 186 | + */ |
|
| 187 | + public static function locate_template( |
|
| 188 | + $templates = [], |
|
| 189 | + $template_args = [], |
|
| 190 | + $load = true, |
|
| 191 | + $return_string = true, |
|
| 192 | + $check_if_custom = false |
|
| 193 | + ) { |
|
| 194 | + // first use WP locate_template to check for template in the current theme folder |
|
| 195 | + $template_path = locate_template($templates); |
|
| 196 | + |
|
| 197 | + if ($check_if_custom && ! empty($template_path)) { |
|
| 198 | + return true; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // not in the theme |
|
| 202 | + if (empty($template_path)) { |
|
| 203 | + // not even a template to look for ? |
|
| 204 | + if (empty($templates)) { |
|
| 205 | + $loader = LoaderFactory::getLoader(); |
|
| 206 | + /** @var RequestInterface $request */ |
|
| 207 | + $request = $loader->getShared(RequestInterface::class); |
|
| 208 | + // get post_type |
|
| 209 | + $post_type = $request->getRequestParam('post_type'); |
|
| 210 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
| 211 | + $custom_post_types = $loader->getShared( |
|
| 212 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 213 | + ); |
|
| 214 | + // get array of EE Custom Post Types |
|
| 215 | + $EE_CPTs = $custom_post_types->getDefinitions(); |
|
| 216 | + // build template name based on request |
|
| 217 | + if (isset($EE_CPTs[ $post_type ])) { |
|
| 218 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
| 219 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
| 220 | + $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + // currently active EE template theme |
|
| 224 | + $current_theme = EE_Config::get_current_theme(); |
|
| 225 | + |
|
| 226 | + // array of paths to folders that may contain templates |
|
| 227 | + $template_folder_paths = [ |
|
| 228 | + // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
| 229 | + EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 230 | + // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
| 231 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 232 | + ]; |
|
| 233 | + |
|
| 234 | + // add core plugin folders for checking only if we're not $check_if_custom |
|
| 235 | + if (! $check_if_custom) { |
|
| 236 | + $core_paths = [ |
|
| 237 | + // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
| 238 | + EE_PUBLIC . $current_theme, |
|
| 239 | + // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
| 240 | + EE_TEMPLATES . $current_theme, |
|
| 241 | + // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
| 242 | + EE_PLUGIN_DIR_PATH, |
|
| 243 | + ]; |
|
| 244 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + // now filter that array |
|
| 248 | + $template_folder_paths = apply_filters( |
|
| 249 | + 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
| 250 | + $template_folder_paths |
|
| 251 | + ); |
|
| 252 | + $templates = is_array($templates) ? $templates : [$templates]; |
|
| 253 | + $template_folder_paths = |
|
| 254 | + is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths]; |
|
| 255 | + // array to hold all possible template paths |
|
| 256 | + $full_template_paths = []; |
|
| 257 | + $file_name = ''; |
|
| 258 | + |
|
| 259 | + // loop through $templates |
|
| 260 | + foreach ($templates as $template) { |
|
| 261 | + // normalize directory separators |
|
| 262 | + $template = EEH_File::standardise_directory_separators($template); |
|
| 263 | + $file_name = basename($template); |
|
| 264 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
| 265 | + // while looping through all template folder paths |
|
| 266 | + foreach ($template_folder_paths as $template_folder_path) { |
|
| 267 | + // normalize directory separators |
|
| 268 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
| 269 | + // determine if any common base path exists between the two paths |
|
| 270 | + $common_base_path = EEH_Template::_find_common_base_path( |
|
| 271 | + [$template_folder_path, $template_path_minus_file_name] |
|
| 272 | + ); |
|
| 273 | + if ($common_base_path !== '') { |
|
| 274 | + // both paths have a common base, so just tack the filename onto our search path |
|
| 275 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 276 | + } else { |
|
| 277 | + // no common base path, so let's just concatenate |
|
| 278 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 279 | + } |
|
| 280 | + // build up our template locations array by adding our resolved paths |
|
| 281 | + $full_template_paths[] = $resolved_path; |
|
| 282 | + } |
|
| 283 | + // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
| 284 | + array_unshift($full_template_paths, $template); |
|
| 285 | + // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
| 286 | + array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
| 287 | + } |
|
| 288 | + // filter final array of full template paths |
|
| 289 | + $full_template_paths = apply_filters( |
|
| 290 | + 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
| 291 | + $full_template_paths, |
|
| 292 | + $file_name |
|
| 293 | + ); |
|
| 294 | + // now loop through our final array of template location paths and check each location |
|
| 295 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
| 296 | + if (is_readable($full_template_path)) { |
|
| 297 | + $template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path); |
|
| 298 | + break; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // hook that can be used to display the full template path that will be used |
|
| 304 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
| 305 | + |
|
| 306 | + // if we got it and you want to see it... |
|
| 307 | + if ($template_path && $load && ! $check_if_custom) { |
|
| 308 | + if ($return_string) { |
|
| 309 | + return EEH_Template::display_template($template_path, $template_args, true); |
|
| 310 | + } |
|
| 311 | + EEH_Template::display_template($template_path, $template_args); |
|
| 312 | + } |
|
| 313 | + return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * _find_common_base_path |
|
| 319 | + * given two paths, this determines if there is a common base path between the two |
|
| 320 | + * |
|
| 321 | + * @param array $paths |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | + protected static function _find_common_base_path($paths) |
|
| 325 | + { |
|
| 326 | + $last_offset = 0; |
|
| 327 | + $common_base_path = ''; |
|
| 328 | + while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
| 329 | + $dir_length = $index - $last_offset + 1; |
|
| 330 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
| 331 | + foreach ($paths as $path) { |
|
| 332 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
| 333 | + return $common_base_path; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + $common_base_path .= $directory; |
|
| 337 | + $last_offset = $index + 1; |
|
| 338 | + } |
|
| 339 | + return substr($common_base_path, 0, -1); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * load and display a template |
|
| 345 | + * |
|
| 346 | + * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
| 347 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
| 348 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
| 349 | + * string |
|
| 350 | + * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
| 351 | + * not found or is not readable |
|
| 352 | + * @return string |
|
| 353 | + * @throws DomainException |
|
| 354 | + */ |
|
| 355 | + public static function display_template( |
|
| 356 | + $template_path = false, |
|
| 357 | + $template_args = [], |
|
| 358 | + $return_string = false, |
|
| 359 | + $throw_exceptions = false |
|
| 360 | + ) { |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
| 364 | + * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
| 365 | + * the display_template method are templates we DON'T want modified (usually because of js |
|
| 366 | + * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
| 367 | + * using this. |
|
| 368 | + * |
|
| 369 | + * @since 4.6.0 |
|
| 370 | + */ |
|
| 371 | + $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
| 372 | + $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
| 373 | + |
|
| 374 | + // you gimme nuttin - YOU GET NUTTIN !! |
|
| 375 | + if (! $template_path || ! is_readable($template_path)) { |
|
| 376 | + // ignore whether template is accessible ? |
|
| 377 | + if ($throw_exceptions) { |
|
| 378 | + throw new DomainException( |
|
| 379 | + esc_html__('Invalid, unreadable, or missing file.', 'event_espresso') |
|
| 380 | + ); |
|
| 381 | + } |
|
| 382 | + return ''; |
|
| 383 | + } |
|
| 384 | + // if $template_args are not in an array, then make it so |
|
| 385 | + if (! is_array($template_args) && ! is_object($template_args)) { |
|
| 386 | + $template_args = [$template_args]; |
|
| 387 | + } |
|
| 388 | + extract($template_args, EXTR_SKIP); |
|
| 389 | + |
|
| 390 | + if ($return_string) { |
|
| 391 | + // because we want to return a string, we are going to capture the output |
|
| 392 | + ob_start(); |
|
| 393 | + include($template_path); |
|
| 394 | + return ob_get_clean(); |
|
| 395 | + } |
|
| 396 | + include($template_path); |
|
| 397 | + return ''; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
| 403 | + * |
|
| 404 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
| 405 | + * @param string $prefix added to the beginning of the generated class |
|
| 406 | + * @param string $suffix added to the end of the generated class |
|
| 407 | + * @return string |
|
| 408 | + * @throws EE_Error |
|
| 409 | + * @throws ReflectionException |
|
| 410 | + */ |
|
| 411 | + public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
| 412 | + { |
|
| 413 | + // in the beginning... |
|
| 414 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 415 | + // da muddle |
|
| 416 | + $class = ''; |
|
| 417 | + // the end |
|
| 418 | + $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 419 | + // is the passed object an EE object ? |
|
| 420 | + if ($object instanceof EE_Base_Class) { |
|
| 421 | + // grab the exact type of object |
|
| 422 | + $obj_class = get_class($object); |
|
| 423 | + // depending on the type of object... |
|
| 424 | + switch ($obj_class) { |
|
| 425 | + // no specifics just yet... |
|
| 426 | + default: |
|
| 427 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
| 428 | + $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + return $prefix . $class . $suffix; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * EEH_Template::format_currency |
|
| 437 | + * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
| 438 | + * the country currency settings from the supplied country ISO code |
|
| 439 | + * |
|
| 440 | + * @param float $amount raw money value |
|
| 441 | + * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
| 442 | + * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
| 443 | + * @param string $CNT_ISO 2 letter ISO code for a country |
|
| 444 | + * @param string $cur_code_span_class |
|
| 445 | + * @return string the html output for the formatted money value |
|
| 446 | + */ |
|
| 447 | + public static function format_currency( |
|
| 448 | + $amount = null, |
|
| 449 | + $return_raw = false, |
|
| 450 | + $display_code = true, |
|
| 451 | + $CNT_ISO = '', |
|
| 452 | + $cur_code_span_class = 'currency-code' |
|
| 453 | + ) { |
|
| 454 | + // ensure amount was received |
|
| 455 | + if ($amount === null) { |
|
| 456 | + $msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
| 457 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 458 | + return ''; |
|
| 459 | + } |
|
| 460 | + // ensure amount is float |
|
| 461 | + $amount = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
| 462 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
| 463 | + // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
| 464 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
| 465 | + // still a number, or was amount converted to a string like "free" ? |
|
| 466 | + if (! is_float($amount_formatted)) { |
|
| 467 | + return esc_html($amount_formatted); |
|
| 468 | + } |
|
| 469 | + try { |
|
| 470 | + // was a country ISO code passed ? if so generate currency config object for that country |
|
| 471 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
| 472 | + } catch (Exception $e) { |
|
| 473 | + // eat exception |
|
| 474 | + $mny = null; |
|
| 475 | + } |
|
| 476 | + // verify results |
|
| 477 | + if (! $mny instanceof EE_Currency_Config) { |
|
| 478 | + // set default config country currency settings |
|
| 479 | + $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
| 480 | + ? EE_Registry::instance()->CFG->currency |
|
| 481 | + : new EE_Currency_Config(); |
|
| 482 | + } |
|
| 483 | + // format float |
|
| 484 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
| 485 | + // add formatting ? |
|
| 486 | + if (! $return_raw) { |
|
| 487 | + // add currency sign |
|
| 488 | + if ($mny->sign_b4) { |
|
| 489 | + if ($amount >= 0) { |
|
| 490 | + $amount_formatted = $mny->sign . $amount_formatted; |
|
| 491 | + } else { |
|
| 492 | + $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 493 | + } |
|
| 494 | + } else { |
|
| 495 | + $amount_formatted = $amount_formatted . $mny->sign; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + // filter to allow global setting of display_code |
|
| 499 | + $display_code = (bool) apply_filters( |
|
| 500 | + 'FHEE__EEH_Template__format_currency__display_code', |
|
| 501 | + $display_code |
|
| 502 | + ); |
|
| 503 | + |
|
| 504 | + // add currency code ? |
|
| 505 | + $amount_formatted = $display_code |
|
| 506 | + ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' |
|
| 507 | + : $amount_formatted; |
|
| 508 | + } |
|
| 509 | + // filter results |
|
| 510 | + $amount_formatted = apply_filters( |
|
| 511 | + 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
| 512 | + $amount_formatted, |
|
| 513 | + $mny, |
|
| 514 | + $return_raw |
|
| 515 | + ); |
|
| 516 | + // clean up vars |
|
| 517 | + unset($mny); |
|
| 518 | + // return formatted currency amount |
|
| 519 | + return $amount_formatted; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
| 525 | + * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
| 526 | + * related status model or model object (i.e. in documentation etc.) |
|
| 527 | + * |
|
| 528 | + * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
| 529 | + * match, then 'Unknown' will be returned. |
|
| 530 | + * @param boolean $plural Whether to return plural or not |
|
| 531 | + * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
| 532 | + * @return string The localized label for the status id. |
|
| 533 | + * @throws EE_Error |
|
| 534 | + */ |
|
| 535 | + public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
| 536 | + { |
|
| 537 | + $status = EEM_Status::instance()->localized_status( |
|
| 538 | + [$status_id => esc_html__('unknown', 'event_espresso')], |
|
| 539 | + $plural, |
|
| 540 | + $schema |
|
| 541 | + ); |
|
| 542 | + return $status[ $status_id ]; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * This helper just returns a button or link for the given parameters |
|
| 548 | + * |
|
| 549 | + * @param string $url the url for the link, note that `esc_url` will be called on it |
|
| 550 | + * @param string $label What is the label you want displayed for the button |
|
| 551 | + * @param string $class what class is used for the button (defaults to 'button-primary') |
|
| 552 | + * @param string $icon |
|
| 553 | + * @param string $title |
|
| 554 | + * @return string the html output for the button |
|
| 555 | + */ |
|
| 556 | + public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '') |
|
| 557 | + { |
|
| 558 | + $icon_html = ''; |
|
| 559 | + if (! empty($icon)) { |
|
| 560 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
| 561 | + $dashicons = array_filter($dashicons); |
|
| 562 | + $count = count($dashicons); |
|
| 563 | + $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
| 564 | + foreach ($dashicons as $dashicon) { |
|
| 565 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 566 | + $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 567 | + } |
|
| 568 | + $icon_html .= $count > 1 ? '</span>' : ''; |
|
| 569 | + } |
|
| 570 | + // sanitize & escape |
|
| 571 | + $id = sanitize_title_with_dashes($label); |
|
| 572 | + $url = esc_url_raw($url); |
|
| 573 | + $class = esc_attr($class); |
|
| 574 | + $title = esc_attr($title); |
|
| 575 | + $label = esc_html($label); |
|
| 576 | + return "<a id='{$id}' href='{$url}' class='{$class}' title='{$title}'>{$icon_html}{$label}</a>"; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * This returns a generated link that will load the related help tab on admin pages. |
|
| 582 | + * |
|
| 583 | + * @param string $help_tab_id the id for the connected help tab |
|
| 584 | + * @param bool|string $page The page identifier for the page the help tab is on |
|
| 585 | + * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
| 586 | + * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 587 | + * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 588 | + * @return string generated link |
|
| 589 | + */ |
|
| 590 | + public static function get_help_tab_link( |
|
| 591 | + $help_tab_id, |
|
| 592 | + $page = false, |
|
| 593 | + $action = false, |
|
| 594 | + $icon_style = false, |
|
| 595 | + $help_text = false |
|
| 596 | + ) { |
|
| 597 | + $allowedtags = AllowedTags::getAllowedTags(); |
|
| 598 | + /** @var RequestInterface $request */ |
|
| 599 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 600 | + $page = $page ?: $request->getRequestParam('page', '', 'key'); |
|
| 601 | + $action = $action ?: $request->getRequestParam('action', 'default', 'key'); |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 605 | + $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
| 606 | + $help_text = ! $help_text ? '' : $help_text; |
|
| 607 | + return '<a id="' |
|
| 608 | + . esc_attr($help_tab_lnk) |
|
| 609 | + . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' |
|
| 610 | + . esc_attr($icon) |
|
| 611 | + . '" title="' |
|
| 612 | + . esc_attr__( |
|
| 613 | + 'Click to open the \'Help\' tab for more information about this feature.', |
|
| 614 | + 'event_espresso' |
|
| 615 | + ) |
|
| 616 | + . '" > ' |
|
| 617 | + . wp_kses($help_text, $allowedtags) |
|
| 618 | + . ' </a>'; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * This is a helper method to generate a status legend for a given status array. |
|
| 624 | + * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
| 625 | + * status_array. |
|
| 626 | + * |
|
| 627 | + * @param array $status_array array of statuses that will make up the legend. In format: |
|
| 628 | + * array( |
|
| 629 | + * 'status_item' => 'status_name' |
|
| 630 | + * ) |
|
| 631 | + * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
| 632 | + * the legend. |
|
| 633 | + * @return string html structure for status. |
|
| 634 | + * @throws EE_Error |
|
| 635 | + */ |
|
| 636 | + public static function status_legend($status_array, $active_status = '') |
|
| 637 | + { |
|
| 638 | + if (! is_array($status_array)) { |
|
| 639 | + throw new EE_Error( |
|
| 640 | + esc_html__( |
|
| 641 | + 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
| 642 | + 'event_espresso' |
|
| 643 | + ) |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + $content = ' |
|
| 648 | 648 | <div class="ee-list-table-legend-container"> |
| 649 | 649 | <h4 class="status-legend-title"> |
| 650 | 650 | ' . esc_html__('Status Legend', 'event_espresso') . ' |
| 651 | 651 | </h4> |
| 652 | 652 | <dl class="ee-list-table-legend">'; |
| 653 | 653 | |
| 654 | - foreach ($status_array as $item => $status) { |
|
| 655 | - $active_class = $active_status == $status ? 'class="ee-is-active-status"' : ''; |
|
| 656 | - $content .= ' |
|
| 654 | + foreach ($status_array as $item => $status) { |
|
| 655 | + $active_class = $active_status == $status ? 'class="ee-is-active-status"' : ''; |
|
| 656 | + $content .= ' |
|
| 657 | 657 | <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '> |
| 658 | 658 | <span class="' . esc_attr('ee-status-legend ee-status-legend-' . $status) . '"></span> |
| 659 | 659 | <span class="ee-legend-description"> |
| 660 | 660 | ' . EEH_Template::pretty_status($status, false, 'sentence') . ' |
| 661 | 661 | </span> |
| 662 | 662 | </dt>'; |
| 663 | - } |
|
| 663 | + } |
|
| 664 | 664 | |
| 665 | - $content .= ' |
|
| 665 | + $content .= ' |
|
| 666 | 666 | </dl> |
| 667 | 667 | </div> |
| 668 | 668 | '; |
| 669 | - return $content; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
| 675 | - * that's nice for presenting in the wp admin |
|
| 676 | - * |
|
| 677 | - * @param mixed $data |
|
| 678 | - * @return string |
|
| 679 | - */ |
|
| 680 | - public static function layout_array_as_table($data) |
|
| 681 | - { |
|
| 682 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 683 | - $data = (array) $data; |
|
| 684 | - } |
|
| 685 | - ob_start(); |
|
| 686 | - if (is_array($data)) { |
|
| 687 | - if (EEH_Array::is_associative_array($data)) { ?> |
|
| 669 | + return $content; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
| 675 | + * that's nice for presenting in the wp admin |
|
| 676 | + * |
|
| 677 | + * @param mixed $data |
|
| 678 | + * @return string |
|
| 679 | + */ |
|
| 680 | + public static function layout_array_as_table($data) |
|
| 681 | + { |
|
| 682 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 683 | + $data = (array) $data; |
|
| 684 | + } |
|
| 685 | + ob_start(); |
|
| 686 | + if (is_array($data)) { |
|
| 687 | + if (EEH_Array::is_associative_array($data)) { ?> |
|
| 688 | 688 | <table class="widefat"> |
| 689 | 689 | <tbody> |
| 690 | 690 | <?php foreach ($data as $data_key => $data_values) { ?> |
@@ -702,292 +702,292 @@ discard block |
||
| 702 | 702 | <?php } else { ?> |
| 703 | 703 | <ul> |
| 704 | 704 | <?php |
| 705 | - foreach ($data as $datum) { |
|
| 706 | - echo "<li>"; |
|
| 707 | - echo self::layout_array_as_table($datum); |
|
| 708 | - echo "</li>"; |
|
| 709 | - } ?> |
|
| 705 | + foreach ($data as $datum) { |
|
| 706 | + echo "<li>"; |
|
| 707 | + echo self::layout_array_as_table($datum); |
|
| 708 | + echo "</li>"; |
|
| 709 | + } ?> |
|
| 710 | 710 | </ul> |
| 711 | 711 | <?php } |
| 712 | - } else { |
|
| 713 | - // simple value |
|
| 714 | - echo esc_html($data); |
|
| 715 | - } |
|
| 716 | - return ob_get_clean(); |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
| 722 | - * |
|
| 723 | - * @param $total_items |
|
| 724 | - * @param $current |
|
| 725 | - * @param $per_page |
|
| 726 | - * @param $url |
|
| 727 | - * @param bool $show_num_field |
|
| 728 | - * @param string $paged_arg_name |
|
| 729 | - * @param array $items_label |
|
| 730 | - * @see self:get_paging_html() for argument docs. |
|
| 731 | - * @since 4.4.0 |
|
| 732 | - */ |
|
| 733 | - public static function paging_html( |
|
| 734 | - $total_items, |
|
| 735 | - $current, |
|
| 736 | - $per_page, |
|
| 737 | - $url, |
|
| 738 | - $show_num_field = true, |
|
| 739 | - $paged_arg_name = 'paged', |
|
| 740 | - $items_label = [] |
|
| 741 | - ) { |
|
| 742 | - echo self::get_paging_html( |
|
| 743 | - $total_items, |
|
| 744 | - $current, |
|
| 745 | - $per_page, |
|
| 746 | - $url, |
|
| 747 | - $show_num_field, |
|
| 748 | - $paged_arg_name, |
|
| 749 | - $items_label |
|
| 750 | - ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - /** |
|
| 755 | - * A method for generating paging similar to WP_List_Table |
|
| 756 | - * |
|
| 757 | - * @param integer $total_items How many total items there are to page. |
|
| 758 | - * @param integer $current What the current page is. |
|
| 759 | - * @param integer $per_page How many items per page. |
|
| 760 | - * @param string $url What the base url for page links is. |
|
| 761 | - * @param boolean $show_num_field Whether to show the input for changing page number. |
|
| 762 | - * @param string $paged_arg_name The name of the key for the paged query argument. |
|
| 763 | - * @param array $items_label An array of singular/plural values for the items label: |
|
| 764 | - * array( |
|
| 765 | - * 'single' => 'item', |
|
| 766 | - * 'plural' => 'items' |
|
| 767 | - * ) |
|
| 768 | - * @return string |
|
| 769 | - * @since 4.4.0 |
|
| 770 | - * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
| 771 | - */ |
|
| 772 | - public static function get_paging_html( |
|
| 773 | - $total_items, |
|
| 774 | - $current, |
|
| 775 | - $per_page, |
|
| 776 | - $url, |
|
| 777 | - $show_num_field = true, |
|
| 778 | - $paged_arg_name = 'paged', |
|
| 779 | - $items_label = [] |
|
| 780 | - ) { |
|
| 781 | - $page_links = []; |
|
| 782 | - $disable_first = $disable_last = ''; |
|
| 783 | - $total_items = (int) $total_items; |
|
| 784 | - $per_page = (int) $per_page; |
|
| 785 | - $current = (int) $current; |
|
| 786 | - $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
| 787 | - |
|
| 788 | - // filter items_label |
|
| 789 | - $items_label = apply_filters( |
|
| 790 | - 'FHEE__EEH_Template__get_paging_html__items_label', |
|
| 791 | - $items_label |
|
| 792 | - ); |
|
| 793 | - |
|
| 794 | - if ( |
|
| 795 | - empty($items_label) |
|
| 796 | - || ! is_array($items_label) |
|
| 797 | - || ! isset($items_label['single']) |
|
| 798 | - || ! isset($items_label['plural']) |
|
| 799 | - ) { |
|
| 800 | - $items_label = [ |
|
| 801 | - 'single' => esc_html__('1 item', 'event_espresso'), |
|
| 802 | - 'plural' => esc_html__('%s items', 'event_espresso'), |
|
| 803 | - ]; |
|
| 804 | - } else { |
|
| 805 | - $items_label = [ |
|
| 806 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
| 807 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 808 | - ]; |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - $total_pages = ceil($total_items / $per_page); |
|
| 812 | - |
|
| 813 | - if ($total_pages <= 1) { |
|
| 814 | - return ''; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
| 818 | - |
|
| 819 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 820 | - |
|
| 821 | - if ($current === 1) { |
|
| 822 | - $disable_first = ' disabled'; |
|
| 823 | - } |
|
| 824 | - if ($current == $total_pages) { |
|
| 825 | - $disable_last = ' disabled'; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - $page_links[] = sprintf( |
|
| 829 | - "<a class='%s' title='%s' href='%s'>%s</a>", |
|
| 830 | - 'first-page' . $disable_first, |
|
| 831 | - esc_attr__('Go to the first page', 'event_espresso'), |
|
| 832 | - esc_url_raw(remove_query_arg($paged_arg_name, $url)), |
|
| 833 | - '«' |
|
| 834 | - ); |
|
| 835 | - |
|
| 836 | - $page_links[] = sprintf( |
|
| 837 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 838 | - 'prev-page' . $disable_first, |
|
| 839 | - esc_attr__('Go to the previous page', 'event_espresso'), |
|
| 840 | - esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
| 841 | - '‹' |
|
| 842 | - ); |
|
| 843 | - |
|
| 844 | - if (! $show_num_field) { |
|
| 845 | - $html_current_page = $current; |
|
| 846 | - } else { |
|
| 847 | - $html_current_page = sprintf( |
|
| 848 | - "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
| 849 | - esc_attr__('Current page', 'event_espresso'), |
|
| 850 | - esc_attr($current), |
|
| 851 | - strlen($total_pages) |
|
| 852 | - ); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - $html_total_pages = sprintf( |
|
| 856 | - '<span class="total-pages">%s</span>', |
|
| 857 | - number_format_i18n($total_pages) |
|
| 858 | - ); |
|
| 859 | - $page_links[] = sprintf( |
|
| 860 | - _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
| 861 | - $html_current_page, |
|
| 862 | - $html_total_pages, |
|
| 863 | - '<span class="paging-input">', |
|
| 864 | - '</span>' |
|
| 865 | - ); |
|
| 866 | - |
|
| 867 | - $page_links[] = sprintf( |
|
| 868 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 869 | - 'next-page' . $disable_last, |
|
| 870 | - esc_attr__('Go to the next page', 'event_espresso'), |
|
| 871 | - esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
| 872 | - '›' |
|
| 873 | - ); |
|
| 874 | - |
|
| 875 | - $page_links[] = sprintf( |
|
| 876 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 877 | - 'last-page' . $disable_last, |
|
| 878 | - esc_attr__('Go to the last page', 'event_espresso'), |
|
| 879 | - esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
| 880 | - '»' |
|
| 881 | - ); |
|
| 882 | - |
|
| 883 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 884 | - // set page class |
|
| 885 | - if ($total_pages) { |
|
| 886 | - $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
| 887 | - } else { |
|
| 888 | - $page_class = ' no-pages'; |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * @param string $wrap_class |
|
| 897 | - * @param string $wrap_id |
|
| 898 | - * @return string |
|
| 899 | - */ |
|
| 900 | - public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = []) |
|
| 901 | - { |
|
| 902 | - $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
| 903 | - if ( |
|
| 904 | - ! $admin |
|
| 905 | - && ! apply_filters( |
|
| 906 | - 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
| 907 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 908 | - ) |
|
| 909 | - ) { |
|
| 910 | - return ''; |
|
| 911 | - } |
|
| 912 | - $tag = $admin ? 'span' : 'div'; |
|
| 913 | - $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
| 914 | - $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
| 915 | - $attributes .= ! empty($wrap_class) |
|
| 916 | - ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
| 917 | - : ' class="powered-by-event-espresso-credit"'; |
|
| 918 | - $query_args = array_merge( |
|
| 919 | - [ |
|
| 920 | - 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
| 921 | - 'utm_source' => 'powered_by_event_espresso', |
|
| 922 | - 'utm_medium' => 'link', |
|
| 923 | - 'utm_campaign' => 'powered_by', |
|
| 924 | - ], |
|
| 925 | - $query_args |
|
| 926 | - ); |
|
| 927 | - $powered_by = apply_filters( |
|
| 928 | - 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
| 929 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 930 | - ); |
|
| 931 | - $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
| 932 | - $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
| 933 | - return (string) apply_filters( |
|
| 934 | - 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
| 935 | - sprintf( |
|
| 936 | - esc_html_x( |
|
| 937 | - '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
| 938 | - 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
| 939 | - 'event_espresso' |
|
| 940 | - ), |
|
| 941 | - "<{$tag}{$attributes}>", |
|
| 942 | - "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
| 943 | - $admin ? '' : '<br />' |
|
| 944 | - ), |
|
| 945 | - $wrap_class, |
|
| 946 | - $wrap_id |
|
| 947 | - ); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - |
|
| 951 | - /** |
|
| 952 | - * @param string $image_name |
|
| 953 | - * @return string|null |
|
| 954 | - * @since 4.10.14.p |
|
| 955 | - */ |
|
| 956 | - public static function getScreenshotUrl($image_name) |
|
| 957 | - { |
|
| 958 | - return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg'); |
|
| 959 | - } |
|
| 712 | + } else { |
|
| 713 | + // simple value |
|
| 714 | + echo esc_html($data); |
|
| 715 | + } |
|
| 716 | + return ob_get_clean(); |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
| 722 | + * |
|
| 723 | + * @param $total_items |
|
| 724 | + * @param $current |
|
| 725 | + * @param $per_page |
|
| 726 | + * @param $url |
|
| 727 | + * @param bool $show_num_field |
|
| 728 | + * @param string $paged_arg_name |
|
| 729 | + * @param array $items_label |
|
| 730 | + * @see self:get_paging_html() for argument docs. |
|
| 731 | + * @since 4.4.0 |
|
| 732 | + */ |
|
| 733 | + public static function paging_html( |
|
| 734 | + $total_items, |
|
| 735 | + $current, |
|
| 736 | + $per_page, |
|
| 737 | + $url, |
|
| 738 | + $show_num_field = true, |
|
| 739 | + $paged_arg_name = 'paged', |
|
| 740 | + $items_label = [] |
|
| 741 | + ) { |
|
| 742 | + echo self::get_paging_html( |
|
| 743 | + $total_items, |
|
| 744 | + $current, |
|
| 745 | + $per_page, |
|
| 746 | + $url, |
|
| 747 | + $show_num_field, |
|
| 748 | + $paged_arg_name, |
|
| 749 | + $items_label |
|
| 750 | + ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * A method for generating paging similar to WP_List_Table |
|
| 756 | + * |
|
| 757 | + * @param integer $total_items How many total items there are to page. |
|
| 758 | + * @param integer $current What the current page is. |
|
| 759 | + * @param integer $per_page How many items per page. |
|
| 760 | + * @param string $url What the base url for page links is. |
|
| 761 | + * @param boolean $show_num_field Whether to show the input for changing page number. |
|
| 762 | + * @param string $paged_arg_name The name of the key for the paged query argument. |
|
| 763 | + * @param array $items_label An array of singular/plural values for the items label: |
|
| 764 | + * array( |
|
| 765 | + * 'single' => 'item', |
|
| 766 | + * 'plural' => 'items' |
|
| 767 | + * ) |
|
| 768 | + * @return string |
|
| 769 | + * @since 4.4.0 |
|
| 770 | + * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
| 771 | + */ |
|
| 772 | + public static function get_paging_html( |
|
| 773 | + $total_items, |
|
| 774 | + $current, |
|
| 775 | + $per_page, |
|
| 776 | + $url, |
|
| 777 | + $show_num_field = true, |
|
| 778 | + $paged_arg_name = 'paged', |
|
| 779 | + $items_label = [] |
|
| 780 | + ) { |
|
| 781 | + $page_links = []; |
|
| 782 | + $disable_first = $disable_last = ''; |
|
| 783 | + $total_items = (int) $total_items; |
|
| 784 | + $per_page = (int) $per_page; |
|
| 785 | + $current = (int) $current; |
|
| 786 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
| 787 | + |
|
| 788 | + // filter items_label |
|
| 789 | + $items_label = apply_filters( |
|
| 790 | + 'FHEE__EEH_Template__get_paging_html__items_label', |
|
| 791 | + $items_label |
|
| 792 | + ); |
|
| 793 | + |
|
| 794 | + if ( |
|
| 795 | + empty($items_label) |
|
| 796 | + || ! is_array($items_label) |
|
| 797 | + || ! isset($items_label['single']) |
|
| 798 | + || ! isset($items_label['plural']) |
|
| 799 | + ) { |
|
| 800 | + $items_label = [ |
|
| 801 | + 'single' => esc_html__('1 item', 'event_espresso'), |
|
| 802 | + 'plural' => esc_html__('%s items', 'event_espresso'), |
|
| 803 | + ]; |
|
| 804 | + } else { |
|
| 805 | + $items_label = [ |
|
| 806 | + 'single' => '1 ' . esc_html($items_label['single']), |
|
| 807 | + 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 808 | + ]; |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + $total_pages = ceil($total_items / $per_page); |
|
| 812 | + |
|
| 813 | + if ($total_pages <= 1) { |
|
| 814 | + return ''; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
| 818 | + |
|
| 819 | + $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 820 | + |
|
| 821 | + if ($current === 1) { |
|
| 822 | + $disable_first = ' disabled'; |
|
| 823 | + } |
|
| 824 | + if ($current == $total_pages) { |
|
| 825 | + $disable_last = ' disabled'; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + $page_links[] = sprintf( |
|
| 829 | + "<a class='%s' title='%s' href='%s'>%s</a>", |
|
| 830 | + 'first-page' . $disable_first, |
|
| 831 | + esc_attr__('Go to the first page', 'event_espresso'), |
|
| 832 | + esc_url_raw(remove_query_arg($paged_arg_name, $url)), |
|
| 833 | + '«' |
|
| 834 | + ); |
|
| 835 | + |
|
| 836 | + $page_links[] = sprintf( |
|
| 837 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 838 | + 'prev-page' . $disable_first, |
|
| 839 | + esc_attr__('Go to the previous page', 'event_espresso'), |
|
| 840 | + esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
| 841 | + '‹' |
|
| 842 | + ); |
|
| 843 | + |
|
| 844 | + if (! $show_num_field) { |
|
| 845 | + $html_current_page = $current; |
|
| 846 | + } else { |
|
| 847 | + $html_current_page = sprintf( |
|
| 848 | + "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
| 849 | + esc_attr__('Current page', 'event_espresso'), |
|
| 850 | + esc_attr($current), |
|
| 851 | + strlen($total_pages) |
|
| 852 | + ); |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + $html_total_pages = sprintf( |
|
| 856 | + '<span class="total-pages">%s</span>', |
|
| 857 | + number_format_i18n($total_pages) |
|
| 858 | + ); |
|
| 859 | + $page_links[] = sprintf( |
|
| 860 | + _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
| 861 | + $html_current_page, |
|
| 862 | + $html_total_pages, |
|
| 863 | + '<span class="paging-input">', |
|
| 864 | + '</span>' |
|
| 865 | + ); |
|
| 866 | + |
|
| 867 | + $page_links[] = sprintf( |
|
| 868 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 869 | + 'next-page' . $disable_last, |
|
| 870 | + esc_attr__('Go to the next page', 'event_espresso'), |
|
| 871 | + esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
| 872 | + '›' |
|
| 873 | + ); |
|
| 874 | + |
|
| 875 | + $page_links[] = sprintf( |
|
| 876 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
| 877 | + 'last-page' . $disable_last, |
|
| 878 | + esc_attr__('Go to the last page', 'event_espresso'), |
|
| 879 | + esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
| 880 | + '»' |
|
| 881 | + ); |
|
| 882 | + |
|
| 883 | + $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 884 | + // set page class |
|
| 885 | + if ($total_pages) { |
|
| 886 | + $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
| 887 | + } else { |
|
| 888 | + $page_class = ' no-pages'; |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * @param string $wrap_class |
|
| 897 | + * @param string $wrap_id |
|
| 898 | + * @return string |
|
| 899 | + */ |
|
| 900 | + public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = []) |
|
| 901 | + { |
|
| 902 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
| 903 | + if ( |
|
| 904 | + ! $admin |
|
| 905 | + && ! apply_filters( |
|
| 906 | + 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
| 907 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 908 | + ) |
|
| 909 | + ) { |
|
| 910 | + return ''; |
|
| 911 | + } |
|
| 912 | + $tag = $admin ? 'span' : 'div'; |
|
| 913 | + $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
| 914 | + $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
| 915 | + $attributes .= ! empty($wrap_class) |
|
| 916 | + ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
| 917 | + : ' class="powered-by-event-espresso-credit"'; |
|
| 918 | + $query_args = array_merge( |
|
| 919 | + [ |
|
| 920 | + 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
| 921 | + 'utm_source' => 'powered_by_event_espresso', |
|
| 922 | + 'utm_medium' => 'link', |
|
| 923 | + 'utm_campaign' => 'powered_by', |
|
| 924 | + ], |
|
| 925 | + $query_args |
|
| 926 | + ); |
|
| 927 | + $powered_by = apply_filters( |
|
| 928 | + 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
| 929 | + $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 930 | + ); |
|
| 931 | + $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
| 932 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
| 933 | + return (string) apply_filters( |
|
| 934 | + 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
| 935 | + sprintf( |
|
| 936 | + esc_html_x( |
|
| 937 | + '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
| 938 | + 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
| 939 | + 'event_espresso' |
|
| 940 | + ), |
|
| 941 | + "<{$tag}{$attributes}>", |
|
| 942 | + "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
| 943 | + $admin ? '' : '<br />' |
|
| 944 | + ), |
|
| 945 | + $wrap_class, |
|
| 946 | + $wrap_id |
|
| 947 | + ); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + |
|
| 951 | + /** |
|
| 952 | + * @param string $image_name |
|
| 953 | + * @return string|null |
|
| 954 | + * @since 4.10.14.p |
|
| 955 | + */ |
|
| 956 | + public static function getScreenshotUrl($image_name) |
|
| 957 | + { |
|
| 958 | + return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg'); |
|
| 959 | + } |
|
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | |
| 963 | 963 | if (! function_exists('espresso_pagination')) { |
| 964 | - /** |
|
| 965 | - * espresso_pagination |
|
| 966 | - * |
|
| 967 | - * @access public |
|
| 968 | - * @return void |
|
| 969 | - */ |
|
| 970 | - function espresso_pagination() |
|
| 971 | - { |
|
| 972 | - global $wp_query; |
|
| 973 | - $big = 999999999; // need an unlikely integer |
|
| 974 | - $pagination = paginate_links( |
|
| 975 | - [ |
|
| 976 | - 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 977 | - 'format' => '?paged=%#%', |
|
| 978 | - 'current' => max(1, get_query_var('paged')), |
|
| 979 | - 'total' => $wp_query->max_num_pages, |
|
| 980 | - 'show_all' => true, |
|
| 981 | - 'end_size' => 10, |
|
| 982 | - 'mid_size' => 6, |
|
| 983 | - 'prev_next' => true, |
|
| 984 | - 'prev_text' => esc_html__('‹ PREV', 'event_espresso'), |
|
| 985 | - 'next_text' => esc_html__('NEXT ›', 'event_espresso'), |
|
| 986 | - 'type' => 'plain', |
|
| 987 | - 'add_args' => false, |
|
| 988 | - 'add_fragment' => '', |
|
| 989 | - ] |
|
| 990 | - ); |
|
| 991 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
| 992 | - } |
|
| 964 | + /** |
|
| 965 | + * espresso_pagination |
|
| 966 | + * |
|
| 967 | + * @access public |
|
| 968 | + * @return void |
|
| 969 | + */ |
|
| 970 | + function espresso_pagination() |
|
| 971 | + { |
|
| 972 | + global $wp_query; |
|
| 973 | + $big = 999999999; // need an unlikely integer |
|
| 974 | + $pagination = paginate_links( |
|
| 975 | + [ |
|
| 976 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 977 | + 'format' => '?paged=%#%', |
|
| 978 | + 'current' => max(1, get_query_var('paged')), |
|
| 979 | + 'total' => $wp_query->max_num_pages, |
|
| 980 | + 'show_all' => true, |
|
| 981 | + 'end_size' => 10, |
|
| 982 | + 'mid_size' => 6, |
|
| 983 | + 'prev_next' => true, |
|
| 984 | + 'prev_text' => esc_html__('‹ PREV', 'event_espresso'), |
|
| 985 | + 'next_text' => esc_html__('NEXT ›', 'event_espresso'), |
|
| 986 | + 'type' => 'plain', |
|
| 987 | + 'add_args' => false, |
|
| 988 | + 'add_fragment' => '', |
|
| 989 | + ] |
|
| 990 | + ); |
|
| 991 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
| 992 | + } |
|
| 993 | 993 | } |
| 994 | 994 | \ No newline at end of file |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use EventEspresso\core\services\request\RequestInterface; |
| 7 | 7 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
| 8 | 8 | |
| 9 | -if (! function_exists('espresso_get_template_part')) { |
|
| 9 | +if ( ! function_exists('espresso_get_template_part')) { |
|
| 10 | 10 | /** |
| 11 | 11 | * espresso_get_template_part |
| 12 | 12 | * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | -if (! function_exists('espresso_get_object_css_class')) { |
|
| 25 | +if ( ! function_exists('espresso_get_object_css_class')) { |
|
| 26 | 26 | /** |
| 27 | 27 | * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
| 28 | 28 | * |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public static function load_espresso_theme_functions() |
| 75 | 75 | { |
| 76 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 77 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
| 78 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
| 76 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
| 77 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) { |
|
| 78 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php'); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | public static function get_espresso_themes() |
| 90 | 90 | { |
| 91 | 91 | if (empty(EEH_Template::$_espresso_themes)) { |
| 92 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
| 92 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
| 93 | 93 | if (empty($espresso_themes)) { |
| 94 | 94 | return []; |
| 95 | 95 | } |
| 96 | 96 | if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
| 97 | - unset($espresso_themes[ $key ]); |
|
| 97 | + unset($espresso_themes[$key]); |
|
| 98 | 98 | } |
| 99 | 99 | EEH_Template::$_espresso_themes = []; |
| 100 | 100 | foreach ($espresso_themes as $espresso_theme) { |
| 101 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
| 101 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | return EEH_Template::$_espresso_themes; |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | // get array of EE Custom Post Types |
| 215 | 215 | $EE_CPTs = $custom_post_types->getDefinitions(); |
| 216 | 216 | // build template name based on request |
| 217 | - if (isset($EE_CPTs[ $post_type ])) { |
|
| 217 | + if (isset($EE_CPTs[$post_type])) { |
|
| 218 | 218 | $archive_or_single = is_archive() ? 'archive' : ''; |
| 219 | 219 | $archive_or_single = is_single() ? 'single' : $archive_or_single; |
| 220 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
| 220 | + $templates = $archive_or_single.'-'.$post_type.'.php'; |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | // currently active EE template theme |
@@ -226,18 +226,18 @@ discard block |
||
| 226 | 226 | // array of paths to folders that may contain templates |
| 227 | 227 | $template_folder_paths = [ |
| 228 | 228 | // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
| 229 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
| 229 | + EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme, |
|
| 230 | 230 | // then in the root of the /wp-content/uploads/espresso/templates/ folder |
| 231 | 231 | EVENT_ESPRESSO_TEMPLATE_DIR, |
| 232 | 232 | ]; |
| 233 | 233 | |
| 234 | 234 | // add core plugin folders for checking only if we're not $check_if_custom |
| 235 | - if (! $check_if_custom) { |
|
| 236 | - $core_paths = [ |
|
| 235 | + if ( ! $check_if_custom) { |
|
| 236 | + $core_paths = [ |
|
| 237 | 237 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
| 238 | - EE_PUBLIC . $current_theme, |
|
| 238 | + EE_PUBLIC.$current_theme, |
|
| 239 | 239 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
| 240 | - EE_TEMPLATES . $current_theme, |
|
| 240 | + EE_TEMPLATES.$current_theme, |
|
| 241 | 241 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
| 242 | 242 | EE_PLUGIN_DIR_PATH, |
| 243 | 243 | ]; |
@@ -272,10 +272,10 @@ discard block |
||
| 272 | 272 | ); |
| 273 | 273 | if ($common_base_path !== '') { |
| 274 | 274 | // both paths have a common base, so just tack the filename onto our search path |
| 275 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
| 275 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
| 276 | 276 | } else { |
| 277 | 277 | // no common base path, so let's just concatenate |
| 278 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
| 278 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
| 279 | 279 | } |
| 280 | 280 | // build up our template locations array by adding our resolved paths |
| 281 | 281 | $full_template_paths[] = $resolved_path; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
| 284 | 284 | array_unshift($full_template_paths, $template); |
| 285 | 285 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
| 286 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
| 286 | + array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name); |
|
| 287 | 287 | } |
| 288 | 288 | // filter final array of full template paths |
| 289 | 289 | $full_template_paths = apply_filters( |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | $common_base_path .= $directory; |
| 337 | - $last_offset = $index + 1; |
|
| 337 | + $last_offset = $index + 1; |
|
| 338 | 338 | } |
| 339 | 339 | return substr($common_base_path, 0, -1); |
| 340 | 340 | } |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
| 373 | 373 | |
| 374 | 374 | // you gimme nuttin - YOU GET NUTTIN !! |
| 375 | - if (! $template_path || ! is_readable($template_path)) { |
|
| 375 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
| 376 | 376 | // ignore whether template is accessible ? |
| 377 | 377 | if ($throw_exceptions) { |
| 378 | 378 | throw new DomainException( |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | return ''; |
| 383 | 383 | } |
| 384 | 384 | // if $template_args are not in an array, then make it so |
| 385 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
| 385 | + if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
| 386 | 386 | $template_args = [$template_args]; |
| 387 | 387 | } |
| 388 | 388 | extract($template_args, EXTR_SKIP); |
@@ -411,11 +411,11 @@ discard block |
||
| 411 | 411 | public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
| 412 | 412 | { |
| 413 | 413 | // in the beginning... |
| 414 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
| 414 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
| 415 | 415 | // da muddle |
| 416 | 416 | $class = ''; |
| 417 | 417 | // the end |
| 418 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
| 418 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
| 419 | 419 | // is the passed object an EE object ? |
| 420 | 420 | if ($object instanceof EE_Base_Class) { |
| 421 | 421 | // grab the exact type of object |
@@ -425,10 +425,10 @@ discard block |
||
| 425 | 425 | // no specifics just yet... |
| 426 | 426 | default: |
| 427 | 427 | $class = strtolower(str_replace('_', '-', $obj_class)); |
| 428 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
| 428 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | - return $prefix . $class . $suffix; |
|
| 431 | + return $prefix.$class.$suffix; |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | // filter raw amount (allows 0.00 to be changed to "free" for example) |
| 464 | 464 | $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
| 465 | 465 | // still a number, or was amount converted to a string like "free" ? |
| 466 | - if (! is_float($amount_formatted)) { |
|
| 466 | + if ( ! is_float($amount_formatted)) { |
|
| 467 | 467 | return esc_html($amount_formatted); |
| 468 | 468 | } |
| 469 | 469 | try { |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | $mny = null; |
| 475 | 475 | } |
| 476 | 476 | // verify results |
| 477 | - if (! $mny instanceof EE_Currency_Config) { |
|
| 477 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
| 478 | 478 | // set default config country currency settings |
| 479 | 479 | $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
| 480 | 480 | ? EE_Registry::instance()->CFG->currency |
@@ -483,16 +483,16 @@ discard block |
||
| 483 | 483 | // format float |
| 484 | 484 | $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
| 485 | 485 | // add formatting ? |
| 486 | - if (! $return_raw) { |
|
| 486 | + if ( ! $return_raw) { |
|
| 487 | 487 | // add currency sign |
| 488 | 488 | if ($mny->sign_b4) { |
| 489 | 489 | if ($amount >= 0) { |
| 490 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
| 490 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
| 491 | 491 | } else { |
| 492 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
| 492 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
| 493 | 493 | } |
| 494 | 494 | } else { |
| 495 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
| 495 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | // filter to allow global setting of display_code |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | |
| 504 | 504 | // add currency code ? |
| 505 | 505 | $amount_formatted = $display_code |
| 506 | - ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' |
|
| 506 | + ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' |
|
| 507 | 507 | : $amount_formatted; |
| 508 | 508 | } |
| 509 | 509 | // filter results |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | $plural, |
| 540 | 540 | $schema |
| 541 | 541 | ); |
| 542 | - return $status[ $status_id ]; |
|
| 542 | + return $status[$status_id]; |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
@@ -556,14 +556,14 @@ discard block |
||
| 556 | 556 | public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '') |
| 557 | 557 | { |
| 558 | 558 | $icon_html = ''; |
| 559 | - if (! empty($icon)) { |
|
| 559 | + if ( ! empty($icon)) { |
|
| 560 | 560 | $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
| 561 | 561 | $dashicons = array_filter($dashicons); |
| 562 | 562 | $count = count($dashicons); |
| 563 | 563 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
| 564 | 564 | foreach ($dashicons as $dashicon) { |
| 565 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 566 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
| 565 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
| 566 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
| 567 | 567 | } |
| 568 | 568 | $icon_html .= $count > 1 ? '</span>' : ''; |
| 569 | 569 | } |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | $action = $action ?: $request->getRequestParam('action', 'default', 'key'); |
| 602 | 602 | |
| 603 | 603 | |
| 604 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
| 604 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
| 605 | 605 | $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
| 606 | 606 | $help_text = ! $help_text ? '' : $help_text; |
| 607 | 607 | return '<a id="' |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | */ |
| 636 | 636 | public static function status_legend($status_array, $active_status = '') |
| 637 | 637 | { |
| 638 | - if (! is_array($status_array)) { |
|
| 638 | + if ( ! is_array($status_array)) { |
|
| 639 | 639 | throw new EE_Error( |
| 640 | 640 | esc_html__( |
| 641 | 641 | 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
@@ -647,17 +647,17 @@ discard block |
||
| 647 | 647 | $content = ' |
| 648 | 648 | <div class="ee-list-table-legend-container"> |
| 649 | 649 | <h4 class="status-legend-title"> |
| 650 | - ' . esc_html__('Status Legend', 'event_espresso') . ' |
|
| 650 | + ' . esc_html__('Status Legend', 'event_espresso').' |
|
| 651 | 651 | </h4> |
| 652 | 652 | <dl class="ee-list-table-legend">'; |
| 653 | 653 | |
| 654 | 654 | foreach ($status_array as $item => $status) { |
| 655 | 655 | $active_class = $active_status == $status ? 'class="ee-is-active-status"' : ''; |
| 656 | - $content .= ' |
|
| 657 | - <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '> |
|
| 658 | - <span class="' . esc_attr('ee-status-legend ee-status-legend-' . $status) . '"></span> |
|
| 656 | + $content .= ' |
|
| 657 | + <dt id="' . esc_attr('ee-legend-item-tooltip-'.$item).'" '.$active_class.'> |
|
| 658 | + <span class="' . esc_attr('ee-status-legend ee-status-legend-'.$status).'"></span> |
|
| 659 | 659 | <span class="ee-legend-description"> |
| 660 | - ' . EEH_Template::pretty_status($status, false, 'sentence') . ' |
|
| 660 | + ' . EEH_Template::pretty_status($status, false, 'sentence').' |
|
| 661 | 661 | </span> |
| 662 | 662 | </dt>'; |
| 663 | 663 | } |
@@ -803,8 +803,8 @@ discard block |
||
| 803 | 803 | ]; |
| 804 | 804 | } else { |
| 805 | 805 | $items_label = [ |
| 806 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
| 807 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
| 806 | + 'single' => '1 '.esc_html($items_label['single']), |
|
| 807 | + 'plural' => '%s '.esc_html($items_label['plural']), |
|
| 808 | 808 | ]; |
| 809 | 809 | } |
| 810 | 810 | |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | |
| 817 | 817 | $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
| 818 | 818 | |
| 819 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
| 819 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
| 820 | 820 | |
| 821 | 821 | if ($current === 1) { |
| 822 | 822 | $disable_first = ' disabled'; |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | |
| 828 | 828 | $page_links[] = sprintf( |
| 829 | 829 | "<a class='%s' title='%s' href='%s'>%s</a>", |
| 830 | - 'first-page' . $disable_first, |
|
| 830 | + 'first-page'.$disable_first, |
|
| 831 | 831 | esc_attr__('Go to the first page', 'event_espresso'), |
| 832 | 832 | esc_url_raw(remove_query_arg($paged_arg_name, $url)), |
| 833 | 833 | '«' |
@@ -835,13 +835,13 @@ discard block |
||
| 835 | 835 | |
| 836 | 836 | $page_links[] = sprintf( |
| 837 | 837 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 838 | - 'prev-page' . $disable_first, |
|
| 838 | + 'prev-page'.$disable_first, |
|
| 839 | 839 | esc_attr__('Go to the previous page', 'event_espresso'), |
| 840 | 840 | esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
| 841 | 841 | '‹' |
| 842 | 842 | ); |
| 843 | 843 | |
| 844 | - if (! $show_num_field) { |
|
| 844 | + if ( ! $show_num_field) { |
|
| 845 | 845 | $html_current_page = $current; |
| 846 | 846 | } else { |
| 847 | 847 | $html_current_page = sprintf( |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | '<span class="total-pages">%s</span>', |
| 857 | 857 | number_format_i18n($total_pages) |
| 858 | 858 | ); |
| 859 | - $page_links[] = sprintf( |
|
| 859 | + $page_links[] = sprintf( |
|
| 860 | 860 | _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
| 861 | 861 | $html_current_page, |
| 862 | 862 | $html_total_pages, |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | |
| 867 | 867 | $page_links[] = sprintf( |
| 868 | 868 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 869 | - 'next-page' . $disable_last, |
|
| 869 | + 'next-page'.$disable_last, |
|
| 870 | 870 | esc_attr__('Go to the next page', 'event_espresso'), |
| 871 | 871 | esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
| 872 | 872 | '›' |
@@ -874,13 +874,13 @@ discard block |
||
| 874 | 874 | |
| 875 | 875 | $page_links[] = sprintf( |
| 876 | 876 | '<a class="%s" title="%s" href="%s">%s</a>', |
| 877 | - 'last-page' . $disable_last, |
|
| 877 | + 'last-page'.$disable_last, |
|
| 878 | 878 | esc_attr__('Go to the last page', 'event_espresso'), |
| 879 | 879 | esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)), |
| 880 | 880 | '»' |
| 881 | 881 | ); |
| 882 | 882 | |
| 883 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
| 883 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
| 884 | 884 | // set page class |
| 885 | 885 | if ($total_pages) { |
| 886 | 886 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | $page_class = ' no-pages'; |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
| 891 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | ); |
| 927 | 927 | $powered_by = apply_filters( |
| 928 | 928 | 'FHEE__EEH_Template__powered_by_event_espresso_text', |
| 929 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 929 | + $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
| 930 | 930 | ); |
| 931 | 931 | $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
| 932 | 932 | $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
@@ -955,12 +955,12 @@ discard block |
||
| 955 | 955 | */ |
| 956 | 956 | public static function getScreenshotUrl($image_name) |
| 957 | 957 | { |
| 958 | - return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg'); |
|
| 958 | + return esc_url_raw(EE_GLOBAL_ASSETS_URL.'images/screenshots/'.$image_name.'.jpg'); |
|
| 959 | 959 | } |
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | |
| 963 | -if (! function_exists('espresso_pagination')) { |
|
| 963 | +if ( ! function_exists('espresso_pagination')) { |
|
| 964 | 964 | /** |
| 965 | 965 | * espresso_pagination |
| 966 | 966 | * |
@@ -988,6 +988,6 @@ discard block |
||
| 988 | 988 | 'add_fragment' => '', |
| 989 | 989 | ] |
| 990 | 990 | ); |
| 991 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
| 991 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
| 992 | 992 | } |
| 993 | 993 | } |
| 994 | 994 | \ No newline at end of file |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | $route_details = [ |
| 45 | 45 | 'route' => 'registrations_report', |
| 46 | - 'extra_request' => [ 'return_url' => $return_url ], |
|
| 46 | + 'extra_request' => ['return_url' => $return_url], |
|
| 47 | 47 | ]; |
| 48 | - if (! empty($EVT_ID)) { |
|
| 48 | + if ( ! empty($EVT_ID)) { |
|
| 49 | 49 | $route_details['extra_request']['EVT_ID'] = $EVT_ID; |
| 50 | 50 | } |
| 51 | 51 | if ($DTT_ID) { |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | <span class="csv-report-notice__wrapper"> |
| 76 | 76 | <span class="dashicons dashicons-info"></span> |
| 77 | 77 | <span class="csv-report-notice__text"> |
| 78 | - ' . esc_html('All Registration CSV Reports are now triggered by the preceding button') . ' |
|
| 78 | + ' . esc_html('All Registration CSV Reports are now triggered by the preceding button').' |
|
| 79 | 79 | </span> |
| 80 | 80 | </span>'; |
| 81 | 81 | } |
@@ -14,68 +14,68 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class RegistrationsCsvReportParams |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @param string $return_url |
|
| 19 | - * @param array $request_params |
|
| 20 | - * @param int $EVT_ID |
|
| 21 | - * @param int $DTT_ID |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public static function getRequestParams( |
|
| 25 | - $return_url, |
|
| 26 | - $request_params = [], |
|
| 27 | - $EVT_ID = 0, |
|
| 28 | - $DTT_ID = 0 |
|
| 29 | - ) { |
|
| 30 | - if ( |
|
| 31 | - ! EE_Capabilities::instance()->current_user_can( |
|
| 32 | - 'ee_read_registrations', |
|
| 33 | - 'espresso_registrations_registrations_reports', |
|
| 34 | - $EVT_ID |
|
| 35 | - ) |
|
| 36 | - ) { |
|
| 37 | - return []; |
|
| 38 | - } |
|
| 39 | - add_action( |
|
| 40 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 41 | - [RegistrationsCsvReportParams::class, 'csvReportNotice'] |
|
| 42 | - ); |
|
| 17 | + /** |
|
| 18 | + * @param string $return_url |
|
| 19 | + * @param array $request_params |
|
| 20 | + * @param int $EVT_ID |
|
| 21 | + * @param int $DTT_ID |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public static function getRequestParams( |
|
| 25 | + $return_url, |
|
| 26 | + $request_params = [], |
|
| 27 | + $EVT_ID = 0, |
|
| 28 | + $DTT_ID = 0 |
|
| 29 | + ) { |
|
| 30 | + if ( |
|
| 31 | + ! EE_Capabilities::instance()->current_user_can( |
|
| 32 | + 'ee_read_registrations', |
|
| 33 | + 'espresso_registrations_registrations_reports', |
|
| 34 | + $EVT_ID |
|
| 35 | + ) |
|
| 36 | + ) { |
|
| 37 | + return []; |
|
| 38 | + } |
|
| 39 | + add_action( |
|
| 40 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 41 | + [RegistrationsCsvReportParams::class, 'csvReportNotice'] |
|
| 42 | + ); |
|
| 43 | 43 | |
| 44 | - $route_details = [ |
|
| 45 | - 'route' => 'registrations_report', |
|
| 46 | - 'extra_request' => [ 'return_url' => $return_url ], |
|
| 47 | - ]; |
|
| 48 | - if (! empty($EVT_ID)) { |
|
| 49 | - $route_details['extra_request']['EVT_ID'] = $EVT_ID; |
|
| 50 | - } |
|
| 51 | - if ($DTT_ID) { |
|
| 52 | - $route_details['extra_request']['DTT_ID'] = $DTT_ID; |
|
| 53 | - } |
|
| 54 | - if ( |
|
| 55 | - isset($request_params['use_filters']) |
|
| 56 | - && filter_var($request_params['use_filters'], FILTER_VALIDATE_BOOLEAN) |
|
| 57 | - ) { |
|
| 58 | - $route_details['extra_request']['filters'] = array_diff_key( |
|
| 59 | - $request_params, |
|
| 60 | - [ |
|
| 61 | - 'page' => '', |
|
| 62 | - 'action' => '', |
|
| 63 | - 'default_nonce' => '', |
|
| 64 | - ] |
|
| 65 | - ); |
|
| 66 | - } |
|
| 67 | - return $route_details; |
|
| 68 | - } |
|
| 44 | + $route_details = [ |
|
| 45 | + 'route' => 'registrations_report', |
|
| 46 | + 'extra_request' => [ 'return_url' => $return_url ], |
|
| 47 | + ]; |
|
| 48 | + if (! empty($EVT_ID)) { |
|
| 49 | + $route_details['extra_request']['EVT_ID'] = $EVT_ID; |
|
| 50 | + } |
|
| 51 | + if ($DTT_ID) { |
|
| 52 | + $route_details['extra_request']['DTT_ID'] = $DTT_ID; |
|
| 53 | + } |
|
| 54 | + if ( |
|
| 55 | + isset($request_params['use_filters']) |
|
| 56 | + && filter_var($request_params['use_filters'], FILTER_VALIDATE_BOOLEAN) |
|
| 57 | + ) { |
|
| 58 | + $route_details['extra_request']['filters'] = array_diff_key( |
|
| 59 | + $request_params, |
|
| 60 | + [ |
|
| 61 | + 'page' => '', |
|
| 62 | + 'action' => '', |
|
| 63 | + 'default_nonce' => '', |
|
| 64 | + ] |
|
| 65 | + ); |
|
| 66 | + } |
|
| 67 | + return $route_details; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | - public static function csvReportNotice() |
|
| 72 | - { |
|
| 73 | - echo ' |
|
| 71 | + public static function csvReportNotice() |
|
| 72 | + { |
|
| 73 | + echo ' |
|
| 74 | 74 | <span class="csv-report-notice__wrapper"> |
| 75 | 75 | <span class="dashicons dashicons-info"></span> |
| 76 | 76 | <span class="csv-report-notice__text"> |
| 77 | 77 | ' . esc_html('All Registration CSV Reports are now triggered by the preceding button') . ' |
| 78 | 78 | </span> |
| 79 | 79 | </span>'; |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -20,1429 +20,1429 @@ |
||
| 20 | 20 | class General_Settings_Admin_Page extends EE_Admin_Page |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var EE_Core_Config |
|
| 25 | - */ |
|
| 26 | - public $core_config; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Initialize basic properties. |
|
| 31 | - */ |
|
| 32 | - protected function _init_page_props() |
|
| 33 | - { |
|
| 34 | - $this->page_slug = GEN_SET_PG_SLUG; |
|
| 35 | - $this->page_label = GEN_SET_LABEL; |
|
| 36 | - $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
| 37 | - $this->_admin_base_path = GEN_SET_ADMIN; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Set ajax hooks |
|
| 43 | - */ |
|
| 44 | - protected function _ajax_hooks() |
|
| 45 | - { |
|
| 46 | - add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']); |
|
| 47 | - add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']); |
|
| 48 | - add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3); |
|
| 49 | - add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * More page properties initialization. |
|
| 55 | - */ |
|
| 56 | - protected function _define_page_props() |
|
| 57 | - { |
|
| 58 | - $this->_admin_page_title = GEN_SET_LABEL; |
|
| 59 | - $this->_labels = ['publishbox' => esc_html__('Update Settings', 'event_espresso')]; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Set page routes property. |
|
| 65 | - */ |
|
| 66 | - protected function _set_page_routes() |
|
| 67 | - { |
|
| 68 | - $this->_page_routes = [ |
|
| 69 | - 'critical_pages' => [ |
|
| 70 | - 'func' => '_espresso_page_settings', |
|
| 71 | - 'capability' => 'manage_options', |
|
| 72 | - ], |
|
| 73 | - 'update_espresso_page_settings' => [ |
|
| 74 | - 'func' => '_update_espresso_page_settings', |
|
| 75 | - 'capability' => 'manage_options', |
|
| 76 | - 'noheader' => true, |
|
| 77 | - ], |
|
| 78 | - 'default' => [ |
|
| 79 | - 'func' => '_your_organization_settings', |
|
| 80 | - 'capability' => 'manage_options', |
|
| 81 | - ], |
|
| 82 | - |
|
| 83 | - 'update_your_organization_settings' => [ |
|
| 84 | - 'func' => '_update_your_organization_settings', |
|
| 85 | - 'capability' => 'manage_options', |
|
| 86 | - 'noheader' => true, |
|
| 87 | - ], |
|
| 88 | - |
|
| 89 | - 'admin_option_settings' => [ |
|
| 90 | - 'func' => '_admin_option_settings', |
|
| 91 | - 'capability' => 'manage_options', |
|
| 92 | - ], |
|
| 93 | - |
|
| 94 | - 'update_admin_option_settings' => [ |
|
| 95 | - 'func' => '_update_admin_option_settings', |
|
| 96 | - 'capability' => 'manage_options', |
|
| 97 | - 'noheader' => true, |
|
| 98 | - ], |
|
| 99 | - |
|
| 100 | - 'country_settings' => [ |
|
| 101 | - 'func' => '_country_settings', |
|
| 102 | - 'capability' => 'manage_options', |
|
| 103 | - ], |
|
| 104 | - |
|
| 105 | - 'update_country_settings' => [ |
|
| 106 | - 'func' => '_update_country_settings', |
|
| 107 | - 'capability' => 'manage_options', |
|
| 108 | - 'noheader' => true, |
|
| 109 | - ], |
|
| 110 | - |
|
| 111 | - 'display_country_settings' => [ |
|
| 112 | - 'func' => 'display_country_settings', |
|
| 113 | - 'capability' => 'manage_options', |
|
| 114 | - 'noheader' => true, |
|
| 115 | - ], |
|
| 116 | - |
|
| 117 | - 'add_new_state' => [ |
|
| 118 | - 'func' => 'add_new_state', |
|
| 119 | - 'capability' => 'manage_options', |
|
| 120 | - 'noheader' => true, |
|
| 121 | - ], |
|
| 122 | - |
|
| 123 | - 'delete_state' => [ |
|
| 124 | - 'func' => 'delete_state', |
|
| 125 | - 'capability' => 'manage_options', |
|
| 126 | - 'noheader' => true, |
|
| 127 | - ], |
|
| 128 | - 'privacy_settings' => [ |
|
| 129 | - 'func' => 'privacySettings', |
|
| 130 | - 'capability' => 'manage_options', |
|
| 131 | - ], |
|
| 132 | - 'update_privacy_settings' => [ |
|
| 133 | - 'func' => 'updatePrivacySettings', |
|
| 134 | - 'capability' => 'manage_options', |
|
| 135 | - 'noheader' => true, |
|
| 136 | - 'headers_sent_route' => 'privacy_settings', |
|
| 137 | - ], |
|
| 138 | - ]; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Set page configuration property |
|
| 144 | - */ |
|
| 145 | - protected function _set_page_config() |
|
| 146 | - { |
|
| 147 | - $this->_page_config = [ |
|
| 148 | - 'critical_pages' => [ |
|
| 149 | - 'nav' => [ |
|
| 150 | - 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
| 151 | - 'order' => 50, |
|
| 152 | - ], |
|
| 153 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 154 | - 'help_tabs' => [ |
|
| 155 | - 'general_settings_critical_pages_help_tab' => [ |
|
| 156 | - 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
| 157 | - 'filename' => 'general_settings_critical_pages', |
|
| 158 | - ], |
|
| 159 | - ], |
|
| 160 | - 'require_nonce' => false, |
|
| 161 | - ], |
|
| 162 | - 'default' => [ |
|
| 163 | - 'nav' => [ |
|
| 164 | - 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
| 165 | - 'order' => 20, |
|
| 166 | - ], |
|
| 167 | - 'help_tabs' => [ |
|
| 168 | - 'general_settings_your_organization_help_tab' => [ |
|
| 169 | - 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
| 170 | - 'filename' => 'general_settings_your_organization', |
|
| 171 | - ], |
|
| 172 | - ], |
|
| 173 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 174 | - 'require_nonce' => false, |
|
| 175 | - ], |
|
| 176 | - 'admin_option_settings' => [ |
|
| 177 | - 'nav' => [ |
|
| 178 | - 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
| 179 | - 'order' => 60, |
|
| 180 | - ], |
|
| 181 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 182 | - 'help_tabs' => [ |
|
| 183 | - 'general_settings_admin_options_help_tab' => [ |
|
| 184 | - 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
| 185 | - 'filename' => 'general_settings_admin_options', |
|
| 186 | - ], |
|
| 187 | - ], |
|
| 188 | - 'require_nonce' => false, |
|
| 189 | - ], |
|
| 190 | - 'country_settings' => [ |
|
| 191 | - 'nav' => [ |
|
| 192 | - 'label' => esc_html__('Countries', 'event_espresso'), |
|
| 193 | - 'order' => 70, |
|
| 194 | - ], |
|
| 195 | - 'help_tabs' => [ |
|
| 196 | - 'general_settings_countries_help_tab' => [ |
|
| 197 | - 'title' => esc_html__('Countries', 'event_espresso'), |
|
| 198 | - 'filename' => 'general_settings_countries', |
|
| 199 | - ], |
|
| 200 | - ], |
|
| 201 | - 'require_nonce' => false, |
|
| 202 | - ], |
|
| 203 | - 'privacy_settings' => [ |
|
| 204 | - 'nav' => [ |
|
| 205 | - 'label' => esc_html__('Privacy', 'event_espresso'), |
|
| 206 | - 'order' => 80, |
|
| 207 | - ], |
|
| 208 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 209 | - 'require_nonce' => false, |
|
| 210 | - ], |
|
| 211 | - ]; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - protected function _add_screen_options() |
|
| 216 | - { |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - protected function _add_feature_pointers() |
|
| 221 | - { |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
| 227 | - */ |
|
| 228 | - public function load_scripts_styles() |
|
| 229 | - { |
|
| 230 | - // styles |
|
| 231 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 232 | - // scripts |
|
| 233 | - wp_enqueue_script('ee_admin_js'); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Execute logic running on `admin_init` |
|
| 239 | - */ |
|
| 240 | - public function admin_init() |
|
| 241 | - { |
|
| 242 | - $this->core_config = EE_Registry::instance()->CFG->core; |
|
| 243 | - |
|
| 244 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags( |
|
| 245 | - esc_html__( |
|
| 246 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 247 | - 'event_espresso' |
|
| 248 | - ) |
|
| 249 | - ); |
|
| 250 | - EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags( |
|
| 251 | - esc_html__( |
|
| 252 | - 'An error occurred! Please refresh the page and try again.', |
|
| 253 | - 'event_espresso' |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags( |
|
| 257 | - esc_html__( |
|
| 258 | - 'Are you sure you want to delete this State / Province?', |
|
| 259 | - 'event_espresso' |
|
| 260 | - ) |
|
| 261 | - ); |
|
| 262 | - EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
| 263 | - 'admin-ajax.php?page=espresso_general_settings', |
|
| 264 | - is_ssl() ? 'https://' : 'http://' |
|
| 265 | - ); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - public function admin_notices() |
|
| 270 | - { |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - public function admin_footer_scripts() |
|
| 275 | - { |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Enqueue scripts and styles for the default route. |
|
| 281 | - */ |
|
| 282 | - public function load_scripts_styles_default() |
|
| 283 | - { |
|
| 284 | - // styles |
|
| 285 | - wp_enqueue_style('thickbox'); |
|
| 286 | - // scripts |
|
| 287 | - wp_enqueue_script('media-upload'); |
|
| 288 | - wp_enqueue_script('thickbox'); |
|
| 289 | - wp_register_script( |
|
| 290 | - 'organization_settings', |
|
| 291 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 292 | - ['jquery', 'media-upload', 'thickbox'], |
|
| 293 | - EVENT_ESPRESSO_VERSION, |
|
| 294 | - true |
|
| 295 | - ); |
|
| 296 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
| 297 | - wp_enqueue_script('organization_settings'); |
|
| 298 | - wp_enqueue_style('organization-css'); |
|
| 299 | - $confirm_image_delete = [ |
|
| 300 | - 'text' => wp_strip_all_tags( |
|
| 301 | - esc_html__( |
|
| 302 | - 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
| 303 | - 'event_espresso' |
|
| 304 | - ) |
|
| 305 | - ), |
|
| 306 | - ]; |
|
| 307 | - wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Enqueue scripts and styles for the country settings route. |
|
| 313 | - */ |
|
| 314 | - public function load_scripts_styles_country_settings() |
|
| 315 | - { |
|
| 316 | - // scripts |
|
| 317 | - wp_register_script( |
|
| 318 | - 'gen_settings_countries', |
|
| 319 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 320 | - ['ee_admin_js'], |
|
| 321 | - EVENT_ESPRESSO_VERSION, |
|
| 322 | - true |
|
| 323 | - ); |
|
| 324 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
| 325 | - wp_enqueue_script('gen_settings_countries'); |
|
| 326 | - wp_enqueue_style('organization-css'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /************* Espresso Pages *************/ |
|
| 331 | - /** |
|
| 332 | - * _espresso_page_settings |
|
| 333 | - * |
|
| 334 | - * @throws EE_Error |
|
| 335 | - * @throws DomainException |
|
| 336 | - * @throws DomainException |
|
| 337 | - * @throws InvalidDataTypeException |
|
| 338 | - * @throws InvalidArgumentException |
|
| 339 | - */ |
|
| 340 | - protected function _espresso_page_settings() |
|
| 341 | - { |
|
| 342 | - // Check to make sure all of the main pages are set up properly, |
|
| 343 | - // if not create the default pages and display an admin notice |
|
| 344 | - EEH_Activation::verify_default_pages_exist(); |
|
| 345 | - $this->_transient_garbage_collection(); |
|
| 346 | - |
|
| 347 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 348 | - |
|
| 349 | - $this->_template_args['reg_page_id'] = $this->core_config->reg_page_id ?? null; |
|
| 350 | - $this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id) |
|
| 351 | - ? get_post($this->core_config->reg_page_id) |
|
| 352 | - : false; |
|
| 353 | - |
|
| 354 | - $this->_template_args['txn_page_id'] = $this->core_config->txn_page_id ?? null; |
|
| 355 | - $this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id) |
|
| 356 | - ? get_post($this->core_config->txn_page_id) |
|
| 357 | - : false; |
|
| 358 | - |
|
| 359 | - $this->_template_args['thank_you_page_id'] = $this->core_config->thank_you_page_id ?? null; |
|
| 360 | - $this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id) |
|
| 361 | - ? get_post($this->core_config->thank_you_page_id) |
|
| 362 | - : false; |
|
| 363 | - |
|
| 364 | - $this->_template_args['cancel_page_id'] = $this->core_config->cancel_page_id ?? null; |
|
| 365 | - $this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id) |
|
| 366 | - ? get_post($this->core_config->cancel_page_id) |
|
| 367 | - : false; |
|
| 368 | - |
|
| 369 | - $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
| 370 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 371 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 372 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 373 | - $this->_template_args, |
|
| 374 | - true |
|
| 375 | - ); |
|
| 376 | - $this->display_admin_page_with_sidebar(); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Handler for updating espresso page settings. |
|
| 382 | - * |
|
| 383 | - * @throws EE_Error |
|
| 384 | - */ |
|
| 385 | - protected function _update_espresso_page_settings() |
|
| 386 | - { |
|
| 387 | - // capture incoming request data && set page IDs |
|
| 388 | - $this->core_config->reg_page_id = $this->request->getRequestParam( |
|
| 389 | - 'reg_page_id', |
|
| 390 | - $this->core_config->reg_page_id, |
|
| 391 | - DataType::INT |
|
| 392 | - ); |
|
| 393 | - $this->core_config->txn_page_id = $this->request->getRequestParam( |
|
| 394 | - 'txn_page_id', |
|
| 395 | - $this->core_config->txn_page_id, |
|
| 396 | - DataType::INT |
|
| 397 | - ); |
|
| 398 | - $this->core_config->thank_you_page_id = $this->request->getRequestParam( |
|
| 399 | - 'thank_you_page_id', |
|
| 400 | - $this->core_config->thank_you_page_id, |
|
| 401 | - DataType::INT |
|
| 402 | - ); |
|
| 403 | - $this->core_config->cancel_page_id = $this->request->getRequestParam( |
|
| 404 | - 'cancel_page_id', |
|
| 405 | - $this->core_config->cancel_page_id, |
|
| 406 | - DataType::INT |
|
| 407 | - ); |
|
| 408 | - |
|
| 409 | - $this->core_config = apply_filters( |
|
| 410 | - 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
| 411 | - $this->core_config, |
|
| 412 | - $this->request->requestParams() |
|
| 413 | - ); |
|
| 414 | - |
|
| 415 | - $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 416 | - $this->_redirect_after_action( |
|
| 417 | - $this->_update_espresso_configuration( |
|
| 418 | - $what, |
|
| 419 | - $this->core_config, |
|
| 420 | - __FILE__, |
|
| 421 | - __FUNCTION__, |
|
| 422 | - __LINE__ |
|
| 423 | - ), |
|
| 424 | - $what, |
|
| 425 | - '', |
|
| 426 | - [ |
|
| 427 | - 'action' => 'critical_pages', |
|
| 428 | - ], |
|
| 429 | - true |
|
| 430 | - ); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /************* Your Organization *************/ |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * @throws DomainException |
|
| 439 | - * @throws EE_Error |
|
| 440 | - * @throws InvalidArgumentException |
|
| 441 | - * @throws InvalidDataTypeException |
|
| 442 | - * @throws InvalidInterfaceException |
|
| 443 | - */ |
|
| 444 | - protected function _your_organization_settings() |
|
| 445 | - { |
|
| 446 | - $this->_template_args['admin_page_content'] = ''; |
|
| 447 | - try { |
|
| 448 | - /** @var OrganizationSettings $organization_settings_form */ |
|
| 449 | - $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
| 450 | - |
|
| 451 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
| 452 | - $organization_settings_form->display(), |
|
| 453 | - '', |
|
| 454 | - 'padding' |
|
| 455 | - ); |
|
| 456 | - } catch (Exception $e) { |
|
| 457 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 458 | - } |
|
| 459 | - $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
| 460 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 461 | - $this->display_admin_page_with_sidebar(); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Handler for updating organization settings. |
|
| 467 | - * |
|
| 468 | - * @throws EE_Error |
|
| 469 | - */ |
|
| 470 | - protected function _update_your_organization_settings() |
|
| 471 | - { |
|
| 472 | - try { |
|
| 473 | - /** @var OrganizationSettings $organization_settings_form */ |
|
| 474 | - $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
| 475 | - |
|
| 476 | - $success = $organization_settings_form->process($this->request->requestParams()); |
|
| 477 | - |
|
| 478 | - EE_Registry::instance()->CFG = apply_filters( |
|
| 479 | - 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
| 480 | - EE_Registry::instance()->CFG |
|
| 481 | - ); |
|
| 482 | - } catch (Exception $e) { |
|
| 483 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 484 | - $success = false; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - if ($success) { |
|
| 488 | - $success = $this->_update_espresso_configuration( |
|
| 489 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
| 490 | - EE_Registry::instance()->CFG, |
|
| 491 | - __FILE__, |
|
| 492 | - __FUNCTION__, |
|
| 493 | - __LINE__ |
|
| 494 | - ); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - $this->_redirect_after_action($success, '', '', ['action' => 'default'], true); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /************* Admin Options *************/ |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * _admin_option_settings |
|
| 507 | - * |
|
| 508 | - * @throws EE_Error |
|
| 509 | - * @throws LogicException |
|
| 510 | - */ |
|
| 511 | - protected function _admin_option_settings() |
|
| 512 | - { |
|
| 513 | - $this->_template_args['admin_page_content'] = ''; |
|
| 514 | - try { |
|
| 515 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 516 | - // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
| 517 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 518 | - // also need to account for the do_action that was in the old template |
|
| 519 | - $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
| 520 | - $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
| 521 | - } catch (Exception $e) { |
|
| 522 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 523 | - } |
|
| 524 | - $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
| 525 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 526 | - $this->display_admin_page_with_sidebar(); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * _update_admin_option_settings |
|
| 532 | - * |
|
| 533 | - * @throws EE_Error |
|
| 534 | - * @throws InvalidDataTypeException |
|
| 535 | - * @throws InvalidFormSubmissionException |
|
| 536 | - * @throws InvalidArgumentException |
|
| 537 | - * @throws LogicException |
|
| 538 | - */ |
|
| 539 | - protected function _update_admin_option_settings() |
|
| 540 | - { |
|
| 541 | - try { |
|
| 542 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 543 | - $admin_options_settings_form->process( |
|
| 544 | - $this->request->getRequestParam( |
|
| 545 | - $admin_options_settings_form->slug(), |
|
| 546 | - [], |
|
| 547 | - DataType::OBJECT // need to change this to ARRAY after min PHP version gets bumped to 7+ |
|
| 548 | - ) |
|
| 549 | - ); |
|
| 550 | - EE_Registry::instance()->CFG->admin = apply_filters( |
|
| 551 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
| 552 | - EE_Registry::instance()->CFG->admin |
|
| 553 | - ); |
|
| 554 | - } catch (Exception $e) { |
|
| 555 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 556 | - } |
|
| 557 | - $this->_redirect_after_action( |
|
| 558 | - apply_filters( |
|
| 559 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
| 560 | - $this->_update_espresso_configuration( |
|
| 561 | - esc_html__('Admin Options', 'event_espresso'), |
|
| 562 | - EE_Registry::instance()->CFG->admin, |
|
| 563 | - __FILE__, |
|
| 564 | - __FUNCTION__, |
|
| 565 | - __LINE__ |
|
| 566 | - ) |
|
| 567 | - ), |
|
| 568 | - esc_html__('Admin Options', 'event_espresso'), |
|
| 569 | - 'updated', |
|
| 570 | - ['action' => 'admin_option_settings'] |
|
| 571 | - ); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /************* Countries *************/ |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * @param string|null $default |
|
| 580 | - * @return string |
|
| 581 | - */ |
|
| 582 | - protected function getCountryISO(?string $default = null): string |
|
| 583 | - { |
|
| 584 | - $default = $default ?? $this->getCountryIsoForSite(); |
|
| 585 | - $CNT_ISO = $this->request->getRequestParam('country', $default); |
|
| 586 | - $CNT_ISO = $this->request->getRequestParam('CNT_ISO', $CNT_ISO); |
|
| 587 | - return strtoupper($CNT_ISO); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * @return string |
|
| 593 | - */ |
|
| 594 | - protected function getCountryIsoForSite(): string |
|
| 595 | - { |
|
| 596 | - return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 597 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 598 | - : 'US'; |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * @param string $CNT_ISO |
|
| 604 | - * @param EE_Country|null $country |
|
| 605 | - * @return EE_Base_Class|EE_Country |
|
| 606 | - * @throws EE_Error |
|
| 607 | - * @throws InvalidArgumentException |
|
| 608 | - * @throws InvalidDataTypeException |
|
| 609 | - * @throws InvalidInterfaceException |
|
| 610 | - * @throws ReflectionException |
|
| 611 | - */ |
|
| 612 | - protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null) |
|
| 613 | - { |
|
| 614 | - /** @var EE_Country $country */ |
|
| 615 | - return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
| 616 | - ? $country |
|
| 617 | - : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Output Country Settings view. |
|
| 623 | - * |
|
| 624 | - * @throws DomainException |
|
| 625 | - * @throws EE_Error |
|
| 626 | - * @throws InvalidArgumentException |
|
| 627 | - * @throws InvalidDataTypeException |
|
| 628 | - * @throws InvalidInterfaceException |
|
| 629 | - * @throws ReflectionException |
|
| 630 | - */ |
|
| 631 | - protected function _country_settings() |
|
| 632 | - { |
|
| 633 | - $CNT_ISO = $this->getCountryISO(); |
|
| 634 | - |
|
| 635 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 636 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 637 | - EE_Question::new_instance( |
|
| 638 | - [ |
|
| 639 | - 'QST_ID' => 0, |
|
| 640 | - 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
| 641 | - 'QST_system' => 'admin-country', |
|
| 642 | - ] |
|
| 643 | - ), |
|
| 644 | - EE_Answer::new_instance( |
|
| 645 | - [ |
|
| 646 | - 'ANS_ID' => 0, |
|
| 647 | - 'ANS_value' => $CNT_ISO, |
|
| 648 | - ] |
|
| 649 | - ), |
|
| 650 | - [ |
|
| 651 | - 'input_id' => 'country', |
|
| 652 | - 'input_name' => 'country', |
|
| 653 | - 'input_prefix' => '', |
|
| 654 | - 'append_qstn_id' => false, |
|
| 655 | - ] |
|
| 656 | - ); |
|
| 657 | - |
|
| 658 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
| 659 | - add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10); |
|
| 660 | - add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10); |
|
| 661 | - $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
| 662 | - $country->ID(), |
|
| 663 | - $country |
|
| 664 | - ); |
|
| 665 | - $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
| 666 | - $country->ID(), |
|
| 667 | - $country |
|
| 668 | - ); |
|
| 669 | - $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
| 670 | - |
|
| 671 | - $this->_set_add_edit_form_tags('update_country_settings'); |
|
| 672 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 673 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 674 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 675 | - $this->_template_args, |
|
| 676 | - true |
|
| 677 | - ); |
|
| 678 | - $this->display_admin_page_with_no_sidebar(); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * @param string $CNT_ISO |
|
| 684 | - * @param EE_Country|null $country |
|
| 685 | - * @return string |
|
| 686 | - * @throws DomainException |
|
| 687 | - * @throws EE_Error |
|
| 688 | - * @throws InvalidArgumentException |
|
| 689 | - * @throws InvalidDataTypeException |
|
| 690 | - * @throws InvalidInterfaceException |
|
| 691 | - * @throws ReflectionException |
|
| 692 | - */ |
|
| 693 | - public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
| 694 | - { |
|
| 695 | - $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
| 696 | - $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
| 697 | - |
|
| 698 | - if (! $CNT_ISO) { |
|
| 699 | - return ''; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - // for ajax |
|
| 703 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 704 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 705 | - add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2); |
|
| 706 | - add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2); |
|
| 707 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
| 708 | - $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
| 709 | - $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
| 710 | - |
|
| 711 | - $country_input_types = [ |
|
| 712 | - 'CNT_active' => [ |
|
| 713 | - 'type' => 'RADIO_BTN', |
|
| 714 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 715 | - 'class' => '', |
|
| 716 | - 'options' => $this->_yes_no_values, |
|
| 717 | - 'use_desc_4_label' => true, |
|
| 718 | - ], |
|
| 719 | - 'CNT_ISO' => [ |
|
| 720 | - 'type' => 'TEXT', |
|
| 721 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 722 | - 'class' => 'small-text', |
|
| 723 | - ], |
|
| 724 | - 'CNT_ISO3' => [ |
|
| 725 | - 'type' => 'TEXT', |
|
| 726 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 727 | - 'class' => 'small-text', |
|
| 728 | - ], |
|
| 729 | - // 'RGN_ID' => [ |
|
| 730 | - // 'type' => 'TEXT', |
|
| 731 | - // 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 732 | - // 'class' => 'ee-input-size--small', |
|
| 733 | - // ], |
|
| 734 | - 'CNT_name' => [ |
|
| 735 | - 'type' => 'TEXT', |
|
| 736 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 737 | - 'class' => 'regular-text', |
|
| 738 | - ], |
|
| 739 | - 'CNT_cur_code' => [ |
|
| 740 | - 'type' => 'TEXT', |
|
| 741 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 742 | - 'class' => 'small-text', |
|
| 743 | - 'disabled' => $CNT_cur_disabled, |
|
| 744 | - ], |
|
| 745 | - 'CNT_cur_single' => [ |
|
| 746 | - 'type' => 'TEXT', |
|
| 747 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 748 | - 'class' => 'medium-text', |
|
| 749 | - 'disabled' => $CNT_cur_disabled, |
|
| 750 | - ], |
|
| 751 | - 'CNT_cur_plural' => [ |
|
| 752 | - 'type' => 'TEXT', |
|
| 753 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 754 | - 'class' => 'medium-text', |
|
| 755 | - 'disabled' => $CNT_cur_disabled, |
|
| 756 | - ], |
|
| 757 | - 'CNT_cur_sign' => [ |
|
| 758 | - 'type' => 'TEXT', |
|
| 759 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 760 | - 'class' => 'small-text', |
|
| 761 | - 'htmlentities' => false, |
|
| 762 | - 'disabled' => $CNT_cur_disabled, |
|
| 763 | - ], |
|
| 764 | - 'CNT_cur_sign_b4' => [ |
|
| 765 | - 'type' => 'RADIO_BTN', |
|
| 766 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 767 | - 'class' => '', |
|
| 768 | - 'options' => $this->_yes_no_values, |
|
| 769 | - 'use_desc_4_label' => true, |
|
| 770 | - 'disabled' => $CNT_cur_disabled, |
|
| 771 | - ], |
|
| 772 | - 'CNT_cur_dec_plc' => [ |
|
| 773 | - 'type' => 'RADIO_BTN', |
|
| 774 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 775 | - 'class' => '', |
|
| 776 | - 'options' => [ |
|
| 777 | - ['id' => 0, 'text' => ''], |
|
| 778 | - ['id' => 1, 'text' => ''], |
|
| 779 | - ['id' => 2, 'text' => ''], |
|
| 780 | - ['id' => 3, 'text' => ''], |
|
| 781 | - ], |
|
| 782 | - 'disabled' => $CNT_cur_disabled, |
|
| 783 | - ], |
|
| 784 | - 'CNT_cur_dec_mrk' => [ |
|
| 785 | - 'type' => 'RADIO_BTN', |
|
| 786 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 787 | - 'class' => '', |
|
| 788 | - 'options' => [ |
|
| 789 | - [ |
|
| 790 | - 'id' => ',', |
|
| 791 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
| 792 | - ], |
|
| 793 | - ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')], |
|
| 794 | - ], |
|
| 795 | - 'use_desc_4_label' => true, |
|
| 796 | - 'disabled' => $CNT_cur_disabled, |
|
| 797 | - ], |
|
| 798 | - 'CNT_cur_thsnds' => [ |
|
| 799 | - 'type' => 'RADIO_BTN', |
|
| 800 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 801 | - 'class' => '', |
|
| 802 | - 'options' => [ |
|
| 803 | - [ |
|
| 804 | - 'id' => ',', |
|
| 805 | - 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
| 806 | - ], |
|
| 807 | - [ |
|
| 808 | - 'id' => '.', |
|
| 809 | - 'text' => esc_html__('. (decimal)', 'event_espresso'), |
|
| 810 | - ], |
|
| 811 | - [ |
|
| 812 | - 'id' => ' ', |
|
| 813 | - 'text' => esc_html__('(space)', 'event_espresso'), |
|
| 814 | - ], |
|
| 815 | - ], |
|
| 816 | - 'use_desc_4_label' => true, |
|
| 817 | - 'disabled' => $CNT_cur_disabled, |
|
| 818 | - ], |
|
| 819 | - 'CNT_tel_code' => [ |
|
| 820 | - 'type' => 'TEXT', |
|
| 821 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 822 | - 'class' => 'small-text', |
|
| 823 | - ], |
|
| 824 | - 'CNT_is_EU' => [ |
|
| 825 | - 'type' => 'RADIO_BTN', |
|
| 826 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 827 | - 'class' => '', |
|
| 828 | - 'options' => $this->_yes_no_values, |
|
| 829 | - 'use_desc_4_label' => true, |
|
| 830 | - ], |
|
| 831 | - ]; |
|
| 832 | - $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 833 | - $country, |
|
| 834 | - $country_input_types |
|
| 835 | - ); |
|
| 836 | - $country_details_settings = EEH_Template::display_template( |
|
| 837 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 838 | - $this->_template_args, |
|
| 839 | - true |
|
| 840 | - ); |
|
| 841 | - |
|
| 842 | - if (defined('DOING_AJAX')) { |
|
| 843 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 844 | - echo wp_json_encode( |
|
| 845 | - [ |
|
| 846 | - 'return_data' => $country_details_settings, |
|
| 847 | - 'success' => $notices['success'], |
|
| 848 | - 'errors' => $notices['errors'], |
|
| 849 | - ] |
|
| 850 | - ); |
|
| 851 | - die(); |
|
| 852 | - } |
|
| 853 | - return $country_details_settings; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * @param string $CNT_ISO |
|
| 859 | - * @param EE_Country|null $country |
|
| 860 | - * @return string |
|
| 861 | - * @throws DomainException |
|
| 862 | - * @throws EE_Error |
|
| 863 | - * @throws InvalidArgumentException |
|
| 864 | - * @throws InvalidDataTypeException |
|
| 865 | - * @throws InvalidInterfaceException |
|
| 866 | - * @throws ReflectionException |
|
| 867 | - */ |
|
| 868 | - public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
| 869 | - { |
|
| 870 | - $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
| 871 | - if (! $CNT_ISO) { |
|
| 872 | - return ''; |
|
| 873 | - } |
|
| 874 | - // for ajax |
|
| 875 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 876 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 877 | - add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2); |
|
| 878 | - add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10); |
|
| 879 | - $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
| 880 | - if (empty($states)) { |
|
| 881 | - /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
| 882 | - $countrySubRegionDao = $this->loader->getShared( |
|
| 883 | - 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
| 884 | - ); |
|
| 885 | - if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
| 886 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
| 887 | - if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
| 888 | - $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
| 889 | - } |
|
| 890 | - } |
|
| 891 | - } |
|
| 892 | - if (is_array($states)) { |
|
| 893 | - foreach ($states as $STA_ID => $state) { |
|
| 894 | - if ($state instanceof EE_State) { |
|
| 895 | - $inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 896 | - $state, |
|
| 897 | - [ |
|
| 898 | - 'STA_abbrev' => [ |
|
| 899 | - 'type' => 'TEXT', |
|
| 900 | - 'label' => esc_html__('Code', 'event_espresso'), |
|
| 901 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 902 | - 'class' => 'small-text', |
|
| 903 | - 'add_mobile_label' => true, |
|
| 904 | - ], |
|
| 905 | - 'STA_name' => [ |
|
| 906 | - 'type' => 'TEXT', |
|
| 907 | - 'label' => esc_html__('Name', 'event_espresso'), |
|
| 908 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 909 | - 'class' => 'regular-text', |
|
| 910 | - 'add_mobile_label' => true, |
|
| 911 | - ], |
|
| 912 | - 'STA_active' => [ |
|
| 913 | - 'type' => 'RADIO_BTN', |
|
| 914 | - 'label' => esc_html__( |
|
| 915 | - 'State Appears in Dropdown Select Lists', |
|
| 916 | - 'event_espresso' |
|
| 917 | - ), |
|
| 918 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 919 | - 'options' => $this->_yes_no_values, |
|
| 920 | - 'use_desc_4_label' => true, |
|
| 921 | - 'add_mobile_label' => true, |
|
| 922 | - ], |
|
| 923 | - ] |
|
| 924 | - ); |
|
| 925 | - |
|
| 926 | - $delete_state_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 927 | - [ |
|
| 928 | - 'action' => 'delete_state', |
|
| 929 | - 'STA_ID' => $STA_ID, |
|
| 930 | - 'CNT_ISO' => $CNT_ISO, |
|
| 931 | - 'STA_abbrev' => $state->abbrev(), |
|
| 932 | - ], |
|
| 933 | - GEN_SET_ADMIN_URL |
|
| 934 | - ); |
|
| 935 | - |
|
| 936 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = $inputs; |
|
| 937 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url; |
|
| 938 | - } |
|
| 939 | - } |
|
| 940 | - } else { |
|
| 941 | - $this->_template_args['states'] = false; |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 945 | - ['action' => 'add_new_state'], |
|
| 946 | - GEN_SET_ADMIN_URL |
|
| 947 | - ); |
|
| 948 | - |
|
| 949 | - $state_details_settings = EEH_Template::display_template( |
|
| 950 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 951 | - $this->_template_args, |
|
| 952 | - true |
|
| 953 | - ); |
|
| 954 | - |
|
| 955 | - if (defined('DOING_AJAX')) { |
|
| 956 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 957 | - echo wp_json_encode( |
|
| 958 | - [ |
|
| 959 | - 'return_data' => $state_details_settings, |
|
| 960 | - 'success' => $notices['success'], |
|
| 961 | - 'errors' => $notices['errors'], |
|
| 962 | - ] |
|
| 963 | - ); |
|
| 964 | - die(); |
|
| 965 | - } |
|
| 966 | - return $state_details_settings; |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - |
|
| 970 | - /** |
|
| 971 | - * @return void |
|
| 972 | - * @throws EE_Error |
|
| 973 | - * @throws InvalidArgumentException |
|
| 974 | - * @throws InvalidDataTypeException |
|
| 975 | - * @throws InvalidInterfaceException |
|
| 976 | - * @throws ReflectionException |
|
| 977 | - */ |
|
| 978 | - public function add_new_state() |
|
| 979 | - { |
|
| 980 | - $success = true; |
|
| 981 | - $CNT_ISO = $this->getCountryISO(''); |
|
| 982 | - if (! $CNT_ISO) { |
|
| 983 | - EE_Error::add_error( |
|
| 984 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 985 | - __FILE__, |
|
| 986 | - __FUNCTION__, |
|
| 987 | - __LINE__ |
|
| 988 | - ); |
|
| 989 | - $success = false; |
|
| 990 | - } |
|
| 991 | - $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
| 992 | - if (! $STA_abbrev) { |
|
| 993 | - EE_Error::add_error( |
|
| 994 | - esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
| 995 | - __FILE__, |
|
| 996 | - __FUNCTION__, |
|
| 997 | - __LINE__ |
|
| 998 | - ); |
|
| 999 | - $success = false; |
|
| 1000 | - } |
|
| 1001 | - $STA_name = $this->request->getRequestParam('STA_name'); |
|
| 1002 | - if (! $STA_name) { |
|
| 1003 | - EE_Error::add_error( |
|
| 1004 | - esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
| 1005 | - __FILE__, |
|
| 1006 | - __FUNCTION__, |
|
| 1007 | - __LINE__ |
|
| 1008 | - ); |
|
| 1009 | - $success = false; |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - if ($success) { |
|
| 1013 | - $cols_n_values = [ |
|
| 1014 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1015 | - 'STA_abbrev' => $STA_abbrev, |
|
| 1016 | - 'STA_name' => $STA_name, |
|
| 1017 | - 'STA_active' => true, |
|
| 1018 | - ]; |
|
| 1019 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1020 | - EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - if (defined('DOING_AJAX')) { |
|
| 1024 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1025 | - echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO])); |
|
| 1026 | - die(); |
|
| 1027 | - } else { |
|
| 1028 | - $this->_redirect_after_action( |
|
| 1029 | - $success, |
|
| 1030 | - esc_html__('State', 'event_espresso'), |
|
| 1031 | - 'added', |
|
| 1032 | - ['action' => 'country_settings'] |
|
| 1033 | - ); |
|
| 1034 | - } |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - |
|
| 1038 | - /** |
|
| 1039 | - * @return void |
|
| 1040 | - * @throws EE_Error |
|
| 1041 | - * @throws InvalidArgumentException |
|
| 1042 | - * @throws InvalidDataTypeException |
|
| 1043 | - * @throws InvalidInterfaceException |
|
| 1044 | - * @throws ReflectionException |
|
| 1045 | - */ |
|
| 1046 | - public function delete_state() |
|
| 1047 | - { |
|
| 1048 | - $CNT_ISO = $this->getCountryISO(); |
|
| 1049 | - $STA_ID = $this->request->getRequestParam('STA_ID'); |
|
| 1050 | - $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
| 1051 | - |
|
| 1052 | - if (! $STA_ID) { |
|
| 1053 | - EE_Error::add_error( |
|
| 1054 | - esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
| 1055 | - __FILE__, |
|
| 1056 | - __FUNCTION__, |
|
| 1057 | - __LINE__ |
|
| 1058 | - ); |
|
| 1059 | - return; |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
| 1063 | - if ($success !== false) { |
|
| 1064 | - do_action( |
|
| 1065 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 1066 | - $CNT_ISO, |
|
| 1067 | - $STA_ID, |
|
| 1068 | - ['STA_abbrev' => $STA_abbrev] |
|
| 1069 | - ); |
|
| 1070 | - EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
| 1071 | - } |
|
| 1072 | - if (defined('DOING_AJAX')) { |
|
| 1073 | - $notices = EE_Error::get_notices(false); |
|
| 1074 | - $notices['return_data'] = true; |
|
| 1075 | - echo wp_json_encode($notices); |
|
| 1076 | - die(); |
|
| 1077 | - } else { |
|
| 1078 | - $this->_redirect_after_action( |
|
| 1079 | - $success, |
|
| 1080 | - esc_html__('State', 'event_espresso'), |
|
| 1081 | - 'deleted', |
|
| 1082 | - ['action' => 'country_settings'] |
|
| 1083 | - ); |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - |
|
| 1088 | - /** |
|
| 1089 | - * _update_country_settings |
|
| 1090 | - * |
|
| 1091 | - * @return void |
|
| 1092 | - * @throws EE_Error |
|
| 1093 | - * @throws InvalidArgumentException |
|
| 1094 | - * @throws InvalidDataTypeException |
|
| 1095 | - * @throws InvalidInterfaceException |
|
| 1096 | - * @throws ReflectionException |
|
| 1097 | - */ |
|
| 1098 | - protected function _update_country_settings() |
|
| 1099 | - { |
|
| 1100 | - $CNT_ISO = $this->getCountryISO(); |
|
| 1101 | - if (! $CNT_ISO) { |
|
| 1102 | - EE_Error::add_error( |
|
| 1103 | - esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1104 | - __FILE__, |
|
| 1105 | - __FUNCTION__, |
|
| 1106 | - __LINE__ |
|
| 1107 | - ); |
|
| 1108 | - return; |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
| 1112 | - |
|
| 1113 | - $cols_n_values = []; |
|
| 1114 | - $cols_n_values['CNT_ISO3'] = strtoupper( |
|
| 1115 | - $this->request->getRequestParam('cntry', $country->ISO3()) |
|
| 1116 | - ); |
|
| 1117 | - $cols_n_values['CNT_name'] = $this->request->getRequestParam( |
|
| 1118 | - "cntry[$CNT_ISO][CNT_name]", |
|
| 1119 | - $country->name() |
|
| 1120 | - ); |
|
| 1121 | - $cols_n_values['CNT_cur_code'] = strtoupper( |
|
| 1122 | - $this->request->getRequestParam( |
|
| 1123 | - "cntry[$CNT_ISO][CNT_cur_code]", |
|
| 1124 | - $country->currency_code() |
|
| 1125 | - ) |
|
| 1126 | - ); |
|
| 1127 | - $cols_n_values['CNT_cur_single'] = $this->request->getRequestParam( |
|
| 1128 | - "cntry[$CNT_ISO][CNT_cur_single]", |
|
| 1129 | - $country->currency_name_single() |
|
| 1130 | - ); |
|
| 1131 | - $cols_n_values['CNT_cur_plural'] = $this->request->getRequestParam( |
|
| 1132 | - "cntry[$CNT_ISO][CNT_cur_plural]", |
|
| 1133 | - $country->currency_name_plural() |
|
| 1134 | - ); |
|
| 1135 | - $cols_n_values['CNT_cur_sign'] = $this->request->getRequestParam( |
|
| 1136 | - "cntry[$CNT_ISO][CNT_cur_sign]", |
|
| 1137 | - $country->currency_sign() |
|
| 1138 | - ); |
|
| 1139 | - $cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam( |
|
| 1140 | - "cntry[$CNT_ISO][CNT_cur_sign_b4]", |
|
| 1141 | - $country->currency_sign_before(), |
|
| 1142 | - DataType::BOOL |
|
| 1143 | - ); |
|
| 1144 | - $cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam( |
|
| 1145 | - "cntry[$CNT_ISO][CNT_cur_dec_plc]", |
|
| 1146 | - $country->currency_decimal_places() |
|
| 1147 | - ); |
|
| 1148 | - $cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam( |
|
| 1149 | - "cntry[$CNT_ISO][CNT_cur_dec_mrk]", |
|
| 1150 | - $country->currency_decimal_mark() |
|
| 1151 | - ); |
|
| 1152 | - $cols_n_values['CNT_cur_thsnds'] = $this->request->getRequestParam( |
|
| 1153 | - "cntry[$CNT_ISO][CNT_cur_thsnds]", |
|
| 1154 | - $country->currency_thousands_separator() |
|
| 1155 | - ); |
|
| 1156 | - $cols_n_values['CNT_tel_code'] = $this->request->getRequestParam( |
|
| 1157 | - "cntry[$CNT_ISO][CNT_tel_code]", |
|
| 1158 | - $country->telephoneCode() |
|
| 1159 | - ); |
|
| 1160 | - $cols_n_values['CNT_active'] = $this->request->getRequestParam( |
|
| 1161 | - "cntry[$CNT_ISO][CNT_active]", |
|
| 1162 | - $country->isActive(), |
|
| 1163 | - DataType::BOOL |
|
| 1164 | - ); |
|
| 1165 | - |
|
| 1166 | - // allow filtering of country data |
|
| 1167 | - $cols_n_values = apply_filters( |
|
| 1168 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
| 1169 | - $cols_n_values |
|
| 1170 | - ); |
|
| 1171 | - |
|
| 1172 | - // where values |
|
| 1173 | - $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]]; |
|
| 1174 | - // run the update |
|
| 1175 | - $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1176 | - |
|
| 1177 | - // allow filtering of states data |
|
| 1178 | - $states = apply_filters( |
|
| 1179 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
| 1180 | - $this->request->getRequestParam('states', [], DataType::STRING, true) |
|
| 1181 | - ); |
|
| 1182 | - |
|
| 1183 | - if (! empty($states) && $success !== false) { |
|
| 1184 | - // loop thru state data ( looks like : states[75][STA_name] ) |
|
| 1185 | - foreach ($states as $STA_ID => $state) { |
|
| 1186 | - $cols_n_values = [ |
|
| 1187 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1188 | - 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
| 1189 | - 'STA_name' => sanitize_text_field($state['STA_name']), |
|
| 1190 | - 'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN), |
|
| 1191 | - ]; |
|
| 1192 | - // where values |
|
| 1193 | - $where_cols_n_values = [['STA_ID' => $STA_ID]]; |
|
| 1194 | - // run the update |
|
| 1195 | - $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1196 | - if ($success !== false) { |
|
| 1197 | - do_action( |
|
| 1198 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 1199 | - $CNT_ISO, |
|
| 1200 | - $STA_ID, |
|
| 1201 | - $cols_n_values |
|
| 1202 | - ); |
|
| 1203 | - } |
|
| 1204 | - } |
|
| 1205 | - } |
|
| 1206 | - // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
| 1207 | - if ( |
|
| 1208 | - isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 1209 | - && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 1210 | - ) { |
|
| 1211 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
| 1212 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - if ($success !== false) { |
|
| 1216 | - EE_Error::add_success( |
|
| 1217 | - esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
| 1218 | - ); |
|
| 1219 | - } |
|
| 1220 | - $this->_redirect_after_action( |
|
| 1221 | - $success, |
|
| 1222 | - '', |
|
| 1223 | - '', |
|
| 1224 | - ['action' => 'country_settings', 'country' => $CNT_ISO], |
|
| 1225 | - true |
|
| 1226 | - ); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * form_form_field_label_wrap |
|
| 1232 | - * |
|
| 1233 | - * @param string $label |
|
| 1234 | - * @return string |
|
| 1235 | - */ |
|
| 1236 | - public function country_form_field_label_wrap(string $label): string |
|
| 1237 | - { |
|
| 1238 | - return ' |
|
| 23 | + /** |
|
| 24 | + * @var EE_Core_Config |
|
| 25 | + */ |
|
| 26 | + public $core_config; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Initialize basic properties. |
|
| 31 | + */ |
|
| 32 | + protected function _init_page_props() |
|
| 33 | + { |
|
| 34 | + $this->page_slug = GEN_SET_PG_SLUG; |
|
| 35 | + $this->page_label = GEN_SET_LABEL; |
|
| 36 | + $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
| 37 | + $this->_admin_base_path = GEN_SET_ADMIN; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Set ajax hooks |
|
| 43 | + */ |
|
| 44 | + protected function _ajax_hooks() |
|
| 45 | + { |
|
| 46 | + add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']); |
|
| 47 | + add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']); |
|
| 48 | + add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3); |
|
| 49 | + add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * More page properties initialization. |
|
| 55 | + */ |
|
| 56 | + protected function _define_page_props() |
|
| 57 | + { |
|
| 58 | + $this->_admin_page_title = GEN_SET_LABEL; |
|
| 59 | + $this->_labels = ['publishbox' => esc_html__('Update Settings', 'event_espresso')]; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Set page routes property. |
|
| 65 | + */ |
|
| 66 | + protected function _set_page_routes() |
|
| 67 | + { |
|
| 68 | + $this->_page_routes = [ |
|
| 69 | + 'critical_pages' => [ |
|
| 70 | + 'func' => '_espresso_page_settings', |
|
| 71 | + 'capability' => 'manage_options', |
|
| 72 | + ], |
|
| 73 | + 'update_espresso_page_settings' => [ |
|
| 74 | + 'func' => '_update_espresso_page_settings', |
|
| 75 | + 'capability' => 'manage_options', |
|
| 76 | + 'noheader' => true, |
|
| 77 | + ], |
|
| 78 | + 'default' => [ |
|
| 79 | + 'func' => '_your_organization_settings', |
|
| 80 | + 'capability' => 'manage_options', |
|
| 81 | + ], |
|
| 82 | + |
|
| 83 | + 'update_your_organization_settings' => [ |
|
| 84 | + 'func' => '_update_your_organization_settings', |
|
| 85 | + 'capability' => 'manage_options', |
|
| 86 | + 'noheader' => true, |
|
| 87 | + ], |
|
| 88 | + |
|
| 89 | + 'admin_option_settings' => [ |
|
| 90 | + 'func' => '_admin_option_settings', |
|
| 91 | + 'capability' => 'manage_options', |
|
| 92 | + ], |
|
| 93 | + |
|
| 94 | + 'update_admin_option_settings' => [ |
|
| 95 | + 'func' => '_update_admin_option_settings', |
|
| 96 | + 'capability' => 'manage_options', |
|
| 97 | + 'noheader' => true, |
|
| 98 | + ], |
|
| 99 | + |
|
| 100 | + 'country_settings' => [ |
|
| 101 | + 'func' => '_country_settings', |
|
| 102 | + 'capability' => 'manage_options', |
|
| 103 | + ], |
|
| 104 | + |
|
| 105 | + 'update_country_settings' => [ |
|
| 106 | + 'func' => '_update_country_settings', |
|
| 107 | + 'capability' => 'manage_options', |
|
| 108 | + 'noheader' => true, |
|
| 109 | + ], |
|
| 110 | + |
|
| 111 | + 'display_country_settings' => [ |
|
| 112 | + 'func' => 'display_country_settings', |
|
| 113 | + 'capability' => 'manage_options', |
|
| 114 | + 'noheader' => true, |
|
| 115 | + ], |
|
| 116 | + |
|
| 117 | + 'add_new_state' => [ |
|
| 118 | + 'func' => 'add_new_state', |
|
| 119 | + 'capability' => 'manage_options', |
|
| 120 | + 'noheader' => true, |
|
| 121 | + ], |
|
| 122 | + |
|
| 123 | + 'delete_state' => [ |
|
| 124 | + 'func' => 'delete_state', |
|
| 125 | + 'capability' => 'manage_options', |
|
| 126 | + 'noheader' => true, |
|
| 127 | + ], |
|
| 128 | + 'privacy_settings' => [ |
|
| 129 | + 'func' => 'privacySettings', |
|
| 130 | + 'capability' => 'manage_options', |
|
| 131 | + ], |
|
| 132 | + 'update_privacy_settings' => [ |
|
| 133 | + 'func' => 'updatePrivacySettings', |
|
| 134 | + 'capability' => 'manage_options', |
|
| 135 | + 'noheader' => true, |
|
| 136 | + 'headers_sent_route' => 'privacy_settings', |
|
| 137 | + ], |
|
| 138 | + ]; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Set page configuration property |
|
| 144 | + */ |
|
| 145 | + protected function _set_page_config() |
|
| 146 | + { |
|
| 147 | + $this->_page_config = [ |
|
| 148 | + 'critical_pages' => [ |
|
| 149 | + 'nav' => [ |
|
| 150 | + 'label' => esc_html__('Critical Pages', 'event_espresso'), |
|
| 151 | + 'order' => 50, |
|
| 152 | + ], |
|
| 153 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 154 | + 'help_tabs' => [ |
|
| 155 | + 'general_settings_critical_pages_help_tab' => [ |
|
| 156 | + 'title' => esc_html__('Critical Pages', 'event_espresso'), |
|
| 157 | + 'filename' => 'general_settings_critical_pages', |
|
| 158 | + ], |
|
| 159 | + ], |
|
| 160 | + 'require_nonce' => false, |
|
| 161 | + ], |
|
| 162 | + 'default' => [ |
|
| 163 | + 'nav' => [ |
|
| 164 | + 'label' => esc_html__('Your Organization', 'event_espresso'), |
|
| 165 | + 'order' => 20, |
|
| 166 | + ], |
|
| 167 | + 'help_tabs' => [ |
|
| 168 | + 'general_settings_your_organization_help_tab' => [ |
|
| 169 | + 'title' => esc_html__('Your Organization', 'event_espresso'), |
|
| 170 | + 'filename' => 'general_settings_your_organization', |
|
| 171 | + ], |
|
| 172 | + ], |
|
| 173 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 174 | + 'require_nonce' => false, |
|
| 175 | + ], |
|
| 176 | + 'admin_option_settings' => [ |
|
| 177 | + 'nav' => [ |
|
| 178 | + 'label' => esc_html__('Admin Options', 'event_espresso'), |
|
| 179 | + 'order' => 60, |
|
| 180 | + ], |
|
| 181 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 182 | + 'help_tabs' => [ |
|
| 183 | + 'general_settings_admin_options_help_tab' => [ |
|
| 184 | + 'title' => esc_html__('Admin Options', 'event_espresso'), |
|
| 185 | + 'filename' => 'general_settings_admin_options', |
|
| 186 | + ], |
|
| 187 | + ], |
|
| 188 | + 'require_nonce' => false, |
|
| 189 | + ], |
|
| 190 | + 'country_settings' => [ |
|
| 191 | + 'nav' => [ |
|
| 192 | + 'label' => esc_html__('Countries', 'event_espresso'), |
|
| 193 | + 'order' => 70, |
|
| 194 | + ], |
|
| 195 | + 'help_tabs' => [ |
|
| 196 | + 'general_settings_countries_help_tab' => [ |
|
| 197 | + 'title' => esc_html__('Countries', 'event_espresso'), |
|
| 198 | + 'filename' => 'general_settings_countries', |
|
| 199 | + ], |
|
| 200 | + ], |
|
| 201 | + 'require_nonce' => false, |
|
| 202 | + ], |
|
| 203 | + 'privacy_settings' => [ |
|
| 204 | + 'nav' => [ |
|
| 205 | + 'label' => esc_html__('Privacy', 'event_espresso'), |
|
| 206 | + 'order' => 80, |
|
| 207 | + ], |
|
| 208 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 209 | + 'require_nonce' => false, |
|
| 210 | + ], |
|
| 211 | + ]; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + protected function _add_screen_options() |
|
| 216 | + { |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + protected function _add_feature_pointers() |
|
| 221 | + { |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
| 227 | + */ |
|
| 228 | + public function load_scripts_styles() |
|
| 229 | + { |
|
| 230 | + // styles |
|
| 231 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 232 | + // scripts |
|
| 233 | + wp_enqueue_script('ee_admin_js'); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Execute logic running on `admin_init` |
|
| 239 | + */ |
|
| 240 | + public function admin_init() |
|
| 241 | + { |
|
| 242 | + $this->core_config = EE_Registry::instance()->CFG->core; |
|
| 243 | + |
|
| 244 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags( |
|
| 245 | + esc_html__( |
|
| 246 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 247 | + 'event_espresso' |
|
| 248 | + ) |
|
| 249 | + ); |
|
| 250 | + EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags( |
|
| 251 | + esc_html__( |
|
| 252 | + 'An error occurred! Please refresh the page and try again.', |
|
| 253 | + 'event_espresso' |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags( |
|
| 257 | + esc_html__( |
|
| 258 | + 'Are you sure you want to delete this State / Province?', |
|
| 259 | + 'event_espresso' |
|
| 260 | + ) |
|
| 261 | + ); |
|
| 262 | + EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
| 263 | + 'admin-ajax.php?page=espresso_general_settings', |
|
| 264 | + is_ssl() ? 'https://' : 'http://' |
|
| 265 | + ); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + public function admin_notices() |
|
| 270 | + { |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + public function admin_footer_scripts() |
|
| 275 | + { |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Enqueue scripts and styles for the default route. |
|
| 281 | + */ |
|
| 282 | + public function load_scripts_styles_default() |
|
| 283 | + { |
|
| 284 | + // styles |
|
| 285 | + wp_enqueue_style('thickbox'); |
|
| 286 | + // scripts |
|
| 287 | + wp_enqueue_script('media-upload'); |
|
| 288 | + wp_enqueue_script('thickbox'); |
|
| 289 | + wp_register_script( |
|
| 290 | + 'organization_settings', |
|
| 291 | + GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 292 | + ['jquery', 'media-upload', 'thickbox'], |
|
| 293 | + EVENT_ESPRESSO_VERSION, |
|
| 294 | + true |
|
| 295 | + ); |
|
| 296 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
| 297 | + wp_enqueue_script('organization_settings'); |
|
| 298 | + wp_enqueue_style('organization-css'); |
|
| 299 | + $confirm_image_delete = [ |
|
| 300 | + 'text' => wp_strip_all_tags( |
|
| 301 | + esc_html__( |
|
| 302 | + 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
| 303 | + 'event_espresso' |
|
| 304 | + ) |
|
| 305 | + ), |
|
| 306 | + ]; |
|
| 307 | + wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Enqueue scripts and styles for the country settings route. |
|
| 313 | + */ |
|
| 314 | + public function load_scripts_styles_country_settings() |
|
| 315 | + { |
|
| 316 | + // scripts |
|
| 317 | + wp_register_script( |
|
| 318 | + 'gen_settings_countries', |
|
| 319 | + GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 320 | + ['ee_admin_js'], |
|
| 321 | + EVENT_ESPRESSO_VERSION, |
|
| 322 | + true |
|
| 323 | + ); |
|
| 324 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION); |
|
| 325 | + wp_enqueue_script('gen_settings_countries'); |
|
| 326 | + wp_enqueue_style('organization-css'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /************* Espresso Pages *************/ |
|
| 331 | + /** |
|
| 332 | + * _espresso_page_settings |
|
| 333 | + * |
|
| 334 | + * @throws EE_Error |
|
| 335 | + * @throws DomainException |
|
| 336 | + * @throws DomainException |
|
| 337 | + * @throws InvalidDataTypeException |
|
| 338 | + * @throws InvalidArgumentException |
|
| 339 | + */ |
|
| 340 | + protected function _espresso_page_settings() |
|
| 341 | + { |
|
| 342 | + // Check to make sure all of the main pages are set up properly, |
|
| 343 | + // if not create the default pages and display an admin notice |
|
| 344 | + EEH_Activation::verify_default_pages_exist(); |
|
| 345 | + $this->_transient_garbage_collection(); |
|
| 346 | + |
|
| 347 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 348 | + |
|
| 349 | + $this->_template_args['reg_page_id'] = $this->core_config->reg_page_id ?? null; |
|
| 350 | + $this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id) |
|
| 351 | + ? get_post($this->core_config->reg_page_id) |
|
| 352 | + : false; |
|
| 353 | + |
|
| 354 | + $this->_template_args['txn_page_id'] = $this->core_config->txn_page_id ?? null; |
|
| 355 | + $this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id) |
|
| 356 | + ? get_post($this->core_config->txn_page_id) |
|
| 357 | + : false; |
|
| 358 | + |
|
| 359 | + $this->_template_args['thank_you_page_id'] = $this->core_config->thank_you_page_id ?? null; |
|
| 360 | + $this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id) |
|
| 361 | + ? get_post($this->core_config->thank_you_page_id) |
|
| 362 | + : false; |
|
| 363 | + |
|
| 364 | + $this->_template_args['cancel_page_id'] = $this->core_config->cancel_page_id ?? null; |
|
| 365 | + $this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id) |
|
| 366 | + ? get_post($this->core_config->cancel_page_id) |
|
| 367 | + : false; |
|
| 368 | + |
|
| 369 | + $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
| 370 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 371 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 372 | + GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 373 | + $this->_template_args, |
|
| 374 | + true |
|
| 375 | + ); |
|
| 376 | + $this->display_admin_page_with_sidebar(); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Handler for updating espresso page settings. |
|
| 382 | + * |
|
| 383 | + * @throws EE_Error |
|
| 384 | + */ |
|
| 385 | + protected function _update_espresso_page_settings() |
|
| 386 | + { |
|
| 387 | + // capture incoming request data && set page IDs |
|
| 388 | + $this->core_config->reg_page_id = $this->request->getRequestParam( |
|
| 389 | + 'reg_page_id', |
|
| 390 | + $this->core_config->reg_page_id, |
|
| 391 | + DataType::INT |
|
| 392 | + ); |
|
| 393 | + $this->core_config->txn_page_id = $this->request->getRequestParam( |
|
| 394 | + 'txn_page_id', |
|
| 395 | + $this->core_config->txn_page_id, |
|
| 396 | + DataType::INT |
|
| 397 | + ); |
|
| 398 | + $this->core_config->thank_you_page_id = $this->request->getRequestParam( |
|
| 399 | + 'thank_you_page_id', |
|
| 400 | + $this->core_config->thank_you_page_id, |
|
| 401 | + DataType::INT |
|
| 402 | + ); |
|
| 403 | + $this->core_config->cancel_page_id = $this->request->getRequestParam( |
|
| 404 | + 'cancel_page_id', |
|
| 405 | + $this->core_config->cancel_page_id, |
|
| 406 | + DataType::INT |
|
| 407 | + ); |
|
| 408 | + |
|
| 409 | + $this->core_config = apply_filters( |
|
| 410 | + 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
| 411 | + $this->core_config, |
|
| 412 | + $this->request->requestParams() |
|
| 413 | + ); |
|
| 414 | + |
|
| 415 | + $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 416 | + $this->_redirect_after_action( |
|
| 417 | + $this->_update_espresso_configuration( |
|
| 418 | + $what, |
|
| 419 | + $this->core_config, |
|
| 420 | + __FILE__, |
|
| 421 | + __FUNCTION__, |
|
| 422 | + __LINE__ |
|
| 423 | + ), |
|
| 424 | + $what, |
|
| 425 | + '', |
|
| 426 | + [ |
|
| 427 | + 'action' => 'critical_pages', |
|
| 428 | + ], |
|
| 429 | + true |
|
| 430 | + ); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /************* Your Organization *************/ |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * @throws DomainException |
|
| 439 | + * @throws EE_Error |
|
| 440 | + * @throws InvalidArgumentException |
|
| 441 | + * @throws InvalidDataTypeException |
|
| 442 | + * @throws InvalidInterfaceException |
|
| 443 | + */ |
|
| 444 | + protected function _your_organization_settings() |
|
| 445 | + { |
|
| 446 | + $this->_template_args['admin_page_content'] = ''; |
|
| 447 | + try { |
|
| 448 | + /** @var OrganizationSettings $organization_settings_form */ |
|
| 449 | + $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
| 450 | + |
|
| 451 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
| 452 | + $organization_settings_form->display(), |
|
| 453 | + '', |
|
| 454 | + 'padding' |
|
| 455 | + ); |
|
| 456 | + } catch (Exception $e) { |
|
| 457 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 458 | + } |
|
| 459 | + $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
| 460 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 461 | + $this->display_admin_page_with_sidebar(); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Handler for updating organization settings. |
|
| 467 | + * |
|
| 468 | + * @throws EE_Error |
|
| 469 | + */ |
|
| 470 | + protected function _update_your_organization_settings() |
|
| 471 | + { |
|
| 472 | + try { |
|
| 473 | + /** @var OrganizationSettings $organization_settings_form */ |
|
| 474 | + $organization_settings_form = $this->loader->getShared(OrganizationSettings::class); |
|
| 475 | + |
|
| 476 | + $success = $organization_settings_form->process($this->request->requestParams()); |
|
| 477 | + |
|
| 478 | + EE_Registry::instance()->CFG = apply_filters( |
|
| 479 | + 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
| 480 | + EE_Registry::instance()->CFG |
|
| 481 | + ); |
|
| 482 | + } catch (Exception $e) { |
|
| 483 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 484 | + $success = false; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + if ($success) { |
|
| 488 | + $success = $this->_update_espresso_configuration( |
|
| 489 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
| 490 | + EE_Registry::instance()->CFG, |
|
| 491 | + __FILE__, |
|
| 492 | + __FUNCTION__, |
|
| 493 | + __LINE__ |
|
| 494 | + ); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + $this->_redirect_after_action($success, '', '', ['action' => 'default'], true); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /************* Admin Options *************/ |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * _admin_option_settings |
|
| 507 | + * |
|
| 508 | + * @throws EE_Error |
|
| 509 | + * @throws LogicException |
|
| 510 | + */ |
|
| 511 | + protected function _admin_option_settings() |
|
| 512 | + { |
|
| 513 | + $this->_template_args['admin_page_content'] = ''; |
|
| 514 | + try { |
|
| 515 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 516 | + // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
| 517 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 518 | + // also need to account for the do_action that was in the old template |
|
| 519 | + $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
| 520 | + $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
| 521 | + } catch (Exception $e) { |
|
| 522 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 523 | + } |
|
| 524 | + $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
| 525 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 526 | + $this->display_admin_page_with_sidebar(); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * _update_admin_option_settings |
|
| 532 | + * |
|
| 533 | + * @throws EE_Error |
|
| 534 | + * @throws InvalidDataTypeException |
|
| 535 | + * @throws InvalidFormSubmissionException |
|
| 536 | + * @throws InvalidArgumentException |
|
| 537 | + * @throws LogicException |
|
| 538 | + */ |
|
| 539 | + protected function _update_admin_option_settings() |
|
| 540 | + { |
|
| 541 | + try { |
|
| 542 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 543 | + $admin_options_settings_form->process( |
|
| 544 | + $this->request->getRequestParam( |
|
| 545 | + $admin_options_settings_form->slug(), |
|
| 546 | + [], |
|
| 547 | + DataType::OBJECT // need to change this to ARRAY after min PHP version gets bumped to 7+ |
|
| 548 | + ) |
|
| 549 | + ); |
|
| 550 | + EE_Registry::instance()->CFG->admin = apply_filters( |
|
| 551 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
| 552 | + EE_Registry::instance()->CFG->admin |
|
| 553 | + ); |
|
| 554 | + } catch (Exception $e) { |
|
| 555 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 556 | + } |
|
| 557 | + $this->_redirect_after_action( |
|
| 558 | + apply_filters( |
|
| 559 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
| 560 | + $this->_update_espresso_configuration( |
|
| 561 | + esc_html__('Admin Options', 'event_espresso'), |
|
| 562 | + EE_Registry::instance()->CFG->admin, |
|
| 563 | + __FILE__, |
|
| 564 | + __FUNCTION__, |
|
| 565 | + __LINE__ |
|
| 566 | + ) |
|
| 567 | + ), |
|
| 568 | + esc_html__('Admin Options', 'event_espresso'), |
|
| 569 | + 'updated', |
|
| 570 | + ['action' => 'admin_option_settings'] |
|
| 571 | + ); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /************* Countries *************/ |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * @param string|null $default |
|
| 580 | + * @return string |
|
| 581 | + */ |
|
| 582 | + protected function getCountryISO(?string $default = null): string |
|
| 583 | + { |
|
| 584 | + $default = $default ?? $this->getCountryIsoForSite(); |
|
| 585 | + $CNT_ISO = $this->request->getRequestParam('country', $default); |
|
| 586 | + $CNT_ISO = $this->request->getRequestParam('CNT_ISO', $CNT_ISO); |
|
| 587 | + return strtoupper($CNT_ISO); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * @return string |
|
| 593 | + */ |
|
| 594 | + protected function getCountryIsoForSite(): string |
|
| 595 | + { |
|
| 596 | + return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 597 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 598 | + : 'US'; |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * @param string $CNT_ISO |
|
| 604 | + * @param EE_Country|null $country |
|
| 605 | + * @return EE_Base_Class|EE_Country |
|
| 606 | + * @throws EE_Error |
|
| 607 | + * @throws InvalidArgumentException |
|
| 608 | + * @throws InvalidDataTypeException |
|
| 609 | + * @throws InvalidInterfaceException |
|
| 610 | + * @throws ReflectionException |
|
| 611 | + */ |
|
| 612 | + protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null) |
|
| 613 | + { |
|
| 614 | + /** @var EE_Country $country */ |
|
| 615 | + return $country instanceof EE_Country && $country->ID() === $CNT_ISO |
|
| 616 | + ? $country |
|
| 617 | + : EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Output Country Settings view. |
|
| 623 | + * |
|
| 624 | + * @throws DomainException |
|
| 625 | + * @throws EE_Error |
|
| 626 | + * @throws InvalidArgumentException |
|
| 627 | + * @throws InvalidDataTypeException |
|
| 628 | + * @throws InvalidInterfaceException |
|
| 629 | + * @throws ReflectionException |
|
| 630 | + */ |
|
| 631 | + protected function _country_settings() |
|
| 632 | + { |
|
| 633 | + $CNT_ISO = $this->getCountryISO(); |
|
| 634 | + |
|
| 635 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 636 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 637 | + EE_Question::new_instance( |
|
| 638 | + [ |
|
| 639 | + 'QST_ID' => 0, |
|
| 640 | + 'QST_display_text' => esc_html__('Select Country', 'event_espresso'), |
|
| 641 | + 'QST_system' => 'admin-country', |
|
| 642 | + ] |
|
| 643 | + ), |
|
| 644 | + EE_Answer::new_instance( |
|
| 645 | + [ |
|
| 646 | + 'ANS_ID' => 0, |
|
| 647 | + 'ANS_value' => $CNT_ISO, |
|
| 648 | + ] |
|
| 649 | + ), |
|
| 650 | + [ |
|
| 651 | + 'input_id' => 'country', |
|
| 652 | + 'input_name' => 'country', |
|
| 653 | + 'input_prefix' => '', |
|
| 654 | + 'append_qstn_id' => false, |
|
| 655 | + ] |
|
| 656 | + ); |
|
| 657 | + |
|
| 658 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
| 659 | + add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10); |
|
| 660 | + add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10); |
|
| 661 | + $this->_template_args['country_details_settings'] = $this->display_country_settings( |
|
| 662 | + $country->ID(), |
|
| 663 | + $country |
|
| 664 | + ); |
|
| 665 | + $this->_template_args['country_states_settings'] = $this->display_country_states( |
|
| 666 | + $country->ID(), |
|
| 667 | + $country |
|
| 668 | + ); |
|
| 669 | + $this->_template_args['CNT_name_for_site'] = $country->name(); |
|
| 670 | + |
|
| 671 | + $this->_set_add_edit_form_tags('update_country_settings'); |
|
| 672 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 673 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 674 | + GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 675 | + $this->_template_args, |
|
| 676 | + true |
|
| 677 | + ); |
|
| 678 | + $this->display_admin_page_with_no_sidebar(); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * @param string $CNT_ISO |
|
| 684 | + * @param EE_Country|null $country |
|
| 685 | + * @return string |
|
| 686 | + * @throws DomainException |
|
| 687 | + * @throws EE_Error |
|
| 688 | + * @throws InvalidArgumentException |
|
| 689 | + * @throws InvalidDataTypeException |
|
| 690 | + * @throws InvalidInterfaceException |
|
| 691 | + * @throws ReflectionException |
|
| 692 | + */ |
|
| 693 | + public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
| 694 | + { |
|
| 695 | + $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
| 696 | + $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
| 697 | + |
|
| 698 | + if (! $CNT_ISO) { |
|
| 699 | + return ''; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + // for ajax |
|
| 703 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 704 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 705 | + add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2); |
|
| 706 | + add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2); |
|
| 707 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
| 708 | + $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
| 709 | + $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
| 710 | + |
|
| 711 | + $country_input_types = [ |
|
| 712 | + 'CNT_active' => [ |
|
| 713 | + 'type' => 'RADIO_BTN', |
|
| 714 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 715 | + 'class' => '', |
|
| 716 | + 'options' => $this->_yes_no_values, |
|
| 717 | + 'use_desc_4_label' => true, |
|
| 718 | + ], |
|
| 719 | + 'CNT_ISO' => [ |
|
| 720 | + 'type' => 'TEXT', |
|
| 721 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 722 | + 'class' => 'small-text', |
|
| 723 | + ], |
|
| 724 | + 'CNT_ISO3' => [ |
|
| 725 | + 'type' => 'TEXT', |
|
| 726 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 727 | + 'class' => 'small-text', |
|
| 728 | + ], |
|
| 729 | + // 'RGN_ID' => [ |
|
| 730 | + // 'type' => 'TEXT', |
|
| 731 | + // 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 732 | + // 'class' => 'ee-input-size--small', |
|
| 733 | + // ], |
|
| 734 | + 'CNT_name' => [ |
|
| 735 | + 'type' => 'TEXT', |
|
| 736 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 737 | + 'class' => 'regular-text', |
|
| 738 | + ], |
|
| 739 | + 'CNT_cur_code' => [ |
|
| 740 | + 'type' => 'TEXT', |
|
| 741 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 742 | + 'class' => 'small-text', |
|
| 743 | + 'disabled' => $CNT_cur_disabled, |
|
| 744 | + ], |
|
| 745 | + 'CNT_cur_single' => [ |
|
| 746 | + 'type' => 'TEXT', |
|
| 747 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 748 | + 'class' => 'medium-text', |
|
| 749 | + 'disabled' => $CNT_cur_disabled, |
|
| 750 | + ], |
|
| 751 | + 'CNT_cur_plural' => [ |
|
| 752 | + 'type' => 'TEXT', |
|
| 753 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 754 | + 'class' => 'medium-text', |
|
| 755 | + 'disabled' => $CNT_cur_disabled, |
|
| 756 | + ], |
|
| 757 | + 'CNT_cur_sign' => [ |
|
| 758 | + 'type' => 'TEXT', |
|
| 759 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 760 | + 'class' => 'small-text', |
|
| 761 | + 'htmlentities' => false, |
|
| 762 | + 'disabled' => $CNT_cur_disabled, |
|
| 763 | + ], |
|
| 764 | + 'CNT_cur_sign_b4' => [ |
|
| 765 | + 'type' => 'RADIO_BTN', |
|
| 766 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 767 | + 'class' => '', |
|
| 768 | + 'options' => $this->_yes_no_values, |
|
| 769 | + 'use_desc_4_label' => true, |
|
| 770 | + 'disabled' => $CNT_cur_disabled, |
|
| 771 | + ], |
|
| 772 | + 'CNT_cur_dec_plc' => [ |
|
| 773 | + 'type' => 'RADIO_BTN', |
|
| 774 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 775 | + 'class' => '', |
|
| 776 | + 'options' => [ |
|
| 777 | + ['id' => 0, 'text' => ''], |
|
| 778 | + ['id' => 1, 'text' => ''], |
|
| 779 | + ['id' => 2, 'text' => ''], |
|
| 780 | + ['id' => 3, 'text' => ''], |
|
| 781 | + ], |
|
| 782 | + 'disabled' => $CNT_cur_disabled, |
|
| 783 | + ], |
|
| 784 | + 'CNT_cur_dec_mrk' => [ |
|
| 785 | + 'type' => 'RADIO_BTN', |
|
| 786 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 787 | + 'class' => '', |
|
| 788 | + 'options' => [ |
|
| 789 | + [ |
|
| 790 | + 'id' => ',', |
|
| 791 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
| 792 | + ], |
|
| 793 | + ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')], |
|
| 794 | + ], |
|
| 795 | + 'use_desc_4_label' => true, |
|
| 796 | + 'disabled' => $CNT_cur_disabled, |
|
| 797 | + ], |
|
| 798 | + 'CNT_cur_thsnds' => [ |
|
| 799 | + 'type' => 'RADIO_BTN', |
|
| 800 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 801 | + 'class' => '', |
|
| 802 | + 'options' => [ |
|
| 803 | + [ |
|
| 804 | + 'id' => ',', |
|
| 805 | + 'text' => esc_html__(', (comma)', 'event_espresso'), |
|
| 806 | + ], |
|
| 807 | + [ |
|
| 808 | + 'id' => '.', |
|
| 809 | + 'text' => esc_html__('. (decimal)', 'event_espresso'), |
|
| 810 | + ], |
|
| 811 | + [ |
|
| 812 | + 'id' => ' ', |
|
| 813 | + 'text' => esc_html__('(space)', 'event_espresso'), |
|
| 814 | + ], |
|
| 815 | + ], |
|
| 816 | + 'use_desc_4_label' => true, |
|
| 817 | + 'disabled' => $CNT_cur_disabled, |
|
| 818 | + ], |
|
| 819 | + 'CNT_tel_code' => [ |
|
| 820 | + 'type' => 'TEXT', |
|
| 821 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 822 | + 'class' => 'small-text', |
|
| 823 | + ], |
|
| 824 | + 'CNT_is_EU' => [ |
|
| 825 | + 'type' => 'RADIO_BTN', |
|
| 826 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 827 | + 'class' => '', |
|
| 828 | + 'options' => $this->_yes_no_values, |
|
| 829 | + 'use_desc_4_label' => true, |
|
| 830 | + ], |
|
| 831 | + ]; |
|
| 832 | + $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 833 | + $country, |
|
| 834 | + $country_input_types |
|
| 835 | + ); |
|
| 836 | + $country_details_settings = EEH_Template::display_template( |
|
| 837 | + GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 838 | + $this->_template_args, |
|
| 839 | + true |
|
| 840 | + ); |
|
| 841 | + |
|
| 842 | + if (defined('DOING_AJAX')) { |
|
| 843 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 844 | + echo wp_json_encode( |
|
| 845 | + [ |
|
| 846 | + 'return_data' => $country_details_settings, |
|
| 847 | + 'success' => $notices['success'], |
|
| 848 | + 'errors' => $notices['errors'], |
|
| 849 | + ] |
|
| 850 | + ); |
|
| 851 | + die(); |
|
| 852 | + } |
|
| 853 | + return $country_details_settings; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * @param string $CNT_ISO |
|
| 859 | + * @param EE_Country|null $country |
|
| 860 | + * @return string |
|
| 861 | + * @throws DomainException |
|
| 862 | + * @throws EE_Error |
|
| 863 | + * @throws InvalidArgumentException |
|
| 864 | + * @throws InvalidDataTypeException |
|
| 865 | + * @throws InvalidInterfaceException |
|
| 866 | + * @throws ReflectionException |
|
| 867 | + */ |
|
| 868 | + public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string |
|
| 869 | + { |
|
| 870 | + $CNT_ISO = $this->getCountryISO($CNT_ISO); |
|
| 871 | + if (! $CNT_ISO) { |
|
| 872 | + return ''; |
|
| 873 | + } |
|
| 874 | + // for ajax |
|
| 875 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 876 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 877 | + add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2); |
|
| 878 | + add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10); |
|
| 879 | + $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
| 880 | + if (empty($states)) { |
|
| 881 | + /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */ |
|
| 882 | + $countrySubRegionDao = $this->loader->getShared( |
|
| 883 | + 'EventEspresso\core\services\address\CountrySubRegionDao' |
|
| 884 | + ); |
|
| 885 | + if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) { |
|
| 886 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country); |
|
| 887 | + if ($countrySubRegionDao->saveCountrySubRegions($country)) { |
|
| 888 | + $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]); |
|
| 889 | + } |
|
| 890 | + } |
|
| 891 | + } |
|
| 892 | + if (is_array($states)) { |
|
| 893 | + foreach ($states as $STA_ID => $state) { |
|
| 894 | + if ($state instanceof EE_State) { |
|
| 895 | + $inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 896 | + $state, |
|
| 897 | + [ |
|
| 898 | + 'STA_abbrev' => [ |
|
| 899 | + 'type' => 'TEXT', |
|
| 900 | + 'label' => esc_html__('Code', 'event_espresso'), |
|
| 901 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 902 | + 'class' => 'small-text', |
|
| 903 | + 'add_mobile_label' => true, |
|
| 904 | + ], |
|
| 905 | + 'STA_name' => [ |
|
| 906 | + 'type' => 'TEXT', |
|
| 907 | + 'label' => esc_html__('Name', 'event_espresso'), |
|
| 908 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 909 | + 'class' => 'regular-text', |
|
| 910 | + 'add_mobile_label' => true, |
|
| 911 | + ], |
|
| 912 | + 'STA_active' => [ |
|
| 913 | + 'type' => 'RADIO_BTN', |
|
| 914 | + 'label' => esc_html__( |
|
| 915 | + 'State Appears in Dropdown Select Lists', |
|
| 916 | + 'event_espresso' |
|
| 917 | + ), |
|
| 918 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 919 | + 'options' => $this->_yes_no_values, |
|
| 920 | + 'use_desc_4_label' => true, |
|
| 921 | + 'add_mobile_label' => true, |
|
| 922 | + ], |
|
| 923 | + ] |
|
| 924 | + ); |
|
| 925 | + |
|
| 926 | + $delete_state_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 927 | + [ |
|
| 928 | + 'action' => 'delete_state', |
|
| 929 | + 'STA_ID' => $STA_ID, |
|
| 930 | + 'CNT_ISO' => $CNT_ISO, |
|
| 931 | + 'STA_abbrev' => $state->abbrev(), |
|
| 932 | + ], |
|
| 933 | + GEN_SET_ADMIN_URL |
|
| 934 | + ); |
|
| 935 | + |
|
| 936 | + $this->_template_args['states'][ $STA_ID ]['inputs'] = $inputs; |
|
| 937 | + $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url; |
|
| 938 | + } |
|
| 939 | + } |
|
| 940 | + } else { |
|
| 941 | + $this->_template_args['states'] = false; |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 945 | + ['action' => 'add_new_state'], |
|
| 946 | + GEN_SET_ADMIN_URL |
|
| 947 | + ); |
|
| 948 | + |
|
| 949 | + $state_details_settings = EEH_Template::display_template( |
|
| 950 | + GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 951 | + $this->_template_args, |
|
| 952 | + true |
|
| 953 | + ); |
|
| 954 | + |
|
| 955 | + if (defined('DOING_AJAX')) { |
|
| 956 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 957 | + echo wp_json_encode( |
|
| 958 | + [ |
|
| 959 | + 'return_data' => $state_details_settings, |
|
| 960 | + 'success' => $notices['success'], |
|
| 961 | + 'errors' => $notices['errors'], |
|
| 962 | + ] |
|
| 963 | + ); |
|
| 964 | + die(); |
|
| 965 | + } |
|
| 966 | + return $state_details_settings; |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + |
|
| 970 | + /** |
|
| 971 | + * @return void |
|
| 972 | + * @throws EE_Error |
|
| 973 | + * @throws InvalidArgumentException |
|
| 974 | + * @throws InvalidDataTypeException |
|
| 975 | + * @throws InvalidInterfaceException |
|
| 976 | + * @throws ReflectionException |
|
| 977 | + */ |
|
| 978 | + public function add_new_state() |
|
| 979 | + { |
|
| 980 | + $success = true; |
|
| 981 | + $CNT_ISO = $this->getCountryISO(''); |
|
| 982 | + if (! $CNT_ISO) { |
|
| 983 | + EE_Error::add_error( |
|
| 984 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 985 | + __FILE__, |
|
| 986 | + __FUNCTION__, |
|
| 987 | + __LINE__ |
|
| 988 | + ); |
|
| 989 | + $success = false; |
|
| 990 | + } |
|
| 991 | + $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
| 992 | + if (! $STA_abbrev) { |
|
| 993 | + EE_Error::add_error( |
|
| 994 | + esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
| 995 | + __FILE__, |
|
| 996 | + __FUNCTION__, |
|
| 997 | + __LINE__ |
|
| 998 | + ); |
|
| 999 | + $success = false; |
|
| 1000 | + } |
|
| 1001 | + $STA_name = $this->request->getRequestParam('STA_name'); |
|
| 1002 | + if (! $STA_name) { |
|
| 1003 | + EE_Error::add_error( |
|
| 1004 | + esc_html__('No State name or an invalid State name was received.', 'event_espresso'), |
|
| 1005 | + __FILE__, |
|
| 1006 | + __FUNCTION__, |
|
| 1007 | + __LINE__ |
|
| 1008 | + ); |
|
| 1009 | + $success = false; |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + if ($success) { |
|
| 1013 | + $cols_n_values = [ |
|
| 1014 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1015 | + 'STA_abbrev' => $STA_abbrev, |
|
| 1016 | + 'STA_name' => $STA_name, |
|
| 1017 | + 'STA_active' => true, |
|
| 1018 | + ]; |
|
| 1019 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1020 | + EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso')); |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + if (defined('DOING_AJAX')) { |
|
| 1024 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1025 | + echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO])); |
|
| 1026 | + die(); |
|
| 1027 | + } else { |
|
| 1028 | + $this->_redirect_after_action( |
|
| 1029 | + $success, |
|
| 1030 | + esc_html__('State', 'event_espresso'), |
|
| 1031 | + 'added', |
|
| 1032 | + ['action' => 'country_settings'] |
|
| 1033 | + ); |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + |
|
| 1038 | + /** |
|
| 1039 | + * @return void |
|
| 1040 | + * @throws EE_Error |
|
| 1041 | + * @throws InvalidArgumentException |
|
| 1042 | + * @throws InvalidDataTypeException |
|
| 1043 | + * @throws InvalidInterfaceException |
|
| 1044 | + * @throws ReflectionException |
|
| 1045 | + */ |
|
| 1046 | + public function delete_state() |
|
| 1047 | + { |
|
| 1048 | + $CNT_ISO = $this->getCountryISO(); |
|
| 1049 | + $STA_ID = $this->request->getRequestParam('STA_ID'); |
|
| 1050 | + $STA_abbrev = $this->request->getRequestParam('STA_abbrev'); |
|
| 1051 | + |
|
| 1052 | + if (! $STA_ID) { |
|
| 1053 | + EE_Error::add_error( |
|
| 1054 | + esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
| 1055 | + __FILE__, |
|
| 1056 | + __FUNCTION__, |
|
| 1057 | + __LINE__ |
|
| 1058 | + ); |
|
| 1059 | + return; |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
| 1063 | + if ($success !== false) { |
|
| 1064 | + do_action( |
|
| 1065 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 1066 | + $CNT_ISO, |
|
| 1067 | + $STA_ID, |
|
| 1068 | + ['STA_abbrev' => $STA_abbrev] |
|
| 1069 | + ); |
|
| 1070 | + EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso')); |
|
| 1071 | + } |
|
| 1072 | + if (defined('DOING_AJAX')) { |
|
| 1073 | + $notices = EE_Error::get_notices(false); |
|
| 1074 | + $notices['return_data'] = true; |
|
| 1075 | + echo wp_json_encode($notices); |
|
| 1076 | + die(); |
|
| 1077 | + } else { |
|
| 1078 | + $this->_redirect_after_action( |
|
| 1079 | + $success, |
|
| 1080 | + esc_html__('State', 'event_espresso'), |
|
| 1081 | + 'deleted', |
|
| 1082 | + ['action' => 'country_settings'] |
|
| 1083 | + ); |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + |
|
| 1088 | + /** |
|
| 1089 | + * _update_country_settings |
|
| 1090 | + * |
|
| 1091 | + * @return void |
|
| 1092 | + * @throws EE_Error |
|
| 1093 | + * @throws InvalidArgumentException |
|
| 1094 | + * @throws InvalidDataTypeException |
|
| 1095 | + * @throws InvalidInterfaceException |
|
| 1096 | + * @throws ReflectionException |
|
| 1097 | + */ |
|
| 1098 | + protected function _update_country_settings() |
|
| 1099 | + { |
|
| 1100 | + $CNT_ISO = $this->getCountryISO(); |
|
| 1101 | + if (! $CNT_ISO) { |
|
| 1102 | + EE_Error::add_error( |
|
| 1103 | + esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1104 | + __FILE__, |
|
| 1105 | + __FUNCTION__, |
|
| 1106 | + __LINE__ |
|
| 1107 | + ); |
|
| 1108 | + return; |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + $country = $this->verifyOrGetCountryFromIso($CNT_ISO); |
|
| 1112 | + |
|
| 1113 | + $cols_n_values = []; |
|
| 1114 | + $cols_n_values['CNT_ISO3'] = strtoupper( |
|
| 1115 | + $this->request->getRequestParam('cntry', $country->ISO3()) |
|
| 1116 | + ); |
|
| 1117 | + $cols_n_values['CNT_name'] = $this->request->getRequestParam( |
|
| 1118 | + "cntry[$CNT_ISO][CNT_name]", |
|
| 1119 | + $country->name() |
|
| 1120 | + ); |
|
| 1121 | + $cols_n_values['CNT_cur_code'] = strtoupper( |
|
| 1122 | + $this->request->getRequestParam( |
|
| 1123 | + "cntry[$CNT_ISO][CNT_cur_code]", |
|
| 1124 | + $country->currency_code() |
|
| 1125 | + ) |
|
| 1126 | + ); |
|
| 1127 | + $cols_n_values['CNT_cur_single'] = $this->request->getRequestParam( |
|
| 1128 | + "cntry[$CNT_ISO][CNT_cur_single]", |
|
| 1129 | + $country->currency_name_single() |
|
| 1130 | + ); |
|
| 1131 | + $cols_n_values['CNT_cur_plural'] = $this->request->getRequestParam( |
|
| 1132 | + "cntry[$CNT_ISO][CNT_cur_plural]", |
|
| 1133 | + $country->currency_name_plural() |
|
| 1134 | + ); |
|
| 1135 | + $cols_n_values['CNT_cur_sign'] = $this->request->getRequestParam( |
|
| 1136 | + "cntry[$CNT_ISO][CNT_cur_sign]", |
|
| 1137 | + $country->currency_sign() |
|
| 1138 | + ); |
|
| 1139 | + $cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam( |
|
| 1140 | + "cntry[$CNT_ISO][CNT_cur_sign_b4]", |
|
| 1141 | + $country->currency_sign_before(), |
|
| 1142 | + DataType::BOOL |
|
| 1143 | + ); |
|
| 1144 | + $cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam( |
|
| 1145 | + "cntry[$CNT_ISO][CNT_cur_dec_plc]", |
|
| 1146 | + $country->currency_decimal_places() |
|
| 1147 | + ); |
|
| 1148 | + $cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam( |
|
| 1149 | + "cntry[$CNT_ISO][CNT_cur_dec_mrk]", |
|
| 1150 | + $country->currency_decimal_mark() |
|
| 1151 | + ); |
|
| 1152 | + $cols_n_values['CNT_cur_thsnds'] = $this->request->getRequestParam( |
|
| 1153 | + "cntry[$CNT_ISO][CNT_cur_thsnds]", |
|
| 1154 | + $country->currency_thousands_separator() |
|
| 1155 | + ); |
|
| 1156 | + $cols_n_values['CNT_tel_code'] = $this->request->getRequestParam( |
|
| 1157 | + "cntry[$CNT_ISO][CNT_tel_code]", |
|
| 1158 | + $country->telephoneCode() |
|
| 1159 | + ); |
|
| 1160 | + $cols_n_values['CNT_active'] = $this->request->getRequestParam( |
|
| 1161 | + "cntry[$CNT_ISO][CNT_active]", |
|
| 1162 | + $country->isActive(), |
|
| 1163 | + DataType::BOOL |
|
| 1164 | + ); |
|
| 1165 | + |
|
| 1166 | + // allow filtering of country data |
|
| 1167 | + $cols_n_values = apply_filters( |
|
| 1168 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
| 1169 | + $cols_n_values |
|
| 1170 | + ); |
|
| 1171 | + |
|
| 1172 | + // where values |
|
| 1173 | + $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]]; |
|
| 1174 | + // run the update |
|
| 1175 | + $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1176 | + |
|
| 1177 | + // allow filtering of states data |
|
| 1178 | + $states = apply_filters( |
|
| 1179 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
| 1180 | + $this->request->getRequestParam('states', [], DataType::STRING, true) |
|
| 1181 | + ); |
|
| 1182 | + |
|
| 1183 | + if (! empty($states) && $success !== false) { |
|
| 1184 | + // loop thru state data ( looks like : states[75][STA_name] ) |
|
| 1185 | + foreach ($states as $STA_ID => $state) { |
|
| 1186 | + $cols_n_values = [ |
|
| 1187 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1188 | + 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
| 1189 | + 'STA_name' => sanitize_text_field($state['STA_name']), |
|
| 1190 | + 'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN), |
|
| 1191 | + ]; |
|
| 1192 | + // where values |
|
| 1193 | + $where_cols_n_values = [['STA_ID' => $STA_ID]]; |
|
| 1194 | + // run the update |
|
| 1195 | + $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1196 | + if ($success !== false) { |
|
| 1197 | + do_action( |
|
| 1198 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 1199 | + $CNT_ISO, |
|
| 1200 | + $STA_ID, |
|
| 1201 | + $cols_n_values |
|
| 1202 | + ); |
|
| 1203 | + } |
|
| 1204 | + } |
|
| 1205 | + } |
|
| 1206 | + // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
| 1207 | + if ( |
|
| 1208 | + isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 1209 | + && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 1210 | + ) { |
|
| 1211 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
| 1212 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + if ($success !== false) { |
|
| 1216 | + EE_Error::add_success( |
|
| 1217 | + esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
| 1218 | + ); |
|
| 1219 | + } |
|
| 1220 | + $this->_redirect_after_action( |
|
| 1221 | + $success, |
|
| 1222 | + '', |
|
| 1223 | + '', |
|
| 1224 | + ['action' => 'country_settings', 'country' => $CNT_ISO], |
|
| 1225 | + true |
|
| 1226 | + ); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * form_form_field_label_wrap |
|
| 1232 | + * |
|
| 1233 | + * @param string $label |
|
| 1234 | + * @return string |
|
| 1235 | + */ |
|
| 1236 | + public function country_form_field_label_wrap(string $label): string |
|
| 1237 | + { |
|
| 1238 | + return ' |
|
| 1239 | 1239 | <tr> |
| 1240 | 1240 | <th> |
| 1241 | 1241 | ' . $label . ' |
| 1242 | 1242 | </th>'; |
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - |
|
| 1246 | - /** |
|
| 1247 | - * form_form_field_input__wrap |
|
| 1248 | - * |
|
| 1249 | - * @param string $input |
|
| 1250 | - * @return string |
|
| 1251 | - */ |
|
| 1252 | - public function country_form_field_input__wrap(string $input): string |
|
| 1253 | - { |
|
| 1254 | - return ' |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + |
|
| 1246 | + /** |
|
| 1247 | + * form_form_field_input__wrap |
|
| 1248 | + * |
|
| 1249 | + * @param string $input |
|
| 1250 | + * @return string |
|
| 1251 | + */ |
|
| 1252 | + public function country_form_field_input__wrap(string $input): string |
|
| 1253 | + { |
|
| 1254 | + return ' |
|
| 1255 | 1255 | <td class="general-settings-country-input-td"> |
| 1256 | 1256 | ' . $input . ' |
| 1257 | 1257 | </td> |
| 1258 | 1258 | </tr>'; |
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - |
|
| 1262 | - /** |
|
| 1263 | - * form_form_field_label_wrap |
|
| 1264 | - * |
|
| 1265 | - * @param string $label |
|
| 1266 | - * @param string $required_text |
|
| 1267 | - * @return string |
|
| 1268 | - */ |
|
| 1269 | - public function state_form_field_label_wrap(string $label, string $required_text): string |
|
| 1270 | - { |
|
| 1271 | - return $required_text; |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - |
|
| 1275 | - /** |
|
| 1276 | - * form_form_field_input__wrap |
|
| 1277 | - * |
|
| 1278 | - * @param string $input |
|
| 1279 | - * @return string |
|
| 1280 | - */ |
|
| 1281 | - public function state_form_field_input__wrap(string $input): string |
|
| 1282 | - { |
|
| 1283 | - return ' |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + |
|
| 1262 | + /** |
|
| 1263 | + * form_form_field_label_wrap |
|
| 1264 | + * |
|
| 1265 | + * @param string $label |
|
| 1266 | + * @param string $required_text |
|
| 1267 | + * @return string |
|
| 1268 | + */ |
|
| 1269 | + public function state_form_field_label_wrap(string $label, string $required_text): string |
|
| 1270 | + { |
|
| 1271 | + return $required_text; |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + |
|
| 1275 | + /** |
|
| 1276 | + * form_form_field_input__wrap |
|
| 1277 | + * |
|
| 1278 | + * @param string $input |
|
| 1279 | + * @return string |
|
| 1280 | + */ |
|
| 1281 | + public function state_form_field_input__wrap(string $input): string |
|
| 1282 | + { |
|
| 1283 | + return ' |
|
| 1284 | 1284 | <td class="general-settings-country-state-input-td"> |
| 1285 | 1285 | ' . $input . ' |
| 1286 | 1286 | </td>'; |
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - |
|
| 1290 | - /***********/ |
|
| 1291 | - |
|
| 1292 | - |
|
| 1293 | - /** |
|
| 1294 | - * displays edit and view links for critical EE pages |
|
| 1295 | - * |
|
| 1296 | - * @param int $ee_page_id |
|
| 1297 | - * @return string |
|
| 1298 | - */ |
|
| 1299 | - public static function edit_view_links(int $ee_page_id): string |
|
| 1300 | - { |
|
| 1301 | - $edit_url = add_query_arg( |
|
| 1302 | - ['post' => $ee_page_id, 'action' => 'edit'], |
|
| 1303 | - admin_url('post.php') |
|
| 1304 | - ); |
|
| 1305 | - $links = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
| 1306 | - $links .= ' | '; |
|
| 1307 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
| 1308 | - |
|
| 1309 | - return $links; |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - |
|
| 1313 | - /** |
|
| 1314 | - * displays page and shortcode status for critical EE pages |
|
| 1315 | - * |
|
| 1316 | - * @param WP_Post $ee_page |
|
| 1317 | - * @param string $shortcode |
|
| 1318 | - * @return string |
|
| 1319 | - */ |
|
| 1320 | - public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string |
|
| 1321 | - { |
|
| 1322 | - // page status |
|
| 1323 | - if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
| 1324 | - $pg_colour = 'green'; |
|
| 1325 | - $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
| 1326 | - } else { |
|
| 1327 | - $pg_colour = 'red'; |
|
| 1328 | - $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - // shortcode status |
|
| 1332 | - if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
| 1333 | - $sc_colour = 'green'; |
|
| 1334 | - $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
| 1335 | - } else { |
|
| 1336 | - $sc_colour = 'red'; |
|
| 1337 | - $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1341 | - . $pg_status |
|
| 1342 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1343 | - } |
|
| 1344 | - |
|
| 1345 | - |
|
| 1346 | - /** |
|
| 1347 | - * generates a dropdown of all parent pages - copied from WP core |
|
| 1348 | - * |
|
| 1349 | - * @param int $default |
|
| 1350 | - * @param int $parent |
|
| 1351 | - * @param int $level |
|
| 1352 | - * @param bool $echo |
|
| 1353 | - * @return string; |
|
| 1354 | - */ |
|
| 1355 | - public static function page_settings_dropdown( |
|
| 1356 | - int $default = 0, |
|
| 1357 | - int $parent = 0, |
|
| 1358 | - int $level = 0, |
|
| 1359 | - bool $echo = true |
|
| 1360 | - ): string { |
|
| 1361 | - global $wpdb; |
|
| 1362 | - $items = $wpdb->get_results( |
|
| 1363 | - $wpdb->prepare( |
|
| 1364 | - "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
| 1365 | - $parent |
|
| 1366 | - ) |
|
| 1367 | - ); |
|
| 1368 | - $output = ''; |
|
| 1369 | - |
|
| 1370 | - if ($items) { |
|
| 1371 | - $level = absint($level); |
|
| 1372 | - foreach ($items as $item) { |
|
| 1373 | - $ID = absint($item->ID); |
|
| 1374 | - $post_title = wp_strip_all_tags($item->post_title); |
|
| 1375 | - $pad = str_repeat(' ', $level * 3); |
|
| 1376 | - $option = "\n\t"; |
|
| 1377 | - $option .= '<option class="level-' . $level . '" '; |
|
| 1378 | - $option .= 'value="' . $ID . '" '; |
|
| 1379 | - $option .= $ID === absint($default) ? ' selected' : ''; |
|
| 1380 | - $option .= '>'; |
|
| 1381 | - $option .= "$pad {$post_title}"; |
|
| 1382 | - $option .= '</option>'; |
|
| 1383 | - $output .= $option; |
|
| 1384 | - ob_start(); |
|
| 1385 | - parent_dropdown($default, $item->ID, $level + 1); |
|
| 1386 | - $output .= ob_get_clean(); |
|
| 1387 | - } |
|
| 1388 | - } |
|
| 1389 | - if ($echo) { |
|
| 1390 | - echo wp_kses($output, AllowedTags::getAllowedTags()); |
|
| 1391 | - return ''; |
|
| 1392 | - } |
|
| 1393 | - return $output; |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - |
|
| 1397 | - /** |
|
| 1398 | - * Loads the scripts for the privacy settings form |
|
| 1399 | - */ |
|
| 1400 | - public function load_scripts_styles_privacy_settings() |
|
| 1401 | - { |
|
| 1402 | - $form_handler = $this->loader->getShared( |
|
| 1403 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
| 1404 | - ); |
|
| 1405 | - $form_handler->enqueueStylesAndScripts(); |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - |
|
| 1409 | - /** |
|
| 1410 | - * display the privacy settings form |
|
| 1411 | - * |
|
| 1412 | - * @throws EE_Error |
|
| 1413 | - */ |
|
| 1414 | - public function privacySettings() |
|
| 1415 | - { |
|
| 1416 | - $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
| 1417 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1418 | - $form_handler = $this->loader->getShared( |
|
| 1419 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
| 1420 | - ); |
|
| 1421 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
| 1422 | - $form_handler->display(), |
|
| 1423 | - '', |
|
| 1424 | - 'padding' |
|
| 1425 | - ); |
|
| 1426 | - $this->display_admin_page_with_sidebar(); |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - |
|
| 1430 | - /** |
|
| 1431 | - * Update the privacy settings from form data |
|
| 1432 | - * |
|
| 1433 | - * @throws EE_Error |
|
| 1434 | - */ |
|
| 1435 | - public function updatePrivacySettings() |
|
| 1436 | - { |
|
| 1437 | - $form_handler = $this->loader->getShared( |
|
| 1438 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
| 1439 | - ); |
|
| 1440 | - $success = $form_handler->process($this->get_request_data()); |
|
| 1441 | - $this->_redirect_after_action( |
|
| 1442 | - $success, |
|
| 1443 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1444 | - 'updated', |
|
| 1445 | - ['action' => 'privacy_settings'] |
|
| 1446 | - ); |
|
| 1447 | - } |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + |
|
| 1290 | + /***********/ |
|
| 1291 | + |
|
| 1292 | + |
|
| 1293 | + /** |
|
| 1294 | + * displays edit and view links for critical EE pages |
|
| 1295 | + * |
|
| 1296 | + * @param int $ee_page_id |
|
| 1297 | + * @return string |
|
| 1298 | + */ |
|
| 1299 | + public static function edit_view_links(int $ee_page_id): string |
|
| 1300 | + { |
|
| 1301 | + $edit_url = add_query_arg( |
|
| 1302 | + ['post' => $ee_page_id, 'action' => 'edit'], |
|
| 1303 | + admin_url('post.php') |
|
| 1304 | + ); |
|
| 1305 | + $links = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
| 1306 | + $links .= ' | '; |
|
| 1307 | + $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>'; |
|
| 1308 | + |
|
| 1309 | + return $links; |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + |
|
| 1313 | + /** |
|
| 1314 | + * displays page and shortcode status for critical EE pages |
|
| 1315 | + * |
|
| 1316 | + * @param WP_Post $ee_page |
|
| 1317 | + * @param string $shortcode |
|
| 1318 | + * @return string |
|
| 1319 | + */ |
|
| 1320 | + public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string |
|
| 1321 | + { |
|
| 1322 | + // page status |
|
| 1323 | + if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
| 1324 | + $pg_colour = 'green'; |
|
| 1325 | + $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
| 1326 | + } else { |
|
| 1327 | + $pg_colour = 'red'; |
|
| 1328 | + $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + // shortcode status |
|
| 1332 | + if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
| 1333 | + $sc_colour = 'green'; |
|
| 1334 | + $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), ' '); |
|
| 1335 | + } else { |
|
| 1336 | + $sc_colour = 'red'; |
|
| 1337 | + $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1341 | + . $pg_status |
|
| 1342 | + . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1343 | + } |
|
| 1344 | + |
|
| 1345 | + |
|
| 1346 | + /** |
|
| 1347 | + * generates a dropdown of all parent pages - copied from WP core |
|
| 1348 | + * |
|
| 1349 | + * @param int $default |
|
| 1350 | + * @param int $parent |
|
| 1351 | + * @param int $level |
|
| 1352 | + * @param bool $echo |
|
| 1353 | + * @return string; |
|
| 1354 | + */ |
|
| 1355 | + public static function page_settings_dropdown( |
|
| 1356 | + int $default = 0, |
|
| 1357 | + int $parent = 0, |
|
| 1358 | + int $level = 0, |
|
| 1359 | + bool $echo = true |
|
| 1360 | + ): string { |
|
| 1361 | + global $wpdb; |
|
| 1362 | + $items = $wpdb->get_results( |
|
| 1363 | + $wpdb->prepare( |
|
| 1364 | + "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
| 1365 | + $parent |
|
| 1366 | + ) |
|
| 1367 | + ); |
|
| 1368 | + $output = ''; |
|
| 1369 | + |
|
| 1370 | + if ($items) { |
|
| 1371 | + $level = absint($level); |
|
| 1372 | + foreach ($items as $item) { |
|
| 1373 | + $ID = absint($item->ID); |
|
| 1374 | + $post_title = wp_strip_all_tags($item->post_title); |
|
| 1375 | + $pad = str_repeat(' ', $level * 3); |
|
| 1376 | + $option = "\n\t"; |
|
| 1377 | + $option .= '<option class="level-' . $level . '" '; |
|
| 1378 | + $option .= 'value="' . $ID . '" '; |
|
| 1379 | + $option .= $ID === absint($default) ? ' selected' : ''; |
|
| 1380 | + $option .= '>'; |
|
| 1381 | + $option .= "$pad {$post_title}"; |
|
| 1382 | + $option .= '</option>'; |
|
| 1383 | + $output .= $option; |
|
| 1384 | + ob_start(); |
|
| 1385 | + parent_dropdown($default, $item->ID, $level + 1); |
|
| 1386 | + $output .= ob_get_clean(); |
|
| 1387 | + } |
|
| 1388 | + } |
|
| 1389 | + if ($echo) { |
|
| 1390 | + echo wp_kses($output, AllowedTags::getAllowedTags()); |
|
| 1391 | + return ''; |
|
| 1392 | + } |
|
| 1393 | + return $output; |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + |
|
| 1397 | + /** |
|
| 1398 | + * Loads the scripts for the privacy settings form |
|
| 1399 | + */ |
|
| 1400 | + public function load_scripts_styles_privacy_settings() |
|
| 1401 | + { |
|
| 1402 | + $form_handler = $this->loader->getShared( |
|
| 1403 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
| 1404 | + ); |
|
| 1405 | + $form_handler->enqueueStylesAndScripts(); |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + |
|
| 1409 | + /** |
|
| 1410 | + * display the privacy settings form |
|
| 1411 | + * |
|
| 1412 | + * @throws EE_Error |
|
| 1413 | + */ |
|
| 1414 | + public function privacySettings() |
|
| 1415 | + { |
|
| 1416 | + $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
| 1417 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1418 | + $form_handler = $this->loader->getShared( |
|
| 1419 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
| 1420 | + ); |
|
| 1421 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
| 1422 | + $form_handler->display(), |
|
| 1423 | + '', |
|
| 1424 | + 'padding' |
|
| 1425 | + ); |
|
| 1426 | + $this->display_admin_page_with_sidebar(); |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + |
|
| 1430 | + /** |
|
| 1431 | + * Update the privacy settings from form data |
|
| 1432 | + * |
|
| 1433 | + * @throws EE_Error |
|
| 1434 | + */ |
|
| 1435 | + public function updatePrivacySettings() |
|
| 1436 | + { |
|
| 1437 | + $form_handler = $this->loader->getShared( |
|
| 1438 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' |
|
| 1439 | + ); |
|
| 1440 | + $success = $form_handler->process($this->get_request_data()); |
|
| 1441 | + $this->_redirect_after_action( |
|
| 1442 | + $success, |
|
| 1443 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
| 1444 | + 'updated', |
|
| 1445 | + ['action' => 'privacy_settings'] |
|
| 1446 | + ); |
|
| 1447 | + } |
|
| 1448 | 1448 | } |
@@ -17,812 +17,812 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return EED_Add_New_State|EED_Module |
|
| 22 | - * @throws EE_Error |
|
| 23 | - * @throws ReflectionException |
|
| 24 | - */ |
|
| 25 | - public static function instance() |
|
| 26 | - { |
|
| 27 | - return parent::get_instance(__CLASS__); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 33 | - * |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public static function set_hooks() |
|
| 37 | - { |
|
| 38 | - add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2); |
|
| 39 | - add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'translate_js_strings'], 0); |
|
| 40 | - add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'wp_enqueue_scripts'], 10); |
|
| 41 | - add_filter( |
|
| 42 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 43 | - ['EED_Add_New_State', 'display_add_new_state_micro_form'], |
|
| 44 | - 1, |
|
| 45 | - 1 |
|
| 46 | - ); |
|
| 47 | - add_filter( |
|
| 48 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 49 | - ['EED_Add_New_State', 'display_add_new_state_micro_form'], |
|
| 50 | - 1, |
|
| 51 | - 1 |
|
| 52 | - ); |
|
| 53 | - add_filter( |
|
| 54 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 55 | - ['EED_Add_New_State', 'unset_new_state_request_params'], |
|
| 56 | - 10, |
|
| 57 | - 1 |
|
| 58 | - ); |
|
| 59 | - add_filter( |
|
| 60 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 61 | - ['EED_Add_New_State', 'inject_new_reg_state_into_options'], |
|
| 62 | - 10, |
|
| 63 | - 5 |
|
| 64 | - ); |
|
| 65 | - add_filter( |
|
| 66 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 67 | - ['EED_Add_New_State', 'inject_new_reg_country_into_options'], |
|
| 68 | - 10, |
|
| 69 | - 5 |
|
| 70 | - ); |
|
| 71 | - add_filter( |
|
| 72 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 73 | - ['EED_Add_New_State', 'state_options'], |
|
| 74 | - 10, |
|
| 75 | - 1 |
|
| 76 | - ); |
|
| 77 | - add_filter( |
|
| 78 | - 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 79 | - ['EED_Add_New_State', 'country_options'], |
|
| 80 | - 10, |
|
| 81 | - 1 |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 88 | - * |
|
| 89 | - * @return void |
|
| 90 | - */ |
|
| 91 | - public static function set_hooks_admin() |
|
| 92 | - { |
|
| 93 | - add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2); |
|
| 94 | - add_filter( |
|
| 95 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 96 | - ['EED_Add_New_State', 'display_add_new_state_micro_form'], |
|
| 97 | - 1, |
|
| 98 | - 1 |
|
| 99 | - ); |
|
| 100 | - add_filter( |
|
| 101 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 102 | - ['EED_Add_New_State', 'display_add_new_state_micro_form'], |
|
| 103 | - 1, |
|
| 104 | - 1 |
|
| 105 | - ); |
|
| 106 | - add_action('wp_ajax_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']); |
|
| 107 | - add_action('wp_ajax_nopriv_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']); |
|
| 108 | - add_filter( |
|
| 109 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 110 | - ['EED_Add_New_State', 'unset_new_state_request_params'], |
|
| 111 | - 10, |
|
| 112 | - 1 |
|
| 113 | - ); |
|
| 114 | - add_action( |
|
| 115 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 116 | - ['EED_Add_New_State', 'update_country_settings'], |
|
| 117 | - 10, |
|
| 118 | - 3 |
|
| 119 | - ); |
|
| 120 | - add_action( |
|
| 121 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 122 | - ['EED_Add_New_State', 'update_country_settings'], |
|
| 123 | - 10, |
|
| 124 | - 3 |
|
| 125 | - ); |
|
| 126 | - add_filter( |
|
| 127 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 128 | - ['EED_Add_New_State', 'state_options'], |
|
| 129 | - 10, |
|
| 130 | - 1 |
|
| 131 | - ); |
|
| 132 | - add_filter( |
|
| 133 | - 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 134 | - ['EED_Add_New_State', 'country_options'], |
|
| 135 | - 10, |
|
| 136 | - 1 |
|
| 137 | - ); |
|
| 138 | - add_filter( |
|
| 139 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 140 | - ['EED_Add_New_State', 'filter_checkout_request_params'], |
|
| 141 | - 10, |
|
| 142 | - 1 |
|
| 143 | - ); |
|
| 144 | - add_filter( |
|
| 145 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 146 | - ['EED_Add_New_State', 'inject_new_reg_state_into_options'], |
|
| 147 | - 10, |
|
| 148 | - 5 |
|
| 149 | - ); |
|
| 150 | - add_filter( |
|
| 151 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 152 | - ['EED_Add_New_State', 'inject_new_reg_country_into_options'], |
|
| 153 | - 10, |
|
| 154 | - 5 |
|
| 155 | - ); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return void |
|
| 161 | - */ |
|
| 162 | - public static function set_definitions() |
|
| 163 | - { |
|
| 164 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 165 | - define( |
|
| 166 | - 'ANS_TEMPLATES_PATH', |
|
| 167 | - str_replace( |
|
| 168 | - '\\', |
|
| 169 | - '/', |
|
| 170 | - plugin_dir_path(__FILE__) |
|
| 171 | - ) . 'templates/' |
|
| 172 | - ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param WP $WP |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public function run($WP) |
|
| 181 | - { |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return void |
|
| 187 | - */ |
|
| 188 | - public static function translate_js_strings() |
|
| 189 | - { |
|
| 190 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 191 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 192 | - 'event_espresso' |
|
| 193 | - ); |
|
| 194 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 195 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 196 | - 'event_espresso' |
|
| 197 | - ); |
|
| 198 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 199 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 200 | - 'event_espresso' |
|
| 201 | - ); |
|
| 202 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 203 | - 'The new state was successfully saved to the database.', |
|
| 204 | - 'event_espresso' |
|
| 205 | - ); |
|
| 206 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 207 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 208 | - 'event_espresso' |
|
| 209 | - ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - public static function wp_enqueue_scripts() |
|
| 217 | - { |
|
| 218 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 219 | - wp_register_script( |
|
| 220 | - 'add_new_state', |
|
| 221 | - ANS_ASSETS_URL . 'add_new_state.js', |
|
| 222 | - ['espresso_core', 'single_page_checkout'], |
|
| 223 | - EVENT_ESPRESSO_VERSION, |
|
| 224 | - true |
|
| 225 | - ); |
|
| 226 | - wp_enqueue_script('add_new_state'); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * display_add_new_state_micro_form |
|
| 233 | - * |
|
| 234 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 235 | - * @return EE_Form_Section_Proper |
|
| 236 | - * @throws EE_Error |
|
| 237 | - * @throws ReflectionException |
|
| 238 | - */ |
|
| 239 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 240 | - { |
|
| 241 | - $request = self::getRequest(); |
|
| 242 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 243 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 244 | - $action = $request->getRequestParam('action'); |
|
| 245 | - // is the "state" question in this form section? |
|
| 246 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 247 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 248 | - // ok then all we need to do is make sure the input's HTML name is consistent |
|
| 249 | - // by forcing it to set it now, like it did while getting the form for display |
|
| 250 | - if ($input instanceof EE_State_Select_Input) { |
|
| 251 | - $input->html_name(); |
|
| 252 | - } |
|
| 253 | - return $question_group_reg_form; |
|
| 254 | - } |
|
| 255 | - // we're only doing this for state select inputs |
|
| 256 | - if ( |
|
| 257 | - $input instanceof EE_State_Select_Input |
|
| 258 | - && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
| 259 | - ) { |
|
| 260 | - // grab any set values from the request |
|
| 261 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 262 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 263 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 264 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 265 | - $country_options = []; |
|
| 266 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 267 | - if (! empty($countries)) { |
|
| 268 | - foreach ($countries as $country) { |
|
| 269 | - if ($country instanceof EE_Country) { |
|
| 270 | - $country_options[ $country->ID() ] = $country->name(); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 275 | - [ |
|
| 276 | - 'name' => 'new_state_micro_form', |
|
| 277 | - 'html_id' => 'new_state_micro_form', |
|
| 278 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 279 | - 'subsections' => [ |
|
| 280 | - // add hidden input to indicate that a new state is being added |
|
| 281 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 282 | - [ |
|
| 283 | - 'html_name' => str_replace( |
|
| 284 | - 'state', |
|
| 285 | - 'nsmf_add_new_state', |
|
| 286 | - $input->html_name() |
|
| 287 | - ), |
|
| 288 | - 'html_id' => str_replace( |
|
| 289 | - 'state', |
|
| 290 | - 'nsmf_add_new_state', |
|
| 291 | - $input->html_id() |
|
| 292 | - ), |
|
| 293 | - 'default' => 0, |
|
| 294 | - ] |
|
| 295 | - ), |
|
| 296 | - // add link for displaying hidden container |
|
| 297 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 298 | - apply_filters( |
|
| 299 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 300 | - EEH_HTML::link( |
|
| 301 | - '', |
|
| 302 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 303 | - '', |
|
| 304 | - 'display-' . $input->html_id(), |
|
| 305 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 306 | - '', |
|
| 307 | - 'data-target="' . $input->html_id() . '"' |
|
| 308 | - ) |
|
| 309 | - ) |
|
| 310 | - ), |
|
| 311 | - // add initial html for hidden container |
|
| 312 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 313 | - apply_filters( |
|
| 314 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 315 | - EEH_HTML::div( |
|
| 316 | - '', |
|
| 317 | - $input->html_id() . '-dv', |
|
| 318 | - 'ee-form-add-new-state-dv', |
|
| 319 | - 'display: none;' |
|
| 320 | - ) . |
|
| 321 | - EEH_HTML::h6( |
|
| 322 | - esc_html__( |
|
| 323 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 324 | - 'event_espresso' |
|
| 325 | - ) |
|
| 326 | - ) . |
|
| 327 | - EEH_HTML::ul() . |
|
| 328 | - EEH_HTML::li( |
|
| 329 | - esc_html__( |
|
| 330 | - 'first select the Country that your State/Province belongs to', |
|
| 331 | - 'event_espresso' |
|
| 332 | - ) |
|
| 333 | - ) . |
|
| 334 | - EEH_HTML::li( |
|
| 335 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 336 | - ) . |
|
| 337 | - EEH_HTML::li( |
|
| 338 | - esc_html__( |
|
| 339 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 340 | - 'event_espresso' |
|
| 341 | - ) |
|
| 342 | - ) . |
|
| 343 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 344 | - EEH_HTML::ulx() |
|
| 345 | - ) |
|
| 346 | - ), |
|
| 347 | - // NEW STATE COUNTRY |
|
| 348 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 349 | - $country_options, |
|
| 350 | - [ |
|
| 351 | - 'html_name' => $country_name, |
|
| 352 | - 'html_id' => str_replace( |
|
| 353 | - 'state', |
|
| 354 | - 'nsmf_new_state_country', |
|
| 355 | - $input->html_id() |
|
| 356 | - ), |
|
| 357 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 358 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 359 | - 'default' => $request->getRequestParam($country_name), |
|
| 360 | - 'required' => false, |
|
| 361 | - ] |
|
| 362 | - ), |
|
| 363 | - // NEW STATE NAME |
|
| 364 | - 'new_state_name' => new EE_Text_Input( |
|
| 365 | - [ |
|
| 366 | - 'html_name' => $state_name, |
|
| 367 | - 'html_id' => str_replace( |
|
| 368 | - 'state', |
|
| 369 | - 'nsmf_new_state_name', |
|
| 370 | - $input->html_id() |
|
| 371 | - ), |
|
| 372 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 373 | - 'html_label_text' => esc_html__( |
|
| 374 | - 'New State/Province Name', |
|
| 375 | - 'event_espresso' |
|
| 376 | - ), |
|
| 377 | - 'default' => $request->getRequestParam($state_name), |
|
| 378 | - 'required' => false, |
|
| 379 | - ] |
|
| 380 | - ), |
|
| 381 | - // NEW STATE NAME |
|
| 382 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 383 | - [ |
|
| 384 | - 'html_name' => $abbrv_name, |
|
| 385 | - 'html_id' => str_replace( |
|
| 386 | - 'state', |
|
| 387 | - 'nsmf_new_state_abbrv', |
|
| 388 | - $input->html_id() |
|
| 389 | - ), |
|
| 390 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 391 | - 'html_label_text' => esc_html__( |
|
| 392 | - 'New State/Province Abbreviation', |
|
| 393 | - 'event_espresso' |
|
| 394 | - ) . ' *', |
|
| 395 | - 'other_html_attributes' => 'size="24"', |
|
| 396 | - 'default' => $request->getRequestParam($abbrv_name), |
|
| 397 | - 'required' => false, |
|
| 398 | - ] |
|
| 399 | - ), |
|
| 400 | - // "submit" button |
|
| 401 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 402 | - apply_filters( |
|
| 403 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 404 | - EEH_HTML::div( |
|
| 405 | - EEH_HTML::button( |
|
| 406 | - esc_html__('ADD', 'event_espresso'), |
|
| 407 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 408 | - '', |
|
| 409 | - 'submit-' . $new_state_submit_id, |
|
| 410 | - '', |
|
| 411 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 412 | - . ' data-value-field-name="' . $input->valueFieldName() . '"' |
|
| 413 | - ), |
|
| 414 | - '', |
|
| 415 | - 'ee-form-add-new-state-submit-dv' |
|
| 416 | - ) |
|
| 417 | - ) |
|
| 418 | - ), |
|
| 419 | - // extra info |
|
| 420 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 421 | - apply_filters( |
|
| 422 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 423 | - EEH_HTML::br() |
|
| 424 | - . |
|
| 425 | - EEH_HTML::div('', '', 'small-text') |
|
| 426 | - . |
|
| 427 | - EEH_HTML::strong( |
|
| 428 | - '* ' . |
|
| 429 | - esc_html__( |
|
| 430 | - 'Don\'t know your State/Province Abbreviation?', |
|
| 431 | - 'event_espresso' |
|
| 432 | - ) |
|
| 433 | - ) |
|
| 434 | - . |
|
| 435 | - EEH_HTML::br() |
|
| 436 | - . |
|
| 437 | - sprintf( |
|
| 438 | - esc_html__( |
|
| 439 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 440 | - 'event_espresso' |
|
| 441 | - ), |
|
| 442 | - EEH_HTML::link( |
|
| 443 | - 'https://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 444 | - 'https://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 445 | - '', |
|
| 446 | - '', |
|
| 447 | - 'ee-form-add-new-state-wiki-lnk', |
|
| 448 | - '', |
|
| 449 | - 'target="_blank"' |
|
| 450 | - ) |
|
| 451 | - ) |
|
| 452 | - . |
|
| 453 | - EEH_HTML::divx() |
|
| 454 | - . |
|
| 455 | - EEH_HTML::br() |
|
| 456 | - . |
|
| 457 | - EEH_HTML::link( |
|
| 458 | - '', |
|
| 459 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 460 | - '', |
|
| 461 | - 'hide-' . $input->html_id(), |
|
| 462 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 463 | - '', |
|
| 464 | - 'data-target="' . $input->html_id() . '"' |
|
| 465 | - ) |
|
| 466 | - . |
|
| 467 | - EEH_HTML::divx() |
|
| 468 | - . |
|
| 469 | - EEH_HTML::br() |
|
| 470 | - ) |
|
| 471 | - ), |
|
| 472 | - ], |
|
| 473 | - ] |
|
| 474 | - ); |
|
| 475 | - $question_group_reg_form->add_subsections( |
|
| 476 | - ['new_state_micro_form' => $new_state_micro_form], |
|
| 477 | - 'state', |
|
| 478 | - false |
|
| 479 | - ); |
|
| 480 | - } |
|
| 481 | - return $question_group_reg_form; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * set_new_state_input_width |
|
| 487 | - * |
|
| 488 | - * @return int|string |
|
| 489 | - * @throws EE_Error |
|
| 490 | - * @throws InvalidArgumentException |
|
| 491 | - * @throws InvalidDataTypeException |
|
| 492 | - * @throws InvalidInterfaceException |
|
| 493 | - * @throws ReflectionException |
|
| 494 | - */ |
|
| 495 | - public static function add_new_state() |
|
| 496 | - { |
|
| 497 | - $request = self::getRequest(); |
|
| 498 | - if ($request->getRequestParam('nsmf_add_new_state', 0, 'int') === 1) { |
|
| 499 | - EE_Registry::instance()->load_model('State'); |
|
| 500 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 501 | - $state_country = $request->getRequestParam('nsmf_new_state_country'); |
|
| 502 | - $state_name = $request->getRequestParam('nsmf_new_state_name'); |
|
| 503 | - $state_abbr = $request->getRequestParam('nsmf_new_state_abbrv'); |
|
| 504 | - if ($state_country && $state_name && $state_abbr) { |
|
| 505 | - $new_state = EED_Add_New_State::save_new_state_to_db( |
|
| 506 | - [ |
|
| 507 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 508 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 509 | - 'STA_name' => ucwords($state_name), |
|
| 510 | - 'STA_active' => false, |
|
| 511 | - ] |
|
| 512 | - ); |
|
| 513 | - if ($new_state instanceof EE_State) { |
|
| 514 | - // clean house |
|
| 515 | - $request->unSetRequestParams( |
|
| 516 | - [ |
|
| 517 | - 'nsmf_add_new_state', |
|
| 518 | - 'nsmf_new_state_country', |
|
| 519 | - 'nsmf_new_state_name', |
|
| 520 | - 'nsmf_new_state_abbrv', |
|
| 521 | - ] |
|
| 522 | - ); |
|
| 523 | - // get any existing new states |
|
| 524 | - $new_states = EE_Registry::instance()->SSN->get_session_data('nsmf_new_states'); |
|
| 525 | - $new_states[ $new_state->ID() ] = $new_state; |
|
| 526 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 527 | - ['nsmf_new_states' => $new_states] |
|
| 528 | - ); |
|
| 529 | - if ($request->isAjax()) { |
|
| 530 | - echo wp_json_encode( |
|
| 531 | - [ |
|
| 532 | - 'success' => true, |
|
| 533 | - 'id' => $new_state->ID(), |
|
| 534 | - 'name' => $new_state->name(), |
|
| 535 | - 'abbrev' => $new_state->abbrev(), |
|
| 536 | - 'country_iso' => $new_state->country_iso(), |
|
| 537 | - 'country_name' => $new_state->country()->name(), |
|
| 538 | - ] |
|
| 539 | - ); |
|
| 540 | - exit(); |
|
| 541 | - } |
|
| 542 | - return $new_state->ID(); |
|
| 543 | - } |
|
| 544 | - } else { |
|
| 545 | - $error = esc_html__( |
|
| 546 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 547 | - 'event_espresso' |
|
| 548 | - ); |
|
| 549 | - if ($request->isAjax()) { |
|
| 550 | - echo wp_json_encode(['error' => $error]); |
|
| 551 | - exit(); |
|
| 552 | - } |
|
| 553 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - return false; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * recursively drills down through request params to remove any that were added by this module |
|
| 562 | - * |
|
| 563 | - * @param array $request_params |
|
| 564 | - * @return array |
|
| 565 | - */ |
|
| 566 | - public static function filter_checkout_request_params($request_params) |
|
| 567 | - { |
|
| 568 | - foreach ($request_params as $form_section) { |
|
| 569 | - if (is_array($form_section)) { |
|
| 570 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 571 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - return $request_params; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * @param array $request_params |
|
| 580 | - * @return array |
|
| 581 | - */ |
|
| 582 | - public static function unset_new_state_request_params($request_params) |
|
| 583 | - { |
|
| 584 | - unset( |
|
| 585 | - $request_params['new_state_micro_form'], |
|
| 586 | - $request_params['new_state_micro_add_new_state'], |
|
| 587 | - $request_params['new_state_micro_new_state_country'], |
|
| 588 | - $request_params['new_state_micro_new_state_name'], |
|
| 589 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 590 | - ); |
|
| 591 | - return $request_params; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * @param array $props_n_values |
|
| 597 | - * @return EE_State|null |
|
| 598 | - * @throws EE_Error |
|
| 599 | - * @throws ReflectionException |
|
| 600 | - */ |
|
| 601 | - public static function save_new_state_to_db($props_n_values = []) |
|
| 602 | - { |
|
| 603 | - /** @var EE_State[] $existing_state */ |
|
| 604 | - $existing_state = EEM_State::instance()->get_all([$props_n_values, 'limit' => 1]); |
|
| 605 | - if (! empty($existing_state)) { |
|
| 606 | - return array_pop($existing_state); |
|
| 607 | - } |
|
| 608 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 609 | - if ($new_state instanceof EE_State) { |
|
| 610 | - $country_settings_url = add_query_arg( |
|
| 611 | - [ |
|
| 612 | - 'page' => 'espresso_general_settings', |
|
| 613 | - 'action' => 'country_settings', |
|
| 614 | - 'country' => $new_state->country_iso(), |
|
| 615 | - ], |
|
| 616 | - admin_url('admin.php') |
|
| 617 | - ); |
|
| 618 | - // if not non-ajax admin |
|
| 619 | - new PersistentAdminNotice( |
|
| 620 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 621 | - sprintf( |
|
| 622 | - esc_html__( |
|
| 623 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 624 | - 'event_espresso' |
|
| 625 | - ), |
|
| 626 | - '<b>' . $new_state->name() . '</b>', |
|
| 627 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 628 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 629 | - '<a href="' |
|
| 630 | - . $country_settings_url |
|
| 631 | - . '">' |
|
| 632 | - . esc_html__( |
|
| 633 | - 'Event Espresso - General Settings > Countries Tab', |
|
| 634 | - 'event_espresso' |
|
| 635 | - ) |
|
| 636 | - . '</a>', |
|
| 637 | - '<br />' |
|
| 638 | - ) |
|
| 639 | - ); |
|
| 640 | - $new_state->save(); |
|
| 641 | - EEM_State::instance()->reset_cached_states(); |
|
| 642 | - return $new_state; |
|
| 643 | - } |
|
| 644 | - return null; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * @param string $CNT_ISO |
|
| 650 | - * @param string $STA_ID |
|
| 651 | - * @param array $cols_n_values |
|
| 652 | - * @return void |
|
| 653 | - * @throws DomainException |
|
| 654 | - * @throws EE_Error |
|
| 655 | - * @throws InvalidArgumentException |
|
| 656 | - * @throws InvalidDataTypeException |
|
| 657 | - * @throws InvalidInterfaceException |
|
| 658 | - */ |
|
| 659 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = []) |
|
| 660 | - { |
|
| 661 | - if (! $CNT_ISO) { |
|
| 662 | - EE_Error::add_error( |
|
| 663 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 664 | - __FILE__, |
|
| 665 | - __FUNCTION__, |
|
| 666 | - __LINE__ |
|
| 667 | - ); |
|
| 668 | - } |
|
| 669 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 670 | - : false; |
|
| 671 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 672 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 673 | - if ($state instanceof EE_State) { |
|
| 674 | - $STA_abbrev = $state->abbrev(); |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - if (! $STA_abbrev) { |
|
| 678 | - EE_Error::add_error( |
|
| 679 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 680 | - __FILE__, |
|
| 681 | - __FUNCTION__, |
|
| 682 | - __LINE__ |
|
| 683 | - ); |
|
| 684 | - } |
|
| 685 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 686 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 687 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 688 | - ); |
|
| 689 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * @param EE_State[] $state_options |
|
| 695 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 696 | - * @param EE_Registration $registration |
|
| 697 | - * @param EE_Question $question |
|
| 698 | - * @param $answer |
|
| 699 | - * @return array |
|
| 700 | - * @throws EE_Error |
|
| 701 | - * @throws ReflectionException |
|
| 702 | - */ |
|
| 703 | - public static function inject_new_reg_state_into_options( |
|
| 704 | - array $state_options, |
|
| 705 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 706 | - EE_Registration $registration, |
|
| 707 | - EE_Question $question, |
|
| 708 | - $answer |
|
| 709 | - ) { |
|
| 710 | - if ( |
|
| 711 | - $answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 712 | - && $question->type() === EEM_Question::QST_type_state |
|
| 713 | - ) { |
|
| 714 | - $STA_ID = $answer->value(); |
|
| 715 | - if (! empty($STA_ID)) { |
|
| 716 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 717 | - if ($state instanceof EE_State) { |
|
| 718 | - $country = $state->country(); |
|
| 719 | - if ($country instanceof EE_Country) { |
|
| 720 | - if (! isset($state_options[ $country->name() ])) { |
|
| 721 | - $state_options[ $country->name() ] = []; |
|
| 722 | - } |
|
| 723 | - if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
| 724 | - $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - return $state_options; |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * @param EE_Country[] $country_options |
|
| 736 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 737 | - * @param EE_Registration $registration |
|
| 738 | - * @param EE_Question $question |
|
| 739 | - * @param $answer |
|
| 740 | - * @return array |
|
| 741 | - * @throws EE_Error |
|
| 742 | - * @throws ReflectionException |
|
| 743 | - */ |
|
| 744 | - public static function inject_new_reg_country_into_options( |
|
| 745 | - array $country_options, |
|
| 746 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 747 | - EE_Registration $registration, |
|
| 748 | - EE_Question $question, |
|
| 749 | - $answer |
|
| 750 | - ) { |
|
| 751 | - if ( |
|
| 752 | - $answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 753 | - && $question->type() |
|
| 754 | - === EEM_Question::QST_type_country |
|
| 755 | - ) { |
|
| 756 | - $CNT_ISO = $answer->value(); |
|
| 757 | - if (! empty($CNT_ISO)) { |
|
| 758 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 759 | - if ($country instanceof EE_Country) { |
|
| 760 | - if (! isset($country_options[ $CNT_ISO ])) { |
|
| 761 | - $country_options[ $CNT_ISO ] = $country->name(); |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - } |
|
| 766 | - return $country_options; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * @param EE_State[] $state_options |
|
| 772 | - * @return array |
|
| 773 | - * @throws EE_Error |
|
| 774 | - * @throws ReflectionException |
|
| 775 | - */ |
|
| 776 | - public static function state_options($state_options = []) |
|
| 777 | - { |
|
| 778 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 779 | - foreach ($new_states as $new_state) { |
|
| 780 | - if ( |
|
| 781 | - $new_state instanceof EE_State |
|
| 782 | - && $new_state->country() instanceof EE_Country |
|
| 783 | - ) { |
|
| 784 | - $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - return $state_options; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * @return array |
|
| 793 | - * @throws InvalidArgumentException |
|
| 794 | - * @throws InvalidDataTypeException |
|
| 795 | - * @throws InvalidInterfaceException |
|
| 796 | - */ |
|
| 797 | - protected static function _get_new_states() |
|
| 798 | - { |
|
| 799 | - $new_states = []; |
|
| 800 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 801 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 802 | - 'nsmf_new_states' |
|
| 803 | - ); |
|
| 804 | - } |
|
| 805 | - return is_array($new_states) ? $new_states : []; |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * @param EE_Country[] $country_options |
|
| 811 | - * @return array |
|
| 812 | - * @throws EE_Error |
|
| 813 | - * @throws ReflectionException |
|
| 814 | - */ |
|
| 815 | - public static function country_options($country_options = []) |
|
| 816 | - { |
|
| 817 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 818 | - foreach ($new_states as $new_state) { |
|
| 819 | - if ( |
|
| 820 | - $new_state instanceof EE_State |
|
| 821 | - && $new_state->country() instanceof EE_Country |
|
| 822 | - ) { |
|
| 823 | - $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - return $country_options; |
|
| 827 | - } |
|
| 20 | + /** |
|
| 21 | + * @return EED_Add_New_State|EED_Module |
|
| 22 | + * @throws EE_Error |
|
| 23 | + * @throws ReflectionException |
|
| 24 | + */ |
|
| 25 | + public static function instance() |
|
| 26 | + { |
|
| 27 | + return parent::get_instance(__CLASS__); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 33 | + * |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public static function set_hooks() |
|
| 37 | + { |
|
| 38 | + add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2); |
|
| 39 | + add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'translate_js_strings'], 0); |
|
| 40 | + add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'wp_enqueue_scripts'], 10); |
|
| 41 | + add_filter( |
|
| 42 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 43 | + ['EED_Add_New_State', 'display_add_new_state_micro_form'], |
|
| 44 | + 1, |
|
| 45 | + 1 |
|
| 46 | + ); |
|
| 47 | + add_filter( |
|
| 48 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 49 | + ['EED_Add_New_State', 'display_add_new_state_micro_form'], |
|
| 50 | + 1, |
|
| 51 | + 1 |
|
| 52 | + ); |
|
| 53 | + add_filter( |
|
| 54 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 55 | + ['EED_Add_New_State', 'unset_new_state_request_params'], |
|
| 56 | + 10, |
|
| 57 | + 1 |
|
| 58 | + ); |
|
| 59 | + add_filter( |
|
| 60 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 61 | + ['EED_Add_New_State', 'inject_new_reg_state_into_options'], |
|
| 62 | + 10, |
|
| 63 | + 5 |
|
| 64 | + ); |
|
| 65 | + add_filter( |
|
| 66 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 67 | + ['EED_Add_New_State', 'inject_new_reg_country_into_options'], |
|
| 68 | + 10, |
|
| 69 | + 5 |
|
| 70 | + ); |
|
| 71 | + add_filter( |
|
| 72 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 73 | + ['EED_Add_New_State', 'state_options'], |
|
| 74 | + 10, |
|
| 75 | + 1 |
|
| 76 | + ); |
|
| 77 | + add_filter( |
|
| 78 | + 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 79 | + ['EED_Add_New_State', 'country_options'], |
|
| 80 | + 10, |
|
| 81 | + 1 |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 88 | + * |
|
| 89 | + * @return void |
|
| 90 | + */ |
|
| 91 | + public static function set_hooks_admin() |
|
| 92 | + { |
|
| 93 | + add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2); |
|
| 94 | + add_filter( |
|
| 95 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 96 | + ['EED_Add_New_State', 'display_add_new_state_micro_form'], |
|
| 97 | + 1, |
|
| 98 | + 1 |
|
| 99 | + ); |
|
| 100 | + add_filter( |
|
| 101 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 102 | + ['EED_Add_New_State', 'display_add_new_state_micro_form'], |
|
| 103 | + 1, |
|
| 104 | + 1 |
|
| 105 | + ); |
|
| 106 | + add_action('wp_ajax_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']); |
|
| 107 | + add_action('wp_ajax_nopriv_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']); |
|
| 108 | + add_filter( |
|
| 109 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 110 | + ['EED_Add_New_State', 'unset_new_state_request_params'], |
|
| 111 | + 10, |
|
| 112 | + 1 |
|
| 113 | + ); |
|
| 114 | + add_action( |
|
| 115 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 116 | + ['EED_Add_New_State', 'update_country_settings'], |
|
| 117 | + 10, |
|
| 118 | + 3 |
|
| 119 | + ); |
|
| 120 | + add_action( |
|
| 121 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 122 | + ['EED_Add_New_State', 'update_country_settings'], |
|
| 123 | + 10, |
|
| 124 | + 3 |
|
| 125 | + ); |
|
| 126 | + add_filter( |
|
| 127 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 128 | + ['EED_Add_New_State', 'state_options'], |
|
| 129 | + 10, |
|
| 130 | + 1 |
|
| 131 | + ); |
|
| 132 | + add_filter( |
|
| 133 | + 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 134 | + ['EED_Add_New_State', 'country_options'], |
|
| 135 | + 10, |
|
| 136 | + 1 |
|
| 137 | + ); |
|
| 138 | + add_filter( |
|
| 139 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 140 | + ['EED_Add_New_State', 'filter_checkout_request_params'], |
|
| 141 | + 10, |
|
| 142 | + 1 |
|
| 143 | + ); |
|
| 144 | + add_filter( |
|
| 145 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 146 | + ['EED_Add_New_State', 'inject_new_reg_state_into_options'], |
|
| 147 | + 10, |
|
| 148 | + 5 |
|
| 149 | + ); |
|
| 150 | + add_filter( |
|
| 151 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 152 | + ['EED_Add_New_State', 'inject_new_reg_country_into_options'], |
|
| 153 | + 10, |
|
| 154 | + 5 |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return void |
|
| 161 | + */ |
|
| 162 | + public static function set_definitions() |
|
| 163 | + { |
|
| 164 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 165 | + define( |
|
| 166 | + 'ANS_TEMPLATES_PATH', |
|
| 167 | + str_replace( |
|
| 168 | + '\\', |
|
| 169 | + '/', |
|
| 170 | + plugin_dir_path(__FILE__) |
|
| 171 | + ) . 'templates/' |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param WP $WP |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public function run($WP) |
|
| 181 | + { |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @return void |
|
| 187 | + */ |
|
| 188 | + public static function translate_js_strings() |
|
| 189 | + { |
|
| 190 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 191 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 192 | + 'event_espresso' |
|
| 193 | + ); |
|
| 194 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 195 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 196 | + 'event_espresso' |
|
| 197 | + ); |
|
| 198 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 199 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 200 | + 'event_espresso' |
|
| 201 | + ); |
|
| 202 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 203 | + 'The new state was successfully saved to the database.', |
|
| 204 | + 'event_espresso' |
|
| 205 | + ); |
|
| 206 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 207 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 208 | + 'event_espresso' |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + public static function wp_enqueue_scripts() |
|
| 217 | + { |
|
| 218 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 219 | + wp_register_script( |
|
| 220 | + 'add_new_state', |
|
| 221 | + ANS_ASSETS_URL . 'add_new_state.js', |
|
| 222 | + ['espresso_core', 'single_page_checkout'], |
|
| 223 | + EVENT_ESPRESSO_VERSION, |
|
| 224 | + true |
|
| 225 | + ); |
|
| 226 | + wp_enqueue_script('add_new_state'); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * display_add_new_state_micro_form |
|
| 233 | + * |
|
| 234 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 235 | + * @return EE_Form_Section_Proper |
|
| 236 | + * @throws EE_Error |
|
| 237 | + * @throws ReflectionException |
|
| 238 | + */ |
|
| 239 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 240 | + { |
|
| 241 | + $request = self::getRequest(); |
|
| 242 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 243 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 244 | + $action = $request->getRequestParam('action'); |
|
| 245 | + // is the "state" question in this form section? |
|
| 246 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 247 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 248 | + // ok then all we need to do is make sure the input's HTML name is consistent |
|
| 249 | + // by forcing it to set it now, like it did while getting the form for display |
|
| 250 | + if ($input instanceof EE_State_Select_Input) { |
|
| 251 | + $input->html_name(); |
|
| 252 | + } |
|
| 253 | + return $question_group_reg_form; |
|
| 254 | + } |
|
| 255 | + // we're only doing this for state select inputs |
|
| 256 | + if ( |
|
| 257 | + $input instanceof EE_State_Select_Input |
|
| 258 | + && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
| 259 | + ) { |
|
| 260 | + // grab any set values from the request |
|
| 261 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 262 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 263 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 264 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 265 | + $country_options = []; |
|
| 266 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 267 | + if (! empty($countries)) { |
|
| 268 | + foreach ($countries as $country) { |
|
| 269 | + if ($country instanceof EE_Country) { |
|
| 270 | + $country_options[ $country->ID() ] = $country->name(); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 275 | + [ |
|
| 276 | + 'name' => 'new_state_micro_form', |
|
| 277 | + 'html_id' => 'new_state_micro_form', |
|
| 278 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 279 | + 'subsections' => [ |
|
| 280 | + // add hidden input to indicate that a new state is being added |
|
| 281 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 282 | + [ |
|
| 283 | + 'html_name' => str_replace( |
|
| 284 | + 'state', |
|
| 285 | + 'nsmf_add_new_state', |
|
| 286 | + $input->html_name() |
|
| 287 | + ), |
|
| 288 | + 'html_id' => str_replace( |
|
| 289 | + 'state', |
|
| 290 | + 'nsmf_add_new_state', |
|
| 291 | + $input->html_id() |
|
| 292 | + ), |
|
| 293 | + 'default' => 0, |
|
| 294 | + ] |
|
| 295 | + ), |
|
| 296 | + // add link for displaying hidden container |
|
| 297 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 298 | + apply_filters( |
|
| 299 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 300 | + EEH_HTML::link( |
|
| 301 | + '', |
|
| 302 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 303 | + '', |
|
| 304 | + 'display-' . $input->html_id(), |
|
| 305 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 306 | + '', |
|
| 307 | + 'data-target="' . $input->html_id() . '"' |
|
| 308 | + ) |
|
| 309 | + ) |
|
| 310 | + ), |
|
| 311 | + // add initial html for hidden container |
|
| 312 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 313 | + apply_filters( |
|
| 314 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 315 | + EEH_HTML::div( |
|
| 316 | + '', |
|
| 317 | + $input->html_id() . '-dv', |
|
| 318 | + 'ee-form-add-new-state-dv', |
|
| 319 | + 'display: none;' |
|
| 320 | + ) . |
|
| 321 | + EEH_HTML::h6( |
|
| 322 | + esc_html__( |
|
| 323 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 324 | + 'event_espresso' |
|
| 325 | + ) |
|
| 326 | + ) . |
|
| 327 | + EEH_HTML::ul() . |
|
| 328 | + EEH_HTML::li( |
|
| 329 | + esc_html__( |
|
| 330 | + 'first select the Country that your State/Province belongs to', |
|
| 331 | + 'event_espresso' |
|
| 332 | + ) |
|
| 333 | + ) . |
|
| 334 | + EEH_HTML::li( |
|
| 335 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 336 | + ) . |
|
| 337 | + EEH_HTML::li( |
|
| 338 | + esc_html__( |
|
| 339 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 340 | + 'event_espresso' |
|
| 341 | + ) |
|
| 342 | + ) . |
|
| 343 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 344 | + EEH_HTML::ulx() |
|
| 345 | + ) |
|
| 346 | + ), |
|
| 347 | + // NEW STATE COUNTRY |
|
| 348 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 349 | + $country_options, |
|
| 350 | + [ |
|
| 351 | + 'html_name' => $country_name, |
|
| 352 | + 'html_id' => str_replace( |
|
| 353 | + 'state', |
|
| 354 | + 'nsmf_new_state_country', |
|
| 355 | + $input->html_id() |
|
| 356 | + ), |
|
| 357 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 358 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 359 | + 'default' => $request->getRequestParam($country_name), |
|
| 360 | + 'required' => false, |
|
| 361 | + ] |
|
| 362 | + ), |
|
| 363 | + // NEW STATE NAME |
|
| 364 | + 'new_state_name' => new EE_Text_Input( |
|
| 365 | + [ |
|
| 366 | + 'html_name' => $state_name, |
|
| 367 | + 'html_id' => str_replace( |
|
| 368 | + 'state', |
|
| 369 | + 'nsmf_new_state_name', |
|
| 370 | + $input->html_id() |
|
| 371 | + ), |
|
| 372 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 373 | + 'html_label_text' => esc_html__( |
|
| 374 | + 'New State/Province Name', |
|
| 375 | + 'event_espresso' |
|
| 376 | + ), |
|
| 377 | + 'default' => $request->getRequestParam($state_name), |
|
| 378 | + 'required' => false, |
|
| 379 | + ] |
|
| 380 | + ), |
|
| 381 | + // NEW STATE NAME |
|
| 382 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 383 | + [ |
|
| 384 | + 'html_name' => $abbrv_name, |
|
| 385 | + 'html_id' => str_replace( |
|
| 386 | + 'state', |
|
| 387 | + 'nsmf_new_state_abbrv', |
|
| 388 | + $input->html_id() |
|
| 389 | + ), |
|
| 390 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 391 | + 'html_label_text' => esc_html__( |
|
| 392 | + 'New State/Province Abbreviation', |
|
| 393 | + 'event_espresso' |
|
| 394 | + ) . ' *', |
|
| 395 | + 'other_html_attributes' => 'size="24"', |
|
| 396 | + 'default' => $request->getRequestParam($abbrv_name), |
|
| 397 | + 'required' => false, |
|
| 398 | + ] |
|
| 399 | + ), |
|
| 400 | + // "submit" button |
|
| 401 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 402 | + apply_filters( |
|
| 403 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 404 | + EEH_HTML::div( |
|
| 405 | + EEH_HTML::button( |
|
| 406 | + esc_html__('ADD', 'event_espresso'), |
|
| 407 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 408 | + '', |
|
| 409 | + 'submit-' . $new_state_submit_id, |
|
| 410 | + '', |
|
| 411 | + 'data-target="' . $new_state_submit_id . '"' |
|
| 412 | + . ' data-value-field-name="' . $input->valueFieldName() . '"' |
|
| 413 | + ), |
|
| 414 | + '', |
|
| 415 | + 'ee-form-add-new-state-submit-dv' |
|
| 416 | + ) |
|
| 417 | + ) |
|
| 418 | + ), |
|
| 419 | + // extra info |
|
| 420 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 421 | + apply_filters( |
|
| 422 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 423 | + EEH_HTML::br() |
|
| 424 | + . |
|
| 425 | + EEH_HTML::div('', '', 'small-text') |
|
| 426 | + . |
|
| 427 | + EEH_HTML::strong( |
|
| 428 | + '* ' . |
|
| 429 | + esc_html__( |
|
| 430 | + 'Don\'t know your State/Province Abbreviation?', |
|
| 431 | + 'event_espresso' |
|
| 432 | + ) |
|
| 433 | + ) |
|
| 434 | + . |
|
| 435 | + EEH_HTML::br() |
|
| 436 | + . |
|
| 437 | + sprintf( |
|
| 438 | + esc_html__( |
|
| 439 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 440 | + 'event_espresso' |
|
| 441 | + ), |
|
| 442 | + EEH_HTML::link( |
|
| 443 | + 'https://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 444 | + 'https://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 445 | + '', |
|
| 446 | + '', |
|
| 447 | + 'ee-form-add-new-state-wiki-lnk', |
|
| 448 | + '', |
|
| 449 | + 'target="_blank"' |
|
| 450 | + ) |
|
| 451 | + ) |
|
| 452 | + . |
|
| 453 | + EEH_HTML::divx() |
|
| 454 | + . |
|
| 455 | + EEH_HTML::br() |
|
| 456 | + . |
|
| 457 | + EEH_HTML::link( |
|
| 458 | + '', |
|
| 459 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 460 | + '', |
|
| 461 | + 'hide-' . $input->html_id(), |
|
| 462 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 463 | + '', |
|
| 464 | + 'data-target="' . $input->html_id() . '"' |
|
| 465 | + ) |
|
| 466 | + . |
|
| 467 | + EEH_HTML::divx() |
|
| 468 | + . |
|
| 469 | + EEH_HTML::br() |
|
| 470 | + ) |
|
| 471 | + ), |
|
| 472 | + ], |
|
| 473 | + ] |
|
| 474 | + ); |
|
| 475 | + $question_group_reg_form->add_subsections( |
|
| 476 | + ['new_state_micro_form' => $new_state_micro_form], |
|
| 477 | + 'state', |
|
| 478 | + false |
|
| 479 | + ); |
|
| 480 | + } |
|
| 481 | + return $question_group_reg_form; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * set_new_state_input_width |
|
| 487 | + * |
|
| 488 | + * @return int|string |
|
| 489 | + * @throws EE_Error |
|
| 490 | + * @throws InvalidArgumentException |
|
| 491 | + * @throws InvalidDataTypeException |
|
| 492 | + * @throws InvalidInterfaceException |
|
| 493 | + * @throws ReflectionException |
|
| 494 | + */ |
|
| 495 | + public static function add_new_state() |
|
| 496 | + { |
|
| 497 | + $request = self::getRequest(); |
|
| 498 | + if ($request->getRequestParam('nsmf_add_new_state', 0, 'int') === 1) { |
|
| 499 | + EE_Registry::instance()->load_model('State'); |
|
| 500 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 501 | + $state_country = $request->getRequestParam('nsmf_new_state_country'); |
|
| 502 | + $state_name = $request->getRequestParam('nsmf_new_state_name'); |
|
| 503 | + $state_abbr = $request->getRequestParam('nsmf_new_state_abbrv'); |
|
| 504 | + if ($state_country && $state_name && $state_abbr) { |
|
| 505 | + $new_state = EED_Add_New_State::save_new_state_to_db( |
|
| 506 | + [ |
|
| 507 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 508 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 509 | + 'STA_name' => ucwords($state_name), |
|
| 510 | + 'STA_active' => false, |
|
| 511 | + ] |
|
| 512 | + ); |
|
| 513 | + if ($new_state instanceof EE_State) { |
|
| 514 | + // clean house |
|
| 515 | + $request->unSetRequestParams( |
|
| 516 | + [ |
|
| 517 | + 'nsmf_add_new_state', |
|
| 518 | + 'nsmf_new_state_country', |
|
| 519 | + 'nsmf_new_state_name', |
|
| 520 | + 'nsmf_new_state_abbrv', |
|
| 521 | + ] |
|
| 522 | + ); |
|
| 523 | + // get any existing new states |
|
| 524 | + $new_states = EE_Registry::instance()->SSN->get_session_data('nsmf_new_states'); |
|
| 525 | + $new_states[ $new_state->ID() ] = $new_state; |
|
| 526 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 527 | + ['nsmf_new_states' => $new_states] |
|
| 528 | + ); |
|
| 529 | + if ($request->isAjax()) { |
|
| 530 | + echo wp_json_encode( |
|
| 531 | + [ |
|
| 532 | + 'success' => true, |
|
| 533 | + 'id' => $new_state->ID(), |
|
| 534 | + 'name' => $new_state->name(), |
|
| 535 | + 'abbrev' => $new_state->abbrev(), |
|
| 536 | + 'country_iso' => $new_state->country_iso(), |
|
| 537 | + 'country_name' => $new_state->country()->name(), |
|
| 538 | + ] |
|
| 539 | + ); |
|
| 540 | + exit(); |
|
| 541 | + } |
|
| 542 | + return $new_state->ID(); |
|
| 543 | + } |
|
| 544 | + } else { |
|
| 545 | + $error = esc_html__( |
|
| 546 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 547 | + 'event_espresso' |
|
| 548 | + ); |
|
| 549 | + if ($request->isAjax()) { |
|
| 550 | + echo wp_json_encode(['error' => $error]); |
|
| 551 | + exit(); |
|
| 552 | + } |
|
| 553 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + return false; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * recursively drills down through request params to remove any that were added by this module |
|
| 562 | + * |
|
| 563 | + * @param array $request_params |
|
| 564 | + * @return array |
|
| 565 | + */ |
|
| 566 | + public static function filter_checkout_request_params($request_params) |
|
| 567 | + { |
|
| 568 | + foreach ($request_params as $form_section) { |
|
| 569 | + if (is_array($form_section)) { |
|
| 570 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 571 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + return $request_params; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * @param array $request_params |
|
| 580 | + * @return array |
|
| 581 | + */ |
|
| 582 | + public static function unset_new_state_request_params($request_params) |
|
| 583 | + { |
|
| 584 | + unset( |
|
| 585 | + $request_params['new_state_micro_form'], |
|
| 586 | + $request_params['new_state_micro_add_new_state'], |
|
| 587 | + $request_params['new_state_micro_new_state_country'], |
|
| 588 | + $request_params['new_state_micro_new_state_name'], |
|
| 589 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 590 | + ); |
|
| 591 | + return $request_params; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * @param array $props_n_values |
|
| 597 | + * @return EE_State|null |
|
| 598 | + * @throws EE_Error |
|
| 599 | + * @throws ReflectionException |
|
| 600 | + */ |
|
| 601 | + public static function save_new_state_to_db($props_n_values = []) |
|
| 602 | + { |
|
| 603 | + /** @var EE_State[] $existing_state */ |
|
| 604 | + $existing_state = EEM_State::instance()->get_all([$props_n_values, 'limit' => 1]); |
|
| 605 | + if (! empty($existing_state)) { |
|
| 606 | + return array_pop($existing_state); |
|
| 607 | + } |
|
| 608 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 609 | + if ($new_state instanceof EE_State) { |
|
| 610 | + $country_settings_url = add_query_arg( |
|
| 611 | + [ |
|
| 612 | + 'page' => 'espresso_general_settings', |
|
| 613 | + 'action' => 'country_settings', |
|
| 614 | + 'country' => $new_state->country_iso(), |
|
| 615 | + ], |
|
| 616 | + admin_url('admin.php') |
|
| 617 | + ); |
|
| 618 | + // if not non-ajax admin |
|
| 619 | + new PersistentAdminNotice( |
|
| 620 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 621 | + sprintf( |
|
| 622 | + esc_html__( |
|
| 623 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 624 | + 'event_espresso' |
|
| 625 | + ), |
|
| 626 | + '<b>' . $new_state->name() . '</b>', |
|
| 627 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 628 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 629 | + '<a href="' |
|
| 630 | + . $country_settings_url |
|
| 631 | + . '">' |
|
| 632 | + . esc_html__( |
|
| 633 | + 'Event Espresso - General Settings > Countries Tab', |
|
| 634 | + 'event_espresso' |
|
| 635 | + ) |
|
| 636 | + . '</a>', |
|
| 637 | + '<br />' |
|
| 638 | + ) |
|
| 639 | + ); |
|
| 640 | + $new_state->save(); |
|
| 641 | + EEM_State::instance()->reset_cached_states(); |
|
| 642 | + return $new_state; |
|
| 643 | + } |
|
| 644 | + return null; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * @param string $CNT_ISO |
|
| 650 | + * @param string $STA_ID |
|
| 651 | + * @param array $cols_n_values |
|
| 652 | + * @return void |
|
| 653 | + * @throws DomainException |
|
| 654 | + * @throws EE_Error |
|
| 655 | + * @throws InvalidArgumentException |
|
| 656 | + * @throws InvalidDataTypeException |
|
| 657 | + * @throws InvalidInterfaceException |
|
| 658 | + */ |
|
| 659 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = []) |
|
| 660 | + { |
|
| 661 | + if (! $CNT_ISO) { |
|
| 662 | + EE_Error::add_error( |
|
| 663 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 664 | + __FILE__, |
|
| 665 | + __FUNCTION__, |
|
| 666 | + __LINE__ |
|
| 667 | + ); |
|
| 668 | + } |
|
| 669 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 670 | + : false; |
|
| 671 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 672 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 673 | + if ($state instanceof EE_State) { |
|
| 674 | + $STA_abbrev = $state->abbrev(); |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + if (! $STA_abbrev) { |
|
| 678 | + EE_Error::add_error( |
|
| 679 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 680 | + __FILE__, |
|
| 681 | + __FUNCTION__, |
|
| 682 | + __LINE__ |
|
| 683 | + ); |
|
| 684 | + } |
|
| 685 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 686 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 687 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 688 | + ); |
|
| 689 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * @param EE_State[] $state_options |
|
| 695 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 696 | + * @param EE_Registration $registration |
|
| 697 | + * @param EE_Question $question |
|
| 698 | + * @param $answer |
|
| 699 | + * @return array |
|
| 700 | + * @throws EE_Error |
|
| 701 | + * @throws ReflectionException |
|
| 702 | + */ |
|
| 703 | + public static function inject_new_reg_state_into_options( |
|
| 704 | + array $state_options, |
|
| 705 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 706 | + EE_Registration $registration, |
|
| 707 | + EE_Question $question, |
|
| 708 | + $answer |
|
| 709 | + ) { |
|
| 710 | + if ( |
|
| 711 | + $answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 712 | + && $question->type() === EEM_Question::QST_type_state |
|
| 713 | + ) { |
|
| 714 | + $STA_ID = $answer->value(); |
|
| 715 | + if (! empty($STA_ID)) { |
|
| 716 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 717 | + if ($state instanceof EE_State) { |
|
| 718 | + $country = $state->country(); |
|
| 719 | + if ($country instanceof EE_Country) { |
|
| 720 | + if (! isset($state_options[ $country->name() ])) { |
|
| 721 | + $state_options[ $country->name() ] = []; |
|
| 722 | + } |
|
| 723 | + if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
| 724 | + $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + return $state_options; |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * @param EE_Country[] $country_options |
|
| 736 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 737 | + * @param EE_Registration $registration |
|
| 738 | + * @param EE_Question $question |
|
| 739 | + * @param $answer |
|
| 740 | + * @return array |
|
| 741 | + * @throws EE_Error |
|
| 742 | + * @throws ReflectionException |
|
| 743 | + */ |
|
| 744 | + public static function inject_new_reg_country_into_options( |
|
| 745 | + array $country_options, |
|
| 746 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 747 | + EE_Registration $registration, |
|
| 748 | + EE_Question $question, |
|
| 749 | + $answer |
|
| 750 | + ) { |
|
| 751 | + if ( |
|
| 752 | + $answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 753 | + && $question->type() |
|
| 754 | + === EEM_Question::QST_type_country |
|
| 755 | + ) { |
|
| 756 | + $CNT_ISO = $answer->value(); |
|
| 757 | + if (! empty($CNT_ISO)) { |
|
| 758 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 759 | + if ($country instanceof EE_Country) { |
|
| 760 | + if (! isset($country_options[ $CNT_ISO ])) { |
|
| 761 | + $country_options[ $CNT_ISO ] = $country->name(); |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + } |
|
| 766 | + return $country_options; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * @param EE_State[] $state_options |
|
| 772 | + * @return array |
|
| 773 | + * @throws EE_Error |
|
| 774 | + * @throws ReflectionException |
|
| 775 | + */ |
|
| 776 | + public static function state_options($state_options = []) |
|
| 777 | + { |
|
| 778 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 779 | + foreach ($new_states as $new_state) { |
|
| 780 | + if ( |
|
| 781 | + $new_state instanceof EE_State |
|
| 782 | + && $new_state->country() instanceof EE_Country |
|
| 783 | + ) { |
|
| 784 | + $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + return $state_options; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * @return array |
|
| 793 | + * @throws InvalidArgumentException |
|
| 794 | + * @throws InvalidDataTypeException |
|
| 795 | + * @throws InvalidInterfaceException |
|
| 796 | + */ |
|
| 797 | + protected static function _get_new_states() |
|
| 798 | + { |
|
| 799 | + $new_states = []; |
|
| 800 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 801 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 802 | + 'nsmf_new_states' |
|
| 803 | + ); |
|
| 804 | + } |
|
| 805 | + return is_array($new_states) ? $new_states : []; |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * @param EE_Country[] $country_options |
|
| 811 | + * @return array |
|
| 812 | + * @throws EE_Error |
|
| 813 | + * @throws ReflectionException |
|
| 814 | + */ |
|
| 815 | + public static function country_options($country_options = []) |
|
| 816 | + { |
|
| 817 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 818 | + foreach ($new_states as $new_state) { |
|
| 819 | + if ( |
|
| 820 | + $new_state instanceof EE_State |
|
| 821 | + && $new_state->country() instanceof EE_Country |
|
| 822 | + ) { |
|
| 823 | + $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + return $country_options; |
|
| 827 | + } |
|
| 828 | 828 | } |
@@ -161,14 +161,14 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public static function set_definitions() |
| 163 | 163 | { |
| 164 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 164 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
| 165 | 165 | define( |
| 166 | 166 | 'ANS_TEMPLATES_PATH', |
| 167 | 167 | str_replace( |
| 168 | 168 | '\\', |
| 169 | 169 | '/', |
| 170 | 170 | plugin_dir_path(__FILE__) |
| 171 | - ) . 'templates/' |
|
| 171 | + ).'templates/' |
|
| 172 | 172 | ); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -187,19 +187,19 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public static function translate_js_strings() |
| 189 | 189 | { |
| 190 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 190 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 191 | 191 | 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
| 192 | 192 | 'event_espresso' |
| 193 | 193 | ); |
| 194 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 194 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 195 | 195 | 'In order to proceed, you need to enter the name of your State/Province.', |
| 196 | 196 | 'event_espresso' |
| 197 | 197 | ); |
| 198 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 198 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 199 | 199 | 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
| 200 | 200 | 'event_espresso' |
| 201 | 201 | ); |
| 202 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 202 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 203 | 203 | 'The new state was successfully saved to the database.', |
| 204 | 204 | 'event_espresso' |
| 205 | 205 | ); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
| 219 | 219 | wp_register_script( |
| 220 | 220 | 'add_new_state', |
| 221 | - ANS_ASSETS_URL . 'add_new_state.js', |
|
| 221 | + ANS_ASSETS_URL.'add_new_state.js', |
|
| 222 | 222 | ['espresso_core', 'single_page_checkout'], |
| 223 | 223 | EVENT_ESPRESSO_VERSION, |
| 224 | 224 | true |
@@ -264,10 +264,10 @@ discard block |
||
| 264 | 264 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
| 265 | 265 | $country_options = []; |
| 266 | 266 | $countries = EEM_Country::instance()->get_all_countries(); |
| 267 | - if (! empty($countries)) { |
|
| 267 | + if ( ! empty($countries)) { |
|
| 268 | 268 | foreach ($countries as $country) { |
| 269 | 269 | if ($country instanceof EE_Country) { |
| 270 | - $country_options[ $country->ID() ] = $country->name(); |
|
| 270 | + $country_options[$country->ID()] = $country->name(); |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | } |
@@ -301,10 +301,10 @@ discard block |
||
| 301 | 301 | '', |
| 302 | 302 | esc_html__('click here to add a new state/province', 'event_espresso'), |
| 303 | 303 | '', |
| 304 | - 'display-' . $input->html_id(), |
|
| 304 | + 'display-'.$input->html_id(), |
|
| 305 | 305 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
| 306 | 306 | '', |
| 307 | - 'data-target="' . $input->html_id() . '"' |
|
| 307 | + 'data-target="'.$input->html_id().'"' |
|
| 308 | 308 | ) |
| 309 | 309 | ) |
| 310 | 310 | ), |
@@ -314,33 +314,33 @@ discard block |
||
| 314 | 314 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
| 315 | 315 | EEH_HTML::div( |
| 316 | 316 | '', |
| 317 | - $input->html_id() . '-dv', |
|
| 317 | + $input->html_id().'-dv', |
|
| 318 | 318 | 'ee-form-add-new-state-dv', |
| 319 | 319 | 'display: none;' |
| 320 | - ) . |
|
| 320 | + ). |
|
| 321 | 321 | EEH_HTML::h6( |
| 322 | 322 | esc_html__( |
| 323 | 323 | 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
| 324 | 324 | 'event_espresso' |
| 325 | 325 | ) |
| 326 | - ) . |
|
| 327 | - EEH_HTML::ul() . |
|
| 326 | + ). |
|
| 327 | + EEH_HTML::ul(). |
|
| 328 | 328 | EEH_HTML::li( |
| 329 | 329 | esc_html__( |
| 330 | 330 | 'first select the Country that your State/Province belongs to', |
| 331 | 331 | 'event_espresso' |
| 332 | 332 | ) |
| 333 | - ) . |
|
| 333 | + ). |
|
| 334 | 334 | EEH_HTML::li( |
| 335 | 335 | esc_html__('enter the name of your State/Province', 'event_espresso') |
| 336 | - ) . |
|
| 336 | + ). |
|
| 337 | 337 | EEH_HTML::li( |
| 338 | 338 | esc_html__( |
| 339 | 339 | 'enter a two to six letter abbreviation for the name of your State/Province', |
| 340 | 340 | 'event_espresso' |
| 341 | 341 | ) |
| 342 | - ) . |
|
| 343 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 342 | + ). |
|
| 343 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')). |
|
| 344 | 344 | EEH_HTML::ulx() |
| 345 | 345 | ) |
| 346 | 346 | ), |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | 'nsmf_new_state_country', |
| 355 | 355 | $input->html_id() |
| 356 | 356 | ), |
| 357 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 357 | + 'html_class' => $input->html_class().' new-state-country', |
|
| 358 | 358 | 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
| 359 | 359 | 'default' => $request->getRequestParam($country_name), |
| 360 | 360 | 'required' => false, |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | 'nsmf_new_state_name', |
| 370 | 370 | $input->html_id() |
| 371 | 371 | ), |
| 372 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 372 | + 'html_class' => $input->html_class().' new-state-state', |
|
| 373 | 373 | 'html_label_text' => esc_html__( |
| 374 | 374 | 'New State/Province Name', |
| 375 | 375 | 'event_espresso' |
@@ -387,11 +387,11 @@ discard block |
||
| 387 | 387 | 'nsmf_new_state_abbrv', |
| 388 | 388 | $input->html_id() |
| 389 | 389 | ), |
| 390 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 390 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
| 391 | 391 | 'html_label_text' => esc_html__( |
| 392 | 392 | 'New State/Province Abbreviation', |
| 393 | 393 | 'event_espresso' |
| 394 | - ) . ' *', |
|
| 394 | + ).' *', |
|
| 395 | 395 | 'other_html_attributes' => 'size="24"', |
| 396 | 396 | 'default' => $request->getRequestParam($abbrv_name), |
| 397 | 397 | 'required' => false, |
@@ -406,10 +406,10 @@ discard block |
||
| 406 | 406 | esc_html__('ADD', 'event_espresso'), |
| 407 | 407 | 'ee-form-add-new-state-submit button button-secondary', |
| 408 | 408 | '', |
| 409 | - 'submit-' . $new_state_submit_id, |
|
| 409 | + 'submit-'.$new_state_submit_id, |
|
| 410 | 410 | '', |
| 411 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 412 | - . ' data-value-field-name="' . $input->valueFieldName() . '"' |
|
| 411 | + 'data-target="'.$new_state_submit_id.'"' |
|
| 412 | + . ' data-value-field-name="'.$input->valueFieldName().'"' |
|
| 413 | 413 | ), |
| 414 | 414 | '', |
| 415 | 415 | 'ee-form-add-new-state-submit-dv' |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | EEH_HTML::div('', '', 'small-text') |
| 426 | 426 | . |
| 427 | 427 | EEH_HTML::strong( |
| 428 | - '* ' . |
|
| 428 | + '* '. |
|
| 429 | 429 | esc_html__( |
| 430 | 430 | 'Don\'t know your State/Province Abbreviation?', |
| 431 | 431 | 'event_espresso' |
@@ -458,10 +458,10 @@ discard block |
||
| 458 | 458 | '', |
| 459 | 459 | esc_html__('cancel new State/Province', 'event_espresso'), |
| 460 | 460 | '', |
| 461 | - 'hide-' . $input->html_id(), |
|
| 461 | + 'hide-'.$input->html_id(), |
|
| 462 | 462 | 'ee-form-cancel-new-state-lnk smaller-text', |
| 463 | 463 | '', |
| 464 | - 'data-target="' . $input->html_id() . '"' |
|
| 464 | + 'data-target="'.$input->html_id().'"' |
|
| 465 | 465 | ) |
| 466 | 466 | . |
| 467 | 467 | EEH_HTML::divx() |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | ); |
| 523 | 523 | // get any existing new states |
| 524 | 524 | $new_states = EE_Registry::instance()->SSN->get_session_data('nsmf_new_states'); |
| 525 | - $new_states[ $new_state->ID() ] = $new_state; |
|
| 525 | + $new_states[$new_state->ID()] = $new_state; |
|
| 526 | 526 | EE_Registry::instance()->SSN->set_session_data( |
| 527 | 527 | ['nsmf_new_states' => $new_states] |
| 528 | 528 | ); |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | { |
| 603 | 603 | /** @var EE_State[] $existing_state */ |
| 604 | 604 | $existing_state = EEM_State::instance()->get_all([$props_n_values, 'limit' => 1]); |
| 605 | - if (! empty($existing_state)) { |
|
| 605 | + if ( ! empty($existing_state)) { |
|
| 606 | 606 | return array_pop($existing_state); |
| 607 | 607 | } |
| 608 | 608 | $new_state = EE_State::new_instance($props_n_values); |
@@ -617,15 +617,15 @@ discard block |
||
| 617 | 617 | ); |
| 618 | 618 | // if not non-ajax admin |
| 619 | 619 | new PersistentAdminNotice( |
| 620 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 620 | + 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(), |
|
| 621 | 621 | sprintf( |
| 622 | 622 | esc_html__( |
| 623 | 623 | 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
| 624 | 624 | 'event_espresso' |
| 625 | 625 | ), |
| 626 | - '<b>' . $new_state->name() . '</b>', |
|
| 627 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 628 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 626 | + '<b>'.$new_state->name().'</b>', |
|
| 627 | + '<b>'.$new_state->abbrev().'</b>', |
|
| 628 | + '<b>'.$new_state->country()->name().'</b>', |
|
| 629 | 629 | '<a href="' |
| 630 | 630 | . $country_settings_url |
| 631 | 631 | . '">' |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | */ |
| 659 | 659 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = []) |
| 660 | 660 | { |
| 661 | - if (! $CNT_ISO) { |
|
| 661 | + if ( ! $CNT_ISO) { |
|
| 662 | 662 | EE_Error::add_error( |
| 663 | 663 | esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
| 664 | 664 | __FILE__, |
@@ -668,13 +668,13 @@ discard block |
||
| 668 | 668 | } |
| 669 | 669 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
| 670 | 670 | : false; |
| 671 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 671 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
| 672 | 672 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 673 | 673 | if ($state instanceof EE_State) { |
| 674 | 674 | $STA_abbrev = $state->abbrev(); |
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | - if (! $STA_abbrev) { |
|
| 677 | + if ( ! $STA_abbrev) { |
|
| 678 | 678 | EE_Error::add_error( |
| 679 | 679 | esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
| 680 | 680 | __FILE__, |
@@ -686,7 +686,7 @@ discard block |
||
| 686 | 686 | $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
| 687 | 687 | 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
| 688 | 688 | ); |
| 689 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 689 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | |
@@ -712,16 +712,16 @@ discard block |
||
| 712 | 712 | && $question->type() === EEM_Question::QST_type_state |
| 713 | 713 | ) { |
| 714 | 714 | $STA_ID = $answer->value(); |
| 715 | - if (! empty($STA_ID)) { |
|
| 715 | + if ( ! empty($STA_ID)) { |
|
| 716 | 716 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 717 | 717 | if ($state instanceof EE_State) { |
| 718 | 718 | $country = $state->country(); |
| 719 | 719 | if ($country instanceof EE_Country) { |
| 720 | - if (! isset($state_options[ $country->name() ])) { |
|
| 721 | - $state_options[ $country->name() ] = []; |
|
| 720 | + if ( ! isset($state_options[$country->name()])) { |
|
| 721 | + $state_options[$country->name()] = []; |
|
| 722 | 722 | } |
| 723 | - if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
| 724 | - $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
| 723 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
| 724 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 725 | 725 | } |
| 726 | 726 | } |
| 727 | 727 | } |
@@ -754,11 +754,11 @@ discard block |
||
| 754 | 754 | === EEM_Question::QST_type_country |
| 755 | 755 | ) { |
| 756 | 756 | $CNT_ISO = $answer->value(); |
| 757 | - if (! empty($CNT_ISO)) { |
|
| 757 | + if ( ! empty($CNT_ISO)) { |
|
| 758 | 758 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
| 759 | 759 | if ($country instanceof EE_Country) { |
| 760 | - if (! isset($country_options[ $CNT_ISO ])) { |
|
| 761 | - $country_options[ $CNT_ISO ] = $country->name(); |
|
| 760 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
| 761 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 762 | 762 | } |
| 763 | 763 | } |
| 764 | 764 | } |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | $new_state instanceof EE_State |
| 782 | 782 | && $new_state->country() instanceof EE_Country |
| 783 | 783 | ) { |
| 784 | - $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
| 784 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | return $state_options; |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | $new_state instanceof EE_State |
| 821 | 821 | && $new_state->country() instanceof EE_Country |
| 822 | 822 | ) { |
| 823 | - $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
| 823 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 824 | 824 | } |
| 825 | 825 | } |
| 826 | 826 | return $country_options; |
@@ -12,166 +12,166 @@ |
||
| 12 | 12 | class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * opening div tag for a form |
|
| 17 | - * |
|
| 18 | - * @return string |
|
| 19 | - */ |
|
| 20 | - public function layout_form_begin() |
|
| 21 | - { |
|
| 22 | - return EEH_HTML::div( |
|
| 23 | - '', |
|
| 24 | - $this->_form_section->html_id(), |
|
| 25 | - $this->_form_section->html_class(), |
|
| 26 | - $this->_form_section->html_style() |
|
| 27 | - ); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Lays out the row for the input, including label and errors |
|
| 34 | - * |
|
| 35 | - * @param EE_Form_Input_Base $input |
|
| 36 | - * @return string |
|
| 37 | - * @throws \EE_Error |
|
| 38 | - */ |
|
| 39 | - public function layout_input($input) |
|
| 40 | - { |
|
| 41 | - $html = ''; |
|
| 42 | - // set something unique for the id |
|
| 43 | - $html_id = (string) $input->html_id() !== '' |
|
| 44 | - ? (string) $input->html_id() |
|
| 45 | - : spl_object_hash($input); |
|
| 46 | - // and add a generic input type class |
|
| 47 | - $html_class = $this->processHtmlClasses( |
|
| 48 | - sanitize_key(str_replace('_', '-', get_class($input))), |
|
| 49 | - '-dv' |
|
| 50 | - ); |
|
| 51 | - if ($input instanceof EE_Hidden_Input) { |
|
| 52 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 53 | - } elseif ($input instanceof EE_Submit_Input) { |
|
| 54 | - $input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv'); |
|
| 55 | - $html .= EEH_HTML::div( |
|
| 56 | - $input->get_html_for_input(), |
|
| 57 | - $html_id . '-submit-dv', |
|
| 58 | - "$input_class $html_class" |
|
| 59 | - ); |
|
| 60 | - } elseif ($input instanceof EE_Select_Input) { |
|
| 61 | - $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
| 62 | - $html .= EEH_HTML::div( |
|
| 63 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 64 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 65 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 66 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 67 | - $html_id . '-input-dv', |
|
| 68 | - "$input_class $html_class" |
|
| 69 | - ); |
|
| 70 | - } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
| 71 | - $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
| 72 | - $html .= EEH_HTML::div( |
|
| 73 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
| 74 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 75 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 76 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 77 | - $html_id . '-input-dv', |
|
| 78 | - "$input_class $html_class" |
|
| 79 | - ); |
|
| 80 | - } else { |
|
| 81 | - $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
| 82 | - $html .= EEH_HTML::div( |
|
| 83 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 84 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 85 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 86 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 87 | - $html_id . '-input-dv', |
|
| 88 | - "$input_class $html_class" |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - return $html; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * appends one or more css classes in a string with the provided suffix |
|
| 97 | - * |
|
| 98 | - * @param array|string $classes |
|
| 99 | - * @param string $suffix |
|
| 100 | - * @return string |
|
| 101 | - * @since $VID:$ |
|
| 102 | - */ |
|
| 103 | - private function processHtmlClasses($classes, string $suffix): string |
|
| 104 | - { |
|
| 105 | - $html_classes = []; |
|
| 106 | - $classes = is_string($classes) ? explode(' ', $classes) : $classes; |
|
| 107 | - $classes = (array) $classes; |
|
| 108 | - foreach ($classes as $class) { |
|
| 109 | - // don't append suffix if class already has "-js" suffix |
|
| 110 | - $html_classes[] = strpos($class, '-js') !== strlen($class) - 3 |
|
| 111 | - ? "$class$suffix" |
|
| 112 | - : $class; |
|
| 113 | - } |
|
| 114 | - return implode(' ', $html_classes); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * |
|
| 121 | - * _display_label_for_option_type_question |
|
| 122 | - * Gets the HTML for the 'label', which is just text for this (because labels |
|
| 123 | - * should be for each input) |
|
| 124 | - * |
|
| 125 | - * @param EE_Form_Input_With_Options_Base $input |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
| 129 | - { |
|
| 130 | - if ($input->display_html_label_text()) { |
|
| 131 | - $html_label_text = $input->html_label_text(); |
|
| 132 | - $label_html = EEH_HTML::div( |
|
| 133 | - $input->required() |
|
| 134 | - ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
| 135 | - : $html_label_text, |
|
| 136 | - $input->html_label_id(), |
|
| 137 | - $input->required() |
|
| 138 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 139 | - : $input->html_label_class(), |
|
| 140 | - $input->html_label_style(), |
|
| 141 | - $input->other_html_attributes() |
|
| 142 | - ); |
|
| 143 | - // if no content was provided to EEH_HTML::div() above (ie: an empty label), |
|
| 144 | - // then we need to close the div manually |
|
| 145 | - if (empty($html_label_text)) { |
|
| 146 | - $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class()); |
|
| 147 | - } |
|
| 148 | - return $label_html; |
|
| 149 | - } |
|
| 150 | - return ''; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Lays out a row for the subsection |
|
| 157 | - * |
|
| 158 | - * @param EE_Form_Section_Proper $form_section |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function layout_subsection($form_section) |
|
| 162 | - { |
|
| 163 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * closing div tag for a form |
|
| 170 | - * |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 173 | - public function layout_form_end() |
|
| 174 | - { |
|
| 175 | - return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
| 176 | - } |
|
| 15 | + /** |
|
| 16 | + * opening div tag for a form |
|
| 17 | + * |
|
| 18 | + * @return string |
|
| 19 | + */ |
|
| 20 | + public function layout_form_begin() |
|
| 21 | + { |
|
| 22 | + return EEH_HTML::div( |
|
| 23 | + '', |
|
| 24 | + $this->_form_section->html_id(), |
|
| 25 | + $this->_form_section->html_class(), |
|
| 26 | + $this->_form_section->html_style() |
|
| 27 | + ); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Lays out the row for the input, including label and errors |
|
| 34 | + * |
|
| 35 | + * @param EE_Form_Input_Base $input |
|
| 36 | + * @return string |
|
| 37 | + * @throws \EE_Error |
|
| 38 | + */ |
|
| 39 | + public function layout_input($input) |
|
| 40 | + { |
|
| 41 | + $html = ''; |
|
| 42 | + // set something unique for the id |
|
| 43 | + $html_id = (string) $input->html_id() !== '' |
|
| 44 | + ? (string) $input->html_id() |
|
| 45 | + : spl_object_hash($input); |
|
| 46 | + // and add a generic input type class |
|
| 47 | + $html_class = $this->processHtmlClasses( |
|
| 48 | + sanitize_key(str_replace('_', '-', get_class($input))), |
|
| 49 | + '-dv' |
|
| 50 | + ); |
|
| 51 | + if ($input instanceof EE_Hidden_Input) { |
|
| 52 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 53 | + } elseif ($input instanceof EE_Submit_Input) { |
|
| 54 | + $input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv'); |
|
| 55 | + $html .= EEH_HTML::div( |
|
| 56 | + $input->get_html_for_input(), |
|
| 57 | + $html_id . '-submit-dv', |
|
| 58 | + "$input_class $html_class" |
|
| 59 | + ); |
|
| 60 | + } elseif ($input instanceof EE_Select_Input) { |
|
| 61 | + $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
| 62 | + $html .= EEH_HTML::div( |
|
| 63 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 64 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 65 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 66 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 67 | + $html_id . '-input-dv', |
|
| 68 | + "$input_class $html_class" |
|
| 69 | + ); |
|
| 70 | + } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
| 71 | + $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
| 72 | + $html .= EEH_HTML::div( |
|
| 73 | + EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
| 74 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 75 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 76 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 77 | + $html_id . '-input-dv', |
|
| 78 | + "$input_class $html_class" |
|
| 79 | + ); |
|
| 80 | + } else { |
|
| 81 | + $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
| 82 | + $html .= EEH_HTML::div( |
|
| 83 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 84 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 85 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 86 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 87 | + $html_id . '-input-dv', |
|
| 88 | + "$input_class $html_class" |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + return $html; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * appends one or more css classes in a string with the provided suffix |
|
| 97 | + * |
|
| 98 | + * @param array|string $classes |
|
| 99 | + * @param string $suffix |
|
| 100 | + * @return string |
|
| 101 | + * @since $VID:$ |
|
| 102 | + */ |
|
| 103 | + private function processHtmlClasses($classes, string $suffix): string |
|
| 104 | + { |
|
| 105 | + $html_classes = []; |
|
| 106 | + $classes = is_string($classes) ? explode(' ', $classes) : $classes; |
|
| 107 | + $classes = (array) $classes; |
|
| 108 | + foreach ($classes as $class) { |
|
| 109 | + // don't append suffix if class already has "-js" suffix |
|
| 110 | + $html_classes[] = strpos($class, '-js') !== strlen($class) - 3 |
|
| 111 | + ? "$class$suffix" |
|
| 112 | + : $class; |
|
| 113 | + } |
|
| 114 | + return implode(' ', $html_classes); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * |
|
| 121 | + * _display_label_for_option_type_question |
|
| 122 | + * Gets the HTML for the 'label', which is just text for this (because labels |
|
| 123 | + * should be for each input) |
|
| 124 | + * |
|
| 125 | + * @param EE_Form_Input_With_Options_Base $input |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
| 129 | + { |
|
| 130 | + if ($input->display_html_label_text()) { |
|
| 131 | + $html_label_text = $input->html_label_text(); |
|
| 132 | + $label_html = EEH_HTML::div( |
|
| 133 | + $input->required() |
|
| 134 | + ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
| 135 | + : $html_label_text, |
|
| 136 | + $input->html_label_id(), |
|
| 137 | + $input->required() |
|
| 138 | + ? 'ee-required-label ' . $input->html_label_class() |
|
| 139 | + : $input->html_label_class(), |
|
| 140 | + $input->html_label_style(), |
|
| 141 | + $input->other_html_attributes() |
|
| 142 | + ); |
|
| 143 | + // if no content was provided to EEH_HTML::div() above (ie: an empty label), |
|
| 144 | + // then we need to close the div manually |
|
| 145 | + if (empty($html_label_text)) { |
|
| 146 | + $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class()); |
|
| 147 | + } |
|
| 148 | + return $label_html; |
|
| 149 | + } |
|
| 150 | + return ''; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Lays out a row for the subsection |
|
| 157 | + * |
|
| 158 | + * @param EE_Form_Section_Proper $form_section |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function layout_subsection($form_section) |
|
| 162 | + { |
|
| 163 | + return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * closing div tag for a form |
|
| 170 | + * |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | + public function layout_form_end() |
|
| 174 | + { |
|
| 175 | + return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
| 176 | + } |
|
| 177 | 177 | } |
@@ -49,42 +49,42 @@ discard block |
||
| 49 | 49 | '-dv' |
| 50 | 50 | ); |
| 51 | 51 | if ($input instanceof EE_Hidden_Input) { |
| 52 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 52 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
| 53 | 53 | } elseif ($input instanceof EE_Submit_Input) { |
| 54 | 54 | $input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv'); |
| 55 | 55 | $html .= EEH_HTML::div( |
| 56 | 56 | $input->get_html_for_input(), |
| 57 | - $html_id . '-submit-dv', |
|
| 57 | + $html_id.'-submit-dv', |
|
| 58 | 58 | "$input_class $html_class" |
| 59 | 59 | ); |
| 60 | 60 | } elseif ($input instanceof EE_Select_Input) { |
| 61 | 61 | $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
| 62 | 62 | $html .= EEH_HTML::div( |
| 63 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 64 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 65 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 66 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 67 | - $html_id . '-input-dv', |
|
| 63 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
| 64 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
| 65 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
| 66 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
| 67 | + $html_id.'-input-dv', |
|
| 68 | 68 | "$input_class $html_class" |
| 69 | 69 | ); |
| 70 | 70 | } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
| 71 | 71 | $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
| 72 | 72 | $html .= EEH_HTML::div( |
| 73 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
| 74 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 75 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 76 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 77 | - $html_id . '-input-dv', |
|
| 73 | + EEH_HTML::nl().$this->_display_label_for_option_type_question($input). |
|
| 74 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
| 75 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
| 76 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
| 77 | + $html_id.'-input-dv', |
|
| 78 | 78 | "$input_class $html_class" |
| 79 | 79 | ); |
| 80 | 80 | } else { |
| 81 | 81 | $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
| 82 | 82 | $html .= EEH_HTML::div( |
| 83 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 84 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 85 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 86 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 87 | - $html_id . '-input-dv', |
|
| 83 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
| 84 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
| 85 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
| 86 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
| 87 | + $html_id.'-input-dv', |
|
| 88 | 88 | "$input_class $html_class" |
| 89 | 89 | ); |
| 90 | 90 | } |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | $html_label_text = $input->html_label_text(); |
| 132 | 132 | $label_html = EEH_HTML::div( |
| 133 | 133 | $input->required() |
| 134 | - ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
| 134 | + ? $html_label_text.EEH_HTML::span('*', '', 'ee-asterisk') |
|
| 135 | 135 | : $html_label_text, |
| 136 | 136 | $input->html_label_id(), |
| 137 | 137 | $input->required() |
| 138 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 138 | + ? 'ee-required-label '.$input->html_label_class() |
|
| 139 | 139 | : $input->html_label_class(), |
| 140 | 140 | $input->html_label_style(), |
| 141 | 141 | $input->other_html_attributes() |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function layout_subsection($form_section) |
| 162 | 162 | { |
| 163 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
| 163 | + return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | |
@@ -1,905 +1,905 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * |
|
| 5 | - * Class EEH_HTML |
|
| 6 | - * |
|
| 4 | + * |
|
| 5 | + * Class EEH_HTML |
|
| 6 | + * |
|
| 7 | 7 | * Sometimes when writing PHP you need to generate some standard HTML, |
| 8 | 8 | * but either not enough to warrant creating a template file, |
| 9 | 9 | * or the amount of PHP conditionals and/or loops peppered throughout the HTML |
| 10 | 10 | * just make it really ugly and difficult to read. |
| 11 | 11 | * This class simply adds a bunch of methods for generating basic HTML tags. |
| 12 | 12 | * Most of the methods have the same name as the HTML tag they generate, and most have the same set of parameters. |
| 13 | - * |
|
| 14 | - * @package Event Espresso |
|
| 15 | - * @subpackage core |
|
| 16 | - * @author Brent Christensen |
|
| 17 | - * |
|
| 18 | - * |
|
| 19 | - */ |
|
| 13 | + * |
|
| 14 | + * @package Event Espresso |
|
| 15 | + * @subpackage core |
|
| 16 | + * @author Brent Christensen |
|
| 17 | + * |
|
| 18 | + * |
|
| 19 | + */ |
|
| 20 | 20 | class EEH_HTML |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * instance of the EEH_Autoloader object |
|
| 25 | - * @var $_instance |
|
| 26 | - * @access private |
|
| 27 | - */ |
|
| 28 | - private static $_instance; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array $_indent |
|
| 32 | - * @access private |
|
| 33 | - */ |
|
| 34 | - private static $_indent = array(); |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @singleton method used to instantiate class object |
|
| 40 | - * @access public |
|
| 41 | - * @return EEH_HTML |
|
| 42 | - */ |
|
| 43 | - public static function instance() |
|
| 44 | - { |
|
| 45 | - // check if class object is instantiated, and instantiated properly |
|
| 46 | - if (! self::$_instance instanceof EEH_HTML) { |
|
| 47 | - self::$_instance = new EEH_HTML(); |
|
| 48 | - } |
|
| 49 | - return self::$_instance; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * class constructor |
|
| 56 | - * |
|
| 57 | - * @access private |
|
| 58 | - * @return \EEH_HTML |
|
| 59 | - */ |
|
| 60 | - private function __construct() |
|
| 61 | - { |
|
| 62 | - // set some initial formatting for table indentation |
|
| 63 | - EEH_HTML::$_indent = array( |
|
| 64 | - 'table' => 0, |
|
| 65 | - 'thead' => 1, |
|
| 66 | - 'tbody' => 1, |
|
| 67 | - 'tr' => 2, |
|
| 68 | - 'th' => 3, |
|
| 69 | - 'td' => 3, |
|
| 70 | - 'div' => 0, |
|
| 71 | - 'h1' => 0, |
|
| 72 | - 'h2' => 0, |
|
| 73 | - 'h3' => 0, |
|
| 74 | - 'h4' => 0, |
|
| 75 | - 'h5' => 0, |
|
| 76 | - 'h6' => 0, |
|
| 77 | - 'p' => 0, |
|
| 78 | - 'ul' => 0, |
|
| 79 | - 'li' => 1 |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Generates an opening HTML <XX> tag and adds any passed attributes |
|
| 87 | - * if passed content, it will also add that, as well as the closing </XX> tag |
|
| 88 | - * |
|
| 89 | - * @access protected |
|
| 90 | - * @param string $tag |
|
| 91 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 92 | - * @param string $id - html id attribute |
|
| 93 | - * @param string $class - html class attribute |
|
| 94 | - * @param string $style - html style attribute for applying inline styles |
|
| 95 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 96 | - * @param bool $force_close |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - protected static function _open_tag( |
|
| 100 | - $tag = 'div', |
|
| 101 | - $content = '', |
|
| 102 | - $id = '', |
|
| 103 | - $class = '', |
|
| 104 | - $style = '', |
|
| 105 | - $other_attributes = '', |
|
| 106 | - $force_close = false |
|
| 107 | - ) { |
|
| 108 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 109 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 110 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 111 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 112 | - $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
| 113 | - $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
| 114 | - $indent = ! empty($content) || $force_close ? true : false; |
|
| 115 | - $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
|
| 116 | - return $html; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Generates HTML closing </XX> tag - if passed the id or class attribute |
|
| 123 | - * used for the opening tag, will append a comment |
|
| 124 | - * |
|
| 23 | + /** |
|
| 24 | + * instance of the EEH_Autoloader object |
|
| 25 | + * @var $_instance |
|
| 26 | + * @access private |
|
| 27 | + */ |
|
| 28 | + private static $_instance; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array $_indent |
|
| 32 | + * @access private |
|
| 33 | + */ |
|
| 34 | + private static $_indent = array(); |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @singleton method used to instantiate class object |
|
| 40 | + * @access public |
|
| 41 | + * @return EEH_HTML |
|
| 42 | + */ |
|
| 43 | + public static function instance() |
|
| 44 | + { |
|
| 45 | + // check if class object is instantiated, and instantiated properly |
|
| 46 | + if (! self::$_instance instanceof EEH_HTML) { |
|
| 47 | + self::$_instance = new EEH_HTML(); |
|
| 48 | + } |
|
| 49 | + return self::$_instance; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * class constructor |
|
| 56 | + * |
|
| 57 | + * @access private |
|
| 58 | + * @return \EEH_HTML |
|
| 59 | + */ |
|
| 60 | + private function __construct() |
|
| 61 | + { |
|
| 62 | + // set some initial formatting for table indentation |
|
| 63 | + EEH_HTML::$_indent = array( |
|
| 64 | + 'table' => 0, |
|
| 65 | + 'thead' => 1, |
|
| 66 | + 'tbody' => 1, |
|
| 67 | + 'tr' => 2, |
|
| 68 | + 'th' => 3, |
|
| 69 | + 'td' => 3, |
|
| 70 | + 'div' => 0, |
|
| 71 | + 'h1' => 0, |
|
| 72 | + 'h2' => 0, |
|
| 73 | + 'h3' => 0, |
|
| 74 | + 'h4' => 0, |
|
| 75 | + 'h5' => 0, |
|
| 76 | + 'h6' => 0, |
|
| 77 | + 'p' => 0, |
|
| 78 | + 'ul' => 0, |
|
| 79 | + 'li' => 1 |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Generates an opening HTML <XX> tag and adds any passed attributes |
|
| 87 | + * if passed content, it will also add that, as well as the closing </XX> tag |
|
| 88 | + * |
|
| 89 | + * @access protected |
|
| 90 | + * @param string $tag |
|
| 91 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 92 | + * @param string $id - html id attribute |
|
| 93 | + * @param string $class - html class attribute |
|
| 94 | + * @param string $style - html style attribute for applying inline styles |
|
| 95 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 96 | + * @param bool $force_close |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + protected static function _open_tag( |
|
| 100 | + $tag = 'div', |
|
| 101 | + $content = '', |
|
| 102 | + $id = '', |
|
| 103 | + $class = '', |
|
| 104 | + $style = '', |
|
| 105 | + $other_attributes = '', |
|
| 106 | + $force_close = false |
|
| 107 | + ) { |
|
| 108 | + $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 109 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 110 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 111 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 112 | + $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
| 113 | + $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
| 114 | + $indent = ! empty($content) || $force_close ? true : false; |
|
| 115 | + $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
|
| 116 | + return $html; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Generates HTML closing </XX> tag - if passed the id or class attribute |
|
| 123 | + * used for the opening tag, will append a comment |
|
| 124 | + * |
|
| 125 | 125 | *@access protected |
| 126 | - * @param string $tag |
|
| 127 | - * @param string $id - html id attribute |
|
| 128 | - * @param string $class - html class attribute |
|
| 129 | - * @param bool $indent |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true) |
|
| 133 | - { |
|
| 134 | - $comment = ''; |
|
| 135 | - if ($id) { |
|
| 136 | - $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
| 137 | - } elseif ($class) { |
|
| 138 | - $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
| 139 | - } |
|
| 140 | - $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
|
| 141 | - $html .= '</' . $tag . '>' . $comment; |
|
| 142 | - return $html; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * div - generates HTML opening <div> tag and adds any passed attributes |
|
| 149 | - * to add an id use: echo EEH_HTML::div( 'this is some content', 'footer' ); |
|
| 150 | - * to add a class use: echo EEH_HTML::div( 'this is some content', '', 'float_left' ); |
|
| 151 | - * to add a both an id and a class use: echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' ); |
|
| 152 | - * |
|
| 153 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 154 | - * @param string $id - html id attribute |
|
| 155 | - * @param string $class - html class attribute |
|
| 156 | - * @param string $style - html style attribute for applying inline styles |
|
| 157 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 161 | - { |
|
| 162 | - return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment |
|
| 169 | - * usage: echo EEH_HTML::divx(); |
|
| 170 | - * |
|
| 171 | - * @param string $id - html id attribute |
|
| 172 | - * @param string $class - html class attribute |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public static function divx($id = '', $class = '') |
|
| 176 | - { |
|
| 177 | - return EEH_HTML::_close_tag('div', $id, $class); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes |
|
| 184 | - * usage: echo EEH_HTML::h1( 'This is a Heading' ); |
|
| 185 | - * |
|
| 186 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 187 | - * @param string $id - html id attribute |
|
| 188 | - * @param string $class - html class attribute |
|
| 189 | - * @param string $style - html style attribute for applying inline styles |
|
| 190 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 191 | - * @return string |
|
| 192 | - */ |
|
| 193 | - public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 194 | - { |
|
| 195 | - return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes |
|
| 202 | - * usage: echo EEH_HTML::h2( 'This is a Heading' ); |
|
| 203 | - * |
|
| 204 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 205 | - * @param string $id - html id attribute |
|
| 206 | - * @param string $class - html class attribute |
|
| 207 | - * @param string $style - html style attribute for applying inline styles |
|
| 208 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 209 | - * @return string |
|
| 210 | - */ |
|
| 211 | - public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 212 | - { |
|
| 213 | - return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes |
|
| 220 | - * usage: echo EEH_HTML::h3( 'This is a Heading' ); |
|
| 221 | - * |
|
| 222 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 223 | - * @param string $id - html id attribute |
|
| 224 | - * @param string $class - html class attribute |
|
| 225 | - * @param string $style - html style attribute for applying inline styles |
|
| 226 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 230 | - { |
|
| 231 | - return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes |
|
| 238 | - * usage: echo EEH_HTML::h4( 'This is a Heading' ); |
|
| 239 | - * |
|
| 240 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 241 | - * @param string $id - html id attribute |
|
| 242 | - * @param string $class - html class attribute |
|
| 243 | - * @param string $style - html style attribute for applying inline styles |
|
| 244 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 245 | - * @return string |
|
| 246 | - */ |
|
| 247 | - public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 248 | - { |
|
| 249 | - return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes |
|
| 256 | - * usage: echo EEH_HTML::h5( 'This is a Heading' ); |
|
| 257 | - * |
|
| 258 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 259 | - * @param string $id - html id attribute |
|
| 260 | - * @param string $class - html class attribute |
|
| 261 | - * @param string $style - html style attribute for applying inline styles |
|
| 262 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 263 | - * @return string |
|
| 264 | - */ |
|
| 265 | - public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 266 | - { |
|
| 267 | - return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes |
|
| 274 | - * usage: echo EEH_HTML::h6( 'This is a Heading' ); |
|
| 275 | - * |
|
| 276 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 277 | - * @param string $id - html id attribute |
|
| 278 | - * @param string $class - html class attribute |
|
| 279 | - * @param string $style - html style attribute for applying inline styles |
|
| 280 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 281 | - * @return string |
|
| 282 | - */ |
|
| 283 | - public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 284 | - { |
|
| 285 | - return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Generates HTML <p></p> tags, inserts content, and adds any passed attributes |
|
| 292 | - * usage: echo EEH_HTML::p( 'this is a paragraph' ); |
|
| 293 | - * |
|
| 294 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 295 | - * @param string $id - html id attribute |
|
| 296 | - * @param string $class - html class attribute |
|
| 297 | - * @param string $style - html style attribute for applying inline styles |
|
| 298 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 299 | - * @return string |
|
| 300 | - */ |
|
| 301 | - public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 302 | - { |
|
| 303 | - return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * ul - generates HTML opening <ul> tag and adds any passed attributes |
|
| 310 | - * usage: echo EEH_HTML::ul( 'my-list-id', 'my-list-class' ); |
|
| 311 | - * |
|
| 312 | - * @param string $id - html id attribute |
|
| 313 | - * @param string $class - html class attribute |
|
| 314 | - * @param string $style - html style attribute for applying inline styles |
|
| 315 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 316 | - * @return string |
|
| 317 | - */ |
|
| 318 | - public static function ul($id = '', $class = '', $style = '', $other_attributes = '') |
|
| 319 | - { |
|
| 320 | - return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 327 | - * usage: echo EEH_HTML::ulx(); |
|
| 328 | - * |
|
| 329 | - * @param string $id - html id attribute |
|
| 330 | - * @param string $class - html class attribute |
|
| 331 | - * @return string |
|
| 332 | - */ |
|
| 333 | - public static function ulx($id = '', $class = '') |
|
| 334 | - { |
|
| 335 | - return EEH_HTML::_close_tag('ul', $id, $class); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Generates HTML <li> tag, inserts content, and adds any passed attributes |
|
| 342 | - * if passed content, it will also add that, as well as the closing </li> tag |
|
| 343 | - * usage: echo EEH_HTML::li( 'this is a line item' ); |
|
| 344 | - * |
|
| 345 | - * @param string $id - html id attribute |
|
| 346 | - * @param string $class - html class attribute |
|
| 347 | - * @param string $style - html style attribute for applying inline styles |
|
| 348 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 349 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 350 | - * @return string |
|
| 351 | - */ |
|
| 352 | - public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 353 | - { |
|
| 354 | - return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 361 | - * usage: echo EEH_HTML::lix(); |
|
| 362 | - * |
|
| 363 | - * @param string $id - html id attribute |
|
| 364 | - * @param string $class - html class attribute |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 367 | - public static function lix($id = '', $class = '') |
|
| 368 | - { |
|
| 369 | - return EEH_HTML::_close_tag('li', $id, $class); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * table - generates an HTML <table> tag and adds any passed attributes |
|
| 376 | - * usage: echo EEH_HTML::table(); |
|
| 377 | - * |
|
| 378 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 379 | - * @param string $id - html id attribute |
|
| 380 | - * @param string $class - html class attribute |
|
| 381 | - * @param string $style - html style attribute for applying inline styles |
|
| 382 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 383 | - * @return string |
|
| 384 | - */ |
|
| 385 | - public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 386 | - { |
|
| 387 | - return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 394 | - * |
|
| 395 | - * @param string $id - html id attribute |
|
| 396 | - * @param string $class - html class attribute |
|
| 397 | - * @return string |
|
| 398 | - */ |
|
| 399 | - public static function tablex($id = '', $class = '') |
|
| 400 | - { |
|
| 401 | - return EEH_HTML::_close_tag('table', $id, $class); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * thead - generates an HTML <thead> tag and adds any passed attributes |
|
| 408 | - * usage: echo EEH_HTML::thead(); |
|
| 409 | - * |
|
| 410 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 411 | - * @param string $id - html id attribute |
|
| 412 | - * @param string $class - html class attribute |
|
| 413 | - * @param string $style - html style attribute for applying inline styles |
|
| 414 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 415 | - * @return string |
|
| 416 | - */ |
|
| 417 | - public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 418 | - { |
|
| 419 | - return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 426 | - * |
|
| 427 | - * @param string $id - html id attribute |
|
| 428 | - * @param string $class - html class attribute |
|
| 429 | - * @return string |
|
| 430 | - */ |
|
| 431 | - public static function theadx($id = '', $class = '') |
|
| 432 | - { |
|
| 433 | - return EEH_HTML::_close_tag('thead', $id, $class); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * tbody - generates an HTML <tbody> tag and adds any passed attributes |
|
| 440 | - * usage: echo EEH_HTML::tbody(); |
|
| 441 | - * |
|
| 442 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 443 | - * @param string $id - html id attribute |
|
| 444 | - * @param string $class - html class attribute |
|
| 445 | - * @param string $style - html style attribute for applying inline styles |
|
| 446 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 447 | - * @return string |
|
| 448 | - */ |
|
| 449 | - public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 450 | - { |
|
| 451 | - return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 458 | - * |
|
| 459 | - * @param string $id - html id attribute |
|
| 460 | - * @param string $class - html class attribute |
|
| 461 | - * @return string |
|
| 462 | - */ |
|
| 463 | - public static function tbodyx($id = '', $class = '') |
|
| 464 | - { |
|
| 465 | - return EEH_HTML::_close_tag('tbody', $id, $class); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * tr - generates an HTML <tr> tag and adds any passed attributes |
|
| 472 | - * usage: echo EEH_HTML::tr(); |
|
| 473 | - * |
|
| 474 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 475 | - * @param string $id - html id attribute |
|
| 476 | - * @param string $class - html class attribute |
|
| 477 | - * @param string $style - html style attribute for applying inline styles |
|
| 478 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 479 | - * @return string |
|
| 480 | - */ |
|
| 481 | - public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 482 | - { |
|
| 483 | - return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 490 | - * |
|
| 491 | - * @param string $id - html id attribute |
|
| 492 | - * @param string $class - html class attribute |
|
| 493 | - * @return string |
|
| 494 | - */ |
|
| 495 | - public static function trx($id = '', $class = '') |
|
| 496 | - { |
|
| 497 | - return EEH_HTML::_close_tag('tr', $id, $class); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * th - generates an HTML <th> tag and adds any passed attributes |
|
| 504 | - * usage: echo EEH_HTML::th(); |
|
| 505 | - * |
|
| 506 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 507 | - * @param string $id - html id attribute |
|
| 508 | - * @param string $class - html class attribute |
|
| 509 | - * @param string $style - html style attribute for applying inline styles |
|
| 510 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 511 | - * @return string |
|
| 512 | - */ |
|
| 513 | - public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 514 | - { |
|
| 515 | - return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 522 | - * |
|
| 523 | - * @param string $id - html id attribute |
|
| 524 | - * @param string $class - html class attribute |
|
| 525 | - * @return string |
|
| 526 | - */ |
|
| 527 | - public static function thx($id = '', $class = '') |
|
| 528 | - { |
|
| 529 | - return EEH_HTML::_close_tag('th', $id, $class); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * td - generates an HTML <td> tag and adds any passed attributes |
|
| 536 | - * usage: echo EEH_HTML::td(); |
|
| 537 | - * |
|
| 538 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 539 | - * @param string $id - html id attribute |
|
| 540 | - * @param string $class - html class attribute |
|
| 541 | - * @param string $style - html style attribute for applying inline styles |
|
| 542 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 543 | - * @return string |
|
| 544 | - */ |
|
| 545 | - public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 546 | - { |
|
| 547 | - return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 554 | - * |
|
| 555 | - * @param string $id - html id attribute |
|
| 556 | - * @param string $class - html class attribute |
|
| 557 | - * @return string |
|
| 558 | - */ |
|
| 559 | - public static function tdx($id = '', $class = '') |
|
| 560 | - { |
|
| 561 | - return EEH_HTML::_close_tag('td', $id, $class); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * no_row - for generating a "hidden" table row, good for embedding tables within tables |
|
| 568 | - * generates a new table row with one td cell that spans however many columns you set |
|
| 569 | - * removes all styles from the tr and td |
|
| 570 | - * |
|
| 571 | - * @param string $content |
|
| 572 | - * @param int $colspan |
|
| 573 | - * @return string |
|
| 574 | - */ |
|
| 575 | - public static function no_row($content = '', $colspan = 2) |
|
| 576 | - { |
|
| 577 | - return EEH_HTML::tr( |
|
| 578 | - EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
| 579 | - '', |
|
| 580 | - '', |
|
| 581 | - 'padding:0; border:none;' |
|
| 582 | - ); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Generates HTML <a href="url">text</a> tags, inserts content, and adds any passed attributes |
|
| 589 | - * usage: echo EEH_HTML::link( 'domain.com', 'this is a link' ); |
|
| 590 | - * |
|
| 591 | - * @access public |
|
| 592 | - * @param string $href URL to link to |
|
| 593 | - * @param string $link_text - the text that will become "hyperlinked" |
|
| 594 | - * @param string $title - html title attribute |
|
| 595 | - * @param string $id - html id attribute |
|
| 596 | - * @param string $class - html class attribute |
|
| 597 | - * @param string $style - html style attribute for applying inline styles |
|
| 598 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 599 | - * @return string |
|
| 600 | - */ |
|
| 601 | - public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 602 | - { |
|
| 603 | - $link_text = ! empty($link_text) ? $link_text : $href; |
|
| 604 | - $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
| 605 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 606 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 607 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 608 | - $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
| 609 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 610 | - return "<a{$attributes}>{$link_text}</a>"; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Generates HTML <button>text</button> tags, inserts content, and adds any passed attributes |
|
| 617 | - * usage: echo EEH_HTML::button( 'this is a button' ); |
|
| 618 | - * |
|
| 619 | - * @param string $btn_text - the text that will become "hyperlinked" |
|
| 620 | - * @param string $class - html class attribute |
|
| 621 | - * @param string $aria_label - aria-label attribute |
|
| 622 | - * @param string $id - html id attribute |
|
| 623 | - * @param string $style - html style attribute for applying inline styles |
|
| 624 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 625 | - * @return string |
|
| 626 | - */ |
|
| 627 | - public static function button( |
|
| 628 | - $btn_text = '', |
|
| 629 | - $class = '', |
|
| 630 | - $aria_label = '', |
|
| 631 | - $id = '', |
|
| 632 | - $style = '', |
|
| 633 | - $other_attributes = '' |
|
| 634 | - ) { |
|
| 635 | - $attributes = ! empty($aria_label) ? ' aria-label="' . $aria_label . '"' : ''; |
|
| 636 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 637 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 638 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 639 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 640 | - return "<button type='button' {$attributes}>{$btn_text}</button>"; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * img - generates an HTML <img> tag and adds any passed attributes |
|
| 647 | - * usage: echo EEH_HTML::img(); |
|
| 648 | - * |
|
| 649 | - * @param string $src - html src attribute ie: the path or URL to the image |
|
| 650 | - * @param string $alt - html alt attribute |
|
| 651 | - * @param string $id - html id attribute |
|
| 652 | - * @param string $class - html class attribute |
|
| 653 | - * @param string $style - html style attribute for applying inline styles |
|
| 654 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 655 | - * @return string |
|
| 656 | - */ |
|
| 657 | - public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 658 | - { |
|
| 659 | - $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
| 660 | - $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
| 661 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 662 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 663 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 664 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 665 | - return '<img' . $attributes . '/>'; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
| 672 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
| 673 | - * |
|
| 674 | - * @access protected |
|
| 675 | - * @param string $tag |
|
| 676 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 677 | - * @param string $id - html id attribute |
|
| 678 | - * @param string $class - html class attribute |
|
| 679 | - * @param string $style - html style attribute for applying inline styles |
|
| 680 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 681 | - * @return string |
|
| 682 | - */ |
|
| 683 | - protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 684 | - { |
|
| 685 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 686 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 687 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 688 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 689 | - return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
| 696 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
| 697 | - * |
|
| 698 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 699 | - * @param string $id - html id attribute |
|
| 700 | - * @param string $class - html class attribute |
|
| 701 | - * @param string $style - html style attribute for applying inline styles |
|
| 702 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 703 | - * @return string |
|
| 704 | - */ |
|
| 705 | - public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 706 | - { |
|
| 707 | - return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
| 714 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
| 715 | - * |
|
| 716 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 717 | - * @param string $id - html id attribute |
|
| 718 | - * @param string $class - html class attribute |
|
| 719 | - * @param string $style - html style attribute for applying inline styles |
|
| 720 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 721 | - * @return string |
|
| 722 | - */ |
|
| 723 | - public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 724 | - { |
|
| 725 | - return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
| 732 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
| 733 | - * |
|
| 734 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 735 | - * @param string $id - html id attribute |
|
| 736 | - * @param string $class - html class attribute |
|
| 737 | - * @param string $style - html style attribute for applying inline styles |
|
| 738 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 739 | - * @return string |
|
| 740 | - */ |
|
| 741 | - public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 742 | - { |
|
| 743 | - return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Generates an html <-- comment --> tag |
|
| 750 | - * usage: echo comment( 'this is a comment' ); |
|
| 751 | - * |
|
| 752 | - * @param string $comment |
|
| 753 | - * @return string |
|
| 754 | - */ |
|
| 755 | - public static function comment($comment = '') |
|
| 756 | - { |
|
| 757 | - return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * br - generates a line break |
|
| 764 | - * |
|
| 765 | - * @param int $nmbr - the number of line breaks to return |
|
| 766 | - * @return string |
|
| 767 | - */ |
|
| 768 | - public static function br($nmbr = 1) |
|
| 769 | - { |
|
| 770 | - return str_repeat('<br />', $nmbr); |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * nbsp - generates non-breaking space entities based on number supplied |
|
| 777 | - * |
|
| 778 | - * @param int $nmbr - the number of non-breaking spaces to return |
|
| 779 | - * @return string |
|
| 780 | - */ |
|
| 781 | - public static function nbsp($nmbr = 1) |
|
| 782 | - { |
|
| 783 | - return str_repeat(' ', $nmbr); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * sanitize_id |
|
| 790 | - * |
|
| 791 | - * functionally does the same as the wp_core function sanitize_key except it does NOT use |
|
| 792 | - * strtolower and allows capitals. |
|
| 793 | - * |
|
| 794 | - * @param string $id |
|
| 795 | - * @return string |
|
| 796 | - */ |
|
| 797 | - public static function sanitize_id($id = '') |
|
| 798 | - { |
|
| 799 | - $key = str_replace(' ', '-', trim($id)); |
|
| 800 | - return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * return a newline and tabs ("nl" stands for "new line") |
|
| 807 | - * |
|
| 808 | - * @param int $indent the number of tabs to ADD to the current indent (can be negative or zero) |
|
| 809 | - * @param string $tag |
|
| 810 | - * @return string - newline character plus # of indents passed (can be + or -) |
|
| 811 | - */ |
|
| 812 | - public static function nl($indent = 0, $tag = 'none') |
|
| 813 | - { |
|
| 814 | - $html = "\n"; |
|
| 815 | - EEH_HTML::indent($indent, $tag); |
|
| 816 | - for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
| 817 | - $html .= "\t"; |
|
| 818 | - } |
|
| 819 | - return $html; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * Changes the indents used in EEH_HTML::nl. Often its convenient to change |
|
| 826 | - * the indentation level without actually creating a new line |
|
| 827 | - * |
|
| 828 | - * @param int $indent can be negative to decrease the indentation level |
|
| 829 | - * @param string $tag |
|
| 830 | - */ |
|
| 831 | - public static function indent($indent, $tag = 'none') |
|
| 832 | - { |
|
| 833 | - static $default_indentation = false; |
|
| 834 | - if (! $default_indentation) { |
|
| 835 | - EEH_HTML::_set_default_indentation(); |
|
| 836 | - $default_indentation = true; |
|
| 837 | - } |
|
| 838 | - if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
| 839 | - EEH_HTML::$_indent[ $tag ] = 0; |
|
| 840 | - } |
|
| 841 | - EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
| 842 | - EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * class _set_default_indentation |
|
| 848 | - * |
|
| 849 | - * @access private |
|
| 850 | - */ |
|
| 851 | - private static function _set_default_indentation() |
|
| 852 | - { |
|
| 853 | - // set some initial formatting for table indentation |
|
| 854 | - EEH_HTML::$_indent = array( |
|
| 855 | - 'none' => 0, |
|
| 856 | - 'form' => 0, |
|
| 857 | - 'radio' => 0, |
|
| 858 | - 'checkbox' => 0, |
|
| 859 | - 'select' => 0, |
|
| 860 | - 'option' => 0, |
|
| 861 | - 'optgroup' => 0, |
|
| 862 | - 'table' => 1, |
|
| 863 | - 'thead' => 2, |
|
| 864 | - 'tbody' => 2, |
|
| 865 | - 'tr' => 3, |
|
| 866 | - 'th' => 4, |
|
| 867 | - 'td' => 4, |
|
| 868 | - 'div' => 0, |
|
| 869 | - 'h1' => 0, |
|
| 870 | - 'h2' => 0, |
|
| 871 | - 'h3' => 0, |
|
| 872 | - 'h4' => 0, |
|
| 873 | - 'h5' => 0, |
|
| 874 | - 'h6' => 0, |
|
| 875 | - 'p' => 0, |
|
| 876 | - 'ul' => 0, |
|
| 877 | - 'li' => 1 |
|
| 878 | - ); |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * Retrieves the list of tags considered "simple", that are probably safe for |
|
| 885 | - * use in inputs |
|
| 886 | - * @global array $allowedtags |
|
| 887 | - * @return array |
|
| 888 | - */ |
|
| 889 | - public static function get_simple_tags() |
|
| 890 | - { |
|
| 891 | - global $allowedtags; |
|
| 892 | - $tags_we_allow = array_merge_recursive( |
|
| 893 | - $allowedtags, |
|
| 894 | - [ |
|
| 895 | - 'ol' => [], |
|
| 896 | - 'ul' => [], |
|
| 897 | - 'li' => [], |
|
| 898 | - 'br' => [], |
|
| 899 | - 'p' => [], |
|
| 900 | - 'a' => ['target'] |
|
| 901 | - ] |
|
| 902 | - ); |
|
| 903 | - return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow); |
|
| 904 | - } |
|
| 126 | + * @param string $tag |
|
| 127 | + * @param string $id - html id attribute |
|
| 128 | + * @param string $class - html class attribute |
|
| 129 | + * @param bool $indent |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true) |
|
| 133 | + { |
|
| 134 | + $comment = ''; |
|
| 135 | + if ($id) { |
|
| 136 | + $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
| 137 | + } elseif ($class) { |
|
| 138 | + $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
| 139 | + } |
|
| 140 | + $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
|
| 141 | + $html .= '</' . $tag . '>' . $comment; |
|
| 142 | + return $html; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * div - generates HTML opening <div> tag and adds any passed attributes |
|
| 149 | + * to add an id use: echo EEH_HTML::div( 'this is some content', 'footer' ); |
|
| 150 | + * to add a class use: echo EEH_HTML::div( 'this is some content', '', 'float_left' ); |
|
| 151 | + * to add a both an id and a class use: echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' ); |
|
| 152 | + * |
|
| 153 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 154 | + * @param string $id - html id attribute |
|
| 155 | + * @param string $class - html class attribute |
|
| 156 | + * @param string $style - html style attribute for applying inline styles |
|
| 157 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 161 | + { |
|
| 162 | + return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment |
|
| 169 | + * usage: echo EEH_HTML::divx(); |
|
| 170 | + * |
|
| 171 | + * @param string $id - html id attribute |
|
| 172 | + * @param string $class - html class attribute |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public static function divx($id = '', $class = '') |
|
| 176 | + { |
|
| 177 | + return EEH_HTML::_close_tag('div', $id, $class); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes |
|
| 184 | + * usage: echo EEH_HTML::h1( 'This is a Heading' ); |
|
| 185 | + * |
|
| 186 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 187 | + * @param string $id - html id attribute |
|
| 188 | + * @param string $class - html class attribute |
|
| 189 | + * @param string $style - html style attribute for applying inline styles |
|
| 190 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 191 | + * @return string |
|
| 192 | + */ |
|
| 193 | + public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 194 | + { |
|
| 195 | + return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes |
|
| 202 | + * usage: echo EEH_HTML::h2( 'This is a Heading' ); |
|
| 203 | + * |
|
| 204 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 205 | + * @param string $id - html id attribute |
|
| 206 | + * @param string $class - html class attribute |
|
| 207 | + * @param string $style - html style attribute for applying inline styles |
|
| 208 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 212 | + { |
|
| 213 | + return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes |
|
| 220 | + * usage: echo EEH_HTML::h3( 'This is a Heading' ); |
|
| 221 | + * |
|
| 222 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 223 | + * @param string $id - html id attribute |
|
| 224 | + * @param string $class - html class attribute |
|
| 225 | + * @param string $style - html style attribute for applying inline styles |
|
| 226 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 230 | + { |
|
| 231 | + return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes |
|
| 238 | + * usage: echo EEH_HTML::h4( 'This is a Heading' ); |
|
| 239 | + * |
|
| 240 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 241 | + * @param string $id - html id attribute |
|
| 242 | + * @param string $class - html class attribute |
|
| 243 | + * @param string $style - html style attribute for applying inline styles |
|
| 244 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 245 | + * @return string |
|
| 246 | + */ |
|
| 247 | + public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 248 | + { |
|
| 249 | + return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes |
|
| 256 | + * usage: echo EEH_HTML::h5( 'This is a Heading' ); |
|
| 257 | + * |
|
| 258 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 259 | + * @param string $id - html id attribute |
|
| 260 | + * @param string $class - html class attribute |
|
| 261 | + * @param string $style - html style attribute for applying inline styles |
|
| 262 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 263 | + * @return string |
|
| 264 | + */ |
|
| 265 | + public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 266 | + { |
|
| 267 | + return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes |
|
| 274 | + * usage: echo EEH_HTML::h6( 'This is a Heading' ); |
|
| 275 | + * |
|
| 276 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 277 | + * @param string $id - html id attribute |
|
| 278 | + * @param string $class - html class attribute |
|
| 279 | + * @param string $style - html style attribute for applying inline styles |
|
| 280 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 281 | + * @return string |
|
| 282 | + */ |
|
| 283 | + public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 284 | + { |
|
| 285 | + return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Generates HTML <p></p> tags, inserts content, and adds any passed attributes |
|
| 292 | + * usage: echo EEH_HTML::p( 'this is a paragraph' ); |
|
| 293 | + * |
|
| 294 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 295 | + * @param string $id - html id attribute |
|
| 296 | + * @param string $class - html class attribute |
|
| 297 | + * @param string $style - html style attribute for applying inline styles |
|
| 298 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 299 | + * @return string |
|
| 300 | + */ |
|
| 301 | + public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 302 | + { |
|
| 303 | + return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * ul - generates HTML opening <ul> tag and adds any passed attributes |
|
| 310 | + * usage: echo EEH_HTML::ul( 'my-list-id', 'my-list-class' ); |
|
| 311 | + * |
|
| 312 | + * @param string $id - html id attribute |
|
| 313 | + * @param string $class - html class attribute |
|
| 314 | + * @param string $style - html style attribute for applying inline styles |
|
| 315 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 316 | + * @return string |
|
| 317 | + */ |
|
| 318 | + public static function ul($id = '', $class = '', $style = '', $other_attributes = '') |
|
| 319 | + { |
|
| 320 | + return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 327 | + * usage: echo EEH_HTML::ulx(); |
|
| 328 | + * |
|
| 329 | + * @param string $id - html id attribute |
|
| 330 | + * @param string $class - html class attribute |
|
| 331 | + * @return string |
|
| 332 | + */ |
|
| 333 | + public static function ulx($id = '', $class = '') |
|
| 334 | + { |
|
| 335 | + return EEH_HTML::_close_tag('ul', $id, $class); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Generates HTML <li> tag, inserts content, and adds any passed attributes |
|
| 342 | + * if passed content, it will also add that, as well as the closing </li> tag |
|
| 343 | + * usage: echo EEH_HTML::li( 'this is a line item' ); |
|
| 344 | + * |
|
| 345 | + * @param string $id - html id attribute |
|
| 346 | + * @param string $class - html class attribute |
|
| 347 | + * @param string $style - html style attribute for applying inline styles |
|
| 348 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 349 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 350 | + * @return string |
|
| 351 | + */ |
|
| 352 | + public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 353 | + { |
|
| 354 | + return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 361 | + * usage: echo EEH_HTML::lix(); |
|
| 362 | + * |
|
| 363 | + * @param string $id - html id attribute |
|
| 364 | + * @param string $class - html class attribute |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | + public static function lix($id = '', $class = '') |
|
| 368 | + { |
|
| 369 | + return EEH_HTML::_close_tag('li', $id, $class); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * table - generates an HTML <table> tag and adds any passed attributes |
|
| 376 | + * usage: echo EEH_HTML::table(); |
|
| 377 | + * |
|
| 378 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 379 | + * @param string $id - html id attribute |
|
| 380 | + * @param string $class - html class attribute |
|
| 381 | + * @param string $style - html style attribute for applying inline styles |
|
| 382 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 383 | + * @return string |
|
| 384 | + */ |
|
| 385 | + public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 386 | + { |
|
| 387 | + return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 394 | + * |
|
| 395 | + * @param string $id - html id attribute |
|
| 396 | + * @param string $class - html class attribute |
|
| 397 | + * @return string |
|
| 398 | + */ |
|
| 399 | + public static function tablex($id = '', $class = '') |
|
| 400 | + { |
|
| 401 | + return EEH_HTML::_close_tag('table', $id, $class); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * thead - generates an HTML <thead> tag and adds any passed attributes |
|
| 408 | + * usage: echo EEH_HTML::thead(); |
|
| 409 | + * |
|
| 410 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 411 | + * @param string $id - html id attribute |
|
| 412 | + * @param string $class - html class attribute |
|
| 413 | + * @param string $style - html style attribute for applying inline styles |
|
| 414 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 415 | + * @return string |
|
| 416 | + */ |
|
| 417 | + public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 418 | + { |
|
| 419 | + return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 426 | + * |
|
| 427 | + * @param string $id - html id attribute |
|
| 428 | + * @param string $class - html class attribute |
|
| 429 | + * @return string |
|
| 430 | + */ |
|
| 431 | + public static function theadx($id = '', $class = '') |
|
| 432 | + { |
|
| 433 | + return EEH_HTML::_close_tag('thead', $id, $class); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * tbody - generates an HTML <tbody> tag and adds any passed attributes |
|
| 440 | + * usage: echo EEH_HTML::tbody(); |
|
| 441 | + * |
|
| 442 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 443 | + * @param string $id - html id attribute |
|
| 444 | + * @param string $class - html class attribute |
|
| 445 | + * @param string $style - html style attribute for applying inline styles |
|
| 446 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 447 | + * @return string |
|
| 448 | + */ |
|
| 449 | + public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 450 | + { |
|
| 451 | + return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 458 | + * |
|
| 459 | + * @param string $id - html id attribute |
|
| 460 | + * @param string $class - html class attribute |
|
| 461 | + * @return string |
|
| 462 | + */ |
|
| 463 | + public static function tbodyx($id = '', $class = '') |
|
| 464 | + { |
|
| 465 | + return EEH_HTML::_close_tag('tbody', $id, $class); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * tr - generates an HTML <tr> tag and adds any passed attributes |
|
| 472 | + * usage: echo EEH_HTML::tr(); |
|
| 473 | + * |
|
| 474 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 475 | + * @param string $id - html id attribute |
|
| 476 | + * @param string $class - html class attribute |
|
| 477 | + * @param string $style - html style attribute for applying inline styles |
|
| 478 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 479 | + * @return string |
|
| 480 | + */ |
|
| 481 | + public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 482 | + { |
|
| 483 | + return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 490 | + * |
|
| 491 | + * @param string $id - html id attribute |
|
| 492 | + * @param string $class - html class attribute |
|
| 493 | + * @return string |
|
| 494 | + */ |
|
| 495 | + public static function trx($id = '', $class = '') |
|
| 496 | + { |
|
| 497 | + return EEH_HTML::_close_tag('tr', $id, $class); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * th - generates an HTML <th> tag and adds any passed attributes |
|
| 504 | + * usage: echo EEH_HTML::th(); |
|
| 505 | + * |
|
| 506 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 507 | + * @param string $id - html id attribute |
|
| 508 | + * @param string $class - html class attribute |
|
| 509 | + * @param string $style - html style attribute for applying inline styles |
|
| 510 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 511 | + * @return string |
|
| 512 | + */ |
|
| 513 | + public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 514 | + { |
|
| 515 | + return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 522 | + * |
|
| 523 | + * @param string $id - html id attribute |
|
| 524 | + * @param string $class - html class attribute |
|
| 525 | + * @return string |
|
| 526 | + */ |
|
| 527 | + public static function thx($id = '', $class = '') |
|
| 528 | + { |
|
| 529 | + return EEH_HTML::_close_tag('th', $id, $class); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * td - generates an HTML <td> tag and adds any passed attributes |
|
| 536 | + * usage: echo EEH_HTML::td(); |
|
| 537 | + * |
|
| 538 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 539 | + * @param string $id - html id attribute |
|
| 540 | + * @param string $class - html class attribute |
|
| 541 | + * @param string $style - html style attribute for applying inline styles |
|
| 542 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 543 | + * @return string |
|
| 544 | + */ |
|
| 545 | + public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 546 | + { |
|
| 547 | + return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
| 554 | + * |
|
| 555 | + * @param string $id - html id attribute |
|
| 556 | + * @param string $class - html class attribute |
|
| 557 | + * @return string |
|
| 558 | + */ |
|
| 559 | + public static function tdx($id = '', $class = '') |
|
| 560 | + { |
|
| 561 | + return EEH_HTML::_close_tag('td', $id, $class); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * no_row - for generating a "hidden" table row, good for embedding tables within tables |
|
| 568 | + * generates a new table row with one td cell that spans however many columns you set |
|
| 569 | + * removes all styles from the tr and td |
|
| 570 | + * |
|
| 571 | + * @param string $content |
|
| 572 | + * @param int $colspan |
|
| 573 | + * @return string |
|
| 574 | + */ |
|
| 575 | + public static function no_row($content = '', $colspan = 2) |
|
| 576 | + { |
|
| 577 | + return EEH_HTML::tr( |
|
| 578 | + EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
| 579 | + '', |
|
| 580 | + '', |
|
| 581 | + 'padding:0; border:none;' |
|
| 582 | + ); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Generates HTML <a href="url">text</a> tags, inserts content, and adds any passed attributes |
|
| 589 | + * usage: echo EEH_HTML::link( 'domain.com', 'this is a link' ); |
|
| 590 | + * |
|
| 591 | + * @access public |
|
| 592 | + * @param string $href URL to link to |
|
| 593 | + * @param string $link_text - the text that will become "hyperlinked" |
|
| 594 | + * @param string $title - html title attribute |
|
| 595 | + * @param string $id - html id attribute |
|
| 596 | + * @param string $class - html class attribute |
|
| 597 | + * @param string $style - html style attribute for applying inline styles |
|
| 598 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 599 | + * @return string |
|
| 600 | + */ |
|
| 601 | + public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 602 | + { |
|
| 603 | + $link_text = ! empty($link_text) ? $link_text : $href; |
|
| 604 | + $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
| 605 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 606 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 607 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 608 | + $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
| 609 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 610 | + return "<a{$attributes}>{$link_text}</a>"; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Generates HTML <button>text</button> tags, inserts content, and adds any passed attributes |
|
| 617 | + * usage: echo EEH_HTML::button( 'this is a button' ); |
|
| 618 | + * |
|
| 619 | + * @param string $btn_text - the text that will become "hyperlinked" |
|
| 620 | + * @param string $class - html class attribute |
|
| 621 | + * @param string $aria_label - aria-label attribute |
|
| 622 | + * @param string $id - html id attribute |
|
| 623 | + * @param string $style - html style attribute for applying inline styles |
|
| 624 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 625 | + * @return string |
|
| 626 | + */ |
|
| 627 | + public static function button( |
|
| 628 | + $btn_text = '', |
|
| 629 | + $class = '', |
|
| 630 | + $aria_label = '', |
|
| 631 | + $id = '', |
|
| 632 | + $style = '', |
|
| 633 | + $other_attributes = '' |
|
| 634 | + ) { |
|
| 635 | + $attributes = ! empty($aria_label) ? ' aria-label="' . $aria_label . '"' : ''; |
|
| 636 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 637 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 638 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 639 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 640 | + return "<button type='button' {$attributes}>{$btn_text}</button>"; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * img - generates an HTML <img> tag and adds any passed attributes |
|
| 647 | + * usage: echo EEH_HTML::img(); |
|
| 648 | + * |
|
| 649 | + * @param string $src - html src attribute ie: the path or URL to the image |
|
| 650 | + * @param string $alt - html alt attribute |
|
| 651 | + * @param string $id - html id attribute |
|
| 652 | + * @param string $class - html class attribute |
|
| 653 | + * @param string $style - html style attribute for applying inline styles |
|
| 654 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 655 | + * @return string |
|
| 656 | + */ |
|
| 657 | + public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 658 | + { |
|
| 659 | + $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
| 660 | + $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
| 661 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 662 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 663 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 664 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 665 | + return '<img' . $attributes . '/>'; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
| 672 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
| 673 | + * |
|
| 674 | + * @access protected |
|
| 675 | + * @param string $tag |
|
| 676 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 677 | + * @param string $id - html id attribute |
|
| 678 | + * @param string $class - html class attribute |
|
| 679 | + * @param string $style - html style attribute for applying inline styles |
|
| 680 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 681 | + * @return string |
|
| 682 | + */ |
|
| 683 | + protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 684 | + { |
|
| 685 | + $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 686 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 687 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 688 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 689 | + return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
| 696 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
| 697 | + * |
|
| 698 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 699 | + * @param string $id - html id attribute |
|
| 700 | + * @param string $class - html class attribute |
|
| 701 | + * @param string $style - html style attribute for applying inline styles |
|
| 702 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 703 | + * @return string |
|
| 704 | + */ |
|
| 705 | + public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 706 | + { |
|
| 707 | + return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
| 714 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
| 715 | + * |
|
| 716 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 717 | + * @param string $id - html id attribute |
|
| 718 | + * @param string $class - html class attribute |
|
| 719 | + * @param string $style - html style attribute for applying inline styles |
|
| 720 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 721 | + * @return string |
|
| 722 | + */ |
|
| 723 | + public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 724 | + { |
|
| 725 | + return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
| 732 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
| 733 | + * |
|
| 734 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
| 735 | + * @param string $id - html id attribute |
|
| 736 | + * @param string $class - html class attribute |
|
| 737 | + * @param string $style - html style attribute for applying inline styles |
|
| 738 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
| 739 | + * @return string |
|
| 740 | + */ |
|
| 741 | + public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
| 742 | + { |
|
| 743 | + return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Generates an html <-- comment --> tag |
|
| 750 | + * usage: echo comment( 'this is a comment' ); |
|
| 751 | + * |
|
| 752 | + * @param string $comment |
|
| 753 | + * @return string |
|
| 754 | + */ |
|
| 755 | + public static function comment($comment = '') |
|
| 756 | + { |
|
| 757 | + return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * br - generates a line break |
|
| 764 | + * |
|
| 765 | + * @param int $nmbr - the number of line breaks to return |
|
| 766 | + * @return string |
|
| 767 | + */ |
|
| 768 | + public static function br($nmbr = 1) |
|
| 769 | + { |
|
| 770 | + return str_repeat('<br />', $nmbr); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * nbsp - generates non-breaking space entities based on number supplied |
|
| 777 | + * |
|
| 778 | + * @param int $nmbr - the number of non-breaking spaces to return |
|
| 779 | + * @return string |
|
| 780 | + */ |
|
| 781 | + public static function nbsp($nmbr = 1) |
|
| 782 | + { |
|
| 783 | + return str_repeat(' ', $nmbr); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * sanitize_id |
|
| 790 | + * |
|
| 791 | + * functionally does the same as the wp_core function sanitize_key except it does NOT use |
|
| 792 | + * strtolower and allows capitals. |
|
| 793 | + * |
|
| 794 | + * @param string $id |
|
| 795 | + * @return string |
|
| 796 | + */ |
|
| 797 | + public static function sanitize_id($id = '') |
|
| 798 | + { |
|
| 799 | + $key = str_replace(' ', '-', trim($id)); |
|
| 800 | + return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * return a newline and tabs ("nl" stands for "new line") |
|
| 807 | + * |
|
| 808 | + * @param int $indent the number of tabs to ADD to the current indent (can be negative or zero) |
|
| 809 | + * @param string $tag |
|
| 810 | + * @return string - newline character plus # of indents passed (can be + or -) |
|
| 811 | + */ |
|
| 812 | + public static function nl($indent = 0, $tag = 'none') |
|
| 813 | + { |
|
| 814 | + $html = "\n"; |
|
| 815 | + EEH_HTML::indent($indent, $tag); |
|
| 816 | + for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
| 817 | + $html .= "\t"; |
|
| 818 | + } |
|
| 819 | + return $html; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * Changes the indents used in EEH_HTML::nl. Often its convenient to change |
|
| 826 | + * the indentation level without actually creating a new line |
|
| 827 | + * |
|
| 828 | + * @param int $indent can be negative to decrease the indentation level |
|
| 829 | + * @param string $tag |
|
| 830 | + */ |
|
| 831 | + public static function indent($indent, $tag = 'none') |
|
| 832 | + { |
|
| 833 | + static $default_indentation = false; |
|
| 834 | + if (! $default_indentation) { |
|
| 835 | + EEH_HTML::_set_default_indentation(); |
|
| 836 | + $default_indentation = true; |
|
| 837 | + } |
|
| 838 | + if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
| 839 | + EEH_HTML::$_indent[ $tag ] = 0; |
|
| 840 | + } |
|
| 841 | + EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
| 842 | + EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * class _set_default_indentation |
|
| 848 | + * |
|
| 849 | + * @access private |
|
| 850 | + */ |
|
| 851 | + private static function _set_default_indentation() |
|
| 852 | + { |
|
| 853 | + // set some initial formatting for table indentation |
|
| 854 | + EEH_HTML::$_indent = array( |
|
| 855 | + 'none' => 0, |
|
| 856 | + 'form' => 0, |
|
| 857 | + 'radio' => 0, |
|
| 858 | + 'checkbox' => 0, |
|
| 859 | + 'select' => 0, |
|
| 860 | + 'option' => 0, |
|
| 861 | + 'optgroup' => 0, |
|
| 862 | + 'table' => 1, |
|
| 863 | + 'thead' => 2, |
|
| 864 | + 'tbody' => 2, |
|
| 865 | + 'tr' => 3, |
|
| 866 | + 'th' => 4, |
|
| 867 | + 'td' => 4, |
|
| 868 | + 'div' => 0, |
|
| 869 | + 'h1' => 0, |
|
| 870 | + 'h2' => 0, |
|
| 871 | + 'h3' => 0, |
|
| 872 | + 'h4' => 0, |
|
| 873 | + 'h5' => 0, |
|
| 874 | + 'h6' => 0, |
|
| 875 | + 'p' => 0, |
|
| 876 | + 'ul' => 0, |
|
| 877 | + 'li' => 1 |
|
| 878 | + ); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * Retrieves the list of tags considered "simple", that are probably safe for |
|
| 885 | + * use in inputs |
|
| 886 | + * @global array $allowedtags |
|
| 887 | + * @return array |
|
| 888 | + */ |
|
| 889 | + public static function get_simple_tags() |
|
| 890 | + { |
|
| 891 | + global $allowedtags; |
|
| 892 | + $tags_we_allow = array_merge_recursive( |
|
| 893 | + $allowedtags, |
|
| 894 | + [ |
|
| 895 | + 'ol' => [], |
|
| 896 | + 'ul' => [], |
|
| 897 | + 'li' => [], |
|
| 898 | + 'br' => [], |
|
| 899 | + 'p' => [], |
|
| 900 | + 'a' => ['target'] |
|
| 901 | + ] |
|
| 902 | + ); |
|
| 903 | + return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow); |
|
| 904 | + } |
|
| 905 | 905 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | public static function instance() |
| 44 | 44 | { |
| 45 | 45 | // check if class object is instantiated, and instantiated properly |
| 46 | - if (! self::$_instance instanceof EEH_HTML) { |
|
| 46 | + if ( ! self::$_instance instanceof EEH_HTML) { |
|
| 47 | 47 | self::$_instance = new EEH_HTML(); |
| 48 | 48 | } |
| 49 | 49 | return self::$_instance; |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | $other_attributes = '', |
| 106 | 106 | $force_close = false |
| 107 | 107 | ) { |
| 108 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 109 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 110 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 111 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 112 | - $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
| 113 | - $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
| 108 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
| 109 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
| 110 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
| 111 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
| 112 | + $html = EEH_HTML::nl(0, $tag).'<'.$tag.$attributes.'>'; |
|
| 113 | + $html .= ! empty($content) ? EEH_HTML::nl(1, $tag).$content : ''; |
|
| 114 | 114 | $indent = ! empty($content) || $force_close ? true : false; |
| 115 | 115 | $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
| 116 | 116 | return $html; |
@@ -133,12 +133,12 @@ discard block |
||
| 133 | 133 | { |
| 134 | 134 | $comment = ''; |
| 135 | 135 | if ($id) { |
| 136 | - $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
| 136 | + $comment = EEH_HTML::comment('close '.$id).EEH_HTML::nl(0, $tag); |
|
| 137 | 137 | } elseif ($class) { |
| 138 | - $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
| 138 | + $comment = EEH_HTML::comment('close '.$class).EEH_HTML::nl(0, $tag); |
|
| 139 | 139 | } |
| 140 | 140 | $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
| 141 | - $html .= '</' . $tag . '>' . $comment; |
|
| 141 | + $html .= '</'.$tag.'>'.$comment; |
|
| 142 | 142 | return $html; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | public static function no_row($content = '', $colspan = 2) |
| 576 | 576 | { |
| 577 | 577 | return EEH_HTML::tr( |
| 578 | - EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
| 578 | + EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="'.$colspan.'"'), |
|
| 579 | 579 | '', |
| 580 | 580 | '', |
| 581 | 581 | 'padding:0; border:none;' |
@@ -601,12 +601,12 @@ discard block |
||
| 601 | 601 | public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
| 602 | 602 | { |
| 603 | 603 | $link_text = ! empty($link_text) ? $link_text : $href; |
| 604 | - $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
| 605 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 606 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 607 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 608 | - $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
| 609 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 604 | + $attributes = ! empty($href) ? ' href="'.$href.'"' : ''; |
|
| 605 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
| 606 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
| 607 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
| 608 | + $attributes .= ! empty($title) ? ' title="'.esc_attr($title).'"' : ''; |
|
| 609 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
| 610 | 610 | return "<a{$attributes}>{$link_text}</a>"; |
| 611 | 611 | } |
| 612 | 612 | |
@@ -632,11 +632,11 @@ discard block |
||
| 632 | 632 | $style = '', |
| 633 | 633 | $other_attributes = '' |
| 634 | 634 | ) { |
| 635 | - $attributes = ! empty($aria_label) ? ' aria-label="' . $aria_label . '"' : ''; |
|
| 636 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 637 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 638 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 639 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 635 | + $attributes = ! empty($aria_label) ? ' aria-label="'.$aria_label.'"' : ''; |
|
| 636 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
| 637 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
| 638 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
| 639 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
| 640 | 640 | return "<button type='button' {$attributes}>{$btn_text}</button>"; |
| 641 | 641 | } |
| 642 | 642 | |
@@ -656,13 +656,13 @@ discard block |
||
| 656 | 656 | */ |
| 657 | 657 | public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
| 658 | 658 | { |
| 659 | - $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
| 660 | - $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
| 661 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 662 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 663 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 664 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 665 | - return '<img' . $attributes . '/>'; |
|
| 659 | + $attributes = ! empty($src) ? ' src="'.esc_url_raw($src).'"' : ''; |
|
| 660 | + $attributes .= ! empty($alt) ? ' alt="'.esc_attr($alt).'"' : ''; |
|
| 661 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
| 662 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
| 663 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
| 664 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
| 665 | + return '<img'.$attributes.'/>'; |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | |
@@ -682,11 +682,11 @@ discard block |
||
| 682 | 682 | */ |
| 683 | 683 | protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
| 684 | 684 | { |
| 685 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
| 686 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
| 687 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
| 688 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
| 689 | - return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
| 685 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
| 686 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
| 687 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
| 688 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
| 689 | + return '<'.$tag.' '.$attributes.'>'.$content.'</'.$tag.'>'; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | */ |
| 755 | 755 | public static function comment($comment = '') |
| 756 | 756 | { |
| 757 | - return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
| 757 | + return ! empty($comment) ? EEH_HTML::nl().'<!-- '.$comment.' -->' : ''; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | { |
| 814 | 814 | $html = "\n"; |
| 815 | 815 | EEH_HTML::indent($indent, $tag); |
| 816 | - for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
| 816 | + for ($x = 0; $x < EEH_HTML::$_indent[$tag]; $x++) { |
|
| 817 | 817 | $html .= "\t"; |
| 818 | 818 | } |
| 819 | 819 | return $html; |
@@ -831,15 +831,15 @@ discard block |
||
| 831 | 831 | public static function indent($indent, $tag = 'none') |
| 832 | 832 | { |
| 833 | 833 | static $default_indentation = false; |
| 834 | - if (! $default_indentation) { |
|
| 834 | + if ( ! $default_indentation) { |
|
| 835 | 835 | EEH_HTML::_set_default_indentation(); |
| 836 | 836 | $default_indentation = true; |
| 837 | 837 | } |
| 838 | - if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
| 839 | - EEH_HTML::$_indent[ $tag ] = 0; |
|
| 838 | + if ( ! isset(EEH_HTML::$_indent[$tag])) { |
|
| 839 | + EEH_HTML::$_indent[$tag] = 0; |
|
| 840 | 840 | } |
| 841 | - EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
| 842 | - EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
| 841 | + EEH_HTML::$_indent[$tag] += (int) $indent; |
|
| 842 | + EEH_HTML::$_indent[$tag] = EEH_HTML::$_indent[$tag] >= 0 ? EEH_HTML::$_indent[$tag] : 0; |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.31.rc.006'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.31.rc.006'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
| 4 | 4 | |
| 5 | 5 | if (! class_exists('WP_List_Table')) { |
| 6 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 6 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | |
@@ -21,893 +21,893 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class EE_Admin_List_Table extends WP_List_Table |
| 23 | 23 | { |
| 24 | - const ACTION_COPY = 'duplicate'; |
|
| 25 | - |
|
| 26 | - const ACTION_DELETE = 'delete'; |
|
| 27 | - |
|
| 28 | - const ACTION_EDIT = 'edit'; |
|
| 29 | - |
|
| 30 | - const ACTION_RESTORE = 'restore'; |
|
| 31 | - |
|
| 32 | - const ACTION_TRASH = 'trash'; |
|
| 33 | - |
|
| 34 | - protected static $actions = [ |
|
| 35 | - self::ACTION_COPY, |
|
| 36 | - self::ACTION_DELETE, |
|
| 37 | - self::ACTION_EDIT, |
|
| 38 | - self::ACTION_RESTORE, |
|
| 39 | - self::ACTION_TRASH, |
|
| 40 | - ]; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * holds the data that will be processed for the table |
|
| 44 | - * |
|
| 45 | - * @var array $_data |
|
| 46 | - */ |
|
| 47 | - protected $_data; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This holds the value of all the data available for the given view (for all pages). |
|
| 52 | - * |
|
| 53 | - * @var int $_all_data_count |
|
| 54 | - */ |
|
| 55 | - protected $_all_data_count; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Will contain the count of trashed items for the view label. |
|
| 60 | - * |
|
| 61 | - * @var int $_trashed_count |
|
| 62 | - */ |
|
| 63 | - protected $_trashed_count; |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * This is what will be referenced as the slug for the current screen |
|
| 68 | - * |
|
| 69 | - * @var string $_screen |
|
| 70 | - */ |
|
| 71 | - protected $_screen; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * this is the EE_Admin_Page object |
|
| 76 | - * |
|
| 77 | - * @var EE_Admin_Page $_admin_page |
|
| 78 | - */ |
|
| 79 | - protected $_admin_page; |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The current view |
|
| 84 | - * |
|
| 85 | - * @var string $_view |
|
| 86 | - */ |
|
| 87 | - protected $_view; |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * array of possible views for this table |
|
| 92 | - * |
|
| 93 | - * @var array $_views |
|
| 94 | - */ |
|
| 95 | - protected $_views; |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * An array of key => value pairs containing information about the current table |
|
| 100 | - * array( |
|
| 101 | - * 'plural' => 'plural label', |
|
| 102 | - * 'singular' => 'singular label', |
|
| 103 | - * 'ajax' => false, //whether to use ajax or not |
|
| 104 | - * 'screen' => null, //string used to reference what screen this is |
|
| 105 | - * (WP_List_table converts to screen object) |
|
| 106 | - * ) |
|
| 107 | - * |
|
| 108 | - * @var array $_wp_list_args |
|
| 109 | - */ |
|
| 110 | - protected $_wp_list_args; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * an array of column names |
|
| 114 | - * array( |
|
| 115 | - * 'internal-name' => 'Title' |
|
| 116 | - * ) |
|
| 117 | - * |
|
| 118 | - * @var array $_columns |
|
| 119 | - */ |
|
| 120 | - protected $_columns; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * An array of sortable columns |
|
| 124 | - * array( |
|
| 125 | - * 'internal-name' => 'orderby' //or |
|
| 126 | - * 'internal-name' => array( 'orderby', true ) |
|
| 127 | - * ) |
|
| 128 | - * |
|
| 129 | - * @var array $_sortable_columns |
|
| 130 | - */ |
|
| 131 | - protected $_sortable_columns; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * callback method used to perform AJAX row reordering |
|
| 135 | - * |
|
| 136 | - * @var string $_ajax_sorting_callback |
|
| 137 | - */ |
|
| 138 | - protected $_ajax_sorting_callback; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * An array of hidden columns (if needed) |
|
| 142 | - * array('internal-name', 'internal-name') |
|
| 143 | - * |
|
| 144 | - * @var array $_hidden_columns |
|
| 145 | - */ |
|
| 146 | - protected $_hidden_columns; |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * holds the per_page value |
|
| 150 | - * |
|
| 151 | - * @var int $_per_page |
|
| 152 | - */ |
|
| 153 | - protected $_per_page; |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * holds what page number is currently being viewed |
|
| 157 | - * |
|
| 158 | - * @var int $_current_page |
|
| 159 | - */ |
|
| 160 | - protected $_current_page; |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * the reference string for the nonce_action |
|
| 164 | - * |
|
| 165 | - * @var string $_nonce_action_ref |
|
| 166 | - */ |
|
| 167 | - protected $_nonce_action_ref; |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * property to hold incoming request data (as set by the admin_page_core) |
|
| 171 | - * |
|
| 172 | - * @var array $_req_data |
|
| 173 | - */ |
|
| 174 | - protected $_req_data; |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * yes / no array for admin form fields |
|
| 179 | - * |
|
| 180 | - * @var array $_yes_no |
|
| 181 | - */ |
|
| 182 | - protected $_yes_no = []; |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Array describing buttons that should appear at the bottom of the page |
|
| 186 | - * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 187 | - * and the values are another array with the following keys |
|
| 188 | - * array( |
|
| 189 | - * 'route' => 'page_route', |
|
| 190 | - * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 191 | - * ) |
|
| 192 | - * |
|
| 193 | - * @var array $_bottom_buttons |
|
| 194 | - */ |
|
| 195 | - protected $_bottom_buttons = []; |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Used to indicate what should be the primary column for the list table. |
|
| 200 | - * If not present then falls back to what WP calculates |
|
| 201 | - * as the primary column. |
|
| 202 | - * |
|
| 203 | - * @type string $_primary_column |
|
| 204 | - */ |
|
| 205 | - protected $_primary_column = ''; |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Used to indicate whether the table has a checkbox column or not. |
|
| 210 | - * |
|
| 211 | - * @type bool $_has_checkbox_column |
|
| 212 | - */ |
|
| 213 | - protected $_has_checkbox_column = false; |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 218 | - */ |
|
| 219 | - public function __construct(EE_Admin_Page $admin_page) |
|
| 220 | - { |
|
| 221 | - $this->_admin_page = $admin_page; |
|
| 222 | - $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 223 | - $this->_view = $this->_admin_page->get_view(); |
|
| 224 | - $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
| 225 | - $this->_current_page = $this->get_pagenum(); |
|
| 226 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 227 | - $this->_yes_no = [ |
|
| 228 | - esc_html__('No', 'event_espresso'), |
|
| 229 | - esc_html__('Yes', 'event_espresso') |
|
| 230 | - ]; |
|
| 231 | - |
|
| 232 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 233 | - |
|
| 234 | - $this->_setup_data(); |
|
| 235 | - $this->_add_view_counts(); |
|
| 236 | - |
|
| 237 | - $this->_nonce_action_ref = $this->_view; |
|
| 238 | - |
|
| 239 | - $this->_set_properties(); |
|
| 240 | - |
|
| 241 | - // set primary column |
|
| 242 | - add_filter('list_table_primary_column', [$this, 'set_primary_column']); |
|
| 243 | - |
|
| 244 | - // set parent defaults |
|
| 245 | - parent::__construct($this->_wp_list_args); |
|
| 246 | - |
|
| 247 | - $this->prepare_items(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * _setup_data |
|
| 253 | - * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 254 | - * |
|
| 255 | - * @return void |
|
| 256 | - * @uses $this->_admin_page |
|
| 257 | - */ |
|
| 258 | - abstract protected function _setup_data(); |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 263 | - * properties set: |
|
| 264 | - * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 265 | - * _columns = set the columns in an array. |
|
| 266 | - * _sortable_columns = columns that are sortable (array). |
|
| 267 | - * _hidden_columns = columns that are hidden (array) |
|
| 268 | - * _default_orderby = the default orderby for sorting. |
|
| 269 | - * |
|
| 270 | - * @abstract |
|
| 271 | - * @access protected |
|
| 272 | - * @return void |
|
| 273 | - */ |
|
| 274 | - abstract protected function _set_properties(); |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * _get_table_filters |
|
| 279 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 280 | - * gets shown in the table. |
|
| 281 | - * |
|
| 282 | - * @abstract |
|
| 283 | - * @access protected |
|
| 284 | - * @return string |
|
| 285 | - */ |
|
| 286 | - abstract protected function _get_table_filters(); |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 291 | - * counts of the views is accurate. |
|
| 292 | - * |
|
| 293 | - * @abstract |
|
| 294 | - * @access protected |
|
| 295 | - * @return void |
|
| 296 | - */ |
|
| 297 | - abstract protected function _add_view_counts(); |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * _get_hidden_fields |
|
| 302 | - * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 303 | - * |
|
| 304 | - * @return string |
|
| 305 | - */ |
|
| 306 | - protected function _get_hidden_fields() |
|
| 307 | - { |
|
| 308 | - $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 309 | - $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 310 | - // if action is STILL empty, then we set it to default |
|
| 311 | - $action = empty($action) ? 'default' : $action; |
|
| 312 | - $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 313 | - $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 314 | - $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 315 | - |
|
| 316 | - $bulk_actions = $this->_get_bulk_actions(); |
|
| 317 | - foreach ($bulk_actions as $bulk_action => $label) { |
|
| 318 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 319 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - return $field; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * _set_column_info |
|
| 328 | - * we're using this to set the column headers property. |
|
| 329 | - * |
|
| 330 | - * @access protected |
|
| 331 | - * @return void |
|
| 332 | - */ |
|
| 333 | - protected function _set_column_info() |
|
| 334 | - { |
|
| 335 | - $columns = $this->get_columns(); |
|
| 336 | - $hidden = $this->get_hidden_columns(); |
|
| 337 | - $_sortable = $this->get_sortable_columns(); |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 341 | - * Note that $this->screen->id is in the format |
|
| 342 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 343 | - * table it is: event-espresso_page_espresso_messages. |
|
| 344 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 345 | - * hook prefix ("event-espresso") will be different. |
|
| 346 | - * |
|
| 347 | - * @var array |
|
| 348 | - */ |
|
| 349 | - $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
| 350 | - |
|
| 351 | - $sortable = []; |
|
| 352 | - foreach ($_sortable as $id => $data) { |
|
| 353 | - if (empty($data)) { |
|
| 354 | - continue; |
|
| 355 | - } |
|
| 356 | - // fix for offset errors with WP_List_Table default get_columninfo() |
|
| 357 | - if (is_array($data)) { |
|
| 358 | - $_data[0] = key($data); |
|
| 359 | - $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 360 | - } else { |
|
| 361 | - $_data[0] = $data; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $data = (array) $data; |
|
| 365 | - |
|
| 366 | - if (! isset($data[1])) { |
|
| 367 | - $_data[1] = false; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $sortable[ $id ] = $_data; |
|
| 371 | - } |
|
| 372 | - $primary = $this->get_primary_column_name(); |
|
| 373 | - $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 379 | - * |
|
| 380 | - * @return string |
|
| 381 | - */ |
|
| 382 | - protected function get_primary_column_name() |
|
| 383 | - { |
|
| 384 | - foreach (class_parents($this) as $parent) { |
|
| 385 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 386 | - return parent::get_primary_column_name(); |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - return $this->_primary_column; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 395 | - * |
|
| 396 | - * @param EE_Base_Class $item |
|
| 397 | - * @param string $column_name |
|
| 398 | - * @param string $primary |
|
| 399 | - * @return string |
|
| 400 | - */ |
|
| 401 | - protected function handle_row_actions($item, $column_name, $primary) |
|
| 402 | - { |
|
| 403 | - foreach (class_parents($this) as $parent) { |
|
| 404 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 405 | - return parent::handle_row_actions($item, $column_name, $primary); |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - return ''; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * _get_bulk_actions |
|
| 414 | - * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 415 | - * |
|
| 416 | - * @access protected |
|
| 417 | - * @return array bulk_actions |
|
| 418 | - */ |
|
| 419 | - protected function _get_bulk_actions() |
|
| 420 | - { |
|
| 421 | - $actions = []; |
|
| 422 | - // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
| 423 | - // formatted array for the wp_list_table(); |
|
| 424 | - foreach ($this->_views as $view => $args) { |
|
| 425 | - if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 426 | - // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
| 427 | - // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 428 | - foreach ($args['bulk_action'] as $route => $label) { |
|
| 429 | - if ($this->_admin_page->check_user_access($route, true)) { |
|
| 430 | - $actions[ $route ] = $label; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - return $actions; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Generate the table navigation above or below the table. |
|
| 441 | - * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
| 442 | - * |
|
| 443 | - * @throws EE_Error |
|
| 444 | - * @since 4.9.44.rc.001 |
|
| 445 | - */ |
|
| 446 | - public function display_tablenav($which) |
|
| 447 | - { |
|
| 448 | - if ('top' === $which) { |
|
| 449 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 450 | - } |
|
| 451 | - ?> |
|
| 24 | + const ACTION_COPY = 'duplicate'; |
|
| 25 | + |
|
| 26 | + const ACTION_DELETE = 'delete'; |
|
| 27 | + |
|
| 28 | + const ACTION_EDIT = 'edit'; |
|
| 29 | + |
|
| 30 | + const ACTION_RESTORE = 'restore'; |
|
| 31 | + |
|
| 32 | + const ACTION_TRASH = 'trash'; |
|
| 33 | + |
|
| 34 | + protected static $actions = [ |
|
| 35 | + self::ACTION_COPY, |
|
| 36 | + self::ACTION_DELETE, |
|
| 37 | + self::ACTION_EDIT, |
|
| 38 | + self::ACTION_RESTORE, |
|
| 39 | + self::ACTION_TRASH, |
|
| 40 | + ]; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * holds the data that will be processed for the table |
|
| 44 | + * |
|
| 45 | + * @var array $_data |
|
| 46 | + */ |
|
| 47 | + protected $_data; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This holds the value of all the data available for the given view (for all pages). |
|
| 52 | + * |
|
| 53 | + * @var int $_all_data_count |
|
| 54 | + */ |
|
| 55 | + protected $_all_data_count; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Will contain the count of trashed items for the view label. |
|
| 60 | + * |
|
| 61 | + * @var int $_trashed_count |
|
| 62 | + */ |
|
| 63 | + protected $_trashed_count; |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * This is what will be referenced as the slug for the current screen |
|
| 68 | + * |
|
| 69 | + * @var string $_screen |
|
| 70 | + */ |
|
| 71 | + protected $_screen; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * this is the EE_Admin_Page object |
|
| 76 | + * |
|
| 77 | + * @var EE_Admin_Page $_admin_page |
|
| 78 | + */ |
|
| 79 | + protected $_admin_page; |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The current view |
|
| 84 | + * |
|
| 85 | + * @var string $_view |
|
| 86 | + */ |
|
| 87 | + protected $_view; |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * array of possible views for this table |
|
| 92 | + * |
|
| 93 | + * @var array $_views |
|
| 94 | + */ |
|
| 95 | + protected $_views; |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * An array of key => value pairs containing information about the current table |
|
| 100 | + * array( |
|
| 101 | + * 'plural' => 'plural label', |
|
| 102 | + * 'singular' => 'singular label', |
|
| 103 | + * 'ajax' => false, //whether to use ajax or not |
|
| 104 | + * 'screen' => null, //string used to reference what screen this is |
|
| 105 | + * (WP_List_table converts to screen object) |
|
| 106 | + * ) |
|
| 107 | + * |
|
| 108 | + * @var array $_wp_list_args |
|
| 109 | + */ |
|
| 110 | + protected $_wp_list_args; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * an array of column names |
|
| 114 | + * array( |
|
| 115 | + * 'internal-name' => 'Title' |
|
| 116 | + * ) |
|
| 117 | + * |
|
| 118 | + * @var array $_columns |
|
| 119 | + */ |
|
| 120 | + protected $_columns; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * An array of sortable columns |
|
| 124 | + * array( |
|
| 125 | + * 'internal-name' => 'orderby' //or |
|
| 126 | + * 'internal-name' => array( 'orderby', true ) |
|
| 127 | + * ) |
|
| 128 | + * |
|
| 129 | + * @var array $_sortable_columns |
|
| 130 | + */ |
|
| 131 | + protected $_sortable_columns; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * callback method used to perform AJAX row reordering |
|
| 135 | + * |
|
| 136 | + * @var string $_ajax_sorting_callback |
|
| 137 | + */ |
|
| 138 | + protected $_ajax_sorting_callback; |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * An array of hidden columns (if needed) |
|
| 142 | + * array('internal-name', 'internal-name') |
|
| 143 | + * |
|
| 144 | + * @var array $_hidden_columns |
|
| 145 | + */ |
|
| 146 | + protected $_hidden_columns; |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * holds the per_page value |
|
| 150 | + * |
|
| 151 | + * @var int $_per_page |
|
| 152 | + */ |
|
| 153 | + protected $_per_page; |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * holds what page number is currently being viewed |
|
| 157 | + * |
|
| 158 | + * @var int $_current_page |
|
| 159 | + */ |
|
| 160 | + protected $_current_page; |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * the reference string for the nonce_action |
|
| 164 | + * |
|
| 165 | + * @var string $_nonce_action_ref |
|
| 166 | + */ |
|
| 167 | + protected $_nonce_action_ref; |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * property to hold incoming request data (as set by the admin_page_core) |
|
| 171 | + * |
|
| 172 | + * @var array $_req_data |
|
| 173 | + */ |
|
| 174 | + protected $_req_data; |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * yes / no array for admin form fields |
|
| 179 | + * |
|
| 180 | + * @var array $_yes_no |
|
| 181 | + */ |
|
| 182 | + protected $_yes_no = []; |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Array describing buttons that should appear at the bottom of the page |
|
| 186 | + * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
| 187 | + * and the values are another array with the following keys |
|
| 188 | + * array( |
|
| 189 | + * 'route' => 'page_route', |
|
| 190 | + * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
| 191 | + * ) |
|
| 192 | + * |
|
| 193 | + * @var array $_bottom_buttons |
|
| 194 | + */ |
|
| 195 | + protected $_bottom_buttons = []; |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Used to indicate what should be the primary column for the list table. |
|
| 200 | + * If not present then falls back to what WP calculates |
|
| 201 | + * as the primary column. |
|
| 202 | + * |
|
| 203 | + * @type string $_primary_column |
|
| 204 | + */ |
|
| 205 | + protected $_primary_column = ''; |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Used to indicate whether the table has a checkbox column or not. |
|
| 210 | + * |
|
| 211 | + * @type bool $_has_checkbox_column |
|
| 212 | + */ |
|
| 213 | + protected $_has_checkbox_column = false; |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
| 218 | + */ |
|
| 219 | + public function __construct(EE_Admin_Page $admin_page) |
|
| 220 | + { |
|
| 221 | + $this->_admin_page = $admin_page; |
|
| 222 | + $this->_req_data = $this->_admin_page->get_request_data(); |
|
| 223 | + $this->_view = $this->_admin_page->get_view(); |
|
| 224 | + $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
| 225 | + $this->_current_page = $this->get_pagenum(); |
|
| 226 | + $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
| 227 | + $this->_yes_no = [ |
|
| 228 | + esc_html__('No', 'event_espresso'), |
|
| 229 | + esc_html__('Yes', 'event_espresso') |
|
| 230 | + ]; |
|
| 231 | + |
|
| 232 | + $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page'); |
|
| 233 | + |
|
| 234 | + $this->_setup_data(); |
|
| 235 | + $this->_add_view_counts(); |
|
| 236 | + |
|
| 237 | + $this->_nonce_action_ref = $this->_view; |
|
| 238 | + |
|
| 239 | + $this->_set_properties(); |
|
| 240 | + |
|
| 241 | + // set primary column |
|
| 242 | + add_filter('list_table_primary_column', [$this, 'set_primary_column']); |
|
| 243 | + |
|
| 244 | + // set parent defaults |
|
| 245 | + parent::__construct($this->_wp_list_args); |
|
| 246 | + |
|
| 247 | + $this->prepare_items(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * _setup_data |
|
| 253 | + * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
| 254 | + * |
|
| 255 | + * @return void |
|
| 256 | + * @uses $this->_admin_page |
|
| 257 | + */ |
|
| 258 | + abstract protected function _setup_data(); |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * set the properties that this class needs to be able to execute wp_list_table properly |
|
| 263 | + * properties set: |
|
| 264 | + * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
| 265 | + * _columns = set the columns in an array. |
|
| 266 | + * _sortable_columns = columns that are sortable (array). |
|
| 267 | + * _hidden_columns = columns that are hidden (array) |
|
| 268 | + * _default_orderby = the default orderby for sorting. |
|
| 269 | + * |
|
| 270 | + * @abstract |
|
| 271 | + * @access protected |
|
| 272 | + * @return void |
|
| 273 | + */ |
|
| 274 | + abstract protected function _set_properties(); |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * _get_table_filters |
|
| 279 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
| 280 | + * gets shown in the table. |
|
| 281 | + * |
|
| 282 | + * @abstract |
|
| 283 | + * @access protected |
|
| 284 | + * @return string |
|
| 285 | + */ |
|
| 286 | + abstract protected function _get_table_filters(); |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
| 291 | + * counts of the views is accurate. |
|
| 292 | + * |
|
| 293 | + * @abstract |
|
| 294 | + * @access protected |
|
| 295 | + * @return void |
|
| 296 | + */ |
|
| 297 | + abstract protected function _add_view_counts(); |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * _get_hidden_fields |
|
| 302 | + * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
| 303 | + * |
|
| 304 | + * @return string |
|
| 305 | + */ |
|
| 306 | + protected function _get_hidden_fields() |
|
| 307 | + { |
|
| 308 | + $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
| 309 | + $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
| 310 | + // if action is STILL empty, then we set it to default |
|
| 311 | + $action = empty($action) ? 'default' : $action; |
|
| 312 | + $field = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n"; |
|
| 313 | + $field .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n"; |
|
| 314 | + $field .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n"; |
|
| 315 | + |
|
| 316 | + $bulk_actions = $this->_get_bulk_actions(); |
|
| 317 | + foreach ($bulk_actions as $bulk_action => $label) { |
|
| 318 | + $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
| 319 | + . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + return $field; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * _set_column_info |
|
| 328 | + * we're using this to set the column headers property. |
|
| 329 | + * |
|
| 330 | + * @access protected |
|
| 331 | + * @return void |
|
| 332 | + */ |
|
| 333 | + protected function _set_column_info() |
|
| 334 | + { |
|
| 335 | + $columns = $this->get_columns(); |
|
| 336 | + $hidden = $this->get_hidden_columns(); |
|
| 337 | + $_sortable = $this->get_sortable_columns(); |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Dynamic hook allowing for adding sortable columns in this list table. |
|
| 341 | + * Note that $this->screen->id is in the format |
|
| 342 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 343 | + * table it is: event-espresso_page_espresso_messages. |
|
| 344 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 345 | + * hook prefix ("event-espresso") will be different. |
|
| 346 | + * |
|
| 347 | + * @var array |
|
| 348 | + */ |
|
| 349 | + $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
| 350 | + |
|
| 351 | + $sortable = []; |
|
| 352 | + foreach ($_sortable as $id => $data) { |
|
| 353 | + if (empty($data)) { |
|
| 354 | + continue; |
|
| 355 | + } |
|
| 356 | + // fix for offset errors with WP_List_Table default get_columninfo() |
|
| 357 | + if (is_array($data)) { |
|
| 358 | + $_data[0] = key($data); |
|
| 359 | + $_data[1] = isset($data[1]) ? $data[1] : false; |
|
| 360 | + } else { |
|
| 361 | + $_data[0] = $data; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $data = (array) $data; |
|
| 365 | + |
|
| 366 | + if (! isset($data[1])) { |
|
| 367 | + $_data[1] = false; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $sortable[ $id ] = $_data; |
|
| 371 | + } |
|
| 372 | + $primary = $this->get_primary_column_name(); |
|
| 373 | + $this->_column_headers = [$columns, $hidden, $sortable, $primary]; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 379 | + * |
|
| 380 | + * @return string |
|
| 381 | + */ |
|
| 382 | + protected function get_primary_column_name() |
|
| 383 | + { |
|
| 384 | + foreach (class_parents($this) as $parent) { |
|
| 385 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
| 386 | + return parent::get_primary_column_name(); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + return $this->_primary_column; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
| 395 | + * |
|
| 396 | + * @param EE_Base_Class $item |
|
| 397 | + * @param string $column_name |
|
| 398 | + * @param string $primary |
|
| 399 | + * @return string |
|
| 400 | + */ |
|
| 401 | + protected function handle_row_actions($item, $column_name, $primary) |
|
| 402 | + { |
|
| 403 | + foreach (class_parents($this) as $parent) { |
|
| 404 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
| 405 | + return parent::handle_row_actions($item, $column_name, $primary); |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + return ''; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * _get_bulk_actions |
|
| 414 | + * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
| 415 | + * |
|
| 416 | + * @access protected |
|
| 417 | + * @return array bulk_actions |
|
| 418 | + */ |
|
| 419 | + protected function _get_bulk_actions() |
|
| 420 | + { |
|
| 421 | + $actions = []; |
|
| 422 | + // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
| 423 | + // formatted array for the wp_list_table(); |
|
| 424 | + foreach ($this->_views as $view => $args) { |
|
| 425 | + if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
| 426 | + // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
| 427 | + // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
| 428 | + foreach ($args['bulk_action'] as $route => $label) { |
|
| 429 | + if ($this->_admin_page->check_user_access($route, true)) { |
|
| 430 | + $actions[ $route ] = $label; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + return $actions; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Generate the table navigation above or below the table. |
|
| 441 | + * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
| 442 | + * |
|
| 443 | + * @throws EE_Error |
|
| 444 | + * @since 4.9.44.rc.001 |
|
| 445 | + */ |
|
| 446 | + public function display_tablenav($which) |
|
| 447 | + { |
|
| 448 | + if ('top' === $which) { |
|
| 449 | + wp_nonce_field('bulk-' . $this->_args['plural']); |
|
| 450 | + } |
|
| 451 | + ?> |
|
| 452 | 452 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
| 453 | 453 | <?php if ($this->_get_bulk_actions()) { ?> |
| 454 | 454 | <div class="alignleft actions bulkactions"> |
| 455 | 455 | <?php $this->bulk_actions(); ?> |
| 456 | 456 | </div> |
| 457 | 457 | <?php } |
| 458 | - $this->extra_tablenav($which); |
|
| 459 | - $this->pagination($which); |
|
| 460 | - ?> |
|
| 458 | + $this->extra_tablenav($which); |
|
| 459 | + $this->pagination($which); |
|
| 460 | + ?> |
|
| 461 | 461 | |
| 462 | 462 | <br class="clear" /> |
| 463 | 463 | </div> |
| 464 | 464 | <?php |
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * _filters |
|
| 470 | - * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 471 | - * button. |
|
| 472 | - * |
|
| 473 | - * @access private |
|
| 474 | - * @return void echos html showing filters |
|
| 475 | - */ |
|
| 476 | - private function _filters() |
|
| 477 | - { |
|
| 478 | - $classname = get_class($this); |
|
| 479 | - $filters = apply_filters( |
|
| 480 | - "FHEE__{$classname}__filters", |
|
| 481 | - (array) $this->_get_table_filters(), |
|
| 482 | - $this, |
|
| 483 | - $this->_screen |
|
| 484 | - ); |
|
| 485 | - |
|
| 486 | - if (empty($filters)) { |
|
| 487 | - return; |
|
| 488 | - } |
|
| 489 | - foreach ($filters as $filter) { |
|
| 490 | - echo wp_kses($filter, AllowedTags::getWithFormTags()); |
|
| 491 | - } |
|
| 492 | - // add filter button at end |
|
| 493 | - echo '<input type="submit" class="ee-list-table-filter-submit button button--secondary" value="' |
|
| 494 | - . esc_html__('Filter', 'event_espresso') |
|
| 495 | - . '" id="post-query-submit" />'; |
|
| 496 | - echo '<input type="hidden" id="ee-list-table-use-filters" name="use_filters" value="no"/>'; |
|
| 497 | - |
|
| 498 | - // add reset filters button at end |
|
| 499 | - echo '<a class="button button--secondary" href="' |
|
| 500 | - . esc_url_raw($this->_admin_page->get_current_page_view_url()) |
|
| 501 | - . '" style="display:inline-block">' |
|
| 502 | - . esc_html__('Reset Filters', 'event_espresso') |
|
| 503 | - . '</a>'; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Callback for 'list_table_primary_column' WordPress filter |
|
| 509 | - * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 510 | - * column when class is instantiated. |
|
| 511 | - * |
|
| 512 | - * @param string $column_name |
|
| 513 | - * @return string |
|
| 514 | - * @see WP_List_Table::get_primary_column_name |
|
| 515 | - */ |
|
| 516 | - public function set_primary_column($column_name) |
|
| 517 | - { |
|
| 518 | - return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * |
|
| 524 | - */ |
|
| 525 | - public function prepare_items() |
|
| 526 | - { |
|
| 527 | - |
|
| 528 | - $this->_set_column_info(); |
|
| 529 | - // $this->_column_headers = $this->get_column_info(); |
|
| 530 | - $total_items = $this->_all_data_count; |
|
| 531 | - $this->process_bulk_action(); |
|
| 532 | - |
|
| 533 | - $this->items = $this->_data; |
|
| 534 | - $this->set_pagination_args( |
|
| 535 | - [ |
|
| 536 | - 'total_items' => $total_items, |
|
| 537 | - 'per_page' => $this->_per_page, |
|
| 538 | - 'total_pages' => ceil($total_items / $this->_per_page), |
|
| 539 | - ] |
|
| 540 | - ); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * @param object|array $item |
|
| 546 | - * @return string html content for the column |
|
| 547 | - */ |
|
| 548 | - protected function column_cb($item) |
|
| 549 | - { |
|
| 550 | - return ''; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * This column is the default for when there is no defined column method for a registered column. |
|
| 556 | - * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 557 | - * |
|
| 558 | - * @param EE_Base_Class $item |
|
| 559 | - * @param string $column_name The column being called. |
|
| 560 | - * @return string html content for the column |
|
| 561 | - */ |
|
| 562 | - public function column_default($item, $column_name) |
|
| 563 | - { |
|
| 564 | - /** |
|
| 565 | - * Dynamic hook allowing for adding additional column content in this list table. |
|
| 566 | - * Note that $this->screen->id is in the format |
|
| 567 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 568 | - * table it is: event-espresso_page_espresso_messages. |
|
| 569 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 570 | - * hook prefix ("event-espresso") will be different. |
|
| 571 | - */ |
|
| 572 | - ob_start(); |
|
| 573 | - do_action( |
|
| 574 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 575 | - $item, |
|
| 576 | - $this->_screen |
|
| 577 | - ); |
|
| 578 | - return ob_get_clean(); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * Get a list of columns. The format is: |
|
| 584 | - * 'internal-name' => 'Title' |
|
| 585 | - * |
|
| 586 | - * @return array |
|
| 587 | - * @since 3.1.0 |
|
| 588 | - * @access public |
|
| 589 | - * @abstract |
|
| 590 | - */ |
|
| 591 | - public function get_columns() |
|
| 592 | - { |
|
| 593 | - /** |
|
| 594 | - * Dynamic hook allowing for adding additional columns in this list table. |
|
| 595 | - * Note that $this->screen->id is in the format |
|
| 596 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 597 | - * table it is: event-espresso_page_espresso_messages. |
|
| 598 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 599 | - * hook prefix ("event-espresso") will be different. |
|
| 600 | - * |
|
| 601 | - * @var array |
|
| 602 | - */ |
|
| 603 | - return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Get an associative array ( id => link ) with the list |
|
| 609 | - * of views available on this table. |
|
| 610 | - * |
|
| 611 | - * @return array |
|
| 612 | - * @since 3.1.0 |
|
| 613 | - * @access protected |
|
| 614 | - */ |
|
| 615 | - public function get_views() |
|
| 616 | - { |
|
| 617 | - return $this->_views; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Generate the views html. |
|
| 623 | - */ |
|
| 624 | - public function display_views() |
|
| 625 | - { |
|
| 626 | - $views = $this->get_views(); |
|
| 627 | - $assembled_views = []; |
|
| 628 | - |
|
| 629 | - if (empty($views)) { |
|
| 630 | - return; |
|
| 631 | - } |
|
| 632 | - echo "<ul class='subsubsub'>\n"; |
|
| 633 | - foreach ($views as $view) { |
|
| 634 | - $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 635 | - if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 636 | - $filter = "<li"; |
|
| 637 | - $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 638 | - $filter .= ">"; |
|
| 639 | - $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 640 | - $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 641 | - $filter .= '</li>'; |
|
| 642 | - $assembled_views[ $view['slug'] ] = $filter; |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - echo ! empty($assembled_views) |
|
| 647 | - ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views) |
|
| 648 | - : ''; |
|
| 649 | - echo "</ul>"; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Generates content for a single row of the table |
|
| 655 | - * |
|
| 656 | - * @param EE_Base_Class $item The current item |
|
| 657 | - * @since 4.1 |
|
| 658 | - * @access public |
|
| 659 | - */ |
|
| 660 | - public function single_row($item) |
|
| 661 | - { |
|
| 662 | - $row_class = $this->_get_row_class($item); |
|
| 663 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 664 | - $this->single_row_columns($item); // already escaped |
|
| 665 | - echo '</tr>'; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * This simply sets up the row class for the table rows. |
|
| 671 | - * Allows for easier overriding of child methods for setting up sorting. |
|
| 672 | - * |
|
| 673 | - * @param EE_Base_Class $item the current item |
|
| 674 | - * @return string |
|
| 675 | - */ |
|
| 676 | - protected function _get_row_class($item) |
|
| 677 | - { |
|
| 678 | - static $row_class = ''; |
|
| 679 | - $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 680 | - |
|
| 681 | - $new_row_class = $row_class; |
|
| 682 | - |
|
| 683 | - if (! empty($this->_ajax_sorting_callback)) { |
|
| 684 | - $new_row_class .= ' rowsortable'; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - return $new_row_class; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * @return array |
|
| 693 | - */ |
|
| 694 | - public function get_sortable_columns() |
|
| 695 | - { |
|
| 696 | - return (array) $this->_sortable_columns; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - public function get_ajax_sorting_callback() |
|
| 704 | - { |
|
| 705 | - return $this->_ajax_sorting_callback; |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * @return array |
|
| 711 | - */ |
|
| 712 | - public function get_hidden_columns() |
|
| 713 | - { |
|
| 714 | - $user_id = get_current_user_id(); |
|
| 715 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 716 | - if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 717 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 718 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 719 | - } |
|
| 720 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 721 | - return (array) get_user_option($ref, $user_id); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * Generates the columns for a single row of the table. |
|
| 727 | - * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 728 | - * column. |
|
| 729 | - * |
|
| 730 | - * @param EE_Base_Class $item The current item |
|
| 731 | - * @since 3.1.0 |
|
| 732 | - */ |
|
| 733 | - public function single_row_columns($item) |
|
| 734 | - { |
|
| 735 | - [$columns, $hidden, $sortable, $primary] = $this->get_column_info(); |
|
| 736 | - |
|
| 737 | - foreach ($columns as $column_name => $column_display_name) { |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
| 741 | - * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 742 | - */ |
|
| 743 | - $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 744 | - |
|
| 745 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 746 | - if ($primary === $column_name) { |
|
| 747 | - $classes .= ' has-row-actions column-primary'; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 751 | - |
|
| 752 | - $class = 'class="' . esc_attr($classes) . '"'; |
|
| 753 | - |
|
| 754 | - $attributes = "{$class}{$data}"; |
|
| 755 | - |
|
| 756 | - if ($column_name === 'cb') { |
|
| 757 | - echo '<th scope="row" class="check-column">'; |
|
| 758 | - echo apply_filters( |
|
| 759 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 760 | - $this->column_cb($item), // already escaped |
|
| 761 | - $item, |
|
| 762 | - $this |
|
| 763 | - ); |
|
| 764 | - echo '</th>'; |
|
| 765 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 766 | - echo "<td $attributes>"; // already escaped |
|
| 767 | - echo apply_filters( |
|
| 768 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 769 | - call_user_func([$this, 'column_' . $column_name], $item), |
|
| 770 | - $item, |
|
| 771 | - $this |
|
| 772 | - ); |
|
| 773 | - echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 774 | - echo "</td>"; |
|
| 775 | - } else { |
|
| 776 | - echo "<td $attributes>"; // already escaped |
|
| 777 | - echo apply_filters( |
|
| 778 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 779 | - $this->column_default($item, $column_name), |
|
| 780 | - $item, |
|
| 781 | - $column_name, |
|
| 782 | - $this |
|
| 783 | - ); |
|
| 784 | - echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 785 | - echo "</td>"; |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * Extra controls to be displayed between bulk actions and pagination |
|
| 793 | - * |
|
| 794 | - * @access public |
|
| 795 | - * @param string $which |
|
| 796 | - * @throws EE_Error |
|
| 797 | - */ |
|
| 798 | - public function extra_tablenav($which) |
|
| 799 | - { |
|
| 800 | - if ($which === 'top') { |
|
| 801 | - $this->_filters(); |
|
| 802 | - echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags()); |
|
| 803 | - } else { |
|
| 804 | - echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 805 | - foreach ($this->_bottom_buttons as $type => $action) { |
|
| 806 | - $route = $action['route'] ?? ''; |
|
| 807 | - $extra_request = $action['extra_request'] ?? ''; |
|
| 808 | - // already escaped |
|
| 809 | - echo wp_kses($this->_admin_page->get_action_link_or_button( |
|
| 810 | - $route, |
|
| 811 | - $type, |
|
| 812 | - $extra_request, |
|
| 813 | - 'button button--secondary' |
|
| 814 | - ), AllowedTags::getWithFormTags()); |
|
| 815 | - } |
|
| 816 | - do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 817 | - echo '</div>'; |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * Get an associative array ( option_name => option_title ) with the list |
|
| 824 | - * of bulk actions available on this table. |
|
| 825 | - * |
|
| 826 | - * @return array |
|
| 827 | - * @since 3.1.0 |
|
| 828 | - * @access protected |
|
| 829 | - */ |
|
| 830 | - public function get_bulk_actions() |
|
| 831 | - { |
|
| 832 | - return (array) $this->_get_bulk_actions(); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * Processing bulk actions. |
|
| 838 | - */ |
|
| 839 | - public function process_bulk_action() |
|
| 840 | - { |
|
| 841 | - // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
| 842 | - // reference in case there is a case where it gets used. |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * returns the EE admin page this list table is associated with |
|
| 848 | - * |
|
| 849 | - * @return EE_Admin_Page |
|
| 850 | - */ |
|
| 851 | - public function get_admin_page() |
|
| 852 | - { |
|
| 853 | - return $this->_admin_page; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * A "helper" function for all children to provide an html string of |
|
| 859 | - * actions to output in their content. It is preferable for child classes |
|
| 860 | - * to use this method for generating their actions content so that it's |
|
| 861 | - * filterable by plugins |
|
| 862 | - * |
|
| 863 | - * @param string $action_container what are the html container |
|
| 864 | - * elements for this actions string? |
|
| 865 | - * @param string $action_class What class is for the container |
|
| 866 | - * element. |
|
| 867 | - * @param string $action_items The contents for the action items |
|
| 868 | - * container. This is filtered before |
|
| 869 | - * returned. |
|
| 870 | - * @param string $action_id What id (optional) is used for the |
|
| 871 | - * container element. |
|
| 872 | - * @param EE_Base_Class $item The object for the column displaying |
|
| 873 | - * the actions. |
|
| 874 | - * @return string The assembled action elements container. |
|
| 875 | - */ |
|
| 876 | - protected function _action_string( |
|
| 877 | - $action_items, |
|
| 878 | - $item, |
|
| 879 | - $action_container = 'ul', |
|
| 880 | - $action_class = '', |
|
| 881 | - $action_id = '' |
|
| 882 | - ) { |
|
| 883 | - $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 884 | - $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 885 | - $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 886 | - $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 887 | - try { |
|
| 888 | - $content = apply_filters( |
|
| 889 | - 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 890 | - $action_items, |
|
| 891 | - $item, |
|
| 892 | - $this |
|
| 893 | - ); |
|
| 894 | - } catch (Exception $e) { |
|
| 895 | - if (WP_DEBUG) { |
|
| 896 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 897 | - } |
|
| 898 | - $content = $action_items; |
|
| 899 | - } |
|
| 900 | - return "{$open_tag}{$content}{$close_tag}"; |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * @return string |
|
| 906 | - */ |
|
| 907 | - protected function getReturnUrl() |
|
| 908 | - { |
|
| 909 | - $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST'); |
|
| 910 | - $uri = $this->_admin_page->get_request()->getServerParam('REQUEST_URI'); |
|
| 911 | - return urlencode(esc_url_raw("//{$host}{$uri}")); |
|
| 912 | - } |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * _filters |
|
| 470 | + * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
| 471 | + * button. |
|
| 472 | + * |
|
| 473 | + * @access private |
|
| 474 | + * @return void echos html showing filters |
|
| 475 | + */ |
|
| 476 | + private function _filters() |
|
| 477 | + { |
|
| 478 | + $classname = get_class($this); |
|
| 479 | + $filters = apply_filters( |
|
| 480 | + "FHEE__{$classname}__filters", |
|
| 481 | + (array) $this->_get_table_filters(), |
|
| 482 | + $this, |
|
| 483 | + $this->_screen |
|
| 484 | + ); |
|
| 485 | + |
|
| 486 | + if (empty($filters)) { |
|
| 487 | + return; |
|
| 488 | + } |
|
| 489 | + foreach ($filters as $filter) { |
|
| 490 | + echo wp_kses($filter, AllowedTags::getWithFormTags()); |
|
| 491 | + } |
|
| 492 | + // add filter button at end |
|
| 493 | + echo '<input type="submit" class="ee-list-table-filter-submit button button--secondary" value="' |
|
| 494 | + . esc_html__('Filter', 'event_espresso') |
|
| 495 | + . '" id="post-query-submit" />'; |
|
| 496 | + echo '<input type="hidden" id="ee-list-table-use-filters" name="use_filters" value="no"/>'; |
|
| 497 | + |
|
| 498 | + // add reset filters button at end |
|
| 499 | + echo '<a class="button button--secondary" href="' |
|
| 500 | + . esc_url_raw($this->_admin_page->get_current_page_view_url()) |
|
| 501 | + . '" style="display:inline-block">' |
|
| 502 | + . esc_html__('Reset Filters', 'event_espresso') |
|
| 503 | + . '</a>'; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Callback for 'list_table_primary_column' WordPress filter |
|
| 509 | + * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
| 510 | + * column when class is instantiated. |
|
| 511 | + * |
|
| 512 | + * @param string $column_name |
|
| 513 | + * @return string |
|
| 514 | + * @see WP_List_Table::get_primary_column_name |
|
| 515 | + */ |
|
| 516 | + public function set_primary_column($column_name) |
|
| 517 | + { |
|
| 518 | + return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * |
|
| 524 | + */ |
|
| 525 | + public function prepare_items() |
|
| 526 | + { |
|
| 527 | + |
|
| 528 | + $this->_set_column_info(); |
|
| 529 | + // $this->_column_headers = $this->get_column_info(); |
|
| 530 | + $total_items = $this->_all_data_count; |
|
| 531 | + $this->process_bulk_action(); |
|
| 532 | + |
|
| 533 | + $this->items = $this->_data; |
|
| 534 | + $this->set_pagination_args( |
|
| 535 | + [ |
|
| 536 | + 'total_items' => $total_items, |
|
| 537 | + 'per_page' => $this->_per_page, |
|
| 538 | + 'total_pages' => ceil($total_items / $this->_per_page), |
|
| 539 | + ] |
|
| 540 | + ); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * @param object|array $item |
|
| 546 | + * @return string html content for the column |
|
| 547 | + */ |
|
| 548 | + protected function column_cb($item) |
|
| 549 | + { |
|
| 550 | + return ''; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * This column is the default for when there is no defined column method for a registered column. |
|
| 556 | + * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
| 557 | + * |
|
| 558 | + * @param EE_Base_Class $item |
|
| 559 | + * @param string $column_name The column being called. |
|
| 560 | + * @return string html content for the column |
|
| 561 | + */ |
|
| 562 | + public function column_default($item, $column_name) |
|
| 563 | + { |
|
| 564 | + /** |
|
| 565 | + * Dynamic hook allowing for adding additional column content in this list table. |
|
| 566 | + * Note that $this->screen->id is in the format |
|
| 567 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 568 | + * table it is: event-espresso_page_espresso_messages. |
|
| 569 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 570 | + * hook prefix ("event-espresso") will be different. |
|
| 571 | + */ |
|
| 572 | + ob_start(); |
|
| 573 | + do_action( |
|
| 574 | + 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
| 575 | + $item, |
|
| 576 | + $this->_screen |
|
| 577 | + ); |
|
| 578 | + return ob_get_clean(); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Get a list of columns. The format is: |
|
| 584 | + * 'internal-name' => 'Title' |
|
| 585 | + * |
|
| 586 | + * @return array |
|
| 587 | + * @since 3.1.0 |
|
| 588 | + * @access public |
|
| 589 | + * @abstract |
|
| 590 | + */ |
|
| 591 | + public function get_columns() |
|
| 592 | + { |
|
| 593 | + /** |
|
| 594 | + * Dynamic hook allowing for adding additional columns in this list table. |
|
| 595 | + * Note that $this->screen->id is in the format |
|
| 596 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
| 597 | + * table it is: event-espresso_page_espresso_messages. |
|
| 598 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
| 599 | + * hook prefix ("event-espresso") will be different. |
|
| 600 | + * |
|
| 601 | + * @var array |
|
| 602 | + */ |
|
| 603 | + return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Get an associative array ( id => link ) with the list |
|
| 609 | + * of views available on this table. |
|
| 610 | + * |
|
| 611 | + * @return array |
|
| 612 | + * @since 3.1.0 |
|
| 613 | + * @access protected |
|
| 614 | + */ |
|
| 615 | + public function get_views() |
|
| 616 | + { |
|
| 617 | + return $this->_views; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Generate the views html. |
|
| 623 | + */ |
|
| 624 | + public function display_views() |
|
| 625 | + { |
|
| 626 | + $views = $this->get_views(); |
|
| 627 | + $assembled_views = []; |
|
| 628 | + |
|
| 629 | + if (empty($views)) { |
|
| 630 | + return; |
|
| 631 | + } |
|
| 632 | + echo "<ul class='subsubsub'>\n"; |
|
| 633 | + foreach ($views as $view) { |
|
| 634 | + $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
| 635 | + if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
| 636 | + $filter = "<li"; |
|
| 637 | + $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : ''; |
|
| 638 | + $filter .= ">"; |
|
| 639 | + $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>'; |
|
| 640 | + $filter .= '<span class="count">(' . $count . ')</span>'; |
|
| 641 | + $filter .= '</li>'; |
|
| 642 | + $assembled_views[ $view['slug'] ] = $filter; |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + echo ! empty($assembled_views) |
|
| 647 | + ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views) |
|
| 648 | + : ''; |
|
| 649 | + echo "</ul>"; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Generates content for a single row of the table |
|
| 655 | + * |
|
| 656 | + * @param EE_Base_Class $item The current item |
|
| 657 | + * @since 4.1 |
|
| 658 | + * @access public |
|
| 659 | + */ |
|
| 660 | + public function single_row($item) |
|
| 661 | + { |
|
| 662 | + $row_class = $this->_get_row_class($item); |
|
| 663 | + echo '<tr class="' . esc_attr($row_class) . '">'; |
|
| 664 | + $this->single_row_columns($item); // already escaped |
|
| 665 | + echo '</tr>'; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * This simply sets up the row class for the table rows. |
|
| 671 | + * Allows for easier overriding of child methods for setting up sorting. |
|
| 672 | + * |
|
| 673 | + * @param EE_Base_Class $item the current item |
|
| 674 | + * @return string |
|
| 675 | + */ |
|
| 676 | + protected function _get_row_class($item) |
|
| 677 | + { |
|
| 678 | + static $row_class = ''; |
|
| 679 | + $row_class = ($row_class === '' ? 'alternate' : ''); |
|
| 680 | + |
|
| 681 | + $new_row_class = $row_class; |
|
| 682 | + |
|
| 683 | + if (! empty($this->_ajax_sorting_callback)) { |
|
| 684 | + $new_row_class .= ' rowsortable'; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + return $new_row_class; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * @return array |
|
| 693 | + */ |
|
| 694 | + public function get_sortable_columns() |
|
| 695 | + { |
|
| 696 | + return (array) $this->_sortable_columns; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + public function get_ajax_sorting_callback() |
|
| 704 | + { |
|
| 705 | + return $this->_ajax_sorting_callback; |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * @return array |
|
| 711 | + */ |
|
| 712 | + public function get_hidden_columns() |
|
| 713 | + { |
|
| 714 | + $user_id = get_current_user_id(); |
|
| 715 | + $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
| 716 | + if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
| 717 | + update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
| 718 | + update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
| 719 | + } |
|
| 720 | + $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
| 721 | + return (array) get_user_option($ref, $user_id); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * Generates the columns for a single row of the table. |
|
| 727 | + * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
| 728 | + * column. |
|
| 729 | + * |
|
| 730 | + * @param EE_Base_Class $item The current item |
|
| 731 | + * @since 3.1.0 |
|
| 732 | + */ |
|
| 733 | + public function single_row_columns($item) |
|
| 734 | + { |
|
| 735 | + [$columns, $hidden, $sortable, $primary] = $this->get_column_info(); |
|
| 736 | + |
|
| 737 | + foreach ($columns as $column_name => $column_display_name) { |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
| 741 | + * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
| 742 | + */ |
|
| 743 | + $hidden_class = in_array($column_name, $hidden) ? ' hidden' : ''; |
|
| 744 | + |
|
| 745 | + $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
| 746 | + if ($primary === $column_name) { |
|
| 747 | + $classes .= ' has-row-actions column-primary'; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
| 751 | + |
|
| 752 | + $class = 'class="' . esc_attr($classes) . '"'; |
|
| 753 | + |
|
| 754 | + $attributes = "{$class}{$data}"; |
|
| 755 | + |
|
| 756 | + if ($column_name === 'cb') { |
|
| 757 | + echo '<th scope="row" class="check-column">'; |
|
| 758 | + echo apply_filters( |
|
| 759 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
| 760 | + $this->column_cb($item), // already escaped |
|
| 761 | + $item, |
|
| 762 | + $this |
|
| 763 | + ); |
|
| 764 | + echo '</th>'; |
|
| 765 | + } elseif (method_exists($this, 'column_' . $column_name)) { |
|
| 766 | + echo "<td $attributes>"; // already escaped |
|
| 767 | + echo apply_filters( |
|
| 768 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
| 769 | + call_user_func([$this, 'column_' . $column_name], $item), |
|
| 770 | + $item, |
|
| 771 | + $this |
|
| 772 | + ); |
|
| 773 | + echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 774 | + echo "</td>"; |
|
| 775 | + } else { |
|
| 776 | + echo "<td $attributes>"; // already escaped |
|
| 777 | + echo apply_filters( |
|
| 778 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
| 779 | + $this->column_default($item, $column_name), |
|
| 780 | + $item, |
|
| 781 | + $column_name, |
|
| 782 | + $this |
|
| 783 | + ); |
|
| 784 | + echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags()); |
|
| 785 | + echo "</td>"; |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * Extra controls to be displayed between bulk actions and pagination |
|
| 793 | + * |
|
| 794 | + * @access public |
|
| 795 | + * @param string $which |
|
| 796 | + * @throws EE_Error |
|
| 797 | + */ |
|
| 798 | + public function extra_tablenav($which) |
|
| 799 | + { |
|
| 800 | + if ($which === 'top') { |
|
| 801 | + $this->_filters(); |
|
| 802 | + echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags()); |
|
| 803 | + } else { |
|
| 804 | + echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
| 805 | + foreach ($this->_bottom_buttons as $type => $action) { |
|
| 806 | + $route = $action['route'] ?? ''; |
|
| 807 | + $extra_request = $action['extra_request'] ?? ''; |
|
| 808 | + // already escaped |
|
| 809 | + echo wp_kses($this->_admin_page->get_action_link_or_button( |
|
| 810 | + $route, |
|
| 811 | + $type, |
|
| 812 | + $extra_request, |
|
| 813 | + 'button button--secondary' |
|
| 814 | + ), AllowedTags::getWithFormTags()); |
|
| 815 | + } |
|
| 816 | + do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
| 817 | + echo '</div>'; |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * Get an associative array ( option_name => option_title ) with the list |
|
| 824 | + * of bulk actions available on this table. |
|
| 825 | + * |
|
| 826 | + * @return array |
|
| 827 | + * @since 3.1.0 |
|
| 828 | + * @access protected |
|
| 829 | + */ |
|
| 830 | + public function get_bulk_actions() |
|
| 831 | + { |
|
| 832 | + return (array) $this->_get_bulk_actions(); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + /** |
|
| 837 | + * Processing bulk actions. |
|
| 838 | + */ |
|
| 839 | + public function process_bulk_action() |
|
| 840 | + { |
|
| 841 | + // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
| 842 | + // reference in case there is a case where it gets used. |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * returns the EE admin page this list table is associated with |
|
| 848 | + * |
|
| 849 | + * @return EE_Admin_Page |
|
| 850 | + */ |
|
| 851 | + public function get_admin_page() |
|
| 852 | + { |
|
| 853 | + return $this->_admin_page; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * A "helper" function for all children to provide an html string of |
|
| 859 | + * actions to output in their content. It is preferable for child classes |
|
| 860 | + * to use this method for generating their actions content so that it's |
|
| 861 | + * filterable by plugins |
|
| 862 | + * |
|
| 863 | + * @param string $action_container what are the html container |
|
| 864 | + * elements for this actions string? |
|
| 865 | + * @param string $action_class What class is for the container |
|
| 866 | + * element. |
|
| 867 | + * @param string $action_items The contents for the action items |
|
| 868 | + * container. This is filtered before |
|
| 869 | + * returned. |
|
| 870 | + * @param string $action_id What id (optional) is used for the |
|
| 871 | + * container element. |
|
| 872 | + * @param EE_Base_Class $item The object for the column displaying |
|
| 873 | + * the actions. |
|
| 874 | + * @return string The assembled action elements container. |
|
| 875 | + */ |
|
| 876 | + protected function _action_string( |
|
| 877 | + $action_items, |
|
| 878 | + $item, |
|
| 879 | + $action_container = 'ul', |
|
| 880 | + $action_class = '', |
|
| 881 | + $action_id = '' |
|
| 882 | + ) { |
|
| 883 | + $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : ''; |
|
| 884 | + $action_id = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : ''; |
|
| 885 | + $open_tag = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
| 886 | + $close_tag = ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
| 887 | + try { |
|
| 888 | + $content = apply_filters( |
|
| 889 | + 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
| 890 | + $action_items, |
|
| 891 | + $item, |
|
| 892 | + $this |
|
| 893 | + ); |
|
| 894 | + } catch (Exception $e) { |
|
| 895 | + if (WP_DEBUG) { |
|
| 896 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 897 | + } |
|
| 898 | + $content = $action_items; |
|
| 899 | + } |
|
| 900 | + return "{$open_tag}{$content}{$close_tag}"; |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * @return string |
|
| 906 | + */ |
|
| 907 | + protected function getReturnUrl() |
|
| 908 | + { |
|
| 909 | + $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST'); |
|
| 910 | + $uri = $this->_admin_page->get_request()->getServerParam('REQUEST_URI'); |
|
| 911 | + return urlencode(esc_url_raw("//{$host}{$uri}")); |
|
| 912 | + } |
|
| 913 | 913 | } |
@@ -19,4166 +19,4166 @@ |
||
| 19 | 19 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var LoaderInterface |
|
| 24 | - */ |
|
| 25 | - protected $loader; |
|
| 22 | + /** |
|
| 23 | + * @var LoaderInterface |
|
| 24 | + */ |
|
| 25 | + protected $loader; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var RequestInterface |
|
| 29 | - */ |
|
| 30 | - protected $request; |
|
| 27 | + /** |
|
| 28 | + * @var RequestInterface |
|
| 29 | + */ |
|
| 30 | + protected $request; |
|
| 31 | 31 | |
| 32 | - // set in _init_page_props() |
|
| 33 | - public $page_slug; |
|
| 32 | + // set in _init_page_props() |
|
| 33 | + public $page_slug; |
|
| 34 | 34 | |
| 35 | - public $page_label; |
|
| 35 | + public $page_label; |
|
| 36 | 36 | |
| 37 | - public $page_folder; |
|
| 37 | + public $page_folder; |
|
| 38 | 38 | |
| 39 | - // set in define_page_props() |
|
| 40 | - protected $_admin_base_url; |
|
| 39 | + // set in define_page_props() |
|
| 40 | + protected $_admin_base_url; |
|
| 41 | 41 | |
| 42 | - protected $_admin_base_path; |
|
| 42 | + protected $_admin_base_path; |
|
| 43 | 43 | |
| 44 | - protected $_admin_page_title; |
|
| 44 | + protected $_admin_page_title; |
|
| 45 | 45 | |
| 46 | - protected $_labels; |
|
| 46 | + protected $_labels; |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - // set early within EE_Admin_Init |
|
| 50 | - protected $_wp_page_slug; |
|
| 49 | + // set early within EE_Admin_Init |
|
| 50 | + protected $_wp_page_slug; |
|
| 51 | 51 | |
| 52 | - // navtabs |
|
| 53 | - protected $_nav_tabs; |
|
| 52 | + // navtabs |
|
| 53 | + protected $_nav_tabs; |
|
| 54 | 54 | |
| 55 | - protected $_default_nav_tab_name; |
|
| 55 | + protected $_default_nav_tab_name; |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - // template variables (used by templates) |
|
| 59 | - protected $_template_path; |
|
| 58 | + // template variables (used by templates) |
|
| 59 | + protected $_template_path; |
|
| 60 | 60 | |
| 61 | - protected $_column_template_path; |
|
| 61 | + protected $_column_template_path; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var array $_template_args |
|
| 65 | - */ |
|
| 66 | - protected $_template_args = []; |
|
| 63 | + /** |
|
| 64 | + * @var array $_template_args |
|
| 65 | + */ |
|
| 66 | + protected $_template_args = []; |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * this will hold the list table object for a given view. |
|
| 70 | - * |
|
| 71 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 72 | - */ |
|
| 73 | - protected $_list_table_object; |
|
| 68 | + /** |
|
| 69 | + * this will hold the list table object for a given view. |
|
| 70 | + * |
|
| 71 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 72 | + */ |
|
| 73 | + protected $_list_table_object; |
|
| 74 | 74 | |
| 75 | - // bools |
|
| 76 | - protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 75 | + // bools |
|
| 76 | + protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 77 | 77 | |
| 78 | - protected $_routing; |
|
| 78 | + protected $_routing; |
|
| 79 | 79 | |
| 80 | - // list table args |
|
| 81 | - protected $_view; |
|
| 80 | + // list table args |
|
| 81 | + protected $_view; |
|
| 82 | 82 | |
| 83 | - protected $_views; |
|
| 83 | + protected $_views; |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | - // action => method pairs used for routing incoming requests |
|
| 87 | - protected $_page_routes; |
|
| 86 | + // action => method pairs used for routing incoming requests |
|
| 87 | + protected $_page_routes; |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @var array $_page_config |
|
| 91 | - */ |
|
| 92 | - protected $_page_config; |
|
| 89 | + /** |
|
| 90 | + * @var array $_page_config |
|
| 91 | + */ |
|
| 92 | + protected $_page_config; |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * the current page route and route config |
|
| 96 | - * |
|
| 97 | - * @var string $_route |
|
| 98 | - */ |
|
| 99 | - protected $_route; |
|
| 94 | + /** |
|
| 95 | + * the current page route and route config |
|
| 96 | + * |
|
| 97 | + * @var string $_route |
|
| 98 | + */ |
|
| 99 | + protected $_route; |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @var string $_cpt_route |
|
| 103 | - */ |
|
| 104 | - protected $_cpt_route; |
|
| 101 | + /** |
|
| 102 | + * @var string $_cpt_route |
|
| 103 | + */ |
|
| 104 | + protected $_cpt_route; |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * @var array $_route_config |
|
| 108 | - */ |
|
| 109 | - protected $_route_config; |
|
| 106 | + /** |
|
| 107 | + * @var array $_route_config |
|
| 108 | + */ |
|
| 109 | + protected $_route_config; |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 113 | - * actions. |
|
| 114 | - * |
|
| 115 | - * @since 4.6.x |
|
| 116 | - * @var array. |
|
| 117 | - */ |
|
| 118 | - protected $_default_route_query_args; |
|
| 119 | - |
|
| 120 | - // set via request page and action args. |
|
| 121 | - protected $_current_page; |
|
| 122 | - |
|
| 123 | - protected $_current_view; |
|
| 124 | - |
|
| 125 | - protected $_current_page_view_url; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * unprocessed value for the 'action' request param (default '') |
|
| 129 | - * |
|
| 130 | - * @var string |
|
| 131 | - */ |
|
| 132 | - protected $raw_req_action = ''; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * unprocessed value for the 'page' request param (default '') |
|
| 136 | - * |
|
| 137 | - * @var string |
|
| 138 | - */ |
|
| 139 | - protected $raw_req_page = ''; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * sanitized request action (and nonce) |
|
| 143 | - * |
|
| 144 | - * @var string |
|
| 145 | - */ |
|
| 146 | - protected $_req_action = ''; |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * sanitized request action nonce |
|
| 150 | - * |
|
| 151 | - * @var string |
|
| 152 | - */ |
|
| 153 | - protected $_req_nonce = ''; |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @var string |
|
| 157 | - */ |
|
| 158 | - protected $_search_btn_label = ''; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @var string |
|
| 162 | - */ |
|
| 163 | - protected $_search_box_callback = ''; |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @var WP_Screen |
|
| 167 | - */ |
|
| 168 | - protected $_current_screen; |
|
| 169 | - |
|
| 170 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 171 | - protected $_hook_obj; |
|
| 172 | - |
|
| 173 | - // for holding incoming request data |
|
| 174 | - protected $_req_data = []; |
|
| 175 | - |
|
| 176 | - // yes / no array for admin form fields |
|
| 177 | - protected $_yes_no_values = []; |
|
| 178 | - |
|
| 179 | - // some default things shared by all child classes |
|
| 180 | - protected $_default_espresso_metaboxes; |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @var EE_Registry |
|
| 184 | - */ |
|
| 185 | - protected $EE = null; |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 190 | - * |
|
| 191 | - * @var boolean |
|
| 192 | - */ |
|
| 193 | - protected $_is_caf = false; |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @Constructor |
|
| 198 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 199 | - * @throws EE_Error |
|
| 200 | - * @throws InvalidArgumentException |
|
| 201 | - * @throws ReflectionException |
|
| 202 | - * @throws InvalidDataTypeException |
|
| 203 | - * @throws InvalidInterfaceException |
|
| 204 | - */ |
|
| 205 | - public function __construct($routing = true) |
|
| 206 | - { |
|
| 207 | - $this->loader = LoaderFactory::getLoader(); |
|
| 208 | - $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 209 | - $this->_routing = $routing; |
|
| 210 | - |
|
| 211 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 212 | - $this->_is_caf = true; |
|
| 213 | - } |
|
| 214 | - $this->_yes_no_values = [ |
|
| 215 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 216 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 217 | - ]; |
|
| 218 | - // set the _req_data property. |
|
| 219 | - $this->_req_data = $this->request->requestParams(); |
|
| 220 | - // set initial page props (child method) |
|
| 221 | - $this->_init_page_props(); |
|
| 222 | - // set global defaults |
|
| 223 | - $this->_set_defaults(); |
|
| 224 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 225 | - $this->_global_ajax_hooks(); |
|
| 226 | - $this->_ajax_hooks(); |
|
| 227 | - // other_page_hooks have to be early too. |
|
| 228 | - $this->_do_other_page_hooks(); |
|
| 229 | - // set up page dependencies |
|
| 230 | - $this->_before_page_setup(); |
|
| 231 | - $this->_page_setup(); |
|
| 232 | - // die(); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * _init_page_props |
|
| 238 | - * Child classes use to set at least the following properties: |
|
| 239 | - * $page_slug. |
|
| 240 | - * $page_label. |
|
| 241 | - * |
|
| 242 | - * @abstract |
|
| 243 | - * @return void |
|
| 244 | - */ |
|
| 245 | - abstract protected function _init_page_props(); |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * _ajax_hooks |
|
| 250 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 251 | - * Note: within the ajax callback methods. |
|
| 252 | - * |
|
| 253 | - * @abstract |
|
| 254 | - * @return void |
|
| 255 | - */ |
|
| 256 | - abstract protected function _ajax_hooks(); |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * _define_page_props |
|
| 261 | - * child classes define page properties in here. Must include at least: |
|
| 262 | - * $_admin_base_url = base_url for all admin pages |
|
| 263 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 264 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 265 | - * array( |
|
| 266 | - * 'buttons' => array( |
|
| 267 | - * 'add' => esc_html__('label for add new button'), |
|
| 268 | - * 'edit' => esc_html__('label for edit button'), |
|
| 269 | - * 'delete' => esc_html__('label for delete button') |
|
| 270 | - * ) |
|
| 271 | - * ) |
|
| 272 | - * |
|
| 273 | - * @abstract |
|
| 274 | - * @return void |
|
| 275 | - */ |
|
| 276 | - abstract protected function _define_page_props(); |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * _set_page_routes |
|
| 281 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 282 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 283 | - * have a 'default' route. Here's the format |
|
| 284 | - * $this->_page_routes = array( |
|
| 285 | - * 'default' => array( |
|
| 286 | - * 'func' => '_default_method_handling_route', |
|
| 287 | - * 'args' => array('array','of','args'), |
|
| 288 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 289 | - * ajax request, backend processing) |
|
| 290 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 291 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 292 | - * headers sent route. |
|
| 293 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 294 | - * this route. |
|
| 295 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 296 | - * checks). |
|
| 297 | - * ), |
|
| 298 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 299 | - * handling method. |
|
| 300 | - * ) |
|
| 301 | - * ) |
|
| 302 | - * |
|
| 303 | - * @abstract |
|
| 304 | - * @return void |
|
| 305 | - */ |
|
| 306 | - abstract protected function _set_page_routes(); |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * _set_page_config |
|
| 311 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 312 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 313 | - * $this->_page_config = array( |
|
| 314 | - * 'default' => array( |
|
| 315 | - * 'labels' => array( |
|
| 316 | - * 'buttons' => array( |
|
| 317 | - * 'add' => esc_html__('label for adding item'), |
|
| 318 | - * 'edit' => esc_html__('label for editing item'), |
|
| 319 | - * 'delete' => esc_html__('label for deleting item') |
|
| 320 | - * ), |
|
| 321 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 322 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 323 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 324 | - * _define_page_props() method |
|
| 325 | - * 'nav' => array( |
|
| 326 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 327 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 328 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 329 | - * 'order' => 10, //required to indicate tab position. |
|
| 330 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 331 | - * displayed then add this parameter. |
|
| 332 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 333 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 334 | - * metaboxes set for eventespresso admin pages. |
|
| 335 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 336 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 337 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 338 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 339 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 340 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 341 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 342 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 343 | - * want to display. |
|
| 344 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 345 | - * 'tab_id' => array( |
|
| 346 | - * 'title' => 'tab_title', |
|
| 347 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 348 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 349 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 350 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 351 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 352 | - * attempt to use the callback which should match the name of a method in the class |
|
| 353 | - * ), |
|
| 354 | - * 'tab2_id' => array( |
|
| 355 | - * 'title' => 'tab2 title', |
|
| 356 | - * 'filename' => 'file_name_2' |
|
| 357 | - * 'callback' => 'callback_method_for_content', |
|
| 358 | - * ), |
|
| 359 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 360 | - * help tab area on an admin page. @return void |
|
| 361 | - * |
|
| 362 | - * @abstract |
|
| 363 | - */ |
|
| 364 | - abstract protected function _set_page_config(); |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * _add_screen_options |
|
| 369 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 370 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 371 | - * to a particular view. |
|
| 372 | - * |
|
| 373 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 374 | - * see also WP_Screen object documents... |
|
| 375 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 376 | - * @abstract |
|
| 377 | - * @return void |
|
| 378 | - */ |
|
| 379 | - abstract protected function _add_screen_options(); |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * _add_feature_pointers |
|
| 384 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 385 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 386 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 387 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 388 | - * extended) also see: |
|
| 389 | - * |
|
| 390 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 391 | - * @abstract |
|
| 392 | - * @return void |
|
| 393 | - */ |
|
| 394 | - abstract protected function _add_feature_pointers(); |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * load_scripts_styles |
|
| 399 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 400 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 401 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 402 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 403 | - * |
|
| 404 | - * @abstract |
|
| 405 | - * @return void |
|
| 406 | - */ |
|
| 407 | - abstract public function load_scripts_styles(); |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * admin_init |
|
| 412 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 413 | - * all pages/views loaded by child class. |
|
| 414 | - * |
|
| 415 | - * @abstract |
|
| 416 | - * @return void |
|
| 417 | - */ |
|
| 418 | - abstract public function admin_init(); |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * admin_notices |
|
| 423 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 424 | - * all pages/views loaded by child class. |
|
| 425 | - * |
|
| 426 | - * @abstract |
|
| 427 | - * @return void |
|
| 428 | - */ |
|
| 429 | - abstract public function admin_notices(); |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * admin_footer_scripts |
|
| 434 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 435 | - * will apply to all pages/views loaded by child class. |
|
| 436 | - * |
|
| 437 | - * @return void |
|
| 438 | - */ |
|
| 439 | - abstract public function admin_footer_scripts(); |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * admin_footer |
|
| 444 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 445 | - * apply to all pages/views loaded by child class. |
|
| 446 | - * |
|
| 447 | - * @return void |
|
| 448 | - */ |
|
| 449 | - public function admin_footer() |
|
| 450 | - { |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * _global_ajax_hooks |
|
| 456 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 457 | - * Note: within the ajax callback methods. |
|
| 458 | - * |
|
| 459 | - * @abstract |
|
| 460 | - * @return void |
|
| 461 | - */ |
|
| 462 | - protected function _global_ajax_hooks() |
|
| 463 | - { |
|
| 464 | - // for lazy loading of metabox content |
|
| 465 | - add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - public function ajax_metabox_content() |
|
| 470 | - { |
|
| 471 | - $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 472 | - $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 473 | - self::cached_rss_display($content_id, $content_url); |
|
| 474 | - wp_die(); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 480 | - * |
|
| 481 | - * @return void |
|
| 482 | - */ |
|
| 483 | - protected function _before_page_setup() |
|
| 484 | - { |
|
| 485 | - // default is to do nothing |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Makes sure any things that need to be loaded early get handled. |
|
| 491 | - * We also escape early here if the page requested doesn't match the object. |
|
| 492 | - * |
|
| 493 | - * @final |
|
| 494 | - * @return void |
|
| 495 | - * @throws EE_Error |
|
| 496 | - * @throws InvalidArgumentException |
|
| 497 | - * @throws ReflectionException |
|
| 498 | - * @throws InvalidDataTypeException |
|
| 499 | - * @throws InvalidInterfaceException |
|
| 500 | - */ |
|
| 501 | - final protected function _page_setup() |
|
| 502 | - { |
|
| 503 | - // requires? |
|
| 504 | - // admin_init stuff - global - we're setting this REALLY early |
|
| 505 | - // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 506 | - // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 507 | - add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 508 | - // next verify if we need to load anything... |
|
| 509 | - $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 510 | - $this->page_folder = strtolower( |
|
| 511 | - str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
| 512 | - ); |
|
| 513 | - global $ee_menu_slugs; |
|
| 514 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 515 | - if ( |
|
| 516 | - ! $this->request->isAjax() |
|
| 517 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 518 | - ) { |
|
| 519 | - return; |
|
| 520 | - } |
|
| 521 | - // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 522 | - // we need to copy the action from the second to the first |
|
| 523 | - $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 524 | - $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 525 | - $action = $action !== '-1' ? $action : $action2; |
|
| 526 | - $req_action = $action !== '-1' ? $action : 'default'; |
|
| 527 | - |
|
| 528 | - // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 529 | - // then let's use the route as the action. |
|
| 530 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 531 | - $route = $this->request->getRequestParam('route'); |
|
| 532 | - $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 533 | - ? $route |
|
| 534 | - : $req_action; |
|
| 535 | - |
|
| 536 | - $this->_current_view = $this->_req_action; |
|
| 537 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 538 | - $this->_define_page_props(); |
|
| 539 | - $this->_current_page_view_url = add_query_arg( |
|
| 540 | - ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 541 | - $this->_admin_base_url |
|
| 542 | - ); |
|
| 543 | - // default things |
|
| 544 | - $this->_default_espresso_metaboxes = [ |
|
| 545 | - '_espresso_news_post_box', |
|
| 546 | - '_espresso_links_post_box', |
|
| 547 | - '_espresso_ratings_request', |
|
| 548 | - '_espresso_sponsors_post_box', |
|
| 549 | - ]; |
|
| 550 | - // set page configs |
|
| 551 | - $this->_set_page_routes(); |
|
| 552 | - $this->_set_page_config(); |
|
| 553 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 554 | - if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 555 | - $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 556 | - if ($wp_referer) { |
|
| 557 | - $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - // for caffeinated and other extended functionality. |
|
| 561 | - // If there is a _extend_page_config method |
|
| 562 | - // then let's run that to modify the all the various page configuration arrays |
|
| 563 | - if (method_exists($this, '_extend_page_config')) { |
|
| 564 | - $this->_extend_page_config(); |
|
| 565 | - } |
|
| 566 | - // for CPT and other extended functionality. |
|
| 567 | - // If there is an _extend_page_config_for_cpt |
|
| 568 | - // then let's run that to modify all the various page configuration arrays. |
|
| 569 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 570 | - $this->_extend_page_config_for_cpt(); |
|
| 571 | - } |
|
| 572 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 573 | - $this->_page_routes = apply_filters( |
|
| 574 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 575 | - $this->_page_routes, |
|
| 576 | - $this |
|
| 577 | - ); |
|
| 578 | - $this->_page_config = apply_filters( |
|
| 579 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 580 | - $this->_page_config, |
|
| 581 | - $this |
|
| 582 | - ); |
|
| 583 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 584 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 585 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 586 | - add_action( |
|
| 587 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 588 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 589 | - 10, |
|
| 590 | - 2 |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - // next route only if routing enabled |
|
| 594 | - if ($this->_routing && ! $this->request->isAjax()) { |
|
| 595 | - $this->_verify_routes(); |
|
| 596 | - // next let's just check user_access and kill if no access |
|
| 597 | - $this->check_user_access(); |
|
| 598 | - if ($this->_is_UI_request) { |
|
| 599 | - // admin_init stuff - global, all views for this page class, specific view |
|
| 600 | - add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 601 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 602 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 603 | - } |
|
| 604 | - } else { |
|
| 605 | - // hijack regular WP loading and route admin request immediately |
|
| 606 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 607 | - $this->route_admin_request(); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 615 | - * |
|
| 616 | - * @return void |
|
| 617 | - * @throws EE_Error |
|
| 618 | - */ |
|
| 619 | - private function _do_other_page_hooks() |
|
| 620 | - { |
|
| 621 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 622 | - foreach ($registered_pages as $page) { |
|
| 623 | - // now let's setup the file name and class that should be present |
|
| 624 | - $classname = str_replace('.class.php', '', $page); |
|
| 625 | - // autoloaders should take care of loading file |
|
| 626 | - if (! class_exists($classname)) { |
|
| 627 | - $error_msg[] = sprintf( |
|
| 628 | - esc_html__( |
|
| 629 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 630 | - 'event_espresso' |
|
| 631 | - ), |
|
| 632 | - $page |
|
| 633 | - ); |
|
| 634 | - $error_msg[] = $error_msg[0] |
|
| 635 | - . "\r\n" |
|
| 636 | - . sprintf( |
|
| 637 | - esc_html__( |
|
| 638 | - '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', |
|
| 639 | - 'event_espresso' |
|
| 640 | - ), |
|
| 641 | - $page, |
|
| 642 | - '<br />', |
|
| 643 | - '<strong>' . $classname . '</strong>' |
|
| 644 | - ); |
|
| 645 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 646 | - } |
|
| 647 | - // notice we are passing the instance of this class to the hook object. |
|
| 648 | - $this->loader->getShared($classname, [$this]); |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * @throws ReflectionException |
|
| 655 | - * @throws EE_Error |
|
| 656 | - */ |
|
| 657 | - public function load_page_dependencies() |
|
| 658 | - { |
|
| 659 | - try { |
|
| 660 | - $this->_load_page_dependencies(); |
|
| 661 | - } catch (EE_Error $e) { |
|
| 662 | - $e->get_error(); |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * load_page_dependencies |
|
| 669 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 670 | - * |
|
| 671 | - * @return void |
|
| 672 | - * @throws DomainException |
|
| 673 | - * @throws EE_Error |
|
| 674 | - * @throws InvalidArgumentException |
|
| 675 | - * @throws InvalidDataTypeException |
|
| 676 | - * @throws InvalidInterfaceException |
|
| 677 | - */ |
|
| 678 | - protected function _load_page_dependencies() |
|
| 679 | - { |
|
| 680 | - // let's set the current_screen and screen options to override what WP set |
|
| 681 | - $this->_current_screen = get_current_screen(); |
|
| 682 | - // load admin_notices - global, page class, and view specific |
|
| 683 | - add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 684 | - add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 685 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 686 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 687 | - } |
|
| 688 | - // load network admin_notices - global, page class, and view specific |
|
| 689 | - add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 690 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 691 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 692 | - } |
|
| 693 | - // this will save any per_page screen options if they are present |
|
| 694 | - $this->_set_per_page_screen_options(); |
|
| 695 | - // setup list table properties |
|
| 696 | - $this->_set_list_table(); |
|
| 697 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 698 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 699 | - $this->_add_registered_meta_boxes(); |
|
| 700 | - $this->_add_screen_columns(); |
|
| 701 | - // add screen options - global, page child class, and view specific |
|
| 702 | - $this->_add_global_screen_options(); |
|
| 703 | - $this->_add_screen_options(); |
|
| 704 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 705 | - if (method_exists($this, $add_screen_options)) { |
|
| 706 | - $this->{$add_screen_options}(); |
|
| 707 | - } |
|
| 708 | - // add help tab(s) - set via page_config and qtips. |
|
| 709 | - $this->_add_help_tabs(); |
|
| 710 | - $this->_add_qtips(); |
|
| 711 | - // add feature_pointers - global, page child class, and view specific |
|
| 712 | - $this->_add_feature_pointers(); |
|
| 713 | - $this->_add_global_feature_pointers(); |
|
| 714 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 715 | - if (method_exists($this, $add_feature_pointer)) { |
|
| 716 | - $this->{$add_feature_pointer}(); |
|
| 717 | - } |
|
| 718 | - // enqueue scripts/styles - global, page class, and view specific |
|
| 719 | - add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 720 | - add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 721 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 722 | - add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 723 | - } |
|
| 724 | - add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 725 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 726 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 727 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 728 | - // is a good use case. Notice the late priority we're giving these |
|
| 729 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 730 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 731 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 732 | - add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 733 | - } |
|
| 734 | - // admin footer scripts |
|
| 735 | - add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 736 | - add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 737 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 738 | - add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 739 | - } |
|
| 740 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 741 | - // targeted hook |
|
| 742 | - do_action( |
|
| 743 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 744 | - ); |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * _set_defaults |
|
| 750 | - * This sets some global defaults for class properties. |
|
| 751 | - */ |
|
| 752 | - private function _set_defaults() |
|
| 753 | - { |
|
| 754 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 755 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 756 | - $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 757 | - $this->_page_config = $this->_default_route_query_args = []; |
|
| 758 | - $this->_default_nav_tab_name = 'overview'; |
|
| 759 | - // init template args |
|
| 760 | - $this->_template_args = [ |
|
| 761 | - 'admin_page_header' => '', |
|
| 762 | - 'admin_page_content' => '', |
|
| 763 | - 'post_body_content' => '', |
|
| 764 | - 'before_list_table' => '', |
|
| 765 | - 'after_list_table' => '', |
|
| 766 | - ]; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * route_admin_request |
|
| 772 | - * |
|
| 773 | - * @return void |
|
| 774 | - * @throws InvalidArgumentException |
|
| 775 | - * @throws InvalidInterfaceException |
|
| 776 | - * @throws InvalidDataTypeException |
|
| 777 | - * @throws EE_Error |
|
| 778 | - * @throws ReflectionException |
|
| 779 | - * @see _route_admin_request() |
|
| 780 | - */ |
|
| 781 | - public function route_admin_request() |
|
| 782 | - { |
|
| 783 | - try { |
|
| 784 | - $this->_route_admin_request(); |
|
| 785 | - } catch (EE_Error $e) { |
|
| 786 | - $e->get_error(); |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - public function set_wp_page_slug($wp_page_slug) |
|
| 792 | - { |
|
| 793 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 794 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 795 | - if (is_network_admin()) { |
|
| 796 | - $this->_wp_page_slug .= '-network'; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * _verify_routes |
|
| 803 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 804 | - * we know if we need to drop out. |
|
| 805 | - * |
|
| 806 | - * @return bool |
|
| 807 | - * @throws EE_Error |
|
| 808 | - */ |
|
| 809 | - protected function _verify_routes() |
|
| 810 | - { |
|
| 811 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 812 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 813 | - return false; |
|
| 814 | - } |
|
| 815 | - $this->_route = false; |
|
| 816 | - // check that the page_routes array is not empty |
|
| 817 | - if (empty($this->_page_routes)) { |
|
| 818 | - // user error msg |
|
| 819 | - $error_msg = sprintf( |
|
| 820 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 821 | - $this->_admin_page_title |
|
| 822 | - ); |
|
| 823 | - // developer error msg |
|
| 824 | - $error_msg .= '||' . $error_msg |
|
| 825 | - . esc_html__( |
|
| 826 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 827 | - 'event_espresso' |
|
| 828 | - ); |
|
| 829 | - throw new EE_Error($error_msg); |
|
| 830 | - } |
|
| 831 | - // and that the requested page route exists |
|
| 832 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 833 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 834 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 835 | - ? $this->_page_config[ $this->_req_action ] |
|
| 836 | - : []; |
|
| 837 | - } else { |
|
| 838 | - // user error msg |
|
| 839 | - $error_msg = sprintf( |
|
| 840 | - esc_html__( |
|
| 841 | - 'The requested page route does not exist for the %s admin page.', |
|
| 842 | - 'event_espresso' |
|
| 843 | - ), |
|
| 844 | - $this->_admin_page_title |
|
| 845 | - ); |
|
| 846 | - // developer error msg |
|
| 847 | - $error_msg .= '||' . $error_msg |
|
| 848 | - . sprintf( |
|
| 849 | - esc_html__( |
|
| 850 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 851 | - 'event_espresso' |
|
| 852 | - ), |
|
| 853 | - $this->_req_action |
|
| 854 | - ); |
|
| 855 | - throw new EE_Error($error_msg); |
|
| 856 | - } |
|
| 857 | - // and that a default route exists |
|
| 858 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 859 | - // user error msg |
|
| 860 | - $error_msg = sprintf( |
|
| 861 | - esc_html__( |
|
| 862 | - 'A default page route has not been set for the % admin page.', |
|
| 863 | - 'event_espresso' |
|
| 864 | - ), |
|
| 865 | - $this->_admin_page_title |
|
| 866 | - ); |
|
| 867 | - // developer error msg |
|
| 868 | - $error_msg .= '||' . $error_msg |
|
| 869 | - . esc_html__( |
|
| 870 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 871 | - 'event_espresso' |
|
| 872 | - ); |
|
| 873 | - throw new EE_Error($error_msg); |
|
| 874 | - } |
|
| 875 | - // first lets' catch if the UI request has EVER been set. |
|
| 876 | - if ($this->_is_UI_request === null) { |
|
| 877 | - // lets set if this is a UI request or not. |
|
| 878 | - $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 879 | - // wait a minute... we might have a noheader in the route array |
|
| 880 | - $this->_is_UI_request = ! ( |
|
| 881 | - is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 882 | - ) |
|
| 883 | - ? $this->_is_UI_request |
|
| 884 | - : false; |
|
| 885 | - } |
|
| 886 | - $this->_set_current_labels(); |
|
| 887 | - return true; |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 893 | - * |
|
| 894 | - * @param string $route the route name we're verifying |
|
| 895 | - * @return bool we'll throw an exception if this isn't a valid route. |
|
| 896 | - * @throws EE_Error |
|
| 897 | - */ |
|
| 898 | - protected function _verify_route($route) |
|
| 899 | - { |
|
| 900 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 901 | - return true; |
|
| 902 | - } |
|
| 903 | - // user error msg |
|
| 904 | - $error_msg = sprintf( |
|
| 905 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 906 | - $this->_admin_page_title |
|
| 907 | - ); |
|
| 908 | - // developer error msg |
|
| 909 | - $error_msg .= '||' . $error_msg |
|
| 910 | - . sprintf( |
|
| 911 | - esc_html__( |
|
| 912 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 913 | - 'event_espresso' |
|
| 914 | - ), |
|
| 915 | - $route |
|
| 916 | - ); |
|
| 917 | - throw new EE_Error($error_msg); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * perform nonce verification |
|
| 923 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 924 | - * using this method (and save retyping!) |
|
| 925 | - * |
|
| 926 | - * @param string $nonce The nonce sent |
|
| 927 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 928 | - * @return void |
|
| 929 | - * @throws EE_Error |
|
| 930 | - */ |
|
| 931 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 932 | - { |
|
| 933 | - // verify nonce against expected value |
|
| 934 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 935 | - // these are not the droids you are looking for !!! |
|
| 936 | - $msg = sprintf( |
|
| 937 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 938 | - '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 939 | - '</a>' |
|
| 940 | - ); |
|
| 941 | - if (WP_DEBUG) { |
|
| 942 | - $msg .= "\n "; |
|
| 943 | - $msg .= sprintf( |
|
| 944 | - esc_html__( |
|
| 945 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 946 | - 'event_espresso' |
|
| 947 | - ), |
|
| 948 | - __CLASS__ |
|
| 949 | - ); |
|
| 950 | - } |
|
| 951 | - if (! $this->request->isAjax()) { |
|
| 952 | - wp_die($msg); |
|
| 953 | - } |
|
| 954 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 955 | - $this->_return_json(); |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - |
|
| 960 | - /** |
|
| 961 | - * _route_admin_request() |
|
| 962 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 963 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 964 | - * in the page routes and then will try to load the corresponding method. |
|
| 965 | - * |
|
| 966 | - * @return void |
|
| 967 | - * @throws EE_Error |
|
| 968 | - * @throws InvalidArgumentException |
|
| 969 | - * @throws InvalidDataTypeException |
|
| 970 | - * @throws InvalidInterfaceException |
|
| 971 | - * @throws ReflectionException |
|
| 972 | - */ |
|
| 973 | - protected function _route_admin_request() |
|
| 974 | - { |
|
| 975 | - if (! $this->_is_UI_request) { |
|
| 976 | - $this->_verify_routes(); |
|
| 977 | - } |
|
| 978 | - $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 979 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 980 | - // set nonce from post data |
|
| 981 | - $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 982 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 983 | - } |
|
| 984 | - // set the nav_tabs array but ONLY if this is UI_request |
|
| 985 | - if ($this->_is_UI_request) { |
|
| 986 | - $this->_set_nav_tabs(); |
|
| 987 | - } |
|
| 988 | - // grab callback function |
|
| 989 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 990 | - // check if callback has args |
|
| 991 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 992 | - $error_msg = ''; |
|
| 993 | - // action right before calling route |
|
| 994 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 995 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 996 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 997 | - } |
|
| 998 | - // right before calling the route, let's clean the _wp_http_referer |
|
| 999 | - $this->request->setServerParam( |
|
| 1000 | - 'REQUEST_URI', |
|
| 1001 | - remove_query_arg( |
|
| 1002 | - '_wp_http_referer', |
|
| 1003 | - wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1004 | - ) |
|
| 1005 | - ); |
|
| 1006 | - if (! empty($func)) { |
|
| 1007 | - if (is_array($func)) { |
|
| 1008 | - [$class, $method] = $func; |
|
| 1009 | - } elseif (strpos($func, '::') !== false) { |
|
| 1010 | - [$class, $method] = explode('::', $func); |
|
| 1011 | - } else { |
|
| 1012 | - $class = $this; |
|
| 1013 | - $method = $func; |
|
| 1014 | - } |
|
| 1015 | - if (! (is_object($class) && $class === $this)) { |
|
| 1016 | - // send along this admin page object for access by addons. |
|
| 1017 | - $args['admin_page_object'] = $this; |
|
| 1018 | - } |
|
| 1019 | - if ( |
|
| 1020 | - // is it a method on a class that doesn't work? |
|
| 1021 | - ( |
|
| 1022 | - ( |
|
| 1023 | - method_exists($class, $method) |
|
| 1024 | - && call_user_func_array([$class, $method], $args) === false |
|
| 1025 | - ) |
|
| 1026 | - && ( |
|
| 1027 | - // is it a standalone function that doesn't work? |
|
| 1028 | - function_exists($method) |
|
| 1029 | - && call_user_func_array( |
|
| 1030 | - $func, |
|
| 1031 | - array_merge(['admin_page_object' => $this], $args) |
|
| 1032 | - ) === false |
|
| 1033 | - ) |
|
| 1034 | - ) |
|
| 1035 | - || ( |
|
| 1036 | - // is it neither a class method NOR a standalone function? |
|
| 1037 | - ! method_exists($class, $method) |
|
| 1038 | - && ! function_exists($method) |
|
| 1039 | - ) |
|
| 1040 | - ) { |
|
| 1041 | - // user error msg |
|
| 1042 | - $error_msg = esc_html__( |
|
| 1043 | - 'An error occurred. The requested page route could not be found.', |
|
| 1044 | - 'event_espresso' |
|
| 1045 | - ); |
|
| 1046 | - // developer error msg |
|
| 1047 | - $error_msg .= '||'; |
|
| 1048 | - $error_msg .= sprintf( |
|
| 1049 | - esc_html__( |
|
| 1050 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1051 | - 'event_espresso' |
|
| 1052 | - ), |
|
| 1053 | - $method |
|
| 1054 | - ); |
|
| 1055 | - } |
|
| 1056 | - if (! empty($error_msg)) { |
|
| 1057 | - throw new EE_Error($error_msg); |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1061 | - // then we need to reset the routing properties to the new route. |
|
| 1062 | - // 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. |
|
| 1063 | - if ( |
|
| 1064 | - $this->_is_UI_request === false |
|
| 1065 | - && is_array($this->_route) |
|
| 1066 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1067 | - ) { |
|
| 1068 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - |
|
| 1073 | - /** |
|
| 1074 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1075 | - * route redirects to a headers route in its route config. |
|
| 1076 | - * |
|
| 1077 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1078 | - * @return void |
|
| 1079 | - * @throws ReflectionException |
|
| 1080 | - * @throws InvalidArgumentException |
|
| 1081 | - * @throws InvalidInterfaceException |
|
| 1082 | - * @throws InvalidDataTypeException |
|
| 1083 | - * @throws EE_Error |
|
| 1084 | - * @since 4.3.0 |
|
| 1085 | - */ |
|
| 1086 | - protected function _reset_routing_properties($new_route) |
|
| 1087 | - { |
|
| 1088 | - $this->_is_UI_request = true; |
|
| 1089 | - // now we set the current route to whatever the headers_sent_route is set at |
|
| 1090 | - $this->request->setRequestParam('action', $new_route); |
|
| 1091 | - // rerun page setup |
|
| 1092 | - $this->_page_setup(); |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * _add_query_arg |
|
| 1098 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1099 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1100 | - * |
|
| 1101 | - * @param array $args |
|
| 1102 | - * @param string $url |
|
| 1103 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1104 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1105 | - * Example usage: If the current page is: |
|
| 1106 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1107 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1108 | - * &_wpnonce=5467821 |
|
| 1109 | - * and you call: |
|
| 1110 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1111 | - * array( |
|
| 1112 | - * 'action' => 'resend_something', |
|
| 1113 | - * 'page=>espresso_registrations' |
|
| 1114 | - * ), |
|
| 1115 | - * $some_url, |
|
| 1116 | - * true |
|
| 1117 | - * ); |
|
| 1118 | - * It will produce a url in this structure: |
|
| 1119 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1120 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1121 | - * month_range]=March%202015 |
|
| 1122 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1123 | - * @return string |
|
| 1124 | - */ |
|
| 1125 | - public static function add_query_args_and_nonce( |
|
| 1126 | - $args = [], |
|
| 1127 | - $url = false, |
|
| 1128 | - $sticky = false, |
|
| 1129 | - $exclude_nonce = false |
|
| 1130 | - ) { |
|
| 1131 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1132 | - if ($sticky) { |
|
| 1133 | - /** @var RequestInterface $request */ |
|
| 1134 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1135 | - $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']); |
|
| 1136 | - foreach ($request->requestParams() as $key => $value) { |
|
| 1137 | - // do not add nonces |
|
| 1138 | - if (strpos($key, 'nonce') !== false) { |
|
| 1139 | - continue; |
|
| 1140 | - } |
|
| 1141 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1142 | - } |
|
| 1143 | - } |
|
| 1144 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - |
|
| 1148 | - /** |
|
| 1149 | - * This returns a generated link that will load the related help tab. |
|
| 1150 | - * |
|
| 1151 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1152 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1153 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1154 | - * @return string generated link |
|
| 1155 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1156 | - */ |
|
| 1157 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1158 | - { |
|
| 1159 | - return EEH_Template::get_help_tab_link( |
|
| 1160 | - $help_tab_id, |
|
| 1161 | - $this->page_slug, |
|
| 1162 | - $this->_req_action, |
|
| 1163 | - $icon_style, |
|
| 1164 | - $help_text |
|
| 1165 | - ); |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * _add_help_tabs |
|
| 1171 | - * Note child classes define their help tabs within the page_config array. |
|
| 1172 | - * |
|
| 1173 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1174 | - * @return void |
|
| 1175 | - * @throws DomainException |
|
| 1176 | - * @throws EE_Error |
|
| 1177 | - */ |
|
| 1178 | - protected function _add_help_tabs() |
|
| 1179 | - { |
|
| 1180 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1181 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1182 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1183 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1184 | - // check that the callback given is valid |
|
| 1185 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1186 | - throw new EE_Error( |
|
| 1187 | - sprintf( |
|
| 1188 | - esc_html__( |
|
| 1189 | - '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', |
|
| 1190 | - 'event_espresso' |
|
| 1191 | - ), |
|
| 1192 | - $config['help_sidebar'], |
|
| 1193 | - get_class($this) |
|
| 1194 | - ) |
|
| 1195 | - ); |
|
| 1196 | - } |
|
| 1197 | - $content = apply_filters( |
|
| 1198 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1199 | - $this->{$config['help_sidebar']}() |
|
| 1200 | - ); |
|
| 1201 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1202 | - } |
|
| 1203 | - if (! isset($config['help_tabs'])) { |
|
| 1204 | - return; |
|
| 1205 | - } //no help tabs for this route |
|
| 1206 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1207 | - // we're here so there ARE help tabs! |
|
| 1208 | - // make sure we've got what we need |
|
| 1209 | - if (! isset($cfg['title'])) { |
|
| 1210 | - throw new EE_Error( |
|
| 1211 | - esc_html__( |
|
| 1212 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1213 | - 'event_espresso' |
|
| 1214 | - ) |
|
| 1215 | - ); |
|
| 1216 | - } |
|
| 1217 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1218 | - throw new EE_Error( |
|
| 1219 | - esc_html__( |
|
| 1220 | - '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', |
|
| 1221 | - 'event_espresso' |
|
| 1222 | - ) |
|
| 1223 | - ); |
|
| 1224 | - } |
|
| 1225 | - // first priority goes to content. |
|
| 1226 | - if (! empty($cfg['content'])) { |
|
| 1227 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1228 | - // second priority goes to filename |
|
| 1229 | - } elseif (! empty($cfg['filename'])) { |
|
| 1230 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1231 | - // 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) |
|
| 1232 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1233 | - . basename($this->_get_dir()) |
|
| 1234 | - . '/help_tabs/' |
|
| 1235 | - . $cfg['filename'] |
|
| 1236 | - . '.help_tab.php' : $file_path; |
|
| 1237 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1238 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1239 | - EE_Error::add_error( |
|
| 1240 | - sprintf( |
|
| 1241 | - esc_html__( |
|
| 1242 | - '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', |
|
| 1243 | - 'event_espresso' |
|
| 1244 | - ), |
|
| 1245 | - $tab_id, |
|
| 1246 | - key($config), |
|
| 1247 | - $file_path |
|
| 1248 | - ), |
|
| 1249 | - __FILE__, |
|
| 1250 | - __FUNCTION__, |
|
| 1251 | - __LINE__ |
|
| 1252 | - ); |
|
| 1253 | - return; |
|
| 1254 | - } |
|
| 1255 | - $template_args['admin_page_obj'] = $this; |
|
| 1256 | - $content = EEH_Template::display_template( |
|
| 1257 | - $file_path, |
|
| 1258 | - $template_args, |
|
| 1259 | - true |
|
| 1260 | - ); |
|
| 1261 | - } else { |
|
| 1262 | - $content = ''; |
|
| 1263 | - } |
|
| 1264 | - // check if callback is valid |
|
| 1265 | - if ( |
|
| 1266 | - empty($content) |
|
| 1267 | - && ( |
|
| 1268 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1269 | - ) |
|
| 1270 | - ) { |
|
| 1271 | - EE_Error::add_error( |
|
| 1272 | - sprintf( |
|
| 1273 | - esc_html__( |
|
| 1274 | - '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.', |
|
| 1275 | - 'event_espresso' |
|
| 1276 | - ), |
|
| 1277 | - $cfg['title'] |
|
| 1278 | - ), |
|
| 1279 | - __FILE__, |
|
| 1280 | - __FUNCTION__, |
|
| 1281 | - __LINE__ |
|
| 1282 | - ); |
|
| 1283 | - return; |
|
| 1284 | - } |
|
| 1285 | - // setup config array for help tab method |
|
| 1286 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1287 | - $_ht = [ |
|
| 1288 | - 'id' => $id, |
|
| 1289 | - 'title' => $cfg['title'], |
|
| 1290 | - 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1291 | - 'content' => $content, |
|
| 1292 | - ]; |
|
| 1293 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1294 | - } |
|
| 1295 | - } |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - |
|
| 1299 | - /** |
|
| 1300 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1301 | - * |
|
| 1302 | - * @return void |
|
| 1303 | - */ |
|
| 1304 | - protected function _add_qtips() |
|
| 1305 | - { |
|
| 1306 | - if (isset($this->_route_config['qtips'])) { |
|
| 1307 | - $qtips = (array) $this->_route_config['qtips']; |
|
| 1308 | - // load qtip loader |
|
| 1309 | - $path = [ |
|
| 1310 | - $this->_get_dir() . '/qtips/', |
|
| 1311 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1312 | - ]; |
|
| 1313 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * _set_nav_tabs |
|
| 1320 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1321 | - * wish to add additional tabs or modify accordingly. |
|
| 1322 | - * |
|
| 1323 | - * @return void |
|
| 1324 | - * @throws InvalidArgumentException |
|
| 1325 | - * @throws InvalidInterfaceException |
|
| 1326 | - * @throws InvalidDataTypeException |
|
| 1327 | - */ |
|
| 1328 | - protected function _set_nav_tabs() |
|
| 1329 | - { |
|
| 1330 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1331 | - $i = 0; |
|
| 1332 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1333 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1334 | - continue; |
|
| 1335 | - } |
|
| 1336 | - // no nav tab for this config |
|
| 1337 | - // check for persistent flag |
|
| 1338 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1339 | - // nav tab is only to appear when route requested. |
|
| 1340 | - continue; |
|
| 1341 | - } |
|
| 1342 | - if (! $this->check_user_access($slug, true)) { |
|
| 1343 | - // no nav tab because current user does not have access. |
|
| 1344 | - continue; |
|
| 1345 | - } |
|
| 1346 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1347 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1348 | - 'url' => isset($config['nav']['url']) |
|
| 1349 | - ? $config['nav']['url'] |
|
| 1350 | - : self::add_query_args_and_nonce( |
|
| 1351 | - ['action' => $slug], |
|
| 1352 | - $this->_admin_base_url |
|
| 1353 | - ), |
|
| 1354 | - 'link_text' => isset($config['nav']['label']) |
|
| 1355 | - ? $config['nav']['label'] |
|
| 1356 | - : ucwords( |
|
| 1357 | - str_replace('_', ' ', $slug) |
|
| 1358 | - ), |
|
| 1359 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1360 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1361 | - ]; |
|
| 1362 | - $i++; |
|
| 1363 | - } |
|
| 1364 | - // if $this->_nav_tabs is empty then lets set the default |
|
| 1365 | - if (empty($this->_nav_tabs)) { |
|
| 1366 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1367 | - 'url' => $this->_admin_base_url, |
|
| 1368 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1369 | - 'css_class' => 'nav-tab-active', |
|
| 1370 | - 'order' => 10, |
|
| 1371 | - ]; |
|
| 1372 | - } |
|
| 1373 | - // now let's sort the tabs according to order |
|
| 1374 | - usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * _set_current_labels |
|
| 1380 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1381 | - * property array |
|
| 1382 | - * |
|
| 1383 | - * @return void |
|
| 1384 | - */ |
|
| 1385 | - private function _set_current_labels() |
|
| 1386 | - { |
|
| 1387 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1388 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1389 | - if (is_array($text)) { |
|
| 1390 | - foreach ($text as $sublabel => $subtext) { |
|
| 1391 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1392 | - } |
|
| 1393 | - } else { |
|
| 1394 | - $this->_labels[ $label ] = $text; |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * verifies user access for this admin page |
|
| 1403 | - * |
|
| 1404 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1405 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1406 | - * return false if verify fail. |
|
| 1407 | - * @return bool |
|
| 1408 | - * @throws InvalidArgumentException |
|
| 1409 | - * @throws InvalidDataTypeException |
|
| 1410 | - * @throws InvalidInterfaceException |
|
| 1411 | - */ |
|
| 1412 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1413 | - { |
|
| 1414 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1415 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1416 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1417 | - && is_array( |
|
| 1418 | - $this->_page_routes[ $route_to_check ] |
|
| 1419 | - ) |
|
| 1420 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1421 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1422 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1423 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1424 | - : $this->_route['capability']; |
|
| 1425 | - } else { |
|
| 1426 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1427 | - } |
|
| 1428 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1429 | - if ( |
|
| 1430 | - ! $this->request->isAjax() |
|
| 1431 | - && ( |
|
| 1432 | - ! function_exists('is_admin') |
|
| 1433 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1434 | - $capability, |
|
| 1435 | - $this->page_slug |
|
| 1436 | - . '_' |
|
| 1437 | - . $route_to_check, |
|
| 1438 | - $id |
|
| 1439 | - ) |
|
| 1440 | - ) |
|
| 1441 | - ) { |
|
| 1442 | - if ($verify_only) { |
|
| 1443 | - return false; |
|
| 1444 | - } |
|
| 1445 | - if (is_user_logged_in()) { |
|
| 1446 | - wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1447 | - } else { |
|
| 1448 | - return false; |
|
| 1449 | - } |
|
| 1450 | - } |
|
| 1451 | - return true; |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - |
|
| 1455 | - /** |
|
| 1456 | - * admin_init_global |
|
| 1457 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1458 | - * This method executes for ALL EE Admin pages. |
|
| 1459 | - * |
|
| 1460 | - * @return void |
|
| 1461 | - */ |
|
| 1462 | - public function admin_init_global() |
|
| 1463 | - { |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * wp_loaded_global |
|
| 1469 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1470 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1471 | - * |
|
| 1472 | - * @return void |
|
| 1473 | - */ |
|
| 1474 | - public function wp_loaded() |
|
| 1475 | - { |
|
| 1476 | - } |
|
| 1477 | - |
|
| 1478 | - |
|
| 1479 | - /** |
|
| 1480 | - * admin_notices |
|
| 1481 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1482 | - * ALL EE_Admin pages. |
|
| 1483 | - * |
|
| 1484 | - * @return void |
|
| 1485 | - */ |
|
| 1486 | - public function admin_notices_global() |
|
| 1487 | - { |
|
| 1488 | - $this->_display_no_javascript_warning(); |
|
| 1489 | - $this->_display_espresso_notices(); |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - |
|
| 1493 | - public function network_admin_notices_global() |
|
| 1494 | - { |
|
| 1495 | - $this->_display_no_javascript_warning(); |
|
| 1496 | - $this->_display_espresso_notices(); |
|
| 1497 | - } |
|
| 1498 | - |
|
| 1499 | - |
|
| 1500 | - /** |
|
| 1501 | - * admin_footer_scripts_global |
|
| 1502 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1503 | - * will apply on ALL EE_Admin pages. |
|
| 1504 | - * |
|
| 1505 | - * @return void |
|
| 1506 | - */ |
|
| 1507 | - public function admin_footer_scripts_global() |
|
| 1508 | - { |
|
| 1509 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1510 | - $this->_add_admin_page_overlay(); |
|
| 1511 | - // if metaboxes are present we need to add the nonce field |
|
| 1512 | - if ( |
|
| 1513 | - isset($this->_route_config['metaboxes']) |
|
| 1514 | - || isset($this->_route_config['list_table']) |
|
| 1515 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1516 | - ) { |
|
| 1517 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1518 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1519 | - } |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * admin_footer_global |
|
| 1525 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1526 | - * ALL EE_Admin Pages. |
|
| 1527 | - * |
|
| 1528 | - * @return void |
|
| 1529 | - */ |
|
| 1530 | - public function admin_footer_global() |
|
| 1531 | - { |
|
| 1532 | - // dialog container for dialog helper |
|
| 1533 | - echo ' |
|
| 111 | + /** |
|
| 112 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 113 | + * actions. |
|
| 114 | + * |
|
| 115 | + * @since 4.6.x |
|
| 116 | + * @var array. |
|
| 117 | + */ |
|
| 118 | + protected $_default_route_query_args; |
|
| 119 | + |
|
| 120 | + // set via request page and action args. |
|
| 121 | + protected $_current_page; |
|
| 122 | + |
|
| 123 | + protected $_current_view; |
|
| 124 | + |
|
| 125 | + protected $_current_page_view_url; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * unprocessed value for the 'action' request param (default '') |
|
| 129 | + * |
|
| 130 | + * @var string |
|
| 131 | + */ |
|
| 132 | + protected $raw_req_action = ''; |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * unprocessed value for the 'page' request param (default '') |
|
| 136 | + * |
|
| 137 | + * @var string |
|
| 138 | + */ |
|
| 139 | + protected $raw_req_page = ''; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * sanitized request action (and nonce) |
|
| 143 | + * |
|
| 144 | + * @var string |
|
| 145 | + */ |
|
| 146 | + protected $_req_action = ''; |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * sanitized request action nonce |
|
| 150 | + * |
|
| 151 | + * @var string |
|
| 152 | + */ |
|
| 153 | + protected $_req_nonce = ''; |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @var string |
|
| 157 | + */ |
|
| 158 | + protected $_search_btn_label = ''; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @var string |
|
| 162 | + */ |
|
| 163 | + protected $_search_box_callback = ''; |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @var WP_Screen |
|
| 167 | + */ |
|
| 168 | + protected $_current_screen; |
|
| 169 | + |
|
| 170 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 171 | + protected $_hook_obj; |
|
| 172 | + |
|
| 173 | + // for holding incoming request data |
|
| 174 | + protected $_req_data = []; |
|
| 175 | + |
|
| 176 | + // yes / no array for admin form fields |
|
| 177 | + protected $_yes_no_values = []; |
|
| 178 | + |
|
| 179 | + // some default things shared by all child classes |
|
| 180 | + protected $_default_espresso_metaboxes; |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @var EE_Registry |
|
| 184 | + */ |
|
| 185 | + protected $EE = null; |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 190 | + * |
|
| 191 | + * @var boolean |
|
| 192 | + */ |
|
| 193 | + protected $_is_caf = false; |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @Constructor |
|
| 198 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 199 | + * @throws EE_Error |
|
| 200 | + * @throws InvalidArgumentException |
|
| 201 | + * @throws ReflectionException |
|
| 202 | + * @throws InvalidDataTypeException |
|
| 203 | + * @throws InvalidInterfaceException |
|
| 204 | + */ |
|
| 205 | + public function __construct($routing = true) |
|
| 206 | + { |
|
| 207 | + $this->loader = LoaderFactory::getLoader(); |
|
| 208 | + $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 209 | + $this->_routing = $routing; |
|
| 210 | + |
|
| 211 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 212 | + $this->_is_caf = true; |
|
| 213 | + } |
|
| 214 | + $this->_yes_no_values = [ |
|
| 215 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 216 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 217 | + ]; |
|
| 218 | + // set the _req_data property. |
|
| 219 | + $this->_req_data = $this->request->requestParams(); |
|
| 220 | + // set initial page props (child method) |
|
| 221 | + $this->_init_page_props(); |
|
| 222 | + // set global defaults |
|
| 223 | + $this->_set_defaults(); |
|
| 224 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 225 | + $this->_global_ajax_hooks(); |
|
| 226 | + $this->_ajax_hooks(); |
|
| 227 | + // other_page_hooks have to be early too. |
|
| 228 | + $this->_do_other_page_hooks(); |
|
| 229 | + // set up page dependencies |
|
| 230 | + $this->_before_page_setup(); |
|
| 231 | + $this->_page_setup(); |
|
| 232 | + // die(); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * _init_page_props |
|
| 238 | + * Child classes use to set at least the following properties: |
|
| 239 | + * $page_slug. |
|
| 240 | + * $page_label. |
|
| 241 | + * |
|
| 242 | + * @abstract |
|
| 243 | + * @return void |
|
| 244 | + */ |
|
| 245 | + abstract protected function _init_page_props(); |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * _ajax_hooks |
|
| 250 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 251 | + * Note: within the ajax callback methods. |
|
| 252 | + * |
|
| 253 | + * @abstract |
|
| 254 | + * @return void |
|
| 255 | + */ |
|
| 256 | + abstract protected function _ajax_hooks(); |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * _define_page_props |
|
| 261 | + * child classes define page properties in here. Must include at least: |
|
| 262 | + * $_admin_base_url = base_url for all admin pages |
|
| 263 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 264 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 265 | + * array( |
|
| 266 | + * 'buttons' => array( |
|
| 267 | + * 'add' => esc_html__('label for add new button'), |
|
| 268 | + * 'edit' => esc_html__('label for edit button'), |
|
| 269 | + * 'delete' => esc_html__('label for delete button') |
|
| 270 | + * ) |
|
| 271 | + * ) |
|
| 272 | + * |
|
| 273 | + * @abstract |
|
| 274 | + * @return void |
|
| 275 | + */ |
|
| 276 | + abstract protected function _define_page_props(); |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * _set_page_routes |
|
| 281 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 282 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 283 | + * have a 'default' route. Here's the format |
|
| 284 | + * $this->_page_routes = array( |
|
| 285 | + * 'default' => array( |
|
| 286 | + * 'func' => '_default_method_handling_route', |
|
| 287 | + * 'args' => array('array','of','args'), |
|
| 288 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 289 | + * ajax request, backend processing) |
|
| 290 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 291 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 292 | + * headers sent route. |
|
| 293 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 294 | + * this route. |
|
| 295 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 296 | + * checks). |
|
| 297 | + * ), |
|
| 298 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 299 | + * handling method. |
|
| 300 | + * ) |
|
| 301 | + * ) |
|
| 302 | + * |
|
| 303 | + * @abstract |
|
| 304 | + * @return void |
|
| 305 | + */ |
|
| 306 | + abstract protected function _set_page_routes(); |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * _set_page_config |
|
| 311 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 312 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 313 | + * $this->_page_config = array( |
|
| 314 | + * 'default' => array( |
|
| 315 | + * 'labels' => array( |
|
| 316 | + * 'buttons' => array( |
|
| 317 | + * 'add' => esc_html__('label for adding item'), |
|
| 318 | + * 'edit' => esc_html__('label for editing item'), |
|
| 319 | + * 'delete' => esc_html__('label for deleting item') |
|
| 320 | + * ), |
|
| 321 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 322 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 323 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 324 | + * _define_page_props() method |
|
| 325 | + * 'nav' => array( |
|
| 326 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 327 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 328 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 329 | + * 'order' => 10, //required to indicate tab position. |
|
| 330 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 331 | + * displayed then add this parameter. |
|
| 332 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 333 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 334 | + * metaboxes set for eventespresso admin pages. |
|
| 335 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 336 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 337 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 338 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 339 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 340 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 341 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 342 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 343 | + * want to display. |
|
| 344 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 345 | + * 'tab_id' => array( |
|
| 346 | + * 'title' => 'tab_title', |
|
| 347 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 348 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 349 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 350 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 351 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 352 | + * attempt to use the callback which should match the name of a method in the class |
|
| 353 | + * ), |
|
| 354 | + * 'tab2_id' => array( |
|
| 355 | + * 'title' => 'tab2 title', |
|
| 356 | + * 'filename' => 'file_name_2' |
|
| 357 | + * 'callback' => 'callback_method_for_content', |
|
| 358 | + * ), |
|
| 359 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 360 | + * help tab area on an admin page. @return void |
|
| 361 | + * |
|
| 362 | + * @abstract |
|
| 363 | + */ |
|
| 364 | + abstract protected function _set_page_config(); |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * _add_screen_options |
|
| 369 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 370 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 371 | + * to a particular view. |
|
| 372 | + * |
|
| 373 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 374 | + * see also WP_Screen object documents... |
|
| 375 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 376 | + * @abstract |
|
| 377 | + * @return void |
|
| 378 | + */ |
|
| 379 | + abstract protected function _add_screen_options(); |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * _add_feature_pointers |
|
| 384 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 385 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 386 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 387 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 388 | + * extended) also see: |
|
| 389 | + * |
|
| 390 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 391 | + * @abstract |
|
| 392 | + * @return void |
|
| 393 | + */ |
|
| 394 | + abstract protected function _add_feature_pointers(); |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * load_scripts_styles |
|
| 399 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 400 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 401 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 402 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 403 | + * |
|
| 404 | + * @abstract |
|
| 405 | + * @return void |
|
| 406 | + */ |
|
| 407 | + abstract public function load_scripts_styles(); |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * admin_init |
|
| 412 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 413 | + * all pages/views loaded by child class. |
|
| 414 | + * |
|
| 415 | + * @abstract |
|
| 416 | + * @return void |
|
| 417 | + */ |
|
| 418 | + abstract public function admin_init(); |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * admin_notices |
|
| 423 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 424 | + * all pages/views loaded by child class. |
|
| 425 | + * |
|
| 426 | + * @abstract |
|
| 427 | + * @return void |
|
| 428 | + */ |
|
| 429 | + abstract public function admin_notices(); |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * admin_footer_scripts |
|
| 434 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 435 | + * will apply to all pages/views loaded by child class. |
|
| 436 | + * |
|
| 437 | + * @return void |
|
| 438 | + */ |
|
| 439 | + abstract public function admin_footer_scripts(); |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * admin_footer |
|
| 444 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 445 | + * apply to all pages/views loaded by child class. |
|
| 446 | + * |
|
| 447 | + * @return void |
|
| 448 | + */ |
|
| 449 | + public function admin_footer() |
|
| 450 | + { |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * _global_ajax_hooks |
|
| 456 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 457 | + * Note: within the ajax callback methods. |
|
| 458 | + * |
|
| 459 | + * @abstract |
|
| 460 | + * @return void |
|
| 461 | + */ |
|
| 462 | + protected function _global_ajax_hooks() |
|
| 463 | + { |
|
| 464 | + // for lazy loading of metabox content |
|
| 465 | + add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + public function ajax_metabox_content() |
|
| 470 | + { |
|
| 471 | + $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 472 | + $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 473 | + self::cached_rss_display($content_id, $content_url); |
|
| 474 | + wp_die(); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 480 | + * |
|
| 481 | + * @return void |
|
| 482 | + */ |
|
| 483 | + protected function _before_page_setup() |
|
| 484 | + { |
|
| 485 | + // default is to do nothing |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Makes sure any things that need to be loaded early get handled. |
|
| 491 | + * We also escape early here if the page requested doesn't match the object. |
|
| 492 | + * |
|
| 493 | + * @final |
|
| 494 | + * @return void |
|
| 495 | + * @throws EE_Error |
|
| 496 | + * @throws InvalidArgumentException |
|
| 497 | + * @throws ReflectionException |
|
| 498 | + * @throws InvalidDataTypeException |
|
| 499 | + * @throws InvalidInterfaceException |
|
| 500 | + */ |
|
| 501 | + final protected function _page_setup() |
|
| 502 | + { |
|
| 503 | + // requires? |
|
| 504 | + // admin_init stuff - global - we're setting this REALLY early |
|
| 505 | + // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 506 | + // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 507 | + add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 508 | + // next verify if we need to load anything... |
|
| 509 | + $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 510 | + $this->page_folder = strtolower( |
|
| 511 | + str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
| 512 | + ); |
|
| 513 | + global $ee_menu_slugs; |
|
| 514 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 515 | + if ( |
|
| 516 | + ! $this->request->isAjax() |
|
| 517 | + && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 518 | + ) { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 521 | + // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 522 | + // we need to copy the action from the second to the first |
|
| 523 | + $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 524 | + $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 525 | + $action = $action !== '-1' ? $action : $action2; |
|
| 526 | + $req_action = $action !== '-1' ? $action : 'default'; |
|
| 527 | + |
|
| 528 | + // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 529 | + // then let's use the route as the action. |
|
| 530 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 531 | + $route = $this->request->getRequestParam('route'); |
|
| 532 | + $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 533 | + ? $route |
|
| 534 | + : $req_action; |
|
| 535 | + |
|
| 536 | + $this->_current_view = $this->_req_action; |
|
| 537 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 538 | + $this->_define_page_props(); |
|
| 539 | + $this->_current_page_view_url = add_query_arg( |
|
| 540 | + ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 541 | + $this->_admin_base_url |
|
| 542 | + ); |
|
| 543 | + // default things |
|
| 544 | + $this->_default_espresso_metaboxes = [ |
|
| 545 | + '_espresso_news_post_box', |
|
| 546 | + '_espresso_links_post_box', |
|
| 547 | + '_espresso_ratings_request', |
|
| 548 | + '_espresso_sponsors_post_box', |
|
| 549 | + ]; |
|
| 550 | + // set page configs |
|
| 551 | + $this->_set_page_routes(); |
|
| 552 | + $this->_set_page_config(); |
|
| 553 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 554 | + if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 555 | + $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 556 | + if ($wp_referer) { |
|
| 557 | + $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + // for caffeinated and other extended functionality. |
|
| 561 | + // If there is a _extend_page_config method |
|
| 562 | + // then let's run that to modify the all the various page configuration arrays |
|
| 563 | + if (method_exists($this, '_extend_page_config')) { |
|
| 564 | + $this->_extend_page_config(); |
|
| 565 | + } |
|
| 566 | + // for CPT and other extended functionality. |
|
| 567 | + // If there is an _extend_page_config_for_cpt |
|
| 568 | + // then let's run that to modify all the various page configuration arrays. |
|
| 569 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 570 | + $this->_extend_page_config_for_cpt(); |
|
| 571 | + } |
|
| 572 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 573 | + $this->_page_routes = apply_filters( |
|
| 574 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 575 | + $this->_page_routes, |
|
| 576 | + $this |
|
| 577 | + ); |
|
| 578 | + $this->_page_config = apply_filters( |
|
| 579 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 580 | + $this->_page_config, |
|
| 581 | + $this |
|
| 582 | + ); |
|
| 583 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 584 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 585 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 586 | + add_action( |
|
| 587 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 588 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 589 | + 10, |
|
| 590 | + 2 |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + // next route only if routing enabled |
|
| 594 | + if ($this->_routing && ! $this->request->isAjax()) { |
|
| 595 | + $this->_verify_routes(); |
|
| 596 | + // next let's just check user_access and kill if no access |
|
| 597 | + $this->check_user_access(); |
|
| 598 | + if ($this->_is_UI_request) { |
|
| 599 | + // admin_init stuff - global, all views for this page class, specific view |
|
| 600 | + add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 601 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 602 | + add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 603 | + } |
|
| 604 | + } else { |
|
| 605 | + // hijack regular WP loading and route admin request immediately |
|
| 606 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 607 | + $this->route_admin_request(); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 615 | + * |
|
| 616 | + * @return void |
|
| 617 | + * @throws EE_Error |
|
| 618 | + */ |
|
| 619 | + private function _do_other_page_hooks() |
|
| 620 | + { |
|
| 621 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 622 | + foreach ($registered_pages as $page) { |
|
| 623 | + // now let's setup the file name and class that should be present |
|
| 624 | + $classname = str_replace('.class.php', '', $page); |
|
| 625 | + // autoloaders should take care of loading file |
|
| 626 | + if (! class_exists($classname)) { |
|
| 627 | + $error_msg[] = sprintf( |
|
| 628 | + esc_html__( |
|
| 629 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 630 | + 'event_espresso' |
|
| 631 | + ), |
|
| 632 | + $page |
|
| 633 | + ); |
|
| 634 | + $error_msg[] = $error_msg[0] |
|
| 635 | + . "\r\n" |
|
| 636 | + . sprintf( |
|
| 637 | + esc_html__( |
|
| 638 | + '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', |
|
| 639 | + 'event_espresso' |
|
| 640 | + ), |
|
| 641 | + $page, |
|
| 642 | + '<br />', |
|
| 643 | + '<strong>' . $classname . '</strong>' |
|
| 644 | + ); |
|
| 645 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 646 | + } |
|
| 647 | + // notice we are passing the instance of this class to the hook object. |
|
| 648 | + $this->loader->getShared($classname, [$this]); |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * @throws ReflectionException |
|
| 655 | + * @throws EE_Error |
|
| 656 | + */ |
|
| 657 | + public function load_page_dependencies() |
|
| 658 | + { |
|
| 659 | + try { |
|
| 660 | + $this->_load_page_dependencies(); |
|
| 661 | + } catch (EE_Error $e) { |
|
| 662 | + $e->get_error(); |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * load_page_dependencies |
|
| 669 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 670 | + * |
|
| 671 | + * @return void |
|
| 672 | + * @throws DomainException |
|
| 673 | + * @throws EE_Error |
|
| 674 | + * @throws InvalidArgumentException |
|
| 675 | + * @throws InvalidDataTypeException |
|
| 676 | + * @throws InvalidInterfaceException |
|
| 677 | + */ |
|
| 678 | + protected function _load_page_dependencies() |
|
| 679 | + { |
|
| 680 | + // let's set the current_screen and screen options to override what WP set |
|
| 681 | + $this->_current_screen = get_current_screen(); |
|
| 682 | + // load admin_notices - global, page class, and view specific |
|
| 683 | + add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 684 | + add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 685 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 686 | + add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 687 | + } |
|
| 688 | + // load network admin_notices - global, page class, and view specific |
|
| 689 | + add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 690 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 691 | + add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 692 | + } |
|
| 693 | + // this will save any per_page screen options if they are present |
|
| 694 | + $this->_set_per_page_screen_options(); |
|
| 695 | + // setup list table properties |
|
| 696 | + $this->_set_list_table(); |
|
| 697 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 698 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 699 | + $this->_add_registered_meta_boxes(); |
|
| 700 | + $this->_add_screen_columns(); |
|
| 701 | + // add screen options - global, page child class, and view specific |
|
| 702 | + $this->_add_global_screen_options(); |
|
| 703 | + $this->_add_screen_options(); |
|
| 704 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 705 | + if (method_exists($this, $add_screen_options)) { |
|
| 706 | + $this->{$add_screen_options}(); |
|
| 707 | + } |
|
| 708 | + // add help tab(s) - set via page_config and qtips. |
|
| 709 | + $this->_add_help_tabs(); |
|
| 710 | + $this->_add_qtips(); |
|
| 711 | + // add feature_pointers - global, page child class, and view specific |
|
| 712 | + $this->_add_feature_pointers(); |
|
| 713 | + $this->_add_global_feature_pointers(); |
|
| 714 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 715 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 716 | + $this->{$add_feature_pointer}(); |
|
| 717 | + } |
|
| 718 | + // enqueue scripts/styles - global, page class, and view specific |
|
| 719 | + add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 720 | + add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 721 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 722 | + add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 723 | + } |
|
| 724 | + add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 725 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 726 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 727 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 728 | + // is a good use case. Notice the late priority we're giving these |
|
| 729 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 730 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 731 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 732 | + add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 733 | + } |
|
| 734 | + // admin footer scripts |
|
| 735 | + add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 736 | + add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 737 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 738 | + add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 739 | + } |
|
| 740 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 741 | + // targeted hook |
|
| 742 | + do_action( |
|
| 743 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 744 | + ); |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * _set_defaults |
|
| 750 | + * This sets some global defaults for class properties. |
|
| 751 | + */ |
|
| 752 | + private function _set_defaults() |
|
| 753 | + { |
|
| 754 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 755 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 756 | + $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 757 | + $this->_page_config = $this->_default_route_query_args = []; |
|
| 758 | + $this->_default_nav_tab_name = 'overview'; |
|
| 759 | + // init template args |
|
| 760 | + $this->_template_args = [ |
|
| 761 | + 'admin_page_header' => '', |
|
| 762 | + 'admin_page_content' => '', |
|
| 763 | + 'post_body_content' => '', |
|
| 764 | + 'before_list_table' => '', |
|
| 765 | + 'after_list_table' => '', |
|
| 766 | + ]; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * route_admin_request |
|
| 772 | + * |
|
| 773 | + * @return void |
|
| 774 | + * @throws InvalidArgumentException |
|
| 775 | + * @throws InvalidInterfaceException |
|
| 776 | + * @throws InvalidDataTypeException |
|
| 777 | + * @throws EE_Error |
|
| 778 | + * @throws ReflectionException |
|
| 779 | + * @see _route_admin_request() |
|
| 780 | + */ |
|
| 781 | + public function route_admin_request() |
|
| 782 | + { |
|
| 783 | + try { |
|
| 784 | + $this->_route_admin_request(); |
|
| 785 | + } catch (EE_Error $e) { |
|
| 786 | + $e->get_error(); |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + public function set_wp_page_slug($wp_page_slug) |
|
| 792 | + { |
|
| 793 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 794 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 795 | + if (is_network_admin()) { |
|
| 796 | + $this->_wp_page_slug .= '-network'; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * _verify_routes |
|
| 803 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 804 | + * we know if we need to drop out. |
|
| 805 | + * |
|
| 806 | + * @return bool |
|
| 807 | + * @throws EE_Error |
|
| 808 | + */ |
|
| 809 | + protected function _verify_routes() |
|
| 810 | + { |
|
| 811 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 812 | + if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 813 | + return false; |
|
| 814 | + } |
|
| 815 | + $this->_route = false; |
|
| 816 | + // check that the page_routes array is not empty |
|
| 817 | + if (empty($this->_page_routes)) { |
|
| 818 | + // user error msg |
|
| 819 | + $error_msg = sprintf( |
|
| 820 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 821 | + $this->_admin_page_title |
|
| 822 | + ); |
|
| 823 | + // developer error msg |
|
| 824 | + $error_msg .= '||' . $error_msg |
|
| 825 | + . esc_html__( |
|
| 826 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 827 | + 'event_espresso' |
|
| 828 | + ); |
|
| 829 | + throw new EE_Error($error_msg); |
|
| 830 | + } |
|
| 831 | + // and that the requested page route exists |
|
| 832 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 833 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 834 | + $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 835 | + ? $this->_page_config[ $this->_req_action ] |
|
| 836 | + : []; |
|
| 837 | + } else { |
|
| 838 | + // user error msg |
|
| 839 | + $error_msg = sprintf( |
|
| 840 | + esc_html__( |
|
| 841 | + 'The requested page route does not exist for the %s admin page.', |
|
| 842 | + 'event_espresso' |
|
| 843 | + ), |
|
| 844 | + $this->_admin_page_title |
|
| 845 | + ); |
|
| 846 | + // developer error msg |
|
| 847 | + $error_msg .= '||' . $error_msg |
|
| 848 | + . sprintf( |
|
| 849 | + esc_html__( |
|
| 850 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 851 | + 'event_espresso' |
|
| 852 | + ), |
|
| 853 | + $this->_req_action |
|
| 854 | + ); |
|
| 855 | + throw new EE_Error($error_msg); |
|
| 856 | + } |
|
| 857 | + // and that a default route exists |
|
| 858 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 859 | + // user error msg |
|
| 860 | + $error_msg = sprintf( |
|
| 861 | + esc_html__( |
|
| 862 | + 'A default page route has not been set for the % admin page.', |
|
| 863 | + 'event_espresso' |
|
| 864 | + ), |
|
| 865 | + $this->_admin_page_title |
|
| 866 | + ); |
|
| 867 | + // developer error msg |
|
| 868 | + $error_msg .= '||' . $error_msg |
|
| 869 | + . esc_html__( |
|
| 870 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 871 | + 'event_espresso' |
|
| 872 | + ); |
|
| 873 | + throw new EE_Error($error_msg); |
|
| 874 | + } |
|
| 875 | + // first lets' catch if the UI request has EVER been set. |
|
| 876 | + if ($this->_is_UI_request === null) { |
|
| 877 | + // lets set if this is a UI request or not. |
|
| 878 | + $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 879 | + // wait a minute... we might have a noheader in the route array |
|
| 880 | + $this->_is_UI_request = ! ( |
|
| 881 | + is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 882 | + ) |
|
| 883 | + ? $this->_is_UI_request |
|
| 884 | + : false; |
|
| 885 | + } |
|
| 886 | + $this->_set_current_labels(); |
|
| 887 | + return true; |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 893 | + * |
|
| 894 | + * @param string $route the route name we're verifying |
|
| 895 | + * @return bool we'll throw an exception if this isn't a valid route. |
|
| 896 | + * @throws EE_Error |
|
| 897 | + */ |
|
| 898 | + protected function _verify_route($route) |
|
| 899 | + { |
|
| 900 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 901 | + return true; |
|
| 902 | + } |
|
| 903 | + // user error msg |
|
| 904 | + $error_msg = sprintf( |
|
| 905 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 906 | + $this->_admin_page_title |
|
| 907 | + ); |
|
| 908 | + // developer error msg |
|
| 909 | + $error_msg .= '||' . $error_msg |
|
| 910 | + . sprintf( |
|
| 911 | + esc_html__( |
|
| 912 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 913 | + 'event_espresso' |
|
| 914 | + ), |
|
| 915 | + $route |
|
| 916 | + ); |
|
| 917 | + throw new EE_Error($error_msg); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * perform nonce verification |
|
| 923 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 924 | + * using this method (and save retyping!) |
|
| 925 | + * |
|
| 926 | + * @param string $nonce The nonce sent |
|
| 927 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 928 | + * @return void |
|
| 929 | + * @throws EE_Error |
|
| 930 | + */ |
|
| 931 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 932 | + { |
|
| 933 | + // verify nonce against expected value |
|
| 934 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 935 | + // these are not the droids you are looking for !!! |
|
| 936 | + $msg = sprintf( |
|
| 937 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 938 | + '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 939 | + '</a>' |
|
| 940 | + ); |
|
| 941 | + if (WP_DEBUG) { |
|
| 942 | + $msg .= "\n "; |
|
| 943 | + $msg .= sprintf( |
|
| 944 | + esc_html__( |
|
| 945 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 946 | + 'event_espresso' |
|
| 947 | + ), |
|
| 948 | + __CLASS__ |
|
| 949 | + ); |
|
| 950 | + } |
|
| 951 | + if (! $this->request->isAjax()) { |
|
| 952 | + wp_die($msg); |
|
| 953 | + } |
|
| 954 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 955 | + $this->_return_json(); |
|
| 956 | + } |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + |
|
| 960 | + /** |
|
| 961 | + * _route_admin_request() |
|
| 962 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 963 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 964 | + * in the page routes and then will try to load the corresponding method. |
|
| 965 | + * |
|
| 966 | + * @return void |
|
| 967 | + * @throws EE_Error |
|
| 968 | + * @throws InvalidArgumentException |
|
| 969 | + * @throws InvalidDataTypeException |
|
| 970 | + * @throws InvalidInterfaceException |
|
| 971 | + * @throws ReflectionException |
|
| 972 | + */ |
|
| 973 | + protected function _route_admin_request() |
|
| 974 | + { |
|
| 975 | + if (! $this->_is_UI_request) { |
|
| 976 | + $this->_verify_routes(); |
|
| 977 | + } |
|
| 978 | + $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 979 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 980 | + // set nonce from post data |
|
| 981 | + $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 982 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 983 | + } |
|
| 984 | + // set the nav_tabs array but ONLY if this is UI_request |
|
| 985 | + if ($this->_is_UI_request) { |
|
| 986 | + $this->_set_nav_tabs(); |
|
| 987 | + } |
|
| 988 | + // grab callback function |
|
| 989 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 990 | + // check if callback has args |
|
| 991 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 992 | + $error_msg = ''; |
|
| 993 | + // action right before calling route |
|
| 994 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 995 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 996 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 997 | + } |
|
| 998 | + // right before calling the route, let's clean the _wp_http_referer |
|
| 999 | + $this->request->setServerParam( |
|
| 1000 | + 'REQUEST_URI', |
|
| 1001 | + remove_query_arg( |
|
| 1002 | + '_wp_http_referer', |
|
| 1003 | + wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1004 | + ) |
|
| 1005 | + ); |
|
| 1006 | + if (! empty($func)) { |
|
| 1007 | + if (is_array($func)) { |
|
| 1008 | + [$class, $method] = $func; |
|
| 1009 | + } elseif (strpos($func, '::') !== false) { |
|
| 1010 | + [$class, $method] = explode('::', $func); |
|
| 1011 | + } else { |
|
| 1012 | + $class = $this; |
|
| 1013 | + $method = $func; |
|
| 1014 | + } |
|
| 1015 | + if (! (is_object($class) && $class === $this)) { |
|
| 1016 | + // send along this admin page object for access by addons. |
|
| 1017 | + $args['admin_page_object'] = $this; |
|
| 1018 | + } |
|
| 1019 | + if ( |
|
| 1020 | + // is it a method on a class that doesn't work? |
|
| 1021 | + ( |
|
| 1022 | + ( |
|
| 1023 | + method_exists($class, $method) |
|
| 1024 | + && call_user_func_array([$class, $method], $args) === false |
|
| 1025 | + ) |
|
| 1026 | + && ( |
|
| 1027 | + // is it a standalone function that doesn't work? |
|
| 1028 | + function_exists($method) |
|
| 1029 | + && call_user_func_array( |
|
| 1030 | + $func, |
|
| 1031 | + array_merge(['admin_page_object' => $this], $args) |
|
| 1032 | + ) === false |
|
| 1033 | + ) |
|
| 1034 | + ) |
|
| 1035 | + || ( |
|
| 1036 | + // is it neither a class method NOR a standalone function? |
|
| 1037 | + ! method_exists($class, $method) |
|
| 1038 | + && ! function_exists($method) |
|
| 1039 | + ) |
|
| 1040 | + ) { |
|
| 1041 | + // user error msg |
|
| 1042 | + $error_msg = esc_html__( |
|
| 1043 | + 'An error occurred. The requested page route could not be found.', |
|
| 1044 | + 'event_espresso' |
|
| 1045 | + ); |
|
| 1046 | + // developer error msg |
|
| 1047 | + $error_msg .= '||'; |
|
| 1048 | + $error_msg .= sprintf( |
|
| 1049 | + esc_html__( |
|
| 1050 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1051 | + 'event_espresso' |
|
| 1052 | + ), |
|
| 1053 | + $method |
|
| 1054 | + ); |
|
| 1055 | + } |
|
| 1056 | + if (! empty($error_msg)) { |
|
| 1057 | + throw new EE_Error($error_msg); |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1061 | + // then we need to reset the routing properties to the new route. |
|
| 1062 | + // 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. |
|
| 1063 | + if ( |
|
| 1064 | + $this->_is_UI_request === false |
|
| 1065 | + && is_array($this->_route) |
|
| 1066 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1067 | + ) { |
|
| 1068 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + |
|
| 1073 | + /** |
|
| 1074 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1075 | + * route redirects to a headers route in its route config. |
|
| 1076 | + * |
|
| 1077 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1078 | + * @return void |
|
| 1079 | + * @throws ReflectionException |
|
| 1080 | + * @throws InvalidArgumentException |
|
| 1081 | + * @throws InvalidInterfaceException |
|
| 1082 | + * @throws InvalidDataTypeException |
|
| 1083 | + * @throws EE_Error |
|
| 1084 | + * @since 4.3.0 |
|
| 1085 | + */ |
|
| 1086 | + protected function _reset_routing_properties($new_route) |
|
| 1087 | + { |
|
| 1088 | + $this->_is_UI_request = true; |
|
| 1089 | + // now we set the current route to whatever the headers_sent_route is set at |
|
| 1090 | + $this->request->setRequestParam('action', $new_route); |
|
| 1091 | + // rerun page setup |
|
| 1092 | + $this->_page_setup(); |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * _add_query_arg |
|
| 1098 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1099 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1100 | + * |
|
| 1101 | + * @param array $args |
|
| 1102 | + * @param string $url |
|
| 1103 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1104 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1105 | + * Example usage: If the current page is: |
|
| 1106 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1107 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1108 | + * &_wpnonce=5467821 |
|
| 1109 | + * and you call: |
|
| 1110 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1111 | + * array( |
|
| 1112 | + * 'action' => 'resend_something', |
|
| 1113 | + * 'page=>espresso_registrations' |
|
| 1114 | + * ), |
|
| 1115 | + * $some_url, |
|
| 1116 | + * true |
|
| 1117 | + * ); |
|
| 1118 | + * It will produce a url in this structure: |
|
| 1119 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1120 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1121 | + * month_range]=March%202015 |
|
| 1122 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1123 | + * @return string |
|
| 1124 | + */ |
|
| 1125 | + public static function add_query_args_and_nonce( |
|
| 1126 | + $args = [], |
|
| 1127 | + $url = false, |
|
| 1128 | + $sticky = false, |
|
| 1129 | + $exclude_nonce = false |
|
| 1130 | + ) { |
|
| 1131 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1132 | + if ($sticky) { |
|
| 1133 | + /** @var RequestInterface $request */ |
|
| 1134 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1135 | + $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']); |
|
| 1136 | + foreach ($request->requestParams() as $key => $value) { |
|
| 1137 | + // do not add nonces |
|
| 1138 | + if (strpos($key, 'nonce') !== false) { |
|
| 1139 | + continue; |
|
| 1140 | + } |
|
| 1141 | + $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1142 | + } |
|
| 1143 | + } |
|
| 1144 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + |
|
| 1148 | + /** |
|
| 1149 | + * This returns a generated link that will load the related help tab. |
|
| 1150 | + * |
|
| 1151 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1152 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1153 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1154 | + * @return string generated link |
|
| 1155 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1156 | + */ |
|
| 1157 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1158 | + { |
|
| 1159 | + return EEH_Template::get_help_tab_link( |
|
| 1160 | + $help_tab_id, |
|
| 1161 | + $this->page_slug, |
|
| 1162 | + $this->_req_action, |
|
| 1163 | + $icon_style, |
|
| 1164 | + $help_text |
|
| 1165 | + ); |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * _add_help_tabs |
|
| 1171 | + * Note child classes define their help tabs within the page_config array. |
|
| 1172 | + * |
|
| 1173 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1174 | + * @return void |
|
| 1175 | + * @throws DomainException |
|
| 1176 | + * @throws EE_Error |
|
| 1177 | + */ |
|
| 1178 | + protected function _add_help_tabs() |
|
| 1179 | + { |
|
| 1180 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1181 | + $config = $this->_page_config[ $this->_req_action ]; |
|
| 1182 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1183 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1184 | + // check that the callback given is valid |
|
| 1185 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1186 | + throw new EE_Error( |
|
| 1187 | + sprintf( |
|
| 1188 | + esc_html__( |
|
| 1189 | + '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', |
|
| 1190 | + 'event_espresso' |
|
| 1191 | + ), |
|
| 1192 | + $config['help_sidebar'], |
|
| 1193 | + get_class($this) |
|
| 1194 | + ) |
|
| 1195 | + ); |
|
| 1196 | + } |
|
| 1197 | + $content = apply_filters( |
|
| 1198 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1199 | + $this->{$config['help_sidebar']}() |
|
| 1200 | + ); |
|
| 1201 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1202 | + } |
|
| 1203 | + if (! isset($config['help_tabs'])) { |
|
| 1204 | + return; |
|
| 1205 | + } //no help tabs for this route |
|
| 1206 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1207 | + // we're here so there ARE help tabs! |
|
| 1208 | + // make sure we've got what we need |
|
| 1209 | + if (! isset($cfg['title'])) { |
|
| 1210 | + throw new EE_Error( |
|
| 1211 | + esc_html__( |
|
| 1212 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1213 | + 'event_espresso' |
|
| 1214 | + ) |
|
| 1215 | + ); |
|
| 1216 | + } |
|
| 1217 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1218 | + throw new EE_Error( |
|
| 1219 | + esc_html__( |
|
| 1220 | + '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', |
|
| 1221 | + 'event_espresso' |
|
| 1222 | + ) |
|
| 1223 | + ); |
|
| 1224 | + } |
|
| 1225 | + // first priority goes to content. |
|
| 1226 | + if (! empty($cfg['content'])) { |
|
| 1227 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1228 | + // second priority goes to filename |
|
| 1229 | + } elseif (! empty($cfg['filename'])) { |
|
| 1230 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1231 | + // 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) |
|
| 1232 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1233 | + . basename($this->_get_dir()) |
|
| 1234 | + . '/help_tabs/' |
|
| 1235 | + . $cfg['filename'] |
|
| 1236 | + . '.help_tab.php' : $file_path; |
|
| 1237 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1238 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1239 | + EE_Error::add_error( |
|
| 1240 | + sprintf( |
|
| 1241 | + esc_html__( |
|
| 1242 | + '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', |
|
| 1243 | + 'event_espresso' |
|
| 1244 | + ), |
|
| 1245 | + $tab_id, |
|
| 1246 | + key($config), |
|
| 1247 | + $file_path |
|
| 1248 | + ), |
|
| 1249 | + __FILE__, |
|
| 1250 | + __FUNCTION__, |
|
| 1251 | + __LINE__ |
|
| 1252 | + ); |
|
| 1253 | + return; |
|
| 1254 | + } |
|
| 1255 | + $template_args['admin_page_obj'] = $this; |
|
| 1256 | + $content = EEH_Template::display_template( |
|
| 1257 | + $file_path, |
|
| 1258 | + $template_args, |
|
| 1259 | + true |
|
| 1260 | + ); |
|
| 1261 | + } else { |
|
| 1262 | + $content = ''; |
|
| 1263 | + } |
|
| 1264 | + // check if callback is valid |
|
| 1265 | + if ( |
|
| 1266 | + empty($content) |
|
| 1267 | + && ( |
|
| 1268 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1269 | + ) |
|
| 1270 | + ) { |
|
| 1271 | + EE_Error::add_error( |
|
| 1272 | + sprintf( |
|
| 1273 | + esc_html__( |
|
| 1274 | + '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.', |
|
| 1275 | + 'event_espresso' |
|
| 1276 | + ), |
|
| 1277 | + $cfg['title'] |
|
| 1278 | + ), |
|
| 1279 | + __FILE__, |
|
| 1280 | + __FUNCTION__, |
|
| 1281 | + __LINE__ |
|
| 1282 | + ); |
|
| 1283 | + return; |
|
| 1284 | + } |
|
| 1285 | + // setup config array for help tab method |
|
| 1286 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1287 | + $_ht = [ |
|
| 1288 | + 'id' => $id, |
|
| 1289 | + 'title' => $cfg['title'], |
|
| 1290 | + 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1291 | + 'content' => $content, |
|
| 1292 | + ]; |
|
| 1293 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1294 | + } |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + |
|
| 1299 | + /** |
|
| 1300 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1301 | + * |
|
| 1302 | + * @return void |
|
| 1303 | + */ |
|
| 1304 | + protected function _add_qtips() |
|
| 1305 | + { |
|
| 1306 | + if (isset($this->_route_config['qtips'])) { |
|
| 1307 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1308 | + // load qtip loader |
|
| 1309 | + $path = [ |
|
| 1310 | + $this->_get_dir() . '/qtips/', |
|
| 1311 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1312 | + ]; |
|
| 1313 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * _set_nav_tabs |
|
| 1320 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1321 | + * wish to add additional tabs or modify accordingly. |
|
| 1322 | + * |
|
| 1323 | + * @return void |
|
| 1324 | + * @throws InvalidArgumentException |
|
| 1325 | + * @throws InvalidInterfaceException |
|
| 1326 | + * @throws InvalidDataTypeException |
|
| 1327 | + */ |
|
| 1328 | + protected function _set_nav_tabs() |
|
| 1329 | + { |
|
| 1330 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1331 | + $i = 0; |
|
| 1332 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1333 | + if (! is_array($config) || empty($config['nav'])) { |
|
| 1334 | + continue; |
|
| 1335 | + } |
|
| 1336 | + // no nav tab for this config |
|
| 1337 | + // check for persistent flag |
|
| 1338 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1339 | + // nav tab is only to appear when route requested. |
|
| 1340 | + continue; |
|
| 1341 | + } |
|
| 1342 | + if (! $this->check_user_access($slug, true)) { |
|
| 1343 | + // no nav tab because current user does not have access. |
|
| 1344 | + continue; |
|
| 1345 | + } |
|
| 1346 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1347 | + $this->_nav_tabs[ $slug ] = [ |
|
| 1348 | + 'url' => isset($config['nav']['url']) |
|
| 1349 | + ? $config['nav']['url'] |
|
| 1350 | + : self::add_query_args_and_nonce( |
|
| 1351 | + ['action' => $slug], |
|
| 1352 | + $this->_admin_base_url |
|
| 1353 | + ), |
|
| 1354 | + 'link_text' => isset($config['nav']['label']) |
|
| 1355 | + ? $config['nav']['label'] |
|
| 1356 | + : ucwords( |
|
| 1357 | + str_replace('_', ' ', $slug) |
|
| 1358 | + ), |
|
| 1359 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1360 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1361 | + ]; |
|
| 1362 | + $i++; |
|
| 1363 | + } |
|
| 1364 | + // if $this->_nav_tabs is empty then lets set the default |
|
| 1365 | + if (empty($this->_nav_tabs)) { |
|
| 1366 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1367 | + 'url' => $this->_admin_base_url, |
|
| 1368 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1369 | + 'css_class' => 'nav-tab-active', |
|
| 1370 | + 'order' => 10, |
|
| 1371 | + ]; |
|
| 1372 | + } |
|
| 1373 | + // now let's sort the tabs according to order |
|
| 1374 | + usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * _set_current_labels |
|
| 1380 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1381 | + * property array |
|
| 1382 | + * |
|
| 1383 | + * @return void |
|
| 1384 | + */ |
|
| 1385 | + private function _set_current_labels() |
|
| 1386 | + { |
|
| 1387 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1388 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1389 | + if (is_array($text)) { |
|
| 1390 | + foreach ($text as $sublabel => $subtext) { |
|
| 1391 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1392 | + } |
|
| 1393 | + } else { |
|
| 1394 | + $this->_labels[ $label ] = $text; |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * verifies user access for this admin page |
|
| 1403 | + * |
|
| 1404 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1405 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1406 | + * return false if verify fail. |
|
| 1407 | + * @return bool |
|
| 1408 | + * @throws InvalidArgumentException |
|
| 1409 | + * @throws InvalidDataTypeException |
|
| 1410 | + * @throws InvalidInterfaceException |
|
| 1411 | + */ |
|
| 1412 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1413 | + { |
|
| 1414 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1415 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1416 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1417 | + && is_array( |
|
| 1418 | + $this->_page_routes[ $route_to_check ] |
|
| 1419 | + ) |
|
| 1420 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1421 | + ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1422 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1423 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1424 | + : $this->_route['capability']; |
|
| 1425 | + } else { |
|
| 1426 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1427 | + } |
|
| 1428 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1429 | + if ( |
|
| 1430 | + ! $this->request->isAjax() |
|
| 1431 | + && ( |
|
| 1432 | + ! function_exists('is_admin') |
|
| 1433 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1434 | + $capability, |
|
| 1435 | + $this->page_slug |
|
| 1436 | + . '_' |
|
| 1437 | + . $route_to_check, |
|
| 1438 | + $id |
|
| 1439 | + ) |
|
| 1440 | + ) |
|
| 1441 | + ) { |
|
| 1442 | + if ($verify_only) { |
|
| 1443 | + return false; |
|
| 1444 | + } |
|
| 1445 | + if (is_user_logged_in()) { |
|
| 1446 | + wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1447 | + } else { |
|
| 1448 | + return false; |
|
| 1449 | + } |
|
| 1450 | + } |
|
| 1451 | + return true; |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + |
|
| 1455 | + /** |
|
| 1456 | + * admin_init_global |
|
| 1457 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1458 | + * This method executes for ALL EE Admin pages. |
|
| 1459 | + * |
|
| 1460 | + * @return void |
|
| 1461 | + */ |
|
| 1462 | + public function admin_init_global() |
|
| 1463 | + { |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * wp_loaded_global |
|
| 1469 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1470 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1471 | + * |
|
| 1472 | + * @return void |
|
| 1473 | + */ |
|
| 1474 | + public function wp_loaded() |
|
| 1475 | + { |
|
| 1476 | + } |
|
| 1477 | + |
|
| 1478 | + |
|
| 1479 | + /** |
|
| 1480 | + * admin_notices |
|
| 1481 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1482 | + * ALL EE_Admin pages. |
|
| 1483 | + * |
|
| 1484 | + * @return void |
|
| 1485 | + */ |
|
| 1486 | + public function admin_notices_global() |
|
| 1487 | + { |
|
| 1488 | + $this->_display_no_javascript_warning(); |
|
| 1489 | + $this->_display_espresso_notices(); |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + |
|
| 1493 | + public function network_admin_notices_global() |
|
| 1494 | + { |
|
| 1495 | + $this->_display_no_javascript_warning(); |
|
| 1496 | + $this->_display_espresso_notices(); |
|
| 1497 | + } |
|
| 1498 | + |
|
| 1499 | + |
|
| 1500 | + /** |
|
| 1501 | + * admin_footer_scripts_global |
|
| 1502 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1503 | + * will apply on ALL EE_Admin pages. |
|
| 1504 | + * |
|
| 1505 | + * @return void |
|
| 1506 | + */ |
|
| 1507 | + public function admin_footer_scripts_global() |
|
| 1508 | + { |
|
| 1509 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1510 | + $this->_add_admin_page_overlay(); |
|
| 1511 | + // if metaboxes are present we need to add the nonce field |
|
| 1512 | + if ( |
|
| 1513 | + isset($this->_route_config['metaboxes']) |
|
| 1514 | + || isset($this->_route_config['list_table']) |
|
| 1515 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1516 | + ) { |
|
| 1517 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1518 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1519 | + } |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * admin_footer_global |
|
| 1525 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1526 | + * ALL EE_Admin Pages. |
|
| 1527 | + * |
|
| 1528 | + * @return void |
|
| 1529 | + */ |
|
| 1530 | + public function admin_footer_global() |
|
| 1531 | + { |
|
| 1532 | + // dialog container for dialog helper |
|
| 1533 | + echo ' |
|
| 1534 | 1534 | <div class="ee-admin-dialog-container auto-hide hidden"> |
| 1535 | 1535 | <div class="ee-notices"></div> |
| 1536 | 1536 | <div class="ee-admin-dialog-container-inner-content"></div> |
| 1537 | 1537 | </div> |
| 1538 | 1538 | '; |
| 1539 | 1539 | |
| 1540 | - // current set timezone for timezone js |
|
| 1541 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1542 | - } |
|
| 1543 | - |
|
| 1544 | - |
|
| 1545 | - /** |
|
| 1546 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1547 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1548 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1549 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1550 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1551 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1552 | - * for the |
|
| 1553 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1554 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1555 | - * 'help_trigger_id' => array( |
|
| 1556 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1557 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1558 | - * ) |
|
| 1559 | - * ); |
|
| 1560 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1561 | - * |
|
| 1562 | - * @param array $help_array |
|
| 1563 | - * @param bool $display |
|
| 1564 | - * @return string content |
|
| 1565 | - * @throws DomainException |
|
| 1566 | - * @throws EE_Error |
|
| 1567 | - */ |
|
| 1568 | - protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1569 | - { |
|
| 1570 | - $content = ''; |
|
| 1571 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1572 | - // loop through the array and setup content |
|
| 1573 | - foreach ($help_array as $trigger => $help) { |
|
| 1574 | - // make sure the array is setup properly |
|
| 1575 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1576 | - throw new EE_Error( |
|
| 1577 | - esc_html__( |
|
| 1578 | - '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', |
|
| 1579 | - 'event_espresso' |
|
| 1580 | - ) |
|
| 1581 | - ); |
|
| 1582 | - } |
|
| 1583 | - // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
| 1584 | - $template_args = [ |
|
| 1585 | - 'help_popup_id' => $trigger, |
|
| 1586 | - 'help_popup_title' => $help['title'], |
|
| 1587 | - 'help_popup_content' => $help['content'], |
|
| 1588 | - ]; |
|
| 1589 | - $content .= EEH_Template::display_template( |
|
| 1590 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1591 | - $template_args, |
|
| 1592 | - true |
|
| 1593 | - ); |
|
| 1594 | - } |
|
| 1595 | - if ($display) { |
|
| 1596 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1597 | - return ''; |
|
| 1598 | - } |
|
| 1599 | - return $content; |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - |
|
| 1603 | - /** |
|
| 1604 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1605 | - * |
|
| 1606 | - * @return array properly formatted array for help popup content |
|
| 1607 | - * @throws EE_Error |
|
| 1608 | - */ |
|
| 1609 | - private function _get_help_content() |
|
| 1610 | - { |
|
| 1611 | - // what is the method we're looking for? |
|
| 1612 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1613 | - // if method doesn't exist let's get out. |
|
| 1614 | - if (! method_exists($this, $method_name)) { |
|
| 1615 | - return []; |
|
| 1616 | - } |
|
| 1617 | - // k we're good to go let's retrieve the help array |
|
| 1618 | - $help_array = call_user_func([$this, $method_name]); |
|
| 1619 | - // make sure we've got an array! |
|
| 1620 | - if (! is_array($help_array)) { |
|
| 1621 | - throw new EE_Error( |
|
| 1622 | - esc_html__( |
|
| 1623 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1624 | - 'event_espresso' |
|
| 1625 | - ) |
|
| 1626 | - ); |
|
| 1627 | - } |
|
| 1628 | - return $help_array; |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - |
|
| 1632 | - /** |
|
| 1633 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1634 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1635 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1636 | - * |
|
| 1637 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1638 | - * @param boolean $display if false then we return the trigger string |
|
| 1639 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1640 | - * @return string |
|
| 1641 | - * @throws DomainException |
|
| 1642 | - * @throws EE_Error |
|
| 1643 | - */ |
|
| 1644 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1645 | - { |
|
| 1646 | - if ($this->request->isAjax()) { |
|
| 1647 | - return ''; |
|
| 1648 | - } |
|
| 1649 | - // 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 |
|
| 1650 | - $help_array = $this->_get_help_content(); |
|
| 1651 | - $help_content = ''; |
|
| 1652 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1653 | - $help_array[ $trigger_id ] = [ |
|
| 1654 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1655 | - 'content' => esc_html__( |
|
| 1656 | - '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.)', |
|
| 1657 | - 'event_espresso' |
|
| 1658 | - ), |
|
| 1659 | - ]; |
|
| 1660 | - $help_content = $this->_set_help_popup_content($help_array); |
|
| 1661 | - } |
|
| 1662 | - // let's setup the trigger |
|
| 1663 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1664 | - . esc_attr($dimensions[0]) |
|
| 1665 | - . '&width=' |
|
| 1666 | - . esc_attr($dimensions[1]) |
|
| 1667 | - . '&inlineId=' |
|
| 1668 | - . esc_attr($trigger_id) |
|
| 1669 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1670 | - $content .= $help_content; |
|
| 1671 | - if ($display) { |
|
| 1672 | - echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1673 | - return ''; |
|
| 1674 | - } |
|
| 1675 | - return $content; |
|
| 1676 | - } |
|
| 1677 | - |
|
| 1678 | - |
|
| 1679 | - /** |
|
| 1680 | - * _add_global_screen_options |
|
| 1681 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1682 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1683 | - * |
|
| 1684 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1685 | - * see also WP_Screen object documents... |
|
| 1686 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1687 | - * @abstract |
|
| 1688 | - * @return void |
|
| 1689 | - */ |
|
| 1690 | - private function _add_global_screen_options() |
|
| 1691 | - { |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - |
|
| 1695 | - /** |
|
| 1696 | - * _add_global_feature_pointers |
|
| 1697 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1698 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1699 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1700 | - * |
|
| 1701 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1702 | - * extended) also see: |
|
| 1703 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1704 | - * @abstract |
|
| 1705 | - * @return void |
|
| 1706 | - */ |
|
| 1707 | - private function _add_global_feature_pointers() |
|
| 1708 | - { |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * load_global_scripts_styles |
|
| 1714 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1715 | - * |
|
| 1716 | - * @return void |
|
| 1717 | - */ |
|
| 1718 | - public function load_global_scripts_styles() |
|
| 1719 | - { |
|
| 1720 | - /** STYLES **/ |
|
| 1721 | - // add debugging styles |
|
| 1722 | - if (WP_DEBUG) { |
|
| 1723 | - add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1724 | - } |
|
| 1725 | - // register all styles |
|
| 1726 | - wp_register_style( |
|
| 1727 | - 'espresso-ui-theme', |
|
| 1728 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1729 | - [], |
|
| 1730 | - EVENT_ESPRESSO_VERSION |
|
| 1731 | - ); |
|
| 1732 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1733 | - // helpers styles |
|
| 1734 | - wp_register_style( |
|
| 1735 | - 'ee-text-links', |
|
| 1736 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1737 | - [], |
|
| 1738 | - EVENT_ESPRESSO_VERSION |
|
| 1739 | - ); |
|
| 1740 | - /** SCRIPTS **/ |
|
| 1741 | - // register all scripts |
|
| 1742 | - wp_register_script( |
|
| 1743 | - 'ee-dialog', |
|
| 1744 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1745 | - ['jquery', 'jquery-ui-draggable'], |
|
| 1746 | - EVENT_ESPRESSO_VERSION, |
|
| 1747 | - true |
|
| 1748 | - ); |
|
| 1749 | - wp_register_script( |
|
| 1750 | - 'ee_admin_js', |
|
| 1751 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1752 | - ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
|
| 1753 | - EVENT_ESPRESSO_VERSION, |
|
| 1754 | - true |
|
| 1755 | - ); |
|
| 1756 | - wp_register_script( |
|
| 1757 | - 'jquery-ui-timepicker-addon', |
|
| 1758 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1759 | - ['jquery-ui-datepicker', 'jquery-ui-slider'], |
|
| 1760 | - EVENT_ESPRESSO_VERSION, |
|
| 1761 | - true |
|
| 1762 | - ); |
|
| 1763 | - // script for sorting tables |
|
| 1764 | - wp_register_script( |
|
| 1765 | - 'espresso_ajax_table_sorting', |
|
| 1766 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1767 | - ['ee_admin_js', 'jquery-ui-sortable'], |
|
| 1768 | - EVENT_ESPRESSO_VERSION, |
|
| 1769 | - true |
|
| 1770 | - ); |
|
| 1771 | - // script for parsing uri's |
|
| 1772 | - wp_register_script( |
|
| 1773 | - 'ee-parse-uri', |
|
| 1774 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1775 | - [], |
|
| 1776 | - EVENT_ESPRESSO_VERSION, |
|
| 1777 | - true |
|
| 1778 | - ); |
|
| 1779 | - // and parsing associative serialized form elements |
|
| 1780 | - wp_register_script( |
|
| 1781 | - 'ee-serialize-full-array', |
|
| 1782 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1783 | - ['jquery'], |
|
| 1784 | - EVENT_ESPRESSO_VERSION, |
|
| 1785 | - true |
|
| 1786 | - ); |
|
| 1787 | - // helpers scripts |
|
| 1788 | - wp_register_script( |
|
| 1789 | - 'ee-text-links', |
|
| 1790 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1791 | - ['jquery'], |
|
| 1792 | - EVENT_ESPRESSO_VERSION, |
|
| 1793 | - true |
|
| 1794 | - ); |
|
| 1795 | - wp_register_script( |
|
| 1796 | - 'ee-moment-core', |
|
| 1797 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1798 | - [], |
|
| 1799 | - EVENT_ESPRESSO_VERSION, |
|
| 1800 | - true |
|
| 1801 | - ); |
|
| 1802 | - wp_register_script( |
|
| 1803 | - 'ee-moment', |
|
| 1804 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1805 | - ['ee-moment-core'], |
|
| 1806 | - EVENT_ESPRESSO_VERSION, |
|
| 1807 | - true |
|
| 1808 | - ); |
|
| 1809 | - wp_register_script( |
|
| 1810 | - 'ee-datepicker', |
|
| 1811 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1812 | - ['jquery-ui-timepicker-addon', 'ee-moment'], |
|
| 1813 | - EVENT_ESPRESSO_VERSION, |
|
| 1814 | - true |
|
| 1815 | - ); |
|
| 1816 | - // google charts |
|
| 1817 | - wp_register_script( |
|
| 1818 | - 'google-charts', |
|
| 1819 | - 'https://www.gstatic.com/charts/loader.js', |
|
| 1820 | - [], |
|
| 1821 | - EVENT_ESPRESSO_VERSION |
|
| 1822 | - ); |
|
| 1823 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1824 | - wp_enqueue_style('ee-admin-css'); |
|
| 1825 | - wp_enqueue_script('ee_admin_js'); |
|
| 1826 | - wp_enqueue_script('ee-accounting'); |
|
| 1827 | - wp_enqueue_script('jquery-validate'); |
|
| 1828 | - // taking care of metaboxes |
|
| 1829 | - if ( |
|
| 1830 | - empty($this->_cpt_route) |
|
| 1831 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1832 | - ) { |
|
| 1833 | - wp_enqueue_script('dashboard'); |
|
| 1834 | - } |
|
| 1835 | - // LOCALIZED DATA |
|
| 1836 | - // localize script for ajax lazy loading |
|
| 1837 | - $lazy_loader_container_ids = apply_filters( |
|
| 1838 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1839 | - ['espresso_news_post_box_content'] |
|
| 1840 | - ); |
|
| 1841 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1842 | - add_filter( |
|
| 1843 | - 'admin_body_class', |
|
| 1844 | - function ($classes) { |
|
| 1845 | - if (strpos($classes, 'espresso-admin') === false) { |
|
| 1846 | - $classes .= ' espresso-admin'; |
|
| 1847 | - } |
|
| 1848 | - return $classes; |
|
| 1849 | - } |
|
| 1850 | - ); |
|
| 1851 | - } |
|
| 1852 | - |
|
| 1853 | - |
|
| 1854 | - /** |
|
| 1855 | - * admin_footer_scripts_eei18n_js_strings |
|
| 1856 | - * |
|
| 1857 | - * @return void |
|
| 1858 | - */ |
|
| 1859 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 1860 | - { |
|
| 1861 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1862 | - EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 1863 | - __( |
|
| 1864 | - '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!!!', |
|
| 1865 | - 'event_espresso' |
|
| 1866 | - ) |
|
| 1867 | - ); |
|
| 1868 | - EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 1869 | - EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 1870 | - EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 1871 | - EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 1872 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1873 | - EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 1874 | - EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 1875 | - EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 1876 | - EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 1877 | - EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 1878 | - EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 1879 | - EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 1880 | - EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 1881 | - EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 1882 | - EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 1883 | - EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 1884 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1885 | - EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 1886 | - EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 1887 | - EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 1888 | - EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 1889 | - EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 1890 | - EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 1891 | - EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 1892 | - EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 1893 | - EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 1894 | - EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 1895 | - EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 1896 | - EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 1897 | - EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 1898 | - EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 1899 | - EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 1900 | - EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 1901 | - EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 1902 | - EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 1903 | - EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 1904 | - EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 1905 | - EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 1906 | - } |
|
| 1907 | - |
|
| 1908 | - |
|
| 1909 | - /** |
|
| 1910 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1911 | - * |
|
| 1912 | - * @return void |
|
| 1913 | - */ |
|
| 1914 | - public function add_xdebug_style() |
|
| 1915 | - { |
|
| 1916 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1917 | - } |
|
| 1918 | - |
|
| 1919 | - |
|
| 1920 | - /************************/ |
|
| 1921 | - /** LIST TABLE METHODS **/ |
|
| 1922 | - /************************/ |
|
| 1923 | - /** |
|
| 1924 | - * this sets up the list table if the current view requires it. |
|
| 1925 | - * |
|
| 1926 | - * @return void |
|
| 1927 | - * @throws EE_Error |
|
| 1928 | - */ |
|
| 1929 | - protected function _set_list_table() |
|
| 1930 | - { |
|
| 1931 | - // first is this a list_table view? |
|
| 1932 | - if (! isset($this->_route_config['list_table'])) { |
|
| 1933 | - return; |
|
| 1934 | - } //not a list_table view so get out. |
|
| 1935 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 1936 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 1937 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1938 | - // user error msg |
|
| 1939 | - $error_msg = esc_html__( |
|
| 1940 | - 'An error occurred. The requested list table views could not be found.', |
|
| 1941 | - 'event_espresso' |
|
| 1942 | - ); |
|
| 1943 | - // developer error msg |
|
| 1944 | - $error_msg .= '||' |
|
| 1945 | - . sprintf( |
|
| 1946 | - esc_html__( |
|
| 1947 | - '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.', |
|
| 1948 | - 'event_espresso' |
|
| 1949 | - ), |
|
| 1950 | - $this->_req_action, |
|
| 1951 | - $list_table_view |
|
| 1952 | - ); |
|
| 1953 | - throw new EE_Error($error_msg); |
|
| 1954 | - } |
|
| 1955 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1956 | - $this->_views = apply_filters( |
|
| 1957 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 1958 | - $this->_views |
|
| 1959 | - ); |
|
| 1960 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1961 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1962 | - $this->_set_list_table_view(); |
|
| 1963 | - $this->_set_list_table_object(); |
|
| 1964 | - } |
|
| 1965 | - |
|
| 1966 | - |
|
| 1967 | - /** |
|
| 1968 | - * set current view for List Table |
|
| 1969 | - * |
|
| 1970 | - * @return void |
|
| 1971 | - */ |
|
| 1972 | - protected function _set_list_table_view() |
|
| 1973 | - { |
|
| 1974 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1975 | - $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 1976 | - $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 1977 | - ? $status |
|
| 1978 | - : $this->_view; |
|
| 1979 | - } |
|
| 1980 | - |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * _set_list_table_object |
|
| 1984 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1985 | - * |
|
| 1986 | - * @throws InvalidInterfaceException |
|
| 1987 | - * @throws InvalidArgumentException |
|
| 1988 | - * @throws InvalidDataTypeException |
|
| 1989 | - * @throws EE_Error |
|
| 1990 | - * @throws InvalidInterfaceException |
|
| 1991 | - */ |
|
| 1992 | - protected function _set_list_table_object() |
|
| 1993 | - { |
|
| 1994 | - if (isset($this->_route_config['list_table'])) { |
|
| 1995 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 1996 | - throw new EE_Error( |
|
| 1997 | - sprintf( |
|
| 1998 | - esc_html__( |
|
| 1999 | - '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.', |
|
| 2000 | - 'event_espresso' |
|
| 2001 | - ), |
|
| 2002 | - $this->_route_config['list_table'], |
|
| 2003 | - get_class($this) |
|
| 2004 | - ) |
|
| 2005 | - ); |
|
| 2006 | - } |
|
| 2007 | - $this->_list_table_object = $this->loader->getShared( |
|
| 2008 | - $this->_route_config['list_table'], |
|
| 2009 | - [$this] |
|
| 2010 | - ); |
|
| 2011 | - } |
|
| 2012 | - } |
|
| 2013 | - |
|
| 2014 | - |
|
| 2015 | - /** |
|
| 2016 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2017 | - * |
|
| 2018 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2019 | - * urls. The array should be indexed by the view it is being |
|
| 2020 | - * added to. |
|
| 2021 | - * @return array |
|
| 2022 | - */ |
|
| 2023 | - public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2024 | - { |
|
| 2025 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2026 | - if (empty($this->_views)) { |
|
| 2027 | - $this->_views = []; |
|
| 2028 | - } |
|
| 2029 | - // cycle thru views |
|
| 2030 | - foreach ($this->_views as $key => $view) { |
|
| 2031 | - $query_args = []; |
|
| 2032 | - // check for current view |
|
| 2033 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2034 | - $query_args['action'] = $this->_req_action; |
|
| 2035 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2036 | - $query_args['status'] = $view['slug']; |
|
| 2037 | - // merge any other arguments sent in. |
|
| 2038 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2039 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2040 | - } |
|
| 2041 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2042 | - } |
|
| 2043 | - return $this->_views; |
|
| 2044 | - } |
|
| 2045 | - |
|
| 2046 | - |
|
| 2047 | - /** |
|
| 2048 | - * _entries_per_page_dropdown |
|
| 2049 | - * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2050 | - * |
|
| 2051 | - * @param int $max_entries total number of rows in the table |
|
| 2052 | - * @return string |
|
| 2053 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2054 | - * WP does it. |
|
| 2055 | - */ |
|
| 2056 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2057 | - { |
|
| 2058 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2059 | - $values = [10, 25, 50, 100]; |
|
| 2060 | - $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2061 | - if ($max_entries) { |
|
| 2062 | - $values[] = $max_entries; |
|
| 2063 | - sort($values); |
|
| 2064 | - } |
|
| 2065 | - $entries_per_page_dropdown = ' |
|
| 1540 | + // current set timezone for timezone js |
|
| 1541 | + echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1542 | + } |
|
| 1543 | + |
|
| 1544 | + |
|
| 1545 | + /** |
|
| 1546 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1547 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1548 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1549 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1550 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1551 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1552 | + * for the |
|
| 1553 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1554 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1555 | + * 'help_trigger_id' => array( |
|
| 1556 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1557 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1558 | + * ) |
|
| 1559 | + * ); |
|
| 1560 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1561 | + * |
|
| 1562 | + * @param array $help_array |
|
| 1563 | + * @param bool $display |
|
| 1564 | + * @return string content |
|
| 1565 | + * @throws DomainException |
|
| 1566 | + * @throws EE_Error |
|
| 1567 | + */ |
|
| 1568 | + protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1569 | + { |
|
| 1570 | + $content = ''; |
|
| 1571 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1572 | + // loop through the array and setup content |
|
| 1573 | + foreach ($help_array as $trigger => $help) { |
|
| 1574 | + // make sure the array is setup properly |
|
| 1575 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1576 | + throw new EE_Error( |
|
| 1577 | + esc_html__( |
|
| 1578 | + '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', |
|
| 1579 | + 'event_espresso' |
|
| 1580 | + ) |
|
| 1581 | + ); |
|
| 1582 | + } |
|
| 1583 | + // we're good so let's setup the template vars and then assign parsed template content to our content. |
|
| 1584 | + $template_args = [ |
|
| 1585 | + 'help_popup_id' => $trigger, |
|
| 1586 | + 'help_popup_title' => $help['title'], |
|
| 1587 | + 'help_popup_content' => $help['content'], |
|
| 1588 | + ]; |
|
| 1589 | + $content .= EEH_Template::display_template( |
|
| 1590 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1591 | + $template_args, |
|
| 1592 | + true |
|
| 1593 | + ); |
|
| 1594 | + } |
|
| 1595 | + if ($display) { |
|
| 1596 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1597 | + return ''; |
|
| 1598 | + } |
|
| 1599 | + return $content; |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + |
|
| 1603 | + /** |
|
| 1604 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1605 | + * |
|
| 1606 | + * @return array properly formatted array for help popup content |
|
| 1607 | + * @throws EE_Error |
|
| 1608 | + */ |
|
| 1609 | + private function _get_help_content() |
|
| 1610 | + { |
|
| 1611 | + // what is the method we're looking for? |
|
| 1612 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1613 | + // if method doesn't exist let's get out. |
|
| 1614 | + if (! method_exists($this, $method_name)) { |
|
| 1615 | + return []; |
|
| 1616 | + } |
|
| 1617 | + // k we're good to go let's retrieve the help array |
|
| 1618 | + $help_array = call_user_func([$this, $method_name]); |
|
| 1619 | + // make sure we've got an array! |
|
| 1620 | + if (! is_array($help_array)) { |
|
| 1621 | + throw new EE_Error( |
|
| 1622 | + esc_html__( |
|
| 1623 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1624 | + 'event_espresso' |
|
| 1625 | + ) |
|
| 1626 | + ); |
|
| 1627 | + } |
|
| 1628 | + return $help_array; |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + |
|
| 1632 | + /** |
|
| 1633 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1634 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1635 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1636 | + * |
|
| 1637 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1638 | + * @param boolean $display if false then we return the trigger string |
|
| 1639 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1640 | + * @return string |
|
| 1641 | + * @throws DomainException |
|
| 1642 | + * @throws EE_Error |
|
| 1643 | + */ |
|
| 1644 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1645 | + { |
|
| 1646 | + if ($this->request->isAjax()) { |
|
| 1647 | + return ''; |
|
| 1648 | + } |
|
| 1649 | + // 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 |
|
| 1650 | + $help_array = $this->_get_help_content(); |
|
| 1651 | + $help_content = ''; |
|
| 1652 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1653 | + $help_array[ $trigger_id ] = [ |
|
| 1654 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1655 | + 'content' => esc_html__( |
|
| 1656 | + '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.)', |
|
| 1657 | + 'event_espresso' |
|
| 1658 | + ), |
|
| 1659 | + ]; |
|
| 1660 | + $help_content = $this->_set_help_popup_content($help_array); |
|
| 1661 | + } |
|
| 1662 | + // let's setup the trigger |
|
| 1663 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1664 | + . esc_attr($dimensions[0]) |
|
| 1665 | + . '&width=' |
|
| 1666 | + . esc_attr($dimensions[1]) |
|
| 1667 | + . '&inlineId=' |
|
| 1668 | + . esc_attr($trigger_id) |
|
| 1669 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1670 | + $content .= $help_content; |
|
| 1671 | + if ($display) { |
|
| 1672 | + echo wp_kses($content, AllowedTags::getWithFormTags()); |
|
| 1673 | + return ''; |
|
| 1674 | + } |
|
| 1675 | + return $content; |
|
| 1676 | + } |
|
| 1677 | + |
|
| 1678 | + |
|
| 1679 | + /** |
|
| 1680 | + * _add_global_screen_options |
|
| 1681 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1682 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1683 | + * |
|
| 1684 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1685 | + * see also WP_Screen object documents... |
|
| 1686 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1687 | + * @abstract |
|
| 1688 | + * @return void |
|
| 1689 | + */ |
|
| 1690 | + private function _add_global_screen_options() |
|
| 1691 | + { |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + |
|
| 1695 | + /** |
|
| 1696 | + * _add_global_feature_pointers |
|
| 1697 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1698 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1699 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1700 | + * |
|
| 1701 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1702 | + * extended) also see: |
|
| 1703 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1704 | + * @abstract |
|
| 1705 | + * @return void |
|
| 1706 | + */ |
|
| 1707 | + private function _add_global_feature_pointers() |
|
| 1708 | + { |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * load_global_scripts_styles |
|
| 1714 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1715 | + * |
|
| 1716 | + * @return void |
|
| 1717 | + */ |
|
| 1718 | + public function load_global_scripts_styles() |
|
| 1719 | + { |
|
| 1720 | + /** STYLES **/ |
|
| 1721 | + // add debugging styles |
|
| 1722 | + if (WP_DEBUG) { |
|
| 1723 | + add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1724 | + } |
|
| 1725 | + // register all styles |
|
| 1726 | + wp_register_style( |
|
| 1727 | + 'espresso-ui-theme', |
|
| 1728 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1729 | + [], |
|
| 1730 | + EVENT_ESPRESSO_VERSION |
|
| 1731 | + ); |
|
| 1732 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1733 | + // helpers styles |
|
| 1734 | + wp_register_style( |
|
| 1735 | + 'ee-text-links', |
|
| 1736 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1737 | + [], |
|
| 1738 | + EVENT_ESPRESSO_VERSION |
|
| 1739 | + ); |
|
| 1740 | + /** SCRIPTS **/ |
|
| 1741 | + // register all scripts |
|
| 1742 | + wp_register_script( |
|
| 1743 | + 'ee-dialog', |
|
| 1744 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1745 | + ['jquery', 'jquery-ui-draggable'], |
|
| 1746 | + EVENT_ESPRESSO_VERSION, |
|
| 1747 | + true |
|
| 1748 | + ); |
|
| 1749 | + wp_register_script( |
|
| 1750 | + 'ee_admin_js', |
|
| 1751 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1752 | + ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
|
| 1753 | + EVENT_ESPRESSO_VERSION, |
|
| 1754 | + true |
|
| 1755 | + ); |
|
| 1756 | + wp_register_script( |
|
| 1757 | + 'jquery-ui-timepicker-addon', |
|
| 1758 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1759 | + ['jquery-ui-datepicker', 'jquery-ui-slider'], |
|
| 1760 | + EVENT_ESPRESSO_VERSION, |
|
| 1761 | + true |
|
| 1762 | + ); |
|
| 1763 | + // script for sorting tables |
|
| 1764 | + wp_register_script( |
|
| 1765 | + 'espresso_ajax_table_sorting', |
|
| 1766 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1767 | + ['ee_admin_js', 'jquery-ui-sortable'], |
|
| 1768 | + EVENT_ESPRESSO_VERSION, |
|
| 1769 | + true |
|
| 1770 | + ); |
|
| 1771 | + // script for parsing uri's |
|
| 1772 | + wp_register_script( |
|
| 1773 | + 'ee-parse-uri', |
|
| 1774 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1775 | + [], |
|
| 1776 | + EVENT_ESPRESSO_VERSION, |
|
| 1777 | + true |
|
| 1778 | + ); |
|
| 1779 | + // and parsing associative serialized form elements |
|
| 1780 | + wp_register_script( |
|
| 1781 | + 'ee-serialize-full-array', |
|
| 1782 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1783 | + ['jquery'], |
|
| 1784 | + EVENT_ESPRESSO_VERSION, |
|
| 1785 | + true |
|
| 1786 | + ); |
|
| 1787 | + // helpers scripts |
|
| 1788 | + wp_register_script( |
|
| 1789 | + 'ee-text-links', |
|
| 1790 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1791 | + ['jquery'], |
|
| 1792 | + EVENT_ESPRESSO_VERSION, |
|
| 1793 | + true |
|
| 1794 | + ); |
|
| 1795 | + wp_register_script( |
|
| 1796 | + 'ee-moment-core', |
|
| 1797 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1798 | + [], |
|
| 1799 | + EVENT_ESPRESSO_VERSION, |
|
| 1800 | + true |
|
| 1801 | + ); |
|
| 1802 | + wp_register_script( |
|
| 1803 | + 'ee-moment', |
|
| 1804 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1805 | + ['ee-moment-core'], |
|
| 1806 | + EVENT_ESPRESSO_VERSION, |
|
| 1807 | + true |
|
| 1808 | + ); |
|
| 1809 | + wp_register_script( |
|
| 1810 | + 'ee-datepicker', |
|
| 1811 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1812 | + ['jquery-ui-timepicker-addon', 'ee-moment'], |
|
| 1813 | + EVENT_ESPRESSO_VERSION, |
|
| 1814 | + true |
|
| 1815 | + ); |
|
| 1816 | + // google charts |
|
| 1817 | + wp_register_script( |
|
| 1818 | + 'google-charts', |
|
| 1819 | + 'https://www.gstatic.com/charts/loader.js', |
|
| 1820 | + [], |
|
| 1821 | + EVENT_ESPRESSO_VERSION |
|
| 1822 | + ); |
|
| 1823 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1824 | + wp_enqueue_style('ee-admin-css'); |
|
| 1825 | + wp_enqueue_script('ee_admin_js'); |
|
| 1826 | + wp_enqueue_script('ee-accounting'); |
|
| 1827 | + wp_enqueue_script('jquery-validate'); |
|
| 1828 | + // taking care of metaboxes |
|
| 1829 | + if ( |
|
| 1830 | + empty($this->_cpt_route) |
|
| 1831 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1832 | + ) { |
|
| 1833 | + wp_enqueue_script('dashboard'); |
|
| 1834 | + } |
|
| 1835 | + // LOCALIZED DATA |
|
| 1836 | + // localize script for ajax lazy loading |
|
| 1837 | + $lazy_loader_container_ids = apply_filters( |
|
| 1838 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1839 | + ['espresso_news_post_box_content'] |
|
| 1840 | + ); |
|
| 1841 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1842 | + add_filter( |
|
| 1843 | + 'admin_body_class', |
|
| 1844 | + function ($classes) { |
|
| 1845 | + if (strpos($classes, 'espresso-admin') === false) { |
|
| 1846 | + $classes .= ' espresso-admin'; |
|
| 1847 | + } |
|
| 1848 | + return $classes; |
|
| 1849 | + } |
|
| 1850 | + ); |
|
| 1851 | + } |
|
| 1852 | + |
|
| 1853 | + |
|
| 1854 | + /** |
|
| 1855 | + * admin_footer_scripts_eei18n_js_strings |
|
| 1856 | + * |
|
| 1857 | + * @return void |
|
| 1858 | + */ |
|
| 1859 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 1860 | + { |
|
| 1861 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1862 | + EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 1863 | + __( |
|
| 1864 | + '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!!!', |
|
| 1865 | + 'event_espresso' |
|
| 1866 | + ) |
|
| 1867 | + ); |
|
| 1868 | + EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 1869 | + EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 1870 | + EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 1871 | + EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 1872 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1873 | + EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 1874 | + EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 1875 | + EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 1876 | + EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 1877 | + EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 1878 | + EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 1879 | + EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 1880 | + EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 1881 | + EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 1882 | + EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 1883 | + EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 1884 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 1885 | + EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 1886 | + EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 1887 | + EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 1888 | + EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 1889 | + EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 1890 | + EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 1891 | + EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 1892 | + EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 1893 | + EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 1894 | + EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 1895 | + EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 1896 | + EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 1897 | + EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 1898 | + EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 1899 | + EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 1900 | + EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 1901 | + EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 1902 | + EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 1903 | + EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 1904 | + EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 1905 | + EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 1906 | + } |
|
| 1907 | + |
|
| 1908 | + |
|
| 1909 | + /** |
|
| 1910 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1911 | + * |
|
| 1912 | + * @return void |
|
| 1913 | + */ |
|
| 1914 | + public function add_xdebug_style() |
|
| 1915 | + { |
|
| 1916 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1917 | + } |
|
| 1918 | + |
|
| 1919 | + |
|
| 1920 | + /************************/ |
|
| 1921 | + /** LIST TABLE METHODS **/ |
|
| 1922 | + /************************/ |
|
| 1923 | + /** |
|
| 1924 | + * this sets up the list table if the current view requires it. |
|
| 1925 | + * |
|
| 1926 | + * @return void |
|
| 1927 | + * @throws EE_Error |
|
| 1928 | + */ |
|
| 1929 | + protected function _set_list_table() |
|
| 1930 | + { |
|
| 1931 | + // first is this a list_table view? |
|
| 1932 | + if (! isset($this->_route_config['list_table'])) { |
|
| 1933 | + return; |
|
| 1934 | + } //not a list_table view so get out. |
|
| 1935 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 1936 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 1937 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1938 | + // user error msg |
|
| 1939 | + $error_msg = esc_html__( |
|
| 1940 | + 'An error occurred. The requested list table views could not be found.', |
|
| 1941 | + 'event_espresso' |
|
| 1942 | + ); |
|
| 1943 | + // developer error msg |
|
| 1944 | + $error_msg .= '||' |
|
| 1945 | + . sprintf( |
|
| 1946 | + esc_html__( |
|
| 1947 | + '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.', |
|
| 1948 | + 'event_espresso' |
|
| 1949 | + ), |
|
| 1950 | + $this->_req_action, |
|
| 1951 | + $list_table_view |
|
| 1952 | + ); |
|
| 1953 | + throw new EE_Error($error_msg); |
|
| 1954 | + } |
|
| 1955 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1956 | + $this->_views = apply_filters( |
|
| 1957 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 1958 | + $this->_views |
|
| 1959 | + ); |
|
| 1960 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1961 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1962 | + $this->_set_list_table_view(); |
|
| 1963 | + $this->_set_list_table_object(); |
|
| 1964 | + } |
|
| 1965 | + |
|
| 1966 | + |
|
| 1967 | + /** |
|
| 1968 | + * set current view for List Table |
|
| 1969 | + * |
|
| 1970 | + * @return void |
|
| 1971 | + */ |
|
| 1972 | + protected function _set_list_table_view() |
|
| 1973 | + { |
|
| 1974 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1975 | + $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 1976 | + $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 1977 | + ? $status |
|
| 1978 | + : $this->_view; |
|
| 1979 | + } |
|
| 1980 | + |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * _set_list_table_object |
|
| 1984 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1985 | + * |
|
| 1986 | + * @throws InvalidInterfaceException |
|
| 1987 | + * @throws InvalidArgumentException |
|
| 1988 | + * @throws InvalidDataTypeException |
|
| 1989 | + * @throws EE_Error |
|
| 1990 | + * @throws InvalidInterfaceException |
|
| 1991 | + */ |
|
| 1992 | + protected function _set_list_table_object() |
|
| 1993 | + { |
|
| 1994 | + if (isset($this->_route_config['list_table'])) { |
|
| 1995 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 1996 | + throw new EE_Error( |
|
| 1997 | + sprintf( |
|
| 1998 | + esc_html__( |
|
| 1999 | + '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.', |
|
| 2000 | + 'event_espresso' |
|
| 2001 | + ), |
|
| 2002 | + $this->_route_config['list_table'], |
|
| 2003 | + get_class($this) |
|
| 2004 | + ) |
|
| 2005 | + ); |
|
| 2006 | + } |
|
| 2007 | + $this->_list_table_object = $this->loader->getShared( |
|
| 2008 | + $this->_route_config['list_table'], |
|
| 2009 | + [$this] |
|
| 2010 | + ); |
|
| 2011 | + } |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + |
|
| 2015 | + /** |
|
| 2016 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2017 | + * |
|
| 2018 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2019 | + * urls. The array should be indexed by the view it is being |
|
| 2020 | + * added to. |
|
| 2021 | + * @return array |
|
| 2022 | + */ |
|
| 2023 | + public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2024 | + { |
|
| 2025 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2026 | + if (empty($this->_views)) { |
|
| 2027 | + $this->_views = []; |
|
| 2028 | + } |
|
| 2029 | + // cycle thru views |
|
| 2030 | + foreach ($this->_views as $key => $view) { |
|
| 2031 | + $query_args = []; |
|
| 2032 | + // check for current view |
|
| 2033 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2034 | + $query_args['action'] = $this->_req_action; |
|
| 2035 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2036 | + $query_args['status'] = $view['slug']; |
|
| 2037 | + // merge any other arguments sent in. |
|
| 2038 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2039 | + $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2040 | + } |
|
| 2041 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2042 | + } |
|
| 2043 | + return $this->_views; |
|
| 2044 | + } |
|
| 2045 | + |
|
| 2046 | + |
|
| 2047 | + /** |
|
| 2048 | + * _entries_per_page_dropdown |
|
| 2049 | + * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2050 | + * |
|
| 2051 | + * @param int $max_entries total number of rows in the table |
|
| 2052 | + * @return string |
|
| 2053 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2054 | + * WP does it. |
|
| 2055 | + */ |
|
| 2056 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2057 | + { |
|
| 2058 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2059 | + $values = [10, 25, 50, 100]; |
|
| 2060 | + $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2061 | + if ($max_entries) { |
|
| 2062 | + $values[] = $max_entries; |
|
| 2063 | + sort($values); |
|
| 2064 | + } |
|
| 2065 | + $entries_per_page_dropdown = ' |
|
| 2066 | 2066 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2067 | 2067 | <label class="hide-if-no-js"> |
| 2068 | 2068 | Show |
| 2069 | 2069 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2070 | - foreach ($values as $value) { |
|
| 2071 | - if ($value < $max_entries) { |
|
| 2072 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2073 | - $entries_per_page_dropdown .= ' |
|
| 2070 | + foreach ($values as $value) { |
|
| 2071 | + if ($value < $max_entries) { |
|
| 2072 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2073 | + $entries_per_page_dropdown .= ' |
|
| 2074 | 2074 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2075 | - } |
|
| 2076 | - } |
|
| 2077 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2078 | - $entries_per_page_dropdown .= ' |
|
| 2075 | + } |
|
| 2076 | + } |
|
| 2077 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2078 | + $entries_per_page_dropdown .= ' |
|
| 2079 | 2079 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2080 | - $entries_per_page_dropdown .= ' |
|
| 2080 | + $entries_per_page_dropdown .= ' |
|
| 2081 | 2081 | </select> |
| 2082 | 2082 | entries |
| 2083 | 2083 | </label> |
| 2084 | 2084 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 2085 | 2085 | </div> |
| 2086 | 2086 | '; |
| 2087 | - return $entries_per_page_dropdown; |
|
| 2088 | - } |
|
| 2089 | - |
|
| 2090 | - |
|
| 2091 | - /** |
|
| 2092 | - * _set_search_attributes |
|
| 2093 | - * |
|
| 2094 | - * @return void |
|
| 2095 | - */ |
|
| 2096 | - public function _set_search_attributes() |
|
| 2097 | - { |
|
| 2098 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2099 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2100 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2101 | - : $this->_search_btn_label |
|
| 2102 | - ); |
|
| 2103 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - |
|
| 2107 | - |
|
| 2108 | - /*** END LIST TABLE METHODS **/ |
|
| 2109 | - |
|
| 2110 | - |
|
| 2111 | - /** |
|
| 2112 | - * _add_registered_metaboxes |
|
| 2113 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2114 | - * |
|
| 2115 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2116 | - * @return void |
|
| 2117 | - * @throws EE_Error |
|
| 2118 | - */ |
|
| 2119 | - private function _add_registered_meta_boxes() |
|
| 2120 | - { |
|
| 2121 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2122 | - // we only add meta boxes if the page_route calls for it |
|
| 2123 | - if ( |
|
| 2124 | - is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2125 | - && is_array( |
|
| 2126 | - $this->_route_config['metaboxes'] |
|
| 2127 | - ) |
|
| 2128 | - ) { |
|
| 2129 | - // this simply loops through the callbacks provided |
|
| 2130 | - // and checks if there is a corresponding callback registered by the child |
|
| 2131 | - // if there is then we go ahead and process the metabox loader. |
|
| 2132 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2133 | - // first check for Closures |
|
| 2134 | - if ($metabox_callback instanceof Closure) { |
|
| 2135 | - $result = $metabox_callback(); |
|
| 2136 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2137 | - $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2138 | - } else { |
|
| 2139 | - $result = call_user_func([$this, &$metabox_callback]); |
|
| 2140 | - } |
|
| 2141 | - if ($result === false) { |
|
| 2142 | - // user error msg |
|
| 2143 | - $error_msg = esc_html__( |
|
| 2144 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2145 | - 'event_espresso' |
|
| 2146 | - ); |
|
| 2147 | - // developer error msg |
|
| 2148 | - $error_msg .= '||' |
|
| 2149 | - . sprintf( |
|
| 2150 | - esc_html__( |
|
| 2151 | - '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.', |
|
| 2152 | - 'event_espresso' |
|
| 2153 | - ), |
|
| 2154 | - $metabox_callback |
|
| 2155 | - ); |
|
| 2156 | - throw new EE_Error($error_msg); |
|
| 2157 | - } |
|
| 2158 | - } |
|
| 2159 | - } |
|
| 2160 | - } |
|
| 2161 | - |
|
| 2162 | - |
|
| 2163 | - /** |
|
| 2164 | - * _add_screen_columns |
|
| 2165 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2166 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2167 | - * |
|
| 2168 | - * @return void |
|
| 2169 | - */ |
|
| 2170 | - private function _add_screen_columns() |
|
| 2171 | - { |
|
| 2172 | - if ( |
|
| 2173 | - is_array($this->_route_config) |
|
| 2174 | - && isset($this->_route_config['columns']) |
|
| 2175 | - && is_array($this->_route_config['columns']) |
|
| 2176 | - && count($this->_route_config['columns']) === 2 |
|
| 2177 | - ) { |
|
| 2178 | - add_screen_option( |
|
| 2179 | - 'layout_columns', |
|
| 2180 | - [ |
|
| 2181 | - 'max' => (int) $this->_route_config['columns'][0], |
|
| 2182 | - 'default' => (int) $this->_route_config['columns'][1], |
|
| 2183 | - ] |
|
| 2184 | - ); |
|
| 2185 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2186 | - $screen_id = $this->_current_screen->id; |
|
| 2187 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2188 | - $total_columns = ! empty($screen_columns) |
|
| 2189 | - ? $screen_columns |
|
| 2190 | - : $this->_route_config['columns'][1]; |
|
| 2191 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2192 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2193 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2194 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2195 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2196 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2197 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2198 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2199 | - } |
|
| 2200 | - } |
|
| 2201 | - |
|
| 2202 | - |
|
| 2203 | - |
|
| 2204 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2205 | - |
|
| 2206 | - |
|
| 2207 | - /** |
|
| 2208 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2209 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2210 | - * these get loaded on. |
|
| 2211 | - */ |
|
| 2212 | - private function _espresso_news_post_box() |
|
| 2213 | - { |
|
| 2214 | - $news_box_title = apply_filters( |
|
| 2215 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2216 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2217 | - ); |
|
| 2218 | - add_meta_box( |
|
| 2219 | - 'espresso_news_post_box', |
|
| 2220 | - $news_box_title, |
|
| 2221 | - [ |
|
| 2222 | - $this, |
|
| 2223 | - 'espresso_news_post_box', |
|
| 2224 | - ], |
|
| 2225 | - $this->_wp_page_slug, |
|
| 2226 | - 'side' |
|
| 2227 | - ); |
|
| 2228 | - } |
|
| 2229 | - |
|
| 2230 | - |
|
| 2231 | - /** |
|
| 2232 | - * Code for setting up espresso ratings request metabox. |
|
| 2233 | - */ |
|
| 2234 | - protected function _espresso_ratings_request() |
|
| 2235 | - { |
|
| 2236 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2237 | - return; |
|
| 2238 | - } |
|
| 2239 | - $ratings_box_title = apply_filters( |
|
| 2240 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2241 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2242 | - ); |
|
| 2243 | - add_meta_box( |
|
| 2244 | - 'espresso_ratings_request', |
|
| 2245 | - $ratings_box_title, |
|
| 2246 | - [ |
|
| 2247 | - $this, |
|
| 2248 | - 'espresso_ratings_request', |
|
| 2249 | - ], |
|
| 2250 | - $this->_wp_page_slug, |
|
| 2251 | - 'side' |
|
| 2252 | - ); |
|
| 2253 | - } |
|
| 2254 | - |
|
| 2255 | - |
|
| 2256 | - /** |
|
| 2257 | - * Code for setting up espresso ratings request metabox content. |
|
| 2258 | - * |
|
| 2259 | - * @throws DomainException |
|
| 2260 | - */ |
|
| 2261 | - public function espresso_ratings_request() |
|
| 2262 | - { |
|
| 2263 | - EEH_Template::display_template( |
|
| 2264 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2265 | - [] |
|
| 2266 | - ); |
|
| 2267 | - } |
|
| 2268 | - |
|
| 2269 | - |
|
| 2270 | - public static function cached_rss_display($rss_id, $url) |
|
| 2271 | - { |
|
| 2272 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2273 | - . esc_html__('Loading…', 'event_espresso') |
|
| 2274 | - . '</p><p class="hide-if-js">' |
|
| 2275 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2276 | - . '</p>'; |
|
| 2277 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2278 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2279 | - $post = '</div>' . "\n"; |
|
| 2280 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2281 | - $output = get_transient($cache_key); |
|
| 2282 | - if ($output !== false) { |
|
| 2283 | - echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
| 2284 | - return true; |
|
| 2285 | - } |
|
| 2286 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2287 | - echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
| 2288 | - return false; |
|
| 2289 | - } |
|
| 2290 | - ob_start(); |
|
| 2291 | - wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2292 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2293 | - return true; |
|
| 2294 | - } |
|
| 2295 | - |
|
| 2296 | - |
|
| 2297 | - public function espresso_news_post_box() |
|
| 2298 | - { |
|
| 2299 | - ?> |
|
| 2087 | + return $entries_per_page_dropdown; |
|
| 2088 | + } |
|
| 2089 | + |
|
| 2090 | + |
|
| 2091 | + /** |
|
| 2092 | + * _set_search_attributes |
|
| 2093 | + * |
|
| 2094 | + * @return void |
|
| 2095 | + */ |
|
| 2096 | + public function _set_search_attributes() |
|
| 2097 | + { |
|
| 2098 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2099 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2100 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2101 | + : $this->_search_btn_label |
|
| 2102 | + ); |
|
| 2103 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + |
|
| 2107 | + |
|
| 2108 | + /*** END LIST TABLE METHODS **/ |
|
| 2109 | + |
|
| 2110 | + |
|
| 2111 | + /** |
|
| 2112 | + * _add_registered_metaboxes |
|
| 2113 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2114 | + * |
|
| 2115 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2116 | + * @return void |
|
| 2117 | + * @throws EE_Error |
|
| 2118 | + */ |
|
| 2119 | + private function _add_registered_meta_boxes() |
|
| 2120 | + { |
|
| 2121 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2122 | + // we only add meta boxes if the page_route calls for it |
|
| 2123 | + if ( |
|
| 2124 | + is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2125 | + && is_array( |
|
| 2126 | + $this->_route_config['metaboxes'] |
|
| 2127 | + ) |
|
| 2128 | + ) { |
|
| 2129 | + // this simply loops through the callbacks provided |
|
| 2130 | + // and checks if there is a corresponding callback registered by the child |
|
| 2131 | + // if there is then we go ahead and process the metabox loader. |
|
| 2132 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2133 | + // first check for Closures |
|
| 2134 | + if ($metabox_callback instanceof Closure) { |
|
| 2135 | + $result = $metabox_callback(); |
|
| 2136 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2137 | + $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2138 | + } else { |
|
| 2139 | + $result = call_user_func([$this, &$metabox_callback]); |
|
| 2140 | + } |
|
| 2141 | + if ($result === false) { |
|
| 2142 | + // user error msg |
|
| 2143 | + $error_msg = esc_html__( |
|
| 2144 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2145 | + 'event_espresso' |
|
| 2146 | + ); |
|
| 2147 | + // developer error msg |
|
| 2148 | + $error_msg .= '||' |
|
| 2149 | + . sprintf( |
|
| 2150 | + esc_html__( |
|
| 2151 | + '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.', |
|
| 2152 | + 'event_espresso' |
|
| 2153 | + ), |
|
| 2154 | + $metabox_callback |
|
| 2155 | + ); |
|
| 2156 | + throw new EE_Error($error_msg); |
|
| 2157 | + } |
|
| 2158 | + } |
|
| 2159 | + } |
|
| 2160 | + } |
|
| 2161 | + |
|
| 2162 | + |
|
| 2163 | + /** |
|
| 2164 | + * _add_screen_columns |
|
| 2165 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2166 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2167 | + * |
|
| 2168 | + * @return void |
|
| 2169 | + */ |
|
| 2170 | + private function _add_screen_columns() |
|
| 2171 | + { |
|
| 2172 | + if ( |
|
| 2173 | + is_array($this->_route_config) |
|
| 2174 | + && isset($this->_route_config['columns']) |
|
| 2175 | + && is_array($this->_route_config['columns']) |
|
| 2176 | + && count($this->_route_config['columns']) === 2 |
|
| 2177 | + ) { |
|
| 2178 | + add_screen_option( |
|
| 2179 | + 'layout_columns', |
|
| 2180 | + [ |
|
| 2181 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2182 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2183 | + ] |
|
| 2184 | + ); |
|
| 2185 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2186 | + $screen_id = $this->_current_screen->id; |
|
| 2187 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2188 | + $total_columns = ! empty($screen_columns) |
|
| 2189 | + ? $screen_columns |
|
| 2190 | + : $this->_route_config['columns'][1]; |
|
| 2191 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2192 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2193 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2194 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2195 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2196 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2197 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2198 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2199 | + } |
|
| 2200 | + } |
|
| 2201 | + |
|
| 2202 | + |
|
| 2203 | + |
|
| 2204 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2205 | + |
|
| 2206 | + |
|
| 2207 | + /** |
|
| 2208 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2209 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2210 | + * these get loaded on. |
|
| 2211 | + */ |
|
| 2212 | + private function _espresso_news_post_box() |
|
| 2213 | + { |
|
| 2214 | + $news_box_title = apply_filters( |
|
| 2215 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2216 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2217 | + ); |
|
| 2218 | + add_meta_box( |
|
| 2219 | + 'espresso_news_post_box', |
|
| 2220 | + $news_box_title, |
|
| 2221 | + [ |
|
| 2222 | + $this, |
|
| 2223 | + 'espresso_news_post_box', |
|
| 2224 | + ], |
|
| 2225 | + $this->_wp_page_slug, |
|
| 2226 | + 'side' |
|
| 2227 | + ); |
|
| 2228 | + } |
|
| 2229 | + |
|
| 2230 | + |
|
| 2231 | + /** |
|
| 2232 | + * Code for setting up espresso ratings request metabox. |
|
| 2233 | + */ |
|
| 2234 | + protected function _espresso_ratings_request() |
|
| 2235 | + { |
|
| 2236 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2237 | + return; |
|
| 2238 | + } |
|
| 2239 | + $ratings_box_title = apply_filters( |
|
| 2240 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2241 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2242 | + ); |
|
| 2243 | + add_meta_box( |
|
| 2244 | + 'espresso_ratings_request', |
|
| 2245 | + $ratings_box_title, |
|
| 2246 | + [ |
|
| 2247 | + $this, |
|
| 2248 | + 'espresso_ratings_request', |
|
| 2249 | + ], |
|
| 2250 | + $this->_wp_page_slug, |
|
| 2251 | + 'side' |
|
| 2252 | + ); |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + |
|
| 2256 | + /** |
|
| 2257 | + * Code for setting up espresso ratings request metabox content. |
|
| 2258 | + * |
|
| 2259 | + * @throws DomainException |
|
| 2260 | + */ |
|
| 2261 | + public function espresso_ratings_request() |
|
| 2262 | + { |
|
| 2263 | + EEH_Template::display_template( |
|
| 2264 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2265 | + [] |
|
| 2266 | + ); |
|
| 2267 | + } |
|
| 2268 | + |
|
| 2269 | + |
|
| 2270 | + public static function cached_rss_display($rss_id, $url) |
|
| 2271 | + { |
|
| 2272 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2273 | + . esc_html__('Loading…', 'event_espresso') |
|
| 2274 | + . '</p><p class="hide-if-js">' |
|
| 2275 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2276 | + . '</p>'; |
|
| 2277 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2278 | + $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2279 | + $post = '</div>' . "\n"; |
|
| 2280 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2281 | + $output = get_transient($cache_key); |
|
| 2282 | + if ($output !== false) { |
|
| 2283 | + echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
| 2284 | + return true; |
|
| 2285 | + } |
|
| 2286 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2287 | + echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
| 2288 | + return false; |
|
| 2289 | + } |
|
| 2290 | + ob_start(); |
|
| 2291 | + wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2292 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2293 | + return true; |
|
| 2294 | + } |
|
| 2295 | + |
|
| 2296 | + |
|
| 2297 | + public function espresso_news_post_box() |
|
| 2298 | + { |
|
| 2299 | + ?> |
|
| 2300 | 2300 | <div class="padding"> |
| 2301 | 2301 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2302 | 2302 | <?php |
| 2303 | - // Get RSS Feed(s) |
|
| 2304 | - self::cached_rss_display( |
|
| 2305 | - 'espresso_news_post_box_content', |
|
| 2306 | - esc_url_raw( |
|
| 2307 | - apply_filters( |
|
| 2308 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2309 | - 'https://eventespresso.com/feed/' |
|
| 2310 | - ) |
|
| 2311 | - ) |
|
| 2312 | - ); |
|
| 2313 | - ?> |
|
| 2303 | + // Get RSS Feed(s) |
|
| 2304 | + self::cached_rss_display( |
|
| 2305 | + 'espresso_news_post_box_content', |
|
| 2306 | + esc_url_raw( |
|
| 2307 | + apply_filters( |
|
| 2308 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2309 | + 'https://eventespresso.com/feed/' |
|
| 2310 | + ) |
|
| 2311 | + ) |
|
| 2312 | + ); |
|
| 2313 | + ?> |
|
| 2314 | 2314 | </div> |
| 2315 | 2315 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2316 | 2316 | </div> |
| 2317 | 2317 | <?php |
| 2318 | - } |
|
| 2319 | - |
|
| 2320 | - |
|
| 2321 | - private function _espresso_links_post_box() |
|
| 2322 | - { |
|
| 2323 | - // Hiding until we actually have content to put in here... |
|
| 2324 | - // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2325 | - } |
|
| 2326 | - |
|
| 2327 | - |
|
| 2328 | - public function espresso_links_post_box() |
|
| 2329 | - { |
|
| 2330 | - // Hiding until we actually have content to put in here... |
|
| 2331 | - // EEH_Template::display_template( |
|
| 2332 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2333 | - // ); |
|
| 2334 | - } |
|
| 2335 | - |
|
| 2336 | - |
|
| 2337 | - protected function _espresso_sponsors_post_box() |
|
| 2338 | - { |
|
| 2339 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2340 | - add_meta_box( |
|
| 2341 | - 'espresso_sponsors_post_box', |
|
| 2342 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2343 | - [$this, 'espresso_sponsors_post_box'], |
|
| 2344 | - $this->_wp_page_slug, |
|
| 2345 | - 'side' |
|
| 2346 | - ); |
|
| 2347 | - } |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - |
|
| 2351 | - public function espresso_sponsors_post_box() |
|
| 2352 | - { |
|
| 2353 | - EEH_Template::display_template( |
|
| 2354 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2355 | - ); |
|
| 2356 | - } |
|
| 2357 | - |
|
| 2358 | - |
|
| 2359 | - private function _publish_post_box() |
|
| 2360 | - { |
|
| 2361 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2362 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2363 | - // then we'll use that for the metabox label. |
|
| 2364 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2365 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2366 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2367 | - : $this->_labels['publishbox']; |
|
| 2368 | - } else { |
|
| 2369 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2370 | - } |
|
| 2371 | - $box_label = apply_filters( |
|
| 2372 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2373 | - $box_label, |
|
| 2374 | - $this->_req_action, |
|
| 2375 | - $this |
|
| 2376 | - ); |
|
| 2377 | - add_meta_box( |
|
| 2378 | - $meta_box_ref, |
|
| 2379 | - $box_label, |
|
| 2380 | - [$this, 'editor_overview'], |
|
| 2381 | - $this->_current_screen->id, |
|
| 2382 | - 'side', |
|
| 2383 | - 'high' |
|
| 2384 | - ); |
|
| 2385 | - } |
|
| 2386 | - |
|
| 2387 | - |
|
| 2388 | - public function editor_overview() |
|
| 2389 | - { |
|
| 2390 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2391 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2392 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2393 | - : ''; |
|
| 2394 | - echo EEH_Template::display_template( |
|
| 2395 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2396 | - $this->_template_args, |
|
| 2397 | - true |
|
| 2398 | - ); |
|
| 2399 | - } |
|
| 2400 | - |
|
| 2401 | - |
|
| 2402 | - /** end of globally available metaboxes section **/ |
|
| 2403 | - |
|
| 2404 | - |
|
| 2405 | - /** |
|
| 2406 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2407 | - * protected method. |
|
| 2408 | - * |
|
| 2409 | - * @param string $name |
|
| 2410 | - * @param int $id |
|
| 2411 | - * @param bool $delete |
|
| 2412 | - * @param string $save_close_redirect_URL |
|
| 2413 | - * @param bool $both_btns |
|
| 2414 | - * @throws EE_Error |
|
| 2415 | - * @throws InvalidArgumentException |
|
| 2416 | - * @throws InvalidDataTypeException |
|
| 2417 | - * @throws InvalidInterfaceException |
|
| 2418 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2419 | - * @since 4.6.0 |
|
| 2420 | - */ |
|
| 2421 | - public function set_publish_post_box_vars( |
|
| 2422 | - $name = '', |
|
| 2423 | - $id = 0, |
|
| 2424 | - $delete = false, |
|
| 2425 | - $save_close_redirect_URL = '', |
|
| 2426 | - $both_btns = true |
|
| 2427 | - ) { |
|
| 2428 | - $this->_set_publish_post_box_vars( |
|
| 2429 | - $name, |
|
| 2430 | - $id, |
|
| 2431 | - $delete, |
|
| 2432 | - $save_close_redirect_URL, |
|
| 2433 | - $both_btns |
|
| 2434 | - ); |
|
| 2435 | - } |
|
| 2436 | - |
|
| 2437 | - |
|
| 2438 | - /** |
|
| 2439 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2440 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2441 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2442 | - * values for the name and id arguments. |
|
| 2443 | - * |
|
| 2444 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2445 | - * @param int $id id attached to the item published |
|
| 2446 | - * @param string $delete page route callback for the delete action |
|
| 2447 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2448 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2449 | - * the Save button |
|
| 2450 | - * @throws EE_Error |
|
| 2451 | - * @throws InvalidArgumentException |
|
| 2452 | - * @throws InvalidDataTypeException |
|
| 2453 | - * @throws InvalidInterfaceException |
|
| 2454 | - * @todo Add in validation for name/id arguments. |
|
| 2455 | - */ |
|
| 2456 | - protected function _set_publish_post_box_vars( |
|
| 2457 | - $name = '', |
|
| 2458 | - $id = 0, |
|
| 2459 | - $delete = '', |
|
| 2460 | - $save_close_redirect_URL = '', |
|
| 2461 | - $both_btns = true |
|
| 2462 | - ) { |
|
| 2463 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2464 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2465 | - ? $save_close_redirect_URL |
|
| 2466 | - : $this->_admin_base_url; |
|
| 2467 | - // create the Save & Close and Save buttons |
|
| 2468 | - $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2469 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2470 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2471 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2472 | - : ''; |
|
| 2473 | - if ($delete && ! empty($id)) { |
|
| 2474 | - // make sure we have a default if just true is sent. |
|
| 2475 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2476 | - $delete_link_args = [$name => $id]; |
|
| 2477 | - $delete = $this->get_action_link_or_button( |
|
| 2478 | - $delete, |
|
| 2479 | - $delete, |
|
| 2480 | - $delete_link_args, |
|
| 2481 | - 'submitdelete deletion', |
|
| 2482 | - '', |
|
| 2483 | - false |
|
| 2484 | - ); |
|
| 2485 | - } |
|
| 2486 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2487 | - if (! empty($name) && ! empty($id)) { |
|
| 2488 | - $hidden_field_arr[ $name ] = [ |
|
| 2489 | - 'type' => 'hidden', |
|
| 2490 | - 'value' => $id, |
|
| 2491 | - ]; |
|
| 2492 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2493 | - } else { |
|
| 2494 | - $hf = ''; |
|
| 2495 | - } |
|
| 2496 | - // add hidden field |
|
| 2497 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2498 | - ? $hf[ $name ]['field'] |
|
| 2499 | - : $hf; |
|
| 2500 | - } |
|
| 2501 | - |
|
| 2502 | - |
|
| 2503 | - /** |
|
| 2504 | - * displays an error message to ppl who have javascript disabled |
|
| 2505 | - * |
|
| 2506 | - * @return void |
|
| 2507 | - */ |
|
| 2508 | - private function _display_no_javascript_warning() |
|
| 2509 | - { |
|
| 2510 | - ?> |
|
| 2318 | + } |
|
| 2319 | + |
|
| 2320 | + |
|
| 2321 | + private function _espresso_links_post_box() |
|
| 2322 | + { |
|
| 2323 | + // Hiding until we actually have content to put in here... |
|
| 2324 | + // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2325 | + } |
|
| 2326 | + |
|
| 2327 | + |
|
| 2328 | + public function espresso_links_post_box() |
|
| 2329 | + { |
|
| 2330 | + // Hiding until we actually have content to put in here... |
|
| 2331 | + // EEH_Template::display_template( |
|
| 2332 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2333 | + // ); |
|
| 2334 | + } |
|
| 2335 | + |
|
| 2336 | + |
|
| 2337 | + protected function _espresso_sponsors_post_box() |
|
| 2338 | + { |
|
| 2339 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2340 | + add_meta_box( |
|
| 2341 | + 'espresso_sponsors_post_box', |
|
| 2342 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2343 | + [$this, 'espresso_sponsors_post_box'], |
|
| 2344 | + $this->_wp_page_slug, |
|
| 2345 | + 'side' |
|
| 2346 | + ); |
|
| 2347 | + } |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + |
|
| 2351 | + public function espresso_sponsors_post_box() |
|
| 2352 | + { |
|
| 2353 | + EEH_Template::display_template( |
|
| 2354 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2355 | + ); |
|
| 2356 | + } |
|
| 2357 | + |
|
| 2358 | + |
|
| 2359 | + private function _publish_post_box() |
|
| 2360 | + { |
|
| 2361 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2362 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2363 | + // then we'll use that for the metabox label. |
|
| 2364 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2365 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2366 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2367 | + : $this->_labels['publishbox']; |
|
| 2368 | + } else { |
|
| 2369 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2370 | + } |
|
| 2371 | + $box_label = apply_filters( |
|
| 2372 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2373 | + $box_label, |
|
| 2374 | + $this->_req_action, |
|
| 2375 | + $this |
|
| 2376 | + ); |
|
| 2377 | + add_meta_box( |
|
| 2378 | + $meta_box_ref, |
|
| 2379 | + $box_label, |
|
| 2380 | + [$this, 'editor_overview'], |
|
| 2381 | + $this->_current_screen->id, |
|
| 2382 | + 'side', |
|
| 2383 | + 'high' |
|
| 2384 | + ); |
|
| 2385 | + } |
|
| 2386 | + |
|
| 2387 | + |
|
| 2388 | + public function editor_overview() |
|
| 2389 | + { |
|
| 2390 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2391 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2392 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2393 | + : ''; |
|
| 2394 | + echo EEH_Template::display_template( |
|
| 2395 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2396 | + $this->_template_args, |
|
| 2397 | + true |
|
| 2398 | + ); |
|
| 2399 | + } |
|
| 2400 | + |
|
| 2401 | + |
|
| 2402 | + /** end of globally available metaboxes section **/ |
|
| 2403 | + |
|
| 2404 | + |
|
| 2405 | + /** |
|
| 2406 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2407 | + * protected method. |
|
| 2408 | + * |
|
| 2409 | + * @param string $name |
|
| 2410 | + * @param int $id |
|
| 2411 | + * @param bool $delete |
|
| 2412 | + * @param string $save_close_redirect_URL |
|
| 2413 | + * @param bool $both_btns |
|
| 2414 | + * @throws EE_Error |
|
| 2415 | + * @throws InvalidArgumentException |
|
| 2416 | + * @throws InvalidDataTypeException |
|
| 2417 | + * @throws InvalidInterfaceException |
|
| 2418 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2419 | + * @since 4.6.0 |
|
| 2420 | + */ |
|
| 2421 | + public function set_publish_post_box_vars( |
|
| 2422 | + $name = '', |
|
| 2423 | + $id = 0, |
|
| 2424 | + $delete = false, |
|
| 2425 | + $save_close_redirect_URL = '', |
|
| 2426 | + $both_btns = true |
|
| 2427 | + ) { |
|
| 2428 | + $this->_set_publish_post_box_vars( |
|
| 2429 | + $name, |
|
| 2430 | + $id, |
|
| 2431 | + $delete, |
|
| 2432 | + $save_close_redirect_URL, |
|
| 2433 | + $both_btns |
|
| 2434 | + ); |
|
| 2435 | + } |
|
| 2436 | + |
|
| 2437 | + |
|
| 2438 | + /** |
|
| 2439 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2440 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2441 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2442 | + * values for the name and id arguments. |
|
| 2443 | + * |
|
| 2444 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2445 | + * @param int $id id attached to the item published |
|
| 2446 | + * @param string $delete page route callback for the delete action |
|
| 2447 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2448 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2449 | + * the Save button |
|
| 2450 | + * @throws EE_Error |
|
| 2451 | + * @throws InvalidArgumentException |
|
| 2452 | + * @throws InvalidDataTypeException |
|
| 2453 | + * @throws InvalidInterfaceException |
|
| 2454 | + * @todo Add in validation for name/id arguments. |
|
| 2455 | + */ |
|
| 2456 | + protected function _set_publish_post_box_vars( |
|
| 2457 | + $name = '', |
|
| 2458 | + $id = 0, |
|
| 2459 | + $delete = '', |
|
| 2460 | + $save_close_redirect_URL = '', |
|
| 2461 | + $both_btns = true |
|
| 2462 | + ) { |
|
| 2463 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2464 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2465 | + ? $save_close_redirect_URL |
|
| 2466 | + : $this->_admin_base_url; |
|
| 2467 | + // create the Save & Close and Save buttons |
|
| 2468 | + $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2469 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2470 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2471 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2472 | + : ''; |
|
| 2473 | + if ($delete && ! empty($id)) { |
|
| 2474 | + // make sure we have a default if just true is sent. |
|
| 2475 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2476 | + $delete_link_args = [$name => $id]; |
|
| 2477 | + $delete = $this->get_action_link_or_button( |
|
| 2478 | + $delete, |
|
| 2479 | + $delete, |
|
| 2480 | + $delete_link_args, |
|
| 2481 | + 'submitdelete deletion', |
|
| 2482 | + '', |
|
| 2483 | + false |
|
| 2484 | + ); |
|
| 2485 | + } |
|
| 2486 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2487 | + if (! empty($name) && ! empty($id)) { |
|
| 2488 | + $hidden_field_arr[ $name ] = [ |
|
| 2489 | + 'type' => 'hidden', |
|
| 2490 | + 'value' => $id, |
|
| 2491 | + ]; |
|
| 2492 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2493 | + } else { |
|
| 2494 | + $hf = ''; |
|
| 2495 | + } |
|
| 2496 | + // add hidden field |
|
| 2497 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2498 | + ? $hf[ $name ]['field'] |
|
| 2499 | + : $hf; |
|
| 2500 | + } |
|
| 2501 | + |
|
| 2502 | + |
|
| 2503 | + /** |
|
| 2504 | + * displays an error message to ppl who have javascript disabled |
|
| 2505 | + * |
|
| 2506 | + * @return void |
|
| 2507 | + */ |
|
| 2508 | + private function _display_no_javascript_warning() |
|
| 2509 | + { |
|
| 2510 | + ?> |
|
| 2511 | 2511 | <noscript> |
| 2512 | 2512 | <div id="no-js-message" class="error"> |
| 2513 | 2513 | <p style="font-size:1.3em;"> |
| 2514 | 2514 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2515 | 2515 | <?php esc_html_e( |
| 2516 | - '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.', |
|
| 2517 | - 'event_espresso' |
|
| 2518 | - ); ?> |
|
| 2516 | + '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.', |
|
| 2517 | + 'event_espresso' |
|
| 2518 | + ); ?> |
|
| 2519 | 2519 | </p> |
| 2520 | 2520 | </div> |
| 2521 | 2521 | </noscript> |
| 2522 | 2522 | <?php |
| 2523 | - } |
|
| 2524 | - |
|
| 2525 | - |
|
| 2526 | - /** |
|
| 2527 | - * displays espresso success and/or error notices |
|
| 2528 | - * |
|
| 2529 | - * @return void |
|
| 2530 | - */ |
|
| 2531 | - protected function _display_espresso_notices() |
|
| 2532 | - { |
|
| 2533 | - $notices = $this->_get_transient(true); |
|
| 2534 | - echo stripslashes($notices); |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - |
|
| 2538 | - /** |
|
| 2539 | - * spinny things pacify the masses |
|
| 2540 | - * |
|
| 2541 | - * @return void |
|
| 2542 | - */ |
|
| 2543 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2544 | - { |
|
| 2545 | - ?> |
|
| 2523 | + } |
|
| 2524 | + |
|
| 2525 | + |
|
| 2526 | + /** |
|
| 2527 | + * displays espresso success and/or error notices |
|
| 2528 | + * |
|
| 2529 | + * @return void |
|
| 2530 | + */ |
|
| 2531 | + protected function _display_espresso_notices() |
|
| 2532 | + { |
|
| 2533 | + $notices = $this->_get_transient(true); |
|
| 2534 | + echo stripslashes($notices); |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + |
|
| 2538 | + /** |
|
| 2539 | + * spinny things pacify the masses |
|
| 2540 | + * |
|
| 2541 | + * @return void |
|
| 2542 | + */ |
|
| 2543 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2544 | + { |
|
| 2545 | + ?> |
|
| 2546 | 2546 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2547 | 2547 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
| 2548 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2548 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2549 | 2549 | </div> |
| 2550 | 2550 | <?php |
| 2551 | - } |
|
| 2551 | + } |
|
| 2552 | 2552 | |
| 2553 | 2553 | |
| 2554 | - /** |
|
| 2555 | - * add admin page overlay for modal boxes |
|
| 2556 | - * |
|
| 2557 | - * @return void |
|
| 2558 | - */ |
|
| 2559 | - protected function _add_admin_page_overlay() |
|
| 2560 | - { |
|
| 2561 | - ?> |
|
| 2554 | + /** |
|
| 2555 | + * add admin page overlay for modal boxes |
|
| 2556 | + * |
|
| 2557 | + * @return void |
|
| 2558 | + */ |
|
| 2559 | + protected function _add_admin_page_overlay() |
|
| 2560 | + { |
|
| 2561 | + ?> |
|
| 2562 | 2562 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2563 | 2563 | <?php |
| 2564 | - } |
|
| 2565 | - |
|
| 2566 | - |
|
| 2567 | - /** |
|
| 2568 | - * facade for add_meta_box |
|
| 2569 | - * |
|
| 2570 | - * @param string $action where the metabox gets displayed |
|
| 2571 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2572 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2573 | - * instead of the one created in here. |
|
| 2574 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2575 | - * @param string $column what metabox column |
|
| 2576 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2577 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2578 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2579 | - * @throws DomainException |
|
| 2580 | - */ |
|
| 2581 | - public function _add_admin_page_meta_box( |
|
| 2582 | - $action, |
|
| 2583 | - $title, |
|
| 2584 | - $callback, |
|
| 2585 | - $callback_args, |
|
| 2586 | - $column = 'normal', |
|
| 2587 | - $priority = 'high', |
|
| 2588 | - $create_func = true |
|
| 2589 | - ) { |
|
| 2590 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2591 | - // 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. |
|
| 2592 | - if (empty($callback_args) && $create_func) { |
|
| 2593 | - $callback_args = [ |
|
| 2594 | - 'template_path' => $this->_template_path, |
|
| 2595 | - 'template_args' => $this->_template_args, |
|
| 2596 | - ]; |
|
| 2597 | - } |
|
| 2598 | - // 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) |
|
| 2599 | - $call_back_func = $create_func |
|
| 2600 | - ? function ($post, $metabox) { |
|
| 2601 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2602 | - echo EEH_Template::display_template( |
|
| 2603 | - $metabox['args']['template_path'], |
|
| 2604 | - $metabox['args']['template_args'], |
|
| 2605 | - true |
|
| 2606 | - ); |
|
| 2607 | - } |
|
| 2608 | - : $callback; |
|
| 2609 | - add_meta_box( |
|
| 2610 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2611 | - $title, |
|
| 2612 | - $call_back_func, |
|
| 2613 | - $this->_wp_page_slug, |
|
| 2614 | - $column, |
|
| 2615 | - $priority, |
|
| 2616 | - $callback_args |
|
| 2617 | - ); |
|
| 2618 | - } |
|
| 2619 | - |
|
| 2620 | - |
|
| 2621 | - /** |
|
| 2622 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2623 | - * |
|
| 2624 | - * @throws DomainException |
|
| 2625 | - * @throws EE_Error |
|
| 2626 | - */ |
|
| 2627 | - public function display_admin_page_with_metabox_columns() |
|
| 2628 | - { |
|
| 2629 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2630 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2631 | - $this->_column_template_path, |
|
| 2632 | - $this->_template_args, |
|
| 2633 | - true |
|
| 2634 | - ); |
|
| 2635 | - // the final wrapper |
|
| 2636 | - $this->admin_page_wrapper(); |
|
| 2637 | - } |
|
| 2638 | - |
|
| 2639 | - |
|
| 2640 | - /** |
|
| 2641 | - * generates HTML wrapper for an admin details page |
|
| 2642 | - * |
|
| 2643 | - * @return void |
|
| 2644 | - * @throws EE_Error |
|
| 2645 | - * @throws DomainException |
|
| 2646 | - */ |
|
| 2647 | - public function display_admin_page_with_sidebar() |
|
| 2648 | - { |
|
| 2649 | - $this->_display_admin_page(true); |
|
| 2650 | - } |
|
| 2651 | - |
|
| 2652 | - |
|
| 2653 | - /** |
|
| 2654 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2655 | - * |
|
| 2656 | - * @return void |
|
| 2657 | - * @throws EE_Error |
|
| 2658 | - * @throws DomainException |
|
| 2659 | - */ |
|
| 2660 | - public function display_admin_page_with_no_sidebar() |
|
| 2661 | - { |
|
| 2662 | - $this->_display_admin_page(); |
|
| 2663 | - } |
|
| 2664 | - |
|
| 2665 | - |
|
| 2666 | - /** |
|
| 2667 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2668 | - * |
|
| 2669 | - * @return void |
|
| 2670 | - * @throws EE_Error |
|
| 2671 | - * @throws DomainException |
|
| 2672 | - */ |
|
| 2673 | - public function display_about_admin_page() |
|
| 2674 | - { |
|
| 2675 | - $this->_display_admin_page(false, true); |
|
| 2676 | - } |
|
| 2677 | - |
|
| 2678 | - |
|
| 2679 | - /** |
|
| 2680 | - * display_admin_page |
|
| 2681 | - * contains the code for actually displaying an admin page |
|
| 2682 | - * |
|
| 2683 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2684 | - * @param boolean $about use the about_admin_wrapper instead of the default. |
|
| 2685 | - * @return void |
|
| 2686 | - * @throws DomainException |
|
| 2687 | - * @throws EE_Error |
|
| 2688 | - */ |
|
| 2689 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2690 | - { |
|
| 2691 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2692 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2693 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2694 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2695 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2696 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2697 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2698 | - ? 'poststuff' |
|
| 2699 | - : 'espresso-default-admin'; |
|
| 2700 | - $template_path = $sidebar |
|
| 2701 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2702 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2703 | - if ($this->request->isAjax()) { |
|
| 2704 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2705 | - } |
|
| 2706 | - $template_path = ! empty($this->_column_template_path) |
|
| 2707 | - ? $this->_column_template_path : $template_path; |
|
| 2708 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2709 | - ? $this->_template_args['admin_page_content'] |
|
| 2710 | - : ''; |
|
| 2711 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2712 | - ? $this->_template_args['before_admin_page_content'] |
|
| 2713 | - : ''; |
|
| 2714 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2715 | - ? $this->_template_args['after_admin_page_content'] |
|
| 2716 | - : ''; |
|
| 2717 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2718 | - $template_path, |
|
| 2719 | - $this->_template_args, |
|
| 2720 | - true |
|
| 2721 | - ); |
|
| 2722 | - // the final template wrapper |
|
| 2723 | - $this->admin_page_wrapper($about); |
|
| 2724 | - } |
|
| 2725 | - |
|
| 2726 | - |
|
| 2727 | - /** |
|
| 2728 | - * This is used to display caf preview pages. |
|
| 2729 | - * |
|
| 2730 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2731 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2732 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2733 | - * @return void |
|
| 2734 | - * @throws DomainException |
|
| 2735 | - * @throws EE_Error |
|
| 2736 | - * @throws InvalidArgumentException |
|
| 2737 | - * @throws InvalidDataTypeException |
|
| 2738 | - * @throws InvalidInterfaceException |
|
| 2739 | - * @since 4.3.2 |
|
| 2740 | - */ |
|
| 2741 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2742 | - { |
|
| 2743 | - // let's generate a default preview action button if there isn't one already present. |
|
| 2744 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2745 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2746 | - 'event_espresso' |
|
| 2747 | - ); |
|
| 2748 | - $buy_now_url = add_query_arg( |
|
| 2749 | - [ |
|
| 2750 | - 'ee_ver' => 'ee4', |
|
| 2751 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2752 | - 'utm_medium' => 'link', |
|
| 2753 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2754 | - 'utm_content' => 'buy_now_button', |
|
| 2755 | - ], |
|
| 2756 | - 'https://eventespresso.com/pricing/' |
|
| 2757 | - ); |
|
| 2758 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2759 | - ? $this->get_action_link_or_button( |
|
| 2760 | - '', |
|
| 2761 | - 'buy_now', |
|
| 2762 | - [], |
|
| 2763 | - 'button-primary button-large', |
|
| 2764 | - esc_url_raw($buy_now_url), |
|
| 2765 | - true |
|
| 2766 | - ) |
|
| 2767 | - : $this->_template_args['preview_action_button']; |
|
| 2768 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2769 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2770 | - $this->_template_args, |
|
| 2771 | - true |
|
| 2772 | - ); |
|
| 2773 | - $this->_display_admin_page($display_sidebar); |
|
| 2774 | - } |
|
| 2775 | - |
|
| 2776 | - |
|
| 2777 | - /** |
|
| 2778 | - * display_admin_list_table_page_with_sidebar |
|
| 2779 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2780 | - * |
|
| 2781 | - * @return void |
|
| 2782 | - * @throws EE_Error |
|
| 2783 | - * @throws DomainException |
|
| 2784 | - */ |
|
| 2785 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2786 | - { |
|
| 2787 | - $this->_display_admin_list_table_page(true); |
|
| 2788 | - } |
|
| 2789 | - |
|
| 2790 | - |
|
| 2791 | - /** |
|
| 2792 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2793 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2794 | - * |
|
| 2795 | - * @return void |
|
| 2796 | - * @throws EE_Error |
|
| 2797 | - * @throws DomainException |
|
| 2798 | - */ |
|
| 2799 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2800 | - { |
|
| 2801 | - $this->_display_admin_list_table_page(); |
|
| 2802 | - } |
|
| 2803 | - |
|
| 2804 | - |
|
| 2805 | - /** |
|
| 2806 | - * generates html wrapper for an admin_list_table page |
|
| 2807 | - * |
|
| 2808 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2809 | - * @return void |
|
| 2810 | - * @throws DomainException |
|
| 2811 | - * @throws EE_Error |
|
| 2812 | - */ |
|
| 2813 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 2814 | - { |
|
| 2815 | - // setup search attributes |
|
| 2816 | - $this->_set_search_attributes(); |
|
| 2817 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2818 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2819 | - $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 2820 | - ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 2821 | - : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 2822 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2823 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2824 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2825 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2826 | - if (! empty($ajax_sorting_callback)) { |
|
| 2827 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2828 | - $ajax_sorting_callback . '_nonce', |
|
| 2829 | - $ajax_sorting_callback . '_nonce', |
|
| 2830 | - false, |
|
| 2831 | - false |
|
| 2832 | - ); |
|
| 2833 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2834 | - . $this->page_slug |
|
| 2835 | - . '" />'; |
|
| 2836 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2837 | - . $ajax_sorting_callback |
|
| 2838 | - . '" />'; |
|
| 2839 | - } else { |
|
| 2840 | - $sortable_list_table_form_fields = ''; |
|
| 2841 | - } |
|
| 2842 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2843 | - $hidden_form_fields = |
|
| 2844 | - isset($this->_template_args['list_table_hidden_fields']) |
|
| 2845 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 2846 | - : ''; |
|
| 2847 | - |
|
| 2848 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2849 | - $hidden_form_fields .= ' |
|
| 2564 | + } |
|
| 2565 | + |
|
| 2566 | + |
|
| 2567 | + /** |
|
| 2568 | + * facade for add_meta_box |
|
| 2569 | + * |
|
| 2570 | + * @param string $action where the metabox gets displayed |
|
| 2571 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2572 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2573 | + * instead of the one created in here. |
|
| 2574 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2575 | + * @param string $column what metabox column |
|
| 2576 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2577 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2578 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2579 | + * @throws DomainException |
|
| 2580 | + */ |
|
| 2581 | + public function _add_admin_page_meta_box( |
|
| 2582 | + $action, |
|
| 2583 | + $title, |
|
| 2584 | + $callback, |
|
| 2585 | + $callback_args, |
|
| 2586 | + $column = 'normal', |
|
| 2587 | + $priority = 'high', |
|
| 2588 | + $create_func = true |
|
| 2589 | + ) { |
|
| 2590 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2591 | + // 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. |
|
| 2592 | + if (empty($callback_args) && $create_func) { |
|
| 2593 | + $callback_args = [ |
|
| 2594 | + 'template_path' => $this->_template_path, |
|
| 2595 | + 'template_args' => $this->_template_args, |
|
| 2596 | + ]; |
|
| 2597 | + } |
|
| 2598 | + // 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) |
|
| 2599 | + $call_back_func = $create_func |
|
| 2600 | + ? function ($post, $metabox) { |
|
| 2601 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2602 | + echo EEH_Template::display_template( |
|
| 2603 | + $metabox['args']['template_path'], |
|
| 2604 | + $metabox['args']['template_args'], |
|
| 2605 | + true |
|
| 2606 | + ); |
|
| 2607 | + } |
|
| 2608 | + : $callback; |
|
| 2609 | + add_meta_box( |
|
| 2610 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2611 | + $title, |
|
| 2612 | + $call_back_func, |
|
| 2613 | + $this->_wp_page_slug, |
|
| 2614 | + $column, |
|
| 2615 | + $priority, |
|
| 2616 | + $callback_args |
|
| 2617 | + ); |
|
| 2618 | + } |
|
| 2619 | + |
|
| 2620 | + |
|
| 2621 | + /** |
|
| 2622 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2623 | + * |
|
| 2624 | + * @throws DomainException |
|
| 2625 | + * @throws EE_Error |
|
| 2626 | + */ |
|
| 2627 | + public function display_admin_page_with_metabox_columns() |
|
| 2628 | + { |
|
| 2629 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2630 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2631 | + $this->_column_template_path, |
|
| 2632 | + $this->_template_args, |
|
| 2633 | + true |
|
| 2634 | + ); |
|
| 2635 | + // the final wrapper |
|
| 2636 | + $this->admin_page_wrapper(); |
|
| 2637 | + } |
|
| 2638 | + |
|
| 2639 | + |
|
| 2640 | + /** |
|
| 2641 | + * generates HTML wrapper for an admin details page |
|
| 2642 | + * |
|
| 2643 | + * @return void |
|
| 2644 | + * @throws EE_Error |
|
| 2645 | + * @throws DomainException |
|
| 2646 | + */ |
|
| 2647 | + public function display_admin_page_with_sidebar() |
|
| 2648 | + { |
|
| 2649 | + $this->_display_admin_page(true); |
|
| 2650 | + } |
|
| 2651 | + |
|
| 2652 | + |
|
| 2653 | + /** |
|
| 2654 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2655 | + * |
|
| 2656 | + * @return void |
|
| 2657 | + * @throws EE_Error |
|
| 2658 | + * @throws DomainException |
|
| 2659 | + */ |
|
| 2660 | + public function display_admin_page_with_no_sidebar() |
|
| 2661 | + { |
|
| 2662 | + $this->_display_admin_page(); |
|
| 2663 | + } |
|
| 2664 | + |
|
| 2665 | + |
|
| 2666 | + /** |
|
| 2667 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2668 | + * |
|
| 2669 | + * @return void |
|
| 2670 | + * @throws EE_Error |
|
| 2671 | + * @throws DomainException |
|
| 2672 | + */ |
|
| 2673 | + public function display_about_admin_page() |
|
| 2674 | + { |
|
| 2675 | + $this->_display_admin_page(false, true); |
|
| 2676 | + } |
|
| 2677 | + |
|
| 2678 | + |
|
| 2679 | + /** |
|
| 2680 | + * display_admin_page |
|
| 2681 | + * contains the code for actually displaying an admin page |
|
| 2682 | + * |
|
| 2683 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2684 | + * @param boolean $about use the about_admin_wrapper instead of the default. |
|
| 2685 | + * @return void |
|
| 2686 | + * @throws DomainException |
|
| 2687 | + * @throws EE_Error |
|
| 2688 | + */ |
|
| 2689 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2690 | + { |
|
| 2691 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2692 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2693 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2694 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2695 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2696 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2697 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2698 | + ? 'poststuff' |
|
| 2699 | + : 'espresso-default-admin'; |
|
| 2700 | + $template_path = $sidebar |
|
| 2701 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2702 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2703 | + if ($this->request->isAjax()) { |
|
| 2704 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2705 | + } |
|
| 2706 | + $template_path = ! empty($this->_column_template_path) |
|
| 2707 | + ? $this->_column_template_path : $template_path; |
|
| 2708 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2709 | + ? $this->_template_args['admin_page_content'] |
|
| 2710 | + : ''; |
|
| 2711 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2712 | + ? $this->_template_args['before_admin_page_content'] |
|
| 2713 | + : ''; |
|
| 2714 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2715 | + ? $this->_template_args['after_admin_page_content'] |
|
| 2716 | + : ''; |
|
| 2717 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2718 | + $template_path, |
|
| 2719 | + $this->_template_args, |
|
| 2720 | + true |
|
| 2721 | + ); |
|
| 2722 | + // the final template wrapper |
|
| 2723 | + $this->admin_page_wrapper($about); |
|
| 2724 | + } |
|
| 2725 | + |
|
| 2726 | + |
|
| 2727 | + /** |
|
| 2728 | + * This is used to display caf preview pages. |
|
| 2729 | + * |
|
| 2730 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2731 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2732 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2733 | + * @return void |
|
| 2734 | + * @throws DomainException |
|
| 2735 | + * @throws EE_Error |
|
| 2736 | + * @throws InvalidArgumentException |
|
| 2737 | + * @throws InvalidDataTypeException |
|
| 2738 | + * @throws InvalidInterfaceException |
|
| 2739 | + * @since 4.3.2 |
|
| 2740 | + */ |
|
| 2741 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2742 | + { |
|
| 2743 | + // let's generate a default preview action button if there isn't one already present. |
|
| 2744 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2745 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2746 | + 'event_espresso' |
|
| 2747 | + ); |
|
| 2748 | + $buy_now_url = add_query_arg( |
|
| 2749 | + [ |
|
| 2750 | + 'ee_ver' => 'ee4', |
|
| 2751 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2752 | + 'utm_medium' => 'link', |
|
| 2753 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2754 | + 'utm_content' => 'buy_now_button', |
|
| 2755 | + ], |
|
| 2756 | + 'https://eventespresso.com/pricing/' |
|
| 2757 | + ); |
|
| 2758 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2759 | + ? $this->get_action_link_or_button( |
|
| 2760 | + '', |
|
| 2761 | + 'buy_now', |
|
| 2762 | + [], |
|
| 2763 | + 'button-primary button-large', |
|
| 2764 | + esc_url_raw($buy_now_url), |
|
| 2765 | + true |
|
| 2766 | + ) |
|
| 2767 | + : $this->_template_args['preview_action_button']; |
|
| 2768 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2769 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2770 | + $this->_template_args, |
|
| 2771 | + true |
|
| 2772 | + ); |
|
| 2773 | + $this->_display_admin_page($display_sidebar); |
|
| 2774 | + } |
|
| 2775 | + |
|
| 2776 | + |
|
| 2777 | + /** |
|
| 2778 | + * display_admin_list_table_page_with_sidebar |
|
| 2779 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2780 | + * |
|
| 2781 | + * @return void |
|
| 2782 | + * @throws EE_Error |
|
| 2783 | + * @throws DomainException |
|
| 2784 | + */ |
|
| 2785 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2786 | + { |
|
| 2787 | + $this->_display_admin_list_table_page(true); |
|
| 2788 | + } |
|
| 2789 | + |
|
| 2790 | + |
|
| 2791 | + /** |
|
| 2792 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2793 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2794 | + * |
|
| 2795 | + * @return void |
|
| 2796 | + * @throws EE_Error |
|
| 2797 | + * @throws DomainException |
|
| 2798 | + */ |
|
| 2799 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2800 | + { |
|
| 2801 | + $this->_display_admin_list_table_page(); |
|
| 2802 | + } |
|
| 2803 | + |
|
| 2804 | + |
|
| 2805 | + /** |
|
| 2806 | + * generates html wrapper for an admin_list_table page |
|
| 2807 | + * |
|
| 2808 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2809 | + * @return void |
|
| 2810 | + * @throws DomainException |
|
| 2811 | + * @throws EE_Error |
|
| 2812 | + */ |
|
| 2813 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 2814 | + { |
|
| 2815 | + // setup search attributes |
|
| 2816 | + $this->_set_search_attributes(); |
|
| 2817 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2818 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2819 | + $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 2820 | + ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 2821 | + : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 2822 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2823 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2824 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2825 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2826 | + if (! empty($ajax_sorting_callback)) { |
|
| 2827 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2828 | + $ajax_sorting_callback . '_nonce', |
|
| 2829 | + $ajax_sorting_callback . '_nonce', |
|
| 2830 | + false, |
|
| 2831 | + false |
|
| 2832 | + ); |
|
| 2833 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2834 | + . $this->page_slug |
|
| 2835 | + . '" />'; |
|
| 2836 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2837 | + . $ajax_sorting_callback |
|
| 2838 | + . '" />'; |
|
| 2839 | + } else { |
|
| 2840 | + $sortable_list_table_form_fields = ''; |
|
| 2841 | + } |
|
| 2842 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2843 | + $hidden_form_fields = |
|
| 2844 | + isset($this->_template_args['list_table_hidden_fields']) |
|
| 2845 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 2846 | + : ''; |
|
| 2847 | + |
|
| 2848 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2849 | + $hidden_form_fields .= ' |
|
| 2850 | 2850 | <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
| 2851 | 2851 | |
| 2852 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2853 | - // display message about search results? |
|
| 2854 | - $search = $this->request->getRequestParam('s'); |
|
| 2855 | - $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 2856 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2857 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2858 | - trim($search, '%') |
|
| 2859 | - ) . '</p>' |
|
| 2860 | - : ''; |
|
| 2861 | - // filter before_list_table template arg |
|
| 2862 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 2863 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2864 | - $this->_template_args['before_list_table'], |
|
| 2865 | - $this->page_slug, |
|
| 2866 | - $this->request->requestParams(), |
|
| 2867 | - $this->_req_action |
|
| 2868 | - ); |
|
| 2869 | - // convert to array and filter again |
|
| 2870 | - // arrays are easier to inject new items in a specific location, |
|
| 2871 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 2872 | - $this->_template_args['before_list_table'] = implode( |
|
| 2873 | - " \n", |
|
| 2874 | - (array) apply_filters( |
|
| 2875 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 2876 | - (array) $this->_template_args['before_list_table'], |
|
| 2877 | - $this->page_slug, |
|
| 2878 | - $this->request->requestParams(), |
|
| 2879 | - $this->_req_action |
|
| 2880 | - ) |
|
| 2881 | - ); |
|
| 2882 | - // filter after_list_table template arg |
|
| 2883 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 2884 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2885 | - $this->_template_args['after_list_table'], |
|
| 2886 | - $this->page_slug, |
|
| 2887 | - $this->request->requestParams(), |
|
| 2888 | - $this->_req_action |
|
| 2889 | - ); |
|
| 2890 | - // convert to array and filter again |
|
| 2891 | - // arrays are easier to inject new items in a specific location, |
|
| 2892 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 2893 | - $this->_template_args['after_list_table'] = implode( |
|
| 2894 | - " \n", |
|
| 2895 | - (array) apply_filters( |
|
| 2896 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 2897 | - (array) $this->_template_args['after_list_table'], |
|
| 2898 | - $this->page_slug, |
|
| 2899 | - $this->request->requestParams(), |
|
| 2900 | - $this->_req_action |
|
| 2901 | - ) |
|
| 2902 | - ); |
|
| 2903 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2904 | - $template_path, |
|
| 2905 | - $this->_template_args, |
|
| 2906 | - true |
|
| 2907 | - ); |
|
| 2908 | - // the final template wrapper |
|
| 2909 | - if ($sidebar) { |
|
| 2910 | - $this->display_admin_page_with_sidebar(); |
|
| 2911 | - } else { |
|
| 2912 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2913 | - } |
|
| 2914 | - } |
|
| 2915 | - |
|
| 2916 | - |
|
| 2917 | - /** |
|
| 2918 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 2919 | - * html string for the legend. |
|
| 2920 | - * $items are expected in an array in the following format: |
|
| 2921 | - * $legend_items = array( |
|
| 2922 | - * 'item_id' => array( |
|
| 2923 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2924 | - * 'desc' => esc_html__('localized description of item'); |
|
| 2925 | - * ) |
|
| 2926 | - * ); |
|
| 2927 | - * |
|
| 2928 | - * @param array $items see above for format of array |
|
| 2929 | - * @return string html string of legend |
|
| 2930 | - * @throws DomainException |
|
| 2931 | - */ |
|
| 2932 | - protected function _display_legend($items) |
|
| 2933 | - { |
|
| 2934 | - $this->_template_args['items'] = apply_filters( |
|
| 2935 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 2936 | - (array) $items, |
|
| 2937 | - $this |
|
| 2938 | - ); |
|
| 2939 | - return EEH_Template::display_template( |
|
| 2940 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 2941 | - $this->_template_args, |
|
| 2942 | - true |
|
| 2943 | - ); |
|
| 2944 | - } |
|
| 2945 | - |
|
| 2946 | - |
|
| 2947 | - /** |
|
| 2948 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2949 | - * The returned json object is created from an array in the following format: |
|
| 2950 | - * array( |
|
| 2951 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2952 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2953 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2954 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2955 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 2956 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 2957 | - * that might be included in here) |
|
| 2958 | - * ) |
|
| 2959 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 2960 | - * |
|
| 2961 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 2962 | - * instead of displayed. |
|
| 2963 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 2964 | - * @return void |
|
| 2965 | - * @throws EE_Error |
|
| 2966 | - */ |
|
| 2967 | - protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 2968 | - { |
|
| 2969 | - // make sure any EE_Error notices have been handled. |
|
| 2970 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 2971 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 2972 | - unset($this->_template_args['data']); |
|
| 2973 | - $json = [ |
|
| 2974 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2975 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2976 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2977 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2978 | - 'notices' => EE_Error::get_notices(), |
|
| 2979 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 2980 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 2981 | - 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 2982 | - 'isEEajax' => true |
|
| 2983 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2984 | - ]; |
|
| 2985 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2986 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 2987 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 2988 | - } |
|
| 2989 | - echo wp_json_encode($json); |
|
| 2990 | - exit(); |
|
| 2991 | - } |
|
| 2992 | - |
|
| 2993 | - |
|
| 2994 | - /** |
|
| 2995 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2996 | - * |
|
| 2997 | - * @return void |
|
| 2998 | - * @throws EE_Error |
|
| 2999 | - */ |
|
| 3000 | - public function return_json() |
|
| 3001 | - { |
|
| 3002 | - if ($this->request->isAjax()) { |
|
| 3003 | - $this->_return_json(); |
|
| 3004 | - } else { |
|
| 3005 | - throw new EE_Error( |
|
| 3006 | - sprintf( |
|
| 3007 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3008 | - __FUNCTION__ |
|
| 3009 | - ) |
|
| 3010 | - ); |
|
| 3011 | - } |
|
| 3012 | - } |
|
| 3013 | - |
|
| 3014 | - |
|
| 3015 | - /** |
|
| 3016 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3017 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3018 | - * |
|
| 3019 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3020 | - */ |
|
| 3021 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3022 | - { |
|
| 3023 | - $this->_hook_obj = $hook_obj; |
|
| 3024 | - } |
|
| 3025 | - |
|
| 3026 | - |
|
| 3027 | - /** |
|
| 3028 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3029 | - * |
|
| 3030 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3031 | - * @return void |
|
| 3032 | - * @throws DomainException |
|
| 3033 | - * @throws EE_Error |
|
| 3034 | - */ |
|
| 3035 | - public function admin_page_wrapper($about = false) |
|
| 3036 | - { |
|
| 3037 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3038 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3039 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3040 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3041 | - |
|
| 3042 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3043 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3044 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3045 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3046 | - : '' |
|
| 3047 | - ); |
|
| 3048 | - |
|
| 3049 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3050 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3051 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3052 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3053 | - : '' |
|
| 3054 | - ); |
|
| 3055 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3056 | - |
|
| 3057 | - if ($this->request->isAjax()) { |
|
| 3058 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3059 | - // $template_path, |
|
| 3060 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3061 | - $this->_template_args, |
|
| 3062 | - true |
|
| 3063 | - ); |
|
| 3064 | - $this->_return_json(); |
|
| 3065 | - } |
|
| 3066 | - // load settings page wrapper template |
|
| 3067 | - $template_path = $about |
|
| 3068 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3069 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3070 | - |
|
| 3071 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3072 | - } |
|
| 3073 | - |
|
| 3074 | - |
|
| 3075 | - /** |
|
| 3076 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3077 | - * |
|
| 3078 | - * @return string html |
|
| 3079 | - * @throws EE_Error |
|
| 3080 | - */ |
|
| 3081 | - protected function _get_main_nav_tabs() |
|
| 3082 | - { |
|
| 3083 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3084 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3085 | - // (rather than setting in the page_routes array) |
|
| 3086 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3087 | - } |
|
| 3088 | - |
|
| 3089 | - |
|
| 3090 | - /** |
|
| 3091 | - * sort nav tabs |
|
| 3092 | - * |
|
| 3093 | - * @param $a |
|
| 3094 | - * @param $b |
|
| 3095 | - * @return int |
|
| 3096 | - */ |
|
| 3097 | - private function _sort_nav_tabs($a, $b) |
|
| 3098 | - { |
|
| 3099 | - if ($a['order'] === $b['order']) { |
|
| 3100 | - return 0; |
|
| 3101 | - } |
|
| 3102 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3103 | - } |
|
| 3104 | - |
|
| 3105 | - |
|
| 3106 | - /** |
|
| 3107 | - * generates HTML for the forms used on admin pages |
|
| 3108 | - * |
|
| 3109 | - * @param array $input_vars - array of input field details |
|
| 3110 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3111 | - * use) |
|
| 3112 | - * @param bool $id |
|
| 3113 | - * @return array|string |
|
| 3114 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3115 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3116 | - */ |
|
| 3117 | - protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3118 | - { |
|
| 3119 | - return $generator === 'string' |
|
| 3120 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3121 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3122 | - } |
|
| 3123 | - |
|
| 3124 | - |
|
| 3125 | - /** |
|
| 3126 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3127 | - * |
|
| 3128 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3129 | - * Close" button. |
|
| 3130 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3131 | - * 'Save', [1] => 'save & close') |
|
| 3132 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3133 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3134 | - * default actions by submitting some other value. |
|
| 3135 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3136 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3137 | - * close (normal form handling). |
|
| 3138 | - */ |
|
| 3139 | - protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3140 | - { |
|
| 3141 | - // make sure $text and $actions are in an array |
|
| 3142 | - $text = (array) $text; |
|
| 3143 | - $actions = (array) $actions; |
|
| 3144 | - $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
| 3145 | - $button_text = ! empty($text) |
|
| 3146 | - ? $text |
|
| 3147 | - : [ |
|
| 3148 | - esc_html__('Save', 'event_espresso'), |
|
| 3149 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3150 | - ]; |
|
| 3151 | - $default_names = ['save', 'save_and_close']; |
|
| 3152 | - $buttons = ''; |
|
| 3153 | - foreach ($button_text as $key => $button) { |
|
| 3154 | - $ref = $default_names[ $key ]; |
|
| 3155 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3156 | - $buttons .= '<input type="submit" class="button-primary ' . $ref . '" ' |
|
| 3157 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3158 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3159 | - if (! $both) { |
|
| 3160 | - break; |
|
| 3161 | - } |
|
| 3162 | - } |
|
| 3163 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3164 | - $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3165 | - . $referrer_url |
|
| 3166 | - . '" />'; |
|
| 3167 | - $this->_template_args['save_buttons'] = $buttons; |
|
| 3168 | - } |
|
| 3169 | - |
|
| 3170 | - |
|
| 3171 | - /** |
|
| 3172 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3173 | - * |
|
| 3174 | - * @param string $route |
|
| 3175 | - * @param array $additional_hidden_fields |
|
| 3176 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3177 | - * @since 4.6.0 |
|
| 3178 | - */ |
|
| 3179 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3180 | - { |
|
| 3181 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3182 | - } |
|
| 3183 | - |
|
| 3184 | - |
|
| 3185 | - /** |
|
| 3186 | - * set form open and close tags on add/edit pages. |
|
| 3187 | - * |
|
| 3188 | - * @param string $route the route you want the form to direct to |
|
| 3189 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3190 | - * @return void |
|
| 3191 | - */ |
|
| 3192 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3193 | - { |
|
| 3194 | - if (empty($route)) { |
|
| 3195 | - $user_msg = esc_html__( |
|
| 3196 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3197 | - 'event_espresso' |
|
| 3198 | - ); |
|
| 3199 | - $dev_msg = $user_msg . "\n" |
|
| 3200 | - . sprintf( |
|
| 3201 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3202 | - __FUNCTION__, |
|
| 3203 | - __CLASS__ |
|
| 3204 | - ); |
|
| 3205 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3206 | - } |
|
| 3207 | - // open form |
|
| 3208 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3209 | - . $this->_admin_base_url |
|
| 3210 | - . '" id="' |
|
| 3211 | - . $route |
|
| 3212 | - . '_event_form" >'; |
|
| 3213 | - // add nonce |
|
| 3214 | - $nonce = |
|
| 3215 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3216 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3217 | - // add REQUIRED form action |
|
| 3218 | - $hidden_fields = [ |
|
| 3219 | - 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3220 | - ]; |
|
| 3221 | - // merge arrays |
|
| 3222 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3223 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3224 | - : $hidden_fields; |
|
| 3225 | - // generate form fields |
|
| 3226 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3227 | - // add fields to form |
|
| 3228 | - foreach ((array) $form_fields as $form_field) { |
|
| 3229 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3230 | - } |
|
| 3231 | - // close form |
|
| 3232 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3233 | - } |
|
| 3234 | - |
|
| 3235 | - |
|
| 3236 | - /** |
|
| 3237 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3238 | - * discovered it would be useful for external code to have access. |
|
| 3239 | - * |
|
| 3240 | - * @param bool $success |
|
| 3241 | - * @param string $what |
|
| 3242 | - * @param string $action_desc |
|
| 3243 | - * @param array $query_args |
|
| 3244 | - * @param bool $override_overwrite |
|
| 3245 | - * @throws EE_Error |
|
| 3246 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3247 | - * @since 4.5.0 |
|
| 3248 | - */ |
|
| 3249 | - public function redirect_after_action( |
|
| 3250 | - $success = false, |
|
| 3251 | - $what = 'item', |
|
| 3252 | - $action_desc = 'processed', |
|
| 3253 | - $query_args = [], |
|
| 3254 | - $override_overwrite = false |
|
| 3255 | - ) { |
|
| 3256 | - $this->_redirect_after_action( |
|
| 3257 | - $success, |
|
| 3258 | - $what, |
|
| 3259 | - $action_desc, |
|
| 3260 | - $query_args, |
|
| 3261 | - $override_overwrite |
|
| 3262 | - ); |
|
| 3263 | - } |
|
| 3264 | - |
|
| 3265 | - |
|
| 3266 | - /** |
|
| 3267 | - * Helper method for merging existing request data with the returned redirect url. |
|
| 3268 | - * |
|
| 3269 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3270 | - * filters are still applied. |
|
| 3271 | - * |
|
| 3272 | - * @param array $new_route_data |
|
| 3273 | - * @return array |
|
| 3274 | - */ |
|
| 3275 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3276 | - { |
|
| 3277 | - foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3278 | - // unset nonces |
|
| 3279 | - if (strpos($ref, 'nonce') !== false) { |
|
| 3280 | - $this->request->unSetRequestParam($ref); |
|
| 3281 | - continue; |
|
| 3282 | - } |
|
| 3283 | - // urlencode values. |
|
| 3284 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3285 | - $this->request->setRequestParam($ref, $value); |
|
| 3286 | - } |
|
| 3287 | - return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3288 | - } |
|
| 3289 | - |
|
| 3290 | - |
|
| 3291 | - /** |
|
| 3292 | - * _redirect_after_action |
|
| 3293 | - * |
|
| 3294 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3295 | - * @param string $what - what the action was performed on |
|
| 3296 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3297 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3298 | - * action is completed |
|
| 3299 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3300 | - * override this so that they show. |
|
| 3301 | - * @return void |
|
| 3302 | - * @throws EE_Error |
|
| 3303 | - */ |
|
| 3304 | - protected function _redirect_after_action( |
|
| 3305 | - $success = 0, |
|
| 3306 | - $what = 'item', |
|
| 3307 | - $action_desc = 'processed', |
|
| 3308 | - $query_args = [], |
|
| 3309 | - $override_overwrite = false |
|
| 3310 | - ) { |
|
| 3311 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3312 | - // class name for actions/filters. |
|
| 3313 | - $classname = get_class($this); |
|
| 3314 | - // set redirect url. |
|
| 3315 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3316 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3317 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3318 | - $notices = EE_Error::get_notices(false); |
|
| 3319 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3320 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3321 | - EE_Error::overwrite_success(); |
|
| 3322 | - } |
|
| 3323 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3324 | - // how many records affected ? more than one record ? or just one ? |
|
| 3325 | - if ($success > 1) { |
|
| 3326 | - // set plural msg |
|
| 3327 | - EE_Error::add_success( |
|
| 3328 | - sprintf( |
|
| 3329 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3330 | - $what, |
|
| 3331 | - $action_desc |
|
| 3332 | - ), |
|
| 3333 | - __FILE__, |
|
| 3334 | - __FUNCTION__, |
|
| 3335 | - __LINE__ |
|
| 3336 | - ); |
|
| 3337 | - } elseif ($success === 1) { |
|
| 3338 | - // set singular msg |
|
| 3339 | - EE_Error::add_success( |
|
| 3340 | - sprintf( |
|
| 3341 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3342 | - $what, |
|
| 3343 | - $action_desc |
|
| 3344 | - ), |
|
| 3345 | - __FILE__, |
|
| 3346 | - __FUNCTION__, |
|
| 3347 | - __LINE__ |
|
| 3348 | - ); |
|
| 3349 | - } |
|
| 3350 | - } |
|
| 3351 | - // check that $query_args isn't something crazy |
|
| 3352 | - if (! is_array($query_args)) { |
|
| 3353 | - $query_args = []; |
|
| 3354 | - } |
|
| 3355 | - /** |
|
| 3356 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3357 | - * redirections on save and close actions |
|
| 3358 | - * |
|
| 3359 | - * @param array $query_args The original query_args array coming into the |
|
| 3360 | - * method. |
|
| 3361 | - * @since 4.2.0 |
|
| 3362 | - */ |
|
| 3363 | - do_action( |
|
| 3364 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3365 | - $query_args |
|
| 3366 | - ); |
|
| 3367 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3368 | - |
|
| 3369 | - if ( |
|
| 3370 | - $this->request->requestParamIsSet('save_and_close') |
|
| 3371 | - && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3372 | - ) { |
|
| 3373 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3374 | - $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3375 | - // regenerate query args array from referrer URL |
|
| 3376 | - parse_str($parsed_url['query'], $query_args); |
|
| 3377 | - // correct page and action will be in the query args now |
|
| 3378 | - $redirect_url = admin_url('admin.php'); |
|
| 3379 | - } |
|
| 3380 | - // merge any default query_args set in _default_route_query_args property |
|
| 3381 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3382 | - $args_to_merge = []; |
|
| 3383 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3384 | - // is there a wp_referer array in our _default_route_query_args property? |
|
| 3385 | - if ($query_param === 'wp_referer') { |
|
| 3386 | - $query_value = (array) $query_value; |
|
| 3387 | - foreach ($query_value as $reference => $value) { |
|
| 3388 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3389 | - continue; |
|
| 3390 | - } |
|
| 3391 | - // finally we will override any arguments in the referer with |
|
| 3392 | - // what might be set on the _default_route_query_args array. |
|
| 3393 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3394 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3395 | - } else { |
|
| 3396 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3397 | - } |
|
| 3398 | - } |
|
| 3399 | - continue; |
|
| 3400 | - } |
|
| 3401 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3402 | - } |
|
| 3403 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3404 | - // redirect. |
|
| 3405 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3406 | - } |
|
| 3407 | - $this->_process_notices($query_args); |
|
| 3408 | - // generate redirect url |
|
| 3409 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3410 | - if (isset($query_args['action'])) { |
|
| 3411 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3412 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3413 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3414 | - } |
|
| 3415 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3416 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3417 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3418 | - $redirect_url = apply_filters( |
|
| 3419 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3420 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3421 | - $query_args |
|
| 3422 | - ); |
|
| 3423 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3424 | - if ($this->request->isAjax()) { |
|
| 3425 | - $default_data = [ |
|
| 3426 | - 'close' => true, |
|
| 3427 | - 'redirect_url' => $redirect_url, |
|
| 3428 | - 'where' => 'main', |
|
| 3429 | - 'what' => 'append', |
|
| 3430 | - ]; |
|
| 3431 | - $this->_template_args['success'] = $success; |
|
| 3432 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3433 | - $default_data, |
|
| 3434 | - $this->_template_args['data'] |
|
| 3435 | - ) : $default_data; |
|
| 3436 | - $this->_return_json(); |
|
| 3437 | - } |
|
| 3438 | - wp_safe_redirect($redirect_url); |
|
| 3439 | - exit(); |
|
| 3440 | - } |
|
| 3441 | - |
|
| 3442 | - |
|
| 3443 | - /** |
|
| 3444 | - * process any notices before redirecting (or returning ajax request) |
|
| 3445 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3446 | - * |
|
| 3447 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3448 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3449 | - * page_routes haven't been defined yet. |
|
| 3450 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3451 | - * still save a transient for the notice. |
|
| 3452 | - * @return void |
|
| 3453 | - * @throws EE_Error |
|
| 3454 | - */ |
|
| 3455 | - protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3456 | - { |
|
| 3457 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3458 | - if ($this->request->isAjax()) { |
|
| 3459 | - $notices = EE_Error::get_notices(false); |
|
| 3460 | - if (empty($this->_template_args['success'])) { |
|
| 3461 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3462 | - } |
|
| 3463 | - if (empty($this->_template_args['errors'])) { |
|
| 3464 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3465 | - } |
|
| 3466 | - if (empty($this->_template_args['attention'])) { |
|
| 3467 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3468 | - } |
|
| 3469 | - } |
|
| 3470 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3471 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3472 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3473 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3474 | - $this->_add_transient( |
|
| 3475 | - $route, |
|
| 3476 | - $this->_template_args['notices'], |
|
| 3477 | - true, |
|
| 3478 | - $skip_route_verify |
|
| 3479 | - ); |
|
| 3480 | - } |
|
| 3481 | - } |
|
| 3482 | - |
|
| 3483 | - |
|
| 3484 | - /** |
|
| 3485 | - * get_action_link_or_button |
|
| 3486 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3487 | - * |
|
| 3488 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3489 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3490 | - * property. |
|
| 3491 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3492 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3493 | - * @param string $base_url If this is not provided |
|
| 3494 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3495 | - * Otherwise this value will be used. |
|
| 3496 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3497 | - * @return string |
|
| 3498 | - * @throws InvalidArgumentException |
|
| 3499 | - * @throws InvalidInterfaceException |
|
| 3500 | - * @throws InvalidDataTypeException |
|
| 3501 | - * @throws EE_Error |
|
| 3502 | - */ |
|
| 3503 | - public function get_action_link_or_button( |
|
| 3504 | - $action, |
|
| 3505 | - $type = 'add', |
|
| 3506 | - $extra_request = [], |
|
| 3507 | - $class = 'button button--primary', |
|
| 3508 | - $base_url = '', |
|
| 3509 | - $exclude_nonce = false |
|
| 3510 | - ) { |
|
| 3511 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3512 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3513 | - throw new EE_Error( |
|
| 3514 | - sprintf( |
|
| 3515 | - esc_html__( |
|
| 3516 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3517 | - 'event_espresso' |
|
| 3518 | - ), |
|
| 3519 | - $action |
|
| 3520 | - ) |
|
| 3521 | - ); |
|
| 3522 | - } |
|
| 3523 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3524 | - throw new EE_Error( |
|
| 3525 | - sprintf( |
|
| 3526 | - esc_html__( |
|
| 3527 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3528 | - 'event_espresso' |
|
| 3529 | - ), |
|
| 3530 | - $type |
|
| 3531 | - ) |
|
| 3532 | - ); |
|
| 3533 | - } |
|
| 3534 | - // finally check user access for this button. |
|
| 3535 | - $has_access = $this->check_user_access($action, true); |
|
| 3536 | - if (! $has_access) { |
|
| 3537 | - return ''; |
|
| 3538 | - } |
|
| 3539 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3540 | - $query_args = [ |
|
| 3541 | - 'action' => $action, |
|
| 3542 | - ]; |
|
| 3543 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3544 | - if (! empty($extra_request)) { |
|
| 3545 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3546 | - } |
|
| 3547 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3548 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3549 | - } |
|
| 3550 | - |
|
| 3551 | - |
|
| 3552 | - /** |
|
| 3553 | - * _per_page_screen_option |
|
| 3554 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3555 | - * |
|
| 3556 | - * @return void |
|
| 3557 | - * @throws InvalidArgumentException |
|
| 3558 | - * @throws InvalidInterfaceException |
|
| 3559 | - * @throws InvalidDataTypeException |
|
| 3560 | - */ |
|
| 3561 | - protected function _per_page_screen_option() |
|
| 3562 | - { |
|
| 3563 | - $option = 'per_page'; |
|
| 3564 | - $args = [ |
|
| 3565 | - 'label' => apply_filters( |
|
| 3566 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3567 | - $this->_admin_page_title, |
|
| 3568 | - $this |
|
| 3569 | - ), |
|
| 3570 | - 'default' => (int) apply_filters( |
|
| 3571 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3572 | - 20 |
|
| 3573 | - ), |
|
| 3574 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3575 | - ]; |
|
| 3576 | - // ONLY add the screen option if the user has access to it. |
|
| 3577 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3578 | - add_screen_option($option, $args); |
|
| 3579 | - } |
|
| 3580 | - } |
|
| 3581 | - |
|
| 3582 | - |
|
| 3583 | - /** |
|
| 3584 | - * set_per_page_screen_option |
|
| 3585 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3586 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3587 | - * admin_menu. |
|
| 3588 | - * |
|
| 3589 | - * @return void |
|
| 3590 | - */ |
|
| 3591 | - private function _set_per_page_screen_options() |
|
| 3592 | - { |
|
| 3593 | - if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3594 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3595 | - if (! $user = wp_get_current_user()) { |
|
| 3596 | - return; |
|
| 3597 | - } |
|
| 3598 | - $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3599 | - if (! $option) { |
|
| 3600 | - return; |
|
| 3601 | - } |
|
| 3602 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3603 | - $map_option = $option; |
|
| 3604 | - $option = str_replace('-', '_', $option); |
|
| 3605 | - switch ($map_option) { |
|
| 3606 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3607 | - $max_value = apply_filters( |
|
| 3608 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3609 | - 999, |
|
| 3610 | - $this->_current_page, |
|
| 3611 | - $this->_current_view |
|
| 3612 | - ); |
|
| 3613 | - if ($value < 1) { |
|
| 3614 | - return; |
|
| 3615 | - } |
|
| 3616 | - $value = min($value, $max_value); |
|
| 3617 | - break; |
|
| 3618 | - default: |
|
| 3619 | - $value = apply_filters( |
|
| 3620 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3621 | - false, |
|
| 3622 | - $option, |
|
| 3623 | - $value |
|
| 3624 | - ); |
|
| 3625 | - if (false === $value) { |
|
| 3626 | - return; |
|
| 3627 | - } |
|
| 3628 | - break; |
|
| 3629 | - } |
|
| 3630 | - update_user_meta($user->ID, $option, $value); |
|
| 3631 | - wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3632 | - exit; |
|
| 3633 | - } |
|
| 3634 | - } |
|
| 3635 | - |
|
| 3636 | - |
|
| 3637 | - /** |
|
| 3638 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3639 | - * |
|
| 3640 | - * @param array $data array that will be assigned to template args. |
|
| 3641 | - */ |
|
| 3642 | - public function set_template_args($data) |
|
| 3643 | - { |
|
| 3644 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3645 | - } |
|
| 3646 | - |
|
| 3647 | - |
|
| 3648 | - /** |
|
| 3649 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3650 | - * |
|
| 3651 | - * @param string $route the route that should receive the transient |
|
| 3652 | - * @param array $data the data that gets sent |
|
| 3653 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3654 | - * normal route transient. |
|
| 3655 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3656 | - * when we are adding a transient before page_routes have been defined. |
|
| 3657 | - * @return void |
|
| 3658 | - * @throws EE_Error |
|
| 3659 | - */ |
|
| 3660 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3661 | - { |
|
| 3662 | - $user_id = get_current_user_id(); |
|
| 3663 | - if (! $skip_route_verify) { |
|
| 3664 | - $this->_verify_route($route); |
|
| 3665 | - } |
|
| 3666 | - // now let's set the string for what kind of transient we're setting |
|
| 3667 | - $transient = $notices |
|
| 3668 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3669 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3670 | - $data = $notices ? ['notices' => $data] : $data; |
|
| 3671 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3672 | - $existing = is_multisite() && is_network_admin() |
|
| 3673 | - ? get_site_transient($transient) |
|
| 3674 | - : get_transient($transient); |
|
| 3675 | - if ($existing) { |
|
| 3676 | - $data = array_merge((array) $data, (array) $existing); |
|
| 3677 | - } |
|
| 3678 | - if (is_multisite() && is_network_admin()) { |
|
| 3679 | - set_site_transient($transient, $data, 8); |
|
| 3680 | - } else { |
|
| 3681 | - set_transient($transient, $data, 8); |
|
| 3682 | - } |
|
| 3683 | - } |
|
| 3684 | - |
|
| 3685 | - |
|
| 3686 | - /** |
|
| 3687 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3688 | - * |
|
| 3689 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3690 | - * @param string $route |
|
| 3691 | - * @return mixed data |
|
| 3692 | - */ |
|
| 3693 | - protected function _get_transient($notices = false, $route = '') |
|
| 3694 | - { |
|
| 3695 | - $user_id = get_current_user_id(); |
|
| 3696 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3697 | - $transient = $notices |
|
| 3698 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3699 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3700 | - $data = is_multisite() && is_network_admin() |
|
| 3701 | - ? get_site_transient($transient) |
|
| 3702 | - : get_transient($transient); |
|
| 3703 | - // delete transient after retrieval (just in case it hasn't expired); |
|
| 3704 | - if (is_multisite() && is_network_admin()) { |
|
| 3705 | - delete_site_transient($transient); |
|
| 3706 | - } else { |
|
| 3707 | - delete_transient($transient); |
|
| 3708 | - } |
|
| 3709 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3710 | - } |
|
| 3711 | - |
|
| 3712 | - |
|
| 3713 | - /** |
|
| 3714 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3715 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3716 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3717 | - * |
|
| 3718 | - * @return void |
|
| 3719 | - */ |
|
| 3720 | - protected function _transient_garbage_collection() |
|
| 3721 | - { |
|
| 3722 | - global $wpdb; |
|
| 3723 | - // retrieve all existing transients |
|
| 3724 | - $query = |
|
| 3725 | - "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3726 | - if ($results = $wpdb->get_results($query)) { |
|
| 3727 | - foreach ($results as $result) { |
|
| 3728 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3729 | - get_transient($transient); |
|
| 3730 | - if (is_multisite() && is_network_admin()) { |
|
| 3731 | - get_site_transient($transient); |
|
| 3732 | - } |
|
| 3733 | - } |
|
| 3734 | - } |
|
| 3735 | - } |
|
| 3736 | - |
|
| 3737 | - |
|
| 3738 | - /** |
|
| 3739 | - * get_view |
|
| 3740 | - * |
|
| 3741 | - * @return string content of _view property |
|
| 3742 | - */ |
|
| 3743 | - public function get_view() |
|
| 3744 | - { |
|
| 3745 | - return $this->_view; |
|
| 3746 | - } |
|
| 3747 | - |
|
| 3748 | - |
|
| 3749 | - /** |
|
| 3750 | - * getter for the protected $_views property |
|
| 3751 | - * |
|
| 3752 | - * @return array |
|
| 3753 | - */ |
|
| 3754 | - public function get_views() |
|
| 3755 | - { |
|
| 3756 | - return $this->_views; |
|
| 3757 | - } |
|
| 3758 | - |
|
| 3759 | - |
|
| 3760 | - /** |
|
| 3761 | - * get_current_page |
|
| 3762 | - * |
|
| 3763 | - * @return string _current_page property value |
|
| 3764 | - */ |
|
| 3765 | - public function get_current_page() |
|
| 3766 | - { |
|
| 3767 | - return $this->_current_page; |
|
| 3768 | - } |
|
| 3769 | - |
|
| 3770 | - |
|
| 3771 | - /** |
|
| 3772 | - * get_current_view |
|
| 3773 | - * |
|
| 3774 | - * @return string _current_view property value |
|
| 3775 | - */ |
|
| 3776 | - public function get_current_view() |
|
| 3777 | - { |
|
| 3778 | - return $this->_current_view; |
|
| 3779 | - } |
|
| 3780 | - |
|
| 3781 | - |
|
| 3782 | - /** |
|
| 3783 | - * get_current_screen |
|
| 3784 | - * |
|
| 3785 | - * @return object The current WP_Screen object |
|
| 3786 | - */ |
|
| 3787 | - public function get_current_screen() |
|
| 3788 | - { |
|
| 3789 | - return $this->_current_screen; |
|
| 3790 | - } |
|
| 3791 | - |
|
| 3792 | - |
|
| 3793 | - /** |
|
| 3794 | - * get_current_page_view_url |
|
| 3795 | - * |
|
| 3796 | - * @return string This returns the url for the current_page_view. |
|
| 3797 | - */ |
|
| 3798 | - public function get_current_page_view_url() |
|
| 3799 | - { |
|
| 3800 | - return $this->_current_page_view_url; |
|
| 3801 | - } |
|
| 3802 | - |
|
| 3803 | - |
|
| 3804 | - /** |
|
| 3805 | - * just returns the Request |
|
| 3806 | - * |
|
| 3807 | - * @return RequestInterface |
|
| 3808 | - */ |
|
| 3809 | - public function get_request() |
|
| 3810 | - { |
|
| 3811 | - return $this->request; |
|
| 3812 | - } |
|
| 3813 | - |
|
| 3814 | - |
|
| 3815 | - /** |
|
| 3816 | - * just returns the _req_data property |
|
| 3817 | - * |
|
| 3818 | - * @return array |
|
| 3819 | - */ |
|
| 3820 | - public function get_request_data() |
|
| 3821 | - { |
|
| 3822 | - return $this->request->requestParams(); |
|
| 3823 | - } |
|
| 3824 | - |
|
| 3825 | - |
|
| 3826 | - /** |
|
| 3827 | - * returns the _req_data protected property |
|
| 3828 | - * |
|
| 3829 | - * @return string |
|
| 3830 | - */ |
|
| 3831 | - public function get_req_action() |
|
| 3832 | - { |
|
| 3833 | - return $this->_req_action; |
|
| 3834 | - } |
|
| 3835 | - |
|
| 3836 | - |
|
| 3837 | - /** |
|
| 3838 | - * @return bool value of $_is_caf property |
|
| 3839 | - */ |
|
| 3840 | - public function is_caf() |
|
| 3841 | - { |
|
| 3842 | - return $this->_is_caf; |
|
| 3843 | - } |
|
| 3844 | - |
|
| 3845 | - |
|
| 3846 | - /** |
|
| 3847 | - * @return mixed |
|
| 3848 | - */ |
|
| 3849 | - public function default_espresso_metaboxes() |
|
| 3850 | - { |
|
| 3851 | - return $this->_default_espresso_metaboxes; |
|
| 3852 | - } |
|
| 3853 | - |
|
| 3854 | - |
|
| 3855 | - /** |
|
| 3856 | - * @return mixed |
|
| 3857 | - */ |
|
| 3858 | - public function admin_base_url() |
|
| 3859 | - { |
|
| 3860 | - return $this->_admin_base_url; |
|
| 3861 | - } |
|
| 3862 | - |
|
| 3863 | - |
|
| 3864 | - /** |
|
| 3865 | - * @return mixed |
|
| 3866 | - */ |
|
| 3867 | - public function wp_page_slug() |
|
| 3868 | - { |
|
| 3869 | - return $this->_wp_page_slug; |
|
| 3870 | - } |
|
| 3871 | - |
|
| 3872 | - |
|
| 3873 | - /** |
|
| 3874 | - * updates espresso configuration settings |
|
| 3875 | - * |
|
| 3876 | - * @param string $tab |
|
| 3877 | - * @param EE_Config_Base|EE_Config $config |
|
| 3878 | - * @param string $file file where error occurred |
|
| 3879 | - * @param string $func function where error occurred |
|
| 3880 | - * @param string $line line no where error occurred |
|
| 3881 | - * @return boolean |
|
| 3882 | - */ |
|
| 3883 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3884 | - { |
|
| 3885 | - // remove any options that are NOT going to be saved with the config settings. |
|
| 3886 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 3887 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3888 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3889 | - update_option('ee_ueip_has_notified', true); |
|
| 3890 | - } |
|
| 3891 | - // and save it (note we're also doing the network save here) |
|
| 3892 | - $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
| 3893 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3894 | - if ($config_saved && $net_saved) { |
|
| 3895 | - EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3896 | - return true; |
|
| 3897 | - } |
|
| 3898 | - EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3899 | - return false; |
|
| 3900 | - } |
|
| 3901 | - |
|
| 3902 | - |
|
| 3903 | - /** |
|
| 3904 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3905 | - * |
|
| 3906 | - * @return array |
|
| 3907 | - */ |
|
| 3908 | - public function get_yes_no_values() |
|
| 3909 | - { |
|
| 3910 | - return $this->_yes_no_values; |
|
| 3911 | - } |
|
| 3912 | - |
|
| 3913 | - |
|
| 3914 | - protected function _get_dir() |
|
| 3915 | - { |
|
| 3916 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 3917 | - return dirname($reflector->getFileName()); |
|
| 3918 | - } |
|
| 3919 | - |
|
| 3920 | - |
|
| 3921 | - /** |
|
| 3922 | - * A helper for getting a "next link". |
|
| 3923 | - * |
|
| 3924 | - * @param string $url The url to link to |
|
| 3925 | - * @param string $class The class to use. |
|
| 3926 | - * @return string |
|
| 3927 | - */ |
|
| 3928 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3929 | - { |
|
| 3930 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3931 | - } |
|
| 3932 | - |
|
| 3933 | - |
|
| 3934 | - /** |
|
| 3935 | - * A helper for getting a "previous link". |
|
| 3936 | - * |
|
| 3937 | - * @param string $url The url to link to |
|
| 3938 | - * @param string $class The class to use. |
|
| 3939 | - * @return string |
|
| 3940 | - */ |
|
| 3941 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3942 | - { |
|
| 3943 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3944 | - } |
|
| 3945 | - |
|
| 3946 | - |
|
| 3947 | - |
|
| 3948 | - |
|
| 3949 | - |
|
| 3950 | - |
|
| 3951 | - |
|
| 3952 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3953 | - |
|
| 3954 | - |
|
| 3955 | - /** |
|
| 3956 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 3957 | - * 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 |
|
| 3958 | - * _req_data array. |
|
| 3959 | - * |
|
| 3960 | - * @return bool success/fail |
|
| 3961 | - * @throws EE_Error |
|
| 3962 | - * @throws InvalidArgumentException |
|
| 3963 | - * @throws ReflectionException |
|
| 3964 | - * @throws InvalidDataTypeException |
|
| 3965 | - * @throws InvalidInterfaceException |
|
| 3966 | - */ |
|
| 3967 | - protected function _process_resend_registration() |
|
| 3968 | - { |
|
| 3969 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3970 | - do_action( |
|
| 3971 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 3972 | - $this->_template_args['success'], |
|
| 3973 | - $this->request->requestParams() |
|
| 3974 | - ); |
|
| 3975 | - return $this->_template_args['success']; |
|
| 3976 | - } |
|
| 3977 | - |
|
| 3978 | - |
|
| 3979 | - /** |
|
| 3980 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3981 | - * |
|
| 3982 | - * @param EE_Payment $payment |
|
| 3983 | - * @return bool success/fail |
|
| 3984 | - */ |
|
| 3985 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 3986 | - { |
|
| 3987 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3988 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3989 | - $this->_template_args['success'] = apply_filters( |
|
| 3990 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 3991 | - false, |
|
| 3992 | - $payment |
|
| 3993 | - ); |
|
| 3994 | - return $this->_template_args['success']; |
|
| 3995 | - } |
|
| 3996 | - |
|
| 3997 | - |
|
| 3998 | - /** |
|
| 3999 | - * @param EEM_Base $entity_model |
|
| 4000 | - * @param string $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc |
|
| 4001 | - * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4002 | - * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4003 | - * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4004 | - * @return int|float |
|
| 4005 | - * @throws EE_Error |
|
| 4006 | - */ |
|
| 4007 | - protected function trashRestoreDeleteEntities( |
|
| 4008 | - EEM_Base $entity_model, |
|
| 4009 | - string $entity_PK_name, |
|
| 4010 | - string $action = EE_Admin_List_Table::ACTION_DELETE, |
|
| 4011 | - string $delete_column = '', |
|
| 4012 | - callable $callback = null |
|
| 4013 | - ) { |
|
| 4014 | - $entity_PK = $entity_model->get_primary_key_field(); |
|
| 4015 | - $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name(); |
|
| 4016 | - $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK); |
|
| 4017 | - // grab ID if deleting a single entity |
|
| 4018 | - if ($this->request->requestParamIsSet($entity_PK_name)) { |
|
| 4019 | - $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type); |
|
| 4020 | - return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0; |
|
| 4021 | - } |
|
| 4022 | - // or grab checkbox array if bulk deleting |
|
| 4023 | - $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true); |
|
| 4024 | - if (empty($checkboxes)) { |
|
| 4025 | - return 0; |
|
| 4026 | - } |
|
| 4027 | - $success = 0; |
|
| 4028 | - $IDs = array_keys($checkboxes); |
|
| 4029 | - // cycle thru bulk action checkboxes |
|
| 4030 | - foreach ($IDs as $ID) { |
|
| 4031 | - // increment $success |
|
| 4032 | - if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) { |
|
| 4033 | - $success++; |
|
| 4034 | - } |
|
| 4035 | - } |
|
| 4036 | - $count = (int) count($checkboxes); |
|
| 4037 | - // if multiple entities were deleted successfully, then $deleted will be full count of deletions, |
|
| 4038 | - // otherwise it will be a fraction of ( actual deletions / total entities to be deleted ) |
|
| 4039 | - return $success === $count ? $count : $success / $count; |
|
| 4040 | - } |
|
| 4041 | - |
|
| 4042 | - |
|
| 4043 | - /** |
|
| 4044 | - * @param EE_Primary_Key_Field_Base $entity_PK |
|
| 4045 | - * @return string |
|
| 4046 | - * @throws EE_Error |
|
| 4047 | - * @since 4.10.30.p |
|
| 4048 | - */ |
|
| 4049 | - private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string |
|
| 4050 | - { |
|
| 4051 | - $entity_PK_type = $entity_PK->getSchemaType(); |
|
| 4052 | - switch ($entity_PK_type) { |
|
| 4053 | - case 'boolean': |
|
| 4054 | - return 'bool'; |
|
| 4055 | - case 'integer': |
|
| 4056 | - return 'int'; |
|
| 4057 | - case 'number': |
|
| 4058 | - return 'float'; |
|
| 4059 | - case 'string': |
|
| 4060 | - return 'string'; |
|
| 4061 | - } |
|
| 4062 | - throw new RuntimeException( |
|
| 4063 | - sprintf( |
|
| 4064 | - esc_html__( |
|
| 4065 | - '"%1$s" is an invalid schema type for the %2$s primary key.', |
|
| 4066 | - 'event_espresso' |
|
| 4067 | - ), |
|
| 4068 | - $entity_PK_type, |
|
| 4069 | - $entity_PK->get_name() |
|
| 4070 | - ) |
|
| 4071 | - ); |
|
| 4072 | - } |
|
| 4073 | - |
|
| 4074 | - |
|
| 4075 | - /** |
|
| 4076 | - * @param EEM_Base $entity_model |
|
| 4077 | - * @param int|string $entity_ID |
|
| 4078 | - * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4079 | - * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4080 | - * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4081 | - * @return bool |
|
| 4082 | - */ |
|
| 4083 | - protected function trashRestoreDeleteEntity( |
|
| 4084 | - EEM_Base $entity_model, |
|
| 4085 | - $entity_ID, |
|
| 4086 | - string $action, |
|
| 4087 | - string $delete_column, |
|
| 4088 | - callable $callback = null |
|
| 4089 | - ) { |
|
| 4090 | - $entity_ID = absint($entity_ID); |
|
| 4091 | - if (! $entity_ID) { |
|
| 4092 | - $this->trashRestoreDeleteError($action, $entity_model); |
|
| 4093 | - } |
|
| 4094 | - $result = 0; |
|
| 4095 | - try { |
|
| 4096 | - switch ($action) { |
|
| 4097 | - case EE_Admin_List_Table::ACTION_DELETE: |
|
| 4098 | - $result = (bool) $entity_model->delete_permanently_by_ID($entity_ID); |
|
| 4099 | - break; |
|
| 4100 | - case EE_Admin_List_Table::ACTION_RESTORE: |
|
| 4101 | - $this->validateDeleteColumn($entity_model, $delete_column); |
|
| 4102 | - $result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID); |
|
| 4103 | - break; |
|
| 4104 | - case EE_Admin_List_Table::ACTION_TRASH: |
|
| 4105 | - $this->validateDeleteColumn($entity_model, $delete_column); |
|
| 4106 | - $result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID); |
|
| 4107 | - break; |
|
| 4108 | - } |
|
| 4109 | - } catch (Exception $exception) { |
|
| 4110 | - $this->trashRestoreDeleteError($action, $entity_model, $exception); |
|
| 4111 | - } |
|
| 4112 | - if (is_callable($callback)) { |
|
| 4113 | - call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]); |
|
| 4114 | - } |
|
| 4115 | - return $result; |
|
| 4116 | - } |
|
| 4117 | - |
|
| 4118 | - |
|
| 4119 | - /** |
|
| 4120 | - * @param EEM_Base $entity_model |
|
| 4121 | - * @param string $delete_column |
|
| 4122 | - * @since 4.10.30.p |
|
| 4123 | - */ |
|
| 4124 | - private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column) |
|
| 4125 | - { |
|
| 4126 | - if (empty($delete_column)) { |
|
| 4127 | - throw new DomainException( |
|
| 4128 | - sprintf( |
|
| 4129 | - esc_html__( |
|
| 4130 | - 'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.', |
|
| 4131 | - 'event_espresso' |
|
| 4132 | - ), |
|
| 4133 | - $entity_model->get_this_model_name() |
|
| 4134 | - ) |
|
| 4135 | - ); |
|
| 4136 | - } |
|
| 4137 | - if (! $entity_model->has_field($delete_column)) { |
|
| 4138 | - throw new DomainException( |
|
| 4139 | - sprintf( |
|
| 4140 | - esc_html__( |
|
| 4141 | - 'The %1$s field does not exist on the %2$s model.', |
|
| 4142 | - 'event_espresso' |
|
| 4143 | - ), |
|
| 4144 | - $delete_column, |
|
| 4145 | - $entity_model->get_this_model_name() |
|
| 4146 | - ) |
|
| 4147 | - ); |
|
| 4148 | - } |
|
| 4149 | - } |
|
| 4150 | - |
|
| 4151 | - |
|
| 4152 | - /** |
|
| 4153 | - * @param EEM_Base $entity_model |
|
| 4154 | - * @param Exception|null $exception |
|
| 4155 | - * @param string $action |
|
| 4156 | - * @since 4.10.30.p |
|
| 4157 | - */ |
|
| 4158 | - private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null) |
|
| 4159 | - { |
|
| 4160 | - if ($exception instanceof Exception) { |
|
| 4161 | - throw new RuntimeException( |
|
| 4162 | - sprintf( |
|
| 4163 | - esc_html__( |
|
| 4164 | - 'Could not %1$s the %2$s because the following error occurred: %3$s', |
|
| 4165 | - 'event_espresso' |
|
| 4166 | - ), |
|
| 4167 | - $action, |
|
| 4168 | - $entity_model->get_this_model_name(), |
|
| 4169 | - $exception->getMessage() |
|
| 4170 | - ) |
|
| 4171 | - ); |
|
| 4172 | - } |
|
| 4173 | - throw new RuntimeException( |
|
| 4174 | - sprintf( |
|
| 4175 | - esc_html__( |
|
| 4176 | - 'Could not %1$s the %2$s because an invalid ID was received.', |
|
| 4177 | - 'event_espresso' |
|
| 4178 | - ), |
|
| 4179 | - $action, |
|
| 4180 | - $entity_model->get_this_model_name() |
|
| 4181 | - ) |
|
| 4182 | - ); |
|
| 4183 | - } |
|
| 2852 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2853 | + // display message about search results? |
|
| 2854 | + $search = $this->request->getRequestParam('s'); |
|
| 2855 | + $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 2856 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 2857 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2858 | + trim($search, '%') |
|
| 2859 | + ) . '</p>' |
|
| 2860 | + : ''; |
|
| 2861 | + // filter before_list_table template arg |
|
| 2862 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 2863 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2864 | + $this->_template_args['before_list_table'], |
|
| 2865 | + $this->page_slug, |
|
| 2866 | + $this->request->requestParams(), |
|
| 2867 | + $this->_req_action |
|
| 2868 | + ); |
|
| 2869 | + // convert to array and filter again |
|
| 2870 | + // arrays are easier to inject new items in a specific location, |
|
| 2871 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 2872 | + $this->_template_args['before_list_table'] = implode( |
|
| 2873 | + " \n", |
|
| 2874 | + (array) apply_filters( |
|
| 2875 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 2876 | + (array) $this->_template_args['before_list_table'], |
|
| 2877 | + $this->page_slug, |
|
| 2878 | + $this->request->requestParams(), |
|
| 2879 | + $this->_req_action |
|
| 2880 | + ) |
|
| 2881 | + ); |
|
| 2882 | + // filter after_list_table template arg |
|
| 2883 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 2884 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2885 | + $this->_template_args['after_list_table'], |
|
| 2886 | + $this->page_slug, |
|
| 2887 | + $this->request->requestParams(), |
|
| 2888 | + $this->_req_action |
|
| 2889 | + ); |
|
| 2890 | + // convert to array and filter again |
|
| 2891 | + // arrays are easier to inject new items in a specific location, |
|
| 2892 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 2893 | + $this->_template_args['after_list_table'] = implode( |
|
| 2894 | + " \n", |
|
| 2895 | + (array) apply_filters( |
|
| 2896 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 2897 | + (array) $this->_template_args['after_list_table'], |
|
| 2898 | + $this->page_slug, |
|
| 2899 | + $this->request->requestParams(), |
|
| 2900 | + $this->_req_action |
|
| 2901 | + ) |
|
| 2902 | + ); |
|
| 2903 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2904 | + $template_path, |
|
| 2905 | + $this->_template_args, |
|
| 2906 | + true |
|
| 2907 | + ); |
|
| 2908 | + // the final template wrapper |
|
| 2909 | + if ($sidebar) { |
|
| 2910 | + $this->display_admin_page_with_sidebar(); |
|
| 2911 | + } else { |
|
| 2912 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2913 | + } |
|
| 2914 | + } |
|
| 2915 | + |
|
| 2916 | + |
|
| 2917 | + /** |
|
| 2918 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 2919 | + * html string for the legend. |
|
| 2920 | + * $items are expected in an array in the following format: |
|
| 2921 | + * $legend_items = array( |
|
| 2922 | + * 'item_id' => array( |
|
| 2923 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2924 | + * 'desc' => esc_html__('localized description of item'); |
|
| 2925 | + * ) |
|
| 2926 | + * ); |
|
| 2927 | + * |
|
| 2928 | + * @param array $items see above for format of array |
|
| 2929 | + * @return string html string of legend |
|
| 2930 | + * @throws DomainException |
|
| 2931 | + */ |
|
| 2932 | + protected function _display_legend($items) |
|
| 2933 | + { |
|
| 2934 | + $this->_template_args['items'] = apply_filters( |
|
| 2935 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 2936 | + (array) $items, |
|
| 2937 | + $this |
|
| 2938 | + ); |
|
| 2939 | + return EEH_Template::display_template( |
|
| 2940 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 2941 | + $this->_template_args, |
|
| 2942 | + true |
|
| 2943 | + ); |
|
| 2944 | + } |
|
| 2945 | + |
|
| 2946 | + |
|
| 2947 | + /** |
|
| 2948 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2949 | + * The returned json object is created from an array in the following format: |
|
| 2950 | + * array( |
|
| 2951 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2952 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2953 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2954 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2955 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 2956 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 2957 | + * that might be included in here) |
|
| 2958 | + * ) |
|
| 2959 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 2960 | + * |
|
| 2961 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 2962 | + * instead of displayed. |
|
| 2963 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 2964 | + * @return void |
|
| 2965 | + * @throws EE_Error |
|
| 2966 | + */ |
|
| 2967 | + protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 2968 | + { |
|
| 2969 | + // make sure any EE_Error notices have been handled. |
|
| 2970 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 2971 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 2972 | + unset($this->_template_args['data']); |
|
| 2973 | + $json = [ |
|
| 2974 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2975 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2976 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2977 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2978 | + 'notices' => EE_Error::get_notices(), |
|
| 2979 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 2980 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 2981 | + 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 2982 | + 'isEEajax' => true |
|
| 2983 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2984 | + ]; |
|
| 2985 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2986 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 2987 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 2988 | + } |
|
| 2989 | + echo wp_json_encode($json); |
|
| 2990 | + exit(); |
|
| 2991 | + } |
|
| 2992 | + |
|
| 2993 | + |
|
| 2994 | + /** |
|
| 2995 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2996 | + * |
|
| 2997 | + * @return void |
|
| 2998 | + * @throws EE_Error |
|
| 2999 | + */ |
|
| 3000 | + public function return_json() |
|
| 3001 | + { |
|
| 3002 | + if ($this->request->isAjax()) { |
|
| 3003 | + $this->_return_json(); |
|
| 3004 | + } else { |
|
| 3005 | + throw new EE_Error( |
|
| 3006 | + sprintf( |
|
| 3007 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3008 | + __FUNCTION__ |
|
| 3009 | + ) |
|
| 3010 | + ); |
|
| 3011 | + } |
|
| 3012 | + } |
|
| 3013 | + |
|
| 3014 | + |
|
| 3015 | + /** |
|
| 3016 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3017 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3018 | + * |
|
| 3019 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3020 | + */ |
|
| 3021 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3022 | + { |
|
| 3023 | + $this->_hook_obj = $hook_obj; |
|
| 3024 | + } |
|
| 3025 | + |
|
| 3026 | + |
|
| 3027 | + /** |
|
| 3028 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3029 | + * |
|
| 3030 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3031 | + * @return void |
|
| 3032 | + * @throws DomainException |
|
| 3033 | + * @throws EE_Error |
|
| 3034 | + */ |
|
| 3035 | + public function admin_page_wrapper($about = false) |
|
| 3036 | + { |
|
| 3037 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3038 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3039 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3040 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3041 | + |
|
| 3042 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3043 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3044 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3045 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3046 | + : '' |
|
| 3047 | + ); |
|
| 3048 | + |
|
| 3049 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3050 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3051 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3052 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3053 | + : '' |
|
| 3054 | + ); |
|
| 3055 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3056 | + |
|
| 3057 | + if ($this->request->isAjax()) { |
|
| 3058 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3059 | + // $template_path, |
|
| 3060 | + EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3061 | + $this->_template_args, |
|
| 3062 | + true |
|
| 3063 | + ); |
|
| 3064 | + $this->_return_json(); |
|
| 3065 | + } |
|
| 3066 | + // load settings page wrapper template |
|
| 3067 | + $template_path = $about |
|
| 3068 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3069 | + : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3070 | + |
|
| 3071 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3072 | + } |
|
| 3073 | + |
|
| 3074 | + |
|
| 3075 | + /** |
|
| 3076 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3077 | + * |
|
| 3078 | + * @return string html |
|
| 3079 | + * @throws EE_Error |
|
| 3080 | + */ |
|
| 3081 | + protected function _get_main_nav_tabs() |
|
| 3082 | + { |
|
| 3083 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3084 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3085 | + // (rather than setting in the page_routes array) |
|
| 3086 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3087 | + } |
|
| 3088 | + |
|
| 3089 | + |
|
| 3090 | + /** |
|
| 3091 | + * sort nav tabs |
|
| 3092 | + * |
|
| 3093 | + * @param $a |
|
| 3094 | + * @param $b |
|
| 3095 | + * @return int |
|
| 3096 | + */ |
|
| 3097 | + private function _sort_nav_tabs($a, $b) |
|
| 3098 | + { |
|
| 3099 | + if ($a['order'] === $b['order']) { |
|
| 3100 | + return 0; |
|
| 3101 | + } |
|
| 3102 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3103 | + } |
|
| 3104 | + |
|
| 3105 | + |
|
| 3106 | + /** |
|
| 3107 | + * generates HTML for the forms used on admin pages |
|
| 3108 | + * |
|
| 3109 | + * @param array $input_vars - array of input field details |
|
| 3110 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3111 | + * use) |
|
| 3112 | + * @param bool $id |
|
| 3113 | + * @return array|string |
|
| 3114 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3115 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3116 | + */ |
|
| 3117 | + protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3118 | + { |
|
| 3119 | + return $generator === 'string' |
|
| 3120 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3121 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3122 | + } |
|
| 3123 | + |
|
| 3124 | + |
|
| 3125 | + /** |
|
| 3126 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3127 | + * |
|
| 3128 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3129 | + * Close" button. |
|
| 3130 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3131 | + * 'Save', [1] => 'save & close') |
|
| 3132 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3133 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3134 | + * default actions by submitting some other value. |
|
| 3135 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3136 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3137 | + * close (normal form handling). |
|
| 3138 | + */ |
|
| 3139 | + protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3140 | + { |
|
| 3141 | + // make sure $text and $actions are in an array |
|
| 3142 | + $text = (array) $text; |
|
| 3143 | + $actions = (array) $actions; |
|
| 3144 | + $referrer_url = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI'); |
|
| 3145 | + $button_text = ! empty($text) |
|
| 3146 | + ? $text |
|
| 3147 | + : [ |
|
| 3148 | + esc_html__('Save', 'event_espresso'), |
|
| 3149 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3150 | + ]; |
|
| 3151 | + $default_names = ['save', 'save_and_close']; |
|
| 3152 | + $buttons = ''; |
|
| 3153 | + foreach ($button_text as $key => $button) { |
|
| 3154 | + $ref = $default_names[ $key ]; |
|
| 3155 | + $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3156 | + $buttons .= '<input type="submit" class="button-primary ' . $ref . '" ' |
|
| 3157 | + . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3158 | + . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3159 | + if (! $both) { |
|
| 3160 | + break; |
|
| 3161 | + } |
|
| 3162 | + } |
|
| 3163 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3164 | + $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3165 | + . $referrer_url |
|
| 3166 | + . '" />'; |
|
| 3167 | + $this->_template_args['save_buttons'] = $buttons; |
|
| 3168 | + } |
|
| 3169 | + |
|
| 3170 | + |
|
| 3171 | + /** |
|
| 3172 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3173 | + * |
|
| 3174 | + * @param string $route |
|
| 3175 | + * @param array $additional_hidden_fields |
|
| 3176 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3177 | + * @since 4.6.0 |
|
| 3178 | + */ |
|
| 3179 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3180 | + { |
|
| 3181 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3182 | + } |
|
| 3183 | + |
|
| 3184 | + |
|
| 3185 | + /** |
|
| 3186 | + * set form open and close tags on add/edit pages. |
|
| 3187 | + * |
|
| 3188 | + * @param string $route the route you want the form to direct to |
|
| 3189 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3190 | + * @return void |
|
| 3191 | + */ |
|
| 3192 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3193 | + { |
|
| 3194 | + if (empty($route)) { |
|
| 3195 | + $user_msg = esc_html__( |
|
| 3196 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3197 | + 'event_espresso' |
|
| 3198 | + ); |
|
| 3199 | + $dev_msg = $user_msg . "\n" |
|
| 3200 | + . sprintf( |
|
| 3201 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3202 | + __FUNCTION__, |
|
| 3203 | + __CLASS__ |
|
| 3204 | + ); |
|
| 3205 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3206 | + } |
|
| 3207 | + // open form |
|
| 3208 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3209 | + . $this->_admin_base_url |
|
| 3210 | + . '" id="' |
|
| 3211 | + . $route |
|
| 3212 | + . '_event_form" >'; |
|
| 3213 | + // add nonce |
|
| 3214 | + $nonce = |
|
| 3215 | + wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3216 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3217 | + // add REQUIRED form action |
|
| 3218 | + $hidden_fields = [ |
|
| 3219 | + 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3220 | + ]; |
|
| 3221 | + // merge arrays |
|
| 3222 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3223 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3224 | + : $hidden_fields; |
|
| 3225 | + // generate form fields |
|
| 3226 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3227 | + // add fields to form |
|
| 3228 | + foreach ((array) $form_fields as $form_field) { |
|
| 3229 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3230 | + } |
|
| 3231 | + // close form |
|
| 3232 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3233 | + } |
|
| 3234 | + |
|
| 3235 | + |
|
| 3236 | + /** |
|
| 3237 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3238 | + * discovered it would be useful for external code to have access. |
|
| 3239 | + * |
|
| 3240 | + * @param bool $success |
|
| 3241 | + * @param string $what |
|
| 3242 | + * @param string $action_desc |
|
| 3243 | + * @param array $query_args |
|
| 3244 | + * @param bool $override_overwrite |
|
| 3245 | + * @throws EE_Error |
|
| 3246 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3247 | + * @since 4.5.0 |
|
| 3248 | + */ |
|
| 3249 | + public function redirect_after_action( |
|
| 3250 | + $success = false, |
|
| 3251 | + $what = 'item', |
|
| 3252 | + $action_desc = 'processed', |
|
| 3253 | + $query_args = [], |
|
| 3254 | + $override_overwrite = false |
|
| 3255 | + ) { |
|
| 3256 | + $this->_redirect_after_action( |
|
| 3257 | + $success, |
|
| 3258 | + $what, |
|
| 3259 | + $action_desc, |
|
| 3260 | + $query_args, |
|
| 3261 | + $override_overwrite |
|
| 3262 | + ); |
|
| 3263 | + } |
|
| 3264 | + |
|
| 3265 | + |
|
| 3266 | + /** |
|
| 3267 | + * Helper method for merging existing request data with the returned redirect url. |
|
| 3268 | + * |
|
| 3269 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3270 | + * filters are still applied. |
|
| 3271 | + * |
|
| 3272 | + * @param array $new_route_data |
|
| 3273 | + * @return array |
|
| 3274 | + */ |
|
| 3275 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3276 | + { |
|
| 3277 | + foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3278 | + // unset nonces |
|
| 3279 | + if (strpos($ref, 'nonce') !== false) { |
|
| 3280 | + $this->request->unSetRequestParam($ref); |
|
| 3281 | + continue; |
|
| 3282 | + } |
|
| 3283 | + // urlencode values. |
|
| 3284 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3285 | + $this->request->setRequestParam($ref, $value); |
|
| 3286 | + } |
|
| 3287 | + return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3288 | + } |
|
| 3289 | + |
|
| 3290 | + |
|
| 3291 | + /** |
|
| 3292 | + * _redirect_after_action |
|
| 3293 | + * |
|
| 3294 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3295 | + * @param string $what - what the action was performed on |
|
| 3296 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3297 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3298 | + * action is completed |
|
| 3299 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3300 | + * override this so that they show. |
|
| 3301 | + * @return void |
|
| 3302 | + * @throws EE_Error |
|
| 3303 | + */ |
|
| 3304 | + protected function _redirect_after_action( |
|
| 3305 | + $success = 0, |
|
| 3306 | + $what = 'item', |
|
| 3307 | + $action_desc = 'processed', |
|
| 3308 | + $query_args = [], |
|
| 3309 | + $override_overwrite = false |
|
| 3310 | + ) { |
|
| 3311 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3312 | + // class name for actions/filters. |
|
| 3313 | + $classname = get_class($this); |
|
| 3314 | + // set redirect url. |
|
| 3315 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3316 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3317 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3318 | + $notices = EE_Error::get_notices(false); |
|
| 3319 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3320 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3321 | + EE_Error::overwrite_success(); |
|
| 3322 | + } |
|
| 3323 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3324 | + // how many records affected ? more than one record ? or just one ? |
|
| 3325 | + if ($success > 1) { |
|
| 3326 | + // set plural msg |
|
| 3327 | + EE_Error::add_success( |
|
| 3328 | + sprintf( |
|
| 3329 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3330 | + $what, |
|
| 3331 | + $action_desc |
|
| 3332 | + ), |
|
| 3333 | + __FILE__, |
|
| 3334 | + __FUNCTION__, |
|
| 3335 | + __LINE__ |
|
| 3336 | + ); |
|
| 3337 | + } elseif ($success === 1) { |
|
| 3338 | + // set singular msg |
|
| 3339 | + EE_Error::add_success( |
|
| 3340 | + sprintf( |
|
| 3341 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3342 | + $what, |
|
| 3343 | + $action_desc |
|
| 3344 | + ), |
|
| 3345 | + __FILE__, |
|
| 3346 | + __FUNCTION__, |
|
| 3347 | + __LINE__ |
|
| 3348 | + ); |
|
| 3349 | + } |
|
| 3350 | + } |
|
| 3351 | + // check that $query_args isn't something crazy |
|
| 3352 | + if (! is_array($query_args)) { |
|
| 3353 | + $query_args = []; |
|
| 3354 | + } |
|
| 3355 | + /** |
|
| 3356 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3357 | + * redirections on save and close actions |
|
| 3358 | + * |
|
| 3359 | + * @param array $query_args The original query_args array coming into the |
|
| 3360 | + * method. |
|
| 3361 | + * @since 4.2.0 |
|
| 3362 | + */ |
|
| 3363 | + do_action( |
|
| 3364 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3365 | + $query_args |
|
| 3366 | + ); |
|
| 3367 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3368 | + |
|
| 3369 | + if ( |
|
| 3370 | + $this->request->requestParamIsSet('save_and_close') |
|
| 3371 | + && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3372 | + ) { |
|
| 3373 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3374 | + $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3375 | + // regenerate query args array from referrer URL |
|
| 3376 | + parse_str($parsed_url['query'], $query_args); |
|
| 3377 | + // correct page and action will be in the query args now |
|
| 3378 | + $redirect_url = admin_url('admin.php'); |
|
| 3379 | + } |
|
| 3380 | + // merge any default query_args set in _default_route_query_args property |
|
| 3381 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3382 | + $args_to_merge = []; |
|
| 3383 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3384 | + // is there a wp_referer array in our _default_route_query_args property? |
|
| 3385 | + if ($query_param === 'wp_referer') { |
|
| 3386 | + $query_value = (array) $query_value; |
|
| 3387 | + foreach ($query_value as $reference => $value) { |
|
| 3388 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3389 | + continue; |
|
| 3390 | + } |
|
| 3391 | + // finally we will override any arguments in the referer with |
|
| 3392 | + // what might be set on the _default_route_query_args array. |
|
| 3393 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3394 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3395 | + } else { |
|
| 3396 | + $args_to_merge[ $reference ] = urlencode($value); |
|
| 3397 | + } |
|
| 3398 | + } |
|
| 3399 | + continue; |
|
| 3400 | + } |
|
| 3401 | + $args_to_merge[ $query_param ] = $query_value; |
|
| 3402 | + } |
|
| 3403 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3404 | + // redirect. |
|
| 3405 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3406 | + } |
|
| 3407 | + $this->_process_notices($query_args); |
|
| 3408 | + // generate redirect url |
|
| 3409 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3410 | + if (isset($query_args['action'])) { |
|
| 3411 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3412 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3413 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3414 | + } |
|
| 3415 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3416 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3417 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3418 | + $redirect_url = apply_filters( |
|
| 3419 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3420 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3421 | + $query_args |
|
| 3422 | + ); |
|
| 3423 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3424 | + if ($this->request->isAjax()) { |
|
| 3425 | + $default_data = [ |
|
| 3426 | + 'close' => true, |
|
| 3427 | + 'redirect_url' => $redirect_url, |
|
| 3428 | + 'where' => 'main', |
|
| 3429 | + 'what' => 'append', |
|
| 3430 | + ]; |
|
| 3431 | + $this->_template_args['success'] = $success; |
|
| 3432 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3433 | + $default_data, |
|
| 3434 | + $this->_template_args['data'] |
|
| 3435 | + ) : $default_data; |
|
| 3436 | + $this->_return_json(); |
|
| 3437 | + } |
|
| 3438 | + wp_safe_redirect($redirect_url); |
|
| 3439 | + exit(); |
|
| 3440 | + } |
|
| 3441 | + |
|
| 3442 | + |
|
| 3443 | + /** |
|
| 3444 | + * process any notices before redirecting (or returning ajax request) |
|
| 3445 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3446 | + * |
|
| 3447 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3448 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3449 | + * page_routes haven't been defined yet. |
|
| 3450 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3451 | + * still save a transient for the notice. |
|
| 3452 | + * @return void |
|
| 3453 | + * @throws EE_Error |
|
| 3454 | + */ |
|
| 3455 | + protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3456 | + { |
|
| 3457 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3458 | + if ($this->request->isAjax()) { |
|
| 3459 | + $notices = EE_Error::get_notices(false); |
|
| 3460 | + if (empty($this->_template_args['success'])) { |
|
| 3461 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3462 | + } |
|
| 3463 | + if (empty($this->_template_args['errors'])) { |
|
| 3464 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3465 | + } |
|
| 3466 | + if (empty($this->_template_args['attention'])) { |
|
| 3467 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3468 | + } |
|
| 3469 | + } |
|
| 3470 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3471 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3472 | + if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3473 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3474 | + $this->_add_transient( |
|
| 3475 | + $route, |
|
| 3476 | + $this->_template_args['notices'], |
|
| 3477 | + true, |
|
| 3478 | + $skip_route_verify |
|
| 3479 | + ); |
|
| 3480 | + } |
|
| 3481 | + } |
|
| 3482 | + |
|
| 3483 | + |
|
| 3484 | + /** |
|
| 3485 | + * get_action_link_or_button |
|
| 3486 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3487 | + * |
|
| 3488 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3489 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3490 | + * property. |
|
| 3491 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3492 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3493 | + * @param string $base_url If this is not provided |
|
| 3494 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3495 | + * Otherwise this value will be used. |
|
| 3496 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3497 | + * @return string |
|
| 3498 | + * @throws InvalidArgumentException |
|
| 3499 | + * @throws InvalidInterfaceException |
|
| 3500 | + * @throws InvalidDataTypeException |
|
| 3501 | + * @throws EE_Error |
|
| 3502 | + */ |
|
| 3503 | + public function get_action_link_or_button( |
|
| 3504 | + $action, |
|
| 3505 | + $type = 'add', |
|
| 3506 | + $extra_request = [], |
|
| 3507 | + $class = 'button button--primary', |
|
| 3508 | + $base_url = '', |
|
| 3509 | + $exclude_nonce = false |
|
| 3510 | + ) { |
|
| 3511 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3512 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3513 | + throw new EE_Error( |
|
| 3514 | + sprintf( |
|
| 3515 | + esc_html__( |
|
| 3516 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3517 | + 'event_espresso' |
|
| 3518 | + ), |
|
| 3519 | + $action |
|
| 3520 | + ) |
|
| 3521 | + ); |
|
| 3522 | + } |
|
| 3523 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3524 | + throw new EE_Error( |
|
| 3525 | + sprintf( |
|
| 3526 | + esc_html__( |
|
| 3527 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3528 | + 'event_espresso' |
|
| 3529 | + ), |
|
| 3530 | + $type |
|
| 3531 | + ) |
|
| 3532 | + ); |
|
| 3533 | + } |
|
| 3534 | + // finally check user access for this button. |
|
| 3535 | + $has_access = $this->check_user_access($action, true); |
|
| 3536 | + if (! $has_access) { |
|
| 3537 | + return ''; |
|
| 3538 | + } |
|
| 3539 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3540 | + $query_args = [ |
|
| 3541 | + 'action' => $action, |
|
| 3542 | + ]; |
|
| 3543 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3544 | + if (! empty($extra_request)) { |
|
| 3545 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3546 | + } |
|
| 3547 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3548 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3549 | + } |
|
| 3550 | + |
|
| 3551 | + |
|
| 3552 | + /** |
|
| 3553 | + * _per_page_screen_option |
|
| 3554 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3555 | + * |
|
| 3556 | + * @return void |
|
| 3557 | + * @throws InvalidArgumentException |
|
| 3558 | + * @throws InvalidInterfaceException |
|
| 3559 | + * @throws InvalidDataTypeException |
|
| 3560 | + */ |
|
| 3561 | + protected function _per_page_screen_option() |
|
| 3562 | + { |
|
| 3563 | + $option = 'per_page'; |
|
| 3564 | + $args = [ |
|
| 3565 | + 'label' => apply_filters( |
|
| 3566 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3567 | + $this->_admin_page_title, |
|
| 3568 | + $this |
|
| 3569 | + ), |
|
| 3570 | + 'default' => (int) apply_filters( |
|
| 3571 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3572 | + 20 |
|
| 3573 | + ), |
|
| 3574 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3575 | + ]; |
|
| 3576 | + // ONLY add the screen option if the user has access to it. |
|
| 3577 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3578 | + add_screen_option($option, $args); |
|
| 3579 | + } |
|
| 3580 | + } |
|
| 3581 | + |
|
| 3582 | + |
|
| 3583 | + /** |
|
| 3584 | + * set_per_page_screen_option |
|
| 3585 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3586 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3587 | + * admin_menu. |
|
| 3588 | + * |
|
| 3589 | + * @return void |
|
| 3590 | + */ |
|
| 3591 | + private function _set_per_page_screen_options() |
|
| 3592 | + { |
|
| 3593 | + if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3594 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3595 | + if (! $user = wp_get_current_user()) { |
|
| 3596 | + return; |
|
| 3597 | + } |
|
| 3598 | + $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3599 | + if (! $option) { |
|
| 3600 | + return; |
|
| 3601 | + } |
|
| 3602 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3603 | + $map_option = $option; |
|
| 3604 | + $option = str_replace('-', '_', $option); |
|
| 3605 | + switch ($map_option) { |
|
| 3606 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3607 | + $max_value = apply_filters( |
|
| 3608 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3609 | + 999, |
|
| 3610 | + $this->_current_page, |
|
| 3611 | + $this->_current_view |
|
| 3612 | + ); |
|
| 3613 | + if ($value < 1) { |
|
| 3614 | + return; |
|
| 3615 | + } |
|
| 3616 | + $value = min($value, $max_value); |
|
| 3617 | + break; |
|
| 3618 | + default: |
|
| 3619 | + $value = apply_filters( |
|
| 3620 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3621 | + false, |
|
| 3622 | + $option, |
|
| 3623 | + $value |
|
| 3624 | + ); |
|
| 3625 | + if (false === $value) { |
|
| 3626 | + return; |
|
| 3627 | + } |
|
| 3628 | + break; |
|
| 3629 | + } |
|
| 3630 | + update_user_meta($user->ID, $option, $value); |
|
| 3631 | + wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3632 | + exit; |
|
| 3633 | + } |
|
| 3634 | + } |
|
| 3635 | + |
|
| 3636 | + |
|
| 3637 | + /** |
|
| 3638 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3639 | + * |
|
| 3640 | + * @param array $data array that will be assigned to template args. |
|
| 3641 | + */ |
|
| 3642 | + public function set_template_args($data) |
|
| 3643 | + { |
|
| 3644 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3645 | + } |
|
| 3646 | + |
|
| 3647 | + |
|
| 3648 | + /** |
|
| 3649 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3650 | + * |
|
| 3651 | + * @param string $route the route that should receive the transient |
|
| 3652 | + * @param array $data the data that gets sent |
|
| 3653 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3654 | + * normal route transient. |
|
| 3655 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3656 | + * when we are adding a transient before page_routes have been defined. |
|
| 3657 | + * @return void |
|
| 3658 | + * @throws EE_Error |
|
| 3659 | + */ |
|
| 3660 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3661 | + { |
|
| 3662 | + $user_id = get_current_user_id(); |
|
| 3663 | + if (! $skip_route_verify) { |
|
| 3664 | + $this->_verify_route($route); |
|
| 3665 | + } |
|
| 3666 | + // now let's set the string for what kind of transient we're setting |
|
| 3667 | + $transient = $notices |
|
| 3668 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3669 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3670 | + $data = $notices ? ['notices' => $data] : $data; |
|
| 3671 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3672 | + $existing = is_multisite() && is_network_admin() |
|
| 3673 | + ? get_site_transient($transient) |
|
| 3674 | + : get_transient($transient); |
|
| 3675 | + if ($existing) { |
|
| 3676 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3677 | + } |
|
| 3678 | + if (is_multisite() && is_network_admin()) { |
|
| 3679 | + set_site_transient($transient, $data, 8); |
|
| 3680 | + } else { |
|
| 3681 | + set_transient($transient, $data, 8); |
|
| 3682 | + } |
|
| 3683 | + } |
|
| 3684 | + |
|
| 3685 | + |
|
| 3686 | + /** |
|
| 3687 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3688 | + * |
|
| 3689 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3690 | + * @param string $route |
|
| 3691 | + * @return mixed data |
|
| 3692 | + */ |
|
| 3693 | + protected function _get_transient($notices = false, $route = '') |
|
| 3694 | + { |
|
| 3695 | + $user_id = get_current_user_id(); |
|
| 3696 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3697 | + $transient = $notices |
|
| 3698 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3699 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3700 | + $data = is_multisite() && is_network_admin() |
|
| 3701 | + ? get_site_transient($transient) |
|
| 3702 | + : get_transient($transient); |
|
| 3703 | + // delete transient after retrieval (just in case it hasn't expired); |
|
| 3704 | + if (is_multisite() && is_network_admin()) { |
|
| 3705 | + delete_site_transient($transient); |
|
| 3706 | + } else { |
|
| 3707 | + delete_transient($transient); |
|
| 3708 | + } |
|
| 3709 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3710 | + } |
|
| 3711 | + |
|
| 3712 | + |
|
| 3713 | + /** |
|
| 3714 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3715 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3716 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3717 | + * |
|
| 3718 | + * @return void |
|
| 3719 | + */ |
|
| 3720 | + protected function _transient_garbage_collection() |
|
| 3721 | + { |
|
| 3722 | + global $wpdb; |
|
| 3723 | + // retrieve all existing transients |
|
| 3724 | + $query = |
|
| 3725 | + "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3726 | + if ($results = $wpdb->get_results($query)) { |
|
| 3727 | + foreach ($results as $result) { |
|
| 3728 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3729 | + get_transient($transient); |
|
| 3730 | + if (is_multisite() && is_network_admin()) { |
|
| 3731 | + get_site_transient($transient); |
|
| 3732 | + } |
|
| 3733 | + } |
|
| 3734 | + } |
|
| 3735 | + } |
|
| 3736 | + |
|
| 3737 | + |
|
| 3738 | + /** |
|
| 3739 | + * get_view |
|
| 3740 | + * |
|
| 3741 | + * @return string content of _view property |
|
| 3742 | + */ |
|
| 3743 | + public function get_view() |
|
| 3744 | + { |
|
| 3745 | + return $this->_view; |
|
| 3746 | + } |
|
| 3747 | + |
|
| 3748 | + |
|
| 3749 | + /** |
|
| 3750 | + * getter for the protected $_views property |
|
| 3751 | + * |
|
| 3752 | + * @return array |
|
| 3753 | + */ |
|
| 3754 | + public function get_views() |
|
| 3755 | + { |
|
| 3756 | + return $this->_views; |
|
| 3757 | + } |
|
| 3758 | + |
|
| 3759 | + |
|
| 3760 | + /** |
|
| 3761 | + * get_current_page |
|
| 3762 | + * |
|
| 3763 | + * @return string _current_page property value |
|
| 3764 | + */ |
|
| 3765 | + public function get_current_page() |
|
| 3766 | + { |
|
| 3767 | + return $this->_current_page; |
|
| 3768 | + } |
|
| 3769 | + |
|
| 3770 | + |
|
| 3771 | + /** |
|
| 3772 | + * get_current_view |
|
| 3773 | + * |
|
| 3774 | + * @return string _current_view property value |
|
| 3775 | + */ |
|
| 3776 | + public function get_current_view() |
|
| 3777 | + { |
|
| 3778 | + return $this->_current_view; |
|
| 3779 | + } |
|
| 3780 | + |
|
| 3781 | + |
|
| 3782 | + /** |
|
| 3783 | + * get_current_screen |
|
| 3784 | + * |
|
| 3785 | + * @return object The current WP_Screen object |
|
| 3786 | + */ |
|
| 3787 | + public function get_current_screen() |
|
| 3788 | + { |
|
| 3789 | + return $this->_current_screen; |
|
| 3790 | + } |
|
| 3791 | + |
|
| 3792 | + |
|
| 3793 | + /** |
|
| 3794 | + * get_current_page_view_url |
|
| 3795 | + * |
|
| 3796 | + * @return string This returns the url for the current_page_view. |
|
| 3797 | + */ |
|
| 3798 | + public function get_current_page_view_url() |
|
| 3799 | + { |
|
| 3800 | + return $this->_current_page_view_url; |
|
| 3801 | + } |
|
| 3802 | + |
|
| 3803 | + |
|
| 3804 | + /** |
|
| 3805 | + * just returns the Request |
|
| 3806 | + * |
|
| 3807 | + * @return RequestInterface |
|
| 3808 | + */ |
|
| 3809 | + public function get_request() |
|
| 3810 | + { |
|
| 3811 | + return $this->request; |
|
| 3812 | + } |
|
| 3813 | + |
|
| 3814 | + |
|
| 3815 | + /** |
|
| 3816 | + * just returns the _req_data property |
|
| 3817 | + * |
|
| 3818 | + * @return array |
|
| 3819 | + */ |
|
| 3820 | + public function get_request_data() |
|
| 3821 | + { |
|
| 3822 | + return $this->request->requestParams(); |
|
| 3823 | + } |
|
| 3824 | + |
|
| 3825 | + |
|
| 3826 | + /** |
|
| 3827 | + * returns the _req_data protected property |
|
| 3828 | + * |
|
| 3829 | + * @return string |
|
| 3830 | + */ |
|
| 3831 | + public function get_req_action() |
|
| 3832 | + { |
|
| 3833 | + return $this->_req_action; |
|
| 3834 | + } |
|
| 3835 | + |
|
| 3836 | + |
|
| 3837 | + /** |
|
| 3838 | + * @return bool value of $_is_caf property |
|
| 3839 | + */ |
|
| 3840 | + public function is_caf() |
|
| 3841 | + { |
|
| 3842 | + return $this->_is_caf; |
|
| 3843 | + } |
|
| 3844 | + |
|
| 3845 | + |
|
| 3846 | + /** |
|
| 3847 | + * @return mixed |
|
| 3848 | + */ |
|
| 3849 | + public function default_espresso_metaboxes() |
|
| 3850 | + { |
|
| 3851 | + return $this->_default_espresso_metaboxes; |
|
| 3852 | + } |
|
| 3853 | + |
|
| 3854 | + |
|
| 3855 | + /** |
|
| 3856 | + * @return mixed |
|
| 3857 | + */ |
|
| 3858 | + public function admin_base_url() |
|
| 3859 | + { |
|
| 3860 | + return $this->_admin_base_url; |
|
| 3861 | + } |
|
| 3862 | + |
|
| 3863 | + |
|
| 3864 | + /** |
|
| 3865 | + * @return mixed |
|
| 3866 | + */ |
|
| 3867 | + public function wp_page_slug() |
|
| 3868 | + { |
|
| 3869 | + return $this->_wp_page_slug; |
|
| 3870 | + } |
|
| 3871 | + |
|
| 3872 | + |
|
| 3873 | + /** |
|
| 3874 | + * updates espresso configuration settings |
|
| 3875 | + * |
|
| 3876 | + * @param string $tab |
|
| 3877 | + * @param EE_Config_Base|EE_Config $config |
|
| 3878 | + * @param string $file file where error occurred |
|
| 3879 | + * @param string $func function where error occurred |
|
| 3880 | + * @param string $line line no where error occurred |
|
| 3881 | + * @return boolean |
|
| 3882 | + */ |
|
| 3883 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3884 | + { |
|
| 3885 | + // remove any options that are NOT going to be saved with the config settings. |
|
| 3886 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 3887 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3888 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3889 | + update_option('ee_ueip_has_notified', true); |
|
| 3890 | + } |
|
| 3891 | + // and save it (note we're also doing the network save here) |
|
| 3892 | + $net_saved = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false); |
|
| 3893 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3894 | + if ($config_saved && $net_saved) { |
|
| 3895 | + EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3896 | + return true; |
|
| 3897 | + } |
|
| 3898 | + EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3899 | + return false; |
|
| 3900 | + } |
|
| 3901 | + |
|
| 3902 | + |
|
| 3903 | + /** |
|
| 3904 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3905 | + * |
|
| 3906 | + * @return array |
|
| 3907 | + */ |
|
| 3908 | + public function get_yes_no_values() |
|
| 3909 | + { |
|
| 3910 | + return $this->_yes_no_values; |
|
| 3911 | + } |
|
| 3912 | + |
|
| 3913 | + |
|
| 3914 | + protected function _get_dir() |
|
| 3915 | + { |
|
| 3916 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 3917 | + return dirname($reflector->getFileName()); |
|
| 3918 | + } |
|
| 3919 | + |
|
| 3920 | + |
|
| 3921 | + /** |
|
| 3922 | + * A helper for getting a "next link". |
|
| 3923 | + * |
|
| 3924 | + * @param string $url The url to link to |
|
| 3925 | + * @param string $class The class to use. |
|
| 3926 | + * @return string |
|
| 3927 | + */ |
|
| 3928 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3929 | + { |
|
| 3930 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3931 | + } |
|
| 3932 | + |
|
| 3933 | + |
|
| 3934 | + /** |
|
| 3935 | + * A helper for getting a "previous link". |
|
| 3936 | + * |
|
| 3937 | + * @param string $url The url to link to |
|
| 3938 | + * @param string $class The class to use. |
|
| 3939 | + * @return string |
|
| 3940 | + */ |
|
| 3941 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3942 | + { |
|
| 3943 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3944 | + } |
|
| 3945 | + |
|
| 3946 | + |
|
| 3947 | + |
|
| 3948 | + |
|
| 3949 | + |
|
| 3950 | + |
|
| 3951 | + |
|
| 3952 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3953 | + |
|
| 3954 | + |
|
| 3955 | + /** |
|
| 3956 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 3957 | + * 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 |
|
| 3958 | + * _req_data array. |
|
| 3959 | + * |
|
| 3960 | + * @return bool success/fail |
|
| 3961 | + * @throws EE_Error |
|
| 3962 | + * @throws InvalidArgumentException |
|
| 3963 | + * @throws ReflectionException |
|
| 3964 | + * @throws InvalidDataTypeException |
|
| 3965 | + * @throws InvalidInterfaceException |
|
| 3966 | + */ |
|
| 3967 | + protected function _process_resend_registration() |
|
| 3968 | + { |
|
| 3969 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3970 | + do_action( |
|
| 3971 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 3972 | + $this->_template_args['success'], |
|
| 3973 | + $this->request->requestParams() |
|
| 3974 | + ); |
|
| 3975 | + return $this->_template_args['success']; |
|
| 3976 | + } |
|
| 3977 | + |
|
| 3978 | + |
|
| 3979 | + /** |
|
| 3980 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3981 | + * |
|
| 3982 | + * @param EE_Payment $payment |
|
| 3983 | + * @return bool success/fail |
|
| 3984 | + */ |
|
| 3985 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 3986 | + { |
|
| 3987 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3988 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3989 | + $this->_template_args['success'] = apply_filters( |
|
| 3990 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 3991 | + false, |
|
| 3992 | + $payment |
|
| 3993 | + ); |
|
| 3994 | + return $this->_template_args['success']; |
|
| 3995 | + } |
|
| 3996 | + |
|
| 3997 | + |
|
| 3998 | + /** |
|
| 3999 | + * @param EEM_Base $entity_model |
|
| 4000 | + * @param string $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc |
|
| 4001 | + * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4002 | + * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4003 | + * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4004 | + * @return int|float |
|
| 4005 | + * @throws EE_Error |
|
| 4006 | + */ |
|
| 4007 | + protected function trashRestoreDeleteEntities( |
|
| 4008 | + EEM_Base $entity_model, |
|
| 4009 | + string $entity_PK_name, |
|
| 4010 | + string $action = EE_Admin_List_Table::ACTION_DELETE, |
|
| 4011 | + string $delete_column = '', |
|
| 4012 | + callable $callback = null |
|
| 4013 | + ) { |
|
| 4014 | + $entity_PK = $entity_model->get_primary_key_field(); |
|
| 4015 | + $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name(); |
|
| 4016 | + $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK); |
|
| 4017 | + // grab ID if deleting a single entity |
|
| 4018 | + if ($this->request->requestParamIsSet($entity_PK_name)) { |
|
| 4019 | + $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type); |
|
| 4020 | + return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0; |
|
| 4021 | + } |
|
| 4022 | + // or grab checkbox array if bulk deleting |
|
| 4023 | + $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true); |
|
| 4024 | + if (empty($checkboxes)) { |
|
| 4025 | + return 0; |
|
| 4026 | + } |
|
| 4027 | + $success = 0; |
|
| 4028 | + $IDs = array_keys($checkboxes); |
|
| 4029 | + // cycle thru bulk action checkboxes |
|
| 4030 | + foreach ($IDs as $ID) { |
|
| 4031 | + // increment $success |
|
| 4032 | + if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) { |
|
| 4033 | + $success++; |
|
| 4034 | + } |
|
| 4035 | + } |
|
| 4036 | + $count = (int) count($checkboxes); |
|
| 4037 | + // if multiple entities were deleted successfully, then $deleted will be full count of deletions, |
|
| 4038 | + // otherwise it will be a fraction of ( actual deletions / total entities to be deleted ) |
|
| 4039 | + return $success === $count ? $count : $success / $count; |
|
| 4040 | + } |
|
| 4041 | + |
|
| 4042 | + |
|
| 4043 | + /** |
|
| 4044 | + * @param EE_Primary_Key_Field_Base $entity_PK |
|
| 4045 | + * @return string |
|
| 4046 | + * @throws EE_Error |
|
| 4047 | + * @since 4.10.30.p |
|
| 4048 | + */ |
|
| 4049 | + private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string |
|
| 4050 | + { |
|
| 4051 | + $entity_PK_type = $entity_PK->getSchemaType(); |
|
| 4052 | + switch ($entity_PK_type) { |
|
| 4053 | + case 'boolean': |
|
| 4054 | + return 'bool'; |
|
| 4055 | + case 'integer': |
|
| 4056 | + return 'int'; |
|
| 4057 | + case 'number': |
|
| 4058 | + return 'float'; |
|
| 4059 | + case 'string': |
|
| 4060 | + return 'string'; |
|
| 4061 | + } |
|
| 4062 | + throw new RuntimeException( |
|
| 4063 | + sprintf( |
|
| 4064 | + esc_html__( |
|
| 4065 | + '"%1$s" is an invalid schema type for the %2$s primary key.', |
|
| 4066 | + 'event_espresso' |
|
| 4067 | + ), |
|
| 4068 | + $entity_PK_type, |
|
| 4069 | + $entity_PK->get_name() |
|
| 4070 | + ) |
|
| 4071 | + ); |
|
| 4072 | + } |
|
| 4073 | + |
|
| 4074 | + |
|
| 4075 | + /** |
|
| 4076 | + * @param EEM_Base $entity_model |
|
| 4077 | + * @param int|string $entity_ID |
|
| 4078 | + * @param string $action one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash |
|
| 4079 | + * @param string $delete_column name of the field that denotes whether entity is trashed |
|
| 4080 | + * @param callable|null $callback called after entity is trashed, restored, or deleted |
|
| 4081 | + * @return bool |
|
| 4082 | + */ |
|
| 4083 | + protected function trashRestoreDeleteEntity( |
|
| 4084 | + EEM_Base $entity_model, |
|
| 4085 | + $entity_ID, |
|
| 4086 | + string $action, |
|
| 4087 | + string $delete_column, |
|
| 4088 | + callable $callback = null |
|
| 4089 | + ) { |
|
| 4090 | + $entity_ID = absint($entity_ID); |
|
| 4091 | + if (! $entity_ID) { |
|
| 4092 | + $this->trashRestoreDeleteError($action, $entity_model); |
|
| 4093 | + } |
|
| 4094 | + $result = 0; |
|
| 4095 | + try { |
|
| 4096 | + switch ($action) { |
|
| 4097 | + case EE_Admin_List_Table::ACTION_DELETE: |
|
| 4098 | + $result = (bool) $entity_model->delete_permanently_by_ID($entity_ID); |
|
| 4099 | + break; |
|
| 4100 | + case EE_Admin_List_Table::ACTION_RESTORE: |
|
| 4101 | + $this->validateDeleteColumn($entity_model, $delete_column); |
|
| 4102 | + $result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID); |
|
| 4103 | + break; |
|
| 4104 | + case EE_Admin_List_Table::ACTION_TRASH: |
|
| 4105 | + $this->validateDeleteColumn($entity_model, $delete_column); |
|
| 4106 | + $result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID); |
|
| 4107 | + break; |
|
| 4108 | + } |
|
| 4109 | + } catch (Exception $exception) { |
|
| 4110 | + $this->trashRestoreDeleteError($action, $entity_model, $exception); |
|
| 4111 | + } |
|
| 4112 | + if (is_callable($callback)) { |
|
| 4113 | + call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]); |
|
| 4114 | + } |
|
| 4115 | + return $result; |
|
| 4116 | + } |
|
| 4117 | + |
|
| 4118 | + |
|
| 4119 | + /** |
|
| 4120 | + * @param EEM_Base $entity_model |
|
| 4121 | + * @param string $delete_column |
|
| 4122 | + * @since 4.10.30.p |
|
| 4123 | + */ |
|
| 4124 | + private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column) |
|
| 4125 | + { |
|
| 4126 | + if (empty($delete_column)) { |
|
| 4127 | + throw new DomainException( |
|
| 4128 | + sprintf( |
|
| 4129 | + esc_html__( |
|
| 4130 | + 'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.', |
|
| 4131 | + 'event_espresso' |
|
| 4132 | + ), |
|
| 4133 | + $entity_model->get_this_model_name() |
|
| 4134 | + ) |
|
| 4135 | + ); |
|
| 4136 | + } |
|
| 4137 | + if (! $entity_model->has_field($delete_column)) { |
|
| 4138 | + throw new DomainException( |
|
| 4139 | + sprintf( |
|
| 4140 | + esc_html__( |
|
| 4141 | + 'The %1$s field does not exist on the %2$s model.', |
|
| 4142 | + 'event_espresso' |
|
| 4143 | + ), |
|
| 4144 | + $delete_column, |
|
| 4145 | + $entity_model->get_this_model_name() |
|
| 4146 | + ) |
|
| 4147 | + ); |
|
| 4148 | + } |
|
| 4149 | + } |
|
| 4150 | + |
|
| 4151 | + |
|
| 4152 | + /** |
|
| 4153 | + * @param EEM_Base $entity_model |
|
| 4154 | + * @param Exception|null $exception |
|
| 4155 | + * @param string $action |
|
| 4156 | + * @since 4.10.30.p |
|
| 4157 | + */ |
|
| 4158 | + private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null) |
|
| 4159 | + { |
|
| 4160 | + if ($exception instanceof Exception) { |
|
| 4161 | + throw new RuntimeException( |
|
| 4162 | + sprintf( |
|
| 4163 | + esc_html__( |
|
| 4164 | + 'Could not %1$s the %2$s because the following error occurred: %3$s', |
|
| 4165 | + 'event_espresso' |
|
| 4166 | + ), |
|
| 4167 | + $action, |
|
| 4168 | + $entity_model->get_this_model_name(), |
|
| 4169 | + $exception->getMessage() |
|
| 4170 | + ) |
|
| 4171 | + ); |
|
| 4172 | + } |
|
| 4173 | + throw new RuntimeException( |
|
| 4174 | + sprintf( |
|
| 4175 | + esc_html__( |
|
| 4176 | + 'Could not %1$s the %2$s because an invalid ID was received.', |
|
| 4177 | + 'event_espresso' |
|
| 4178 | + ), |
|
| 4179 | + $action, |
|
| 4180 | + $entity_model->get_this_model_name() |
|
| 4181 | + ) |
|
| 4182 | + ); |
|
| 4183 | + } |
|
| 4184 | 4184 | } |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | $ee_menu_slugs = (array) $ee_menu_slugs; |
| 515 | 515 | if ( |
| 516 | 516 | ! $this->request->isAjax() |
| 517 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 517 | + && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) |
|
| 518 | 518 | ) { |
| 519 | 519 | return; |
| 520 | 520 | } |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | : $req_action; |
| 535 | 535 | |
| 536 | 536 | $this->_current_view = $this->_req_action; |
| 537 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 537 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 538 | 538 | $this->_define_page_props(); |
| 539 | 539 | $this->_current_page_view_url = add_query_arg( |
| 540 | 540 | ['page' => $this->_current_page, 'action' => $this->_current_view], |
@@ -571,21 +571,21 @@ discard block |
||
| 571 | 571 | } |
| 572 | 572 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
| 573 | 573 | $this->_page_routes = apply_filters( |
| 574 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 574 | + 'FHEE__'.get_class($this).'__page_setup__page_routes', |
|
| 575 | 575 | $this->_page_routes, |
| 576 | 576 | $this |
| 577 | 577 | ); |
| 578 | 578 | $this->_page_config = apply_filters( |
| 579 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 579 | + 'FHEE__'.get_class($this).'__page_setup__page_config', |
|
| 580 | 580 | $this->_page_config, |
| 581 | 581 | $this |
| 582 | 582 | ); |
| 583 | 583 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
| 584 | 584 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 585 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 585 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 586 | 586 | add_action( |
| 587 | 587 | 'AHEE__EE_Admin_Page__route_admin_request', |
| 588 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 588 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view], |
|
| 589 | 589 | 10, |
| 590 | 590 | 2 |
| 591 | 591 | ); |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | if ($this->_is_UI_request) { |
| 599 | 599 | // admin_init stuff - global, all views for this page class, specific view |
| 600 | 600 | add_action('admin_init', [$this, 'admin_init'], 10); |
| 601 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 602 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 601 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 602 | + add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15); |
|
| 603 | 603 | } |
| 604 | 604 | } else { |
| 605 | 605 | // hijack regular WP loading and route admin request immediately |
@@ -618,12 +618,12 @@ discard block |
||
| 618 | 618 | */ |
| 619 | 619 | private function _do_other_page_hooks() |
| 620 | 620 | { |
| 621 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 621 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []); |
|
| 622 | 622 | foreach ($registered_pages as $page) { |
| 623 | 623 | // now let's setup the file name and class that should be present |
| 624 | 624 | $classname = str_replace('.class.php', '', $page); |
| 625 | 625 | // autoloaders should take care of loading file |
| 626 | - if (! class_exists($classname)) { |
|
| 626 | + if ( ! class_exists($classname)) { |
|
| 627 | 627 | $error_msg[] = sprintf( |
| 628 | 628 | esc_html__( |
| 629 | 629 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | ), |
| 641 | 641 | $page, |
| 642 | 642 | '<br />', |
| 643 | - '<strong>' . $classname . '</strong>' |
|
| 643 | + '<strong>'.$classname.'</strong>' |
|
| 644 | 644 | ); |
| 645 | 645 | throw new EE_Error(implode('||', $error_msg)); |
| 646 | 646 | } |
@@ -682,13 +682,13 @@ discard block |
||
| 682 | 682 | // load admin_notices - global, page class, and view specific |
| 683 | 683 | add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
| 684 | 684 | add_action('admin_notices', [$this, 'admin_notices'], 10); |
| 685 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 686 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 685 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 686 | + add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15); |
|
| 687 | 687 | } |
| 688 | 688 | // load network admin_notices - global, page class, and view specific |
| 689 | 689 | add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
| 690 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 691 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 690 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 691 | + add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]); |
|
| 692 | 692 | } |
| 693 | 693 | // this will save any per_page screen options if they are present |
| 694 | 694 | $this->_set_per_page_screen_options(); |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | protected function _verify_routes() |
| 810 | 810 | { |
| 811 | 811 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 812 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 812 | + if ( ! $this->_current_page && ! $this->request->isAjax()) { |
|
| 813 | 813 | return false; |
| 814 | 814 | } |
| 815 | 815 | $this->_route = false; |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | $this->_admin_page_title |
| 822 | 822 | ); |
| 823 | 823 | // developer error msg |
| 824 | - $error_msg .= '||' . $error_msg |
|
| 824 | + $error_msg .= '||'.$error_msg |
|
| 825 | 825 | . esc_html__( |
| 826 | 826 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
| 827 | 827 | 'event_espresso' |
@@ -830,9 +830,9 @@ discard block |
||
| 830 | 830 | } |
| 831 | 831 | // and that the requested page route exists |
| 832 | 832 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
| 833 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 834 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 835 | - ? $this->_page_config[ $this->_req_action ] |
|
| 833 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 834 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 835 | + ? $this->_page_config[$this->_req_action] |
|
| 836 | 836 | : []; |
| 837 | 837 | } else { |
| 838 | 838 | // user error msg |
@@ -844,7 +844,7 @@ discard block |
||
| 844 | 844 | $this->_admin_page_title |
| 845 | 845 | ); |
| 846 | 846 | // developer error msg |
| 847 | - $error_msg .= '||' . $error_msg |
|
| 847 | + $error_msg .= '||'.$error_msg |
|
| 848 | 848 | . sprintf( |
| 849 | 849 | esc_html__( |
| 850 | 850 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -855,7 +855,7 @@ discard block |
||
| 855 | 855 | throw new EE_Error($error_msg); |
| 856 | 856 | } |
| 857 | 857 | // and that a default route exists |
| 858 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 858 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 859 | 859 | // user error msg |
| 860 | 860 | $error_msg = sprintf( |
| 861 | 861 | esc_html__( |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | $this->_admin_page_title |
| 866 | 866 | ); |
| 867 | 867 | // developer error msg |
| 868 | - $error_msg .= '||' . $error_msg |
|
| 868 | + $error_msg .= '||'.$error_msg |
|
| 869 | 869 | . esc_html__( |
| 870 | 870 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
| 871 | 871 | 'event_espresso' |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | $this->_admin_page_title |
| 907 | 907 | ); |
| 908 | 908 | // developer error msg |
| 909 | - $error_msg .= '||' . $error_msg |
|
| 909 | + $error_msg .= '||'.$error_msg |
|
| 910 | 910 | . sprintf( |
| 911 | 911 | esc_html__( |
| 912 | 912 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | protected function _verify_nonce($nonce, $nonce_ref) |
| 932 | 932 | { |
| 933 | 933 | // verify nonce against expected value |
| 934 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 934 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 935 | 935 | // these are not the droids you are looking for !!! |
| 936 | 936 | $msg = sprintf( |
| 937 | 937 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | __CLASS__ |
| 949 | 949 | ); |
| 950 | 950 | } |
| 951 | - if (! $this->request->isAjax()) { |
|
| 951 | + if ( ! $this->request->isAjax()) { |
|
| 952 | 952 | wp_die($msg); |
| 953 | 953 | } |
| 954 | 954 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | */ |
| 973 | 973 | protected function _route_admin_request() |
| 974 | 974 | { |
| 975 | - if (! $this->_is_UI_request) { |
|
| 975 | + if ( ! $this->_is_UI_request) { |
|
| 976 | 976 | $this->_verify_routes(); |
| 977 | 977 | } |
| 978 | 978 | $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | $error_msg = ''; |
| 993 | 993 | // action right before calling route |
| 994 | 994 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
| 995 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 995 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 996 | 996 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
| 997 | 997 | } |
| 998 | 998 | // right before calling the route, let's clean the _wp_http_referer |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | wp_unslash($this->request->getServerParam('REQUEST_URI')) |
| 1004 | 1004 | ) |
| 1005 | 1005 | ); |
| 1006 | - if (! empty($func)) { |
|
| 1006 | + if ( ! empty($func)) { |
|
| 1007 | 1007 | if (is_array($func)) { |
| 1008 | 1008 | [$class, $method] = $func; |
| 1009 | 1009 | } elseif (strpos($func, '::') !== false) { |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | $class = $this; |
| 1013 | 1013 | $method = $func; |
| 1014 | 1014 | } |
| 1015 | - if (! (is_object($class) && $class === $this)) { |
|
| 1015 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 1016 | 1016 | // send along this admin page object for access by addons. |
| 1017 | 1017 | $args['admin_page_object'] = $this; |
| 1018 | 1018 | } |
@@ -1053,7 +1053,7 @@ discard block |
||
| 1053 | 1053 | $method |
| 1054 | 1054 | ); |
| 1055 | 1055 | } |
| 1056 | - if (! empty($error_msg)) { |
|
| 1056 | + if ( ! empty($error_msg)) { |
|
| 1057 | 1057 | throw new EE_Error($error_msg); |
| 1058 | 1058 | } |
| 1059 | 1059 | } |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | if (strpos($key, 'nonce') !== false) { |
| 1139 | 1139 | continue; |
| 1140 | 1140 | } |
| 1141 | - $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1141 | + $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value; |
|
| 1142 | 1142 | } |
| 1143 | 1143 | } |
| 1144 | 1144 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1177,12 +1177,12 @@ discard block |
||
| 1177 | 1177 | */ |
| 1178 | 1178 | protected function _add_help_tabs() |
| 1179 | 1179 | { |
| 1180 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1181 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1180 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1181 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1182 | 1182 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
| 1183 | 1183 | if (is_array($config) && isset($config['help_sidebar'])) { |
| 1184 | 1184 | // check that the callback given is valid |
| 1185 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1185 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1186 | 1186 | throw new EE_Error( |
| 1187 | 1187 | sprintf( |
| 1188 | 1188 | esc_html__( |
@@ -1195,18 +1195,18 @@ discard block |
||
| 1195 | 1195 | ); |
| 1196 | 1196 | } |
| 1197 | 1197 | $content = apply_filters( |
| 1198 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1198 | + 'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', |
|
| 1199 | 1199 | $this->{$config['help_sidebar']}() |
| 1200 | 1200 | ); |
| 1201 | 1201 | $this->_current_screen->set_help_sidebar($content); |
| 1202 | 1202 | } |
| 1203 | - if (! isset($config['help_tabs'])) { |
|
| 1203 | + if ( ! isset($config['help_tabs'])) { |
|
| 1204 | 1204 | return; |
| 1205 | 1205 | } //no help tabs for this route |
| 1206 | 1206 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
| 1207 | 1207 | // we're here so there ARE help tabs! |
| 1208 | 1208 | // make sure we've got what we need |
| 1209 | - if (! isset($cfg['title'])) { |
|
| 1209 | + if ( ! isset($cfg['title'])) { |
|
| 1210 | 1210 | throw new EE_Error( |
| 1211 | 1211 | esc_html__( |
| 1212 | 1212 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1214,7 +1214,7 @@ discard block |
||
| 1214 | 1214 | ) |
| 1215 | 1215 | ); |
| 1216 | 1216 | } |
| 1217 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1217 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1218 | 1218 | throw new EE_Error( |
| 1219 | 1219 | esc_html__( |
| 1220 | 1220 | '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', |
@@ -1223,11 +1223,11 @@ discard block |
||
| 1223 | 1223 | ); |
| 1224 | 1224 | } |
| 1225 | 1225 | // first priority goes to content. |
| 1226 | - if (! empty($cfg['content'])) { |
|
| 1226 | + if ( ! empty($cfg['content'])) { |
|
| 1227 | 1227 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1228 | 1228 | // second priority goes to filename |
| 1229 | - } elseif (! empty($cfg['filename'])) { |
|
| 1230 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1229 | + } elseif ( ! empty($cfg['filename'])) { |
|
| 1230 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1231 | 1231 | // 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) |
| 1232 | 1232 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
| 1233 | 1233 | . basename($this->_get_dir()) |
@@ -1235,7 +1235,7 @@ discard block |
||
| 1235 | 1235 | . $cfg['filename'] |
| 1236 | 1236 | . '.help_tab.php' : $file_path; |
| 1237 | 1237 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1238 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1238 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1239 | 1239 | EE_Error::add_error( |
| 1240 | 1240 | sprintf( |
| 1241 | 1241 | esc_html__( |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | return; |
| 1284 | 1284 | } |
| 1285 | 1285 | // setup config array for help tab method |
| 1286 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1286 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1287 | 1287 | $_ht = [ |
| 1288 | 1288 | 'id' => $id, |
| 1289 | 1289 | 'title' => $cfg['title'], |
@@ -1307,8 +1307,8 @@ discard block |
||
| 1307 | 1307 | $qtips = (array) $this->_route_config['qtips']; |
| 1308 | 1308 | // load qtip loader |
| 1309 | 1309 | $path = [ |
| 1310 | - $this->_get_dir() . '/qtips/', |
|
| 1311 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1310 | + $this->_get_dir().'/qtips/', |
|
| 1311 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1312 | 1312 | ]; |
| 1313 | 1313 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1314 | 1314 | } |
@@ -1330,7 +1330,7 @@ discard block |
||
| 1330 | 1330 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1331 | 1331 | $i = 0; |
| 1332 | 1332 | foreach ($this->_page_config as $slug => $config) { |
| 1333 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1333 | + if ( ! is_array($config) || empty($config['nav'])) { |
|
| 1334 | 1334 | continue; |
| 1335 | 1335 | } |
| 1336 | 1336 | // no nav tab for this config |
@@ -1339,12 +1339,12 @@ discard block |
||
| 1339 | 1339 | // nav tab is only to appear when route requested. |
| 1340 | 1340 | continue; |
| 1341 | 1341 | } |
| 1342 | - if (! $this->check_user_access($slug, true)) { |
|
| 1342 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1343 | 1343 | // no nav tab because current user does not have access. |
| 1344 | 1344 | continue; |
| 1345 | 1345 | } |
| 1346 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1347 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1346 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1347 | + $this->_nav_tabs[$slug] = [ |
|
| 1348 | 1348 | 'url' => isset($config['nav']['url']) |
| 1349 | 1349 | ? $config['nav']['url'] |
| 1350 | 1350 | : self::add_query_args_and_nonce( |
@@ -1356,14 +1356,14 @@ discard block |
||
| 1356 | 1356 | : ucwords( |
| 1357 | 1357 | str_replace('_', ' ', $slug) |
| 1358 | 1358 | ), |
| 1359 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1359 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1360 | 1360 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1361 | 1361 | ]; |
| 1362 | 1362 | $i++; |
| 1363 | 1363 | } |
| 1364 | 1364 | // if $this->_nav_tabs is empty then lets set the default |
| 1365 | 1365 | if (empty($this->_nav_tabs)) { |
| 1366 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1366 | + $this->_nav_tabs[$this->_default_nav_tab_name] = [ |
|
| 1367 | 1367 | 'url' => $this->_admin_base_url, |
| 1368 | 1368 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
| 1369 | 1369 | 'css_class' => 'nav-tab-active', |
@@ -1388,10 +1388,10 @@ discard block |
||
| 1388 | 1388 | foreach ($this->_route_config['labels'] as $label => $text) { |
| 1389 | 1389 | if (is_array($text)) { |
| 1390 | 1390 | foreach ($text as $sublabel => $subtext) { |
| 1391 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1391 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1392 | 1392 | } |
| 1393 | 1393 | } else { |
| 1394 | - $this->_labels[ $label ] = $text; |
|
| 1394 | + $this->_labels[$label] = $text; |
|
| 1395 | 1395 | } |
| 1396 | 1396 | } |
| 1397 | 1397 | } |
@@ -1413,12 +1413,12 @@ discard block |
||
| 1413 | 1413 | { |
| 1414 | 1414 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1415 | 1415 | $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
| 1416 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1416 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1417 | 1417 | && is_array( |
| 1418 | - $this->_page_routes[ $route_to_check ] |
|
| 1418 | + $this->_page_routes[$route_to_check] |
|
| 1419 | 1419 | ) |
| 1420 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1421 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1420 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1421 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1422 | 1422 | if (empty($capability) && empty($route_to_check)) { |
| 1423 | 1423 | $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
| 1424 | 1424 | : $this->_route['capability']; |
@@ -1538,7 +1538,7 @@ discard block |
||
| 1538 | 1538 | '; |
| 1539 | 1539 | |
| 1540 | 1540 | // current set timezone for timezone js |
| 1541 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1541 | + echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>'; |
|
| 1542 | 1542 | } |
| 1543 | 1543 | |
| 1544 | 1544 | |
@@ -1572,7 +1572,7 @@ discard block |
||
| 1572 | 1572 | // loop through the array and setup content |
| 1573 | 1573 | foreach ($help_array as $trigger => $help) { |
| 1574 | 1574 | // make sure the array is setup properly |
| 1575 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1575 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1576 | 1576 | throw new EE_Error( |
| 1577 | 1577 | esc_html__( |
| 1578 | 1578 | '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', |
@@ -1586,8 +1586,8 @@ discard block |
||
| 1586 | 1586 | 'help_popup_title' => $help['title'], |
| 1587 | 1587 | 'help_popup_content' => $help['content'], |
| 1588 | 1588 | ]; |
| 1589 | - $content .= EEH_Template::display_template( |
|
| 1590 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1589 | + $content .= EEH_Template::display_template( |
|
| 1590 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
| 1591 | 1591 | $template_args, |
| 1592 | 1592 | true |
| 1593 | 1593 | ); |
@@ -1609,15 +1609,15 @@ discard block |
||
| 1609 | 1609 | private function _get_help_content() |
| 1610 | 1610 | { |
| 1611 | 1611 | // what is the method we're looking for? |
| 1612 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1612 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1613 | 1613 | // if method doesn't exist let's get out. |
| 1614 | - if (! method_exists($this, $method_name)) { |
|
| 1614 | + if ( ! method_exists($this, $method_name)) { |
|
| 1615 | 1615 | return []; |
| 1616 | 1616 | } |
| 1617 | 1617 | // k we're good to go let's retrieve the help array |
| 1618 | 1618 | $help_array = call_user_func([$this, $method_name]); |
| 1619 | 1619 | // make sure we've got an array! |
| 1620 | - if (! is_array($help_array)) { |
|
| 1620 | + if ( ! is_array($help_array)) { |
|
| 1621 | 1621 | throw new EE_Error( |
| 1622 | 1622 | esc_html__( |
| 1623 | 1623 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1649,15 +1649,15 @@ discard block |
||
| 1649 | 1649 | // 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 |
| 1650 | 1650 | $help_array = $this->_get_help_content(); |
| 1651 | 1651 | $help_content = ''; |
| 1652 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1653 | - $help_array[ $trigger_id ] = [ |
|
| 1652 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1653 | + $help_array[$trigger_id] = [ |
|
| 1654 | 1654 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
| 1655 | 1655 | 'content' => esc_html__( |
| 1656 | 1656 | '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.)', |
| 1657 | 1657 | 'event_espresso' |
| 1658 | 1658 | ), |
| 1659 | 1659 | ]; |
| 1660 | - $help_content = $this->_set_help_popup_content($help_array); |
|
| 1660 | + $help_content = $this->_set_help_popup_content($help_array); |
|
| 1661 | 1661 | } |
| 1662 | 1662 | // let's setup the trigger |
| 1663 | 1663 | $content = '<a class="ee-dialog" href="?height=' |
@@ -1725,15 +1725,15 @@ discard block |
||
| 1725 | 1725 | // register all styles |
| 1726 | 1726 | wp_register_style( |
| 1727 | 1727 | 'espresso-ui-theme', |
| 1728 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1728 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1729 | 1729 | [], |
| 1730 | 1730 | EVENT_ESPRESSO_VERSION |
| 1731 | 1731 | ); |
| 1732 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1732 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1733 | 1733 | // helpers styles |
| 1734 | 1734 | wp_register_style( |
| 1735 | 1735 | 'ee-text-links', |
| 1736 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1736 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', |
|
| 1737 | 1737 | [], |
| 1738 | 1738 | EVENT_ESPRESSO_VERSION |
| 1739 | 1739 | ); |
@@ -1741,21 +1741,21 @@ discard block |
||
| 1741 | 1741 | // register all scripts |
| 1742 | 1742 | wp_register_script( |
| 1743 | 1743 | 'ee-dialog', |
| 1744 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1744 | + EE_ADMIN_URL.'assets/ee-dialog-helper.js', |
|
| 1745 | 1745 | ['jquery', 'jquery-ui-draggable'], |
| 1746 | 1746 | EVENT_ESPRESSO_VERSION, |
| 1747 | 1747 | true |
| 1748 | 1748 | ); |
| 1749 | 1749 | wp_register_script( |
| 1750 | 1750 | 'ee_admin_js', |
| 1751 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1751 | + EE_ADMIN_URL.'assets/ee-admin-page.js', |
|
| 1752 | 1752 | ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
| 1753 | 1753 | EVENT_ESPRESSO_VERSION, |
| 1754 | 1754 | true |
| 1755 | 1755 | ); |
| 1756 | 1756 | wp_register_script( |
| 1757 | 1757 | 'jquery-ui-timepicker-addon', |
| 1758 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1758 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', |
|
| 1759 | 1759 | ['jquery-ui-datepicker', 'jquery-ui-slider'], |
| 1760 | 1760 | EVENT_ESPRESSO_VERSION, |
| 1761 | 1761 | true |
@@ -1763,7 +1763,7 @@ discard block |
||
| 1763 | 1763 | // script for sorting tables |
| 1764 | 1764 | wp_register_script( |
| 1765 | 1765 | 'espresso_ajax_table_sorting', |
| 1766 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1766 | + EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js', |
|
| 1767 | 1767 | ['ee_admin_js', 'jquery-ui-sortable'], |
| 1768 | 1768 | EVENT_ESPRESSO_VERSION, |
| 1769 | 1769 | true |
@@ -1771,7 +1771,7 @@ discard block |
||
| 1771 | 1771 | // script for parsing uri's |
| 1772 | 1772 | wp_register_script( |
| 1773 | 1773 | 'ee-parse-uri', |
| 1774 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1774 | + EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', |
|
| 1775 | 1775 | [], |
| 1776 | 1776 | EVENT_ESPRESSO_VERSION, |
| 1777 | 1777 | true |
@@ -1779,7 +1779,7 @@ discard block |
||
| 1779 | 1779 | // and parsing associative serialized form elements |
| 1780 | 1780 | wp_register_script( |
| 1781 | 1781 | 'ee-serialize-full-array', |
| 1782 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1782 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', |
|
| 1783 | 1783 | ['jquery'], |
| 1784 | 1784 | EVENT_ESPRESSO_VERSION, |
| 1785 | 1785 | true |
@@ -1787,28 +1787,28 @@ discard block |
||
| 1787 | 1787 | // helpers scripts |
| 1788 | 1788 | wp_register_script( |
| 1789 | 1789 | 'ee-text-links', |
| 1790 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1790 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', |
|
| 1791 | 1791 | ['jquery'], |
| 1792 | 1792 | EVENT_ESPRESSO_VERSION, |
| 1793 | 1793 | true |
| 1794 | 1794 | ); |
| 1795 | 1795 | wp_register_script( |
| 1796 | 1796 | 'ee-moment-core', |
| 1797 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1797 | + EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', |
|
| 1798 | 1798 | [], |
| 1799 | 1799 | EVENT_ESPRESSO_VERSION, |
| 1800 | 1800 | true |
| 1801 | 1801 | ); |
| 1802 | 1802 | wp_register_script( |
| 1803 | 1803 | 'ee-moment', |
| 1804 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1804 | + EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', |
|
| 1805 | 1805 | ['ee-moment-core'], |
| 1806 | 1806 | EVENT_ESPRESSO_VERSION, |
| 1807 | 1807 | true |
| 1808 | 1808 | ); |
| 1809 | 1809 | wp_register_script( |
| 1810 | 1810 | 'ee-datepicker', |
| 1811 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1811 | + EE_ADMIN_URL.'assets/ee-datepicker.js', |
|
| 1812 | 1812 | ['jquery-ui-timepicker-addon', 'ee-moment'], |
| 1813 | 1813 | EVENT_ESPRESSO_VERSION, |
| 1814 | 1814 | true |
@@ -1841,7 +1841,7 @@ discard block |
||
| 1841 | 1841 | wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
| 1842 | 1842 | add_filter( |
| 1843 | 1843 | 'admin_body_class', |
| 1844 | - function ($classes) { |
|
| 1844 | + function($classes) { |
|
| 1845 | 1845 | if (strpos($classes, 'espresso-admin') === false) { |
| 1846 | 1846 | $classes .= ' espresso-admin'; |
| 1847 | 1847 | } |
@@ -1929,12 +1929,12 @@ discard block |
||
| 1929 | 1929 | protected function _set_list_table() |
| 1930 | 1930 | { |
| 1931 | 1931 | // first is this a list_table view? |
| 1932 | - if (! isset($this->_route_config['list_table'])) { |
|
| 1932 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 1933 | 1933 | return; |
| 1934 | 1934 | } //not a list_table view so get out. |
| 1935 | 1935 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
| 1936 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 1937 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1936 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
| 1937 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 1938 | 1938 | // user error msg |
| 1939 | 1939 | $error_msg = esc_html__( |
| 1940 | 1940 | 'An error occurred. The requested list table views could not be found.', |
@@ -1954,10 +1954,10 @@ discard block |
||
| 1954 | 1954 | } |
| 1955 | 1955 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 1956 | 1956 | $this->_views = apply_filters( |
| 1957 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 1957 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
| 1958 | 1958 | $this->_views |
| 1959 | 1959 | ); |
| 1960 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1960 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 1961 | 1961 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 1962 | 1962 | $this->_set_list_table_view(); |
| 1963 | 1963 | $this->_set_list_table_object(); |
@@ -1992,7 +1992,7 @@ discard block |
||
| 1992 | 1992 | protected function _set_list_table_object() |
| 1993 | 1993 | { |
| 1994 | 1994 | if (isset($this->_route_config['list_table'])) { |
| 1995 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 1995 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 1996 | 1996 | throw new EE_Error( |
| 1997 | 1997 | sprintf( |
| 1998 | 1998 | esc_html__( |
@@ -2030,15 +2030,15 @@ discard block |
||
| 2030 | 2030 | foreach ($this->_views as $key => $view) { |
| 2031 | 2031 | $query_args = []; |
| 2032 | 2032 | // check for current view |
| 2033 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2033 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2034 | 2034 | $query_args['action'] = $this->_req_action; |
| 2035 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2035 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2036 | 2036 | $query_args['status'] = $view['slug']; |
| 2037 | 2037 | // merge any other arguments sent in. |
| 2038 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2039 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2038 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2039 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2040 | 2040 | } |
| 2041 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2041 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2042 | 2042 | } |
| 2043 | 2043 | return $this->_views; |
| 2044 | 2044 | } |
@@ -2069,14 +2069,14 @@ discard block |
||
| 2069 | 2069 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2070 | 2070 | foreach ($values as $value) { |
| 2071 | 2071 | if ($value < $max_entries) { |
| 2072 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2072 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2073 | 2073 | $entries_per_page_dropdown .= ' |
| 2074 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 2074 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 2075 | 2075 | } |
| 2076 | 2076 | } |
| 2077 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2077 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2078 | 2078 | $entries_per_page_dropdown .= ' |
| 2079 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 2079 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 2080 | 2080 | $entries_per_page_dropdown .= ' |
| 2081 | 2081 | </select> |
| 2082 | 2082 | entries |
@@ -2100,7 +2100,7 @@ discard block |
||
| 2100 | 2100 | empty($this->_search_btn_label) ? $this->page_label |
| 2101 | 2101 | : $this->_search_btn_label |
| 2102 | 2102 | ); |
| 2103 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2103 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 2104 | 2104 | } |
| 2105 | 2105 | |
| 2106 | 2106 | |
@@ -2188,7 +2188,7 @@ discard block |
||
| 2188 | 2188 | $total_columns = ! empty($screen_columns) |
| 2189 | 2189 | ? $screen_columns |
| 2190 | 2190 | : $this->_route_config['columns'][1]; |
| 2191 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2191 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 2192 | 2192 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2193 | 2193 | $this->_template_args['screen'] = $this->_current_screen; |
| 2194 | 2194 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2233,7 +2233,7 @@ discard block |
||
| 2233 | 2233 | */ |
| 2234 | 2234 | protected function _espresso_ratings_request() |
| 2235 | 2235 | { |
| 2236 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2236 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2237 | 2237 | return; |
| 2238 | 2238 | } |
| 2239 | 2239 | $ratings_box_title = apply_filters( |
@@ -2261,7 +2261,7 @@ discard block |
||
| 2261 | 2261 | public function espresso_ratings_request() |
| 2262 | 2262 | { |
| 2263 | 2263 | EEH_Template::display_template( |
| 2264 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2264 | + EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php', |
|
| 2265 | 2265 | [] |
| 2266 | 2266 | ); |
| 2267 | 2267 | } |
@@ -2269,22 +2269,22 @@ discard block |
||
| 2269 | 2269 | |
| 2270 | 2270 | public static function cached_rss_display($rss_id, $url) |
| 2271 | 2271 | { |
| 2272 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2272 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2273 | 2273 | . esc_html__('Loading…', 'event_espresso') |
| 2274 | 2274 | . '</p><p class="hide-if-js">' |
| 2275 | 2275 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
| 2276 | 2276 | . '</p>'; |
| 2277 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2278 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2279 | - $post = '</div>' . "\n"; |
|
| 2280 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2277 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 2278 | + $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>'; |
|
| 2279 | + $post = '</div>'."\n"; |
|
| 2280 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 2281 | 2281 | $output = get_transient($cache_key); |
| 2282 | 2282 | if ($output !== false) { |
| 2283 | - echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags()); |
|
| 2283 | + echo wp_kses($pre.$output.$post, AllowedTags::getWithFormTags()); |
|
| 2284 | 2284 | return true; |
| 2285 | 2285 | } |
| 2286 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2287 | - echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags()); |
|
| 2286 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2287 | + echo wp_kses($pre.$loading.$post, AllowedTags::getWithFormTags()); |
|
| 2288 | 2288 | return false; |
| 2289 | 2289 | } |
| 2290 | 2290 | ob_start(); |
@@ -2351,19 +2351,19 @@ discard block |
||
| 2351 | 2351 | public function espresso_sponsors_post_box() |
| 2352 | 2352 | { |
| 2353 | 2353 | EEH_Template::display_template( |
| 2354 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2354 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2355 | 2355 | ); |
| 2356 | 2356 | } |
| 2357 | 2357 | |
| 2358 | 2358 | |
| 2359 | 2359 | private function _publish_post_box() |
| 2360 | 2360 | { |
| 2361 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2361 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2362 | 2362 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
| 2363 | 2363 | // then we'll use that for the metabox label. |
| 2364 | 2364 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2365 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2366 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2365 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2366 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2367 | 2367 | : $this->_labels['publishbox']; |
| 2368 | 2368 | } else { |
| 2369 | 2369 | $box_label = esc_html__('Publish', 'event_espresso'); |
@@ -2392,7 +2392,7 @@ discard block |
||
| 2392 | 2392 | ? $this->_template_args['publish_box_extra_content'] |
| 2393 | 2393 | : ''; |
| 2394 | 2394 | echo EEH_Template::display_template( |
| 2395 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2395 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
| 2396 | 2396 | $this->_template_args, |
| 2397 | 2397 | true |
| 2398 | 2398 | ); |
@@ -2484,18 +2484,18 @@ discard block |
||
| 2484 | 2484 | ); |
| 2485 | 2485 | } |
| 2486 | 2486 | $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
| 2487 | - if (! empty($name) && ! empty($id)) { |
|
| 2488 | - $hidden_field_arr[ $name ] = [ |
|
| 2487 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2488 | + $hidden_field_arr[$name] = [ |
|
| 2489 | 2489 | 'type' => 'hidden', |
| 2490 | 2490 | 'value' => $id, |
| 2491 | 2491 | ]; |
| 2492 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2492 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2493 | 2493 | } else { |
| 2494 | 2494 | $hf = ''; |
| 2495 | 2495 | } |
| 2496 | 2496 | // add hidden field |
| 2497 | 2497 | $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
| 2498 | - ? $hf[ $name ]['field'] |
|
| 2498 | + ? $hf[$name]['field'] |
|
| 2499 | 2499 | : $hf; |
| 2500 | 2500 | } |
| 2501 | 2501 | |
@@ -2597,7 +2597,7 @@ discard block |
||
| 2597 | 2597 | } |
| 2598 | 2598 | // 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) |
| 2599 | 2599 | $call_back_func = $create_func |
| 2600 | - ? function ($post, $metabox) { |
|
| 2600 | + ? function($post, $metabox) { |
|
| 2601 | 2601 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2602 | 2602 | echo EEH_Template::display_template( |
| 2603 | 2603 | $metabox['args']['template_path'], |
@@ -2607,7 +2607,7 @@ discard block |
||
| 2607 | 2607 | } |
| 2608 | 2608 | : $callback; |
| 2609 | 2609 | add_meta_box( |
| 2610 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2610 | + str_replace('_', '-', $action).'-mbox', |
|
| 2611 | 2611 | $title, |
| 2612 | 2612 | $call_back_func, |
| 2613 | 2613 | $this->_wp_page_slug, |
@@ -2699,9 +2699,9 @@ discard block |
||
| 2699 | 2699 | : 'espresso-default-admin'; |
| 2700 | 2700 | $template_path = $sidebar |
| 2701 | 2701 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
| 2702 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2702 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2703 | 2703 | if ($this->request->isAjax()) { |
| 2704 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2704 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2705 | 2705 | } |
| 2706 | 2706 | $template_path = ! empty($this->_column_template_path) |
| 2707 | 2707 | ? $this->_column_template_path : $template_path; |
@@ -2741,11 +2741,11 @@ discard block |
||
| 2741 | 2741 | public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
| 2742 | 2742 | { |
| 2743 | 2743 | // let's generate a default preview action button if there isn't one already present. |
| 2744 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2744 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2745 | 2745 | 'Upgrade to Event Espresso 4 Right Now', |
| 2746 | 2746 | 'event_espresso' |
| 2747 | 2747 | ); |
| 2748 | - $buy_now_url = add_query_arg( |
|
| 2748 | + $buy_now_url = add_query_arg( |
|
| 2749 | 2749 | [ |
| 2750 | 2750 | 'ee_ver' => 'ee4', |
| 2751 | 2751 | 'utm_source' => 'ee4_plugin_admin', |
@@ -2765,8 +2765,8 @@ discard block |
||
| 2765 | 2765 | true |
| 2766 | 2766 | ) |
| 2767 | 2767 | : $this->_template_args['preview_action_button']; |
| 2768 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2769 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2768 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2769 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
| 2770 | 2770 | $this->_template_args, |
| 2771 | 2771 | true |
| 2772 | 2772 | ); |
@@ -2815,7 +2815,7 @@ discard block |
||
| 2815 | 2815 | // setup search attributes |
| 2816 | 2816 | $this->_set_search_attributes(); |
| 2817 | 2817 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2818 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2818 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2819 | 2819 | $this->_template_args['table_url'] = $this->request->isAjax() |
| 2820 | 2820 | ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
| 2821 | 2821 | : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
@@ -2823,10 +2823,10 @@ discard block |
||
| 2823 | 2823 | $this->_template_args['current_route'] = $this->_req_action; |
| 2824 | 2824 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
| 2825 | 2825 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2826 | - if (! empty($ajax_sorting_callback)) { |
|
| 2826 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2827 | 2827 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2828 | - $ajax_sorting_callback . '_nonce', |
|
| 2829 | - $ajax_sorting_callback . '_nonce', |
|
| 2828 | + $ajax_sorting_callback.'_nonce', |
|
| 2829 | + $ajax_sorting_callback.'_nonce', |
|
| 2830 | 2830 | false, |
| 2831 | 2831 | false |
| 2832 | 2832 | ); |
@@ -2845,18 +2845,18 @@ discard block |
||
| 2845 | 2845 | ? $this->_template_args['list_table_hidden_fields'] |
| 2846 | 2846 | : ''; |
| 2847 | 2847 | |
| 2848 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2848 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 2849 | 2849 | $hidden_form_fields .= ' |
| 2850 | - <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2850 | + <input type="hidden" name="' . $nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">'; |
|
| 2851 | 2851 | |
| 2852 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2852 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2853 | 2853 | // display message about search results? |
| 2854 | 2854 | $search = $this->request->getRequestParam('s'); |
| 2855 | 2855 | $this->_template_args['before_list_table'] .= ! empty($search) |
| 2856 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2856 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 2857 | 2857 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 2858 | 2858 | trim($search, '%') |
| 2859 | - ) . '</p>' |
|
| 2859 | + ).'</p>' |
|
| 2860 | 2860 | : ''; |
| 2861 | 2861 | // filter before_list_table template arg |
| 2862 | 2862 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -2890,7 +2890,7 @@ discard block |
||
| 2890 | 2890 | // convert to array and filter again |
| 2891 | 2891 | // arrays are easier to inject new items in a specific location, |
| 2892 | 2892 | // but would not be backwards compatible, so we have to add a new filter |
| 2893 | - $this->_template_args['after_list_table'] = implode( |
|
| 2893 | + $this->_template_args['after_list_table'] = implode( |
|
| 2894 | 2894 | " \n", |
| 2895 | 2895 | (array) apply_filters( |
| 2896 | 2896 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
@@ -2937,7 +2937,7 @@ discard block |
||
| 2937 | 2937 | $this |
| 2938 | 2938 | ); |
| 2939 | 2939 | return EEH_Template::display_template( |
| 2940 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 2940 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
| 2941 | 2941 | $this->_template_args, |
| 2942 | 2942 | true |
| 2943 | 2943 | ); |
@@ -3046,18 +3046,18 @@ discard block |
||
| 3046 | 3046 | : '' |
| 3047 | 3047 | ); |
| 3048 | 3048 | |
| 3049 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3049 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3050 | 3050 | "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
| 3051 | 3051 | isset($this->_template_args['after_admin_page_content']) |
| 3052 | 3052 | ? $this->_template_args['after_admin_page_content'] |
| 3053 | 3053 | : '' |
| 3054 | 3054 | ); |
| 3055 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3055 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3056 | 3056 | |
| 3057 | 3057 | if ($this->request->isAjax()) { |
| 3058 | 3058 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 3059 | 3059 | // $template_path, |
| 3060 | - EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php', |
|
| 3060 | + EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php', |
|
| 3061 | 3061 | $this->_template_args, |
| 3062 | 3062 | true |
| 3063 | 3063 | ); |
@@ -3066,7 +3066,7 @@ discard block |
||
| 3066 | 3066 | // load settings page wrapper template |
| 3067 | 3067 | $template_path = $about |
| 3068 | 3068 | ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
| 3069 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'; |
|
| 3069 | + : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php'; |
|
| 3070 | 3070 | |
| 3071 | 3071 | EEH_Template::display_template($template_path, $this->_template_args); |
| 3072 | 3072 | } |
@@ -3151,12 +3151,12 @@ discard block |
||
| 3151 | 3151 | $default_names = ['save', 'save_and_close']; |
| 3152 | 3152 | $buttons = ''; |
| 3153 | 3153 | foreach ($button_text as $key => $button) { |
| 3154 | - $ref = $default_names[ $key ]; |
|
| 3155 | - $name = ! empty($actions) ? $actions[ $key ] : $ref; |
|
| 3156 | - $buttons .= '<input type="submit" class="button-primary ' . $ref . '" ' |
|
| 3157 | - . 'value="' . $button . '" name="' . $name . '" ' |
|
| 3158 | - . 'id="' . $this->_current_view . '_' . $ref . '" />'; |
|
| 3159 | - if (! $both) { |
|
| 3154 | + $ref = $default_names[$key]; |
|
| 3155 | + $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 3156 | + $buttons .= '<input type="submit" class="button-primary '.$ref.'" ' |
|
| 3157 | + . 'value="'.$button.'" name="'.$name.'" ' |
|
| 3158 | + . 'id="'.$this->_current_view.'_'.$ref.'" />'; |
|
| 3159 | + if ( ! $both) { |
|
| 3160 | 3160 | break; |
| 3161 | 3161 | } |
| 3162 | 3162 | } |
@@ -3196,13 +3196,13 @@ discard block |
||
| 3196 | 3196 | 'An error occurred. No action was set for this page\'s form.', |
| 3197 | 3197 | 'event_espresso' |
| 3198 | 3198 | ); |
| 3199 | - $dev_msg = $user_msg . "\n" |
|
| 3199 | + $dev_msg = $user_msg."\n" |
|
| 3200 | 3200 | . sprintf( |
| 3201 | 3201 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
| 3202 | 3202 | __FUNCTION__, |
| 3203 | 3203 | __CLASS__ |
| 3204 | 3204 | ); |
| 3205 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3205 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3206 | 3206 | } |
| 3207 | 3207 | // open form |
| 3208 | 3208 | $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
@@ -3211,9 +3211,9 @@ discard block |
||
| 3211 | 3211 | . $route |
| 3212 | 3212 | . '_event_form" >'; |
| 3213 | 3213 | // add nonce |
| 3214 | - $nonce = |
|
| 3215 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3216 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3214 | + $nonce = |
|
| 3215 | + wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 3216 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 3217 | 3217 | // add REQUIRED form action |
| 3218 | 3218 | $hidden_fields = [ |
| 3219 | 3219 | 'action' => ['type' => 'hidden', 'value' => $route], |
@@ -3226,7 +3226,7 @@ discard block |
||
| 3226 | 3226 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 3227 | 3227 | // add fields to form |
| 3228 | 3228 | foreach ((array) $form_fields as $form_field) { |
| 3229 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3229 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 3230 | 3230 | } |
| 3231 | 3231 | // close form |
| 3232 | 3232 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3317,10 +3317,10 @@ discard block |
||
| 3317 | 3317 | $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
| 3318 | 3318 | $notices = EE_Error::get_notices(false); |
| 3319 | 3319 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
| 3320 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3320 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3321 | 3321 | EE_Error::overwrite_success(); |
| 3322 | 3322 | } |
| 3323 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3323 | + if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3324 | 3324 | // how many records affected ? more than one record ? or just one ? |
| 3325 | 3325 | if ($success > 1) { |
| 3326 | 3326 | // set plural msg |
@@ -3349,7 +3349,7 @@ discard block |
||
| 3349 | 3349 | } |
| 3350 | 3350 | } |
| 3351 | 3351 | // check that $query_args isn't something crazy |
| 3352 | - if (! is_array($query_args)) { |
|
| 3352 | + if ( ! is_array($query_args)) { |
|
| 3353 | 3353 | $query_args = []; |
| 3354 | 3354 | } |
| 3355 | 3355 | /** |
@@ -3378,7 +3378,7 @@ discard block |
||
| 3378 | 3378 | $redirect_url = admin_url('admin.php'); |
| 3379 | 3379 | } |
| 3380 | 3380 | // merge any default query_args set in _default_route_query_args property |
| 3381 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3381 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3382 | 3382 | $args_to_merge = []; |
| 3383 | 3383 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 3384 | 3384 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3390,15 +3390,15 @@ discard block |
||
| 3390 | 3390 | } |
| 3391 | 3391 | // finally we will override any arguments in the referer with |
| 3392 | 3392 | // what might be set on the _default_route_query_args array. |
| 3393 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3394 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3393 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3394 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3395 | 3395 | } else { |
| 3396 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3396 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3397 | 3397 | } |
| 3398 | 3398 | } |
| 3399 | 3399 | continue; |
| 3400 | 3400 | } |
| 3401 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3401 | + $args_to_merge[$query_param] = $query_value; |
|
| 3402 | 3402 | } |
| 3403 | 3403 | // now let's merge these arguments but override with what was specifically sent in to the |
| 3404 | 3404 | // redirect. |
@@ -3410,19 +3410,19 @@ discard block |
||
| 3410 | 3410 | if (isset($query_args['action'])) { |
| 3411 | 3411 | // manually generate wp_nonce and merge that with the query vars |
| 3412 | 3412 | // becuz the wp_nonce_url function wrecks havoc on some vars |
| 3413 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3413 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 3414 | 3414 | } |
| 3415 | 3415 | // we're adding some hooks and filters in here for processing any things just before redirects |
| 3416 | 3416 | // (example: an admin page has done an insert or update and we want to run something after that). |
| 3417 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3417 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 3418 | 3418 | $redirect_url = apply_filters( |
| 3419 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3419 | + 'FHEE_redirect_'.$classname.$this->_req_action, |
|
| 3420 | 3420 | self::add_query_args_and_nonce($query_args, $redirect_url), |
| 3421 | 3421 | $query_args |
| 3422 | 3422 | ); |
| 3423 | 3423 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
| 3424 | 3424 | if ($this->request->isAjax()) { |
| 3425 | - $default_data = [ |
|
| 3425 | + $default_data = [ |
|
| 3426 | 3426 | 'close' => true, |
| 3427 | 3427 | 'redirect_url' => $redirect_url, |
| 3428 | 3428 | 'where' => 'main', |
@@ -3469,7 +3469,7 @@ discard block |
||
| 3469 | 3469 | } |
| 3470 | 3470 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 3471 | 3471 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
| 3472 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3472 | + if ( ! $this->request->isAjax() || $sticky_notices) { |
|
| 3473 | 3473 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
| 3474 | 3474 | $this->_add_transient( |
| 3475 | 3475 | $route, |
@@ -3509,7 +3509,7 @@ discard block |
||
| 3509 | 3509 | $exclude_nonce = false |
| 3510 | 3510 | ) { |
| 3511 | 3511 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
| 3512 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3512 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3513 | 3513 | throw new EE_Error( |
| 3514 | 3514 | sprintf( |
| 3515 | 3515 | esc_html__( |
@@ -3520,7 +3520,7 @@ discard block |
||
| 3520 | 3520 | ) |
| 3521 | 3521 | ); |
| 3522 | 3522 | } |
| 3523 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3523 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 3524 | 3524 | throw new EE_Error( |
| 3525 | 3525 | sprintf( |
| 3526 | 3526 | esc_html__( |
@@ -3533,7 +3533,7 @@ discard block |
||
| 3533 | 3533 | } |
| 3534 | 3534 | // finally check user access for this button. |
| 3535 | 3535 | $has_access = $this->check_user_access($action, true); |
| 3536 | - if (! $has_access) { |
|
| 3536 | + if ( ! $has_access) { |
|
| 3537 | 3537 | return ''; |
| 3538 | 3538 | } |
| 3539 | 3539 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3541,11 +3541,11 @@ discard block |
||
| 3541 | 3541 | 'action' => $action, |
| 3542 | 3542 | ]; |
| 3543 | 3543 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
| 3544 | - if (! empty($extra_request)) { |
|
| 3544 | + if ( ! empty($extra_request)) { |
|
| 3545 | 3545 | $query_args = array_merge($extra_request, $query_args); |
| 3546 | 3546 | } |
| 3547 | 3547 | $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
| 3548 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3548 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3549 | 3549 | } |
| 3550 | 3550 | |
| 3551 | 3551 | |
@@ -3571,7 +3571,7 @@ discard block |
||
| 3571 | 3571 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
| 3572 | 3572 | 20 |
| 3573 | 3573 | ), |
| 3574 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3574 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3575 | 3575 | ]; |
| 3576 | 3576 | // ONLY add the screen option if the user has access to it. |
| 3577 | 3577 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3592,18 +3592,18 @@ discard block |
||
| 3592 | 3592 | { |
| 3593 | 3593 | if ($this->request->requestParamIsSet('wp_screen_options')) { |
| 3594 | 3594 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
| 3595 | - if (! $user = wp_get_current_user()) { |
|
| 3595 | + if ( ! $user = wp_get_current_user()) { |
|
| 3596 | 3596 | return; |
| 3597 | 3597 | } |
| 3598 | 3598 | $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
| 3599 | - if (! $option) { |
|
| 3599 | + if ( ! $option) { |
|
| 3600 | 3600 | return; |
| 3601 | 3601 | } |
| 3602 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3602 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3603 | 3603 | $map_option = $option; |
| 3604 | 3604 | $option = str_replace('-', '_', $option); |
| 3605 | 3605 | switch ($map_option) { |
| 3606 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3606 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3607 | 3607 | $max_value = apply_filters( |
| 3608 | 3608 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
| 3609 | 3609 | 999, |
@@ -3660,13 +3660,13 @@ discard block |
||
| 3660 | 3660 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
| 3661 | 3661 | { |
| 3662 | 3662 | $user_id = get_current_user_id(); |
| 3663 | - if (! $skip_route_verify) { |
|
| 3663 | + if ( ! $skip_route_verify) { |
|
| 3664 | 3664 | $this->_verify_route($route); |
| 3665 | 3665 | } |
| 3666 | 3666 | // now let's set the string for what kind of transient we're setting |
| 3667 | 3667 | $transient = $notices |
| 3668 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3669 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3668 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3669 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3670 | 3670 | $data = $notices ? ['notices' => $data] : $data; |
| 3671 | 3671 | // is there already a transient for this route? If there is then let's ADD to that transient |
| 3672 | 3672 | $existing = is_multisite() && is_network_admin() |
@@ -3695,8 +3695,8 @@ discard block |
||
| 3695 | 3695 | $user_id = get_current_user_id(); |
| 3696 | 3696 | $route = ! $route ? $this->_req_action : $route; |
| 3697 | 3697 | $transient = $notices |
| 3698 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3699 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3698 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3699 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3700 | 3700 | $data = is_multisite() && is_network_admin() |
| 3701 | 3701 | ? get_site_transient($transient) |
| 3702 | 3702 | : get_transient($transient); |
@@ -3927,7 +3927,7 @@ discard block |
||
| 3927 | 3927 | */ |
| 3928 | 3928 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 3929 | 3929 | { |
| 3930 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3930 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3931 | 3931 | } |
| 3932 | 3932 | |
| 3933 | 3933 | |
@@ -3940,7 +3940,7 @@ discard block |
||
| 3940 | 3940 | */ |
| 3941 | 3941 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 3942 | 3942 | { |
| 3943 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3943 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3944 | 3944 | } |
| 3945 | 3945 | |
| 3946 | 3946 | |
@@ -4088,7 +4088,7 @@ discard block |
||
| 4088 | 4088 | callable $callback = null |
| 4089 | 4089 | ) { |
| 4090 | 4090 | $entity_ID = absint($entity_ID); |
| 4091 | - if (! $entity_ID) { |
|
| 4091 | + if ( ! $entity_ID) { |
|
| 4092 | 4092 | $this->trashRestoreDeleteError($action, $entity_model); |
| 4093 | 4093 | } |
| 4094 | 4094 | $result = 0; |
@@ -4134,7 +4134,7 @@ discard block |
||
| 4134 | 4134 | ) |
| 4135 | 4135 | ); |
| 4136 | 4136 | } |
| 4137 | - if (! $entity_model->has_field($delete_column)) { |
|
| 4137 | + if ( ! $entity_model->has_field($delete_column)) { |
|
| 4138 | 4138 | throw new DomainException( |
| 4139 | 4139 | sprintf( |
| 4140 | 4140 | esc_html__( |